-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Conversation
Size Change: +2.51 kB (+0.23%) Total Size: 1.1 MB
|
4b9522e
to
df2f5f9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
frontend/src/scenes/urls.ts
Outdated
@@ -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)}` : ''}`, |
There was a problem hiding this comment.
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.
posthog/schema.py
Outdated
@@ -5607,6 +5607,7 @@ class QueryRequest(BaseModel): | |||
discriminator="kind", | |||
) | |||
refresh: Optional[Union[bool, str]] = None | |||
filters_override: Optional[DashboardFilter] = None |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
df2f5f9
to
e64b83d
Compare
📸 UI snapshots have been updated10 snapshot changes in total. 0 added, 10 modified, 0 deleted:
Triggered by this commit. |
7e1858c
to
1ce8a37
Compare
📸 UI snapshots have been updated10 snapshot changes in total. 0 added, 10 modified, 0 deleted:
Triggered by this commit. |
863c389
to
1986fff
Compare
📸 UI snapshots have been updated10 snapshot changes in total. 0 added, 10 modified, 0 deleted:
Triggered by this commit. |
5164a38
to
1ebe217
Compare
@@ -1149,6 +1149,7 @@ export interface QueryRequest { | |||
* see the [PostHog HogQL documentation](/docs/hogql#api-access). | |||
*/ | |||
query: QuerySchema | |||
filters_override?: DashboardFilter |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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
<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' | ||
)} | ||
> |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
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
There was a problem hiding this comment.
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
Took a glance, a few nits, but feels really good! |
9da2bdd
to
1566f8a
Compare
📸 UI snapshots have been updated10 snapshot changes in total. 0 added, 10 modified, 0 deleted:
Triggered by this commit. |
📸 UI snapshots have been updated10 snapshot changes in total. 0 added, 10 modified, 0 deleted:
Triggered by this commit. |
…Hog/posthog into feat/insight-with-dashboard-filters
📸 UI snapshots have been updated7 snapshot changes in total. 0 added, 7 modified, 0 deleted:
Triggered by this commit. |
…Hog/posthog into feat/insight-with-dashboard-filters
…-with-dashboard-filters
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