Skip to content

Commit

Permalink
fix: fix datastore submit statement (#800)
Browse files Browse the repository at this point in the history
* fix: fix incorrect branch out

* chore: update snapshots

* chore: remove unused function
  • Loading branch information
zchenwei authored Nov 29, 2022
1 parent c25b427 commit f00cf16
Show file tree
Hide file tree
Showing 6 changed files with 246 additions and 333 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7158,6 +7158,7 @@ export default function SchoolUpdateForm(props) {
modelFields = onSubmit(modelFields);
}
try {
const promises = [];
const studentsToLink = [];
const studentsToUnLink = [];
const studentsSet = new Set();
Expand All @@ -7174,7 +7175,6 @@ export default function SchoolUpdateForm(props) {
studentsToLink.push(r);
}
});
const promises = [];
studentsToUnLink.forEach((original) => {
promises.push(
DataStore.save(
Expand Down Expand Up @@ -7871,6 +7871,7 @@ function ArrayField({
lengthLimit,
getBadgeText,
}) {
const labelElement = <Text>{label}</Text>;
const { tokens } = useTheme();
const [selectedBadgeIndex, setSelectedBadgeIndex] = React.useState();
const [isEditing, setIsEditing] = React.useState();
Expand Down Expand Up @@ -7954,11 +7955,16 @@ function ArrayField({
</React.Fragment>
);
if (lengthLimit !== undefined && items.length >= lengthLimit && !isEditing) {
return arraySection;
return (
<React.Fragment>
{labelElement}
{arraySection}
</React.Fragment>
);
}
return (
<React.Fragment>
<Text>{label}</Text>
{labelElement}
{isEditing && children}
{!isEditing ? (
<>
Expand Down Expand Up @@ -8140,6 +8146,7 @@ export default function TagUpdateForm(props) {
modelFields = onSubmit(modelFields);
}
try {
const promises = [];
const postsToLinkMap = new Map();
const postsToUnLinkMap = new Map();
const postsMap = new Map();
Expand Down Expand Up @@ -8176,7 +8183,6 @@ export default function TagUpdateForm(props) {
postsToLinkMap.set(id, count);
}
});
const promises = [];
postsToUnLinkMap.forEach(async (count, id) => {
const tagPostRecords = await DataStore.query(TagPost, (r) =>
r.and((r) => [r.postID.eq(id), r.tagID.eq(tagRecord.id)])
Expand Down Expand Up @@ -8264,9 +8270,10 @@ export default function TagUpdateForm(props) {
items={Posts}
hasError={errors.Posts?.hasError}
getBadgeText={getDisplayValue.Posts}
setFieldValue={(model) =>
setCurrentPostsDisplayValue(getDisplayValue.Posts(model))
}
setFieldValue={(model) => {
setCurrentPostsDisplayValue(getDisplayValue.Posts(model));
setCurrentPostsValue(model);
}}
inputFieldRef={PostsRef}
defaultFieldValue={\\"\\"}
>
Expand Down
5 changes: 2 additions & 3 deletions packages/codegen-ui-react/lib/amplify-ui-renderers/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { ReactComponentRenderer } from '../react-component-renderer';
import { buildLayoutProperties, buildOpeningElementProperties } from '../react-component-render-helper';
import { ImportCollection, ImportSource } from '../imports';
import { buildDataStoreExpression } from '../forms';
import { onSubmitValidationRun, buildModelFieldObject, getHasManyFieldConfigs } from '../forms/form-renderer-helper';
import { onSubmitValidationRun, buildModelFieldObject } from '../forms/form-renderer-helper';
import { hasTokenReference } from '../utils/forms/layout-helpers';
import { resetFunctionCheck } from '../forms/form-renderer-helper/value-props';
import { isModelDataType } from '../forms/form-renderer-helper/render-checkers';
Expand Down Expand Up @@ -98,7 +98,6 @@ export default class FormRenderer extends ReactComponentRenderer<BaseComponentPr
if (!formMetadata) {
throw new Error(`Form Metadata is missing from form: ${this.component.name}`);
}
const hasManyFieldConfigs = getHasManyFieldConfigs(formMetadata.fieldConfigs);

const onSubmitIdentifier = factory.createIdentifier('onSubmit');

Expand Down Expand Up @@ -134,7 +133,7 @@ export default class FormRenderer extends ReactComponentRenderer<BaseComponentPr
factory.createTryStatement(
factory.createBlock(
[
...buildDataStoreExpression(formActionType, importedModelName, hasManyFieldConfigs),
...buildDataStoreExpression(formActionType, importedModelName, formMetadata.fieldConfigs),
// call onSuccess hook if it exists
factory.createIfStatement(
factory.createIdentifier('onSuccess'),
Expand Down
Loading

0 comments on commit f00cf16

Please sign in to comment.