Remove names from stored segment block values
[MAILPOET-2801]
This commit is contained in:
committed by
Veljko V
parent
76e6d4d296
commit
936a75c277
@ -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 (<p className="mailpoet_error">{MailPoet.I18n.t('blockSegmentSelectNoLists')}</p>);
|
||||
@ -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,
|
||||
],
|
||||
]),
|
||||
})}
|
||||
/>
|
||||
<span className="mailpoet_segment_label">
|
||||
@ -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,
|
||||
|
@ -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,
|
||||
})),
|
||||
},
|
||||
};
|
||||
|
@ -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 {
|
||||
|
@ -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' },
|
||||
],
|
||||
},
|
||||
};
|
||||
|
@ -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');
|
||||
});
|
||||
|
@ -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);
|
||||
});
|
||||
|
||||
|
@ -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',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
Reference in New Issue
Block a user