Remove redundant attributes
[MAILPOET-2613]
This commit is contained in:
@@ -7,7 +7,6 @@ const mapCustomField = (block, customFields, mappedCommonProperties) => {
|
||||
...mappedCommonProperties,
|
||||
id: block.attributes.customFieldId.toString(),
|
||||
name: customField.name,
|
||||
unique: '1',
|
||||
};
|
||||
if (block.name.startsWith('mailpoet-form/custom-date')) {
|
||||
mapped.type = 'date';
|
||||
@@ -87,12 +86,9 @@ export const blocksToFormBodyFactory = (colorDefinitions, customFields = []) =>
|
||||
if (!Array.isArray(customFields)) {
|
||||
throw new Error('Mapper expects customFields to be an array.');
|
||||
}
|
||||
return blocks.map((block, index) => {
|
||||
return blocks.map((block) => {
|
||||
const mapped = {
|
||||
type: 'text',
|
||||
unique: '0',
|
||||
static: '1',
|
||||
position: (index + 1).toString(),
|
||||
params: {
|
||||
label: block.attributes.label,
|
||||
},
|
||||
@@ -107,7 +103,6 @@ export const blocksToFormBodyFactory = (colorDefinitions, customFields = []) =>
|
||||
switch (block.name) {
|
||||
case 'core/heading':
|
||||
return {
|
||||
position: (index + 1).toString(),
|
||||
type: 'heading',
|
||||
id: 'heading',
|
||||
params: {
|
||||
@@ -121,7 +116,6 @@ export const blocksToFormBodyFactory = (colorDefinitions, customFields = []) =>
|
||||
};
|
||||
case 'core/column':
|
||||
return {
|
||||
position: (index + 1).toString(),
|
||||
type: 'column',
|
||||
params: {
|
||||
class_name: block.attributes.className || null,
|
||||
@@ -133,7 +127,6 @@ export const blocksToFormBodyFactory = (colorDefinitions, customFields = []) =>
|
||||
};
|
||||
case 'core/columns':
|
||||
return {
|
||||
position: (index + 1).toString(),
|
||||
type: 'columns',
|
||||
body: mapBlocks(block.innerBlocks, block),
|
||||
params: {
|
||||
@@ -165,16 +158,12 @@ export const blocksToFormBodyFactory = (colorDefinitions, customFields = []) =>
|
||||
return {
|
||||
...mapped,
|
||||
id: 'first_name',
|
||||
unique: '1',
|
||||
static: '0',
|
||||
name: 'First name',
|
||||
};
|
||||
case 'mailpoet-form/last-name-input':
|
||||
return {
|
||||
...mapped,
|
||||
id: 'last_name',
|
||||
unique: '1',
|
||||
static: '0',
|
||||
name: 'Last name',
|
||||
};
|
||||
case 'mailpoet-form/segment-select':
|
||||
@@ -182,8 +171,6 @@ export const blocksToFormBodyFactory = (colorDefinitions, customFields = []) =>
|
||||
...mapped,
|
||||
id: 'segments',
|
||||
type: 'segment',
|
||||
unique: '1',
|
||||
static: '0',
|
||||
name: 'List selection',
|
||||
params: {
|
||||
...mapped.params,
|
||||
@@ -207,7 +194,6 @@ export const blocksToFormBodyFactory = (colorDefinitions, customFields = []) =>
|
||||
id: 'divider',
|
||||
type: 'divider',
|
||||
name: 'Divider',
|
||||
static: '0',
|
||||
params: '',
|
||||
};
|
||||
case 'mailpoet-form/html':
|
||||
@@ -216,7 +202,6 @@ export const blocksToFormBodyFactory = (colorDefinitions, customFields = []) =>
|
||||
id: 'html',
|
||||
type: 'html',
|
||||
name: 'Custom text or HTML',
|
||||
static: '0',
|
||||
params: {
|
||||
text: block.attributes && block.attributes.content ? block.attributes.content : '',
|
||||
nl2br: block.attributes && block.attributes.nl2br ? '1' : '0',
|
||||
|
@@ -29,7 +29,6 @@ const colorDefinitions = [{
|
||||
|
||||
const checkBodyInputBasics = (input) => {
|
||||
expect(input.id).to.be.a('string');
|
||||
expect(parseInt(input.position, 10)).to.be.a('number');
|
||||
expect(input.type).to.be.a('string');
|
||||
expect(input.type).to.be.not.empty;
|
||||
};
|
||||
@@ -51,9 +50,6 @@ describe('Blocks to Form Body', () => {
|
||||
expect(input.id).to.be.equal('email');
|
||||
expect(input.name).to.be.equal('Email');
|
||||
expect(input.type).to.be.equal('text');
|
||||
expect(input.position).to.be.equal('1');
|
||||
expect(input.unique).to.be.equal('0');
|
||||
expect(input.static).to.be.equal('1');
|
||||
expect(input.params.label).to.be.equal('Email Address');
|
||||
expect(input.params.required).to.be.equal('1');
|
||||
expect(input.params.label_within).to.be.undefined;
|
||||
@@ -73,9 +69,6 @@ describe('Blocks to Form Body', () => {
|
||||
expect(input.id).to.be.equal('last_name');
|
||||
expect(input.name).to.be.equal('Last name');
|
||||
expect(input.type).to.be.equal('text');
|
||||
expect(input.position).to.be.equal('1');
|
||||
expect(input.unique).to.be.equal('1');
|
||||
expect(input.static).to.be.equal('0');
|
||||
expect(input.params.label).to.be.equal('Last Name');
|
||||
expect(input.params.required).to.be.undefined;
|
||||
expect(input.params.label_within).to.be.undefined;
|
||||
@@ -97,9 +90,6 @@ describe('Blocks to Form Body', () => {
|
||||
expect(input.id).to.be.equal('first_name');
|
||||
expect(input.name).to.be.equal('First name');
|
||||
expect(input.type).to.be.equal('text');
|
||||
expect(input.position).to.be.equal('1');
|
||||
expect(input.unique).to.be.equal('1');
|
||||
expect(input.static).to.be.equal('0');
|
||||
expect(input.params.label).to.be.equal('First Name');
|
||||
expect(input.params.required).to.be.undefined;
|
||||
expect(input.params.label_within).to.be.undefined;
|
||||
@@ -133,9 +123,6 @@ describe('Blocks to Form Body', () => {
|
||||
expect(input.id).to.be.equal('submit');
|
||||
expect(input.name).to.be.equal('Submit');
|
||||
expect(input.type).to.be.equal('submit');
|
||||
expect(input.position).to.be.equal('1');
|
||||
expect(input.unique).to.be.equal('0');
|
||||
expect(input.static).to.be.equal('1');
|
||||
expect(input.params.label).to.be.equal('Subscribe!');
|
||||
});
|
||||
|
||||
@@ -145,9 +132,6 @@ describe('Blocks to Form Body', () => {
|
||||
expect(divider.id).to.be.equal('divider');
|
||||
expect(divider.name).to.be.equal('Divider');
|
||||
expect(divider.type).to.be.equal('divider');
|
||||
expect(divider.position).to.be.equal('1');
|
||||
expect(divider.unique).to.be.equal('0');
|
||||
expect(divider.static).to.be.equal('0');
|
||||
expect(divider.params).to.be.equal('');
|
||||
});
|
||||
|
||||
@@ -157,8 +141,6 @@ describe('Blocks to Form Body', () => {
|
||||
checkBodyInputBasics(divider2);
|
||||
expect(divider1.id).to.be.equal('divider');
|
||||
expect(divider2.id).to.be.equal('divider');
|
||||
expect(divider1.position).to.be.equal('1');
|
||||
expect(divider2.position).to.be.equal('2');
|
||||
});
|
||||
|
||||
it('Should custom html block to form data', () => {
|
||||
@@ -167,9 +149,6 @@ describe('Blocks to Form Body', () => {
|
||||
expect(html.id).to.be.equal('html');
|
||||
expect(html.name).to.be.equal('Custom text or HTML');
|
||||
expect(html.type).to.be.equal('html');
|
||||
expect(html.position).to.be.equal('1');
|
||||
expect(html.unique).to.be.equal('0');
|
||||
expect(html.static).to.be.equal('0');
|
||||
expect(html.params.text).to.be.equal('HTML content');
|
||||
expect(html.params.nl2br).to.be.equal('1');
|
||||
});
|
||||
@@ -193,7 +172,6 @@ describe('Blocks to Form Body', () => {
|
||||
expect(input.id).to.be.equal('1');
|
||||
expect(input.name).to.be.equal('Custom Field name');
|
||||
expect(input.type).to.be.equal('text');
|
||||
expect(input.position).to.be.equal('1');
|
||||
expect(input.params.label).to.be.equal('Name of the street');
|
||||
expect(input.params.required).to.be.undefined;
|
||||
expect(input.params.label_within).to.be.undefined;
|
||||
@@ -221,8 +199,6 @@ describe('Blocks to Form Body', () => {
|
||||
expect(input.id).to.be.equal('6');
|
||||
expect(input.name).to.be.equal('Custom Select');
|
||||
expect(input.type).to.be.equal('select');
|
||||
expect(input.position).to.be.equal('1');
|
||||
expect(input.unique).to.be.equal('1');
|
||||
expect(input.params.label).to.be.equal('Select');
|
||||
expect(input.params.values).to.be.an('Array').that.has.length(2);
|
||||
expect(input.params.values[0]).to.have.property('value', 'option 1');
|
||||
@@ -250,8 +226,6 @@ describe('Blocks to Form Body', () => {
|
||||
expect(input.id).to.be.equal('2');
|
||||
expect(input.name).to.be.equal('Custom Field name');
|
||||
expect(input.type).to.be.equal('radio');
|
||||
expect(input.position).to.be.equal('1');
|
||||
expect(input.unique).to.be.equal('1');
|
||||
expect(input.params.label).to.be.equal('Options');
|
||||
expect(input.params.required).to.be.eq('1');
|
||||
expect(input.params.hide_label).to.eq('1');
|
||||
@@ -316,8 +290,6 @@ describe('Blocks to Form Body', () => {
|
||||
expect(input.id).to.be.equal('3');
|
||||
expect(input.name).to.be.equal('Custom Checkbox');
|
||||
expect(input.type).to.be.equal('checkbox');
|
||||
expect(input.position).to.be.equal('1');
|
||||
expect(input.unique).to.be.equal('1');
|
||||
expect(input.params.label).to.be.equal('Checkbox');
|
||||
expect(input.params.required).to.be.be.undefined;
|
||||
expect(input.params.hide_label).to.be.undefined;
|
||||
@@ -346,8 +318,6 @@ describe('Blocks to Form Body', () => {
|
||||
expect(input.id).to.be.equal('6');
|
||||
expect(input.name).to.be.equal('Custom Date');
|
||||
expect(input.type).to.be.equal('date');
|
||||
expect(input.position).to.be.equal('1');
|
||||
expect(input.unique).to.be.equal('1');
|
||||
expect(input.params.label).to.be.equal('Date');
|
||||
expect(input.params.required).to.be.undefined;
|
||||
expect(input.params.date_type).to.be.equal('month_year');
|
||||
@@ -362,7 +332,6 @@ describe('Blocks to Form Body', () => {
|
||||
// First level
|
||||
expect(columns.body.length).to.be.equal(2);
|
||||
expect(columns.type).to.be.equal('columns');
|
||||
expect(columns.position).to.be.equal('2');
|
||||
expect(columns.params.vertical_alignment).to.be.equal('center');
|
||||
const column1 = columns.body[0];
|
||||
const column2 = columns.body[1];
|
||||
|
@@ -56,7 +56,7 @@ describe('Form Body To Blocks', () => {
|
||||
});
|
||||
|
||||
it('Should map email input to block', () => {
|
||||
const [block] = formBodyToBlocks([{ ...emailInput, position: '1' }]);
|
||||
const [block] = formBodyToBlocks([emailInput]);
|
||||
checkBlockBasics(block);
|
||||
expect(block.clientId).to.include('email_');
|
||||
expect(block.name).to.be.equal('mailpoet-form/email-input');
|
||||
@@ -65,22 +65,22 @@ describe('Form Body To Blocks', () => {
|
||||
});
|
||||
|
||||
it('Should map email with label within correctly', () => {
|
||||
const email = { ...emailInput, position: '1' };
|
||||
const email = { ...emailInput };
|
||||
email.params.label_within = '1';
|
||||
const [block] = formBodyToBlocks([email]);
|
||||
expect(block.attributes.labelWithinInput).to.be.equal(true);
|
||||
});
|
||||
|
||||
it('Should add a label if label is missing in data', () => {
|
||||
const input = { ...emailInput, position: '1' };
|
||||
const input = { ...emailInput };
|
||||
delete input.params.label;
|
||||
const [block] = formBodyToBlocks([{ ...emailInput, position: '1' }]);
|
||||
const [block] = formBodyToBlocks([{ ...emailInput }]);
|
||||
checkBlockBasics(block);
|
||||
expect(block.attributes.label).to.be.equal('');
|
||||
});
|
||||
|
||||
it('Should map first name input to block', () => {
|
||||
const [block] = formBodyToBlocks([{ ...firstNameInput, position: '1' }]);
|
||||
const [block] = formBodyToBlocks([firstNameInput]);
|
||||
checkBlockBasics(block);
|
||||
expect(block.clientId).to.be.include('first_name_');
|
||||
expect(block.name).to.be.equal('mailpoet-form/first-name-input');
|
||||
@@ -90,7 +90,7 @@ describe('Form Body To Blocks', () => {
|
||||
});
|
||||
|
||||
it('Should map first name with label within correctly', () => {
|
||||
const input = { ...firstNameInput, position: '1' };
|
||||
const input = { ...firstNameInput };
|
||||
input.params.label_within = '1';
|
||||
input.params.required = '1';
|
||||
const [block] = formBodyToBlocks([input]);
|
||||
@@ -99,7 +99,7 @@ describe('Form Body To Blocks', () => {
|
||||
});
|
||||
|
||||
it('Should map last name input to block', () => {
|
||||
const [block] = formBodyToBlocks([{ ...lastNameInput, position: '1' }]);
|
||||
const [block] = formBodyToBlocks([lastNameInput]);
|
||||
checkBlockBasics(block);
|
||||
expect(block.clientId).to.be.include('last_name_');
|
||||
expect(block.name).to.be.equal('mailpoet-form/last-name-input');
|
||||
@@ -109,7 +109,7 @@ describe('Form Body To Blocks', () => {
|
||||
});
|
||||
|
||||
it('Should map last name with label within correctly', () => {
|
||||
const input = { ...lastNameInput, position: '1' };
|
||||
const input = { ...lastNameInput };
|
||||
input.params.label_within = '1';
|
||||
input.params.required = '1';
|
||||
const [block] = formBodyToBlocks([input]);
|
||||
@@ -118,7 +118,7 @@ describe('Form Body To Blocks', () => {
|
||||
});
|
||||
|
||||
it('Should map segments input to block', () => {
|
||||
const [block] = formBodyToBlocks([{ ...segmentsInput, position: '1' }]);
|
||||
const [block] = formBodyToBlocks([segmentsInput]);
|
||||
checkBlockBasics(block);
|
||||
expect(block.clientId).to.be.include('segments_');
|
||||
expect(block.name).to.be.equal('mailpoet-form/segment-select');
|
||||
@@ -130,7 +130,7 @@ describe('Form Body To Blocks', () => {
|
||||
});
|
||||
|
||||
it('Should map segments input without values to block', () => {
|
||||
const input = { ...segmentsInput, position: '1' };
|
||||
const input = { ...segmentsInput };
|
||||
input.params.values = undefined;
|
||||
const [block] = formBodyToBlocks([input]);
|
||||
checkBlockBasics(block);
|
||||
@@ -140,7 +140,7 @@ describe('Form Body To Blocks', () => {
|
||||
});
|
||||
|
||||
it('Should map submit button to block', () => {
|
||||
const [block] = formBodyToBlocks([{ ...submitInput, position: '1' }]);
|
||||
const [block] = formBodyToBlocks([submitInput]);
|
||||
checkBlockBasics(block);
|
||||
expect(block.clientId).to.be.include('submit_');
|
||||
expect(block.name).to.be.equal('mailpoet-form/submit-button');
|
||||
@@ -149,7 +149,7 @@ describe('Form Body To Blocks', () => {
|
||||
|
||||
it('Should map dividers to blocks', () => {
|
||||
const [block1, block2] = formBodyToBlocks([
|
||||
{ ...divider, position: '1' },
|
||||
{ ...divider },
|
||||
{ ...divider, position: '2' },
|
||||
]);
|
||||
checkBlockBasics(block1);
|
||||
@@ -162,7 +162,7 @@ describe('Form Body To Blocks', () => {
|
||||
|
||||
it('Should map custom html to blocks', () => {
|
||||
const [block1, block2] = formBodyToBlocks([
|
||||
{ ...customHtml, position: '1', params: { text: '123', nl2br: '1' } },
|
||||
{ ...customHtml, params: { text: '123', nl2br: '1' } },
|
||||
{ ...customHtml, position: '2', params: { text: 'nice one' } },
|
||||
]);
|
||||
checkBlockBasics(block1);
|
||||
@@ -191,7 +191,8 @@ describe('Form Body To Blocks', () => {
|
||||
updated_at: '2019-12-10T15:05:06+00:00',
|
||||
};
|
||||
const map = formBodyToBlocksFactory(colorDefinitions, [customField]);
|
||||
const [block] = map([{ ...customTextInput, position: '1' }]);
|
||||
const [block] = map([{ ...customTextInput }]);
|
||||
|
||||
checkBlockBasics(block);
|
||||
expect(block.clientId).to.be.include('1_');
|
||||
expect(block.name).to.be.equal('mailpoet-form/custom-text-customfieldname');
|
||||
@@ -219,7 +220,7 @@ describe('Form Body To Blocks', () => {
|
||||
updated_at: '2019-12-10T15:05:06+00:00',
|
||||
};
|
||||
const map = formBodyToBlocksFactory(colorDefinitions, [customField]);
|
||||
const [block] = map([{ ...customRadioInput, position: '1' }]);
|
||||
const [block] = map([{ ...customRadioInput}]);
|
||||
checkBlockBasics(block);
|
||||
expect(block.clientId).to.be.include('3_');
|
||||
expect(block.name).to.be.equal('mailpoet-form/custom-radio-name');
|
||||
@@ -249,7 +250,7 @@ describe('Form Body To Blocks', () => {
|
||||
position: null,
|
||||
};
|
||||
const map = formBodyToBlocksFactory(colorDefinitions, [customField]);
|
||||
const [block] = map([{ ...customCheckboxInput, position: '1' }]);
|
||||
const [block] = map([{ ...customCheckboxInput }]);
|
||||
checkBlockBasics(block);
|
||||
expect(block.clientId).to.be.include('4_');
|
||||
expect(block.name).to.be.equal('mailpoet-form/custom-checkbox-customcheck');
|
||||
@@ -278,7 +279,7 @@ describe('Form Body To Blocks', () => {
|
||||
position: null,
|
||||
};
|
||||
const map = formBodyToBlocksFactory(colorDefinitions, [customField]);
|
||||
const [block] = map([{ ...customSelectInput, position: '1' }]);
|
||||
const [block] = map([{ ...customSelectInput }]);
|
||||
checkBlockBasics(block);
|
||||
expect(block.clientId).to.be.include('5_');
|
||||
expect(block.name).to.be.equal('mailpoet-form/custom-select-customselect');
|
||||
@@ -304,7 +305,7 @@ describe('Form Body To Blocks', () => {
|
||||
updated_at: '2019-12-13T15:22:07+00:00',
|
||||
};
|
||||
const map = formBodyToBlocksFactory(colorDefinitions, [customField]);
|
||||
const [block] = map([{ ...customDateInput, position: '1' }]);
|
||||
const [block] = map([{ ...customDateInput }]);
|
||||
checkBlockBasics(block);
|
||||
expect(block.clientId).to.be.include('6_');
|
||||
expect(block.name).to.be.equal('mailpoet-form/custom-date-customdate');
|
||||
@@ -332,7 +333,7 @@ describe('Form Body To Blocks', () => {
|
||||
});
|
||||
|
||||
it('Should map nested columns', () => {
|
||||
const email = { ...emailInput, position: '1' };
|
||||
const email = { ...emailInput };
|
||||
const nested = { ...nestedColumns, position: '2' };
|
||||
const unknown = { id: 'unknown', position: '3' };
|
||||
const blocks = formBodyToBlocks([email, nested, unknown]);
|
||||
@@ -361,7 +362,7 @@ describe('Form Body To Blocks', () => {
|
||||
});
|
||||
|
||||
it('Should map columns colors', () => {
|
||||
const nested = { ...nestedColumns, position: '1' };
|
||||
const nested = { ...nestedColumns };
|
||||
nested.params = {
|
||||
text_color: '#ffffff',
|
||||
background_color: '#000000',
|
||||
@@ -384,7 +385,7 @@ describe('Form Body To Blocks', () => {
|
||||
});
|
||||
|
||||
it('Should map class name', () => {
|
||||
const nested = { ...nestedColumns, position: '1' };
|
||||
const nested = { ...nestedColumns };
|
||||
nested.params = {
|
||||
class_name: 'custom-class',
|
||||
};
|
||||
@@ -393,7 +394,7 @@ describe('Form Body To Blocks', () => {
|
||||
});
|
||||
|
||||
it('It should map heading', () => {
|
||||
const heading = { ...headingInput, position: '1' };
|
||||
const heading = { ...headingInput };
|
||||
|
||||
const [block] = formBodyToBlocks([heading]);
|
||||
expect(block.attributes.content).to.be.equal('');
|
||||
|
Reference in New Issue
Block a user