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

ref(pageFilters): Constrict types on updateParams better #31073

Conversation

evanpurkhiser
Copy link
Member

This narrows the types on the updateParams function call to better reflect what is actually going on

  • The UrlParams type has been renamed to UpdateParams and PageFilterQuery, which better reflect how the parameters are transformed when being shuttled between query parameters and more structured 'state' objects.

    This is especially important when passing these parameters to the setPageFiltersStorage function which now specifically always wants the project parameters to be a string array.

  • Add a test case to cover the regression that occurred in 0bbbfab, where we could not call .map on a string, which typescript failed to catch since the types in the pageFilters actionCreators were too wide and in some cases incorrect.

    This test would have failed in 0bbbfab.

project: project?.map(String),
environment,
start: statsPeriod ? null : start instanceof Date ? getUtcDateString(start) : start,
end: statsPeriod ? null : end instanceof Date ? getUtcDateString(end) : end,
Copy link
Member

Choose a reason for hiding this comment

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

@evanpurkhiser We should probably check if the dates here are valid, the instanceof new Date("invalid date") will still pass here otherwise. UX wise, I'm not sure if it's best to discard invalid dates or throw an error. I'm in favour of throwing so that in case this happens we have visibility and can fix it.

Copy link
Member Author

Choose a reason for hiding this comment

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

We probably should check somewhere else if the dates are valid or not.

This code is a bit of a rats nest, before it wasn't even handling string-ification of date objects afaict.

For now I am OK with leaving this as it is, since it's at least a big improvement over how it worked before 😬

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense - I'm lacking context on some of these components and how they all work together in the greater deal of things, so I may say something dumb every now and then 😅 Def a nice improvement from before though 🙏🏼

This narrows the types on the updateParams function call to better
reflect what is actually going on

 - The UrlParams type has been renamed to  `UpdateParams` and
   `PageFilterQuery`, which better reflect how the parameters are
   transformed when being shuttled between query parameters and more
   structured 'state' objects.

   This is especially important when passing these parameters to the
   `setPageFiltersStorage` function which now specifically always wants
   the `project` parameters to be a string array.

 - Add a test case to cover the regression that occurred in 0bbbfab,
   where we could not call `.map` on a string, which typescript failed
   to catch since the types in the pageFilters actionCreators were too
   wide and in some cases incorrect.

   This test would have failed in 0bbbfab.
@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/ref-pagefilters-constrict-types-on-updateparams-better branch from 088f128 to 1bb3d6d Compare January 14, 2022 00:02
@evanpurkhiser evanpurkhiser merged commit 83b1f25 into master Jan 14, 2022
@evanpurkhiser evanpurkhiser deleted the evanpurkhiser/ref-pagefilters-constrict-types-on-updateparams-better branch January 14, 2022 20:15
@github-actions github-actions bot locked and limited conversation to collaborators Jan 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants