Skip to content

Commit

Permalink
fix: remove existing element in matrix when requeued (#810)
Browse files Browse the repository at this point in the history
Co-authored-by: Justin Shih <jushih@amazon.com>
  • Loading branch information
Jshhhh and Justin Shih authored Dec 1, 2022
1 parent 6df4d94 commit aa92f84
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
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

0 comments on commit aa92f84

Please sign in to comment.