-
Notifications
You must be signed in to change notification settings - Fork 1
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
Implement the builder form for the selectboxes component #53
Conversation
3b8668c
to
fee85ae
Compare
} = useFormikContext<T>(); | ||
return ( | ||
<> | ||
<ValuesSrc /> |
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.
best would be to pass an onChange
here so that we can reset the appropriate field.
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 tried that and it leads to race conditions, so I'm now using useLayoutEffect
instead.
There might be an option to use React 18's flushSync
instead, but the builder & backend are still stuck on React 17 currently :(
6184b95
to
e1f380d
Compare
201c878
to
eb8abbd
Compare
7e522cd
to
d5a2697
Compare
This component is to be used in the builder preview pane and to set the defaultValue for the SelectBoxes inside the builder edit form.
This was originally planned to use for the itemsExpression in the selectboxes component, but turned out to not be easy to manage to validate for valid JSON and eventually replaced with the already existing (courtesy of Laurens) JSONEdit component. Since we need to eventually implement the TextArea builder component anyway, it will be of good use later and was decided to keep it.
The ArrayField helper that is included in Formik can cause the errors array to contain 'undefined' when re-ordering items. This is unfortunately something outside of our control so it's best to just ignore this situation - knowing where it comes from lets me sleep at night.
This was an (unsuccesful) attempt to make userEvent.click(submitButton) actually submit the form(s) on Firefox, but it is bugged in testing library itself, see: testing-library/user-event#1075
Rather than setting the entire form field values state, it now allows setting a particular field value. This is required for the itemsExpression field in SelectBoxes component.
The filenames have been updated for consistency with other module names and the stories are now grouped under a folder 'values' since there will be more functionality added to values.
The selected mode determines the related inputs to configure the available options for a field with options.
Implemented as a minimal textarea which accepts (and sort-of validates) JSON input, this field will be used to enter the JsonLogic expression when values are to be retrieved dynamically from a variable.
The component manages the (form) state depending on the selected data source for field options/values and renders the appropriate dependent input: * manual -> use the values table so users can enter their options * variable -> use the JSON edit component to set the expression Additionally, it makes sure to clear the state of the 'other' field when a particular data source is selected, as the data model is essentially a discriminated union, which is then processed by the backend.
When manual values are available, they are rendered as is and their default value is taken into account. When the variable data source is specified, a single option is rendered to at least inform the form builder of the expression being used. In the future, we can possibly provide a 'variable' box so that they can try out the preview with a realistic form variable state.
The selectboxes now allows specifying the values, either manually or through an items expression. The labels of options can be translated on the translations tab.
When specifying values manually, the form builder enforces accessible practices in the value/label of each option. There are some limitations in the flexibility with zod validation unions and deep discriminators, but the UI currently prevents ending up in those edge case.
d5a2697
to
4809d36
Compare
Closes #52
Ho boi this got a lot bigger than I expected...