Skip to content

Commit

Permalink
chore: merge from main (#742)
Browse files Browse the repository at this point in the history
* fix: refresh stale data on update form

* fix: fix forms test from main

Co-authored-by: Scott Young <scoyou@amazon.com>
Co-authored-by: Justin Shih <jushih@amazon.com>
  • Loading branch information
3 people authored and hein-j committed Nov 3, 2022
1 parent db310d7 commit 45a2e81
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3996,8 +3996,9 @@ export default function MyFlexUpdateForm(props) {
modelFields = onSubmit(modelFields);
}
try {
const original = await DataStore.query(Flex0, id);
await DataStore.save(
Flex0.copyOf(flexRecord, (updated) => {
Flex0.copyOf(original, (updated) => {
Object.assign(updated, modelFields);
})
);
Expand Down
2 changes: 1 addition & 1 deletion packages/codegen-ui-react/lib/amplify-ui-renderers/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export default class FormRenderer extends ReactComponentRenderer<BaseComponentPr
factory.createTryStatement(
factory.createBlock(
[
...buildDataStoreExpression(formActionType, dataTypeName, importedModelName),
...buildDataStoreExpression(formActionType, importedModelName),
// call onSuccess hook if it exists
factory.createIfStatement(
factory.createIdentifier('onSuccess'),
Expand Down
8 changes: 2 additions & 6 deletions packages/codegen-ui-react/lib/forms/form-renderer-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,11 +546,7 @@ export const buildOnChangeStatement = (
);
};

export const buildDataStoreExpression = (
dataStoreActionType: 'update' | 'create',
dataTypeName: string,
importedModelName: string,
) => {
export const buildDataStoreExpression = (dataStoreActionType: 'update' | 'create', importedModelName: string) => {
if (dataStoreActionType === 'update') {
return [
factory.createVariableStatement(
Expand All @@ -568,7 +564,7 @@ export const buildDataStoreExpression = (
factory.createIdentifier('query'),
),
undefined,
[factory.createIdentifier(modelName), factory.createIdentifier('id')],
[factory.createIdentifier(importedModelName), factory.createIdentifier('id')],
),
),
),
Expand Down

0 comments on commit 45a2e81

Please sign in to comment.