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.

fix(logs): close impact drill-down when the recording modal opens (#98820)

Jimmy Zhuabcd6ca2bb4c
diff --git a/products/logs/frontend/components/LogsViewer/LogsImpactCounts.test.tsx b/products/logs/frontend/components/LogsViewer/LogsImpactCounts.test.tsx
new file mode 100644
index 000000000000..39165f7a5ac2
--- /dev/null
+++ b/products/logs/frontend/components/LogsViewer/LogsImpactCounts.test.tsx
@@ -0,0 +1,51 @@
+import '@testing-library/jest-dom'
+
+import { act, fireEvent, render, screen, waitFor } from '@testing-library/react'
+
+import { sessionPlayerModalLogic } from 'scenes/session-recordings/player/modal/sessionPlayerModalLogic'
+
+import { initKeaTests } from '~/test/init'
+
+import type { _LogsImpactResponseApi } from 'products/logs/frontend/generated/api.schemas'
+
+import { LogsImpactCounts } from './LogsImpactCounts'
+
+describe('LogsImpactCounts', () => {
+ beforeEach(() => {
+ initKeaTests()
+ })
+
+ const impact: _LogsImpactResponseApi = {
+ total: 100,
+ logsWithSessionId: 90,
+ sessions: 3,
+ logsWithDistinctId: 0,
+ users: 0,
+ topSessions: [],
+ topUsers: [],
+ sessionGroupKey: { source: 'log', key: 'sessionId' },
+ personGroupKey: null,
+ }
+
+ it('closes the sessions drill-down when the session player modal opens', async () => {
+ render(<LogsImpactCounts impact={impact} />)
+
+ fireEvent.click(screen.getByText('sessions'))
+ expect(screen.getByText(/Estimated unique session IDs/)).toBeInTheDocument()
+
+ // The player modal renders below the popover layer, so the drill-down must close.
+ act(() => {
+ sessionPlayerModalLogic.actions.openSessionPlayer({ id: 'some-session-id' })
+ })
+ // The popover stays in the DOM until its exit transition completes.
+ await waitFor(() => {
+ expect(screen.queryByText(/Estimated unique session IDs/)).not.toBeInTheDocument()
+ })
+
+ // The drill-down stays closed after the modal closes; it must not pop back open.
+ act(() => {
+ sessionPlayerModalLogic.actions.closeSessionPlayer()
+ })
+ expect(screen.queryByText(/Estimated unique session IDs/)).not.toBeInTheDocument()
+ })
+})
diff --git a/products/logs/frontend/components/LogsViewer/LogsImpactCounts.tsx b/products/logs/frontend/components/LogsViewer/LogsImpactCounts.tsx
index f26088cfca53..4ae75aa0f0a9 100644
--- a/products/logs/frontend/components/LogsViewer/LogsImpactCounts.tsx
+++ b/products/logs/frontend/components/LogsViewer/LogsImpactCounts.tsx
@@ -1,3 +1,6 @@
+import { useValues } from 'kea'
+import { useState } from 'react'
+
import { LemonButton, LemonDropdown, Tooltip } from '@posthog/lemon-ui'
import ViewRecordingButton, {
@@ -5,6 +8,7 @@ import ViewRecordingButton, {
ViewRecordingButtonVariant,
} from 'lib/components/ViewRecordingButton/ViewRecordingButton'
import { humanFriendlyLargeNumber, percentage } from 'lib/utils/numbers'
+import { sessionPlayerModalLogic } from 'scenes/session-recordings/player/modal/sessionPlayerModalLogic'
import type { _LogsImpactResponseApi, _LogsImpactTopValueApi } from 'products/logs/frontend/generated/api.schemas'
import { PersonDisplay } from 'products/persons/frontend/components/PersonDisplay'
@@ -28,6 +32,18 @@ export function LogsImpactCounts({
onGroupBySessions,
onGroupByUsers,
}: LogsImpactCountsProps): JSX.Element | null {
+ const { activeSessionRecording } = useValues(sessionPlayerModalLogic)
+ const [sessionsDropdownVisible, setSessionsDropdownVisible] = useState(false)
+ const [usersDropdownVisible, setUsersDropdownVisible] = useState(false)
+
+ // The player modal renders below the popover layer, so an open drill-down would cover the
+ // recording. Closing the state during render hides the drill-downs from the first modal frame,
+ // and they stay closed after the modal goes away.
+ if (activeSessionRecording && (sessionsDropdownVisible || usersDropdownVisible)) {
+ setSessionsDropdownVisible(false)
+ setUsersDropdownVisible(false)
+ }
+
if (impact.total === 0) {
return null
}
@@ -68,6 +84,8 @@ export function LogsImpactCounts({
<LemonDropdown
placement="bottom-start"
closeOnClickInside={false}
+ visible={sessionsDropdownVisible}
+ onVisibilityChange={setSessionsDropdownVisible}
overlay={
<TopValuesOverlay
caption={sessionsCaption}
@@ -101,6 +119,8 @@ export function LogsImpactCounts({
<LemonDropdown
placement="bottom-start"
closeOnClickInside={false}
+ visible={usersDropdownVisible}
+ onVisibilityChange={setUsersDropdownVisible}
overlay={
<TopValuesOverlay
caption={usersCaption}