Skip to content

Conversation

@manojVivek
Copy link
Contributor

@manojVivek manojVivek commented Jul 9, 2024

Why?

  • Eliminates the need for navigateTo arg to every hook
  • Eliminates application logic spill into the hook
  • Eliminates redundancy of default value assignment
  • Eliminates redux store dependency
  • Follows the useState like API structure with for generic type support

Includes:

  • Replicate existing hook's functionality
  • Support default values and in turn prevent URL polluting
  • Port non-query selector params
  • Remove the old hook and rename the new one to it

Future Work:

  • Port query selector params
  • Support for param config in the context

@manojVivek manojVivek requested a review from a team as a code owner July 9, 2024 06:28
@alwaysmeticulous
Copy link

alwaysmeticulous bot commented Jul 9, 2024

🤖 Meticulous spotted visual differences in 3 of 494 screens tested: view and approve differences detected.

Last updated for commit 7a4f17a. This comment will update as new commits are pushed.

@manojVivek manojVivek changed the title ui: URL State hook revamp (WIP) ui: URL State hook revamp Jul 25, 2024
Comment on lines +147 to 150
const [groupBy, setStoreGroupBy] = useURLState<string[]>('group_by', {
defaultValue: [FIELD_FUNCTION_NAME],
alwaysReturnArray: true,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

what's the difference between setting a default value like this i.e. using the defaultValue prop,

Suggested change
const [groupBy, setStoreGroupBy] = useURLState<string[]>('group_by', {
defaultValue: [FIELD_FUNCTION_NAME],
alwaysReturnArray: true,
});
const [groupBy, setStoreGroupBy] = useURLState<string[]>('group_by', {
defaultValue: [FIELD_FUNCTION_NAME],
alwaysReturnArray: true,
});

and also doing it like the one a bit further in this file, like this:

Suggested change
const [groupBy, setStoreGroupBy] = useURLState<string[]>('group_by', {
defaultValue: [FIELD_FUNCTION_NAME],
alwaysReturnArray: true,
});
const [compareAbsolute = compareAbsoluteDefault, setCompareAbsolute] =
useURLState('compare_absolute');

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No technical difference, just an explicit way to set the default value right now.

But in the future, I'm thinking we should move away from this distributed (passing it while accessing the hook) default value usage to a more centralized usage by passing the default values in the URLStateProvider. So that the consuming hooks don't have to worry about the default state and also when a param is in the default state, we don't actually have to push it to the URL.
This will also help keep the URL to be a bit concise by only having non-default values.

Copy link
Contributor

@yomete yomete left a comment

Choose a reason for hiding this comment

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

lgtm! just one inquisitive question.

@manojVivek manojVivek merged commit c66dc86 into main Jul 29, 2024
@manojVivek manojVivek deleted the url-state-improvements branch July 29, 2024 05:48
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.

3 participants