-
Notifications
You must be signed in to change notification settings - Fork 34
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
feat: add option to allow overwriting state values from query param population #1260
Conversation
… option to be set
designer/client/field-edit.tsx
Outdated
@@ -26,6 +26,7 @@ export function FieldEdit({ | |||
required = true, | |||
exposeToContext = false, | |||
allowPrePopulation = false, | |||
allowOverwriteFromQueryParam = false, |
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.
maybe allowPrePopulationOverwrite
so the flag looks more related to allowPrePopulation
?
const schemaMapping = Object.entries(schema)[0]; | ||
return { | ||
[schemaMapping[0]]: { | ||
schema: schemaMapping[1], | ||
allowOverwriteFromQueryParam: | ||
item.options.allowOverwriteFromQueryParam, | ||
}, | ||
}; | ||
}) |
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.
The array indexing makes it hard to follow
const schemaMapping = Object.entries(schema)[0]; | |
return { | |
[schemaMapping[0]]: { | |
schema: schemaMapping[1], | |
allowOverwriteFromQueryParam: | |
item.options.allowOverwriteFromQueryParam, | |
}, | |
}; | |
}) | |
return { | |
[item.name]: { | |
schema: schema[item.name], | |
allowOverwriteFromQueryParam: | |
item.options.allowOverwriteFromQueryParam, | |
}, | |
}; | |
}) |
alternatively, you can use destructuring to give schemaMapping[0,1] more meaningful names, but Object.entries(schema)[0];
still looks a bit odd imo
const schemaMapping = Object.entries(schema)[0]; | |
return { | |
[schemaMapping[0]]: { | |
schema: schemaMapping[1], | |
allowOverwriteFromQueryParam: | |
item.options.allowOverwriteFromQueryParam, | |
}, | |
}; | |
}) | |
const [key, joiSchema] = Object.entries(schema)[0]; | |
return { | |
[key]: { | |
schema: joiSchema, | |
allowOverwriteFromQueryParam: | |
item.options.allowOverwriteFromQueryParam, | |
}, | |
}; | |
}) |
Description
In some cases it might be necessary to allow query parameters to overwrite present state values. For example, if there is an unreachable field in your form that should be pre-populated from a query parameter, and there is a chance the user may change their selection prior to entering the service that changes the value of that unreachable field, the query parameter should overwrite this value as there is no other way for the user to change their selection.
To solve this, an option
allowOverwriteFromQueryParam
has been added. This option will only have an effect if the component has already been given theallowPrePopulation
flag.allowOverwriteFromQueryParam
flagType of change
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce
the testing if necessary.
allowOverwiteFromQueryParam
flagChecklist: