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(insight-variables): dashboard variables populating and updating urls #27843

Merged
merged 13 commits into from
Jan 30, 2025

Conversation

EDsCODE
Copy link
Member

@EDsCODE EDsCODE commented Jan 23, 2025

Problem

  • dashboard variables can't be overridden by links right now

Changes

  • parse url params for variable override

👉 Stay up-to-date with PostHog coding conventions for a smoother review.

Does this work well for both Cloud and self-hosted?

How did you test this code?

@EDsCODE EDsCODE marked this pull request as ready for review January 23, 2025 21:11
Copy link
Member

@Gilbert09 Gilbert09 left a comment

Choose a reason for hiding this comment

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

The major pushback here is the usage of query params - happy to chat further on this if need be

@@ -1479,6 +1490,51 @@ export const dashboardLogic = kea<dashboardLogicType>([
},
})),

subscriptions(({ values, actions }) => ({
variables: (variables) => {
Copy link
Member

Choose a reason for hiding this comment

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

Should this not be maybeUrlVariables? Or is this triggered from somewhere else?

Copy link
Member Author

Choose a reason for hiding this comment

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

this is sort of dicey basically maybeURLVariables needs to be set first on load and then when variables loads, it'll do a check the maybe variables to populate if possible (which is why this subscription is mounted on variables)

Comment on lines 1499 to 1504
for (const [key, value] of Object.entries(urlVariables)) {
const variable = variables.find((variable: HogQLVariable) => variable.code_name === key)
if (variable) {
overrideVariables.push({ ...variable, value })
}
}
Copy link
Member

Choose a reason for hiding this comment

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

So I'm not a fan of allowing users to set any query param and have our logic try to parse it as variables. In the future, we can't use dashboard query params for anything else in case of a conflict of insight variable names. Instead, I think we should have a single query param (something like query_variables) that is a key/value pair object instead - this makes it a lot more explicit.

The downside to this is that it's more effort on the end of building the URL when writing a HogQL query, but we can add the overrides as a parameter of the <a variableOverrides={...} /> component instead (long term, links are done via chart settings instead of in the query itself)

Copy link
Contributor

github-actions bot commented Jan 24, 2025

Size Change: +5 B (0%)

Total Size: 1.16 MB

ℹ️ View Unchanged
Filename Size Change
frontend/dist/toolbar.js 1.16 MB +5 B (0%)

compressed-size-action

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 1)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@EDsCODE EDsCODE requested a review from Gilbert09 January 27, 2025 22:09
Copy link
Member

@Gilbert09 Gilbert09 left a comment

Choose a reason for hiding this comment

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

Overall looks good, just a handful of nits - feel free to change them or leave them

frontend/src/scenes/dashboard/dashboardLogic.tsx Outdated Show resolved Hide resolved
frontend/src/scenes/dashboard/dashboardLogic.tsx Outdated Show resolved Hide resolved
frontend/src/scenes/dashboard/dashboardLogic.tsx Outdated Show resolved Hide resolved
frontend/src/scenes/dashboard/dashboardLogic.tsx Outdated Show resolved Hide resolved
frontend/src/scenes/dashboard/dashboardLogic.tsx Outdated Show resolved Hide resolved
@EDsCODE EDsCODE merged commit ee0c09b into master Jan 30, 2025
99 checks passed
@EDsCODE EDsCODE deleted the insight-variables-dashboard-urls branch January 30, 2025 04:12
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