-
Notifications
You must be signed in to change notification settings - Fork 133
Add full form data to array builder #34155
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
Changes from 3 commits
b934892
7deeb22
bd93162
d842102
7ea75bc
1c89f1b
66a589e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -261,6 +261,7 @@ export function updateSchemaFromUiSchema( | |
formData, | ||
index = null, | ||
path = [], | ||
fullData, | ||
) { | ||
if (!uiSchema) { | ||
return schema; | ||
|
@@ -277,6 +278,7 @@ export function updateSchemaFromUiSchema( | |
formData, | ||
index, | ||
path.concat(next), | ||
fullData || formData, | ||
); | ||
|
||
if (current.properties[next] !== nextProp) { | ||
|
@@ -303,6 +305,7 @@ export function updateSchemaFromUiSchema( | |
formData, | ||
idx, | ||
path.concat(idx), | ||
fullData || formData, | ||
), | ||
); | ||
|
||
|
@@ -324,6 +327,7 @@ export function updateSchemaFromUiSchema( | |
uiSchema, | ||
index, | ||
path, | ||
fullData || formData, | ||
); | ||
|
||
const newSchema = Object.keys(newSchemaProps).reduce((current, next) => { | ||
|
@@ -348,6 +352,7 @@ export function updateSchemaFromUiSchema( | |
uiSchema, | ||
index, | ||
path, | ||
fullData || formData, | ||
); | ||
|
||
if (newSchema !== currentSchema) { | ||
|
@@ -419,7 +424,7 @@ function mergeUiSchemasIfDifferent(uiSchema, newUiSchema) { | |
* @param {Object} formData - The form data to based uiSchema updates on | ||
* @returns {UISchemaOptions} The new uiSchema object | ||
*/ | ||
export function updateUiSchema(schema, uiSchema, formData) { | ||
export function updateUiSchema(schema, uiSchema, formData, fullData) { | ||
if (!uiSchema) { | ||
return uiSchema; | ||
} | ||
|
@@ -435,6 +440,7 @@ export function updateUiSchema(schema, uiSchema, formData) { | |
schema.properties[key], | ||
modifiedUiSchema[key], | ||
formData, | ||
fullData || formData, | ||
); | ||
|
||
if (modifiedUiSchema[key] !== nextProp) { | ||
|
@@ -463,7 +469,7 @@ export function updateUiSchema(schema, uiSchema, formData) { | |
return currentUiSchema; | ||
} | ||
|
||
const newProps = uiSchemaUpdater(formData); | ||
const newProps = uiSchemaUpdater(formData, fullData || formData); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what do you think of also giving this an index? the user would probably have to use window.location.pathname parsing to check if the index is the same, (since our data structure isn't multiple indecies for uiSchema), but maybe useful. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, looking at the function, where would I get access to the index? Other than the URL? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh, nevermind, it can come from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
return mergeUiSchemasIfDifferent(currentUiSchema, newProps); | ||
} | ||
|
||
|
@@ -614,6 +620,8 @@ export function updateSchemasAndData( | |
uiSchema, | ||
formData, | ||
preserveHiddenData = false, | ||
fullData, | ||
index, | ||
) { | ||
let newSchema = updateItemsSchema(schema, formData); | ||
newSchema = updateRequiredFields(newSchema, uiSchema, formData); | ||
|
@@ -622,8 +630,20 @@ export function updateSchemasAndData( | |
newSchema = setHiddenFields(newSchema, uiSchema, formData); | ||
|
||
// Update the uiSchema and schema with any general updates based on the new data | ||
const newUiSchema = updateUiSchema(newSchema, uiSchema, formData); | ||
newSchema = updateSchemaFromUiSchema(newSchema, newUiSchema, formData); | ||
const newUiSchema = updateUiSchema( | ||
newSchema, | ||
uiSchema, | ||
formData, | ||
fullData || formData, | ||
); | ||
newSchema = updateSchemaFromUiSchema( | ||
newSchema, | ||
newUiSchema, | ||
formData, | ||
index, | ||
[], // path | ||
fullData || formData, | ||
); | ||
|
||
if (!preserveHiddenData) { | ||
// Remove any data that’s now hidden in the schema | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can also get this data by using getFormData passed into CustomPage. Could just use that, or if still want to introduce this on its own, that seems OK too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot about that function. Is it documented somewhere? Either way, I was thinking it's more straight-forward to pass on the data directly; but I'm open to feedback.