:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
refactor(today): share the recent filter menu parts (#109594)
Shy Alter5b746a18f3a7
diff --git a/frontend/src/layout/today/TodayFilterMenuTrigger.tsx b/frontend/src/layout/today/TodayFilterMenuTrigger.tsxnew file mode 100644index 000000000000..7b6ab7cc2278--- /dev/null+++ b/frontend/src/layout/today/TodayFilterMenuTrigger.tsx@@ -0,0 +1,33 @@+import { IconFilter } from '@posthog/icons'+import { Button, Dot, DropdownMenuTrigger, Tooltip, TooltipContent, TooltipTrigger, cn } from '@posthog/quill'++/** The funnel button that opens a list's filter menu. A dot says a filter narrows the list. */+export function TodayFilterMenuTrigger({ active, dataAttr }: { active: boolean; dataAttr: string }): JSX.Element {+ const label = active ? 'Filters on' : 'Filter'+ return (+ <Tooltip>+ <TooltipTrigger+ delay={0}+ render={+ <DropdownMenuTrigger+ render={+ <Button+ size="icon-xs"+ aria-label={label}+ className={cn(+ 'relative text-muted-foreground',+ active && 'bg-fill-selected text-foreground'+ )}+ data-attr={dataAttr}+ />+ }+ />+ }+ >+ <IconFilter />+ {active && <Dot aria-hidden className="absolute top-0 right-0" />}+ </TooltipTrigger>+ <TooltipContent>{label}</TooltipContent>+ </Tooltip>+ )+}diff --git a/frontend/src/layout/today/TodayRecentFilterMenu.tsx b/frontend/src/layout/today/TodayRecentFilterMenu.tsxindex d13001dbab92..608d7f305888 100644--- a/frontend/src/layout/today/TodayRecentFilterMenu.tsx+++ b/frontend/src/layout/today/TodayRecentFilterMenu.tsx@@ -1,52 +1,19 @@import { useActions, useValues } from 'kea'-import { IconFilter } from '@posthog/icons'-import {- Button,- Dot,- DropdownMenu,- DropdownMenuCheckboxItem,- DropdownMenuContent,- DropdownMenuItem,- DropdownMenuSeparator,- DropdownMenuTrigger,- Tooltip,- TooltipContent,- TooltipTrigger,- cn,-} from '@posthog/quill'+import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator } from '@posthog/quill'-import { DEFAULT_RECENT_FILTERS, TodayRecentCreatedByFilter, recentSourceLabel } from './todayRecentFilters'-import { TodayRecentFilterSubmenu } from './TodayRecentFilterSubmenu'-import { DEFAULT_RECENT_GROUPING, DEFAULT_RECENT_SORT, TodayRecentGrouping, TodayRecentSort } from './todayRecentOrder'+import { TodayFilterMenuTrigger } from './TodayFilterMenuTrigger'+import { DEFAULT_RECENT_FILTERS, RECENT_CREATED_BY_OPTIONS } from './todayRecentFilters'+import {+ DEFAULT_RECENT_GROUPING,+ DEFAULT_RECENT_SORT,+ RECENT_GROUPING_OPTIONS,+ RECENT_SORT_OPTIONS,+} from './todayRecentOrder'import { TodayRecentRadioSubmenu } from './TodayRecentRadioSubmenu'+import { TodayRecentSourceSubmenu } from './TodayRecentSourceSubmenu'import { todaySpacesLogic } from './todaySpacesLogic'-const CREATED_BY_OPTIONS: { value: TodayRecentCreatedByFilter; label: string }[] = [- { value: 'anyone', label: 'Anyone' },- { value: 'me', label: 'Me' },- { value: 'others', label: 'Other people' },-]--const GROUPING_OPTIONS: { value: TodayRecentGrouping; label: string }[] = [- { value: 'date', label: 'Date' },- { value: 'space', label: 'Space' },- { value: 'repository', label: 'Repository' },-]--const SORT_OPTIONS: { value: TodayRecentSort; label: string }[] = [- { value: 'recent', label: 'Recent activity' },- { value: 'created', label: 'Date created' },- { value: 'alpha', label: 'Name' },-]--function sourcesLabel(sources: string[]): string {- if (!sources.length) {- return 'Any source'- }- return sources.length > 2 ? `${sources.length} sources` : sources.map(recentSourceLabel).join(', ')-}-export function TodayRecentFilterMenu(): JSX.Element {const {recentFilters: filters,@@ -56,38 +23,14 @@ export function TodayRecentFilterMenu(): JSX.Element {recentGrouping,} = useValues(todaySpacesLogic)const { setRecentFilters, clearRecentFilters, setRecentSort, setRecentGrouping } = useActions(todaySpacesLogic)- const label = active ? 'Filters on' : 'Filter'return (<DropdownMenu>- <Tooltip>- <TooltipTrigger- delay={0}- render={- <DropdownMenuTrigger- render={- <Button- size="icon-xs"- aria-label={label}- className={cn(- 'relative text-muted-foreground',- active && 'bg-fill-selected text-foreground'- )}- data-attr="today-recent-filter"- />- }- />- }- >- <IconFilter />- {active && <Dot aria-hidden className="absolute top-0 right-0" />}- </TooltipTrigger>- <TooltipContent>{label}</TooltipContent>- </Tooltip>+ <TodayFilterMenuTrigger active={active} dataAttr="today-recent-filter" /><DropdownMenuContent align="end" className="min-w-56"><TodayRecentRadioSubmenulabel="Group by"- options={GROUPING_OPTIONS}+ options={RECENT_GROUPING_OPTIONS}value={recentGrouping}defaultValue={DEFAULT_RECENT_GROUPING}onChange={setRecentGrouping}@@ -95,7 +38,7 @@ export function TodayRecentFilterMenu(): JSX.Element {/><TodayRecentRadioSubmenulabel="Sort by"- options={SORT_OPTIONS}+ options={RECENT_SORT_OPTIONS}value={recentSort}defaultValue={DEFAULT_RECENT_SORT}onChange={setRecentSort}@@ -104,45 +47,18 @@ export function TodayRecentFilterMenu(): JSX.Element {<DropdownMenuSeparator /><TodayRecentRadioSubmenulabel="Created by"- options={CREATED_BY_OPTIONS}+ options={RECENT_CREATED_BY_OPTIONS}value={filters.createdBy}defaultValue={DEFAULT_RECENT_FILTERS.createdBy}onChange={(createdBy) => setRecentFilters({ ...filters, createdBy })}dataAttr="today-recent-filter-created-by"/>- <TodayRecentFilterSubmenu- label="Source"- value={sourcesLabel(filters.sources)}- narrowed={filters.sources.length > 0}- >- <DropdownMenuCheckboxItem- checked={!filters.sources.length}- closeOnClick={false}- onCheckedChange={() => setRecentFilters({ ...filters, sources: [] })}- data-attr="today-recent-filter-source-any"- >- Any source- </DropdownMenuCheckboxItem>- <DropdownMenuSeparator />- {recentSourceOptions.map((source) => (- <DropdownMenuCheckboxItem- key={source}- checked={filters.sources.includes(source)}- closeOnClick={false}- onCheckedChange={(checked) =>- setRecentFilters({- ...filters,- sources: checked- ? [...filters.sources, source]- : filters.sources.filter((selected) => selected !== source),- })- }- data-attr="today-recent-filter-source"- >- {recentSourceLabel(source)}- </DropdownMenuCheckboxItem>- ))}- </TodayRecentFilterSubmenu>+ <TodayRecentSourceSubmenu+ selected={filters.sources}+ options={recentSourceOptions}+ onChange={(sources) => setRecentFilters({ ...filters, sources })}+ dataAttr="today-recent-filter-source"+ />{active && (<><DropdownMenuSeparator />diff --git a/frontend/src/layout/today/TodayRecentSourceSubmenu.tsx b/frontend/src/layout/today/TodayRecentSourceSubmenu.tsxnew file mode 100644index 000000000000..54cec6b6360d--- /dev/null+++ b/frontend/src/layout/today/TodayRecentSourceSubmenu.tsx@@ -0,0 +1,54 @@+import { DropdownMenuCheckboxItem, DropdownMenuSeparator } from '@posthog/quill'++import { recentSourceLabel } from './todayRecentFilters'+import { TodayRecentFilterSubmenu } from './TodayRecentFilterSubmenu'++interface TodayRecentSourceSubmenuProps {+ /** The sources kept. An empty list keeps every source. */+ selected: string[]+ options: string[]+ onChange: (sources: string[]) => void+ /** The option rows' `data-attr`. The "Any source" row adds `-any`. */+ dataAttr: string+}++function sourcesLabel(sources: string[]): string {+ if (!sources.length) {+ return 'Any source'+ }+ return sources.length > 2 ? `${sources.length} sources` : sources.map(recentSourceLabel).join(', ')+}++export function TodayRecentSourceSubmenu({+ selected,+ options,+ onChange,+ dataAttr,+}: TodayRecentSourceSubmenuProps): JSX.Element {+ return (+ <TodayRecentFilterSubmenu label="Source" value={sourcesLabel(selected)} narrowed={selected.length > 0}>+ <DropdownMenuCheckboxItem+ checked={!selected.length}+ closeOnClick={false}+ onCheckedChange={() => onChange([])}+ data-attr={`${dataAttr}-any`}+ >+ Any source+ </DropdownMenuCheckboxItem>+ <DropdownMenuSeparator />+ {options.map((source) => (+ <DropdownMenuCheckboxItem+ key={source}+ checked={selected.includes(source)}+ closeOnClick={false}+ onCheckedChange={(checked) =>+ onChange(checked ? [...selected, source] : selected.filter((kept) => kept !== source))+ }+ data-attr={dataAttr}+ >+ {recentSourceLabel(source)}+ </DropdownMenuCheckboxItem>+ ))}+ </TodayRecentFilterSubmenu>+ )+}diff --git a/frontend/src/layout/today/todayRecentFilters.ts b/frontend/src/layout/today/todayRecentFilters.tsindex b84a2f0d2deb..f9b86e3944c9 100644--- a/frontend/src/layout/today/todayRecentFilters.ts+++ b/frontend/src/layout/today/todayRecentFilters.ts@@ -10,6 +10,12 @@ export interface TodayRecentFilters {export const DEFAULT_RECENT_FILTERS: TodayRecentFilters = { createdBy: 'anyone', sources: [] }+export const RECENT_CREATED_BY_OPTIONS: { value: TodayRecentCreatedByFilter; label: string }[] = [+ { value: 'anyone', label: 'Anyone' },+ { value: 'me', label: 'Me' },+ { value: 'others', label: 'Other people' },+]+const SOURCE_LABELS: Record<string, string> = {user_created: 'Manual',posthog_ai: 'PostHog AI',diff --git a/frontend/src/layout/today/todayRecentOrder.ts b/frontend/src/layout/today/todayRecentOrder.tsindex a81391f83c39..c6a5d6c4c5f4 100644--- a/frontend/src/layout/today/todayRecentOrder.ts+++ b/frontend/src/layout/today/todayRecentOrder.ts@@ -8,6 +8,18 @@ export type TodayRecentGrouping = 'date' | 'space' | 'repository'export const DEFAULT_RECENT_SORT: TodayRecentSort = 'recent'export const DEFAULT_RECENT_GROUPING: TodayRecentGrouping = 'date'+export const RECENT_GROUPING_OPTIONS: { value: TodayRecentGrouping; label: string }[] = [+ { value: 'date', label: 'Date' },+ { value: 'space', label: 'Space' },+ { value: 'repository', label: 'Repository' },+]++export const RECENT_SORT_OPTIONS: { value: TodayRecentSort; label: string }[] = [+ { value: 'recent', label: 'Recent activity' },+ { value: 'created', label: 'Date created' },+ { value: 'alpha', label: 'Name' },+]+export interface TodayRecentSection {key: string/** Null for a run with nothing to call it, like an alphabetical list. */