Skip to content

: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.

feat(insights): drill-in chart options panel behind today-rail-nav (#128742)

Sam Pennington2a7ca60b9e91
diff --git a/frontend/src/lib/components/ChartOptions/ChartOptionGroup.tsx b/frontend/src/lib/components/ChartOptions/ChartOptionGroup.tsx
index c8f138139846..b167a764ac5f 100644
--- a/frontend/src/lib/components/ChartOptions/ChartOptionGroup.tsx
+++ b/frontend/src/lib/components/ChartOptions/ChartOptionGroup.tsx
@@ -1,6 +1,9 @@
import { ReactNode } from 'react'
+import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
+
import { ChartOptionLabel } from './ChartOptionLabel'
+import { QuillChartOptionGroup } from './QuillChartOptionGroup'
export interface ChartOptionGroupProps {
title: string
@@ -9,6 +12,12 @@ export interface ChartOptionGroupProps {
}
export function ChartOptionGroup(props: ChartOptionGroupProps): JSX.Element {
+ const todayRailNav = useFeatureFlag('TODAY_RAIL_NAV')
+
+ if (todayRailNav) {
+ return <QuillChartOptionGroup {...props} />
+ }
+
const { title, info, children } = props
return (
<section className="flex flex-col gap-2">
diff --git a/frontend/src/lib/components/ChartOptions/ChartOptionNumberInput.tsx b/frontend/src/lib/components/ChartOptions/ChartOptionNumberInput.tsx
index 6f2d849d4525..ee5a7178915f 100644
--- a/frontend/src/lib/components/ChartOptions/ChartOptionNumberInput.tsx
+++ b/frontend/src/lib/components/ChartOptions/ChartOptionNumberInput.tsx
@@ -2,7 +2,10 @@ import { useId } from 'react'
import { LemonInput } from '@posthog/lemon-ui'
+import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
+
import { ChartOptionLabel } from './ChartOptionLabel'
+import { QuillChartOptionNumberInput } from './QuillChartOptionNumberInput'
import { parseChartOptionNumber, useChartOptionNumberDraft } from './useChartOptionNumberDraft'
export interface ChartOptionNumberInputProps {
@@ -19,9 +22,14 @@ export interface ChartOptionNumberInputProps {
}
export function ChartOptionNumberInput(props: ChartOptionNumberInputProps): JSX.Element {
+ const todayRailNav = useFeatureFlag('TODAY_RAIL_NAV')
const id = useId()
const { draft, setDraft, commit } = useChartOptionNumberDraft(props.value, props.onChange)
+ if (todayRailNav) {
+ return <QuillChartOptionNumberInput {...props} draft={draft} setDraft={setDraft} commit={commit} />
+ }
+
const { label, info, min, max, suffix, placeholder, disabledReason, 'data-attr': dataAttr } = props
return (
<div className="flex items-center justify-between gap-2">
diff --git a/frontend/src/lib/components/ChartOptions/ChartOptionSelect.tsx b/frontend/src/lib/components/ChartOptions/ChartOptionSelect.tsx
index 6f8bb6321e1f..c6a472b7d63a 100644
--- a/frontend/src/lib/components/ChartOptions/ChartOptionSelect.tsx
+++ b/frontend/src/lib/components/ChartOptions/ChartOptionSelect.tsx
@@ -2,7 +2,10 @@ import { useId } from 'react'
import { LemonSelect } from '@posthog/lemon-ui'
+import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
+
import { ChartOptionLabel } from './ChartOptionLabel'
+import { QuillChartOptionSelect } from './QuillChartOptionSelect'
export interface ChartOptionChoice<T extends string | number> {
value: T
@@ -21,8 +24,13 @@ export interface ChartOptionSelectProps<T extends string | number> {
}
export function ChartOptionSelect<T extends string | number>(props: ChartOptionSelectProps<T>): JSX.Element {
+ const todayRailNav = useFeatureFlag('TODAY_RAIL_NAV')
const id = useId()
+ if (todayRailNav) {
+ return <QuillChartOptionSelect {...props} />
+ }
+
const { label, info, value, options, onChange, disabledReason, 'data-attr': dataAttr } = props
const select = (
<LemonSelect<T>
diff --git a/frontend/src/lib/components/ChartOptions/ChartOptionSwitch.tsx b/frontend/src/lib/components/ChartOptions/ChartOptionSwitch.tsx
index 155fbd72b88f..a8636edf0bdc 100644
--- a/frontend/src/lib/components/ChartOptions/ChartOptionSwitch.tsx
+++ b/frontend/src/lib/components/ChartOptions/ChartOptionSwitch.tsx
@@ -1,6 +1,9 @@
import { LemonSwitch } from '@posthog/lemon-ui'
+import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
+
import { ChartOptionLabel } from './ChartOptionLabel'
+import { QuillChartOptionSwitch } from './QuillChartOptionSwitch'
export interface ChartOptionSwitchProps {
label: string
@@ -12,6 +15,12 @@ export interface ChartOptionSwitchProps {
}
export function ChartOptionSwitch(props: ChartOptionSwitchProps): JSX.Element {
+ const todayRailNav = useFeatureFlag('TODAY_RAIL_NAV')
+
+ if (todayRailNav) {
+ return <QuillChartOptionSwitch {...props} />
+ }
+
const { label, info, checked, onChange, disabledReason, 'data-attr': dataAttr } = props
return (
<LemonSwitch
diff --git a/frontend/src/lib/components/ChartOptions/ChartOptionTextInput.tsx b/frontend/src/lib/components/ChartOptions/ChartOptionTextInput.tsx
index d9c2a712c45a..4d9602fd15b4 100644
--- a/frontend/src/lib/components/ChartOptions/ChartOptionTextInput.tsx
+++ b/frontend/src/lib/components/ChartOptions/ChartOptionTextInput.tsx
@@ -2,7 +2,10 @@ import { useId } from 'react'
import { LemonInput } from '@posthog/lemon-ui'
+import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
+
import { ChartOptionLabel } from './ChartOptionLabel'
+import { QuillChartOptionTextInput } from './QuillChartOptionTextInput'
import { useChartOptionTextDraft } from './useChartOptionTextDraft'
export interface ChartOptionTextInputProps {
@@ -17,9 +20,14 @@ export interface ChartOptionTextInputProps {
}
export function ChartOptionTextInput(props: ChartOptionTextInputProps): JSX.Element {
+ const todayRailNav = useFeatureFlag('TODAY_RAIL_NAV')
const id = useId()
const { draft, setDraft, commit } = useChartOptionTextDraft(props.value, props.onChange)
+ if (todayRailNav) {
+ return <QuillChartOptionTextInput {...props} draft={draft} setDraft={setDraft} commit={commit} />
+ }
+
const { label, info, placeholder, 'data-attr': dataAttr } = props
return (
<div className="flex flex-col gap-1">
diff --git a/frontend/src/lib/components/ChartOptions/ChartOptionToggleGroup.tsx b/frontend/src/lib/components/ChartOptions/ChartOptionToggleGroup.tsx
index 05e4e3492f45..622a39f8c777 100644
--- a/frontend/src/lib/components/ChartOptions/ChartOptionToggleGroup.tsx
+++ b/frontend/src/lib/components/ChartOptions/ChartOptionToggleGroup.tsx
@@ -1,7 +1,10 @@
import { LemonSegmentedButton } from '@posthog/lemon-ui'
+import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
+
import { ChartOptionLabel } from './ChartOptionLabel'
import type { ChartOptionChoice } from './ChartOptionSelect'
+import { QuillChartOptionToggleGroup } from './QuillChartOptionToggleGroup'
export interface ChartOptionToggleGroupProps<T extends string | number> {
/** Without a label the choices fill the row, for a group whose heading already names it. */
@@ -15,6 +18,12 @@ export interface ChartOptionToggleGroupProps<T extends string | number> {
}
export function ChartOptionToggleGroup<T extends string | number>(props: ChartOptionToggleGroupProps<T>): JSX.Element {
+ const todayRailNav = useFeatureFlag('TODAY_RAIL_NAV')
+
+ if (todayRailNav) {
+ return <QuillChartOptionToggleGroup {...props} />
+ }
+
const { label, info, value, options, onChange, disabledReason, 'data-attr': dataAttr } = props
return (
<div className="flex flex-col gap-1" data-attr={dataAttr}>
diff --git a/frontend/src/lib/components/ChartOptions/ChartOptionWarning.tsx b/frontend/src/lib/components/ChartOptions/ChartOptionWarning.tsx
index c0779f5e5046..ecbab5aa0879 100644
--- a/frontend/src/lib/components/ChartOptions/ChartOptionWarning.tsx
+++ b/frontend/src/lib/components/ChartOptions/ChartOptionWarning.tsx
@@ -1,3 +1,17 @@
+import { Text } from '@posthog/quill'
+
+import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
+
export function ChartOptionWarning({ children }: { children: string }): JSX.Element {
+ const todayRailNav = useFeatureFlag('TODAY_RAIL_NAV')
+
+ if (todayRailNav) {
+ return (
+ <Text size="xs" variant="destructive">
+ {children}
+ </Text>
+ )
+ }
+
return <span className="text-xs text-danger">{children}</span>
}
diff --git a/frontend/src/lib/components/ChartOptions/QuillChartOptionGroup.tsx b/frontend/src/lib/components/ChartOptions/QuillChartOptionGroup.tsx
new file mode 100644
index 000000000000..023ee7f7ac68
--- /dev/null
+++ b/frontend/src/lib/components/ChartOptions/QuillChartOptionGroup.tsx
@@ -0,0 +1,23 @@
+import { IconInfo } from '@posthog/icons'
+import { FieldLegend, FieldSet, Tooltip, TooltipContent, TooltipTrigger } from '@posthog/quill'
+
+import type { ChartOptionGroupProps } from './ChartOptionGroup'
+
+export function QuillChartOptionGroup({ title, info, children }: ChartOptionGroupProps): JSX.Element {
+ return (
+ <FieldSet className="gap-2">
+ <FieldLegend variant="label" className="flex items-center gap-1">
+ {title}
+ {info && (
+ <Tooltip>
+ <TooltipTrigger render={<span className="inline-flex text-muted-foreground" />}>
+ <IconInfo />
+ </TooltipTrigger>
+ <TooltipContent className="max-w-64">{info}</TooltipContent>
+ </Tooltip>
+ )}
+ </FieldLegend>
+ {children}
+ </FieldSet>
+ )
+}
diff --git a/frontend/src/lib/components/ChartOptions/QuillChartOptionLabel.tsx b/frontend/src/lib/components/ChartOptions/QuillChartOptionLabel.tsx
new file mode 100644
index 000000000000..0fd0f9c76c12
--- /dev/null
+++ b/frontend/src/lib/components/ChartOptions/QuillChartOptionLabel.tsx
@@ -0,0 +1,24 @@
+import { IconInfo } from '@posthog/icons'
+import { FieldLabel, Tooltip, TooltipContent, TooltipTrigger } from '@posthog/quill'
+
+export interface QuillChartOptionLabelProps {
+ htmlFor: string
+ label: string
+ info?: string
+}
+
+export function QuillChartOptionLabel({ htmlFor, label, info }: QuillChartOptionLabelProps): JSX.Element {
+ return (
+ <FieldLabel htmlFor={htmlFor} className="items-center gap-1 font-normal">
+ {label}
+ {info && (
+ <Tooltip>
+ <TooltipTrigger render={<span className="inline-flex text-muted-foreground" />}>
+ <IconInfo />
+ </TooltipTrigger>
+ <TooltipContent className="max-w-64">{info}</TooltipContent>
+ </Tooltip>
+ )}
+ </FieldLabel>
+ )
+}
diff --git a/frontend/src/lib/components/ChartOptions/QuillChartOptionNumberInput.tsx b/frontend/src/lib/components/ChartOptions/QuillChartOptionNumberInput.tsx
new file mode 100644
index 000000000000..d884beb1ee07
--- /dev/null
+++ b/frontend/src/lib/components/ChartOptions/QuillChartOptionNumberInput.tsx
@@ -0,0 +1,61 @@
+import { useId } from 'react'
+
+import { Field, FieldDescription, InputGroup, InputGroupAddon, InputGroupInput, InputGroupText } from '@posthog/quill'
+
+import type { ChartOptionNumberInputProps } from './ChartOptionNumberInput'
+import { QuillChartOptionLabel } from './QuillChartOptionLabel'
+
+export interface QuillChartOptionNumberInputProps extends ChartOptionNumberInputProps {
+ draft: string
+ setDraft: (draft: string) => void
+ commit: () => void
+}
+
+export function QuillChartOptionNumberInput({
+ label,
+ info,
+ suffix,
+ placeholder,
+ disabledReason,
+ draft,
+ setDraft,
+ commit,
+ 'data-attr': dataAttr,
+}: QuillChartOptionNumberInputProps): JSX.Element {
+ const id = useId()
+ const disabled = !!disabledReason
+
+ return (
+ <Field data-disabled={disabled || undefined}>
+ <div className="flex items-center justify-between gap-2">
+ <QuillChartOptionLabel htmlFor={id} label={label} info={info} />
+ <InputGroup className="w-28" aria-disabled={disabled || undefined}>
+ <InputGroupInput
+ id={id}
+ // Text, not a number input: a number input reports "-" as empty while typing "-10".
+ type="text"
+ inputMode="decimal"
+ value={draft}
+ placeholder={placeholder}
+ disabled={disabled}
+ onChange={(event) => setDraft(event.target.value)}
+ onBlur={commit}
+ onKeyDown={(event) => {
+ if (event.key === 'Enter') {
+ commit()
+ }
+ }}
+ data-attr={dataAttr}
+ />
+ {suffix && (
+ <InputGroupAddon align="inline-end">
+ <InputGroupText>{suffix}</InputGroupText>
+ </InputGroupAddon>
+ )}
+ </InputGroup>
+ </div>
+ {/* An input has no disabledReason, so the reason sits under it instead of in a tooltip. */}
+ {disabledReason && <FieldDescription>{disabledReason}</FieldDescription>}
+ </Field>
+ )
+}
diff --git a/frontend/src/lib/components/ChartOptions/QuillChartOptionPages.tsx b/frontend/src/lib/components/ChartOptions/QuillChartOptionPages.tsx
new file mode 100644
index 000000000000..a06ad2391ef0
--- /dev/null
+++ b/frontend/src/lib/components/ChartOptions/QuillChartOptionPages.tsx
@@ -0,0 +1,116 @@
+import { ReactNode, useLayoutEffect, useRef, useState } from 'react'
+
+import { IconChevronLeft, IconChevronRight } from '@posthog/icons'
+import { Badge, Button, Separator, Text, cn } from '@posthog/quill'
+
+export interface ChartOptionPage {
+ key: string
+ title: string
+ // Options on the page set away from their default, shown on its row so none goes unnoticed.
+ count: number
+ content: ReactNode
+}
+
+export interface QuillChartOptionPagesProps {
+ home: ReactNode
+ pages: ChartOptionPage[]
+ className?: string
+ 'data-attr'?: string
+}
+
+export function QuillChartOptionPages({
+ home,
+ pages,
+ className,
+ 'data-attr': dataAttr,
+}: QuillChartOptionPagesProps): JSX.Element {
+ const [openKey, setOpenKey] = useState<string | null>(null)
+ const backRef = useRef<HTMLButtonElement>(null)
+ const rowRefs = useRef(new Map<string, HTMLButtonElement>())
+ const returnFocusKey = useRef<string | null>(null)
+ // A chart type change can remove the open page, so fall back to the list.
+ const openPage = pages.find((page) => page.key === openKey)
+ // Callers rebuild `pages` on every render, so focus follows the key, not the page object.
+ const openPageKey = openPage?.key ?? null
+
+ useLayoutEffect(() => {
+ if (openPageKey) {
+ backRef.current?.focus()
+ } else if (returnFocusKey.current) {
+ rowRefs.current.get(returnFocusKey.current)?.focus()
+ returnFocusKey.current = null
+ }
+ }, [openPageKey])
+
+ const goBack = (): void => {
+ returnFocusKey.current = openKey
+ setOpenKey(null)
+ }
+
+ if (openPage) {
+ return (
+ <div className={cn('flex flex-col gap-2', className)} data-attr={dataAttr}>
+ <div className="-ms-1 flex items-center gap-1">
+ <Button
+ ref={backRef}
+ size="icon-sm"
+ aria-label="Back to all options"
+ tooltip="Back to all options"
+ onClick={goBack}
+ data-attr="chart-option-pages-back"
+ >
+ <IconChevronLeft />
+ </Button>
+ <Text size="sm" weight="semibold" render={<span />} className="min-w-0 truncate">
+ {openPage.title}
+ </Text>
+ </div>
+ <div className="flex flex-col gap-2" data-attr={`chart-option-page-${openPage.key}`}>
+ {openPage.content}
+ </div>
+ </div>
+ )
+ }
+
+ return (
+ <div className={cn('flex flex-col gap-2', className)} data-attr={dataAttr}>
+ {home}
+ {pages.length > 0 && (
+ <>
+ {home && <Separator />}
+ <div className="flex flex-col">
+ {pages.map((page) => (
+ <Button
+ key={page.key}
+ ref={(node) => {
+ if (node) {
+ rowRefs.current.set(page.key, node)
+ } else {
+ rowRefs.current.delete(page.key)
+ }
+ }}
+ size="row"
+ left
+ // Bleeds into the panel's padding so the row text lines up with the option labels.
+ className="-mx-2 w-auto"
+ aria-label={page.count > 0 ? `${page.title}, ${page.count} changed` : page.title}
+ onClick={() => setOpenKey(page.key)}
+ data-attr={`chart-option-page-row-${page.key}`}
+ >
+ <span className="min-w-0 truncate">{page.title}</span>
+ {page.count > 0 && (
+ <Badge className="ml-auto" aria-hidden>
+ {page.count}
+ </Badge>
+ )}
+ <IconChevronRight
+ className={cn('text-muted-foreground', page.count === 0 && 'ml-auto')}
+ />
+ </Button>
+ ))}
+ </div>
+ </>
+ )}
+ </div>
+ )
+}
diff --git a/frontend/src/lib/components/ChartOptions/QuillChartOptionSelect.tsx b/frontend/src/lib/components/ChartOptions/QuillChartOptionSelect.tsx
new file mode 100644
index 000000000000..527c24791a4f
--- /dev/null
+++ b/frontend/src/lib/components/ChartOptions/QuillChartOptionSelect.tsx
@@ -0,0 +1,47 @@
+import { useId } from 'react'
+
+import { Button, Field, Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@posthog/quill'
+
+import type { ChartOptionSelectProps } from './ChartOptionSelect'
+import { QuillChartOptionLabel } from './QuillChartOptionLabel'
+
+export function QuillChartOptionSelect<T extends string | number>({
+ label,
+ info,
+ value,
+ options,
+ onChange,
+ disabledReason,
+ 'data-attr': dataAttr,
+}: ChartOptionSelectProps<T>): JSX.Element {
+ const id = useId()
+
+ return (
+ <Field orientation="horizontal" className="justify-between">
+ {label && <QuillChartOptionLabel htmlFor={id} label={label} info={info} />}
+ <Select<T>
+ value={value}
+ onValueChange={(next: T | null) => next !== null && onChange(next)}
+ disabled={!!disabledReason}
+ >
+ <SelectTrigger
+ id={id}
+ className={label ? undefined : 'w-full'}
+ render={<Button variant="outline" left disabledReason={disabledReason || undefined} />}
+ data-attr={dataAttr}
+ >
+ <SelectValue>
+ {(selected: T) => options.find((option) => option.value === selected)?.label ?? selected}
+ </SelectValue>
+ </SelectTrigger>
+ <SelectContent align="start" alignItemWithTrigger={false}>
+ {options.map((option) => (
+ <SelectItem key={String(option.value)} value={option.value}>
+ {option.label}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ </Field>
+ )
+}
diff --git a/frontend/src/lib/components/ChartOptions/QuillChartOptionSwitch.tsx b/frontend/src/lib/components/ChartOptions/QuillChartOptionSwitch.tsx
new file mode 100644
index 000000000000..300bf999ba41
--- /dev/null
+++ b/frontend/src/lib/components/ChartOptions/QuillChartOptionSwitch.tsx
@@ -0,0 +1,31 @@
+import { useId } from 'react'
+
+import { Field, Switch } from '@posthog/quill'
+
+import type { ChartOptionSwitchProps } from './ChartOptionSwitch'
+import { QuillChartOptionLabel } from './QuillChartOptionLabel'
+
+export function QuillChartOptionSwitch({
+ label,
+ info,
+ checked,
+ onChange,
+ disabledReason,
+ 'data-attr': dataAttr,
+}: ChartOptionSwitchProps): JSX.Element {
+ const id = useId()
+
+ return (
+ <Field orientation="horizontal" className="min-h-6 justify-between">
+ <QuillChartOptionLabel htmlFor={id} label={label} info={info} />
+ <Switch
+ id={id}
+ size="sm"
+ checked={checked}
+ onCheckedChange={(next: boolean) => onChange(next)}
+ disabledReason={disabledReason || undefined}
+ data-attr={dataAttr}
+ />
+ </Field>
+ )
+}
diff --git a/frontend/src/lib/components/ChartOptions/QuillChartOptionTextInput.tsx b/frontend/src/lib/components/ChartOptions/QuillChartOptionTextInput.tsx
new file mode 100644
index 000000000000..b216b694963c
--- /dev/null
+++ b/frontend/src/lib/components/ChartOptions/QuillChartOptionTextInput.tsx
@@ -0,0 +1,44 @@
+import { useId } from 'react'
+
+import { Field, Input } from '@posthog/quill'
+
+import type { ChartOptionTextInputProps } from './ChartOptionTextInput'
+import { QuillChartOptionLabel } from './QuillChartOptionLabel'
+
+export interface QuillChartOptionTextInputProps extends ChartOptionTextInputProps {
+ draft: string
+ setDraft: (draft: string) => void
+ commit: () => void
+}
+
+export function QuillChartOptionTextInput({
+ label,
+ info,
+ placeholder,
+ draft,
+ setDraft,
+ commit,
+ 'data-attr': dataAttr,
+}: QuillChartOptionTextInputProps): JSX.Element {
+ const id = useId()
+
+ return (
+ <Field orientation="horizontal" className="justify-between">
+ {label && <QuillChartOptionLabel htmlFor={id} label={label} info={info} />}
+ <Input
+ id={id}
+ className={label ? 'w-28' : undefined}
+ value={draft}
+ placeholder={placeholder}
+ onChange={(event) => setDraft(event.target.value)}
+ onBlur={commit}
+ onKeyDown={(event) => {
+ if (event.key === 'Enter') {
+ commit()
+ }
+ }}
+ data-attr={dataAttr}
+ />
+ </Field>
+ )
+}
diff --git a/frontend/src/lib/components/ChartOptions/QuillChartOptionToggleGroup.tsx b/frontend/src/lib/components/ChartOptions/QuillChartOptionToggleGroup.tsx
new file mode 100644
index 000000000000..693c9864d1b0
--- /dev/null
+++ b/frontend/src/lib/components/ChartOptions/QuillChartOptionToggleGroup.tsx
@@ -0,0 +1,46 @@
+import { useId } from 'react'
+
+import { Field, ToggleGroup, ToggleGroupItem } from '@posthog/quill'
+
+import type { ChartOptionToggleGroupProps } from './ChartOptionToggleGroup'
+import { QuillChartOptionLabel } from './QuillChartOptionLabel'
+
+export function QuillChartOptionToggleGroup<T extends string | number>({
+ label,
+ info,
+ value,
+ options,
+ onChange,
+ disabledReason,
+ 'data-attr': dataAttr,
+}: ChartOptionToggleGroupProps<T>): JSX.Element {
+ const id = useId()
+
+ return (
+ <Field data-attr={dataAttr}>
+ {label && <QuillChartOptionLabel htmlFor={id} label={label} info={info} />}
+ <ToggleGroup
+ id={id}
+ className="w-full"
+ value={[String(value)]}
+ onValueChange={(next: string[]) => {
+ const picked = options.find((option) => String(option.value) === next[0])
+ if (picked) {
+ onChange(picked.value)
+ }
+ }}
+ >
+ {options.map((option) => (
+ <ToggleGroupItem
+ key={String(option.value)}
+ value={String(option.value)}
+ className="flex-1"
+ disabledReason={disabledReason || undefined}
+ >
+ {option.label}
+ </ToggleGroupItem>
+ ))}
+ </ToggleGroup>
+ </Field>
+ )
+}
diff --git a/frontend/src/lib/components/ChartOptions/buildDisplayOptions.tsx b/frontend/src/lib/components/ChartOptions/buildDisplayOptions.tsx
index 8b1190ba2820..f8748572533d 100644
--- a/frontend/src/lib/components/ChartOptions/buildDisplayOptions.tsx
+++ b/frontend/src/lib/components/ChartOptions/buildDisplayOptions.tsx
@@ -150,11 +150,20 @@ export function buildDisplayOptions<C>(
continue
}
const group = definition.group
+ const changed = Number(binding.changedCount?.(c) ?? 0)
shownByGroup.set(group, [
...(shownByGroup.get(group) ?? []),
- { definition, item: { name, element: renderOption(definition, binding, c) } },
+ {
+ definition,
+ item: {
+ name,
+ element: renderOption(definition, binding, c),
+ changed,
+ advanced: !!definition.advanced,
+ },
+ },
])
- countByGroup.set(group, (countByGroup.get(group) ?? 0) + Number(binding.changedCount?.(c) ?? 0))
+ countByGroup.set(group, (countByGroup.get(group) ?? 0) + changed)
}
const groupSections = (group: (typeof DISPLAY_OPTION_GROUPS)[number]): DisplayOptionSection[] => {
@@ -169,11 +178,12 @@ export function buildDisplayOptions<C>(
isFirstRun
? {
key: group.key,
+ group: group.key,
title: overrides[group.key]?.title ?? ('title' in group ? group.title : undefined),
dataAttr: 'dataAttr' in group ? group.dataAttr : undefined,
items: run,
}
- : { key: `${group.key}-${sections.length}`, items: run }
+ : { key: `${group.key}-${sections.length}`, group: group.key, items: run }
)
run = []
}
@@ -182,6 +192,7 @@ export function buildDisplayOptions<C>(
flushRun()
sections.push({
key: definition.name,
+ group: group.key,
title: definition.label,
tooltip: definition.info,
items: [item],
diff --git a/frontend/src/lib/components/ChartOptions/displayOptionPages.test.ts b/frontend/src/lib/components/ChartOptions/displayOptionPages.test.ts
new file mode 100644
index 000000000000..f75c7430fe92
--- /dev/null
+++ b/frontend/src/lib/components/ChartOptions/displayOptionPages.test.ts
@@ -0,0 +1,61 @@
+import { displayOptionPages } from './displayOptionPages'
+import type { DisplayOptionName, DisplayOptionTab } from './displayOptions'
+
+const item = (
+ name: DisplayOptionName,
+ { changed = 0, advanced = false } = {}
+): DisplayOptionTab['sections'][number]['items'][number] => ({
+ name,
+ element: null,
+ changed,
+ advanced,
+})
+
+describe('displayOptionPages', () => {
+ it('keeps common options on the list and puts the rest one step away', () => {
+ const tabs: DisplayOptionTab[] = [
+ {
+ key: 'general',
+ label: 'General',
+ count: 2,
+ sections: [
+ {
+ key: 'display',
+ group: 'display',
+ items: [item('legend', { changed: 1 }), item('annotations', { changed: 1, advanced: true })],
+ },
+ ],
+ },
+ {
+ key: 'axes',
+ label: 'Axes',
+ count: 1,
+ sections: [
+ { key: 'x-axis', group: 'x-axis', title: 'X-axis', items: [item('xAxisLabel')] },
+ { key: 'y-axis', group: 'y-axis', title: 'Y-axis', items: [item('yAxisLabel', { changed: 1 })] },
+ ],
+ },
+ {
+ key: 'lines',
+ label: 'Lines',
+ count: 0,
+ sections: [
+ { key: 'style', group: 'style', title: 'Style', items: [item('lineStyle')] },
+ { key: 'overlays', group: 'overlays', title: 'Overlays', items: [item('trendLines')] },
+ ],
+ },
+ ]
+
+ const { home, pages } = displayOptionPages(tabs)
+
+ expect(home.flatMap((section) => section.items.map((option) => option.name))).toEqual(['legend'])
+ expect(pages.map(({ key, title, count }) => ({ key, title, count }))).toEqual([
+ { key: 'x-axis', title: 'X-axis', count: 0 },
+ { key: 'y-axis', title: 'Y-axis', count: 1 },
+ { key: 'lines', title: 'Lines', count: 0 },
+ { key: 'more', title: 'More options', count: 1 },
+ ])
+ expect(pages[1].sections[0].title).toBeUndefined()
+ expect(pages[2].sections.map((section) => section.title)).toEqual(['Style', 'Overlays'])
+ })
+})
diff --git a/frontend/src/lib/components/ChartOptions/displayOptionPages.ts b/frontend/src/lib/components/ChartOptions/displayOptionPages.ts
new file mode 100644
index 000000000000..4c08aef42424
--- /dev/null
+++ b/frontend/src/lib/components/ChartOptions/displayOptionPages.ts
@@ -0,0 +1,70 @@
+import type { DisplayOptionGroupKey, DisplayOptionSection, DisplayOptionTab } from './displayOptions'
+
+export interface DisplayOptionPage {
+ key: string
+ title: string
+ count: number
+ sections: DisplayOptionSection[]
+}
+
+export interface DisplayOptionPages {
+ home: DisplayOptionSection[]
+ pages: DisplayOptionPage[]
+}
+
+// Each axis is its own page; the line groups share one, like the "Lines" tab they replace.
+const PAGE_OF_GROUP: Record<Exclude<DisplayOptionGroupKey, 'display'>, { key: string; title?: string }> = {
+ 'x-axis': { key: 'x-axis' },
+ 'y-axis': { key: 'y-axis' },
+ 'right-y-axis': { key: 'right-y-axis' },
+ style: { key: 'lines', title: 'Lines' },
+ overlays: { key: 'lines', title: 'Lines' },
+}
+
+const changedIn = (sections: DisplayOptionSection[]): number =>
+ sections.reduce((sum, section) => sum + section.items.reduce((total, item) => total + item.changed, 0), 0)
+
+// Splits the options into the ones shown straight away and pages one step away, for the quill panels.
+export function displayOptionPages(tabs: DisplayOptionTab[]): DisplayOptionPages {
+ const sections = tabs.flatMap((tab) => tab.sections)
+ const home: DisplayOptionSection[] = []
+ const more: DisplayOptionSection[] = []
+ const pages: DisplayOptionPage[] = []
+
+ for (const section of sections) {
+ if (section.group === 'display') {
+ const common = section.items.filter((item) => !item.advanced)
+ const advanced = section.items.filter((item) => item.advanced)
+ if (common.length > 0) {
+ home.push({ ...section, items: common })
+ }
+ if (advanced.length > 0) {
+ more.push({ ...section, items: advanced })
+ }
+ continue
+ }
+ const { key, title } = PAGE_OF_GROUP[section.group]
+ const page = pages.find((existing) => existing.key === key)
+ if (page) {
+ page.sections.push(section)
+ } else {
+ pages.push({ key, title: title ?? section.title ?? key, count: 0, sections: [section] })
+ }
+ }
+
+ if (more.length > 0) {
+ pages.push({ key: 'more', title: 'More options', count: 0, sections: more })
+ }
+
+ return {
+ home,
+ pages: pages.map((page) => ({
+ ...page,
+ // The page header already names its axis.
+ sections: page.sections.map((section) =>
+ section.title === page.title ? { ...section, title: undefined } : section
+ ),
+ count: changedIn(page.sections),
+ })),
+ }
+}
diff --git a/frontend/src/lib/components/ChartOptions/displayOptions.ts b/frontend/src/lib/components/ChartOptions/displayOptions.ts
index d521ccd34079..2947b2f50c4a 100644
--- a/frontend/src/lib/components/ChartOptions/displayOptions.ts
+++ b/frontend/src/lib/components/ChartOptions/displayOptions.ts
@@ -47,6 +47,8 @@ interface DisplayOptionDefinitionBase {
stacked?: boolean
// Indented under the option above it, which it refines.
nested?: boolean
+ // Rarely set, so the quill panels keep it one step away under "More options".
+ advanced?: boolean
}
export type DisplayOptionDefinition = DisplayOptionDefinitionBase &
@@ -74,6 +76,7 @@ export const DISPLAY_OPTIONS = [
name: 'metricSummary',
label: 'Headline value',
group: 'display',
+ advanced: true,
control: 'select',
options: [
{ value: 'total', label: 'Total' },
@@ -81,27 +84,43 @@ export const DISPLAY_OPTIONS = [
{ value: 'latest', label: 'Latest' },
],
},
- { name: 'metricShowChange', label: 'Show change', group: 'display', control: 'checkbox' },
- { name: 'metricChangeColors', label: 'Change colors', nested: true, group: 'display', control: 'colors' },
- { name: 'metricColorByDirection', label: 'Color by trend', group: 'display', control: 'checkbox' },
- { name: 'metricTrendColors', label: 'Trend colors', nested: true, group: 'display', control: 'colors' },
+ { name: 'metricShowChange', label: 'Show change', group: 'display', advanced: true, control: 'checkbox' },
+ {
+ name: 'metricChangeColors',
+ label: 'Change colors',
+ nested: true,
+ group: 'display',
+ advanced: true,
+ control: 'colors',
+ },
+ { name: 'metricColorByDirection', label: 'Color by trend', group: 'display', advanced: true, control: 'checkbox' },
+ {
+ name: 'metricTrendColors',
+ label: 'Trend colors',
+ nested: true,
+ group: 'display',
+ advanced: true,
+ control: 'colors',
+ },
{ name: 'lifecycleStacking', label: 'Stack bars', group: 'display', control: 'checkbox' },
{ name: 'valuesOnSeries', label: 'Show values on series', group: 'display', control: 'checkbox' },
{
name: 'valueLabelPosition',
label: 'Value position',
group: 'display',
+ advanced: true,
control: 'select',
options: [
{ value: 'end', label: 'At the end' },
{ value: 'center', label: 'Inside' },
],
},
- { name: 'valueLabelBackground', label: 'Value background', group: 'display', control: 'checkbox' },
+ { name: 'valueLabelBackground', label: 'Value background', group: 'display', advanced: true, control: 'checkbox' },
{
name: 'valueLabelFontSize',
label: 'Value font size',
group: 'display',
+ advanced: true,
control: 'select',
options: [8, 10, 12, 14, 16, 20, 24, 32].map((value) => ({ value, label: `${value}px` })),
},
@@ -109,12 +128,13 @@ export const DISPLAY_OPTIONS = [
name: 'valueLabelRotation',
label: 'Value rotation',
group: 'display',
+ advanced: true,
control: 'select',
options: ROTATION_OPTIONS,
},
{ name: 'lifecyclePercentages', label: 'Show percentages on series', group: 'display', control: 'checkbox' },
- { name: 'percentStack', label: 'Show as % of total', group: 'display', control: 'checkbox' },
- { name: 'stackBreakdown', label: 'Stack breakdown values', group: 'display', control: 'checkbox' },
+ { name: 'percentStack', label: 'Show as % of total', group: 'display', advanced: true, control: 'checkbox' },
+ { name: 'stackBreakdown', label: 'Stack breakdown values', group: 'display', advanced: true, control: 'checkbox' },
{ name: 'sliceNames', label: 'Show names on slices', group: 'display', control: 'checkbox' },
{
name: 'pieSliceContent',
@@ -138,12 +158,13 @@ export const DISPLAY_OPTIONS = [
],
},
{ name: 'pieTotal', label: 'Show total', group: 'display', control: 'checkbox' },
- { name: 'showTotalRow', label: 'Show total row', group: 'display', control: 'checkbox' },
- { name: 'showNullsAsZero', label: 'Show nulls as zero', group: 'display', control: 'checkbox' },
+ { name: 'showTotalRow', label: 'Show total row', group: 'display', advanced: true, control: 'checkbox' },
+ { name: 'showNullsAsZero', label: 'Show nulls as zero', group: 'display', advanced: true, control: 'checkbox' },
{
name: 'barSpacing',
label: 'Bar spacing',
group: 'display',
+ advanced: true,
control: 'select',
options: [
{ value: 0, label: 'None' },
@@ -187,6 +208,7 @@ export const DISPLAY_OPTIONS = [
label: 'Annotations',
info: 'Annotations are saved on an insight, a dashboard, the project, or the organization. Choose which of those to show here.',
group: 'display',
+ advanced: true,
control: 'select',
options: [
{ value: 'all', label: 'All' },
@@ -204,6 +226,7 @@ export const DISPLAY_OPTIONS = [
info: "You can customize the appearance of individual results in your insights. This can be done based on the result's name (e.g., customize the breakdown value 'pizza' for the first series) or based on the result's rank (e.g., customize the first dataset in the results).",
stacked: true,
group: 'display',
+ advanced: true,
control: 'toggle',
options: [
{ value: ResultCustomizationBy.Value, label: 'By name' },
@@ -407,10 +430,14 @@ export type DisplayOptionBindings<C> = {
export interface DisplayOptionItem {
name: DisplayOptionName
element: ReactNode
+ // How many settings this option holds away from their default.
+ changed: number
+ advanced: boolean
}
export interface DisplayOptionSection {
key: string
+ group: DisplayOptionGroupKey
title?: string
tooltip?: string
dataAttr?: string
diff --git a/frontend/src/lib/components/UnitPicker/QuillUnitPicker.tsx b/frontend/src/lib/components/UnitPicker/QuillUnitPicker.tsx
new file mode 100644
index 000000000000..e40a1d82de18
--- /dev/null
+++ b/frontend/src/lib/components/UnitPicker/QuillUnitPicker.tsx
@@ -0,0 +1,65 @@
+import { ReactNode } from 'react'
+
+import {
+ Button,
+ DropdownMenu,
+ DropdownMenuCheckboxItem,
+ DropdownMenuContent,
+ DropdownMenuRadioGroup,
+ DropdownMenuRadioItem,
+ DropdownMenuSeparator,
+ DropdownMenuTrigger,
+ SelectTriggerIcon,
+} from '@posthog/quill'
+
+import { AggregationAxisFormat, INSIGHT_UNIT_OPTIONS } from 'lib/insights/aggregationAxisFormat'
+
+export interface QuillUnitPickerProps {
+ displayValue: ReactNode
+ format: AggregationAxisFormat | undefined
+ prefix: string | undefined
+ postfix: string | undefined
+ onFormatChange: (format: AggregationAxisFormat) => void
+ onCustomPrefix: () => void
+ onCustomPostfix: () => void
+}
+
+export function QuillUnitPicker({
+ displayValue,
+ format,
+ prefix,
+ postfix,
+ onFormatChange,
+ onCustomPrefix,
+ onCustomPostfix,
+}: QuillUnitPickerProps): JSX.Element {
+ return (
+ <DropdownMenu>
+ <DropdownMenuTrigger
+ render={<Button variant="outline" left className="w-full" data-attr="chart-aggregation-axis-format" />}
+ >
+ <span className="min-w-0 flex-1 truncate text-left">{displayValue}</span>
+ <SelectTriggerIcon />
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="start">
+ <DropdownMenuRadioGroup
+ value={format ?? ''}
+ onValueChange={(value: string) => onFormatChange(value as AggregationAxisFormat)}
+ >
+ {INSIGHT_UNIT_OPTIONS.map(({ value, label }) => (
+ <DropdownMenuRadioItem key={value} value={value}>
+ {label}
+ </DropdownMenuRadioItem>
+ ))}
+ </DropdownMenuRadioGroup>
+ <DropdownMenuSeparator />
+ <DropdownMenuCheckboxItem checked={!!prefix} onCheckedChange={onCustomPrefix}>
+ Custom prefix{prefix ? `: ${prefix}...` : '...'}
+ </DropdownMenuCheckboxItem>
+ <DropdownMenuCheckboxItem checked={!!postfix} onCheckedChange={onCustomPostfix}>
+ Custom postfix{postfix ? `: ${postfix}...` : '...'}
+ </DropdownMenuCheckboxItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ )
+}
diff --git a/frontend/src/lib/components/UnitPicker/UnitPicker.tsx b/frontend/src/lib/components/UnitPicker/UnitPicker.tsx
index 6df3fe54cd57..6333930d4102 100644
--- a/frontend/src/lib/components/UnitPicker/UnitPicker.tsx
+++ b/frontend/src/lib/components/UnitPicker/UnitPicker.tsx
@@ -1,6 +1,7 @@
import { useActions, useValues } from 'kea'
import { useMemo, useState } from 'react'
+import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
import { useKeyboardHotkeys } from 'lib/hooks/useKeyboardHotkeys'
import {
AggregationAxisFormat,
@@ -14,6 +15,7 @@ import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
import { insightLogic } from 'scenes/insights/insightLogic'
import { insightVizDataLogic } from 'scenes/insights/insightVizDataLogic'
+import { QuillUnitPicker } from './QuillUnitPicker'
import { unitPickerModalLogic } from './unitPickerModalLogic'
export interface HandleUnitChange {
@@ -30,6 +32,7 @@ export function UnitPicker(): JSX.Element {
const { showCustomUnitModal } = useActions(unitPickerModalLogic)
const { reportAxisUnitsChanged } = useActions(eventUsageLogic)
+ const todayRailNav = useFeatureFlag('TODAY_RAIL_NAV')
const [isVisible, setIsVisible] = useState(false)
const [localAxisFormat, setLocalAxisFormat] = useState(trendsFilter?.aggregationAxisFormat || undefined)
@@ -98,6 +101,20 @@ export function UnitPicker(): JSX.Element {
})
}
+ if (todayRailNav) {
+ return (
+ <QuillUnitPicker
+ displayValue={displayValue}
+ format={effectiveAxisFormat}
+ prefix={trendsFilter?.aggregationAxisPrefix}
+ postfix={trendsFilter?.aggregationAxisPostfix}
+ onFormatChange={(format) => handleChange({ format })}
+ onCustomPrefix={handleCustomPrefix}
+ onCustomPostfix={handleCustomPostfix}
+ />
+ )
+ }
+
return (
<div className="flex-1">
<LemonButtonWithDropdown
diff --git a/frontend/src/queries/nodes/DataVisualization/Components/DisplayTab.tsx b/frontend/src/queries/nodes/DataVisualization/Components/DisplayTab.tsx
index 96e76b9c45dc..84ad34640617 100644
--- a/frontend/src/queries/nodes/DataVisualization/Components/DisplayTab.tsx
+++ b/frontend/src/queries/nodes/DataVisualization/Components/DisplayTab.tsx
@@ -7,12 +7,14 @@ import { ChartOptionSections } from 'lib/components/ChartOptions/ChartOptionSect
import { useDisplayOptions } from 'lib/components/ChartOptions/useDisplayOptions'
import { GoalLinesList } from 'lib/components/GoalLinesList'
import { PART_OF_WHOLE_DISPLAY_TYPES } from 'lib/constants'
+import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
import { ChartDisplayType } from '~/types'
import { dataVisualizationLogic } from '../dataVisualizationLogic'
import { displayLogic } from '../displayLogic'
import { DisplayTabPanel, DisplayTabPanels } from './DisplayTabPanels'
+import { QuillDisplayTab } from './QuillDisplayTab'
import { sqlDisplayOptions } from './sqlDisplayOptions'
export const DisplayTab = (): JSX.Element => {
@@ -20,6 +22,7 @@ export const DisplayTab = (): JSX.Element => {
const { goalLines, chartSettings, query } = useValues(displayLogic)
const { addGoalLine, updateGoalLine, removeGoalLine } = useActions(displayLogic)
const { tabs } = useDisplayOptions(sqlDisplayOptions)
+ const todayRailNav = useFeatureFlag('TODAY_RAIL_NAV')
const isStackedBarChart = effectiveVisualizationType === ChartDisplayType.ActionsStackedBar
const isBIVisualization = query.kind === 'BIVisualizationNode'
@@ -51,42 +54,58 @@ export const DisplayTab = (): JSX.Element => {
},
]
)
+ const goalLinesTitle = isBIVisualization ? 'Reference lines' : 'Goal lines'
+ const goalLinesContent = (
+ <>
+ <GoalLinesList
+ allowCalculations={isBIVisualization}
+ calculationDisabledReason={
+ isStackedBarChart && chartSettings.stackBars100
+ ? 'Calculated lines are hidden on 100% stacked charts. Use a constant or turn off percentage stacking.'
+ : undefined
+ }
+ goalLines={goalLines}
+ removeGoalLine={removeGoalLine}
+ updateGoalLine={updateGoalLine}
+ />
+ <LemonButton onClick={addGoalLine} icon={<IconPlusSmall />} fullWidth>
+ {isBIVisualization ? 'Add reference line' : 'Add goal line'}
+ </LemonButton>
+ {isBIVisualization && (
+ <p className="text-xs text-secondary mb-0">
+ Calculations use returned marks on the left axis after aggregation and table calculations. Per
+ series adds a line for each color group or measure. Result limits apply.
+ {isStackedBarChart && chartSettings.stackBars100 && (
+ <span> Calculated lines are hidden on 100% stacked charts.</span>
+ )}
+ </p>
+ )}
+ </>
+ )
+
+ if (todayRailNav) {
+ return (
+ <QuillDisplayTab
+ tabs={tabs}
+ goalLines={
+ supportsGoalLines
+ ? { title: goalLinesTitle, count: goalLines.length, content: goalLinesContent }
+ : null
+ }
+ />
+ )
+ }
+
if (supportsGoalLines) {
panels.push({
key: 'goals',
header: (
<div className="flex items-center gap-1 flex-1">
- <span className="flex-1">{isBIVisualization ? 'Reference lines' : 'Goal lines'}</span>
+ <span className="flex-1">{goalLinesTitle}</span>
{goalLines.length > 0 && <LemonBadge.Number status="muted" size="small" count={goalLines.length} />}
</div>
),
- content: (
- <>
- <GoalLinesList
- allowCalculations={isBIVisualization}
- calculationDisabledReason={
- isStackedBarChart && chartSettings.stackBars100
- ? 'Calculated lines are hidden on 100% stacked charts. Use a constant or turn off percentage stacking.'
- : undefined
- }
- goalLines={goalLines}
- removeGoalLine={removeGoalLine}
- updateGoalLine={updateGoalLine}
- />
- <LemonButton onClick={addGoalLine} icon={<IconPlusSmall />} fullWidth>
- {isBIVisualization ? 'Add reference line' : 'Add goal line'}
- </LemonButton>
- {isBIVisualization && (
- <p className="text-xs text-secondary mb-0">
- Calculations use returned marks on the left axis after aggregation and table calculations.
- Per series adds a line for each color group or measure. Result limits apply.
- {isStackedBarChart && chartSettings.stackBars100 && (
- <span> Calculated lines are hidden on 100% stacked charts.</span>
- )}
- </p>
- )}
- </>
- ),
+ content: goalLinesContent,
})
}
diff --git a/frontend/src/queries/nodes/DataVisualization/Components/QuillDisplayTab.tsx b/frontend/src/queries/nodes/DataVisualization/Components/QuillDisplayTab.tsx
new file mode 100644
index 000000000000..30a54b9059aa
--- /dev/null
+++ b/frontend/src/queries/nodes/DataVisualization/Components/QuillDisplayTab.tsx
@@ -0,0 +1,35 @@
+import { ReactNode } from 'react'
+
+import { ChartOptionSections } from 'lib/components/ChartOptions/ChartOptionSections'
+import { displayOptionPages } from 'lib/components/ChartOptions/displayOptionPages'
+import { DisplayOptionTab } from 'lib/components/ChartOptions/displayOptions'
+import { ChartOptionPage, QuillChartOptionPages } from 'lib/components/ChartOptions/QuillChartOptionPages'
+
+export interface QuillDisplayTabProps {
+ tabs: DisplayOptionTab[]
+ goalLines: { title: string; count: number; content: ReactNode } | null
+}
+
+export function QuillDisplayTab({ tabs, goalLines }: QuillDisplayTabProps): JSX.Element {
+ const { home, pages } = displayOptionPages(tabs)
+ const optionPages: ChartOptionPage[] = pages.map((page) => ({
+ key: page.key,
+ title: page.title,
+ count: page.count,
+ content: <ChartOptionSections sections={page.sections} />,
+ }))
+ if (goalLines) {
+ // Before "More options", which stays last.
+ const moreIndex = optionPages.findIndex((page) => page.key === 'more')
+ optionPages.splice(moreIndex === -1 ? optionPages.length : moreIndex, 0, { key: 'goals', ...goalLines })
+ }
+
+ return (
+ <QuillChartOptionPages
+ className="p-3"
+ data-attr="sql-display-options-panel"
+ home={home.length > 0 ? <ChartOptionSections sections={home} /> : null}
+ pages={optionPages}
+ />
+ )
+}
diff --git a/frontend/src/queries/nodes/DataVisualization/Components/sqlDisplayOptions.tsx b/frontend/src/queries/nodes/DataVisualization/Components/sqlDisplayOptions.tsx
index fd8541cd6e9f..6eb3a2a01026 100644
--- a/frontend/src/queries/nodes/DataVisualization/Components/sqlDisplayOptions.tsx
+++ b/frontend/src/queries/nodes/DataVisualization/Components/sqlDisplayOptions.tsx
@@ -10,6 +10,7 @@ import {
METRIC_SHOW_CHANGE_DEFAULT,
} from 'lib/components/Metric/metricSummary'
import { PART_OF_WHOLE_DISPLAY_TYPES, PIE_DISPLAY_TYPES } from 'lib/constants'
+import { objectsEqual } from 'lib/utils/objects'
import { ChartDisplayType } from '~/types'
@@ -40,6 +41,7 @@ interface SqlDisplayContext
showsSeriesOptions: boolean
showsRightYAxis: boolean
showLegend: boolean
+ legendShownByDefault: boolean
}
function useSqlDisplayContext(): SqlDisplayContext {
@@ -88,6 +90,7 @@ function useSqlDisplayContext(): SqlDisplayContext {
showsSeriesOptions: showsAxes && !isSingleAxisChart,
showsRightYAxis: showsAxes && !isSingleAxisChart && !isHorizontalBarChart,
showLegend: chartSettings.showLegend ?? showsLegendByDefault(isProportionBar, proportionBarPartCount),
+ legendShownByDefault: showsLegendByDefault(isProportionBar, proportionBarPartCount),
}
}
@@ -200,10 +203,9 @@ const SQL_BINDINGS: DisplayOptionBindings<SqlDisplayContext> = {
onChange: (showLegend, c) => c.updateChartSettings({ showLegend }),
},
legendPosition: {
- showCondition: (c) => !c.isMetric,
+ showCondition: (c) => !c.isMetric && c.showLegend,
value: (c) => c.chartSettings.legendPosition ?? (c.isProportionBar ? 'bottom' : c.isPieChart ? 'right' : 'top'),
onChange: (legendPosition, c) => c.updateChartSettings({ legendPosition }),
- disabledReason: (c) => (c.showLegend ? undefined : 'Turn the legend on to set its position'),
},
excludeOutliers: {
showCondition: (c) => c.isBoxPlot,
@@ -342,9 +344,32 @@ const SQL_BINDINGS: DisplayOptionBindings<SqlDisplayContext> = {
}
// The SQL editor's Display tab and the options menu on a dashboard tile for a SQL chart.
+// SQL charts keep no per-option defaults, so an option counts as changed when it reads differently
+// from the same chart with no saved settings.
+function withChangedCounts(
+ bindings: DisplayOptionBindings<SqlDisplayContext>
+): DisplayOptionBindings<SqlDisplayContext> {
+ const unsaved = (c: SqlDisplayContext): SqlDisplayContext => ({
+ ...c,
+ chartSettings: {},
+ showLegend: c.legendShownByDefault,
+ })
+ return Object.fromEntries(
+ Object.entries(bindings).map(([name, binding]) => {
+ const value = binding.value as ((c: SqlDisplayContext) => unknown) | undefined
+ return [
+ name,
+ value && !binding.changedCount
+ ? { ...binding, changedCount: (c: SqlDisplayContext) => !objectsEqual(value(c), value(unsaved(c))) }
+ : binding,
+ ]
+ })
+ ) as DisplayOptionBindings<SqlDisplayContext>
+}
+
export const sqlDisplayOptions: DisplayOptionsAdapter<SqlDisplayContext> = {
useDisplayContext: useSqlDisplayContext,
- bindings: SQL_BINDINGS,
+ bindings: withChangedCounts(SQL_BINDINGS),
settings: (c) => {
// The horizontal bar chart swaps its axes, so the category axis is the Y-axis there.
const categoryAxisName = c.isHorizontalBarChart ? 'Y-axis' : 'X-axis'
diff --git a/products/product_analytics/frontend/insights/editor/InsightDisplayConfig.test.tsx b/products/product_analytics/frontend/insights/editor/InsightDisplayConfig.test.tsx
index 4f51d2a00fa2..d4ed61c8de63 100644
--- a/products/product_analytics/frontend/insights/editor/InsightDisplayConfig.test.tsx
+++ b/products/product_analytics/frontend/insights/editor/InsightDisplayConfig.test.tsx
@@ -53,11 +53,14 @@ function makeRetentionQuery(retentionFilter: NonNullable<RetentionQuery['retenti
return { kind: NodeKind.RetentionQuery, retentionFilter }
}
-function makeStickinessQuery(display?: ChartDisplayType): StickinessQuery {
+function makeStickinessQuery(
+ display?: ChartDisplayType,
+ stickinessFilter: NonNullable<StickinessQuery['stickinessFilter']> = {}
+): StickinessQuery {
return {
kind: NodeKind.StickinessQuery,
series: [...pageviewSeries],
- stickinessFilter: { display },
+ stickinessFilter: { display, ...stickinessFilter },
}
}
@@ -169,7 +172,7 @@ describe('InsightDisplayConfig', () => {
Axes: ['X-axis', 'Y-axis'],
Lines: ['Style', 'Overlays'],
},
- displayItems: ['Show values on series', 'Show legend', 'Legend positionBottom', 'Annotations All'],
+ displayItems: ['Show values on series', 'Show legend', 'Annotations All'],
overlayItems: lineOverlays,
},
],
@@ -183,13 +186,7 @@ describe('InsightDisplayConfig', () => {
Axes: ['X-axis', 'Y-axis'],
Lines: ['Overlays'],
},
- displayItems: [
- 'Show values on series',
- 'Show as % of total',
- 'Show legend',
- 'Legend positionBottom',
- 'Annotations All',
- ],
+ displayItems: ['Show values on series', 'Show as % of total', 'Show legend', 'Annotations All'],
overlayItems: lineOverlays,
},
],
@@ -203,13 +200,7 @@ describe('InsightDisplayConfig', () => {
Axes: ['X-axis', 'Y-axis'],
Lines: ['Style', 'Overlays'],
},
- displayItems: [
- 'Show values on series',
- 'Show as % of total',
- 'Show legend',
- 'Legend positionBottom',
- 'Annotations All',
- ],
+ displayItems: ['Show values on series', 'Show as % of total', 'Show legend', 'Annotations All'],
},
],
[
@@ -228,9 +219,7 @@ describe('InsightDisplayConfig', () => {
'Show as % of total',
'Show names on slices',
'Show total',
- // In-chart legend toggle + position select ("Bottom" is the prospective default)
'Show legend',
- 'Legend positionBottom',
],
},
],
@@ -246,7 +235,6 @@ describe('InsightDisplayConfig', () => {
'Show names on slices',
'Show total',
'Show legend',
- 'Legend positionBottom',
],
},
],
@@ -300,7 +288,7 @@ describe('InsightDisplayConfig', () => {
{
tabs: [],
sections: { General: ['Y-axis', 'Style'] },
- displayItems: ['Show values on series', 'Show legend', 'Legend positionBottom'],
+ displayItems: ['Show values on series', 'Show legend'],
},
],
['stickiness table', makeStickinessQuery(ChartDisplayType.ActionsTable), { tabs: [], sections: {} }],
@@ -472,30 +460,28 @@ describe('InsightDisplayConfig', () => {
})
describe('in-chart legend position options', () => {
- it('shows the "Show legend" toggle with a position select', async () => {
+ it('hides the position select while the legend is off', async () => {
setupAndRender(makeTrendsQuery(ChartDisplayType.ActionsLineGraph))
await openOptionsMenu()
const items = getDisplaySectionItems()
expect(items).toContain('Show legend')
- // legend is off, no saved position → shows 'Bottom' as the prospective default
- expect(items).toContain('Legend positionBottom')
+ expect(items.some((item) => item.startsWith('Legend position'))).toBe(false)
})
it.each([
- ['trends bar', () => makeTrendsQuery(ChartDisplayType.ActionsBar)],
- ['trends unstacked bar', () => makeTrendsQuery(ChartDisplayType.ActionsUnstackedBar)],
- ['trends pie', () => makeTrendsQuery(ChartDisplayType.ActionsPie)],
- ['stickiness line', () => makeStickinessQuery(ChartDisplayType.ActionsLineGraph)],
- ['stickiness bar', () => makeStickinessQuery(ChartDisplayType.ActionsBar)],
+ ['trends line', () => makeTrendsQuery(ChartDisplayType.ActionsLineGraph, { showLegend: true })],
+ ['trends bar', () => makeTrendsQuery(ChartDisplayType.ActionsBar, { showLegend: true })],
+ ['trends unstacked bar', () => makeTrendsQuery(ChartDisplayType.ActionsUnstackedBar, { showLegend: true })],
+ ['trends pie', () => makeTrendsQuery(ChartDisplayType.ActionsPie, { showLegend: true })],
+ ['stickiness line', () => makeStickinessQuery(ChartDisplayType.ActionsLineGraph, { showLegend: true })],
+ ['stickiness bar', () => makeStickinessQuery(ChartDisplayType.ActionsBar, { showLegend: true })],
['lifecycle', () => makeLifecycleQuery()],
- ])('adds the legend position select for %s', async (_desc, makeQuery) => {
+ ])('adds the legend position select for %s once the legend is on', async (_desc, makeQuery) => {
setupAndRender(makeQuery())
await openOptionsMenu()
- const positionItem = getDisplaySectionItems().find((item) => item.startsWith('Legend position'))
- // Lifecycle sets showLegend:true (no saved position → 'Right'); others have legend off (→ 'Bottom').
- expect(positionItem).toMatch(/Bottom|Right/)
+ expect(getDisplaySectionItems()).toContain('Legend positionRight')
})
it('keeps the plain "Show legend" toggle for the aggregated bar-value chart', async () => {
diff --git a/products/product_analytics/frontend/insights/editor/InsightDisplayConfig.tsx b/products/product_analytics/frontend/insights/editor/InsightDisplayConfig.tsx
index 4530acd08591..27cbaa726883 100644
--- a/products/product_analytics/frontend/insights/editor/InsightDisplayConfig.tsx
+++ b/products/product_analytics/frontend/insights/editor/InsightDisplayConfig.tsx
@@ -9,6 +9,7 @@ import { useDisplayOptions } from 'lib/components/ChartOptions/useDisplayOptions
import { CompareFilter } from 'lib/components/CompareFilter/CompareFilter'
import { IntervalFilter } from 'lib/components/IntervalFilter'
import { NON_TIME_SERIES_DISPLAY_TYPES } from 'lib/constants'
+import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
import { LemonDropdown } from 'lib/lemon-ui/LemonDropdown'
import { alignResolvedDateRangeToInterval, formatResolvedDateRange } from 'lib/utils/datetime'
import { insightLogic } from 'scenes/insights/insightLogic'
@@ -29,6 +30,7 @@ import { RetentionDatePicker } from 'products/product_analytics/frontend/insight
import { insightDisplayOptions } from './insightDisplayOptions'
import { InsightDisplayOptionsPanel } from './InsightDisplayOptionsPanel'
+import { QuillInsightDisplayOptionsButton } from './QuillInsightDisplayOptionsButton'
export function InsightDisplayConfig({ chartTypeControl }: { chartTypeControl?: ReactNode }): JSX.Element {
const { insightProps, canEditInsight, editingDisabledReason } = useValues(insightLogic)
@@ -73,6 +75,7 @@ export function InsightDisplayConfig({ chartTypeControl }: { chartTypeControl?:
((isTrends || isStickiness) && !(display && NON_TIME_SERIES_DISPLAY_TYPES.includes(display)))
const { tabs: displayOptionTabs, count: advancedOptionsCount } = useDisplayOptions(insightDisplayOptions)
+ const todayRailNav = useFeatureFlag('TODAY_RAIL_NAV')
return (
<div
@@ -120,44 +123,51 @@ export function InsightDisplayConfig({ chartTypeControl }: { chartTypeControl?:
)}
</div>
<div className="flex items-center gap-x-2">
- {displayOptionTabs.length > 0 && (
- <>
- <LemonDropdown
- overlay={<InsightDisplayOptionsPanel tabs={displayOptionTabs} />}
- closeOnClickInside={false}
- placement="bottom-end"
- >
- <LemonButton
- size="small"
- disabledReason={editingDisabledReason}
- aria-label="Options"
- className="@max-[780px]:hidden"
+ {displayOptionTabs.length > 0 &&
+ (todayRailNav ? (
+ <QuillInsightDisplayOptionsButton
+ tabs={displayOptionTabs}
+ advancedOptionsCount={advancedOptionsCount}
+ disabledReason={editingDisabledReason}
+ />
+ ) : (
+ <>
+ <LemonDropdown
+ overlay={<InsightDisplayOptionsPanel tabs={displayOptionTabs} />}
+ closeOnClickInside={false}
+ placement="bottom-end"
>
- <span className="font-medium whitespace-nowrap">
- Options
- {advancedOptionsCount ? (
- <span className="ml-0.5 text-secondary ligatures-none">
- ({advancedOptionsCount})
- </span>
- ) : null}
- </span>
- </LemonButton>
- </LemonDropdown>
- <LemonDropdown
- overlay={<InsightDisplayOptionsPanel tabs={displayOptionTabs} />}
- closeOnClickInside={false}
- placement="bottom-end"
- >
- <LemonButton
- size="small"
- disabledReason={editingDisabledReason}
- icon={<IconEllipsis />}
- aria-label="Options"
- className="hidden @max-[780px]:flex order-[999]"
- />
- </LemonDropdown>
- </>
- )}
+ <LemonButton
+ size="small"
+ disabledReason={editingDisabledReason}
+ aria-label="Options"
+ className="@max-[780px]:hidden"
+ >
+ <span className="font-medium whitespace-nowrap">
+ Options
+ {advancedOptionsCount ? (
+ <span className="ml-0.5 text-secondary ligatures-none">
+ ({advancedOptionsCount})
+ </span>
+ ) : null}
+ </span>
+ </LemonButton>
+ </LemonDropdown>
+ <LemonDropdown
+ overlay={<InsightDisplayOptionsPanel tabs={displayOptionTabs} />}
+ closeOnClickInside={false}
+ placement="bottom-end"
+ >
+ <LemonButton
+ size="small"
+ disabledReason={editingDisabledReason}
+ icon={<IconEllipsis />}
+ aria-label="Options"
+ className="hidden @max-[780px]:flex order-[999]"
+ />
+ </LemonDropdown>
+ </>
+ ))}
{supportsDisplay && <ConfigFilter>{chartTypeControl ?? <ChartFilter />}</ConfigFilter>}
{!!isRetention && (
<ConfigFilter>
diff --git a/products/product_analytics/frontend/insights/editor/InsightDisplayOptionsPanel.tsx b/products/product_analytics/frontend/insights/editor/InsightDisplayOptionsPanel.tsx
index 08a8deaa1bd3..9d3b189f4f3b 100644
--- a/products/product_analytics/frontend/insights/editor/InsightDisplayOptionsPanel.tsx
+++ b/products/product_analytics/frontend/insights/editor/InsightDisplayOptionsPanel.tsx
@@ -1,9 +1,11 @@
import { useState } from 'react'
import { DisplayOptionSection, DisplayOptionTab, DisplayOptionTabKey } from 'lib/components/ChartOptions/displayOptions'
+import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
import { LemonTabs } from 'lib/lemon-ui/LemonTabs'
import { cn } from 'lib/utils/css-classes'
+import { QuillInsightDisplayOptionsPanel } from './QuillInsightDisplayOptionsPanel'
import { SectionHeader } from './SectionHeader'
function DisplayOptionSectionList({ sections }: { sections: DisplayOptionSection[] }): JSX.Element {
@@ -33,6 +35,7 @@ function DisplayOptionSectionList({ sections }: { sections: DisplayOptionSection
}
export function InsightDisplayOptionsPanel({ tabs }: { tabs: DisplayOptionTab[] }): JSX.Element | null {
+ const todayRailNav = useFeatureFlag('TODAY_RAIL_NAV')
const [activeKey, setActiveKey] = useState<DisplayOptionTabKey>(tabs[0]?.key ?? 'general')
const activeTab = tabs.find((tab) => tab.key === activeKey) ?? tabs[0]
@@ -40,6 +43,10 @@ export function InsightDisplayOptionsPanel({ tabs }: { tabs: DisplayOptionTab[]
return null
}
+ if (todayRailNav) {
+ return <QuillInsightDisplayOptionsPanel tabs={tabs} />
+ }
+
if (tabs.length === 1) {
return (
<div className="py-1" data-attr="insight-display-options-panel">
diff --git a/products/product_analytics/frontend/insights/editor/QuillInsightDisplayOptionsButton.tsx b/products/product_analytics/frontend/insights/editor/QuillInsightDisplayOptionsButton.tsx
new file mode 100644
index 000000000000..38bbdf87d86e
--- /dev/null
+++ b/products/product_analytics/frontend/insights/editor/QuillInsightDisplayOptionsButton.tsx
@@ -0,0 +1,48 @@
+import { IconEllipsis } from '@posthog/icons'
+import { Button, Popover, PopoverContent, PopoverTrigger } from '@posthog/quill'
+
+import { DisplayOptionTab } from 'lib/components/ChartOptions/displayOptions'
+
+import { InsightDisplayOptionsPanel } from './InsightDisplayOptionsPanel'
+
+export interface QuillInsightDisplayOptionsButtonProps {
+ tabs: DisplayOptionTab[]
+ advancedOptionsCount: number | undefined
+ disabledReason: string | null
+}
+
+export function QuillInsightDisplayOptionsButton({
+ tabs,
+ advancedOptionsCount,
+ disabledReason,
+}: QuillInsightDisplayOptionsButtonProps): JSX.Element {
+ return (
+ <Popover>
+ <PopoverTrigger
+ render={
+ <Button
+ variant="default"
+ aria-label="Options"
+ disabledReason={disabledReason}
+ className="@max-[780px]:order-last"
+ />
+ }
+ >
+ <span className="whitespace-nowrap @max-[780px]:hidden">
+ Options
+ {advancedOptionsCount ? (
+ <span className="ml-0.5 text-muted-foreground ligatures-none">({advancedOptionsCount})</span>
+ ) : null}
+ </span>
+ <IconEllipsis className="hidden @max-[780px]:block" />
+ </PopoverTrigger>
+ {/* The switches' enlarged hit areas reach past the panel padding, which would add a horizontal scrollbar. */}
+ <PopoverContent
+ align="end"
+ className="w-auto p-0 max-h-[var(--available-height)] overflow-y-auto overflow-x-hidden"
+ >
+ <InsightDisplayOptionsPanel tabs={tabs} />
+ </PopoverContent>
+ </Popover>
+ )
+}
diff --git a/products/product_analytics/frontend/insights/editor/QuillInsightDisplayOptionsPanel.tsx b/products/product_analytics/frontend/insights/editor/QuillInsightDisplayOptionsPanel.tsx
new file mode 100644
index 000000000000..fa5d4ed499fb
--- /dev/null
+++ b/products/product_analytics/frontend/insights/editor/QuillInsightDisplayOptionsPanel.tsx
@@ -0,0 +1,22 @@
+import { ChartOptionSections } from 'lib/components/ChartOptions/ChartOptionSections'
+import { displayOptionPages } from 'lib/components/ChartOptions/displayOptionPages'
+import { DisplayOptionTab } from 'lib/components/ChartOptions/displayOptions'
+import { QuillChartOptionPages } from 'lib/components/ChartOptions/QuillChartOptionPages'
+
+export function QuillInsightDisplayOptionsPanel({ tabs }: { tabs: DisplayOptionTab[] }): JSX.Element {
+ const { home, pages } = displayOptionPages(tabs)
+
+ return (
+ <QuillChartOptionPages
+ className="w-60 p-2"
+ data-attr="insight-display-options-panel"
+ home={home.length > 0 ? <ChartOptionSections sections={home} /> : null}
+ pages={pages.map((page) => ({
+ key: page.key,
+ title: page.title,
+ count: page.count,
+ content: <ChartOptionSections sections={page.sections} />,
+ }))}
+ />
+ )
+}
diff --git a/products/product_analytics/frontend/insights/editor/insightDisplayOptions.tsx b/products/product_analytics/frontend/insights/editor/insightDisplayOptions.tsx
index e2c23ed9938a..4f0f908320e4 100644
--- a/products/product_analytics/frontend/insights/editor/insightDisplayOptions.tsx
+++ b/products/product_analytics/frontend/insights/editor/insightDisplayOptions.tsx
@@ -412,10 +412,9 @@ const INSIGHT_BINDINGS: DisplayOptionBindings<InsightDisplayContext> = {
: c.showLegend),
},
legendPosition: {
- showCondition: (c) => c.useQuillLegendOptions,
- value: (c) => (c.legendPosition ?? (c.showLegend ? 'right' : 'bottom')) as DisplayOptionValue<'legendPosition'>,
+ showCondition: (c) => c.useQuillLegendOptions && c.showLegend,
+ value: (c) => (c.legendPosition ?? 'right') as DisplayOptionValue<'legendPosition'>,
onChange: (legendPosition, c) => c.updateInsightFilter({ legendPosition }),
- disabledReason: (c) => (c.showLegend ? undefined : 'Turn the legend on to set its position'),
},
excludeOutliers: {
showCondition: (c) => c.showDisplaySection && c.isBoxPlot,