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

feat(web-analytics): Sync web analytics state with url #19400

Merged
merged 2 commits into from
Dec 19, 2023

Conversation

robbie-c
Copy link
Member

@robbie-c robbie-c commented Dec 18, 2023

Problem

Some feedback asking a few related things:

  • Want to preserve filters across a refresh
  • Want to bookmark certain filters

An example zendesk ticket: https://posthoghelp.zendesk.com/agent/tickets/8277

Changes

Store relevant parts of the state in the url.

How did you test this code?

Manually, spending a lot of time making sure that the back button behaviour is correct. A few edge cases:

  • clicking on the device type pie chart changes filters AND changes the tab, and the back button should revert both
  • using the back button to remove the last filters should work, even though no filters are in the url bar

Copy link
Contributor

github-actions bot commented Dec 18, 2023

Size Change: 0 B

Total Size: 1.99 MB

ℹ️ View Unchanged
Filename Size
frontend/dist/toolbar.js 1.99 MB

compressed-size-action

@robbie-c robbie-c changed the title Sync web analytics state with url feat(web-analytics): Sync web analytics state with url Dec 18, 2023
@robbie-c robbie-c requested a review from mariusandra December 18, 2023 23:54
@robbie-c robbie-c marked this pull request as ready for review December 18, 2023 23:54
Copy link
Collaborator

@mariusandra mariusandra left a comment

Choose a reason for hiding this comment

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

👍

Comment on lines +890 to +900
actionToUrl(({ values }) => ({
setWebAnalyticsFilters: () => stateToUrl(values),
togglePropertyFilter: () => stateToUrl(values),
setDates: () => stateToUrl(values),
setInterval: () => stateToUrl(values),
setDeviceTab: () => stateToUrl(values),
setSourceTab: () => stateToUrl(values),
setGraphsTab: () => stateToUrl(values),
setPathTab: () => stateToUrl(values),
setGeographyTab: () => stateToUrl(values),
})),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here's a patter you can use if you want to clean this up a bit, yet keep the url logic contained:

Suggested change
actionToUrl(({ values }) => ({
setWebAnalyticsFilters: () => stateToUrl(values),
togglePropertyFilter: () => stateToUrl(values),
setDates: () => stateToUrl(values),
setInterval: () => stateToUrl(values),
setDeviceTab: () => stateToUrl(values),
setSourceTab: () => stateToUrl(values),
setGraphsTab: () => stateToUrl(values),
setPathTab: () => stateToUrl(values),
setGeographyTab: () => stateToUrl(values),
})),
actionToUrl(({ values }) => {
function stateToUrl() {
const urlParams = new URLSearchParams()
// ...
}
return {
setWebAnalyticsFilters: stateToUrl,
togglePropertyFilter: stateToUrl,
setDates: stateToUrl,
setInterval: stateToUrl,
setDeviceTab: stateToUrl,
setSourceTab: stateToUrl,
setGraphsTab: stateToUrl,
setPathTab: stateToUrl,
setGeographyTab: stateToUrl,
}
})),

This is just a nit at this point, definitely not blocking.

@robbie-c robbie-c merged commit 5cd4088 into master Dec 19, 2023
83 of 84 checks passed
@robbie-c robbie-c deleted the add-web-analytics-state-to-url branch December 19, 2023 10:28
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.

2 participants