:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(insights): hide math/SQL tag in legend when series has a custom name (#58946)
okxint9e142e857e05
diff --git a/frontend/src/lib/components/InsightLabel/index.test.tsx b/frontend/src/lib/components/InsightLabel/index.test.tsxnew file mode 100644index 000000000000..94aaef2e4a7a--- /dev/null+++ b/frontend/src/lib/components/InsightLabel/index.test.tsx@@ -0,0 +1,68 @@+import '@testing-library/jest-dom'++import { cleanup, render, screen } from '@testing-library/react'+import { Provider } from 'kea'++import { initKeaTests } from '~/test/init'+import { ActionFilter } from '~/types'++import { InsightLabel } from './index'++const HOGQL_EXPRESSION = 'avg(properties.usd_amount)'++function hogqlAction(overrides: Partial<ActionFilter> = {}): ActionFilter {+ return {+ id: '$pageview',+ name: '$pageview',+ type: 'events',+ order: 0,+ math: 'hogql',+ math_hogql: HOGQL_EXPRESSION,+ ...overrides,+ } as ActionFilter+}++describe('InsightLabel — hideHogQLTagWhenCustomName', () => {+ beforeEach(() => {+ initKeaTests()+ })++ afterEach(() => {+ cleanup()+ })++ function renderLabel(props: Parameters<typeof InsightLabel>[0]): void {+ render(+ <Provider>+ <InsightLabel {...props} />+ </Provider>+ )+ }++ it('hides the SQL expression tag when the flag is on, the series is named, and math is hogql', () => {+ renderLabel({ action: hogqlAction({ custom_name: 'Revenue' }), hideHogQLTagWhenCustomName: true })++ expect(screen.queryByText(HOGQL_EXPRESSION)).not.toBeInTheDocument()+ })++ it('keeps the SQL expression tag by default (opt-in), even with a custom name', () => {+ renderLabel({ action: hogqlAction({ custom_name: 'Revenue' }) })++ expect(screen.getByText(HOGQL_EXPRESSION)).toBeInTheDocument()+ })++ it('keeps the SQL expression tag when the flag is on but the series has no custom name', () => {+ renderLabel({ action: hogqlAction(), hideHogQLTagWhenCustomName: true })++ expect(screen.getByText(HOGQL_EXPRESSION)).toBeInTheDocument()+ })++ it('does not affect non-hogql math tags — a named sum series still shows its tag', () => {+ renderLabel({+ action: hogqlAction({ custom_name: 'Revenue', math: 'sum', math_property: 'usd_amount' }),+ hideHogQLTagWhenCustomName: true,+ })++ expect(screen.getByText('Sum')).toBeInTheDocument()+ })+})diff --git a/frontend/src/lib/components/InsightLabel/index.tsx b/frontend/src/lib/components/InsightLabel/index.tsxindex b2b6229e553d..d79b4a9a64ef 100644--- a/frontend/src/lib/components/InsightLabel/index.tsx+++ b/frontend/src/lib/components/InsightLabel/index.tsx@@ -50,6 +50,9 @@ interface InsightsLabelProps {pillMidEllipsis?: boolean // Whether to use mid ellipsis if pill text needs to be truncatedpillMaxWidth?: number // Max width of each pill in pxshowPathCleaningHighlight?: boolean // Whether to show path cleaning highlights on the breakdown value+ /** When true, hides the HogQL/SQL math tag when the series has a custom name set.+ * Pass only in legend rows — not in tooltips — to prevent long SQL expressions eating label space. */+ hideHogQLTagWhenCustomName?: boolean}interface MathTagProps {@@ -121,6 +124,7 @@ export function InsightLabel({pillMaxWidth,showSingleName = false,showPathCleaningHighlight = false,+ hideHogQLTagWhenCustomName = false,}: InsightsLabelProps): JSX.Element {const showEventName = _showEventName || !breakdownValue || (hasMultipleSeries && !Array.isArray(breakdownValue))@@ -189,16 +193,17 @@ export function InsightLabel({</>)}- {((action?.math && action.math !== 'total') || showCountedByTag) && (- <div className="insights-label__math flex flex-nowrap items-center gap-x-1">- <MathTag- math={action?.math}- mathProperty={action?.math_property}- mathHogQL={action?.math_hogql}- mathGroupTypeIndex={action?.math_group_type_index}- />- </div>- )}+ {((action?.math && action.math !== 'total') || showCountedByTag) &&+ !(hideHogQLTagWhenCustomName && action?.custom_name && action?.math === 'hogql') && (+ <div className="insights-label__math flex flex-nowrap items-center gap-x-1">+ <MathTag+ math={action?.math}+ mathProperty={action?.math_property}+ mathHogQL={action?.math_hogql}+ mathGroupTypeIndex={action?.math_group_type_index}+ />+ </div>+ )}{pillValues.length > 0 && (<div className="flex flex-wrap gap-1">diff --git a/frontend/src/lib/components/InsightLegend/InsightLegendRow.tsx b/frontend/src/lib/components/InsightLegend/InsightLegendRow.tsxindex cfe68c594d99..d27dfced99ce 100644--- a/frontend/src/lib/components/InsightLegend/InsightLegendRow.tsx+++ b/frontend/src/lib/components/InsightLegend/InsightLegendRow.tsx@@ -108,6 +108,7 @@ export function InsightLegendRow({ item, readOnly = false }: InsightLegendRowProshowPathCleaningHighlight={showPathCleaningHighlight}hideIconshowSingleName+ hideHogQLTagWhenCustomName/>}disabledReason={!canEditInsight ? 'You need editor access to modify this insight.' : undefined}