diff --git a/frontend/src/queries/nodes/InsightQuery/utils/filtersToQueryNode.test.ts b/frontend/src/queries/nodes/InsightQuery/utils/filtersToQueryNode.test.ts index 7af2bd379bb90..6df9b079da534 100644 --- a/frontend/src/queries/nodes/InsightQuery/utils/filtersToQueryNode.test.ts +++ b/frontend/src/queries/nodes/InsightQuery/utils/filtersToQueryNode.test.ts @@ -325,7 +325,7 @@ describe('filtersToQueryNode', () => { kind: NodeKind.TrendsQuery, trendsFilter: { smoothingIntervals: 1, - show_legend: true, + showLegend: true, hidden_legend_indexes: [0, 10], compare: true, aggregationAxisFormat: 'numeric', @@ -500,7 +500,7 @@ describe('filtersToQueryNode', () => { kind: NodeKind.StickinessQuery, stickinessFilter: { compare: true, - show_legend: true, + showLegend: true, hidden_legend_indexes: [0, 10], display: ChartDisplayType.ActionsLineGraph, }, diff --git a/frontend/src/queries/nodes/InsightQuery/utils/filtersToQueryNode.ts b/frontend/src/queries/nodes/InsightQuery/utils/filtersToQueryNode.ts index 246d3677af7d4..fe1a2e0130111 100644 --- a/frontend/src/queries/nodes/InsightQuery/utils/filtersToQueryNode.ts +++ b/frontend/src/queries/nodes/InsightQuery/utils/filtersToQueryNode.ts @@ -259,7 +259,7 @@ export const filtersToQueryNode = (filters: Partial): InsightQueryNo if (isTrendsFilter(filters) && isTrendsQuery(query)) { query.trendsFilter = objectCleanWithEmpty({ smoothingIntervals: filters.smoothing_intervals, - show_legend: filters.show_legend, + showLegend: filters.show_legend, hidden_legend_indexes: cleanHiddenLegendIndexes(filters.hidden_legend_keys), compare: filters.compare, aggregationAxisFormat: filters.aggregation_axis_format, @@ -268,7 +268,7 @@ export const filtersToQueryNode = (filters: Partial): InsightQueryNo decimalPlaces: filters.decimal_places, formula: filters.formula, display: filters.display, - show_values_on_series: filters.show_values_on_series, + showValuesOnSeries: filters.show_values_on_series, showPercentStackView: filters.show_percent_stack_view, showLabelsOnSeries: filters.show_labels_on_series, }) @@ -333,9 +333,9 @@ export const filtersToQueryNode = (filters: Partial): InsightQueryNo query.stickinessFilter = objectCleanWithEmpty({ display: filters.display, compare: filters.compare, - show_legend: filters.show_legend, + showLegend: filters.show_legend, hidden_legend_indexes: cleanHiddenLegendIndexes(filters.hidden_legend_keys), - show_values_on_series: filters.show_values_on_series, + showValuesOnSeries: filters.show_values_on_series, }) } @@ -343,7 +343,7 @@ export const filtersToQueryNode = (filters: Partial): InsightQueryNo if (isLifecycleFilter(filters) && isLifecycleQuery(query)) { query.lifecycleFilter = objectCleanWithEmpty({ toggledLifecycles: filters.toggledLifecycles, - show_values_on_series: filters.show_values_on_series, + showValuesOnSeries: filters.show_values_on_series, }) } diff --git a/frontend/src/queries/nodes/InsightQuery/utils/queryNodeToFilter.test.ts b/frontend/src/queries/nodes/InsightQuery/utils/queryNodeToFilter.test.ts index a935c910522d5..332c625daec4c 100644 --- a/frontend/src/queries/nodes/InsightQuery/utils/queryNodeToFilter.test.ts +++ b/frontend/src/queries/nodes/InsightQuery/utils/queryNodeToFilter.test.ts @@ -55,12 +55,12 @@ describe('queryNodeToFilter', () => { formula: 'A + B', display: ChartDisplayType.ActionsBar, // breakdown_histogram_bin_count?: TrendsFilterLegacy['breakdown_histogram_bin_count'] - // show_legend?: TrendsFilterLegacy['show_legend'] + showLegend: true, aggregationAxisFormat: 'numeric', aggregationAxisPrefix: 'M', aggregationAxisPostfix: '$', decimalPlaces: 5, - // show_values_on_series?: TrendsFilterLegacy['show_values_on_series'] + showValuesOnSeries: true, showLabelsOnSeries: true, showPercentStackView: true, // hidden_legend_indexes?: TrendsFilterLegacy['hidden_legend_indexes'] @@ -84,6 +84,8 @@ describe('queryNodeToFilter', () => { aggregation_axis_postfix: '$', show_labels_on_series: true, show_percent_stack_view: true, + show_legend: true, + show_values_on_series: true, } expect(result).toEqual(filters) }) diff --git a/frontend/src/queries/nodes/InsightQuery/utils/queryNodeToFilter.ts b/frontend/src/queries/nodes/InsightQuery/utils/queryNodeToFilter.ts index c4fa3b175e67c..9dd551edf1a04 100644 --- a/frontend/src/queries/nodes/InsightQuery/utils/queryNodeToFilter.ts +++ b/frontend/src/queries/nodes/InsightQuery/utils/queryNodeToFilter.ts @@ -157,6 +157,8 @@ export const queryNodeToFilter = (query: InsightQueryNode): Partial legacyProps.aggregation_axis_prefix = insightFilter.aggregationAxisPrefix legacyProps.show_labels_on_series = insightFilter.showLabelsOnSeries legacyProps.show_percent_stack_view = insightFilter.showPercentStackView + legacyProps.show_legend = insightFilter.showLegend + legacyProps.show_values_on_series = insightFilter.showValuesOnSeries delete insightFilter.smoothingIntervals delete insightFilter.decimalPlaces delete insightFilter.aggregationAxisFormat @@ -164,6 +166,16 @@ export const queryNodeToFilter = (query: InsightQueryNode): Partial delete insightFilter.aggregationAxisPrefix delete insightFilter.showLabelsOnSeries delete insightFilter.showPercentStackView + delete insightFilter.showLegend + delete insightFilter.showValuesOnSeries + } else if (isStickinessQuery(query)) { + legacyProps.show_legend = insightFilter.showLegend + legacyProps.show_values_on_series = insightFilter.showValuesOnSeries + delete insightFilter.showLegend + delete insightFilter.showValuesOnSeries + } else if (isLifecycleQuery(query)) { + legacyProps.show_values_on_series = insightFilter.showValuesOnSeries + delete insightFilter.showValuesOnSeries } Object.assign(filters, insightFilter) Object.assign(filters, legacyProps) diff --git a/frontend/src/queries/nodes/InsightViz/utils.ts b/frontend/src/queries/nodes/InsightViz/utils.ts index a7fa870d8b355..3ab18a60800b6 100644 --- a/frontend/src/queries/nodes/InsightViz/utils.ts +++ b/frontend/src/queries/nodes/InsightViz/utils.ts @@ -85,9 +85,9 @@ export const getBreakdown = (query: InsightQueryNode): BreakdownFilter | undefin export const getShowLegend = (query: InsightQueryNode): boolean | undefined => { if (isStickinessQuery(query)) { - return query.stickinessFilter?.show_legend + return query.stickinessFilter?.showLegend } else if (isTrendsQuery(query)) { - return query.trendsFilter?.show_legend + return query.trendsFilter?.showLegend } else { return undefined } @@ -95,11 +95,11 @@ export const getShowLegend = (query: InsightQueryNode): boolean | undefined => { export const getShowValueOnSeries = (query: InsightQueryNode): boolean | undefined => { if (isLifecycleQuery(query)) { - return query.lifecycleFilter?.show_values_on_series + return query.lifecycleFilter?.showValuesOnSeries } else if (isStickinessQuery(query)) { - return query.stickinessFilter?.show_values_on_series + return query.stickinessFilter?.showValuesOnSeries } else if (isTrendsQuery(query)) { - return query.trendsFilter?.show_values_on_series + return query.trendsFilter?.showValuesOnSeries } else { return undefined } diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.json index 7706b8e59b10d..c027b8d750b45 100644 --- a/frontend/src/queries/schema.json +++ b/frontend/src/queries/schema.json @@ -1995,6 +1995,21 @@ "type": "string" }, "LifecycleFilter": { + "additionalProperties": false, + "properties": { + "showValuesOnSeries": { + "type": "boolean" + }, + "toggledLifecycles": { + "items": { + "$ref": "#/definitions/LifecycleToggle" + }, + "type": "array" + } + }, + "type": "object" + }, + "LifecycleFilterLegacy": { "additionalProperties": false, "description": "`LifecycleFilterType` minus everything inherited from `FilterType`", "properties": { @@ -3499,6 +3514,30 @@ "type": "string" }, "StickinessFilter": { + "additionalProperties": false, + "properties": { + "compare": { + "type": "boolean" + }, + "display": { + "$ref": "#/definitions/ChartDisplayType" + }, + "hidden_legend_indexes": { + "items": { + "type": "number" + }, + "type": "array" + }, + "showLegend": { + "type": "boolean" + }, + "showValuesOnSeries": { + "type": "boolean" + } + }, + "type": "object" + }, + "StickinessFilterLegacy": { "additionalProperties": false, "description": "`StickinessFilterType` minus everything inherited from `FilterType` and persons modal related params and `hidden_legend_keys` replaced by `hidden_legend_indexes`", "properties": { @@ -3774,13 +3813,13 @@ "showLabelsOnSeries": { "type": "boolean" }, - "showPercentStackView": { + "showLegend": { "type": "boolean" }, - "show_legend": { + "showPercentStackView": { "type": "boolean" }, - "show_values_on_series": { + "showValuesOnSeries": { "type": "boolean" }, "smoothingIntervals": { diff --git a/frontend/src/queries/schema.ts b/frontend/src/queries/schema.ts index 79b4bf385aaa2..6ab1ca28b1e64 100644 --- a/frontend/src/queries/schema.ts +++ b/frontend/src/queries/schema.ts @@ -518,13 +518,13 @@ export type TrendsFilter = { compare?: TrendsFilterLegacy['compare'] formula?: TrendsFilterLegacy['formula'] display?: TrendsFilterLegacy['display'] - show_legend?: TrendsFilterLegacy['show_legend'] + showLegend?: TrendsFilterLegacy['show_legend'] breakdown_histogram_bin_count?: TrendsFilterLegacy['breakdown_histogram_bin_count'] // TODO: fully move into BreakdownFilter aggregationAxisFormat?: TrendsFilterLegacy['aggregation_axis_format'] aggregationAxisPrefix?: TrendsFilterLegacy['aggregation_axis_prefix'] aggregationAxisPostfix?: TrendsFilterLegacy['aggregation_axis_postfix'] decimalPlaces?: TrendsFilterLegacy['decimal_places'] - show_values_on_series?: TrendsFilterLegacy['show_values_on_series'] + showValuesOnSeries?: TrendsFilterLegacy['show_values_on_series'] showLabelsOnSeries?: TrendsFilterLegacy['show_labels_on_series'] showPercentStackView?: TrendsFilterLegacy['show_percent_stack_view'] hidden_legend_indexes?: TrendsFilterLegacy['hidden_legend_indexes'] @@ -611,11 +611,19 @@ export interface PathsQuery extends InsightsQueryBase { /** `StickinessFilterType` minus everything inherited from `FilterType` and persons modal related params * and `hidden_legend_keys` replaced by `hidden_legend_indexes` */ -export type StickinessFilter = Omit< +export type StickinessFilterLegacy = Omit< StickinessFilterType & { hidden_legend_indexes?: number[] }, keyof FilterType | 'hidden_legend_keys' | 'stickiness_days' | 'shown_as' > +export type StickinessFilter = { + compare?: StickinessFilterLegacy['compare'] + display?: StickinessFilterLegacy['display'] + showLegend?: StickinessFilterLegacy['show_legend'] + showValuesOnSeries?: StickinessFilterLegacy['show_values_on_series'] + hidden_legend_indexes?: StickinessFilterLegacy['hidden_legend_indexes'] +} + export interface StickinessQueryResponse extends QueryResponse { results: Record[] } @@ -631,11 +639,16 @@ export interface StickinessQuery extends Omit & { +export type LifecycleFilterLegacy = Omit & { /** Lifecycles that have been removed from display are not included in this array */ toggledLifecycles?: LifecycleToggle[] } // using everything except what it inherits from FilterType +export type LifecycleFilter = { + showValuesOnSeries?: LifecycleFilterLegacy['show_values_on_series'] + toggledLifecycles?: LifecycleFilterLegacy['toggledLifecycles'] +} + export interface QueryRequest { /** Client provided query ID. Can be used to retrieve the status or cancel the query. */ client_query_id?: string diff --git a/frontend/src/scenes/insights/EditorFilters/ShowLegendFilter.tsx b/frontend/src/scenes/insights/EditorFilters/ShowLegendFilter.tsx index 4f6157bdab514..ee2a55ea53e71 100644 --- a/frontend/src/scenes/insights/EditorFilters/ShowLegendFilter.tsx +++ b/frontend/src/scenes/insights/EditorFilters/ShowLegendFilter.tsx @@ -10,7 +10,7 @@ export function ShowLegendFilter(): JSX.Element | null { const { updateInsightFilter } = useActions(insightVizDataLogic(insightProps)) const toggleShowLegend = (): void => { - updateInsightFilter({ show_legend: !showLegend }) + updateInsightFilter({ showLegend: !showLegend }) } return ( diff --git a/frontend/src/scenes/insights/EditorFilters/ValueOnSeriesFilter.tsx b/frontend/src/scenes/insights/EditorFilters/ValueOnSeriesFilter.tsx index 142a2f1d89b4b..8f4880a66b737 100644 --- a/frontend/src/scenes/insights/EditorFilters/ValueOnSeriesFilter.tsx +++ b/frontend/src/scenes/insights/EditorFilters/ValueOnSeriesFilter.tsx @@ -14,7 +14,7 @@ export function ValueOnSeriesFilter(): JSX.Element { className="p-1 px-2" checked={valueOnSeries} onChange={(checked) => { - updateInsightFilter({ show_values_on_series: checked }) + updateInsightFilter({ showValuesOnSeries: checked }) }} label={Show values on series} size="small" diff --git a/frontend/src/scenes/insights/InsightNav/insightNavLogic.test.ts b/frontend/src/scenes/insights/InsightNav/insightNavLogic.test.ts index 088b339b9760e..872148e08a713 100644 --- a/frontend/src/scenes/insights/InsightNav/insightNavLogic.test.ts +++ b/frontend/src/scenes/insights/InsightNav/insightNavLogic.test.ts @@ -135,7 +135,7 @@ describe('insightNavLogic', () => { event: '$pageview', }, ], - trendsFilter: { show_values_on_series: true }, + trendsFilter: { showValuesOnSeries: true }, }, } const funnelsQuery: InsightVizNode = { @@ -229,7 +229,7 @@ describe('insightNavLogic', () => { builtInsightDataLogic.actions.setQuery(trendsQuery) }).toMatchValues({ queryPropertyCache: expect.objectContaining({ - commonFilter: { show_values_on_series: true }, + commonFilter: { showValuesOnSeries: true }, }), }) @@ -238,7 +238,7 @@ describe('insightNavLogic', () => { }).toMatchValues({ queryPropertyCache: expect.objectContaining({ commonFilter: { - show_values_on_series: true, + showValuesOnSeries: true, funnel_order_type: 'strict', funnel_viz_type: 'steps', }, @@ -283,7 +283,7 @@ describe('insightNavLogic', () => { kind: 'LifecycleQuery', series: [{ kind: 'EventsNode', name: '$pageview', event: '$pageview' }], filterTestAccounts: true, - lifecycleFilter: { show_values_on_series: true }, + lifecycleFilter: { showValuesOnSeries: true }, }, } as Node), ]) diff --git a/frontend/src/scenes/insights/InsightNav/insightNavLogic.tsx b/frontend/src/scenes/insights/InsightNav/insightNavLogic.tsx index 58bc021bb3a76..f5e6de98cebb0 100644 --- a/frontend/src/scenes/insights/InsightNav/insightNavLogic.tsx +++ b/frontend/src/scenes/insights/InsightNav/insightNavLogic.tsx @@ -339,8 +339,8 @@ const mergeCachedProperties = (query: InsightQueryNode, cache: QueryPropertyCach // TODO: fix an issue where switching between trends and funnels with the option enabled would // result in an error before uncommenting // ...(getCompare(node) ? { compare: getCompare(node) } : {}), - ...(getShowValueOnSeries(node) ? { show_values_on_series: getShowValueOnSeries(node) } : {}), - ...(getShowPercentStackView(node) ? { show_percent_stack_view: getShowPercentStackView(node) } : {}), + ...(getShowValueOnSeries(node) ? { showValuesOnSeries: getShowValueOnSeries(node) } : {}), + ...(getShowPercentStackView(node) ? { showPercentStackView: getShowPercentStackView(node) } : {}), ...(getDisplay(node) ? { display: getDisplay(node) } : {}), } } diff --git a/frontend/src/scenes/insights/insightLogic.test.ts b/frontend/src/scenes/insights/insightLogic.test.ts index 3856ef09974a3..7875d67b48b70 100644 --- a/frontend/src/scenes/insights/insightLogic.test.ts +++ b/frontend/src/scenes/insights/insightLogic.test.ts @@ -248,22 +248,6 @@ describe('insightLogic', () => { }) describe('insight legend', () => { - it('toggles insight legend', async () => { - logic = insightLogic({ - dashboardItemId: undefined, - filters: { show_legend: false }, - }) - logic.mount() - - await expectLogic(logic, () => { - logic.actions.toggleInsightLegend() - }) - .toDispatchActions(['toggleInsightLegend', 'setFilters']) - .toMatchValues({ - filters: partial({ show_legend: true }), - }) - }) - it('initialize insight with hidden keys', async () => { logic = insightLogic({ dashboardItemId: undefined, diff --git a/frontend/src/scenes/insights/insightLogic.ts b/frontend/src/scenes/insights/insightLogic.ts index 072d0f54adbec..1f6731dca7392 100644 --- a/frontend/src/scenes/insights/insightLogic.ts +++ b/frontend/src/scenes/insights/insightLogic.ts @@ -134,7 +134,6 @@ export const insightLogic = kea([ callback, }), setInsightMetadata: (metadata: Partial) => ({ metadata }), - toggleInsightLegend: true, toggleVisibility: (index: number) => ({ index }), highlightSeries: (seriesIndex: number | null) => ({ seriesIndex }), }), @@ -694,13 +693,6 @@ export const insightLogic = kea([ loadInsightSuccess: async ({ insight }) => { actions.reportInsightViewed(insight, insight?.filters || {}) }, - toggleInsightLegend: () => { - const newFilters: Partial = { - ...values.filters, - show_legend: !(values.filters as Partial).show_legend, - } - actions.setFilters(newFilters) - }, toggleVisibility: ({ index }) => { const currentIsHidden = !!values.hiddenLegendKeys?.[index] const newFilters: Partial = { diff --git a/frontend/src/scenes/insights/insightVizDataLogic.test.ts b/frontend/src/scenes/insights/insightVizDataLogic.test.ts index 53c77d7fc62c6..ce3e11b6c9c51 100644 --- a/frontend/src/scenes/insights/insightVizDataLogic.test.ts +++ b/frontend/src/scenes/insights/insightVizDataLogic.test.ts @@ -204,7 +204,7 @@ describe('insightVizDataLogic', () => { // merges with existing insight filter expectLogic(builtInsightDataLogic, () => { builtInsightVizDataLogic.actions.updateInsightFilter({ - show_values_on_series: true, + showValuesOnSeries: true, }) }).toMatchValues({ query: { @@ -213,7 +213,7 @@ describe('insightVizDataLogic', () => { ...trendsQueryDefault, trendsFilter: { display: 'ActionsAreaGraph', - show_values_on_series: true, + showValuesOnSeries: true, }, }, }, @@ -221,7 +221,7 @@ describe('insightVizDataLogic', () => { expect(builtInsightVizDataLogic.values.insightFilter).toEqual({ display: 'ActionsAreaGraph', - show_values_on_series: true, + showValuesOnSeries: true, }) }) diff --git a/frontend/src/scenes/insights/insightVizDataLogic.ts b/frontend/src/scenes/insights/insightVizDataLogic.ts index d0cfa792e7a57..5780cbbd6f686 100644 --- a/frontend/src/scenes/insights/insightVizDataLogic.ts +++ b/frontend/src/scenes/insights/insightVizDataLogic.ts @@ -55,15 +55,7 @@ import { isTrendsQuery, nodeKindToFilterProperty, } from '~/queries/utils' -import { - BaseMathType, - ChartDisplayType, - FilterType, - FunnelExclusion, - InsightLogicProps, - IntervalType, - TrendsFilterType, -} from '~/types' +import { BaseMathType, ChartDisplayType, FilterType, FunnelExclusion, InsightLogicProps, IntervalType } from '~/types' import { insightLogic } from './insightLogic' import type { insightVizDataLogicType } from './insightVizDataLogicType' @@ -224,11 +216,11 @@ export const insightVizDataLogic = kea([ (isTrends, isStickiness, isLifecycle, insightFilter): boolean => { return !!( ((isTrends || isStickiness || isLifecycle) && - (insightFilter as TrendsFilterType)?.show_values_on_series) || + (insightFilter as TrendsFilter)?.showValuesOnSeries) || // pie charts have value checked by default (isTrends && - (insightFilter as TrendsFilterType)?.display === ChartDisplayType.ActionsPie && - (insightFilter as TrendsFilterType)?.show_values_on_series === undefined) + (insightFilter as TrendsFilter)?.display === ChartDisplayType.ActionsPie && + (insightFilter as TrendsFilter)?.showValuesOnSeries === undefined) ) }, ], diff --git a/frontend/src/scenes/insights/utils/compareInsightQuery.ts b/frontend/src/scenes/insights/utils/compareInsightQuery.ts index 2fc863e4a7bcc..81aed606ba16c 100644 --- a/frontend/src/scenes/insights/utils/compareInsightQuery.ts +++ b/frontend/src/scenes/insights/utils/compareInsightQuery.ts @@ -48,9 +48,9 @@ const cleanInsightQuery = (query: InsightQueryNode, ignoreVisualizationOnlyChang const insightFilterKey = filterKeyForQuery(cleanedQuery) cleanedQuery[insightFilterKey] = { ...insightFilter, - show_legend: undefined, + showLegend: undefined, showPercentStackView: undefined, - show_values_on_series: undefined, + showValuesOnSeries: undefined, aggregationAxisFormat: undefined, aggregationAxisPrefix: undefined, aggregationAxisPostfix: undefined, diff --git a/frontend/src/scenes/insights/views/LineGraph/PieChart.tsx b/frontend/src/scenes/insights/views/LineGraph/PieChart.tsx index 25f09bddf3ef7..3e08f7771372d 100644 --- a/frontend/src/scenes/insights/views/LineGraph/PieChart.tsx +++ b/frontend/src/scenes/insights/views/LineGraph/PieChart.tsx @@ -190,7 +190,7 @@ export function PieChart({ const [tooltipRoot, tooltipEl] = ensureTooltip() if (tooltip.opacity === 0) { // remove highlight from the legend - if (trendsFilter?.show_legend) { + if (trendsFilter?.showLegend) { highlightSeries(null) } tooltipEl.style.opacity = '0' diff --git a/frontend/src/scenes/trends/viz/ActionsPie.tsx b/frontend/src/scenes/trends/viz/ActionsPie.tsx index b9a6aebe28294..48d05084d3e70 100644 --- a/frontend/src/scenes/trends/viz/ActionsPie.tsx +++ b/frontend/src/scenes/trends/viz/ActionsPie.tsx @@ -134,7 +134,7 @@ export function ActionsPie({ )} - {inCardView && trendsFilter?.show_legend && } + {inCardView && trendsFilter?.showLegend && } ) : (

We couldn't find any matching actions.

diff --git a/posthog/hogql_queries/legacy_compatibility/filter_to_query.py b/posthog/hogql_queries/legacy_compatibility/filter_to_query.py index 1b3c1213d77ea..6c61e7359ac17 100644 --- a/posthog/hogql_queries/legacy_compatibility/filter_to_query.py +++ b/posthog/hogql_queries/legacy_compatibility/filter_to_query.py @@ -315,7 +315,7 @@ def _insight_filter(filter: Dict): insight_filter = { "trendsFilter": TrendsFilter( smoothingIntervals=filter.get("smoothing_intervals"), - # show_legend=filter.get('show_legend'), + showLegend=filter.get("show_legend"), # hidden_legend_indexes=cleanHiddenLegendIndexes(filter.get('hidden_legend_keys')), compare=filter.get("compare"), aggregationAxisFormat=filter.get("aggregation_axis_format"), @@ -324,7 +324,7 @@ def _insight_filter(filter: Dict): decimalPlaces=filter.get("decimal_places"), formula=filter.get("formula"), display=clean_display(filter.get("display")), - show_values_on_series=filter.get("show_values_on_series"), + showValuesOnSeries=filter.get("show_values_on_series"), showPercentStackView=filter.get("show_percent_stack_view"), showLabelsOnSeries=filter.get("show_label_on_series"), ) @@ -393,17 +393,17 @@ def _insight_filter(filter: Dict): elif _insight_type(filter) == "LIFECYCLE": insight_filter = { "lifecycleFilter": LifecycleFilter( - # toggledLifecycles=filter.get('toggledLifecycles'), - show_values_on_series=filter.get("show_values_on_series"), + toggledLifecycles=filter.get("toggledLifecycles"), + showValuesOnSeries=filter.get("show_values_on_series"), ) } elif _insight_type(filter) == "STICKINESS": insight_filter = { "stickinessFilter": StickinessFilter( compare=filter.get("compare"), - # show_legend=filter.get('show_legend'), + showLegend=filter.get("show_legend"), # hidden_legend_indexes: cleanHiddenLegendIndexes(filter.get('hidden_legend_keys')), - show_values_on_series=filter.get("show_values_on_series"), + showValuesOnSeries=filter.get("show_values_on_series"), ) } else: diff --git a/posthog/hogql_queries/legacy_compatibility/test/test_filter_to_query.py b/posthog/hogql_queries/legacy_compatibility/test/test_filter_to_query.py index 6fdf7d838fd3d..8c279535a50d6 100644 --- a/posthog/hogql_queries/legacy_compatibility/test/test_filter_to_query.py +++ b/posthog/hogql_queries/legacy_compatibility/test/test_filter_to_query.py @@ -21,6 +21,7 @@ GroupPropertyFilter, HogQLPropertyFilter, Key, + LifecycleToggle, PathCleaningFilter, PathType, PersonPropertyFilter, @@ -35,6 +36,7 @@ RetentionFilter, PathsFilter, StickinessFilter, + LifecycleFilter, ) from posthog.test.base import BaseTest @@ -1286,6 +1288,8 @@ def test_trends_filter(self): "formula": "A + B", "shown_as": "Volume", "display": "ActionsAreaGraph", + "show_legend": True, + "show_percent_stack_view": True, } query = filter_to_query(filter) @@ -1301,6 +1305,8 @@ def test_trends_filter(self): formula="A + B", display=ChartDisplayType.ActionsAreaGraph, decimalPlaces=5, + showLegend=True, + showPercentStackView=True, ), ) @@ -1488,24 +1494,35 @@ def test_paths_filter(self): ) def test_stickiness_filter(self): - filter = {"insight": "STICKINESS", "compare": True, "shown_as": "Stickiness"} + filter = { + "insight": "STICKINESS", + "compare": True, + "show_legend": True, + "show_values_on_series": True, + "shown_as": "Stickiness", + } query = filter_to_query(filter) self.assertEqual( query.stickinessFilter, - StickinessFilter(compare=True), + StickinessFilter(compare=True, showLegend=True, showValuesOnSeries=True), ) def test_lifecycle_filter(self): filter = { "insight": "LIFECYCLE", "shown_as": "Lifecycle", + "show_values_on_series": True, + "toggledLifecycles": ["new", "dormant"], } query = filter_to_query(filter) self.assertEqual( query.lifecycleFilter, - None, + LifecycleFilter( + showValuesOnSeries=True, + toggledLifecycles=[LifecycleToggle.new, LifecycleToggle.dormant], + ), ) diff --git a/posthog/schema.py b/posthog/schema.py index 57287116ecaa3..8db3af5682669 100644 --- a/posthog/schema.py +++ b/posthog/schema.py @@ -579,6 +579,17 @@ class StepOrderValue(str, Enum): class StickinessFilter(BaseModel): + model_config = ConfigDict( + extra="forbid", + ) + compare: Optional[bool] = None + display: Optional[ChartDisplayType] = None + hidden_legend_indexes: Optional[List[float]] = None + showLegend: Optional[bool] = None + showValuesOnSeries: Optional[bool] = None + + +class StickinessFilterLegacy(BaseModel): model_config = ConfigDict( extra="forbid", ) @@ -653,9 +664,9 @@ class TrendsFilter(BaseModel): formula: Optional[str] = None hidden_legend_indexes: Optional[List[float]] = None showLabelsOnSeries: Optional[bool] = None + showLegend: Optional[bool] = None showPercentStackView: Optional[bool] = None - show_legend: Optional[bool] = None - show_values_on_series: Optional[bool] = None + showValuesOnSeries: Optional[bool] = None smoothingIntervals: Optional[float] = None @@ -980,6 +991,14 @@ class HogQLQueryResponse(BaseModel): class LifecycleFilter(BaseModel): + model_config = ConfigDict( + extra="forbid", + ) + showValuesOnSeries: Optional[bool] = None + toggledLifecycles: Optional[List[LifecycleToggle]] = None + + +class LifecycleFilterLegacy(BaseModel): model_config = ConfigDict( extra="forbid", )