Skip to content

Commit

Permalink
fix(notebooks): handle legacy stickiness and lifecycle filters (#20027)
Browse files Browse the repository at this point in the history
  • Loading branch information
thmsobrmlr committed Feb 1, 2024
1 parent 61e3bdc commit e179b8e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 11 deletions.
32 changes: 21 additions & 11 deletions frontend/src/queries/nodes/InsightQuery/utils/filtersToQueryNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ import {
InsightNodeKind,
InsightQueryNode,
InsightsQueryBase,
LifecycleFilter,
NodeKind,
PathsFilter,
RetentionFilter,
StickinessFilter,
TrendsFilter,
} from '~/queries/schema'
import {
Expand Down Expand Up @@ -290,21 +292,12 @@ export const filtersToQueryNode = (filters: Partial<FilterType>): InsightQueryNo

// stickiness filter
if (isStickinessFilter(filters) && isStickinessQuery(query)) {
query.stickinessFilter = objectCleanWithEmpty({
display: filters.display,
compare: filters.compare,
showLegend: filters.show_legend,
hidden_legend_indexes: cleanHiddenLegendIndexes(filters.hidden_legend_keys),
showValuesOnSeries: filters.show_values_on_series,
})
query.stickinessFilter = stickinessFilterToQuery(filters)
}

// lifecycle filter
if (isLifecycleFilter(filters) && isLifecycleQuery(query)) {
query.lifecycleFilter = objectCleanWithEmpty({
toggledLifecycles: filters.toggledLifecycles,
showValuesOnSeries: filters.show_values_on_series,
})
query.lifecycleFilter = lifecycleFilterToQuery(filters)
}

// remove undefined and empty array/objects and return
Expand Down Expand Up @@ -386,6 +379,23 @@ export const pathsFilterToQuery = (filters: Partial<PathsFilterType>): PathsFilt
})
}

export const stickinessFilterToQuery = (filters: Record<string, any>): StickinessFilter => {
return objectCleanWithEmpty({
display: filters.display,
compare: filters.compare,
showLegend: filters.show_legend,
hidden_legend_indexes: cleanHiddenLegendIndexes(filters.hidden_legend_keys),
showValuesOnSeries: filters.show_values_on_series,
})
}

export const lifecycleFilterToQuery = (filters: Record<string, any>): LifecycleFilter => {
return objectCleanWithEmpty({
toggledLifecycles: filters.toggledLifecycles,
showValuesOnSeries: filters.show_values_on_series,
})
}

export const breakdownFilterToQuery = (filters: Record<string, any>, isTrends: boolean): BreakdownFilter => {
return objectCleanWithEmpty({
breakdown_type: filters.breakdown_type,
Expand Down
18 changes: 18 additions & 0 deletions frontend/src/queries/nodes/InsightQuery/utils/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,21 @@ export const isLegacyPathsFilter = (filters: Record<string, any> | undefined): b
]
return legacyKeys.some((key) => key in filters)
}

export const isLegacyStickinessFilter = (filters: Record<string, any> | undefined): boolean => {
if (filters == null) {
return false
}

const legacyKeys = ['show_legend', 'hidden_legend_keys', 'show_values_on_series']
return legacyKeys.some((key) => key in filters)
}

export const isLegacyLifecycleFilter = (filters: Record<string, any> | undefined): boolean => {
if (filters == null) {
return false
}

const legacyKeys = ['show_values_on_series']
return legacyKeys.some((key) => key in filters)
}
12 changes: 12 additions & 0 deletions frontend/src/scenes/notebooks/Notebook/migrations/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ import { JSONContent } from '@tiptap/core'
import {
breakdownFilterToQuery,
funnelsFilterToQuery,
lifecycleFilterToQuery,
pathsFilterToQuery,
retentionFilterToQuery,
stickinessFilterToQuery,
trendsFilterToQuery,
} from '~/queries/nodes/InsightQuery/utils/filtersToQueryNode'
import {
isLegacyFunnelsFilter,
isLegacyLifecycleFilter,
isLegacyPathsFilter,
isLegacyRetentionFilter,
isLegacyStickinessFilter,
isLegacyTrendsFilter,
} from '~/queries/nodes/InsightQuery/utils/legacy'
import { InsightVizNode, NodeKind } from '~/queries/schema'
Expand Down Expand Up @@ -111,6 +115,14 @@ function convertInsightQueriesToNewSchema(content: JSONContent[]): JSONContent[]
query.pathsFilter = pathsFilterToQuery(query.pathsFilter as any)
}

if (query.kind === NodeKind.StickinessQuery && isLegacyStickinessFilter(query.stickinessFilter as any)) {
query.stickinessFilter = stickinessFilterToQuery(query.stickinessFilter as any)
}

if (query.kind === NodeKind.LifecycleQuery && isLegacyLifecycleFilter(query.lifecycleFilter as any)) {
query.lifecycleFilter = lifecycleFilterToQuery(query.lifecycleFilter as any)
}

/*
* Breakdown
*/
Expand Down

0 comments on commit e179b8e

Please sign in to comment.