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 insight bar controls on the rail (#122947)

Sam Penningtonc7df04e5a9cd
diff --git a/frontend/src/lib/components/CompareFilter/CompareFilter.tsx b/frontend/src/lib/components/CompareFilter/CompareFilter.tsx
index 201e5631f48e..38c7f8de7f77 100644
--- a/frontend/src/lib/components/CompareFilter/CompareFilter.tsx
+++ b/frontend/src/lib/components/CompareFilter/CompareFilter.tsx
@@ -1,14 +1,18 @@
import { useEffect, useState } from 'react'
+import { useDebouncedCallback } from 'use-debounce'
import { IconClock } from '@posthog/icons'
-import { LemonButtonProps, LemonSelect } from '@posthog/lemon-ui'
+import { LemonButtonProps, LemonSelect, LemonSelectOptionLeaf } from '@posthog/lemon-ui'
import { RollingDateRangeFilter } from 'lib/components/DateFilter/RollingDateRangeFilter'
+import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
import { useWindowSize } from 'lib/hooks/useWindowSize'
import { dateFromToText } from 'lib/utils/dateFilters'
import { CompareFilter as CompareFilterType } from '~/queries/schema/schema-general'
+import { type CompareFilterOption, type CompareFilterValue, QuillCompareFilter } from './QuillCompareFilter'
+
/** Shared `disableReason` for callers that turn off comparison once the date range is "All time". */
export const COMPARE_ALL_TIME_DISABLED_REASON =
"All time starts at your first event, so there's no earlier period to compare to. Pick a date range to compare."
@@ -46,6 +50,11 @@ export function CompareFilter({
const [tentativeCompareTo, setTentativeCompareTo] = useState<string>(compareFilter?.compare_to || '-1m')
const { isWindowLessThan } = useWindowSize()
+ const todayRailNav = useFeatureFlag('TODAY_RAIL_NAV')
+ const commitCompareTo = useDebouncedCallback(
+ (compare_to: string) => updateCompareFilter({ compare: true, compare_to }),
+ 500
+ )
useEffect(() => {
const newCompareTo = compareFilter?.compare_to
@@ -54,11 +63,75 @@ export function CompareFilter({
}
}, [compareFilter?.compare_to]) // oxlint-disable-line react-hooks/exhaustive-deps
- const options = [
+ let value: CompareFilterValue = 'none'
+ if (onInherit && inheritLabel && compareFilter == null) {
+ value = 'inherit'
+ } else if (compareFilter?.compare) {
+ if (compareFilter?.compare_to) {
+ value = 'compareTo'
+ } else {
+ value = 'previous'
+ }
+ }
+
+ const selectValue = (newValue: CompareFilterValue): void => {
+ commitCompareTo.cancel()
+ if (newValue === 'inherit') {
+ onInherit?.()
+ } else if (newValue === 'none') {
+ updateCompareFilter({ compare: false, compare_to: undefined })
+ } else if (newValue === 'previous') {
+ updateCompareFilter({ compare: true, compare_to: undefined })
+ } else {
+ updateCompareFilter({ compare: true, compare_to: tentativeCompareTo })
+ }
+ }
+
+ const isHugeScreen = size !== 'xsmall' && !isWindowLessThan('2xl')
+ const labelFor = (leafValue: CompareFilterValue): string => {
+ if (leafValue === 'compareTo') {
+ return isHugeScreen
+ ? `Compare to ${dateFromToText(tentativeCompareTo)} earlier`
+ : `${dateFromToText(tentativeCompareTo)} earlier`
+ } else if (leafValue === 'previous') {
+ return isHugeScreen ? 'Compare to previous period' : 'Previous period'
+ } else if (leafValue === 'none') {
+ return isHugeScreen ? 'No comparison between periods' : 'No comparison'
+ }
+ return inheritLabel ?? ''
+ }
+
+ if (todayRailNav) {
+ const quillOptions: CompareFilterOption[] = [
+ ...(onInherit && inheritLabel ? [{ value: 'inherit' as const, label: inheritLabel }] : []),
+ { value: 'none', label: 'No comparison between periods' },
+ { value: 'previous', label: 'Compare to previous period' },
+ ...(allowCustomComparison ? [{ value: 'compareTo' as const, label: 'Compare to' }] : []),
+ ]
+ return (
+ <QuillCompareFilter
+ value={value}
+ label={labelFor(value)}
+ options={quillOptions}
+ tentativeCompareTo={tentativeCompareTo}
+ onSelect={selectValue}
+ onCompareToChange={(compare_to) => {
+ setTentativeCompareTo(compare_to)
+ commitCompareTo(compare_to)
+ }}
+ disabled={disabled}
+ disabledReason={disableReason}
+ tooltip={tooltip}
+ fullWidth={fullWidth}
+ />
+ )
+ }
+
+ const options: LemonSelectOptionLeaf<CompareFilterValue>[] = [
...(onInherit && inheritLabel
? [
{
- value: 'inherit',
+ value: 'inherit' as const,
label: inheritLabel,
},
]
@@ -89,55 +162,20 @@ export function CompareFilter({
},
]
- let value = 'none'
- if (onInherit && inheritLabel && compareFilter == null) {
- value = 'inherit'
- } else if (compareFilter?.compare) {
- if (compareFilter?.compare_to) {
- value = 'compareTo'
- } else {
- value = 'previous'
- }
- }
-
return (
<LemonSelect
icon={<IconClock />}
onSelect={(newValue) => {
if (newValue === 'compareTo') {
- updateCompareFilter({ compare: true, compare_to: tentativeCompareTo })
+ selectValue(newValue)
}
}}
- renderButtonContent={(leaf) => {
- if (!leaf) {
- return 'Compare to'
- }
-
- const isHugeScreen = size !== 'xsmall' && !isWindowLessThan('2xl')
- if (leaf.value === 'compareTo') {
- return isHugeScreen
- ? `Compare to ${dateFromToText(tentativeCompareTo)} earlier`
- : `${dateFromToText(tentativeCompareTo)} earlier`
- } else if (leaf.value === 'previous') {
- return isHugeScreen ? 'Compare to previous period' : 'Previous period'
- } else if (leaf.value === 'none') {
- return isHugeScreen ? 'No comparison between periods' : 'No comparison'
- } else if (leaf.value === 'inherit') {
- return inheritLabel ?? ''
- }
-
- // Should never happen
- return 'Compare to'
- }}
+ renderButtonContent={(leaf) => (leaf?.value ? labelFor(leaf.value) : 'Compare to')}
value={value}
dropdownMatchSelectWidth={false}
- onChange={(value) => {
- if (value === 'inherit') {
- onInherit?.()
- } else if (value === 'none') {
- updateCompareFilter({ compare: false, compare_to: undefined })
- } else if (value === 'previous') {
- updateCompareFilter({ compare: true, compare_to: undefined })
+ onChange={(newValue) => {
+ if (newValue && newValue !== 'compareTo') {
+ selectValue(newValue)
}
}}
data-attr="compare-filter"
diff --git a/frontend/src/lib/components/CompareFilter/QuillCompareFilter.tsx b/frontend/src/lib/components/CompareFilter/QuillCompareFilter.tsx
new file mode 100644
index 000000000000..ce35efd2b66e
--- /dev/null
+++ b/frontend/src/lib/components/CompareFilter/QuillCompareFilter.tsx
@@ -0,0 +1,124 @@
+import { useId, useState } from 'react'
+
+import { IconClock } from '@posthog/icons'
+import {
+ Button,
+ Label,
+ Popover,
+ PopoverContent,
+ PopoverTrigger,
+ RadioGroup,
+ RadioGroupItem,
+ SelectTriggerIcon,
+ Text,
+} from '@posthog/quill'
+
+import { dateRangeForSelection, selectionForDateRange } from 'lib/components/DateFilter/dateRangeSelection'
+import { RelativeRangeInput, type RelativeRangeValue } from 'lib/components/DateFilter/RelativeRangeInput'
+
+export type CompareFilterValue = 'inherit' | 'none' | 'previous' | 'compareTo'
+
+export interface CompareFilterOption {
+ value: CompareFilterValue
+ label: string
+}
+
+export interface QuillCompareFilterProps {
+ value: CompareFilterValue
+ label: string
+ options: CompareFilterOption[]
+ tentativeCompareTo: string
+ onSelect: (value: CompareFilterValue) => void
+ onCompareToChange: (compareTo: string) => void
+ disabled?: boolean
+ disabledReason?: string | null
+ tooltip?: string | null
+ fullWidth?: boolean
+}
+
+const COMPARE_TO_UNITS: RelativeRangeValue['unit'][] = ['hours', 'days', 'weeks', 'months', 'years']
+
+function relativeRangeFor(compareTo: string): RelativeRangeValue {
+ const selection = selectionForDateRange(compareTo, null)
+ return selection.kind === 'rolling'
+ ? { count: selection.count, unit: selection.unit }
+ : { count: 1, unit: 'months' }
+}
+
+export function QuillCompareFilter({
+ value,
+ label,
+ options,
+ tentativeCompareTo,
+ onSelect,
+ onCompareToChange,
+ disabled,
+ disabledReason,
+ tooltip,
+ fullWidth,
+}: QuillCompareFilterProps): JSX.Element {
+ const [open, setOpen] = useState(false)
+ const id = useId()
+
+ return (
+ <Popover open={open} onOpenChange={setOpen}>
+ <PopoverTrigger
+ render={
+ <Button
+ variant="outline"
+ disabled={disabled}
+ disabledReason={disabledReason}
+ tooltip={tooltip}
+ className={fullWidth ? 'w-full' : undefined}
+ data-attr="compare-filter"
+ />
+ }
+ >
+ <IconClock />
+ <span className="text-nowrap">{label}</span>
+ <SelectTriggerIcon />
+ </PopoverTrigger>
+ <PopoverContent align="start" className="w-auto">
+ <RadioGroup
+ value={value}
+ onValueChange={(next) => {
+ onSelect(next as CompareFilterValue)
+ if (next !== 'compareTo') {
+ setOpen(false)
+ }
+ }}
+ >
+ {options.map((option) => (
+ <div key={option.value} className="flex items-center gap-2">
+ <RadioGroupItem value={option.value} id={`${id}-${option.value}`} />
+ <Label htmlFor={`${id}-${option.value}`} className="font-normal whitespace-nowrap">
+ {option.label}
+ </Label>
+ {option.value === 'compareTo' && (
+ <>
+ <RelativeRangeInput
+ value={relativeRangeFor(tentativeCompareTo)}
+ units={COMPARE_TO_UNITS}
+ onChange={(range) =>
+ onCompareToChange(
+ // Relative dates only parse whole numbers: "-1.5d" reads as five days.
+ dateRangeForSelection({
+ kind: 'rolling',
+ count: Math.round(range.count),
+ unit: range.unit,
+ }).date_from ?? tentativeCompareTo
+ )
+ }
+ />
+ <Text size="xs" render={<span />}>
+ earlier
+ </Text>
+ </>
+ )}
+ </div>
+ ))}
+ </RadioGroup>
+ </PopoverContent>
+ </Popover>
+ )
+}
diff --git a/frontend/src/lib/components/DateFilter/DateFilter.tsx b/frontend/src/lib/components/DateFilter/DateFilter.tsx
index abeb478b9467..f42f155fcc29 100644
--- a/frontend/src/lib/components/DateFilter/DateFilter.tsx
+++ b/frontend/src/lib/components/DateFilter/DateFilter.tsx
@@ -5,6 +5,7 @@ import { forwardRef, useEffect, useRef, useState } from 'react'
import { IconCalendar, IconInfo } from '@posthog/icons'
import { LemonButton, LemonButtonProps, LemonDivider, LemonSwitch, Popover } from '@posthog/lemon-ui'
+import { Button, SelectTriggerIcon } from '@posthog/quill'
import {
CUSTOM_OPTION_DESCRIPTION,
@@ -13,6 +14,8 @@ import {
NO_OVERRIDE_RANGE_PLACEHOLDER,
} from 'lib/components/DateFilter/types'
import { dayjs } from 'lib/dayjs'
+import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
+import { quillButtonVariant } from 'lib/lemon-ui/LemonButton/quillButtonVariant'
import { LemonCalendarSelect, LemonCalendarSelectProps } from 'lib/lemon-ui/LemonCalendar/LemonCalendarSelect'
import { LemonCalendarRange } from 'lib/lemon-ui/LemonCalendarRange/LemonCalendarRange'
import { ScrollableShadows } from 'lib/lemon-ui/ScrollableShadows/ScrollableShadows'
@@ -137,6 +140,7 @@ export const DateFilter = forwardRef<HTMLButtonElement, RawDateFilterProps>(func
) {
const effectiveShowCustomRelativeRange = allowSingleAndRange ? true : showCustomRelativeRange
const key = useRef(uuid()).current
+ const todayRailNav = useFeatureFlag('TODAY_RAIL_NAV')
const logicProps: DateFilterLogicProps = {
key,
dateFrom,
@@ -513,20 +517,37 @@ export const DateFilter = forwardRef<HTMLButtonElement, RawDateFilterProps>(func
closeParentPopoverOnClickInside={false}
overflowHidden={view === DateFilterView.QuickList}
>
- <LemonButton
- ref={ref}
- id="daterange_selector"
- size={size ?? 'small'}
- type={type ?? 'secondary'}
- disabledReason={disabledReason}
- data-attr="date-filter"
- icon={<IconCalendar />}
- onClick={isVisible ? close : open}
- fullWidth={fullWidth}
- tooltip={formatResolvedDateRange(resolvedDateRange)}
- >
- <span className={clsx('text-nowrap', className)}>{label}</span>
- </LemonButton>
+ {todayRailNav ? (
+ <Button
+ ref={ref}
+ id="daterange_selector"
+ variant={quillButtonVariant(type ?? 'secondary')}
+ disabledReason={disabledReason}
+ data-attr="date-filter"
+ onClick={isVisible ? close : open}
+ className={fullWidth ? 'w-full' : undefined}
+ tooltip={formatResolvedDateRange(resolvedDateRange)}
+ >
+ <IconCalendar />
+ <span className={clsx('text-nowrap', className)}>{label}</span>
+ <SelectTriggerIcon />
+ </Button>
+ ) : (
+ <LemonButton
+ ref={ref}
+ id="daterange_selector"
+ size={size ?? 'small'}
+ type={type ?? 'secondary'}
+ disabledReason={disabledReason}
+ data-attr="date-filter"
+ icon={<IconCalendar />}
+ onClick={isVisible ? close : open}
+ fullWidth={fullWidth}
+ tooltip={formatResolvedDateRange(resolvedDateRange)}
+ >
+ <span className={clsx('text-nowrap', className)}>{label}</span>
+ </LemonButton>
+ )}
</Popover>
)
})
diff --git a/frontend/src/lib/components/IntervalFilter/IntervalFilter.tsx b/frontend/src/lib/components/IntervalFilter/IntervalFilter.tsx
index 749f2a068a81..33e24f6eca4a 100644
--- a/frontend/src/lib/components/IntervalFilter/IntervalFilter.tsx
+++ b/frontend/src/lib/components/IntervalFilter/IntervalFilter.tsx
@@ -1,14 +1,24 @@
import { useActions, useValues } from 'kea'
import { IconPin } from '@posthog/icons'
-import { LemonButton, LemonSelect, LemonSelectOption } from '@posthog/lemon-ui'
+import {
+ LemonButton,
+ LemonSelect,
+ LemonSelectOption,
+ LemonSelectOptionLeaf,
+ isLemonSelectOptionNode,
+} from '@posthog/lemon-ui'
+import { Button, Text } from '@posthog/quill'
+import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
import { insightLogic } from 'scenes/insights/insightLogic'
import { insightVizDataLogic } from 'scenes/insights/insightVizDataLogic'
import { InsightQueryNode } from '~/queries/schema/schema-general'
import { IntervalType } from '~/types'
+import { QuillIntervalFilterStandalone } from './QuillIntervalFilterStandalone'
+
interface IntervalFilterProps {
disabled?: boolean
}
@@ -17,27 +27,46 @@ export function IntervalFilter({ disabled }: IntervalFilterProps): JSX.Element {
const { insightProps, editingDisabledReason } = useValues(insightLogic)
const { interval, enabledIntervals, isIntervalManuallySet } = useValues(insightVizDataLogic(insightProps))
const { updateQuerySource, setIsIntervalManuallySet } = useActions(insightVizDataLogic(insightProps))
+ const todayRailNav = useFeatureFlag('TODAY_RAIL_NAV')
return (
<span className="flex items-center gap-2">
- <span className="@max-[780px]:hidden">
- <span className="hidden md:inline">grouped </span>by
- </span>
+ {todayRailNav ? (
+ <Text size="xs" render={<span className="@max-[780px]:hidden" />}>
+ <span className="hidden md:inline">grouped </span>by
+ </Text>
+ ) : (
+ <span className="@max-[780px]:hidden">
+ <span className="hidden md:inline">grouped </span>by
+ </span>
+ )}
{isIntervalManuallySet ? (
- <LemonButton
- type="secondary"
- onClick={() => {
- setIsIntervalManuallySet(false)
- }}
- tooltip="Unpin interval"
- className="flex-1"
- center
- size="small"
- icon={<IconPin color="var(--content-warning)" />}
- disabledReason={editingDisabledReason}
- >
- {interval || 'day'}
- </LemonButton>
+ todayRailNav ? (
+ <Button
+ variant="outline"
+ onClick={() => setIsIntervalManuallySet(false)}
+ tooltip="Unpin interval"
+ disabledReason={editingDisabledReason}
+ >
+ <IconPin className="text-warning-foreground" />
+ {interval || 'day'}
+ </Button>
+ ) : (
+ <LemonButton
+ type="secondary"
+ onClick={() => {
+ setIsIntervalManuallySet(false)
+ }}
+ tooltip="Unpin interval"
+ className="flex-1"
+ center
+ size="small"
+ icon={<IconPin color="var(--content-warning)" />}
+ disabledReason={editingDisabledReason}
+ >
+ {interval || 'day'}
+ </LemonButton>
+ )
) : (
<IntervalFilterStandalone
disabled={disabled}
@@ -80,6 +109,22 @@ export function IntervalFilterStandalone({
onIntervalChange,
options = DEFAULT_OPTIONS,
}: IntervalFilterStandaloneProps): JSX.Element {
+ const todayRailNav = useFeatureFlag('TODAY_RAIL_NAV')
+
+ if (todayRailNav) {
+ return (
+ <QuillIntervalFilterStandalone
+ disabled={disabled}
+ disabledReason={disabledReason}
+ interval={interval || 'day'}
+ onIntervalChange={onIntervalChange}
+ options={options.filter(
+ (option): option is LemonSelectOptionLeaf<IntervalType> => !isLemonSelectOptionNode(option)
+ )}
+ />
+ )
+ }
+
return (
<LemonSelect
size="small"
diff --git a/frontend/src/lib/components/IntervalFilter/QuillIntervalFilterStandalone.tsx b/frontend/src/lib/components/IntervalFilter/QuillIntervalFilterStandalone.tsx
new file mode 100644
index 000000000000..95cb192ef07d
--- /dev/null
+++ b/frontend/src/lib/components/IntervalFilter/QuillIntervalFilterStandalone.tsx
@@ -0,0 +1,57 @@
+import type { LemonSelectOptionLeaf } from '@posthog/lemon-ui'
+import { Button, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, Text } from '@posthog/quill'
+
+import { IntervalType } from '~/types'
+
+export interface QuillIntervalFilterStandaloneProps {
+ disabled?: boolean
+ disabledReason?: string | null
+ interval: IntervalType
+ onIntervalChange: (interval: IntervalType) => void
+ options: LemonSelectOptionLeaf<IntervalType>[]
+}
+
+export function QuillIntervalFilterStandalone({
+ disabled,
+ disabledReason,
+ interval,
+ onIntervalChange,
+ options,
+}: QuillIntervalFilterStandaloneProps): JSX.Element {
+ const visibleOptions = options.filter((option) => !option.hidden || option.value === interval)
+
+ return (
+ <Select<IntervalType>
+ value={interval}
+ onValueChange={(value) => value && onIntervalChange(value)}
+ disabled={disabled || !!disabledReason}
+ >
+ <SelectTrigger
+ render={<Button variant="outline" left disabledReason={disabledReason} />}
+ data-attr="interval-filter"
+ >
+ <SelectValue>
+ {(value: IntervalType) => options.find((option) => option.value === value)?.label ?? value}
+ </SelectValue>
+ </SelectTrigger>
+ <SelectContent align="start" alignItemWithTrigger={false}>
+ {visibleOptions.map((option) => (
+ <SelectItem key={option.value} value={option.value} disabled={!!option.disabledReason}>
+ <span className="flex flex-col items-start gap-0.5">
+ {option.label}
+ {option.disabledReason && (
+ <Text
+ size="xs"
+ variant="muted"
+ render={<span className="max-w-64 whitespace-normal" />}
+ >
+ {option.disabledReason}
+ </Text>
+ )}
+ </span>
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ )
+}