Skip to content

Commit

Permalink
fix: coalesce missing record to empty array
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Logan committed Feb 22, 2024
1 parent 80413d4 commit 8298ab1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32764,11 +32764,11 @@ export default function UpdateCompositeDogForm(props) {
setLinkedCompositeToys(linkedCompositeToys);
const linkedCompositeVets = record
? await Promise.all(
(
await record?.CompositeVets?.toArray()
).map((r) => {
return r.compositeVet;
})
((record && (await record.CompositeVets?.toArray())) || []).map(
(r) => {
return r.compositeVet;
}
)
)
: [];
setLinkedCompositeVets(linkedCompositeVets);
Expand Down Expand Up @@ -33887,11 +33887,11 @@ export default function UpdateCPKTeacherForm(props) {
setCPKStudent(CPKStudentRecord);
const linkedCPKClasses = record
? await Promise.all(
(
await record?.CPKClasses?.toArray()
).map((r) => {
return r.cpkClass;
})
((record && (await record.CPKClasses?.toArray())) || []).map(
(r) => {
return r.cpkClass;
}
)
)
: [];
setLinkedCPKClasses(linkedCPKClasses);
Expand Down Expand Up @@ -37260,11 +37260,11 @@ export default function UpdateCompositeDogForm(props) {
setLinkedCompositeToys(linkedCompositeToys);
const linkedCompositeVets = record
? await Promise.all(
(
await record?.CompositeVets?.toArray()
).map((r) => {
return r.compositeVet;
})
((record && (await record.CompositeVets?.toArray())) || []).map(
(r) => {
return r.compositeVet;
}
)
)
: [];
setLinkedCompositeVets(linkedCompositeVets);
Expand Down Expand Up @@ -47889,9 +47889,7 @@ export default function TagUpdateForm(props) {
setTagRecord(record);
const linkedPosts = record
? await Promise.all(
(
await record?.Posts?.toArray()
).map((r) => {
((record && (await record.Posts?.toArray())) || []).map((r) => {
return r.post;
})
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ describe('amplify form renderer tests', () => {
expect(componentText).toContain('const postRecords = useDataStoreBinding({');

// check lazy load linked data
expect(componentText).toContain('await record?.Posts?.toArray()');
expect(componentText).toContain('((record && (await record.Posts?.toArray())) || []).map');

// check custom display value is set
expect(componentText).toContain('Posts: (r) => r?.title');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1231,20 +1231,28 @@ export const buildGetRelationshipModels = (
factory.createCallExpression(
factory.createPropertyAccessExpression(
factory.createParenthesizedExpression(
factory.createAwaitExpression(
factory.createCallExpression(
factory.createPropertyAccessChain(
factory.createPropertyAccessChain(
factory.createIdentifier('record'),
factory.createToken(SyntaxKind.QuestionDotToken),
factory.createIdentifier(fieldName),
factory.createBinaryExpression(
factory.createBinaryExpression(
factory.createIdentifier('record'),
factory.createToken(SyntaxKind.AmpersandAmpersandToken),
factory.createAwaitExpression(
factory.createCallChain(
factory.createPropertyAccessChain(
factory.createPropertyAccessExpression(
factory.createIdentifier('record'),
factory.createIdentifier(fieldName),
),
factory.createToken(SyntaxKind.QuestionDotToken),
factory.createIdentifier('toArray'),
),
undefined,
undefined,
[],
),
factory.createToken(SyntaxKind.QuestionDotToken),
factory.createIdentifier('toArray'),
),
undefined,
[],
),
factory.createToken(SyntaxKind.BarBarToken),
factory.createArrayLiteralExpression([], false),
),
),
factory.createIdentifier('map'),
Expand Down

0 comments on commit 8298ab1

Please sign in to comment.