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 with dashboard filters #24745

Merged
merged 26 commits into from
Sep 12, 2024

Conversation

anirudhpillai
Copy link
Contributor

@anirudhpillai anirudhpillai commented Sep 2, 2024

Problem

Fixes #22939
Later want to enhance this so that when 'previewing' a filter change on dashboard, you can still click into the insight and view the temporary filters.

Changes

When clicking into an insight from dashboard, the insight view loads with the filters from the dashboard.
Works by putting the filters override as query params in the URL.

Screen.Recording.2024-09-02.at.13.53.05.mov

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

N/A

How did you test this code?

WIP

@anirudhpillai anirudhpillai requested a review from a team September 2, 2024 12:55
Copy link
Contributor

github-actions bot commented Sep 2, 2024

Size Change: +2.51 kB (+0.23%)

Total Size: 1.1 MB

Filename Size Change
frontend/dist/toolbar.js 1.1 MB +2.51 kB (+0.23%)

compressed-size-action

@anirudhpillai anirudhpillai force-pushed the feat/insight-with-dashboard-filters branch from 4b9522e to df2f5f9 Compare September 3, 2024 19:25
Copy link
Contributor

@skoob13 skoob13 left a comment

Choose a reason for hiding this comment

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

Kudos for e2e tests! Generally LGTM. There is one thing though: when I click the insight's name and go to the insight view, dashboard filters apply as expected. However, if I go to the insight by clicking on options (three dots), the dashboard filters don't apply. See the GIF.

2024-09-04 12 03 39

@@ -90,7 +90,8 @@ export const urls = {
}
).url,
insightEdit: (id: InsightShortId): string => `/insights/${id}/edit`,
insightView: (id: InsightShortId): string => `/insights/${id}`,
insightView: (id: InsightShortId, filtersOverride?: DashboardFilter): string =>
`/insights/${id}${filtersOverride !== undefined ? `?filters_override=${JSON.stringify(filtersOverride)}` : ''}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you need to encode the filters_override to add escaping. You can use either encodeURIComponent or the URLSearchParams class.

@@ -5607,6 +5607,7 @@ class QueryRequest(BaseModel):
discriminator="kind",
)
refresh: Optional[Union[bool, str]] = None
filters_override: Optional[DashboardFilter] = None
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you manually modify the schema.py file? It's autogenerated, so you need to update schema.ts in order to change it. Then, build a new schema with pnpm schema:build. It will generate new schema.json and schema.py files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

aah amazing thanks for pointing these out! Was just wondering why they get removed on the CI

@anirudhpillai anirudhpillai force-pushed the feat/insight-with-dashboard-filters branch from df2f5f9 to e64b83d Compare September 4, 2024 12:13
@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

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

  • chromium: 0 added, 10 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.

@anirudhpillai anirudhpillai force-pushed the feat/insight-with-dashboard-filters branch from 7e1858c to 1ce8a37 Compare September 4, 2024 19:10
@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

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

  • chromium: 0 added, 10 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.

@anirudhpillai anirudhpillai force-pushed the feat/insight-with-dashboard-filters branch from 863c389 to 1986fff Compare September 4, 2024 21:10
@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

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

  • chromium: 0 added, 10 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.

@anirudhpillai anirudhpillai force-pushed the feat/insight-with-dashboard-filters branch from 5164a38 to 1ebe217 Compare September 5, 2024 10:51
.github/workflows/storybook-chromatic.yml Outdated Show resolved Hide resolved
@@ -1149,6 +1149,7 @@ export interface QueryRequest {
* see the [PostHog HogQL documentation](/docs/hogql#api-access).
*/
query: QuerySchema
filters_override?: DashboardFilter
Copy link
Member

Choose a reason for hiding this comment

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

This is not actually an override, since it adds to the existing filters, not replace. How about literally dashboard_filters?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I change this just for /query endpoint?
As for /insight we already have logic to read filters_override passed down from the /dashboard endpoint here, seems a bit unnecessary to read both filters_override for dashboard filters and dashboard_filters when loading an insight.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

another option is to rename all of it to dashboard_filters_override or something, can address that in a separate PR as this will become a lot bigger then :)

Copy link
Member

Choose a reason for hiding this comment

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

Oh, didn't see the pre-existing filters_override, in that case does seem simplest to just reuse that

Comment on lines +20 to +27
<div
className={clsx(
'flex gap-2 items-center justify-between flex-wrap border',
dashboardMode === DashboardMode.Edit
? '-m-1.5 p-1.5 border-border-bold border-dashed rounded-lg'
: 'border-transparent'
)}
>
Copy link
Member

Choose a reason for hiding this comment

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

Just making sure since we removed this previously: is this addition of the outline intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is for the scenario when user changes filters then clicks into an insight and then navigates back to the dashboard.
At this stage the dashboard is in edit mode, but want to highlight the dates/filters so the user knows what's changed in edit mode if they hit save

image

if data.filters_override is not None:
data.query = apply_dashboard_filters_to_dict(
data.query.model_dump(), data.filters_override.model_dump(), self.team
) # type: ignore
Copy link
Member

Choose a reason for hiding this comment

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

cast() would better signal intentions than ignore

Copy link
Contributor Author

@anirudhpillai anirudhpillai Sep 10, 2024

Choose a reason for hiding this comment

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

might be missing a simple way to do this but
the below doesn't work as data.query has to be one of
image
and the generated schema.py pulls all of the types as a Union here

data.query = cast(
                QuerySchemaRoot,
                apply_dashboard_filters_to_dict(data.query.model_dump(), data.filters_override.model_dump(), self.team),
            )

Would be great if there was a way to cast it as below

data.query = cast(
                QueryRequest["query"],
                apply_dashboard_filters_to_dict(data.query.model_dump(), data.filters_override.model_dump(), self.team),
            )

Felt the type: ignore was cleaner than pulling the full union which might go out sync, but ideally will be great if there's a way around this

Copy link
Member

Choose a reason for hiding this comment

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

That's tough indeed… it's definitely a nit, so let's skip

@Twixes
Copy link
Member

Twixes commented Sep 5, 2024

Took a glance, a few nits, but feels really good!

@anirudhpillai anirudhpillai force-pushed the feat/insight-with-dashboard-filters branch from 9da2bdd to 1566f8a Compare September 10, 2024 10:23
@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

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

  • chromium: 0 added, 10 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.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

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

  • chromium: 0 added, 10 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.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

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

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@anirudhpillai anirudhpillai enabled auto-merge (squash) September 12, 2024 11:37
@anirudhpillai anirudhpillai enabled auto-merge (squash) September 12, 2024 12:51
@anirudhpillai anirudhpillai merged commit d0a8627 into master Sep 12, 2024
91 checks passed
@anirudhpillai anirudhpillai deleted the feat/insight-with-dashboard-filters branch September 12, 2024 14:08
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.

Apply Dashboard Filters to Insights on Click
4 participants