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

refactor(modelSingleSelect): refactor modelSingleSelect to be more ergonomic #465

Merged
merged 14 commits into from
Dec 18, 2024

Conversation

Birkbjo
Copy link
Member

@Birkbjo Birkbjo commented Dec 10, 2024

Refactor ModelSingleSelect to be more ergonomic. The API of passing useOptions-hooks are not very ergonomic, and I'm pretty sure it violates the rule of hooks.

However, most importantly this will now preserve the Model. Previously we had to format and parse back and forth to the id. But I think it's very important that we have the ability to store complex objects in the form-store (as opposed to just the id) - because we have logic that need more information from other fields. All other forms than dataElements follow this idea.

This mostly follows the same composition as ModelTransfer:

  • BaseModelSingleSelect translates a Model (id and displayName) to be used with our SearchableSingleSelect.
    • SingleSelect accept a string as a value, and returns a string. However we want to "preserve" the full model. This component handles that.
  • ModelSingleSelect deals with fetching data. It takes a simple query and fetches an inifinite list with support for "search".
    • I've also added the ability to pass a PartialLoadedDisplayableModel. This makes it possible for this component to fetch the label if you just have access to "id" of the model. This is useful for our filters in the List (where we just have IDs in URL on first render) - and for eg. selected-models in the list.
      • This does add some complexity, and we could always handle this on a level above. However, I think it greatly simplifies usage of these components. The old ModelSingleSelect also had support for this.
  • ModelSingleSelectField is used to compose the selector with a final-form connected field. We mostly use selectors in forms, and this greatly reduces boilerplate for such fields.

Copy link

netlify bot commented Dec 10, 2024

Deploy Preview for dhis2-maintenance-app-beta ready!

Name Link
🔨 Latest commit 771eaa6
🔍 Latest deploy log https://app.netlify.com/sites/dhis2-maintenance-app-beta/deploys/6761a09b0a06eb000763db6a
😎 Deploy Preview https://deploy-preview-465.maintenance-app-beta.netlify.dhis2.org
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@Birkbjo Birkbjo requested a review from tomzemp December 13, 2024 13:29
@flaminic flaminic merged commit ee5314d into master Dec 18, 2024
11 checks passed
@flaminic flaminic deleted the refactor-model-single-select branch December 18, 2024 12:33
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.

2 participants