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(navigation): gear icon opening internal-user settings no longer routes to AI (#59112)

Paul D'Ambraa61c58e87db8
diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/settings/sidePanelSettingsLogic.tsx b/frontend/src/layout/navigation-3000/sidepanel/panels/settings/sidePanelSettingsLogic.tsx
index da5b0c0ba332..1fae613422b9 100644
--- a/frontend/src/layout/navigation-3000/sidepanel/panels/settings/sidePanelSettingsLogic.tsx
+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/settings/sidePanelSettingsLogic.tsx
@@ -44,13 +44,18 @@ export const sidePanelSettingsLogic = kea<sidePanelSettingsLogicType>([
closeSettingsPanel: () => ({}),
},
],
- /** Whether the current settings were explicitly set via openSettingsPanel */
+ /** Whether the current settings were explicitly set via openSettingsPanel.
+ * Stays true while the user remains on the Settings tab so the explicit
+ * section/setting is preserved (and so `sidePanelLogic.enabledTabs` keeps
+ * Settings available on scenes without a `settings_section`). Resets when
+ * the user switches to a different tab or closes the panel. */
isExplicitSettings: [
false,
{
openSettingsPanel: () => true,
closeSettingsPanel: () => false,
- openSidePanel: () => false,
+ closeSidePanel: () => false,
+ openSidePanel: (state, { tab }) => (tab === SidePanelTab.Settings ? state : false),
},
],
previousTab: [
diff --git a/frontend/src/layout/navigation-3000/sidepanel/sidePanelLogic.tsx b/frontend/src/layout/navigation-3000/sidepanel/sidePanelLogic.tsx
index 448509fbc19b..c3ca81e393a2 100644
--- a/frontend/src/layout/navigation-3000/sidepanel/sidePanelLogic.tsx
+++ b/frontend/src/layout/navigation-3000/sidepanel/sidePanelLogic.tsx
@@ -9,6 +9,7 @@ import { userLogic } from 'scenes/userLogic'
import { sceneLayoutLogic } from '~/layout/scenes/sceneLayoutLogic'
import { AvailableFeature, SidePanelTab } from '~/types'
+import { sidePanelSettingsLogic } from './panels/settings/sidePanelSettingsLogic'
import { sidePanelContextLogic } from './sidePanelContextLogic'
import type { sidePanelLogicType } from './sidePanelLogicType'
import { sidePanelStateLogic } from './sidePanelStateLogic'
@@ -38,6 +39,8 @@ export const sidePanelLogic = kea<sidePanelLogicType>([
['isCloudOrDev'],
userLogic,
['hasAvailableFeature'],
+ sidePanelSettingsLogic,
+ ['isExplicitSettings'],
],
actions: [sidePanelStateLogic, ['closeSidePanel', 'openSidePanel']],
})),
@@ -50,8 +53,16 @@ export const sidePanelLogic = kea<sidePanelLogicType>([
s.scenePanelIsPresent,
s.isCloudOrDev,
s.hasAvailableFeature,
+ s.isExplicitSettings,
],
- (sceneSidePanelContext, currentTeam, scenePanelIsPresent, isCloudOrDev, hasAvailableFeature) => {
+ (
+ sceneSidePanelContext,
+ currentTeam,
+ scenePanelIsPresent,
+ isCloudOrDev,
+ hasAvailableFeature,
+ isExplicitSettings
+ ) => {
const tabs: SidePanelTab[] = []
if (scenePanelIsPresent) {
@@ -70,7 +81,11 @@ export const sidePanelLogic = kea<sidePanelLogicType>([
tabs.push(SidePanelTab.AccessControl)
}
- if (sceneSidePanelContext.settings_section) {
+ // Settings is enabled when the scene declares a `settings_section` OR when the
+ // user explicitly opened settings via `openSettingsPanel(...)` (e.g. the gear
+ // icon next to "Filter out internal and test users"). Direct, non-explicit
+ // `openSidePanel(Settings)` calls still respect scene context.
+ if (sceneSidePanelContext.settings_section || isExplicitSettings) {
tabs.push(SidePanelTab.Settings)
}
@@ -91,10 +106,14 @@ export const sidePanelLogic = kea<sidePanelLogicType>([
/** Tabs shown in the navigation bar */
visibleTabs: [
- (s) => [s.enabledTabs],
- (enabledTabs): SidePanelTab[] => {
+ (s) => [s.enabledTabs, s.sceneSidePanelContext],
+ (enabledTabs, sceneSidePanelContext): SidePanelTab[] => {
// Some tabs are openable programmatically but not shown in the nav bar
- const hiddenTabs = [SidePanelTab.Exports]
+ const hiddenTabs: SidePanelTab[] = [SidePanelTab.Exports]
+ // Hide Settings from the nav bar unless the scene declares a settings_section.
+ if (!sceneSidePanelContext.settings_section) {
+ hiddenTabs.push(SidePanelTab.Settings)
+ }
return enabledTabs.filter((tab) => !hiddenTabs.includes(tab))
},
],
diff --git a/frontend/src/lib/components/TestAccountFiltersSwitch.test.tsx b/frontend/src/lib/components/TestAccountFiltersSwitch.test.tsx
new file mode 100644
index 000000000000..e0fe2190ae05
--- /dev/null
+++ b/frontend/src/lib/components/TestAccountFiltersSwitch.test.tsx
@@ -0,0 +1,103 @@
+import '@testing-library/jest-dom'
+
+import { cleanup, render, screen } from '@testing-library/react'
+import userEvent from '@testing-library/user-event'
+
+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
+
+import { sidePanelSettingsLogic } from '~/layout/navigation-3000/sidepanel/panels/settings/sidePanelSettingsLogic'
+import { sidePanelLogic } from '~/layout/navigation-3000/sidepanel/sidePanelLogic'
+import { sidePanelStateLogic } from '~/layout/navigation-3000/sidepanel/sidePanelStateLogic'
+import { initKeaTests } from '~/test/init'
+import { SidePanelTab } from '~/types'
+
+import { TestAccountFilterSwitch } from './TestAccountFiltersSwitch'
+
+// Regression coverage for https://github.com/PostHog/posthog/pull/59112
+// — clicking the gear icon next to "Filter out internal and test users" used to
+// open the PostHog AI (Max) side panel instead of Settings on any scene whose
+// `SIDE_PANEL_CONTEXT_KEY` selector did not declare a `settings_section`
+// (experiments, SQL editor, LLM analytics, hog functions, etc.).
+describe('TestAccountFilterSwitch — gear icon opens Settings, not the AI side panel', () => {
+ beforeEach(() => {
+ initKeaTests()
+ featureFlagLogic.mount()
+ // Mount the side-panel state machinery directly. We deliberately do NOT
+ // mount any scene logic, so `sceneSidePanelContext.settings_section` is
+ // undefined — the exact condition under which the bug used to bite.
+ sidePanelStateLogic.mount()
+ sidePanelSettingsLogic.mount()
+ sidePanelLogic.mount()
+ })
+
+ afterEach(() => {
+ cleanup()
+ })
+
+ it('routes the user to the Settings side panel when the gear icon is clicked', async () => {
+ const onChange = jest.fn()
+ render(<TestAccountFilterSwitch checked={false} onChange={onChange} />)
+
+ // The LemonSwitch itself has role="switch"; the gear is the only plain button.
+ const gear = screen.getByRole('button')
+ await userEvent.click(gear)
+
+ const stateValues = sidePanelStateLogic.values
+ const enabledTabs = sidePanelLogic.values.enabledTabs
+
+ expect(stateValues.sidePanelOpen).toBe(true)
+ expect(stateValues.selectedTab).toBe(SidePanelTab.Settings)
+
+ // The bug was that on a scene without `settings_section`, Settings was
+ // missing from `enabledTabs`, so `SidePanel.tsx`'s fallback `useEffect`
+ // flipped `selectedTab` to `Max`. Asserting Settings is enabled proves
+ // the fallback's `!sidePanelOpenAndAvailable` precondition is false.
+ expect(enabledTabs).toContain(SidePanelTab.Settings)
+ expect(enabledTabs.includes(SidePanelTab.Max)).toBe(true)
+ // Replicates the `sidePanelOpenAndAvailable` check from SidePanel.tsx —
+ // when true, the fallback to Max cannot run.
+ expect(enabledTabs.includes(stateValues.selectedTab!)).toBe(true)
+ })
+
+ it('forwards the explicit section and setting ids that scroll to internal-user-filtering', async () => {
+ const onChange = jest.fn()
+ render(<TestAccountFilterSwitch checked={false} onChange={onChange} />)
+
+ await userEvent.click(screen.getByRole('button'))
+
+ // `settings` carries the explicit args from `openSettingsPanel(...)`. The
+ // Settings panel reads these to scroll the right setting into view.
+ expect(sidePanelSettingsLogic.values.settings).toEqual({
+ sectionId: 'project-product-analytics',
+ settingId: 'internal-user-filtering',
+ })
+ expect(onChange).not.toHaveBeenCalled()
+ })
+
+ it('keeps the Settings nav-bar gear hidden on scenes without a settings_section after the click', async () => {
+ const onChange = jest.fn()
+ render(<TestAccountFilterSwitch checked={false} onChange={onChange} />)
+
+ await userEvent.click(screen.getByRole('button'))
+
+ // Settings is now in enabledTabs (so the panel can render and the fallback
+ // doesn't flip to Max), but it is intentionally still hidden from the nav
+ // bar — that gear icon should only appear when the scene declares a
+ // `settings_section`.
+ expect(sidePanelLogic.values.enabledTabs).toContain(SidePanelTab.Settings)
+ expect(sidePanelLogic.values.visibleTabs).not.toContain(SidePanelTab.Settings)
+ })
+
+ it('does NOT enable Settings when openSidePanel(Settings) is called without explicit args', async () => {
+ // This is the path the SidePanel storybook (`SidePanelSettings` story) uses:
+ // `useActions(sidePanelStateLogic).openSidePanel(SidePanelTab.Settings)`. On
+ // a scene without `settings_section` (e.g. the dashboards URL the stories
+ // pin themselves to) Settings should remain unavailable so the fallback
+ // useEffect in SidePanel.tsx still routes to Max — preserving the existing
+ // storybook snapshot.
+ sidePanelStateLogic.actions.openSidePanel(SidePanelTab.Settings)
+
+ expect(sidePanelLogic.values.enabledTabs).not.toContain(SidePanelTab.Settings)
+ expect(sidePanelSettingsLogic.values.isExplicitSettings).toBe(false)
+ })
+})