: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
feat(tracing): reuse the logs date range picker via a shared component (#64319)
Jon McCallum050977d44676
diff --git a/products/logs/frontend/components/LogsViewer/Filters/LogsFilterBar/LogsFilterBar.scss b/frontend/src/lib/components/DateFilter/DateRangePicker/DateRangePicker.scsssimilarity index 70%rename from products/logs/frontend/components/LogsViewer/Filters/LogsFilterBar/LogsFilterBar.scssrename to frontend/src/lib/components/DateFilter/DateRangePicker/DateRangePicker.scssindex 2f4d1001029f..95d9700814af 100644--- a/products/logs/frontend/components/LogsViewer/Filters/LogsFilterBar/LogsFilterBar.scss+++ b/frontend/src/lib/components/DateFilter/DateRangePicker/DateRangePicker.scss@@ -1,4 +1,6 @@-.LogsDateButtonGroup {+// Visually attach the zoom-out / picker / zoom-in buttons into a single group:+// flush borders, squared inner corners, rounded outer corners.+.DateRangePickerButtonGroup {display: flex;> .LemonButton {diff --git a/frontend/src/lib/components/DateFilter/DateRangePicker/DateRangePicker.test.tsx b/frontend/src/lib/components/DateFilter/DateRangePicker/DateRangePicker.test.tsxnew file mode 100644index 000000000000..e6c49bb287cd--- /dev/null+++ b/frontend/src/lib/components/DateFilter/DateRangePicker/DateRangePicker.test.tsx@@ -0,0 +1,61 @@+import '@testing-library/jest-dom'++import { cleanup, render, screen } from '@testing-library/react'+import userEvent from '@testing-library/user-event'+import { Provider } from 'kea'++import { DateRange } from '~/queries/schema/schema-general'+import { initKeaTests } from '~/test/init'++import { DateRangePicker, DateRangePickerProps } from './DateRangePicker'++const DEFAULT_RANGE: DateRange = { date_from: '-1h', date_to: null }++function renderPicker(overrides: Partial<DateRangePickerProps> = {}): { setDateRange: jest.Mock } {+ const setDateRange = jest.fn()+ render(+ <Provider>+ <DateRangePicker logicKey="test" dateRange={DEFAULT_RANGE} setDateRange={setDateRange} {...overrides} />+ </Provider>+ )+ return { setDateRange }+}++describe('DateRangePicker', () => {+ beforeEach(() => {+ initKeaTests()+ })++ afterEach(() => {+ cleanup()+ })++ it('renders the current range as the trigger label', () => {+ renderPicker()+ expect(screen.getByText('Last 1 hour')).toBeInTheDocument()+ })++ it('selects a preset and calls setDateRange', async () => {+ const { setDateRange } = renderPicker()++ await userEvent.click(screen.getByText('Last 1 hour'))+ await userEvent.click(screen.getByText('5 minutes'))++ expect(setDateRange).toHaveBeenCalledWith({ date_from: '-5M', date_to: null })+ })++ it.each<[string, string | undefined, boolean]>([+ ['hidden', undefined, false],+ ['shown', 'UTC', true],+ ])('timezone selector is %s when timezone props are %s', async (_label, timezone, shouldShow) => {+ renderPicker(timezone ? { timezone, onTimezoneChange: jest.fn() } : {})++ await userEvent.click(screen.getByText('Last 1 hour'))++ if (shouldShow) {+ expect(screen.getByTestId('timezone-select')).toBeInTheDocument()+ } else {+ expect(screen.queryByTestId('timezone-select')).not.toBeInTheDocument()+ }+ })+})diff --git a/frontend/src/lib/components/DateFilter/DateRangePicker/DateRangePicker.tsx b/frontend/src/lib/components/DateFilter/DateRangePicker/DateRangePicker.tsxnew file mode 100644index 000000000000..b22f930a5cc0--- /dev/null+++ b/frontend/src/lib/components/DateFilter/DateRangePicker/DateRangePicker.tsx@@ -0,0 +1,258 @@+import './DateRangePicker.scss'++import { useActions, useValues } from 'kea'+import { useState } from 'react'++import { IconCalendar, IconClock } from '@posthog/icons'+import { LemonButton, LemonDivider, LemonInput, Popover } from '@posthog/lemon-ui'++import { RollingDateRangeFilter } from 'lib/components/DateFilter/RollingDateRangeFilter'+import { DateOption } from 'lib/components/DateFilter/rollingDateRangeFilterLogic'+import { TimezoneSelect } from 'lib/components/TimezoneSelect'+import { dayjs } from 'lib/dayjs'+import { LemonCalendarSelect } from 'lib/lemon-ui/LemonCalendar/LemonCalendarSelect'+import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'++import { DateRange } from '~/queries/schema/schema-general'+import { DateMappingOption } from '~/types'++import { DEFAULT_DATE_RANGE_PICKER_OPTIONS } from './constants'+import { dateRangePickerLogic } from './dateRangePickerLogic'+import { DATE_TIME_FORMAT, formatDateRangeLabel, getShortLabel, parseDateExpression } from './utils'++interface DateTimeInputProps {+ value: string+ onChange: (value: string) => void+ placeholder: string+ timezone: string+ label: string+}++const DateTimeInput = ({ value, onChange, placeholder, timezone, label }: DateTimeInputProps): JSX.Element => {+ const [calendarOpen, setCalendarOpen] = useState(false)++ const parsedValue = parseDateExpression(value, timezone)++ const handleCalendarSelect = (date: dayjs.Dayjs): void => {+ onChange(date.format(DATE_TIME_FORMAT))+ setCalendarOpen(false)+ }++ return (+ <div className="flex-1">+ <div className="text-xs text-secondary mb-1">{label}</div>+ <Popover+ visible={calendarOpen}+ onClickOutside={() => setCalendarOpen(false)}+ placement="bottom-start"+ overlay={+ <LemonCalendarSelect+ value={parsedValue}+ onChange={handleCalendarSelect}+ onClose={() => setCalendarOpen(false)}+ granularity="minute"+ use24HourFormat+ />+ }+ >+ <LemonInput+ value={value}+ onChange={onChange}+ placeholder={placeholder}+ suffix={+ <LemonButton+ size="xsmall"+ noPadding+ icon={<IconCalendar className="text-secondary" />}+ onClick={(e) => {+ e.stopPropagation()+ setCalendarOpen(true)+ }}+ />+ }+ />+ </Popover>+ </div>+ )+}++export interface DateRangePickerProps {+ dateRange: DateRange+ setDateRange: (dateRange: DateRange) => void+ /** Unique per consumer surface ('logs' | 'tracing'); keys the backing logic. */+ logicKey: string+ /** Preset list shown under "In the last". Defaults to DEFAULT_DATE_RANGE_PICKER_OPTIONS. */+ dateOptions?: DateMappingOption[]+ /** Units offered by the embedded rolling stepper. Defaults to ['minutes', 'hours', 'days']. */+ allowedRollingDateOptions?: DateOption[]+ /** Both required to show the timezone selector; absent => hidden, parsing defaults to UTC. */+ timezone?: string+ onTimezoneChange?: (timezone: string) => void+}++export const DateRangePicker = ({+ dateRange,+ setDateRange,+ logicKey,+ dateOptions = DEFAULT_DATE_RANGE_PICKER_OPTIONS,+ allowedRollingDateOptions = ['minutes', 'hours', 'days'],+ timezone,+ onTimezoneChange,+}: DateRangePickerProps): JSX.Element => {+ const logic = dateRangePickerLogic({ key: logicKey })+ const { popoverOpen, customFrom, customTo, history } = useValues(logic)+ const { setPopoverOpen, setCustomFrom, setCustomTo, addToHistory } = useActions(logic)++ const effectiveTimezone = timezone ?? 'UTC'+ const showTimezone = timezone !== undefined && onTimezoneChange !== undefined++ const handleSelectOption = (option: DateMappingOption): void => {+ setDateRange({ date_from: option.values[0], date_to: option.values[1] ?? null })+ addToHistory({ date_from: option.values[0], date_to: option.values[1] ?? null })+ setPopoverOpen(false)+ }++ const handleSelectHistory = (historyDateRange: DateRange): void => {+ setDateRange(historyDateRange)+ addToHistory(historyDateRange)+ setPopoverOpen(false)+ }++ const handleApplyCustom = (): void => {+ const fromDate = parseDateExpression(customFrom, effectiveTimezone)+ const toDate = customTo ? parseDateExpression(customTo, effectiveTimezone) : null++ if (!fromDate) {+ lemonToast.error('Invalid start date format. Use formats like "-1h", "-30M", or "YYYY-MM-DD HH:mm"')+ return+ }++ if (customTo && !toDate) {+ lemonToast.error('Invalid end date format. Use formats like "-1h", "-30M", or "YYYY-MM-DD HH:mm"')+ return+ }++ if (toDate && fromDate.isAfter(toDate)) {+ lemonToast.error('Start date must be before end date')+ return+ }++ const newDateRange: DateRange = {+ date_from: fromDate.toISOString(),+ date_to: toDate ? toDate.toISOString() : null,+ }++ setDateRange(newDateRange)+ addToHistory(newDateRange)+ setPopoverOpen(false)+ }++ const isOptionSelected = (option: DateMappingOption): boolean => {+ return dateRange.date_from === option.values[0] && (dateRange.date_to ?? null) === (option.values[1] ?? null)+ }++ const currentLabel = formatDateRangeLabel(dateRange, effectiveTimezone, dateOptions)++ return (+ <Popover+ visible={popoverOpen}+ onClickOutside={() => setPopoverOpen(false)}+ placement="bottom-end"+ overlay={+ <div className="w-fit bg-bg-light rounded-lg overflow-hidden flex flex-row-reverse">+ <div className="flex flex-col gap-1 p-3">+ <div className="text-xs font-medium text-secondary mb-1">In the last</div>+ {dateOptions.map((option) => (+ <LemonButton+ key={option.key}+ size="small"+ type={isOptionSelected(option) ? 'primary' : 'tertiary'}+ onClick={() => handleSelectOption(option)}+ fullWidth+ >+ {getShortLabel(option)}+ </LemonButton>+ ))}+ <RollingDateRangeFilter+ dateFrom={dateRange.date_from}+ selected={true}+ dateRangeFilterLabel=""+ onChange={(fromDate) => {+ setDateRange({ date_from: fromDate, date_to: null })+ addToHistory({ date_from: fromDate, date_to: null })+ }}+ fullWidth+ allowedDateOptions={allowedRollingDateOptions}+ />+ </div>++ <LemonDivider vertical className="my-3" />++ <div className="flex flex-col gap-3 p-3 w-fit">+ <div className="flex flex-col gap-2">+ <div className="text-xs font-medium text-secondary">Custom range</div>+ <div className="flex gap-2">+ <DateTimeInput+ value={customFrom}+ onChange={setCustomFrom}+ placeholder="-1h, -30M..."+ timezone={effectiveTimezone}+ label="From"+ />+ <DateTimeInput+ value={customTo}+ onChange={setCustomTo}+ placeholder="now"+ timezone={effectiveTimezone}+ label="To"+ />+ </div>+ <LemonButton type="primary" size="small" onClick={handleApplyCustom} fullWidth>+ Apply+ </LemonButton>+ </div>++ {history.length > 0 && (+ <>+ <LemonDivider className="my-0" />+ <div className="flex flex-col gap-1 flex-1">+ <div className="text-xs font-medium text-secondary">Recent</div>+ {history.map((historyDateRange, index) => (+ <LemonButton+ key={index}+ size="small"+ type="tertiary"+ fullWidth+ icon={<IconClock className="text-secondary" />}+ onClick={() => handleSelectHistory(historyDateRange)}+ >+ <span className="truncate">+ {formatDateRangeLabel(historyDateRange, effectiveTimezone, dateOptions)}+ </span>+ </LemonButton>+ ))}+ </div>+ </>+ )}++ {showTimezone && (+ <>+ <LemonDivider className="my-0" />+ <TimezoneSelect value={effectiveTimezone} onChange={onTimezoneChange} size="xsmall" />+ </>+ )}+ </div>+ </div>+ }+ >+ <LemonButton+ size="small"+ type="secondary"+ icon={<IconCalendar />}+ onClick={() => setPopoverOpen(!popoverOpen)}+ >+ {currentLabel}+ </LemonButton>+ </Popover>+ )+}diff --git a/products/logs/frontend/components/LogsViewer/Filters/LogsDateRangePicker/constants.ts b/frontend/src/lib/components/DateFilter/DateRangePicker/constants.tssimilarity index 92%rename from products/logs/frontend/components/LogsViewer/Filters/LogsDateRangePicker/constants.tsrename to frontend/src/lib/components/DateFilter/DateRangePicker/constants.tsindex 6796e5371257..50e31f72d90d 100644--- a/products/logs/frontend/components/LogsViewer/Filters/LogsDateRangePicker/constants.ts+++ b/frontend/src/lib/components/DateFilter/DateRangePicker/constants.ts@@ -1,6 +1,6 @@import { DateMappingOption } from '~/types'-export const LOGS_DATE_OPTIONS: DateMappingOption[] = [+export const DEFAULT_DATE_RANGE_PICKER_OPTIONS: DateMappingOption[] = [{ key: 'Last 1 minute', values: ['-1M'], defaultInterval: 'minute' },{ key: 'Last 5 minutes', values: ['-5M'], defaultInterval: 'minute' },{ key: 'Last 15 minutes', values: ['-15M'], defaultInterval: 'minute' },diff --git a/products/logs/frontend/components/LogsViewer/Filters/LogsDateRangePicker/logsDateRangePickerLogic.ts b/frontend/src/lib/components/DateFilter/DateRangePicker/dateRangePickerLogic.tssimilarity index 69%rename from products/logs/frontend/components/LogsViewer/Filters/LogsDateRangePicker/logsDateRangePickerLogic.tsrename to frontend/src/lib/components/DateFilter/DateRangePicker/dateRangePickerLogic.tsindex d0c4aaf7e3e0..96088a81147d 100644--- a/products/logs/frontend/components/LogsViewer/Filters/LogsDateRangePicker/logsDateRangePickerLogic.ts+++ b/frontend/src/lib/components/DateFilter/DateRangePicker/dateRangePickerLogic.ts@@ -1,15 +1,22 @@-import { actions, kea, path, reducers } from 'kea'+import { actions, kea, key, path, props, reducers } from 'kea'import { DateRange } from '~/queries/schema/schema-general'-import type { logsDateRangePickerLogicType } from './logsDateRangePickerLogicType'+import type { dateRangePickerLogicType } from './dateRangePickerLogicType'const MAX_HISTORY_ITEMS = 5const dateRangesEqual = (a: DateRange, b: DateRange): boolean => a.date_from === b.date_from && a.date_to === b.date_to-export const logsDateRangePickerLogic = kea<logsDateRangePickerLogicType>([- path(['products', 'logs', 'frontend', 'filters', 'LogsDateRangePicker', 'logsDateRangePickerLogic']),+export interface DateRangePickerLogicProps {+ /** Unique per consumer surface ('logs' | 'tracing'); keys popover/custom-input/history state. */+ key: string+}++export const dateRangePickerLogic = kea<dateRangePickerLogicType>([+ props({} as DateRangePickerLogicProps),+ key((props) => props.key),+ path((key) => ['lib', 'components', 'DateFilter', 'DateRangePicker', 'dateRangePickerLogic', key]),actions({setPopoverOpen: (open: boolean) => ({ open }),setCustomFrom: (value: string) => ({ value }),diff --git a/frontend/src/lib/components/DateFilter/DateRangePicker/index.ts b/frontend/src/lib/components/DateFilter/DateRangePicker/index.tsnew file mode 100644index 000000000000..4343b1800721--- /dev/null+++ b/frontend/src/lib/components/DateFilter/DateRangePicker/index.ts@@ -0,0 +1,4 @@+export { DateRangePicker } from './DateRangePicker'+export type { DateRangePickerProps } from './DateRangePicker'+export { DEFAULT_DATE_RANGE_PICKER_OPTIONS } from './constants'+export { zoomDateRange } from './zoom-utils'diff --git a/products/logs/frontend/components/LogsViewer/Filters/LogsDateRangePicker/utils.test.ts b/frontend/src/lib/components/DateFilter/DateRangePicker/utils.test.tssimilarity index 100%rename from products/logs/frontend/components/LogsViewer/Filters/LogsDateRangePicker/utils.test.tsrename to frontend/src/lib/components/DateFilter/DateRangePicker/utils.test.tsdiff --git a/products/logs/frontend/components/LogsViewer/Filters/LogsDateRangePicker/utils.ts b/frontend/src/lib/components/DateFilter/DateRangePicker/utils.tssimilarity index 100%rename from products/logs/frontend/components/LogsViewer/Filters/LogsDateRangePicker/utils.tsrename to frontend/src/lib/components/DateFilter/DateRangePicker/utils.tsdiff --git a/products/logs/frontend/components/LogsViewer/Filters/zoom-utils.test.ts b/frontend/src/lib/components/DateFilter/DateRangePicker/zoom-utils.test.tssimilarity index 79%rename from products/logs/frontend/components/LogsViewer/Filters/zoom-utils.test.tsrename to frontend/src/lib/components/DateFilter/DateRangePicker/zoom-utils.test.tsindex 7191896cb0c9..03e6723e7cea 100644--- a/products/logs/frontend/components/LogsViewer/Filters/zoom-utils.test.ts+++ b/frontend/src/lib/components/DateFilter/DateRangePicker/zoom-utils.test.ts@@ -26,6 +26,33 @@ describe('zoomDateRange', () => {date_to: null,})})++ it('multiplies minute presets while preserving the live-tail (uppercase M)', () => {+ // PostHog's minute presets use uppercase M (e.g. -5M); these must keep date_to: null+ expect(zoomDateRange({ date_from: '-5M', date_to: null }, 2)).toEqual({+ date_from: '-10M',+ date_to: null,+ })+ expect(zoomDateRange({ date_from: '-30M', date_to: null }, 0.5)).toEqual({+ date_from: '-15M',+ date_to: null,+ })+ })++ it('rounds fractional results to a whole unit so they stay valid relative expressions', () => {+ // -5M × 0.5 = 2.5, which must not produce the unparseable "-2.5M"+ expect(zoomDateRange({ date_from: '-5M', date_to: null }, 0.5)).toEqual({+ date_from: '-3M',+ date_to: null,+ })+ })++ it('floors the amount at 1 so zooming in never collapses to zero', () => {+ expect(zoomDateRange({ date_from: '-1M', date_to: null }, 0.25)).toEqual({+ date_from: '-1M',+ date_to: null,+ })+ })})describe('absolute date ranges', () => {diff --git a/products/logs/frontend/components/LogsViewer/Filters/zoom-utils.ts b/frontend/src/lib/components/DateFilter/DateRangePicker/zoom-utils.tssimilarity index 83%rename from products/logs/frontend/components/LogsViewer/Filters/zoom-utils.tsrename to frontend/src/lib/components/DateFilter/DateRangePicker/zoom-utils.tsindex 0f1f089a4bae..2f1fd5916beb 100644--- a/products/logs/frontend/components/LogsViewer/Filters/zoom-utils.ts+++ b/frontend/src/lib/components/DateFilter/DateRangePicker/zoom-utils.ts@@ -1,7 +1,8 @@import { dayjs } from 'lib/dayjs'import { dateStringToDayJs } from 'lib/utils/dateFilters'-const RELATIVE_DATE_REGEX = /(^-?)(\d+)([hdwmy])$/+// Unit letters follow PostHog's date convention: uppercase `M` is minute, lowercase `m` is month+const RELATIVE_DATE_REGEX = /(^-?)(\d+)([sMhdwmqy])$/const zoomDateRelative = (date: string | null | undefined, multiplier: number): string | null => {if (!date) {@@ -9,9 +10,9 @@ const zoomDateRelative = (date: string | null | undefined, multiplier: number):}const match = date.match(RELATIVE_DATE_REGEX)if (match) {- // Just multiply the value if we have it+ // Multiply the value, rounding to a whole unit (and at least 1) so the result stays a valid relative expressionconst [, sign, amount, unit] = match- const newAmount = parseInt(amount) * multiplier+ const newAmount = Math.max(Math.round(parseInt(amount) * multiplier), 1)return `${sign}${newAmount}${unit}`}return nulldiff --git a/products/logs/frontend/components/LogsViewer/TimezoneSelect.test.tsx b/frontend/src/lib/components/TimezoneSelect/TimezoneSelect.test.tsxsimilarity index 100%rename from products/logs/frontend/components/LogsViewer/TimezoneSelect.test.tsxrename to frontend/src/lib/components/TimezoneSelect/TimezoneSelect.test.tsxdiff --git a/products/logs/frontend/components/LogsViewer/TimezoneSelect.tsx b/frontend/src/lib/components/TimezoneSelect/TimezoneSelect.tsxsimilarity index 100%rename from products/logs/frontend/components/LogsViewer/TimezoneSelect.tsxrename to frontend/src/lib/components/TimezoneSelect/TimezoneSelect.tsxdiff --git a/frontend/src/lib/components/TimezoneSelect/index.ts b/frontend/src/lib/components/TimezoneSelect/index.tsnew file mode 100644index 000000000000..57c1d6fe7465--- /dev/null+++ b/frontend/src/lib/components/TimezoneSelect/index.ts@@ -0,0 +1,2 @@+export { TimezoneSelect } from './TimezoneSelect'+export type { TimezoneSelectProps } from './TimezoneSelect'diff --git a/products/logs/frontend/components/LogsViewer/Filters/LogsDateRangePicker/LogsDateRangePicker.tsx b/products/logs/frontend/components/LogsViewer/Filters/LogsDateRangePicker/LogsDateRangePicker.tsxindex 44e34c3d6d57..7c6197e81a75 100644--- a/products/logs/frontend/components/LogsViewer/Filters/LogsDateRangePicker/LogsDateRangePicker.tsx+++ b/products/logs/frontend/components/LogsViewer/Filters/LogsDateRangePicker/LogsDateRangePicker.tsx@@ -1,79 +1,10 @@import { useActions, useValues } from 'kea'-import { useState } from 'react'-import { IconCalendar, IconClock } from '@posthog/icons'-import { LemonButton, LemonDivider, LemonInput, Popover } from '@posthog/lemon-ui'--import { RollingDateRangeFilter } from 'lib/components/DateFilter/RollingDateRangeFilter'-import { dayjs } from 'lib/dayjs'-import { LemonCalendarSelect } from 'lib/lemon-ui/LemonCalendar/LemonCalendarSelect'-import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'+import { DateRangePicker } from 'lib/components/DateFilter/DateRangePicker'import { DateRange } from '~/queries/schema/schema-general'-import { DateMappingOption } from '~/types'import { logsViewerSettingsLogic } from 'products/logs/frontend/components/LogsViewer/logsViewerSettingsLogic'-import { TimezoneSelect } from 'products/logs/frontend/components/LogsViewer/TimezoneSelect'--import { LOGS_DATE_OPTIONS } from './constants'-import { logsDateRangePickerLogic } from './logsDateRangePickerLogic'-import { DATE_TIME_FORMAT, formatDateRangeLabel, getShortLabel, parseDateExpression } from './utils'--interface DateTimeInputProps {- value: string- onChange: (value: string) => void- placeholder: string- timezone: string- label: string-}--const DateTimeInput = ({ value, onChange, placeholder, timezone, label }: DateTimeInputProps): JSX.Element => {- const [calendarOpen, setCalendarOpen] = useState(false)-- const parsedValue = parseDateExpression(value, timezone)-- const handleCalendarSelect = (date: dayjs.Dayjs): void => {- onChange(date.format(DATE_TIME_FORMAT))- setCalendarOpen(false)- }-- return (- <div className="flex-1">- <div className="text-xs text-secondary mb-1">{label}</div>- <Popover- visible={calendarOpen}- onClickOutside={() => setCalendarOpen(false)}- placement="bottom-start"- overlay={- <LemonCalendarSelect- value={parsedValue}- onChange={handleCalendarSelect}- onClose={() => setCalendarOpen(false)}- granularity="minute"- use24HourFormat- />- }- >- <LemonInput- value={value}- onChange={onChange}- placeholder={placeholder}- suffix={- <LemonButton- size="xsmall"- noPadding- icon={<IconCalendar className="text-secondary" />}- onClick={(e) => {- e.stopPropagation()- setCalendarOpen(true)- }}- />- }- />- </Popover>- </div>- )-}export interface LogsDateRangePickerProps {dateRange: DateRange@@ -81,154 +12,16 @@ export interface LogsDateRangePickerProps {}export const LogsDateRangePicker = ({ dateRange, setDateRange }: LogsDateRangePickerProps): JSX.Element => {- const { popoverOpen, customFrom, customTo, history } = useValues(logsDateRangePickerLogic)- const { setPopoverOpen, setCustomFrom, setCustomTo, addToHistory } = useActions(logsDateRangePickerLogic)const { timezone } = useValues(logsViewerSettingsLogic)const { setTimezone } = useActions(logsViewerSettingsLogic)- const handleSelectOption = (option: DateMappingOption): void => {- setDateRange({ date_from: option.values[0], date_to: option.values[1] ?? null })- addToHistory({ date_from: option.values[0], date_to: option.values[1] ?? null })- setPopoverOpen(false)- }-- const handleSelectHistory = (historyDateRange: DateRange): void => {- setDateRange(historyDateRange)- addToHistory(historyDateRange)- setPopoverOpen(false)- }-- const handleApplyCustom = (): void => {- const fromDate = parseDateExpression(customFrom, timezone)- const toDate = customTo ? parseDateExpression(customTo, timezone) : null-- if (!fromDate) {- lemonToast.error('Invalid start date format. Use formats like "-1h", "-30M", or "YYYY-MM-DD HH:mm"')- return- }-- if (customTo && !toDate) {- lemonToast.error('Invalid end date format. Use formats like "-1h", "-30M", or "YYYY-MM-DD HH:mm"')- return- }-- if (toDate && fromDate.isAfter(toDate)) {- lemonToast.error('Start date must be before end date')- return- }-- const newDateRange: DateRange = {- date_from: fromDate.toISOString(),- date_to: toDate ? toDate.toISOString() : null,- }-- setDateRange(newDateRange)- addToHistory(newDateRange)- setPopoverOpen(false)- }-- const isOptionSelected = (option: DateMappingOption): boolean => {- return dateRange.date_from === option.values[0] && (dateRange.date_to ?? null) === (option.values[1] ?? null)- }-- const currentLabel = formatDateRangeLabel(dateRange, timezone, LOGS_DATE_OPTIONS)-return (- <Popover- visible={popoverOpen}- onClickOutside={() => setPopoverOpen(false)}- placement="bottom-end"- overlay={- <div className="w-fit bg-bg-light rounded-lg overflow-hidden flex flex-row-reverse">- <div className="flex flex-col gap-1 p-3">- <div className="text-xs font-medium text-secondary mb-1">In the last</div>- {LOGS_DATE_OPTIONS.map((option) => (- <LemonButton- key={option.key}- size="small"- type={isOptionSelected(option) ? 'primary' : 'tertiary'}- onClick={() => handleSelectOption(option)}- fullWidth- >- {getShortLabel(option)}- </LemonButton>- ))}- <RollingDateRangeFilter- dateFrom={dateRange.date_from}- selected={true}- dateRangeFilterLabel=""- onChange={(fromDate) => {- setDateRange({ date_from: fromDate, date_to: null })- addToHistory({ date_from: fromDate, date_to: null })- }}- fullWidth- allowedDateOptions={['minutes', 'hours', 'days']}- />- </div>-- <LemonDivider vertical className="my-3" />-- <div className="flex flex-col gap-3 p-3 w-fit">- <div className="flex flex-col gap-2">- <div className="text-xs font-medium text-secondary">Custom range</div>- <div className="flex gap-2">- <DateTimeInput- value={customFrom}- onChange={setCustomFrom}- placeholder="-1h, -30M..."- timezone={timezone}- label="From"- />- <DateTimeInput- value={customTo}- onChange={setCustomTo}- placeholder="now"- timezone={timezone}- label="To"- />- </div>- <LemonButton type="primary" size="small" onClick={handleApplyCustom} fullWidth>- Apply- </LemonButton>- </div>-- {history.length > 0 && (- <>- <LemonDivider className="my-0" />- <div className="flex flex-col gap-1 flex-1">- <div className="text-xs font-medium text-secondary">Recent</div>- {history.map((historyDateRange, index) => (- <LemonButton- key={index}- size="small"- type="tertiary"- fullWidth- icon={<IconClock className="text-secondary" />}- onClick={() => handleSelectHistory(historyDateRange)}- >- <span className="truncate">- {formatDateRangeLabel(historyDateRange, timezone, LOGS_DATE_OPTIONS)}- </span>- </LemonButton>- ))}- </div>- </>- )}-- <LemonDivider className="my-0" />- <TimezoneSelect value={timezone} onChange={setTimezone} size="xsmall" />- </div>- </div>- }- >- <LemonButton- size="small"- type="secondary"- icon={<IconCalendar />}- onClick={() => setPopoverOpen(!popoverOpen)}- >- {currentLabel}- </LemonButton>- </Popover>+ <DateRangePicker+ logicKey="logs"+ dateRange={dateRange}+ setDateRange={setDateRange}+ timezone={timezone}+ onTimezoneChange={setTimezone}+ />)}diff --git a/products/logs/frontend/components/LogsViewer/Filters/LogsFilterBar/LogsFilterBar.tsx b/products/logs/frontend/components/LogsViewer/Filters/LogsFilterBar/LogsFilterBar.tsxindex 6c5a5d2caa71..05c51c30be58 100644--- a/products/logs/frontend/components/LogsViewer/Filters/LogsFilterBar/LogsFilterBar.tsx+++ b/products/logs/frontend/components/LogsViewer/Filters/LogsFilterBar/LogsFilterBar.tsx@@ -1,5 +1,3 @@-import './LogsFilterBar.scss'-import { BindLogic, useActions, useValues } from 'kea'import { useRef, useState } from 'react'diff --git a/products/logs/frontend/components/LogsViewer/Filters/logsViewerFiltersLogic.ts b/products/logs/frontend/components/LogsViewer/Filters/logsViewerFiltersLogic.tsindex 6dcb50e0f51b..469f9ee8b206 100644--- a/products/logs/frontend/components/LogsViewer/Filters/logsViewerFiltersLogic.ts+++ b/products/logs/frontend/components/LogsViewer/Filters/logsViewerFiltersLogic.ts@@ -2,6 +2,7 @@ import equal from 'fast-deep-equal'import { actions, afterMount, kea, key, listeners, path, propsChanged, props, reducers, selectors } from 'kea'import posthog from 'posthog-js'+import { zoomDateRange } from 'lib/components/DateFilter/DateRangePicker'import { DEFAULT_UNIVERSAL_GROUP_FILTER } from 'lib/components/UniversalFilters/universalFiltersLogic'import { dayjs } from 'lib/dayjs'@@ -15,7 +16,6 @@ import {} from '~/types'import { LogsViewerFilters } from 'products/logs/frontend/components/LogsViewer/config/types'-import { zoomDateRange } from 'products/logs/frontend/components/LogsViewer/Filters/zoom-utils'import type { logsViewerFiltersLogicType } from './logsViewerFiltersLogicType'diff --git a/products/logs/frontend/components/LogsViewer/LogsViewerToolbar.tsx b/products/logs/frontend/components/LogsViewer/LogsViewerToolbar.tsxindex d3426c35d8bb..6281827af923 100644--- a/products/logs/frontend/components/LogsViewer/LogsViewerToolbar.tsx+++ b/products/logs/frontend/components/LogsViewer/LogsViewerToolbar.tsx@@ -3,6 +3,7 @@ import { useActions, useValues } from 'kea'import { IconExpand45, IconKeyboard } from '@posthog/icons'import { LemonButton, LemonCheckbox, LemonSegmentedButton, Tooltip } from '@posthog/lemon-ui'+import { TimezoneSelect } from 'lib/components/TimezoneSelect'import { humanFriendlyNumber } from 'lib/utils/numbers'import { KeyboardShortcut } from '~/layout/navigation-3000/components/KeyboardShortcut'@@ -11,7 +12,6 @@ import { LogsOrderBy } from 'products/logs/frontend/types'import { LogsExportMenu } from './LogsExportMenu'import { logsViewerLogic } from './logsViewerLogic'-import { TimezoneSelect } from './TimezoneSelect'export interface LogsViewerToolbarProps {totalLogsCount?: numberdiff --git a/products/logs/frontend/utils.test.ts b/products/logs/frontend/utils.test.tsindex 4609e71a05bd..e2d61b91938a 100644--- a/products/logs/frontend/utils.test.ts+++ b/products/logs/frontend/utils.test.ts@@ -6,7 +6,7 @@ import {isSessionIdKey,} from './utils'-jest.mock('products/logs/frontend/components/LogsViewer/Filters/LogsDateRangePicker/utils', () => ({+jest.mock('lib/components/DateFilter/DateRangePicker/utils', () => ({formatDateRangeLabel: () => '-1h \u2192 now',}))diff --git a/products/logs/frontend/utils.tsx b/products/logs/frontend/utils.tsxindex ca3a6c107389..a8079d0d158c 100644--- a/products/logs/frontend/utils.tsx+++ b/products/logs/frontend/utils.tsx@@ -1,10 +1,9 @@+import { formatDateRangeLabel } from 'lib/components/DateFilter/DateRangePicker/utils'import { isValidPropertyFilter } from 'lib/components/PropertyFilters/utils'import { capitalizeFirstLetter } from 'lib/utils/strings'import { AnyPropertyFilter } from '~/types'-import { formatDateRangeLabel } from 'products/logs/frontend/components/LogsViewer/Filters/LogsDateRangePicker/utils'-export function formatFilterGroupValues(filterGroup: Record<string, any> | undefined): string[] {const group = filterGroup?.values?.[0]if (!group || !('values' in group)) {diff --git a/products/tracing/frontend/TracingFilterBar.tsx b/products/tracing/frontend/TracingFilterBar.tsxindex 52a5bc1d6a9c..493bb65edd11 100644--- a/products/tracing/frontend/TracingFilterBar.tsx+++ b/products/tracing/frontend/TracingFilterBar.tsx@@ -12,8 +12,7 @@ import {LemonTag,} from '@posthog/lemon-ui'-import { DateFilter } from 'lib/components/DateFilter/DateFilter'-import { CUSTOM_OPTION_KEY } from 'lib/components/DateFilter/types'+import { DateRangePicker, zoomDateRange } from 'lib/components/DateFilter/DateRangePicker'import { InfiniteSelectResults } from 'lib/components/TaxonomicFilter/InfiniteSelectResults'import { TaxonomicFilterSearchInput } from 'lib/components/TaxonomicFilter/TaxonomicFilter'import { taxonomicFilterLogic } from 'lib/components/TaxonomicFilter/taxonomicFilterLogic'@@ -23,12 +22,10 @@ import { universalFiltersLogic } from 'lib/components/UniversalFilters/universalimport { isUniversalGroupFilterLike } from 'lib/components/UniversalFilters/utils'import { dayjs } from 'lib/dayjs'import { useOnMountEffect } from 'lib/hooks/useOnMountEffect'-import { DATE_TIME_FORMAT, formatDateRange } from 'lib/utils/datetime'import { DateRange } from '~/queries/schema/schema-general'import {AnyPropertyFilter,- DateMappingOption,FilterLogicalOperator,PropertyFilterType,PropertyOperator,@@ -47,51 +44,11 @@ const taxonomicGroupTypes = [TaxonomicFilterGroupType.SpanResourceAttributes,]-const dateMapping: DateMappingOption[] = [- { key: CUSTOM_OPTION_KEY, values: [] },- {- key: 'Last 5 minutes',- values: ['-5M'],- getFormattedDate: (date: dayjs.Dayjs): string => date.subtract(5, 'minute').format(DATE_TIME_FORMAT),- defaultInterval: 'minute',- },- {- key: 'Last 30 minutes',- values: ['-30M'],- getFormattedDate: (date: dayjs.Dayjs): string => date.subtract(30, 'minute').format(DATE_TIME_FORMAT),- defaultInterval: 'minute',- },- {- key: 'Last 1 hour',- values: ['-1h'],- getFormattedDate: (date: dayjs.Dayjs): string => formatDateRange(date.subtract(1, 'h'), date.endOf('d')),- defaultInterval: 'hour',- },- {- key: 'Last 4 hours',- values: ['-4h'],- getFormattedDate: (date: dayjs.Dayjs): string => formatDateRange(date.subtract(4, 'h'), date.endOf('d')),- defaultInterval: 'hour',- },- {- key: 'Last 24 hours',- values: ['-24h'],- getFormattedDate: (date: dayjs.Dayjs): string => formatDateRange(date.subtract(24, 'h'), date.endOf('d')),- defaultInterval: 'hour',- },- {- key: 'Last 7 days',- values: ['-7d'],- getFormattedDate: (date: dayjs.Dayjs): string => formatDateRange(date.subtract(7, 'd'), date.endOf('d')),- defaultInterval: 'day',- },-]-export function TracingFilterBar(): JSX.Element {const { spansLoading } = useValues(tracingDataLogic())const { runQuery } = useActions(tracingDataLogic())- const { filters, utcDateRange } = useValues(tracingFiltersLogic())- const { setDateRange, setServiceNames, setFilterGroup, setViewMode, setCompareMode } =+ const { filters, utcDateRange, timezone } = useValues(tracingFiltersLogic())+ const { setDateRange, setTimezone, setServiceNames, setFilterGroup, setViewMode, setCompareMode } =useActions(tracingFiltersLogic())const { dateRange, serviceNames, filterGroup, viewMode, compareMode } = filters@@ -110,34 +67,26 @@ export function TracingFilterBar(): JSX.Element {</div></div><div className="flex shrink-0 gap-1.5">- <div className="flex">+ <div className="DateRangePickerButtonGroup"><LemonButtonsize="small"icon={<IconMinusSquare />}type="secondary"tooltip="Zoom out"onClick={() => {- const from = dayjs(dateRange.date_from)- const to = dateRange.date_to ? dayjs(dateRange.date_to) : dayjs()- const diff = to.diff(from, 'millisecond')+ const zoomed = zoomDateRange(dateRange, 2)setDateRange({- date_from: from.subtract(diff / 2, 'millisecond').toISOString(),- date_to: to.add(diff / 2, 'millisecond').toISOString(),+ date_from: zoomed.date_from ?? null,+ date_to: zoomed.date_to ?? null,})}}/>- <DateFilter- size="small"- dateFrom={dateRange.date_from}- dateTo={dateRange.date_to}- dateOptions={dateMapping}- onChange={(changedDateFrom, changedDateTo) => {- setDateRange({ date_from: changedDateFrom, date_to: changedDateTo })- }}- allowTimePrecision- allowFixedRangeWithTime- allowedRollingDateOptions={['minutes', 'hours', 'days', 'weeks', 'months']}- use24HourFormat+ <DateRangePicker+ logicKey="tracing"+ dateRange={dateRange}+ setDateRange={setDateRange}+ timezone={timezone}+ onTimezoneChange={setTimezone}/><LemonButtonsize="small"@@ -145,12 +94,10 @@ export function TracingFilterBar(): JSX.Element {type="secondary"tooltip="Zoom in"onClick={() => {- const from = dayjs(dateRange.date_from)- const to = dateRange.date_to ? dayjs(dateRange.date_to) : dayjs()- const diff = to.diff(from, 'millisecond')+ const zoomed = zoomDateRange(dateRange, 0.5)setDateRange({- date_from: from.add(diff / 4, 'millisecond').toISOString(),- date_to: to.subtract(diff / 4, 'millisecond').toISOString(),+ date_from: zoomed.date_from ?? null,+ date_to: zoomed.date_to ?? null,})}}/>diff --git a/products/tracing/frontend/tracingFiltersLogic.ts b/products/tracing/frontend/tracingFiltersLogic.tsindex 19192e4ff7fd..e65e74432c92 100644--- a/products/tracing/frontend/tracingFiltersLogic.ts+++ b/products/tracing/frontend/tracingFiltersLogic.ts@@ -9,6 +9,7 @@ import { UniversalFiltersGroup } from '~/types'import type { tracingFiltersLogicType } from './tracingFiltersLogicType'export const DEFAULT_DATE_RANGE: DateRange = { date_from: '-1h', date_to: null }+export const DEFAULT_TIMEZONE: string = 'UTC'export const DEFAULT_SERVICE_NAMES: string[] = []export const DEFAULT_ORDER_BY = 'timestamp' as constexport const DEFAULT_ORDER_DIRECTION = 'DESC' as const@@ -46,6 +47,7 @@ export const tracingFiltersLogic = kea<tracingFiltersLogicType>([actions({setDateRange: (dateRange: DateRange) => ({ dateRange }),+ setTimezone: (timezone: string) => ({ timezone }),setServiceNames: (serviceNames: string[]) => ({ serviceNames }),setFilterGroup: (filterGroup: UniversalFiltersGroup) => ({ filterGroup }),setSort: (orderBy: TracingOrderBy, orderDirection: TracingOrderDirection) => ({ orderBy, orderDirection }),@@ -67,6 +69,13 @@ export const tracingFiltersLogic = kea<tracingFiltersLogicType>([setFilters: (state, { filters }) => filters.dateRange ?? state,},],+ timezone: [+ DEFAULT_TIMEZONE,+ { persist: true },+ {+ setTimezone: (_, { timezone }) => timezone,+ },+ ],serviceNames: [DEFAULT_SERVICE_NAMES as string[],{