Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove existing element in matrix when requeued #810

Merged
merged 1 commit into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -344,13 +344,41 @@ it('should requeue if related element is not yet found', () => {
},
sectionalElements: {
Heading123: { type: 'Heading', position: { fixed: 'first' }, level: 1, text: 'Create Dog' },
Heading456: { type: 'Heading', position: { below: 'color' }, level: 1, text: 'Dog Created' },
},

style: {},
cta: {},
},
dataSchema: {
dataSourceType: 'DataStore',
models: {
Event: {
fields: {
name: {
dataType: 'String',
required: false,
readOnly: false,
isArray: false,
},
age: {
dataType: 'String',
required: false,
readOnly: false,
isArray: false,
},
},
},
},
enums: {},
nonModels: {},
},
});
expect(formDefinition.elementMatrix).toStrictEqual([['Heading123'], ['name', 'age', 'weight'], ['color']]);
expect(formDefinition.elementMatrix).toStrictEqual([
['Heading123'],
['name', 'age', 'weight'],
['color'],
['Heading456'],
]);
});

it('should handle fields without position', () => {
Expand All @@ -370,7 +398,6 @@ it('should handle fields without position', () => {
sectionalElements: {
Heading123: { type: 'Heading', position: { fixed: 'first' }, level: 1, text: 'Create Dog' },
},

style: {},
cta: {},
},
Expand All @@ -387,7 +414,6 @@ it('should fill out styles using defaults', () => {
dataType: { dataSourceType: 'Custom', dataTypeName: 'dfkjad' },
fields: {},
sectionalElements: {},

style: {},
cta: {},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ export function mapElementMatrix({
tempRightOf.push(element);
} else if (typeof element.position === 'object' && 'below' in element.position && element.position.below) {
const relationIndices = findIndices(element.position.below, formDefinition.elementMatrix);
const previousIndices = findIndices(element.name, formDefinition.elementMatrix);
if (previousIndices) {
removeFromMatrix(previousIndices, formDefinition);
}
if (!relationIndices) {
requeued.push(element);
} else {
const previousIndices = findIndices(element.name, formDefinition.elementMatrix);
if (previousIndices) {
removeFromMatrix(previousIndices, formDefinition);
}
formDefinition.elementMatrix.splice(relationIndices[0] + 1, 0, [element.name]);
}
} else if (
Expand Down