Skip to content
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

Merged
merged 14 commits into from
Nov 20, 2023

Conversation

sergei-maertens
Copy link
Member

Closes #52

Ho boi this got a lot bigger than I expected...

} = useFormikContext<T>();
return (
<>
<ValuesSrc />
Copy link
Member Author

@sergei-maertens sergei-maertens Nov 15, 2023

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.

Copy link
Member Author

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 :(

@sergei-maertens sergei-maertens force-pushed the feature/52-selectboxes-component branch 2 times, most recently from 201c878 to eb8abbd Compare November 16, 2023 15:27
@sergei-maertens sergei-maertens force-pushed the feature/52-selectboxes-component branch 2 times, most recently from 7e522cd to d5a2697 Compare November 17, 2023 15:27
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.
@sergei-maertens sergei-maertens marked this pull request as ready for review November 17, 2023 15:27
src/components/formio/checkbox.tsx Show resolved Hide resolved
src/registry/selectboxes/helpers.ts Show resolved Hide resolved
src/registry/validation.ts Show resolved Hide resolved
@sergei-maertens sergei-maertens merged commit ce97a08 into main Nov 20, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement selectboxes component edit form
3 participants