Skip to content

fix(insights): hide math/SQL tag in legend when series has a custom name - #58946

Merged
haacked merged 5 commits into
PostHog:masterfrom
okxint:fix/insight-legend-hide-math-tag-when-custom-name
Jun 26, 2026
Merged

haacked merged 5 commits into
PostHog:masterfrom
okxint:fix/insight-legend-hide-math-tag-when-custom-name

Conversation

@okxint

@okxint okxint commented May 19, 2026

Copy link
Copy Markdown
Contributor

Problem

When a series uses a SQL calculation (math=hogql) and has a custom name set, the chart legend renders both the custom name and the full SQL expression as a tag side-by-side. For long SQL expressions like uniqExact(properties.timing_group_id), this makes the legend consume half the chart area.

The same issue occurs with long built-in math options like "First occurrence matching filters".

Fixes #58907

Changes

One condition change in InsightLabel/index.tsx. The MathTag is already conditionally rendered β€” added a check that suppresses it when showSingleName is true (the legend's mode) and action.custom_name is set.

Before: math tag always shown when action.math !== 'total'

After: math tag hidden when showSingleName && action.custom_name β€” the custom name is already the user's chosen description of the series

Contexts that don't pass showSingleName (tooltips, the query editor) are unaffected.

How did you test this code?

TypeScript compilation passes. Manual testing requires a series with math=hogql and a custom name set β€” the legend should show only the custom name without the SQL tag.

Publish to changelog?

No

πŸ€– Agent context

Authored with Claude Code. Traced the legend rendering path from InsightLegendRow β†’ InsightLabel β†’ MathTag. The showSingleName prop already suppresses the underlying event name in EntityFilterInfo when a custom name is set; this PR applies the same logic to the MathTag.

@pr-assigner-resolver-posthog
pr-assigner-resolver-posthog Bot requested review from a team May 19, 2026 06:08
@greptile-apps

greptile-apps Bot commented May 19, 2026

Copy link
Copy Markdown
Contributor
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 2
frontend/src/scenes/surveys/surveysLogic.tsx:344
**`survey_id` metadata will always be `"undefined"`**

`deleteSurvey` returns the merged data object `{ ...values.data, surveys: ..., searchSurveys: ... }` (lines 197–201). In kea-loaders the `...Success` action payload is `{ data: <returnValue> }` (confirmed by the reducer on line 315 using `(_, { data })`). Destructuring `{ payload: surveyId }` from `{ data: {...} }` produces `surveyId = undefined`, so `String(undefined)` = `"undefined"` is sent as `survey_id`. The intended survey ID is only available as the `id` argument passed into the loader, not from what the loader returns.

### Issue 2 of 2
frontend/src/scenes/feature-flags/cohortPickerProps.ts:20
The constant name `COHORTS_ONLY_SUPPORT_IN_PICKER_PROPS` now contradicts the updated JSDoc and the implementation β€” `not_in` is no longer excluded. Future readers will assume `not_in` is still filtered out.

```suggestion
export const COHORTS_PICKER_PROPS = {
```

Reviews (1): Last reviewed commit: "fix(insights): hide math/SQL tag in lege..." | Re-trigger Greptile

@@ -15,9 +15,9 @@ import { PropertyOperator } from '~/types'
*
* Spread into `PropertyFilters` / `TaxonomicPropertyFilter` rather than
* passing each prop individually so the configuration travels as one named
* idea and a future change (e.g. allowing `not_in`) edits one place.
* idea and a future change edits one place.
*/
export const COHORTS_ONLY_SUPPORT_IN_PICKER_PROPS = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 The constant name COHORTS_ONLY_SUPPORT_IN_PICKER_PROPS now contradicts the updated JSDoc and the implementation β€” not_in is no longer excluded. Future readers will assume not_in is still filtered out.

Suggested change
export const COHORTS_ONLY_SUPPORT_IN_PICKER_PROPS = {
export const COHORTS_PICKER_PROPS = {
Prompt To Fix With AI
This is a comment left during a code review.
Path: frontend/src/scenes/feature-flags/cohortPickerProps.ts
Line: 20

Comment:
The constant name `COHORTS_ONLY_SUPPORT_IN_PICKER_PROPS` now contradicts the updated JSDoc and the implementation β€” `not_in` is no longer excluded. Future readers will assume `not_in` is still filtered out.

```suggestion
export const COHORTS_PICKER_PROPS = {
```

How can I resolve this? If you propose a fix, please make it concise.

@okxint
okxint force-pushed the fix/insight-legend-hide-math-tag-when-custom-name branch from f455f3c to 4b6044a Compare May 21, 2026 05:44
@scheduled-actions-posthog

Copy link
Copy Markdown
Contributor

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, please remove the stale label – otherwise this will be closed in another week. If you want to permanently keep it open, use the waiting label.

@okxint

okxint commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

Still relevant β€” bumping to prevent auto-close.

@haacked haacked left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, targeted fix for the legend. One blocking issue inline: the same gate also fires in tooltips, which the description says it leaves alone. A couple of suggestions too.

@okxint
okxint force-pushed the fix/insight-legend-hide-math-tag-when-custom-name branch from 4b6044a to 3a49805 Compare June 9, 2026 06:18
@okxint

okxint commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @haacked β€” addressed both points:

Blocking fix: Replaced the showSingleName gate with a new hideMathTagWhenCustomName prop that's only passed by InsightLegendRow, not InsightTooltip. Tooltips still pass showSingleName but won't receive hideMathTagWhenCustomName, so they're fully unaffected.

Suggestion addressed: Scoped the hide to math === 'hogql' only. A series named 'Avg load time' with math=avg will still show its short 'Average' tag β€” only the long SQL expression is suppressed when a custom name is set.

The showCountedByTag interaction is safe (no caller sets both showCountedByTag and hideMathTagWhenCustomName today, and the new prop defaults to false), but I agree it's worth a comment β€” left a note in the prop JSDoc.

Test for InsightLabel noted as a follow-up β€” happy to add it in this PR or a separate one if preferred.

@okxint

okxint commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

hey @haacked β€” pushed the fixes last week, mind taking another look when you get a chance?

@scheduled-actions-posthog

Copy link
Copy Markdown
Contributor

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, please remove the stale label – otherwise this will be closed in another week. If you want to permanently keep it open, use the waiting label.

okxint added 2 commits June 21, 2026 10:39
When a series uses a SQL calculation (math=hogql) and has a custom name,
the legend showed both the custom name and the full SQL expression as a
tag, making the legend take up excessive space and cramping the chart.

The custom name is the user's explicit label for the series, so the math
tag is redundant when showSingleName is true (the legend's mode). Suppress
the MathTag when showSingleName and action.custom_name are both set.
Contexts that don't pass showSingleName (tooltips, etc.) are unaffected.

Fixes PostHog#58907
…ooltips

The previous approach used showSingleName to gate the math tag, but both
legend rows and tooltips pass showSingleName=true, so tooltips also had
the tag hidden (unintended).

Two issues addressed per review from @haacked:
- Add hideMathTagWhenCustomName prop passed only by InsightLegendRow, not
  InsightTooltip, so tooltips are unaffected
- Scope the hide to math=hogql only β€” short tags like 'Average' on a
  renamed series should still show; only the long SQL expression is
  suppressed
@okxint
okxint force-pushed the fix/insight-legend-hide-math-tag-when-custom-name branch from 3a49805 to cb325a0 Compare June 21, 2026 05:10
@okxint

okxint commented Jun 21, 2026

Copy link
Copy Markdown
Contributor Author

addressed all the feedback β€” switched from showSingleName to a dedicated hideMathTagWhenCustomName prop so tooltips are completely unaffected, and scoped it to math === 'hogql' only so short aggregation tags (Unique, Average, etc.) still show on named series. also cleaned the branch so it only contains these two commits now.

haacked added 3 commits June 26, 2026 14:31
The prop only suppresses the HogQL/SQL expression tag, gated on
math === 'hogql'. The old name implied it hid any math tag under a
custom name; the new name matches the actual behavior.

Claude-Session: https://claude.ai/code/session_015RyuRuvkysWRwMA86t6do8
Pins the four-way condition: the SQL expression tag is hidden only when
the flag is on, the series has a custom name, and math is hogql; it stays
visible by default, without a custom name, and for non-hogql math.

Claude-Session: https://claude.ai/code/session_015RyuRuvkysWRwMA86t6do8

@haacked haacked left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All my feedback was addressed. Nice work!

@haacked
haacked merged commit 9e142e8 into PostHog:master Jun 26, 2026
187 checks passed
@deployment-status-posthog

deployment-status-posthog Bot commented Jun 26, 2026 •

Copy link
Copy Markdown

Deploy status

Environment Status Deployed At Workflow
dev βœ… Deployed 2026-06-26 22:41 UTC Run
prod-us βœ… Deployed 2026-06-26 23:01 UTC Run
prod-eu βœ… Deployed 2026-06-26 23:01 UTC Run

meikelmosby pushed a commit that referenced this pull request Jun 29, 2026
…ame (#58946)

Co-authored-by: Phil Haack <phil.h@posthog.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Legend expands too far when SQL calculations used for a series

2 participants