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(product-analytics): quill chart type menu with a more submenu (#129903)

Sam Pennington865bfd56de62
diff --git a/frontend/src/lib/components/ChartFilter/ChartFilter.tsx b/frontend/src/lib/components/ChartFilter/ChartFilter.tsx
index fc8710b01ffa..0e4a61b825c7 100644
--- a/frontend/src/lib/components/ChartFilter/ChartFilter.tsx
+++ b/frontend/src/lib/components/ChartFilter/ChartFilter.tsx
@@ -7,6 +7,7 @@ import type { ChartDisplayOption } from 'lib/components/ChartFilter/chartDisplay
import { getChartDisplayOptions } from 'lib/components/ChartFilter/chartDisplayOptions'
import { isBoxPlotMissingProperty } from 'lib/components/ChartFilter/isBoxPlotMissingProperty'
import { FEATURE_FLAGS } from 'lib/constants'
+import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { insightLogic } from 'scenes/insights/insightLogic'
import { insightVizDataLogic } from 'scenes/insights/insightVizDataLogic'
@@ -14,6 +15,8 @@ import { insightVizDataLogic } from 'scenes/insights/insightVizDataLogic'
import type { TrendsQuery } from '~/queries/schema/schema-general'
import { ChartDisplayType } from '~/types'
+import { QuillChartFilter } from './QuillChartFilter'
+
function ChartFilterOptionLabel(props: { label: string; description?: string }): JSX.Element {
return (
<div className="flex flex-col gap-[2px]">
@@ -47,11 +50,12 @@ export function ChartFilter({
const { display, compareFilter } = useValues(insightVizDataLogic(insightProps))
const { updateInsightFilter } = useActions(insightVizDataLogic(insightProps))
const { featureFlags } = useValues(featureFlagLogic)
+ const todayRailNav = useFeatureFlag('TODAY_RAIL_NAV')
const { isTrends, isSingleSeriesOutput, formula, formulaNodes, formulas, breakdownFilter, series } = useValues(
insightVizDataLogic(insightProps)
)
- const options: LemonSelectOptions<ChartDisplayType> = getChartDisplayOptions({
+ const groups = getChartDisplayOptions({
isTrends,
hasSingleSeriesOutput: isSingleSeriesOutput,
hasTrendsFormula: !!formula || !!formulas?.length || !!formulaNodes?.length,
@@ -60,7 +64,25 @@ export function ChartFilter({
boxPlotMissingProperty: isBoxPlotMissingProperty(series as TrendsQuery['series']),
hasMetricInsight: !!featureFlags[FEATURE_FLAGS.METRIC_INSIGHT],
isComparing: !!compareFilter?.compare,
- }).map((group) => ({ title: group.title, options: group.options.map(chartDisplayOptionToSelectOption) }))
+ })
+
+ if (todayRailNav) {
+ return (
+ <QuillChartFilter
+ value={display || ChartDisplayType.ActionsLineGraph}
+ groups={groups}
+ onChange={(value) => updateInsightFilter({ display: value })}
+ onOpen={onOpen}
+ fullWidth={fullWidth}
+ disabledReason={editingDisabledReason ?? disabledReason}
+ />
+ )
+ }
+
+ const options: LemonSelectOptions<ChartDisplayType> = groups.map((group) => ({
+ title: group.title,
+ options: group.options.map(chartDisplayOptionToSelectOption),
+ }))
return (
<LemonSelect
diff --git a/frontend/src/lib/components/ChartFilter/QuillChartFilter.tsx b/frontend/src/lib/components/ChartFilter/QuillChartFilter.tsx
new file mode 100644
index 000000000000..0497a4677523
--- /dev/null
+++ b/frontend/src/lib/components/ChartFilter/QuillChartFilter.tsx
@@ -0,0 +1,146 @@
+import {
+ Button,
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuGroup,
+ DropdownMenuLabel,
+ DropdownMenuRadioGroup,
+ DropdownMenuRadioItem,
+ DropdownMenuSeparator,
+ DropdownMenuSub,
+ DropdownMenuSubContent,
+ DropdownMenuSubTrigger,
+ DropdownMenuTrigger,
+ SelectTriggerIcon,
+ Text,
+} from '@posthog/quill'
+
+import { ChartDisplayIcon } from 'lib/components/ChartFilter/ChartDisplayIcon'
+import type { ChartDisplayOption, ChartDisplayOptionGroup } from 'lib/components/ChartFilter/chartDisplayOptions'
+
+import { ChartDisplayType } from '~/types'
+
+// Ordered by how often people pick them; the rest go under "More chart types".
+const PRIMARY_DISPLAYS: ChartDisplayType[] = [
+ ChartDisplayType.ActionsLineGraph,
+ ChartDisplayType.ActionsUnstackedBar,
+ ChartDisplayType.ActionsBar,
+ ChartDisplayType.Metric,
+ ChartDisplayType.BoldNumber,
+ ChartDisplayType.ActionsBarValue,
+ ChartDisplayType.ActionsTable,
+ ChartDisplayType.ActionsPie,
+]
+
+export interface QuillChartFilterProps {
+ value: ChartDisplayType
+ groups: ChartDisplayOptionGroup[]
+ onChange: (value: ChartDisplayType) => void
+ onOpen?: () => void
+ fullWidth?: boolean
+ disabledReason?: string | null
+}
+
+function splitGroups(groups: ChartDisplayOptionGroup[]): {
+ primary: ChartDisplayOptionGroup[]
+ more: ChartDisplayOptionGroup[]
+} {
+ const isPrimary = (option: ChartDisplayOption): boolean => PRIMARY_DISPLAYS.includes(option.display)
+ const byUsage = (a: ChartDisplayOption, b: ChartDisplayOption): number =>
+ PRIMARY_DISPLAYS.indexOf(a.display) - PRIMARY_DISPLAYS.indexOf(b.display)
+ return {
+ primary: groups
+ .map((group) => ({ ...group, options: group.options.filter(isPrimary).sort(byUsage) }))
+ .filter((group) => group.options.length > 0),
+ more: groups
+ .map((group) => ({ ...group, options: group.options.filter((option) => !isPrimary(option)) }))
+ .filter((group) => group.options.length > 0),
+ }
+}
+
+function ChartOptionGroups({
+ groups,
+ value,
+ onChange,
+}: {
+ groups: ChartDisplayOptionGroup[]
+ value: ChartDisplayType
+ onChange: (value: ChartDisplayType) => void
+}): JSX.Element {
+ return (
+ <DropdownMenuRadioGroup value={value} onValueChange={(next) => onChange(next as ChartDisplayType)}>
+ {groups.map((group) => (
+ <DropdownMenuGroup key={group.title}>
+ <DropdownMenuLabel inset>{group.title}</DropdownMenuLabel>
+ {group.options.map((option) => (
+ <DropdownMenuRadioItem
+ key={option.display}
+ value={option.display}
+ closeOnClick
+ tooltip={option.tooltip ?? option.description}
+ disabledReason={option.disabledReason}
+ >
+ <ChartDisplayIcon icon={option.icon} />
+ {option.label}
+ </DropdownMenuRadioItem>
+ ))}
+ </DropdownMenuGroup>
+ ))}
+ </DropdownMenuRadioGroup>
+ )
+}
+
+export function QuillChartFilter({
+ value,
+ groups,
+ onChange,
+ onOpen,
+ fullWidth,
+ disabledReason,
+}: QuillChartFilterProps): JSX.Element {
+ const { primary, more } = splitGroups(groups)
+ const current = groups.flatMap((group) => group.options).find((option) => option.display === value)
+ const currentInMore = more.some((group) => group.options.some((option) => option.display === value))
+
+ return (
+ <DropdownMenu onOpenChange={(open) => open && onOpen?.()}>
+ <DropdownMenuTrigger
+ disabled={!!disabledReason}
+ render={
+ <Button
+ variant="outline"
+ left
+ disabledReason={disabledReason}
+ className={fullWidth ? 'w-full' : undefined}
+ data-attr="chart-filter"
+ />
+ }
+ >
+ {current && <ChartDisplayIcon icon={current.icon} />}
+ <span>{current?.label ?? value}</span>
+ <SelectTriggerIcon />
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end">
+ <ChartOptionGroups groups={primary} value={value} onChange={onChange} />
+ {more.length > 0 && (
+ <>
+ <DropdownMenuSeparator />
+ <DropdownMenuSub>
+ <DropdownMenuSubTrigger inset data-attr="chart-filter-more">
+ More chart types
+ {currentInMore && current && (
+ <Text size="xs" variant="muted" render={<span className="ms-auto ps-4" />}>
+ {current.label}
+ </Text>
+ )}
+ </DropdownMenuSubTrigger>
+ <DropdownMenuSubContent>
+ <ChartOptionGroups groups={more} value={value} onChange={onChange} />
+ </DropdownMenuSubContent>
+ </DropdownMenuSub>
+ </>
+ )}
+ </DropdownMenuContent>
+ </DropdownMenu>
+ )
+}
diff --git a/frontend/src/lib/components/ChartFilter/chartDisplayOptions.ts b/frontend/src/lib/components/ChartFilter/chartDisplayOptions.ts
index 54b419d0f0b8..db7aed583b64 100644
--- a/frontend/src/lib/components/ChartFilter/chartDisplayOptions.ts
+++ b/frontend/src/lib/components/ChartFilter/chartDisplayOptions.ts
@@ -142,6 +142,18 @@ export function getChartDisplayOptions({
label: 'Stacked bar chart',
description: 'Trends over time as vertical bars.',
},
+ ...(hasMetricInsight
+ ? [
+ {
+ display: ChartDisplayType.Metric,
+ icon: 'metric' as const,
+ label: 'Metric',
+ description: 'A headline value with a sparkline and period-over-period change.',
+ disabledReason:
+ trendsOnlyDisabledReason || breakdownDisabledReason || singleSeriesOnlyDisabledReason,
+ },
+ ]
+ : []),
{
display: ChartDisplayType.BoxPlot,
icon: 'bar',
@@ -181,18 +193,6 @@ export function getChartDisplayOptions({
disabledReason:
trendsOnlyDisabledReason || breakdownDisabledReason || singleSeriesOnlyDisabledReason,
},
- ...(hasMetricInsight
- ? [
- {
- display: ChartDisplayType.Metric,
- icon: 'metric' as const,
- label: 'Metric',
- description: 'A headline value with a sparkline and period-over-period change.',
- disabledReason:
- trendsOnlyDisabledReason || breakdownDisabledReason || singleSeriesOnlyDisabledReason,
- },
- ]
- : []),
{
display: ChartDisplayType.ActionsPie,
icon: 'pie',
diff --git a/products/product_analytics/frontend/insights/chartAlternatives/ChartAlternatives.tsx b/products/product_analytics/frontend/insights/chartAlternatives/ChartAlternatives.tsx
index fbb5274b9b19..43b9a47c24a7 100644
--- a/products/product_analytics/frontend/insights/chartAlternatives/ChartAlternatives.tsx
+++ b/products/product_analytics/frontend/insights/chartAlternatives/ChartAlternatives.tsx
@@ -5,12 +5,14 @@ import { LemonButton, Popover } from '@posthog/lemon-ui'
import { ChartFilter } from 'lib/components/ChartFilter'
import { ChartDisplayIcon } from 'lib/components/ChartFilter/ChartDisplayIcon'
+import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
import type { InsightLogicProps } from '~/types'
import { chartAlternativesLogic } from './chartAlternativesLogic'
import { ChartGallery } from './ChartGallery'
import { chartPreviewsLogic } from './chartPreviewsLogic'
+import { QuillChartAlternatives } from './QuillChartAlternatives'
// Leaves the gallery 33rem of content box, just over the @lg breakpoint that puts three tiles in a row.
const GALLERY_WIDTH = 'w-[34rem] max-w-[calc(100vw-2rem)]'
@@ -28,13 +30,35 @@ export function ChartAlternatives({
const logic = useMountedLogic(chartAlternativesLogic(logicProps))
useMountedLogic(chartPreviewsLogic(logicProps))
const { canShowAlternatives, currentOption, galleryOpen, selectionDisabledReason } = useValues(logic)
- const { closeGallery, reportChartMenuOpened, toggleGallery } = useActions(logic)
+ const { closeGallery, openGallery, reportChartMenuOpened, toggleGallery } = useActions(logic)
const triggerRef = useRef<HTMLButtonElement>(null)
+ const todayRailNav = useFeatureFlag('TODAY_RAIL_NAV')
if (!canShowAlternatives) {
return <ChartFilter onOpen={reportChartMenuOpened} />
}
+ const gallery = (
+ <ChartGallery
+ className={GALLERY_WIDTH}
+ insightProps={insightProps}
+ embedded={embedded}
+ inSharedMode={inSharedMode}
+ />
+ )
+
+ if (todayRailNav) {
+ return (
+ <QuillChartAlternatives
+ open={galleryOpen}
+ onOpenChange={(open) => (open ? openGallery() : closeGallery())}
+ currentOption={currentOption}
+ disabledReason={selectionDisabledReason}
+ gallery={gallery}
+ />
+ )
+ }
+
return (
<Popover
visible={galleryOpen}
@@ -46,14 +70,7 @@ export function ChartAlternatives({
}}
placement="bottom-end"
padded={false}
- overlay={
- <ChartGallery
- className={GALLERY_WIDTH}
- insightProps={insightProps}
- embedded={embedded}
- inSharedMode={inSharedMode}
- />
- }
+ overlay={gallery}
>
<LemonButton
ref={triggerRef}
diff --git a/products/product_analytics/frontend/insights/chartAlternatives/QuillChartAlternatives.tsx b/products/product_analytics/frontend/insights/chartAlternatives/QuillChartAlternatives.tsx
new file mode 100644
index 000000000000..a616c397129e
--- /dev/null
+++ b/products/product_analytics/frontend/insights/chartAlternatives/QuillChartAlternatives.tsx
@@ -0,0 +1,39 @@
+import { Button, Popover, PopoverContent, PopoverTrigger, SelectTriggerIcon } from '@posthog/quill'
+
+import { ChartDisplayIcon } from 'lib/components/ChartFilter/ChartDisplayIcon'
+import type { ChartDisplayOption } from 'lib/components/ChartFilter/chartDisplayOptions'
+
+export interface QuillChartAlternativesProps {
+ open: boolean
+ onOpenChange: (open: boolean) => void
+ currentOption: ChartDisplayOption | null | undefined
+ disabledReason?: string
+ gallery: JSX.Element
+}
+
+export function QuillChartAlternatives({
+ open,
+ onOpenChange,
+ currentOption,
+ disabledReason,
+ gallery,
+}: QuillChartAlternativesProps): JSX.Element {
+ return (
+ <Popover open={open} onOpenChange={onOpenChange}>
+ <PopoverTrigger
+ render={<Button variant="outline" disabledReason={disabledReason} data-attr="chart-alternatives-all" />}
+ >
+ {currentOption && <ChartDisplayIcon icon={currentOption.icon} />}
+ <span>{currentOption?.label ?? 'Chart type'}</span>
+ <SelectTriggerIcon />
+ </PopoverTrigger>
+ <PopoverContent
+ align="end"
+ collisionAvoidance={{ side: 'flip', align: 'shift', fallbackAxisSide: 'none' }}
+ className="w-auto max-h-(--available-height) overflow-y-auto p-0 scroll-mask-y-4"
+ >
+ {gallery}
+ </PopoverContent>
+ </Popover>
+ )
+}
diff --git a/products/product_analytics/frontend/insights/chartAlternatives/chartPreviewsLogic.ts b/products/product_analytics/frontend/insights/chartAlternatives/chartPreviewsLogic.ts
index 1e0143dfadec..ef1501cd1dbc 100644
--- a/products/product_analytics/frontend/insights/chartAlternatives/chartPreviewsLogic.ts
+++ b/products/product_analytics/frontend/insights/chartAlternatives/chartPreviewsLogic.ts
@@ -346,33 +346,33 @@ export const chartPreviewsLogic = kea<chartPreviewsLogicType>([
}
scheduleNextChart()
}
+ const reportGalleryViewed = (): void => {
+ scheduleNextChart()
+ if (!values.galleryOpen || values.insightDataLoading) {
+ return
+ }
+ const eligiblePreviews = values.previews.filter((preview) => !preview.option.disabledReason)
+ const loadedPreviews = eligiblePreviews.filter((preview) => preview.response !== null)
+ const samplePreviews = loadedPreviews.filter((preview) => preview.sample)
+ posthog.capture('insight chart alternatives viewed', {
+ current_display: values.currentDisplay,
+ eligible_chart_count: eligiblePreviews.length,
+ eligible_displays: eligiblePreviews.map((preview) => preview.option.display),
+ preview_count: loadedPreviews.length,
+ preview_displays: loadedPreviews.map((preview) => preview.option.display),
+ sample_preview_count: samplePreviews.length,
+ sample_preview_displays: samplePreviews.map((preview) => preview.option.display),
+ suggested_displays: eligiblePreviews
+ .filter((preview) => preview.suggested)
+ .map((preview) => preview.option.display),
+ all_previews_loaded: eligiblePreviews.length > 0 && loadedPreviews.length === eligiblePreviews.length,
+ })
+ }
return {
showNextChart: scheduleNextChart,
- openGallery: scheduleNextChart,
+ openGallery: reportGalleryViewed,
closeGallery: scheduleNextChart,
- toggleGallery: () => {
- scheduleNextChart()
- if (!values.galleryOpen || values.insightDataLoading) {
- return
- }
- const eligiblePreviews = values.previews.filter((preview) => !preview.option.disabledReason)
- const loadedPreviews = eligiblePreviews.filter((preview) => preview.response !== null)
- const samplePreviews = loadedPreviews.filter((preview) => preview.sample)
- posthog.capture('insight chart alternatives viewed', {
- current_display: values.currentDisplay,
- eligible_chart_count: eligiblePreviews.length,
- eligible_displays: eligiblePreviews.map((preview) => preview.option.display),
- preview_count: loadedPreviews.length,
- preview_displays: loadedPreviews.map((preview) => preview.option.display),
- sample_preview_count: samplePreviews.length,
- sample_preview_displays: samplePreviews.map((preview) => preview.option.display),
- suggested_displays: eligiblePreviews
- .filter((preview) => preview.suggested)
- .map((preview) => preview.option.display),
- all_previews_loaded:
- eligiblePreviews.length > 0 && loadedPreviews.length === eligiblePreviews.length,
- })
- },
+ toggleGallery: reportGalleryViewed,
loadDataSuccess: rememberLoadedTimeSeries,
setInsightData: rememberLoadedTimeSeries,
}