From 936a75c277a946c5bf2a11902a5445c203f84adc Mon Sep 17 00:00:00 2001 From: Rostislav Wolny Date: Wed, 8 Apr 2020 16:11:56 +0200 Subject: [PATCH] Remove names from stored segment block values [MAILPOET-2801] --- .../src/form_editor/blocks/segment_select/edit.jsx | 12 ++++++++---- .../js/src/form_editor/store/blocks_to_form_body.jsx | 1 - .../js/src/form_editor/store/form_body_to_blocks.jsx | 1 - .../form_editor/store/block_to_form_test_data.js | 6 +++--- .../form_editor/store/blocks_to_form_body.spec.js | 1 - .../form_editor/store/form_body_to_blocks.spec.js | 1 - .../form_editor/store/form_to_block_test_data.js | 3 --- 7 files changed, 11 insertions(+), 14 deletions(-) diff --git a/assets/js/src/form_editor/blocks/segment_select/edit.jsx b/assets/js/src/form_editor/blocks/segment_select/edit.jsx index 7223a8cfdb..ea75e78bdc 100644 --- a/assets/js/src/form_editor/blocks/segment_select/edit.jsx +++ b/assets/js/src/form_editor/blocks/segment_select/edit.jsx @@ -14,6 +14,11 @@ const SegmentSelectEdit = ({ attributes, setAttributes }) => { valueWithName.name = segment ? segment.name : ''; return valueWithName; }), [attributes.values, segments]); + const stripNamesFromValues = (values) => values.map((value) => { + const valueWithoutName = { ...value }; + delete valueWithoutName.name; + return valueWithoutName; + }); const renderValues = () => { if (attributes.values.length === 0) { return (

{MailPoet.I18n.t('blockSegmentSelectNoLists')}

); @@ -38,12 +43,12 @@ const SegmentSelectEdit = ({ attributes, setAttributes }) => { label={attributes.label} onLabelChanged={(label) => (setAttributes({ label }))} segmentsAddedIntoSelection={valuesWithNames} - setNewSelection={(selection) => setAttributes({ values: selection })} + setNewSelection={(selection) => setAttributes({ values: stripNamesFromValues(selection) })} addSegmentIntoSelection={(newSegment) => setAttributes({ - values: [ + values: stripNamesFromValues([ ...attributes.values, newSegment, - ], + ]), })} /> @@ -60,7 +65,6 @@ SegmentSelectEdit.propTypes = { className: PropTypes.string, values: PropTypes.arrayOf(PropTypes.shape({ isChecked: PropTypes.boolean, - name: PropTypes.string.isRequired, id: PropTypes.string.isRequired, })).isRequired, }).isRequired, diff --git a/assets/js/src/form_editor/store/blocks_to_form_body.jsx b/assets/js/src/form_editor/store/blocks_to_form_body.jsx index e8f800934a..bbc50274dc 100644 --- a/assets/js/src/form_editor/store/blocks_to_form_body.jsx +++ b/assets/js/src/form_editor/store/blocks_to_form_body.jsx @@ -279,7 +279,6 @@ export const blocksToFormBodyFactory = (colorDefinitions, fontSizeDefinitions, c values: block.attributes.values.map((segment) => ({ id: segment.id, is_checked: segment.isChecked ? '1' : undefined, - name: segment.name, })), }, }; diff --git a/assets/js/src/form_editor/store/form_body_to_blocks.jsx b/assets/js/src/form_editor/store/form_body_to_blocks.jsx index 533f75d264..eae020fa74 100644 --- a/assets/js/src/form_editor/store/form_body_to_blocks.jsx +++ b/assets/js/src/form_editor/store/form_body_to_blocks.jsx @@ -323,7 +323,6 @@ export const formBodyToBlocksFactory = ( ) { mapped.attributes.values = item.params.values.map((value) => ({ id: value.id, - name: value.name, isChecked: value.is_checked === '1' ? true : undefined, })); } else { diff --git a/tests/javascript/form_editor/store/block_to_form_test_data.js b/tests/javascript/form_editor/store/block_to_form_test_data.js index 9cae9f05cc..f2e2934466 100644 --- a/tests/javascript/form_editor/store/block_to_form_test_data.js +++ b/tests/javascript/form_editor/store/block_to_form_test_data.js @@ -37,9 +37,9 @@ export const segmentsBlock = { mandatory: false, label: 'Select list(s):', values: [ - { id: '6', name: 'Unicorn Truthers' }, - { id: '24', name: 'Carrots are lit', isChecked: true }, - { id: '29', name: 'Daily' }, + { id: '6' }, + { id: '24', isChecked: true }, + { id: '29' }, ], }, }; diff --git a/tests/javascript/form_editor/store/blocks_to_form_body.spec.js b/tests/javascript/form_editor/store/blocks_to_form_body.spec.js index 555ddf87fc..2205cdb309 100644 --- a/tests/javascript/form_editor/store/blocks_to_form_body.spec.js +++ b/tests/javascript/form_editor/store/blocks_to_form_body.spec.js @@ -211,7 +211,6 @@ describe('Blocks to Form Body', () => { expect(input.name).to.be.equal('List selection'); expect(input.type).to.be.equal('segment'); expect(input.params.values).to.be.an('Array'); - expect(input.params.values[0]).to.have.property('name', 'Unicorn Truthers'); expect(input.params.values[0]).to.have.property('id', '6'); expect(input.params.values[1]).to.have.property('is_checked', '1'); }); diff --git a/tests/javascript/form_editor/store/form_body_to_blocks.spec.js b/tests/javascript/form_editor/store/form_body_to_blocks.spec.js index 19e581b9fd..29c54b6fb1 100644 --- a/tests/javascript/form_editor/store/form_body_to_blocks.spec.js +++ b/tests/javascript/form_editor/store/form_body_to_blocks.spec.js @@ -270,7 +270,6 @@ describe('Form Body To Blocks', () => { expect(block.attributes.label).to.be.equal('Select list(s):'); expect(block.attributes.values).to.be.an('Array'); expect(block.attributes.values[0]).to.haveOwnProperty('id', '6'); - expect(block.attributes.values[0]).to.haveOwnProperty('name', 'Unicorn Truthers'); expect(block.attributes.values[1]).to.haveOwnProperty('isChecked', true); }); diff --git a/tests/javascript/form_editor/store/form_to_block_test_data.js b/tests/javascript/form_editor/store/form_to_block_test_data.js index b6149879f2..76653d62b0 100644 --- a/tests/javascript/form_editor/store/form_to_block_test_data.js +++ b/tests/javascript/form_editor/store/form_to_block_test_data.js @@ -42,16 +42,13 @@ export const segmentsInput = { values: [ { id: '6', - name: 'Unicorn Truthers', }, { id: '24', is_checked: '1', - name: 'Carrots are lit', }, { id: '29', - name: 'Daily', }, ], },