Skip to content

Commit

Permalink
Add support for properties
Browse files Browse the repository at this point in the history
  • Loading branch information
robbie-c committed Oct 19, 2023
1 parent 3de112b commit d426451
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
13 changes: 13 additions & 0 deletions frontend/src/queries/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,19 @@
},
"date_to": {
"type": ["string", "null"]
},
"properties": {
"anyOf": [
{
"items": {
"$ref": "#/definitions/AnyPropertyFilter"
},
"type": "array"
},
{
"type": "null"
}
]
}
},
"type": "object"
Expand Down
1 change: 1 addition & 0 deletions frontend/src/queries/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -703,5 +703,6 @@ export interface BreakdownFilter {
export interface DashboardFilter {
date_from?: string | null
date_to?: string | null
properties?: AnyPropertyFilter[] | null
[s: string]: any
}
4 changes: 2 additions & 2 deletions frontend/src/scenes/dashboard/dashboardLogic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
import {
DashboardTile,
DashboardType,
FilterType,
InsightColor,
InsightModel,
InsightShortId,
Expand All @@ -24,6 +23,7 @@ import { dayjs, now } from 'lib/dayjs'
import { teamLogic } from 'scenes/teamLogic'
import { MOCK_TEAM_ID } from 'lib/api.mock'
import api from 'lib/api'
import { DashboardFilter } from '~/queries/schema'

const dashboardJson = _dashboardJson as any as DashboardType

Expand Down Expand Up @@ -63,7 +63,7 @@ export const tileFromInsight = (insight: InsightModel, id: number = tileId++): D
export const dashboardResult = (
dashboardId: number,
tiles: DashboardTile[],
filters: Partial<Pick<FilterType, 'date_from' | 'date_to' | 'properties'>> = {}
filters: Partial<DashboardFilter> = {}
): DashboardType => {
return {
...dashboardJson,
Expand Down
3 changes: 3 additions & 0 deletions posthog/hogql_queries/hogql_query_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,7 @@ def apply_dashboard_filters(self, dashboard_filter: DashboardFilter) -> HogQLQue
self.query.filters.dateRange.date_to = dashboard_filter.date_to
self.query.filters.dateRange.date_from = dashboard_filter.date_from

if dashboard_filter.properties:
self.query.filters.properties = (self.query.filters.properties or []) + dashboard_filter.properties

return self.query
26 changes: 21 additions & 5 deletions posthog/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@ class CountPerActorMathType(str, Enum):
p99_count_per_actor = "p99_count_per_actor"


class DashboardFilter(BaseModel):
date_from: Optional[str] = None
date_to: Optional[str] = None


class DatabaseSchemaQueryResponseField(BaseModel):
model_config = ConfigDict(
extra="forbid",
Expand Down Expand Up @@ -951,6 +946,27 @@ class AnyResponseType(RootModel):
]


class DashboardFilter(BaseModel):
date_from: Optional[str] = None
date_to: Optional[str] = None
properties: Optional[
List[
Union[
EventPropertyFilter,
PersonPropertyFilter,
ElementPropertyFilter,
SessionPropertyFilter,
CohortPropertyFilter,
RecordingDurationFilter,
GroupPropertyFilter,
FeaturePropertyFilter,
HogQLPropertyFilter,
EmptyPropertyFilter,
]
]
] = None


class DatabaseSchemaQuery(BaseModel):
model_config = ConfigDict(
extra="forbid",
Expand Down

0 comments on commit d426451

Please sign in to comment.