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(grapher): better handling of query params #4248

Merged
merged 8 commits into from
Dec 5, 2024

Conversation

marcelgerber
Copy link
Member

@marcelgerber marcelgerber commented Dec 3, 2024

The way we were handling grapher query params was subpar at best - including that some of the types were not an accurate reflection of the properties that can actually be set, and so on.

d2da674 's commit message explains the changes made to the GrapherQueryParams type, for example.
There were also some corners where we had less type-safety than we can have.

grapherConfigToQueryParams is not used yet, but I'll need it down the road for narrative views. It takes a (partial) chart config and converts it into the query params fitting to achieve this grapher state.

Copy link
Member Author

marcelgerber commented Dec 3, 2024

@owidbot
Copy link
Contributor

owidbot commented Dec 3, 2024

Quick links (staging server):

Site Dev Site Preview Admin Wizard Docs

Login: ssh owid@staging-site-grapher-query-params

SVG tester:

Number of differences (default views): 0 ✅
Number of differences (all views): 0 ✅

Edited: 2024-12-03 16:27:16 UTC
Execution time: 1.39 seconds

@marcelgerber marcelgerber changed the title refactor: remove grapher query params that are not used refactor(grapher): better handling of query params Dec 4, 2024
@marcelgerber marcelgerber marked this pull request as ready for review December 4, 2024 13:41
Copy link
Member

@sophiamersmann sophiamersmann 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! 🙌🏻

).queryStr
tab: "chart",
country: generateSelectedEntityNamesParam(entities),
} satisfies GrapherQueryParams).queryStr
Copy link
Member

Choose a reason for hiding this comment

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

I had to read up on satisfies (again!). Beautiful to see it in action :)

Copy link
Member Author

Choose a reason for hiding this comment

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

It's also my first use of it 🎉

In this case, it's just a way to ensure that the object actually matches that type, and to do that inline. The alternative would be to use as, but that just blindly casts it to that type and only checks the rough shape, not that it actually only specifies known properties.

So, yeah, a nice and useful addition to TS :)

Base automatically changed from narrative-views-admin to master December 5, 2024 16:01
@marcelgerber marcelgerber merged commit 6549fdf into master Dec 5, 2024
16 of 19 checks passed
@marcelgerber marcelgerber deleted the grapher-query-params branch December 5, 2024 16:07
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