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 select component edit form #60

Merged
merged 6 commits into from
Nov 24, 2023

Conversation

sergei-maertens
Copy link
Member

Closes #59

@sergei-maertens sergei-maertens force-pushed the feature/59-select-component branch 4 times, most recently from 17c9651 to 9f2ada3 Compare November 22, 2023 11:11
@sergei-maertens sergei-maertens marked this pull request as ready for review November 22, 2023 11:18
@Viicos
Copy link
Contributor

Viicos commented Nov 24, 2023

I am experiencing a weird behavior with datasource:

  • a * appears in the select when "From variable" is selected:
    image
  • It appears twice when "Manually fill in" is selected:
    image

useLayoutEffect(() => {
if (dataSrc !== 'variable' || isEqual(defaultValue, {})) return;
setFieldValue('defaultValue', '');
}, [dataSrc]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we watch for defaultValue as well?

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 don't think so, because the reset behaviour should only kick in when the dataSrc value changes.

If the dataSrc is set to manual and the user changes the default value in the dropdown, this effect would cause it to be reset to no default value which entirely beats the point of having a default value field :P

There is a bug here however - the comparison should be against '' instead of {} in the guard clause.

The idea is that whenever the user:

  • switch from variable -> manual: nothing to do, since it's not possible to set a default value for 'variable' dataSrc
  • switch from manual -> variable: if a default value was set, clear it, since we don't know which values will exist (they come from itemsExpression). if no default value was set -> nothing to do/reset

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This made me realize that the multiple behaviour was also not incorporated - which is not relevant for selectboxes or radio, so I've included that in my latest commit.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But what about ESLint in this case? As you said it requires every variable used to be watched?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, this would be one case where you silence the ESLint warning - complying with the ESLint rule would lead to incorrect behaviour in this case.

It's not a perfect linter rule, unfortunately. The goal of React was also to figure out the dependencies at compile time, but they can't do so reliably (yet) because of usages like this.

We have another case like this in the SDK, where progress indicator on mobile should collapse on navigate: https://github.com/open-formulieren/open-forms-sdk/blob/8117bacd777d785b197703cc9948bce9c9e004fc/src/components/ProgressIndicator/index.js#L30

Letting the hook run when expanded changes there basically prevents you from ever opening the progress indicator. Sometimes a certain state should deliberately be excluded from the hook triggers.

@sergei-maertens
Copy link
Member Author

sergei-maertens commented Nov 24, 2023

I am experiencing a weird behavior with datasource:

  • a * appears in the select when "From variable" is selected:
    image
  • It appears twice when "Manually fill in" is selected:
    image

It's a CSS issue with bootstrap/formio that applies a dumb z-index to the required indicator of the field below (either values table or itemsexpression). I don't know if this issue is also present in our own admin since we've done a lot of CSS fixes like that there already 🤔

Tracking this in #67

Mostly copy and paste from radio component, with the changes for
data.values rather than the values key in the root.
The hasOwnProperty could not deal with dotted paths, which caused
stale data to be present. This in turn triggered validation errors,
preventing the edit model from being submittable.
* Added documentation on utility function
* Fixed equality check on defaultValue reset

The equality check made me realize that the component supports multiple,
so the empty value depends on how the component is configured. It is
either string or string[], so the empty values are empty string or
empty array.
@sergei-maertens sergei-maertens force-pushed the feature/59-select-component branch from 4f72764 to 04affe5 Compare November 24, 2023 11:18
@sergei-maertens sergei-maertens merged commit 63010fb into main Nov 24, 2023
8 checks passed
@sergei-maertens sergei-maertens deleted the feature/59-select-component branch November 24, 2023 11:40
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 the select component in the builder
2 participants