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 types in CollectionPicker #40377

Merged
merged 41 commits into from
Mar 22, 2024
Merged

Conversation

kamilmielnik
Copy link
Contributor

@kamilmielnik kamilmielnik commented Mar 20, 2024

Needed for #40298

Description

EntityPicker contains a search component which has been build to support all types of models (see SearchModelType).
However - depending on the context - it will usually be used only with a subset of models, for example:

Up until now EntityPicker type declarations were tightly coupled with Collections.
This PR removes this coupling and makes the component generic so that we can have type safety in various context without type casting. It's mostly about moving files and extending the types, but I'm sneaking in a few small code changes as well.

Short summary of changes:

  • Moves all Collection-related things from metabase/common/components/EntityPicker to metabase/common/components/CollectionPicker
  • Makes almost everything in metabase/common/components/EntityPicker/ generic, so that it can be used in various contexts
  • Removes all casts except 1 in EntityPickerSearch and 1 in a unit test
  • Removes all anys
  • Unhookifies searchFilter function (it didn't have to be a hook)
  • Removes NestedItemPicker storybook page - it didn't work and was using an outdated interface of NestedItemPicker. Maybe it used to deserve a storybook page at the time of creation, but I don't think it does anymore as its UI part now lives in ItemList.

How to verify

  • CI is green
  • There are no type casts in metabase/common/components/CollectionPicker
  • The interface of CollectionPicker is Collections-specific

@kamilmielnik kamilmielnik added the no-backport Do not backport this PR to any branch label Mar 20, 2024
@kamilmielnik kamilmielnik marked this pull request as ready for review March 21, 2024 12:49
@@ -26,6 +24,12 @@ const canSelectItem = (item: CollectionPickerItem | null): boolean => {
return !!item && item?.can_write !== false;
};

const searchFilter = (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change is not type-related.

This function does not need to be a hook.

This reverts commit b762d0f.
Copy link

replay-io bot commented Mar 21, 2024

Status In Progress ↗︎ 51 / 52
Commit 9586424
Results
⚠️ 5 Flaky
2368 Passed

@kamilmielnik kamilmielnik requested review from npfitz, iethree and a team March 21, 2024 13:13
Copy link
Contributor

@iethree iethree left a comment

Choose a reason for hiding this comment

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

Very nice work 👏 Thanks! As you can see, we struggled a bit with the types 🥴

I think that the complexity of these types is actually a smell that the diversity of API responses we get for the same things from the backend could use some work. I'm hopeful that the openAPI docs the backend has recently put in, along with some of the code gen features of RTK Query can help us simplify this in the future.

@kamilmielnik kamilmielnik merged commit c6cd140 into master Mar 22, 2024
107 checks passed
@kamilmielnik kamilmielnik deleted the refactor/collection-picker branch March 22, 2024 06:53
Copy link
Contributor

@kamilmielnik Did you forget to add a milestone to the issue for this PR? When and where should I add a milestone?

@kamilmielnik kamilmielnik added this to the 0.50 milestone Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-backport Do not backport this PR to any branch .Team/Querying
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants