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.

feat(data-warehouse): collapse the app navigation in the create view flow (#115604)

Sinan Kucukkoselerf15b7928a91c
diff --git a/frontend/src/layout/panel-layout/panelLayoutLogic.test.ts b/frontend/src/layout/panel-layout/panelLayoutLogic.test.ts
index 1309d33fbce5..6b5f48bde45d 100644
--- a/frontend/src/layout/panel-layout/panelLayoutLogic.test.ts
+++ b/frontend/src/layout/panel-layout/panelLayoutLogic.test.ts
@@ -30,6 +30,27 @@ describe('panelLayoutLogic', () => {
}
)
+ // Regression: a scene that collapses the nav for itself must not write the saved choice. A write
+ // leaves the nav collapsed on every other screen, and so does a toggle made inside that scene.
+ // A late clear from another scene must not expand the nav under the scene that owns the override.
+ it('collapses for a scene without changing the saved choice', () => {
+ panelLayoutLogic.actions.toggleLayoutNavCollapsed(false)
+
+ panelLayoutLogic.actions.setLayoutNavCollapsedOverride('scene-a', true)
+ expect(panelLayoutLogic.values.isLayoutNavCollapsed).toBe(true)
+
+ panelLayoutLogic.actions.toggleLayoutNavCollapsed()
+ expect(panelLayoutLogic.values.isLayoutNavCollapsed).toBe(false)
+ panelLayoutLogic.actions.toggleLayoutNavCollapsed(true)
+ expect(panelLayoutLogic.values.isLayoutNavCollapsed).toBe(true)
+ expect(panelLayoutLogic.values.isLayoutNavCollapsedDesktop).toBe(false)
+
+ panelLayoutLogic.actions.setLayoutNavCollapsedOverride('scene-b', null)
+ expect(panelLayoutLogic.values.isLayoutNavCollapsed).toBe(true)
+ panelLayoutLogic.actions.setLayoutNavCollapsedOverride('scene-a', null)
+ expect(panelLayoutLogic.values.isLayoutNavCollapsed).toBe(false)
+ })
+
it('clears the temporary overlay when the sidebar is permanently expanded', async () => {
panelLayoutLogic.actions.setNavOverlayOpen(true)
await expectLogic(panelLayoutLogic, () =>
diff --git a/frontend/src/layout/panel-layout/panelLayoutLogic.tsx b/frontend/src/layout/panel-layout/panelLayoutLogic.tsx
index e2ee6de68e49..32aba442385f 100644
--- a/frontend/src/layout/panel-layout/panelLayoutLogic.tsx
+++ b/frontend/src/layout/panel-layout/panelLayoutLogic.tsx
@@ -45,6 +45,10 @@ export interface panelLayoutLogicValues {
isLayoutPanelCloseable: boolean
isLayoutPanelVisible: boolean
isNavOverlayOpen: boolean
+ layoutNavCollapsedOverride: {
+ collapsed: boolean
+ owner: string
+ } | null
mainContentRect: DOMRect | null
mainContentRef: PanelLayoutMainContentRef
navExperimentActiveTab: NavExperimentTab
@@ -73,6 +77,16 @@ export interface panelLayoutLogicActions {
setActivePanelIdentifier: (identifier: PanelLayoutNavIdentifier) => {
identifier: PanelLayoutNavIdentifier
}
+ setLayoutNavCollapsedDesktop: (collapsed: boolean) => {
+ collapsed: boolean
+ }
+ setLayoutNavCollapsedOverride: (
+ owner: string,
+ collapsed: boolean | null
+ ) => {
+ collapsed: boolean | null
+ owner: string
+ }
setMainContentRect: (rect: DOMRect) => {
rect: DOMRect
}
@@ -120,7 +134,14 @@ export interface panelLayoutLogicActions {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface panelLayoutLogicMeta {
__keaTypeGenInternalSelectorTypes: {
- isLayoutNavCollapsed: (isLayoutNavCollapsedDesktop: boolean, mobileLayout: boolean) => boolean
+ isLayoutNavCollapsed: (
+ isLayoutNavCollapsedDesktop: boolean,
+ layoutNavCollapsedOverride: {
+ collapsed: boolean
+ owner: string
+ } | null,
+ mobileLayout: boolean
+ ) => boolean
activePanelIdentifierFromUrl: (location: {
hash: string
pathname: string
@@ -157,6 +178,8 @@ export const panelLayoutLogic = kea<panelLayoutLogicType>([
clearActivePanelIdentifier: true,
setMainContentRef: (ref: PanelLayoutMainContentRef) => ({ ref }),
toggleLayoutNavCollapsed: (override?: boolean) => ({ override }),
+ setLayoutNavCollapsedDesktop: (collapsed: boolean) => ({ collapsed }),
+ setLayoutNavCollapsedOverride: (owner: string, collapsed: boolean | null) => ({ owner, collapsed }),
setVisibleSideAction: (sideAction: string) => ({ sideAction }),
setPanelWidth: (width: number) => ({ width }),
setPanelIsResizing: (isResizing: boolean) => ({ isResizing }),
@@ -253,7 +276,17 @@ export const panelLayoutLogic = kea<panelLayoutLogicType>([
false,
{ persist: true },
{
- toggleLayoutNavCollapsed: (state, { override }) => override ?? !state,
+ setLayoutNavCollapsedDesktop: (_, { collapsed }) => collapsed,
+ },
+ ],
+ // A scene sets this to collapse the nav while it shows. It is not persisted, so the saved
+ // choice applies again when the scene clears it. Only the owner can clear it, because the
+ // logic of one scene tab can unmount after the next scene tab set its own override.
+ layoutNavCollapsedOverride: [
+ null as { owner: string; collapsed: boolean } | null,
+ {
+ setLayoutNavCollapsedOverride: (state, { owner, collapsed }) =>
+ collapsed === null ? (state?.owner === owner ? null : state) : { owner, collapsed },
},
],
visibleSideAction: [
@@ -321,6 +354,15 @@ export const panelLayoutLogic = kea<panelLayoutLogicType>([
],
}),
listeners(({ actions, values, cache }) => ({
+ toggleLayoutNavCollapsed: ({ override }) => {
+ // A toggle during a scene override changes the override only, so the saved choice survives the scene.
+ const sceneOverride = values.layoutNavCollapsedOverride
+ if (sceneOverride) {
+ actions.setLayoutNavCollapsedOverride(sceneOverride.owner, override ?? !sceneOverride.collapsed)
+ } else {
+ actions.setLayoutNavCollapsedDesktop(override ?? !values.isLayoutNavCollapsedDesktop)
+ }
+ },
closePanel: () => {
actions.showLayoutPanel(false)
actions.clearActivePanelIdentifier()
@@ -372,9 +414,12 @@ export const panelLayoutLogic = kea<panelLayoutLogicType>([
})),
selectors({
isLayoutNavCollapsed: [
- (s) => [s.isLayoutNavCollapsedDesktop, s.mobileLayout],
- (isLayoutNavCollapsedDesktop: boolean, mobileLayout: boolean): boolean =>
- !mobileLayout && isLayoutNavCollapsedDesktop,
+ (s) => [s.isLayoutNavCollapsedDesktop, s.layoutNavCollapsedOverride, s.mobileLayout],
+ (
+ isLayoutNavCollapsedDesktop: boolean,
+ layoutNavCollapsedOverride: { owner: string; collapsed: boolean } | null,
+ mobileLayout: boolean
+ ): boolean => !mobileLayout && (layoutNavCollapsedOverride?.collapsed ?? isLayoutNavCollapsedDesktop),
],
activePanelIdentifierFromUrl: [
() => [router.selectors.location],
diff --git a/frontend/src/scenes/data-warehouse/editor/editorSceneLogic.test.ts b/frontend/src/scenes/data-warehouse/editor/editorSceneLogic.test.ts
new file mode 100644
index 000000000000..0ad4d01377f3
--- /dev/null
+++ b/frontend/src/scenes/data-warehouse/editor/editorSceneLogic.test.ts
@@ -0,0 +1,46 @@
+import { panelLayoutLogic } from '~/layout/panel-layout/panelLayoutLogic'
+import { useMocks } from '~/mocks/jest'
+import { initKeaTests } from '~/test/init'
+
+import { editorSceneLogic } from './editorSceneLogic'
+import { sqlEditorLogic } from './sqlEditorLogic'
+import { SQLEditorMode } from './sqlEditorModes'
+
+const TAB_ID = 'editor-scene-test'
+
+describe('editorSceneLogic', () => {
+ beforeEach(() => {
+ localStorage.clear()
+ sessionStorage.clear()
+ useMocks({
+ get: {
+ '/api/projects/:team_id/warehouse_saved_queries/': { results: [] },
+ '/api/projects/:team_id/external_data_sources/connections/': [],
+ '/api/user_home_settings/@me/': {},
+ },
+ post: {
+ '/api/environments/:team_id/query/': [200, { tables: {}, joins: [] }],
+ },
+ })
+ initKeaTests()
+ panelLayoutLogic.mount()
+ })
+
+ // Regression: the collapse must end with the flow, or the nav stays collapsed on the next
+ // scene. An embedded editor sits inside another scene and must not collapse that scene's nav.
+ it.each([
+ ['collapses the app nav for the create view flow in the full scene', undefined, true],
+ ['leaves the app nav alone in an embedded editor', SQLEditorMode.Embedded, false],
+ ])('%s', (_name, mode, collapsedInFlow) => {
+ const props = { tabId: TAB_ID, ...(mode ? { mode } : {}) }
+ const logic = editorSceneLogic(props)
+ logic.mount()
+ expect(panelLayoutLogic.values.isLayoutNavCollapsed).toBe(false)
+
+ sqlEditorLogic(props).actions.setEditorSource('view')
+ expect(panelLayoutLogic.values.isLayoutNavCollapsed).toBe(collapsedInFlow)
+
+ logic.unmount()
+ expect(panelLayoutLogic.values.isLayoutNavCollapsed).toBe(false)
+ })
+})
diff --git a/frontend/src/scenes/data-warehouse/editor/editorSceneLogic.tsx b/frontend/src/scenes/data-warehouse/editor/editorSceneLogic.tsx
index ffc05f2ea919..6ffe40385724 100644
--- a/frontend/src/scenes/data-warehouse/editor/editorSceneLogic.tsx
+++ b/frontend/src/scenes/data-warehouse/editor/editorSceneLogic.tsx
@@ -1,6 +1,19 @@
import { deepEqual as equal } from 'fast-equals'
-import { MakeLogicType, actions, connect, kea, key, listeners, path, props, reducers, selectors } from 'kea'
+import {
+ MakeLogicType,
+ actions,
+ beforeUnmount,
+ connect,
+ kea,
+ key,
+ listeners,
+ path,
+ props,
+ reducers,
+ selectors,
+} from 'kea'
import { combineUrl } from 'kea-router'
+import { subscriptions } from 'kea-subscriptions'
import posthog from 'posthog-js'
import { JSONContent } from 'lib/components/RichContentEditor/types'
@@ -13,6 +26,7 @@ import { Scene } from 'scenes/sceneTypes'
import { urls } from 'scenes/urls'
import { SIDE_PANEL_CONTEXT_KEY, SidePanelSceneContext } from '~/layout/navigation-3000/sidepanel/types'
+import { panelLayoutLogic } from '~/layout/panel-layout/panelLayoutLogic'
import { notebooksModel } from '~/models/notebooksModel'
import { DataVisualizationNode, FileSystemIconType, HogQLFilters, NodeKind } from '~/queries/schema/schema-general'
import { Breadcrumb, ProjectTreeRef } from '~/types'
@@ -115,6 +129,7 @@ export interface editorSceneLogicValues {
sourceQuery: DataVisualizationNode // sqlEditorLogic
viewLoading: boolean // sqlEditorLogic
breadcrumbs: Breadcrumb[]
+ isCreateViewFlow: boolean
isHistoryModalOpen: boolean
projectTreeRef: ProjectTreeRef | null
saveAsMenuItems: {
@@ -177,6 +192,13 @@ export interface editorSceneLogicActions {
shortId: string | undefined
title: string | undefined
} // notebooksModel
+ setLayoutNavCollapsedOverride: (
+ owner: string,
+ collapsed: boolean | null
+ ) => {
+ collapsed: boolean | null
+ owner: string
+ } // panelLayoutLogic
closeHistoryModal: () => {
value: true
}
@@ -199,6 +221,11 @@ export interface editorSceneLogicMeta {
editingInsight: InsightModel<import('~/queries/schema/schema-general').Node<Record<string, any>>> | null
) => ProjectTreeRef | null
breadcrumbs: (activeTab: QueryTab | null, editorUrl: string) => Breadcrumb[]
+ isCreateViewFlow: (
+ editorSource: SqlEditorSource,
+ editingView: DataWarehouseSavedQuery | undefined,
+ editingInsight: InsightModel<import('~/queries/schema/schema-general').Node<Record<string, any>>> | null
+ ) => boolean
titleSectionProps: (
editingInsight: InsightModel<import('~/queries/schema/schema-general').Node<Record<string, any>>> | null,
insightLoading: boolean,
@@ -256,6 +283,10 @@ export type editorSceneLogicType = MakeLogicType<
editorSceneLogicMeta
>
+// Only the full-scene editor changes the app navigation. An embedded editor sits inside another scene.
+const ownsLayoutNav = (props: EditorSceneLogicProps): boolean => !props.mode || props.mode === SQLEditorMode.FullScene
+const layoutNavOverrideOwner = (props: EditorSceneLogicProps): string => `sql-editor-${props.tabId}`
+
export const editorSceneLogic = kea<editorSceneLogicType>([
path(['data-warehouse', 'editor', 'editorSceneLogic']),
props({} as EditorSceneLogicProps),
@@ -280,7 +311,7 @@ export const editorSceneLogic = kea<editorSceneLogicType>([
notebooksModel,
['notebooksLoading'],
],
- actions: [notebooksModel, ['createNotebook']],
+ actions: [notebooksModel, ['createNotebook'], panelLayoutLogic, ['setLayoutNavCollapsedOverride']],
})),
actions({
convertToNotebook: true,
@@ -352,6 +383,15 @@ export const editorSceneLogic = kea<editorSceneLogicType>([
return [first]
},
],
+ // Matches the state that titleSectionProps names "New view".
+ isCreateViewFlow: [
+ (s) => [s.editorSource, s.editingView, s.editingInsight],
+ (
+ editorSource: import('./sqlEditorLogic').SqlEditorSource,
+ editingView: import('~/types').DataWarehouseSavedQuery | undefined,
+ editingInsight: null | import('~/types').InsightModel
+ ): boolean => editorSource === 'view' && !editingView && !editingInsight,
+ ],
titleSectionProps: [
(s) => [
s.editingInsight,
@@ -633,4 +673,17 @@ export const editorSceneLogic = kea<editorSceneLogicType>([
}),
],
}),
+ subscriptions(({ actions, props }) => ({
+ // A subscription, because several sqlEditorLogic actions move the editor in and out of the flow.
+ isCreateViewFlow: (isCreateViewFlow: boolean) => {
+ if (ownsLayoutNav(props)) {
+ actions.setLayoutNavCollapsedOverride(layoutNavOverrideOwner(props), isCreateViewFlow ? true : null)
+ }
+ },
+ })),
+ beforeUnmount(({ actions, props }) => {
+ if (ownsLayoutNav(props)) {
+ actions.setLayoutNavCollapsedOverride(layoutNavOverrideOwner(props), null)
+ }
+ }),
])