feat: resources add and edit form - #1037
Chisomchima wants to merge 6 commits into
Conversation
Shared building blocks for the resources add/edit forms: field components, resource schema, and validation logic.
Wire up the New and Edit routes for resources using the shared form fields, schema, and validation.
Cover form rendering, validation, and submission for the New and Edit resource pages.
✅ Deploy Preview for dhis2-maintenance-app-beta ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
… gating The edit form now lets a URL resource be switched to a file upload (and vice versa), matching the field set and payload shape used by the New form. Both forms now share one ResourceFormFields component and a single useOnSubmitResource hook/schema instead of near-duplicate New/Edit copies. Also fixes a bug where clicking a list row navigated to the edit page for file resources even though the row actions menu correctly hid "Edit" for them - row-click now respects the same isResourceEditable check via a new isRowClickable prop on DefaultSectionList/SectionListWrapper.
…edit-form # Conflicts: # i18n/en.pot
tomzemp
left a comment
There was a problem hiding this comment.
Looks good @Chisomchima! 🎉
Something I noticed that I think should be addressed:
- "Save" and "Save and close" both perform the same here (they both save and close). I think it might actually be preferable to only have "Save and close" here? (We could allow "Save" and "Save and close" while editing URLs, but if we have both "Save" and "Save and close" on the new page, the "Save" button for a file resource would have to perform like "Save and close", so maybe just having "Save and close" throughout is easiest)
Other things that I noticed (that don't need to be changed now):
[I think we could ask product/design for input on these]
- backend rejects certain file types (e.g. it doesn't accept 'html' files), but we allow you to upload them and then get that message (this also happens in the old app). I guess an improvement would be to figure out what file types the backend will take and explain that in the UI / restrict the file uploader
- I understand that file resources are not editable, but this is a bit non-intuitive from the list view. It might be better to have a disabled edit button for file resources to indicate that something hasn't just gone wrong? Or maybe we want to map the external boolean to "url/file resource" in the list so the distinction is clearer
(Also see a couple of comments)
| message: i18n.t('A URL is required'), | ||
| path: ['url'], | ||
| }) | ||
| } else if (!z.string().url().safeParse(values.url).success) { |
There was a problem hiding this comment.
we have our own final-form url validator (https://github.com/dhis2/ui/blob/master/collections/forms/src/validators/url.js), but maybe we just want to use this one. I don't know if there's some difference between the parsing
| dataEngine: ReturnType<typeof useDataEngine>, | ||
| values: ResourceSubmitValues | ||
| ) => ({ | ||
| name: values.name, |
There was a problem hiding this comment.
do you need trim values here? It looks like trailing whitespaces are not being removed
Trim name/code before saving a resource, matching the trimming other model forms already get via trimTrimmableFields. Also drop the plain "Save" button on the resources New/Edit forms since it behaved identically to "Save and close" there, which was confusing.
|



implements https://dhis2.atlassian.net/browse/DHIS2-22044