: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
fix(logs): move compare controls to the display bar, drop explain-changes (#70381)
Jon McCallume749459571af
diff --git a/products/logs/frontend/components/LogsPatterns/LogsPatterns.tsx b/products/logs/frontend/components/LogsPatterns/LogsPatterns.tsxindex fbef1114d0cb..de5423465779 100644--- a/products/logs/frontend/components/LogsPatterns/LogsPatterns.tsx+++ b/products/logs/frontend/components/LogsPatterns/LogsPatterns.tsx@@ -1,6 +1,6 @@import { useActions, useValues } from 'kea'-import { LemonBanner, LemonButton, LemonSelect, LemonSwitch, LemonTable, LemonTag, Tooltip } from '@posthog/lemon-ui'+import { LemonBanner, LemonButton, LemonTable, LemonTag, Tooltip } from '@posthog/lemon-ui'import type { LemonTableColumns } from '@posthog/lemon-ui'import { Sparkline } from 'lib/components/Sparkline'@@ -210,11 +210,10 @@ export function LogsPatterns({ id }: { id: string }): JSX.Element {patternsError,sparklineLabels,compareEnabled,- baselineMode,diffResponse,diffResponseLoading,} = useValues(logsPatternsLogic({ id }))- const { viewMatchingLogs, setCompareEnabled, setBaselineMode } = useActions(logsPatternsLogic({ id }))+ const { viewMatchingLogs } = useActions(logsPatternsLogic({ id }))const { sampled, scanned_count, total_count, sample_coverage_pct } = patternsResponse// Estimated counts are rounded (not exact-comma-formatted) and prefixed with "~" so a@@ -364,29 +363,6 @@ export function LogsPatterns({ id }: { id: string }): JSX.Element {return (<div className="flex-1 min-h-0 overflow-auto" data-attr="logs-patterns">- <div className="flex items-center gap-2 m-2">- <LemonSwitch- checked={compareEnabled}- onChange={setCompareEnabled}- label="Compare"- bordered- size="small"- data-attr="logs-patterns-compare-toggle"- />- {compareEnabled && (- <LemonSelect- size="small"- loading={diffResponseLoading}- value={baselineMode}- onChange={setBaselineMode}- options={[- { value: 'lastWeek' as const, label: 'vs. same time last week' },- { value: 'preceding' as const, label: 'vs. preceding period' },- ]}- data-attr="logs-patterns-baseline-mode"- />- )}- </div>{!compareEnabled && sampled && !patternsResponseLoading && !patternsError && (<LemonBanner type="info" className="m-2" data-attr="logs-patterns-sample-info">Patterns are mined from a representative sample of {humanFriendlyNumber(scanned_count)} lines out ofdiff --git a/products/logs/frontend/components/LogsPatterns/logsPatternsLogic.test.ts b/products/logs/frontend/components/LogsPatterns/logsPatternsLogic.test.tsindex a92ed7e3a8d1..eb3b7d58818f 100644--- a/products/logs/frontend/components/LogsPatterns/logsPatternsLogic.test.ts+++ b/products/logs/frontend/components/LogsPatterns/logsPatternsLogic.test.ts@@ -232,17 +232,18 @@ describe('logsPatternsLogic', () => {)})- it('openPatternsComparison before mount arms compare so mounting loads the diff', async () => {- // The "explain changes" button lives in the Logs view and fires before this logic- // exists: it arms compare state on the config logic, then the view switch mounts- // Patterns. If afterMount ignored that state and ran the plain mine, the button- // would silently answer the wrong question.+ it('compare armed before mount makes mounting load the diff, not the plain mine', async () => {+ // Compare state lives on the config logic and survives Logs↔Patterns lens switches,+ // while this logic unmounts when leaving the lens. Re-entering Patterns with compare+ // still on must resume the diff — an afterMount that always ran the plain mine would+ // silently show the wrong table.mockDiffCreate.mockResolvedValue(DIFF_RESPONSE)const configLogic = logsViewerConfigLogic({ id: ID })configLogic.mount()- configLogic.actions.openPatternsComparison('preceding')- expect(configLogic.values.viewMode).toBe('patterns')+ configLogic.actions.setCompareEnabled(true)+ configLogic.actions.setBaselineMode('preceding')+ configLogic.actions.setViewMode('patterns')logic.mount()await expectLogic(logic).toDispatchActions(['loadDiff', 'loadDiffSuccess'])diff --git a/products/logs/frontend/components/LogsPatterns/logsPatternsLogic.ts b/products/logs/frontend/components/LogsPatterns/logsPatternsLogic.tsindex a2d1dc55b92b..40f5caca0e40 100644--- a/products/logs/frontend/components/LogsPatterns/logsPatternsLogic.ts+++ b/products/logs/frontend/components/LogsPatterns/logsPatternsLogic.ts@@ -308,9 +308,9 @@ export const logsPatternsLogic = kea<logsPatternsLogicType>([}),afterMount(({ actions, values }) => {- // Compare may already be armed before this logic mounts — e.g. "explain changes" in the- // Logs view dispatches openPatternsComparison on the config logic, then the view switch- // mounts Patterns. Loading the plain mine here would answer the wrong question.+ // Compare state lives on the config logic and survives Logs↔Patterns lens switches,+ // so this logic can mount with compare already on — loading the plain mine then would+ // answer the wrong question.if (values.compareEnabled) {actions.loadDiff()} else {diff --git a/products/logs/frontend/components/LogsViewer/LogsDisplayBar.tsx b/products/logs/frontend/components/LogsViewer/LogsDisplayBar.tsxindex ed70cf500f86..08343ec974b3 100644--- a/products/logs/frontend/components/LogsViewer/LogsDisplayBar.tsx+++ b/products/logs/frontend/components/LogsViewer/LogsDisplayBar.tsx@@ -1,7 +1,7 @@import { useActions, useValues } from 'kea'import { IconChevronLeft, IconChevronRight } from '@posthog/icons'-import { LemonButton, LemonSegmentedButton } from '@posthog/lemon-ui'+import { LemonButton, LemonSegmentedButton, LemonSelect, LemonSwitch } from '@posthog/lemon-ui'import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'import { TaxonomicStringPopover } from 'lib/components/TaxonomicPopover/TaxonomicPopover'@@ -40,7 +40,7 @@ export const LogsDisplayBar = ({totalLogsCount,}: LogsDisplayBarProps): JSX.Element => {const { facetRailCollapsed, viewMode, groupBy } = useValues(logsViewerConfigLogic)- const { setFacetRailCollapsed, setViewMode, setGroupBy, openPatternsComparison } = useActions(logsViewerConfigLogic)+ const { setFacetRailCollapsed, setViewMode, setGroupBy } = useActions(logsViewerConfigLogic)const showPatternsView = useFeatureFlag('LOGS_PATTERNS_VIEW')const showGroupBy = useFeatureFlag('LOGS_GROUP_BY')@@ -124,18 +124,48 @@ export const LogsDisplayBar = ({<span className="text-muted text-xs">{humanFriendlyNumber(totalLogsCount)} logs</span>))}- {showPatternsView && !inPatternsMode && !inGroupByMode && (- <LemonButton- size="small"- onClick={() => openPatternsComparison('preceding')}- tooltip="Mine this window's log patterns and compare them against the period just before it — new and shifted message templates first. Drag-select a spike on the chart first to explain exactly that range."- data-attr="logs-explain-changes"- >- Explain changes- </LemonButton>- )}</div>- {!inPatternsMode && !inGroupByMode && <LogsViewerToolbar totalLogsCount={totalLogsCount} />}+ {inPatternsMode ? (+ <PatternsCompareControls id={id} />+ ) : (+ !inGroupByMode && <LogsViewerToolbar totalLogsCount={totalLogsCount} />+ )}+ </div>+ )+}++/**+ * Patterns mode's contextual-right tools: the Compare toggle and its baseline picker. Lives in+ * the display bar's right slot (like the Logs toolbar) rather than inside the results region,+ * and in its own component so `logsPatternsLogic` only mounts while Patterns is active.+ */+const PatternsCompareControls = ({ id }: { id: string }): JSX.Element => {+ const { compareEnabled, baselineMode, diffResponseLoading } = useValues(logsPatternsLogic({ id }))+ const { setCompareEnabled, setBaselineMode } = useActions(logsPatternsLogic({ id }))++ return (+ <div className="flex items-center gap-2">+ {compareEnabled && (+ <LemonSelect+ size="small"+ loading={diffResponseLoading}+ value={baselineMode}+ onChange={setBaselineMode}+ options={[+ { value: 'lastWeek' as const, label: 'vs. same time last week' },+ { value: 'preceding' as const, label: 'vs. preceding period' },+ ]}+ data-attr="logs-patterns-baseline-mode"+ />+ )}+ <LemonSwitch+ checked={compareEnabled}+ onChange={setCompareEnabled}+ label="Compare"+ bordered+ size="small"+ data-attr="logs-patterns-compare-toggle"+ /></div>)}diff --git a/products/logs/frontend/components/LogsViewer/config/logsViewerConfigLogic.ts b/products/logs/frontend/components/LogsViewer/config/logsViewerConfigLogic.tsindex 17aa26917e1d..07295a581e01 100644--- a/products/logs/frontend/components/LogsViewer/config/logsViewerConfigLogic.ts+++ b/products/logs/frontend/components/LogsViewer/config/logsViewerConfigLogic.ts@@ -68,10 +68,6 @@ export const logsViewerConfigLogic = kea<logsViewerConfigLogicType>([setGroupBy: (groupBy: LogsViewerGroupBy | null) => ({ groupBy }),setCompareEnabled: (enabled: boolean) => ({ enabled }),setBaselineMode: (mode: PatternsBaselineMode) => ({ mode }),- // One-click "explain this window": open the Patterns view in compare mode against the- // given baseline. Atomic so callers in other views (Logs toolbar, alert scenes) can't- // half-configure the pivot.- openPatternsComparison: (mode: PatternsBaselineMode) => ({ mode }),// Typed columns (unified column model)setColumns: (columns: LogsColumnConfig[]) => ({ columns }),@@ -124,24 +120,21 @@ export const logsViewerConfigLogic = kea<logsViewerConfigLogicType>([DEFAULT_VIEW_MODE as LogsViewerViewMode,{setViewMode: (_, { viewMode }) => viewMode,- openPatternsComparison: () => 'patterns' as LogsViewerViewMode,},],- // Compare state lives here (not in logsPatternsLogic) so views other than Patterns can- // arm the comparison before the patterns logic mounts, and the choice survives- // Logs↔Patterns switches within a visit. Not persisted, like viewMode and groupBy.+ // Compare state lives here (not in logsPatternsLogic) so the choice survives+ // Logs↔Patterns switches within a visit — the patterns logic unmounts when leaving+ // the lens. Not persisted, like viewMode and groupBy.compareEnabled: [false,{setCompareEnabled: (_, { enabled }) => enabled,- openPatternsComparison: () => true,},],baselineMode: ['lastWeek' as PatternsBaselineMode,{setBaselineMode: (_, { mode }) => mode,- openPatternsComparison: (_, { mode }) => mode,},],columns: [