-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename "initialState" to "state" in useStaticSetFilter and useTimeRan…
…geFilter (#19561) ## Summary & Motivation Renaming initialState to state since it better represents what the prop is, though even this is still a bit misleading. Let me explain: These filters were written in such a way to support being uncontrolled and controlled at the same time while allowing switching between uncontrolled and controlled. Basically the filter object returned by this hook has a property `state` which behaves like an uncontrolled component. Meaning whenever the user interacts with the UI, the UI will update accordingly and ignore the state prop you passed in, that means every time the user interacts the hook goes from controlled -> uncontrolled automatically. The one case where this could trip a developer up is in the case where the developer tries to ignore a state update by no-oping in `onStateChanged`(meaning they don't update their copy of the filter state). In that case since the state passed into the hook has not changed, the component will keep its uncontrolled copy of the state (which has diverged). To properly implement a full controlled instance of the hook you would need to create a copy of the old state (a new reference) and pass that in. Why allow both controlled and uncontrolled: Developer ergonomics, In the case where you don't need any fancy translation via the `onStateChanged` callback then you can just rely on the uncontrolled mode. [Here is an example of where we do that](https://github.com/dagster-io/dagster/blob/beff9f6147c68d10bdd49499eb28a64b7ba5d185/js_modules/dagster-ui/packages/ui-core/src/ui/Filters/useInstigationStatusFilter.tsx#L5) https://github.com/dagster-io/dagster/blob/beff9f6147c68d10bdd49499eb28a64b7ba5d185/js_modules/dagster-ui/packages/ui-core/src/overview/OverviewSchedulesRoot.tsx#L83 ## How I Tested These Changes Tested filtering on a few pages to make sure it still works, also jest tests.
- Loading branch information
Showing
7 changed files
with
50 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4a322c8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deploy preview for dagit-core-storybook ready!
✅ Preview
https://dagit-core-storybook-dlex3zmuk-elementl.vercel.app
Built with commit 4a322c8.
This pull request is being automatically deployed with vercel-action