-
Notifications
You must be signed in to change notification settings - Fork 2
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(de form): add field rules #363
Conversation
✅ Deploy Preview for dhis2-maintenance-app-beta ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
23555fc
to
c518123
Compare
I see what you mean, but I do think there can be some value in having zod. The field-level rules could even just refer to those fields - so every validation of a form is co-located. We might also not need field-level validations, if the form-level is run regardless? |
266ecd0
to
aa62a70
Compare
ac4865f
to
d1091ae
Compare
7af7b59
to
911879e
Compare
We've decided to remove validation / require-checks from the zod schema and move that to the field level. |
561fa30
to
a3195b4
Compare
2236b04
to
48ad7ae
Compare
@Birkbjo nice finds! I've implement all change requests! |
🎉 This PR is included in version 1.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This is a draft PR as I want to discuss moving validation from the form-level to the field-level (see last paragraph below).
The old app uses a configuration to define the rules. I tried to follow a similar approach but aligned with how React works and realized that it adds a lot of complexity:
domainType === 'TRACKER'
.Instead, I've co-located everything with the actual field, which makes it somewhat simple because everything related to a particular field is in one place only. It doesn't require too much state (e.g., whether the category combo is disabled or not is simply
values.domainType === 'TRACKER'
). This approach won't yield a list of rules, which requires us to document which rules exist. I've done that in comments above the fields that have rules infields.tsx
.I'm tempted to remove Zod and move validation to the field level. This will further untangle/simplify the architecture as field-level validator functions will be co-located with the fields in the code. The biggest advantage that Zod provides is that we don't have to duplicate types, but this doesn't apply to us as we already have generated types. Having the validators on the field level allows us to have very simple validation functions where necessary (see the new
validateCategoryCombo
function infields.tsx
) which reduces cognitive overhead. With the current approach (with Zod), you'll have to remember the schema itself, where the schema is located (dateElementsSchema.ts
), how it's being applied (on RFF's<Form />
component), and where the form component is located (in the views). This will all be reduced toit's where the field is
(infields.tsx
).