: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
perf(insights): defer sidebar data fetching until opened (#103072)
Matt Puaee5545b48507
diff --git a/frontend/src/layout/panel-layout/ProjectTree/projectTreeDataLogic.test.ts b/frontend/src/layout/panel-layout/ProjectTree/projectTreeDataLogic.test.tsindex 026d8b4c947d..53651a32ba55 100644--- a/frontend/src/layout/panel-layout/ProjectTree/projectTreeDataLogic.test.ts+++ b/frontend/src/layout/panel-layout/ProjectTree/projectTreeDataLogic.test.ts@@ -1,10 +1,13 @@import { expectLogic } from 'kea-test-utils'import api from 'lib/api'+import { sceneFileLogic } from 'lib/components/Scenes/sceneFileLogic'import { lemonToast } from 'lib/lemon-ui/LemonToast'+import { breadcrumbsLogic } from '~/layout/navigation/Breadcrumbs/breadcrumbsLogic'import { initKeaTests } from '~/test/init'+import { panelLayoutLogic } from '../panelLayoutLogic'import { customProductsLogic } from './customProductsLogic'import { MovedItem, projectTreeDataLogic } from './projectTreeDataLogic'import { projectTreeLogic } from './projectTreeLogic'@@ -23,6 +26,8 @@ describe('projectTreeDataLogic', () => {jest.spyOn(api.fileSystemShortcuts, 'list').mockResolvedValue({ count: 0, results: [] })initKeaTests()+ panelLayoutLogic.mount()+ panelLayoutLogic.actions.clearActivePanelIdentifier()logic = projectTreeDataLogic()unmount = logic.mount()await expectLogic(logic).toDispatchActions(['loadFolderSuccess'])@@ -107,6 +112,149 @@ describe('projectTreeDataLogic', () => {projectTree.unmount()})+ it('shares pending item lookups across tree mounts and navigation callbacks', async () => {+ jest.spyOn(breadcrumbsLogic.selectors, 'projectTreeRef').mockReturnValue({ type: 'insight', ref: 'insight1' })+ let resolveItem!: () => void+ jest.mocked(api.fileSystem.list).mockImplementation((params) =>+ params?.ref+ ? new Promise((resolve) => {+ resolveItem = () =>+ resolve({+ count: 1,+ users: [],+ results: [{ id: 'file1', ref: 'insight1', type: 'insight', path: 'Reports/Insight' }],+ })+ })+ : Promise.resolve({ count: 0, results: [], users: [] })+ )+ const projectTree = projectTreeLogic({ key: 'project-tree', root: 'project://', isActiveInPanel: false })+ const pickerTree = projectTreeLogic({ key: 'folder-select', root: 'project://' })+ projectTree.mount()+ pickerTree.mount()+ projectTree.actions.assureVisibility({ type: 'insight', ref: 'insight1' }, false)+ expect(+ jest.mocked(api.fileSystem.list).mock.calls.filter(([params]) => params?.ref === 'insight1')+ ).toHaveLength(1)++ resolveItem()+ await expectLogic(projectTree).toFinishAllListeners()+ expect(logic.values.viableItems).toEqual(expect.arrayContaining([expect.objectContaining({ ref: 'insight1' })]))+ await expectLogic(projectTree, () => {+ projectTree.actions.assureVisibility({ type: 'insight', ref: 'insight1' }, false)+ }).toFinishAllListeners()+ expect(+ jest.mocked(api.fileSystem.list).mock.calls.filter(([params]) => params?.ref === 'insight1')+ ).toHaveLength(1)++ jest.mocked(api.fileSystem.list).mockResolvedValue({ count: 0, results: [], users: [] })+ await expectLogic(logic, () => logic.actions.syncTypeAndRef('insight', 'insight1')).toFinishAllListeners()+ expect(+ jest.mocked(api.fileSystem.list).mock.calls.filter(([params]) => params?.ref === 'insight1')+ ).toHaveLength(2)+ pickerTree.unmount()+ projectTree.unmount()+ })++ it('loads current insight metadata when a file consumer opens and follows navigation', async () => {+ const currentItem = jest+ .spyOn(projectTreeDataLogic.selectors, 'projectTreeRef')+ .mockReturnValue({ type: 'insight', ref: 'insight1' })+ const consumer = sceneFileLogic()+ consumer.mount()+ await expectLogic(consumer).toFinishAllListeners()+ expect(api.fileSystem.list).toHaveBeenCalledWith({ type: 'insight', ref: 'insight1' })+ currentItem.mockReturnValue({ type: 'insight', ref: 'insight2' })+ await expectLogic(consumer, () =>+ panelLayoutLogic.actions.setActivePanelIdentifier('Products')+ ).toFinishAllListeners()+ expect(api.fileSystem.list).toHaveBeenCalledWith({ type: 'insight', ref: 'insight2' })+ consumer.unmount()+ })++ it('defers ancestor folder loading until Files opens and follows the latest insight', async () => {+ const currentItem = jest.spyOn(breadcrumbsLogic.selectors, 'projectTreeRef').mockReturnValue({+ type: 'insight',+ ref: 'insight1',+ })+ jest.mocked(api.fileSystem.list).mockImplementation(async (params) => ({+ count: params?.ref ? 1 : 0,+ users: [],+ results: params?.ref+ ? [+ {+ id: String(params.ref),+ ref: String(params.ref),+ type: 'insight',+ path: params.ref === 'insight1' ? 'Unfiled/Insights/First insight' : 'Reports/Latest insight',+ },+ ]+ : [],+ }))+ const projectTree = projectTreeLogic({ key: 'project-tree' })+ projectTree.mount()+ await expectLogic(projectTree).toFinishAllListeners()+ expect(api.fileSystem.list).not.toHaveBeenCalledWith(expect.objectContaining({ ref: 'insight1' }))+ expect(api.fileSystem.list).not.toHaveBeenCalledWith(expect.objectContaining({ parent: 'Unfiled/Insights' }))+ expect(logic.values.sortedItems).not.toEqual(+ expect.arrayContaining([expect.objectContaining({ ref: 'insight1' })])+ )++ currentItem.mockReturnValue({ type: 'insight', ref: 'insight2' })+ await expectLogic(projectTree, () => {+ panelLayoutLogic.actions.setActivePanelIdentifier('Products')+ }).toFinishAllListeners()+ expect(api.fileSystem.list).not.toHaveBeenCalledWith(expect.objectContaining({ parent: 'Reports' }))+ expect(api.fileSystem.list).not.toHaveBeenCalledWith(expect.objectContaining({ ref: 'insight2' }))++ await expectLogic(projectTree, () => {+ panelLayoutLogic.actions.setActivePanelIdentifier('Project')+ }).toFinishAllListeners()+ expect(api.fileSystem.list).toHaveBeenCalledWith({ parent: 'Reports', depth: 2, limit: 101, offset: 0 })+ expect(api.fileSystem.list).not.toHaveBeenCalledWith(expect.objectContaining({ parent: 'Unfiled/Insights' }))+ projectTree.unmount()+ })++ it.each(['already-open', 'folder-picker', 'explicit-reveal'] as const)(+ 'loads ancestor folders for %s',+ async (mode) => {+ jest.spyOn(breadcrumbsLogic.selectors, 'projectTreeRef').mockReturnValue({+ type: 'insight',+ ref: 'insight1',+ })+ logic.actions.createSavedItem({+ id: 'file1',+ type: 'insight',+ ref: 'insight1',+ path: 'Unfiled/Insights/Insight',+ })+ if (mode === 'already-open') {+ panelLayoutLogic.mount()+ panelLayoutLogic.actions.setActivePanelIdentifier('Project')+ }+ const projectTree = projectTreeLogic({+ key: mode === 'folder-picker' ? 'folder-select' : 'project-tree',+ root: 'project://',+ })+ projectTree.mount()+ await expectLogic(projectTree).toFinishAllListeners()+ if (mode === 'explicit-reveal') {+ expect(api.fileSystem.list).not.toHaveBeenCalledWith(+ expect.objectContaining({ parent: 'Unfiled/Insights' })+ )+ await expectLogic(projectTree, () => {+ projectTree.actions.assureVisibility({ type: 'insight', ref: 'insight1' })+ }).toFinishAllListeners()+ }+ expect(api.fileSystem.list).toHaveBeenCalledWith({+ parent: 'Unfiled/Insights',+ depth: 3,+ limit: 101,+ offset: 0,+ })+ projectTree.unmount()+ }+ )+it('loads unfiled folders when the count response reports items', async () => {logic.actions.createSavedItem({ id: 'saved-insight', path: 'Unfiled/Insights/Saved insight', type: 'insight' })jest.mocked(api.fileSystem.unfiled).mockResolvedValueOnce({ count: 1 })diff --git a/frontend/src/layout/panel-layout/ProjectTree/projectTreeDataLogic.tsx b/frontend/src/layout/panel-layout/ProjectTree/projectTreeDataLogic.tsxindex b4b7a9f8819d..034f3a2a8a3a 100644--- a/frontend/src/layout/panel-layout/ProjectTree/projectTreeDataLogic.tsx+++ b/frontend/src/layout/panel-layout/ProjectTree/projectTreeDataLogic.tsx@@ -1733,11 +1733,25 @@ export const projectTreeDataLogic = kea<projectTreeDataLogicType>([}},syncTypeAndRef: async ({ type, ref }) => {- const items = await api.fileSystem.list({ ...refTypeParams(type), ref })- if (items.users?.length > 0) {- actions.addLoadedUsers(items.users)+ const requestKey = JSON.stringify([type, ref])+ cache.itemRequests ??= new Map<string, Promise<void>>()+ if (cache.itemRequests.has(requestKey)) {+ await cache.itemRequests.get(requestKey)+ return+ }+ const request = (async () => {+ const items = await api.fileSystem.list({ ...refTypeParams(type), ref })+ if (items.users?.length > 0) {+ actions.addLoadedUsers(items.users)+ }+ actions.addLoadedResults(items as any as SearchResults)+ })()+ cache.itemRequests.set(requestKey, request)+ try {+ await request+ } finally {+ cache.itemRequests.delete(requestKey)}- actions.addLoadedResults(items as any as SearchResults)},deleteItem: async ({ item, projectTreeLogicKey }) => {if (isGroupViewShortcut(item) && values.featureFlags[FEATURE_FLAGS.CRM_ITERATION_ONE]) {diff --git a/frontend/src/layout/panel-layout/ProjectTree/projectTreeLogic.tsx b/frontend/src/layout/panel-layout/ProjectTree/projectTreeLogic.tsxindex 0934d966ef3c..6d92b7003b6b 100644--- a/frontend/src/layout/panel-layout/ProjectTree/projectTreeLogic.tsx+++ b/frontend/src/layout/panel-layout/ProjectTree/projectTreeLogic.tsx@@ -40,7 +40,6 @@ import {calculateMovePath,joinPath,matchesRefType,- refTypeParams,sortFilesAndFolders,splitPath,splitProtocolPath,@@ -86,6 +85,7 @@ export interface projectTreeLogicValues {appBreadcrumbs: Breadcrumb[] // breadcrumbsLogicprojectTreeRef: ProjectTreeRef | null // breadcrumbsLogicsceneBreadcrumbs: Breadcrumb[] // breadcrumbsLogic+ activePanelIdentifier: string // panelLayoutLogicfolderLoadOffset: Record<string, number> // projectTreeDataLogicfolderStates: Record<string, FolderState> // projectTreeDataLogicfolders: Record<string, FileSystemEntry[]> // projectTreeDataLogic@@ -265,7 +265,11 @@ export interface projectTreeLogicActions {editAfter: anyfolder: string}- assureVisibility: (projectTreeRef: ProjectTreeRef) => {+ assureVisibility: (+ projectTreeRef: ProjectTreeRef,+ expandIfHidden?: boolean+ ) => {+ expandIfHidden: booleanprojectTreeRef: ProjectTreeRef}checkSelectedFolders: () => {@@ -512,6 +516,12 @@ export type projectTreeLogicType = MakeLogicType<projectTreeLogicMeta>+const isProjectTreeActive = (+ props: ProjectTreeLogicProps,+ values: Pick<projectTreeLogicValues, 'activePanelIdentifier'>+): boolean =>+ props.key === PROJECT_TREE_KEY ? values.activePanelIdentifier === 'Project' : props.isActiveInPanel !== false+const shouldLoadUnfiledItems = (props: ProjectTreeLogicProps,values: Pick<projectTreeLogicValues, 'unfiledItems' | 'unfiledItemsLoading'>@@ -527,6 +537,8 @@ export const projectTreeLogic = kea<projectTreeLogicType>([key((props) => props.key),connect(() => ({values: [+ panelLayoutLogic,+ ['activePanelIdentifier'],breadcrumbsLogic,['projectTreeRef', 'appBreadcrumbs', 'sceneBreadcrumbs'],projectTreeDataLogic,@@ -593,7 +605,10 @@ export const projectTreeLogic = kea<projectTreeLogicType>([clearSearch: true,loadSearchResults: (searchTerm: string, offset = 0) => ({ searchTerm, offset }),loadRecentResults: (type: 'start' | 'end') => ({ type }),- assureVisibility: (projectTreeRef: ProjectTreeRef) => ({ projectTreeRef }),+ assureVisibility: (projectTreeRef: ProjectTreeRef, expandIfHidden: boolean = true) => ({+ projectTreeRef,+ expandIfHidden,+ }),onItemChecked: (id: string, checked: boolean, shift: boolean) => ({ id, checked, shift }),setLastCheckedItem: (id: string, checked: boolean, shift: boolean) => ({ id, checked, shift }),setCheckedItems: (checkedItems: Record<string, boolean>) => ({ checkedItems }),@@ -1223,7 +1238,10 @@ export const projectTreeLogic = kea<projectTreeLogicType>([],}),listeners(({ actions, values, key, props }) => ({- setActivePanelIdentifier: () => {+ setActivePanelIdentifier: ({ identifier }) => {+ if (props.key === PROJECT_TREE_KEY && identifier === 'Project' && values.projectTreeRef) {+ actions.assureVisibility(values.projectTreeRef, false)+ }if (values.searchTerm !== '') {actions.clearSearch()}@@ -1582,9 +1600,15 @@ export const projectTreeLogic = kea<projectTreeLogicType>([actions.loadRecentResults('start')}},- assureVisibility: async ({ projectTreeRef }, breakpoint) => {+ assureVisibility: async ({ projectTreeRef, expandIfHidden }, breakpoint) => {if (projectTreeRef) {+ if (projectTreeRef.type === 'insight' && !expandIfHidden && !isProjectTreeActive(props, values)) {+ return+ }if (projectTreeRef.type === 'folder' && projectTreeRef.ref) {+ if (!expandIfHidden && !isProjectTreeActive(props, values)) {+ return+ }actions.expandProjectFolder(projectTreeRef.ref)const item = values.viableItems.find((item) => item.type === 'folder' && item.path === projectTreeRef.ref@@ -1602,22 +1626,14 @@ export const projectTreeLogic = kea<projectTreeLogicType>([if (treeItem) {path = treeItem.path} else if (projectTreeRef.ref !== null) {- const resp = await api.fileSystem.list({- ref: projectTreeRef.ref,- ...refTypeParams(projectTreeRef.type),- })+ await projectTreeDataLogic.asyncActions.syncTypeAndRef(projectTreeRef.type, projectTreeRef.ref)breakpoint() // bail if we opened some other item in the meanwhile- if (resp.users?.length > 0) {- actions.addLoadedUsers(resp.users)- }- if (resp.results && resp.results.length > 0) {- const result = resp.results[0]- path = result.path- actions.createSavedItem(result)- }+ path = values.viableItems.find(+ (item) => matchesRefType(item.type, projectTreeRef.type) && item.ref === projectTreeRef.ref+ )?.path}- if (path) {+ if (path && (expandIfHidden || isProjectTreeActive(props, values))) {actions.expandProjectFolder(path)if (treeItem) {actions.scrollToView(treeItem)@@ -1640,10 +1656,10 @@ export const projectTreeLogic = kea<projectTreeLogicType>([if (newRef) {if (newRef.ref === null) {if (typeof values.lastNewFolder === 'string') {- actions.assureVisibility({ type: 'folder', ref: values.lastNewFolder })+ actions.assureVisibility({ type: 'folder', ref: values.lastNewFolder }, false)}} else {- actions.assureVisibility(newRef)+ actions.assureVisibility(newRef, false)}}},@@ -1661,7 +1677,7 @@ export const projectTreeLogic = kea<projectTreeLogicType>([actions.loadUnfiledItems()}if (values.projectTreeRef && isProjectRoot) {- actions.assureVisibility(values.projectTreeRef)+ actions.assureVisibility(values.projectTreeRef, false)}if (typeof props.defaultOnlyFolders !== 'undefined') {actions.setOnlyFolders(props.defaultOnlyFolders)@@ -1683,6 +1699,14 @@ export const projectTreeLogic = kea<projectTreeLogicType>([}const projectPanelStateChanged =props.root !== oldProps.root || props.isActiveInPanel !== oldProps.isActiveInPanel+ if (+ projectPanelStateChanged &&+ isProjectTreeActive(props, values) &&+ values.projectTreeRef &&+ (props.root === undefined || props.root.startsWith('project://'))+ ) {+ actions.assureVisibility(values.projectTreeRef, false)+ }if (projectPanelStateChanged && shouldLoadUnfiledItems(props, values)) {actions.loadUnfiledItems()}diff --git a/frontend/src/layout/scenes/sceneLayoutLogic.tsx b/frontend/src/layout/scenes/sceneLayoutLogic.tsxindex 1e9b3f4389a8..c48964d4d618 100644--- a/frontend/src/layout/scenes/sceneLayoutLogic.tsx+++ b/frontend/src/layout/scenes/sceneLayoutLogic.tsx@@ -1,9 +1,12 @@-import { MakeLogicType, actions, connect, kea, listeners, path, reducers } from 'kea'+import { MakeLogicType, actions, connect, kea, listeners, path, reducers, selectors } from 'kea'import React from 'react'import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { SceneConfig } from 'scenes/sceneTypes'+import { sidePanelStateLogic } from '~/layout/navigation-3000/sidepanel/sidePanelStateLogic'+import { SidePanelTab } from '~/types'+import type { FeatureFlagsSet } from '../../lib/logic/featureFlagLogic'import { panelLayoutLogic } from '../panel-layout/panelLayoutLogic'@@ -13,9 +16,12 @@ export type SceneLayoutContainerRef = React.RefObject<HTMLElement> | nullexport interface sceneLayoutLogicValues {featureFlags: FeatureFlagsSet // featureFlagLogicmainContentRect: DOMRect | null // panelLayoutLogic+ selectedTab: SidePanelTab | null // sidePanelStateLogic+ sidePanelOpen: boolean // sidePanelStateLogicsceneLayoutConfig: SceneConfig | nullscenePanelElement: HTMLElement | nullscenePanelIsPresent: boolean+ scenePanelOpen: booleanscenePanelOpenManual: booleansceneTakeoverActive: booleansceneTakeoverElement: HTMLElement | null@@ -47,12 +53,35 @@ export interface sceneLayoutLogicActions {}}-export type sceneLayoutLogicType = MakeLogicType<sceneLayoutLogicValues, sceneLayoutLogicActions>+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface sceneLayoutLogicMeta {+ __keaTypeGenInternalSelectorTypes: {+ scenePanelOpen: (+ scenePanelOpenManual: boolean,+ sidePanelOpen: boolean,+ selectedTab: SidePanelTab | null+ ) => boolean+ }+}++export type sceneLayoutLogicType = MakeLogicType<+ sceneLayoutLogicValues,+ sceneLayoutLogicActions,+ Record<string, any>,+ sceneLayoutLogicMeta+>export const sceneLayoutLogic = kea<sceneLayoutLogicType>([path(['layout', 'scene-layout', 'sceneLayoutLogic']),connect(() => ({- values: [featureFlagLogic, ['featureFlags'], panelLayoutLogic, ['mainContentRect']],+ values: [+ featureFlagLogic,+ ['featureFlags'],+ panelLayoutLogic,+ ['mainContentRect'],+ sidePanelStateLogic,+ ['sidePanelOpen', 'selectedTab'],+ ],})),actions({registerScenePanelElement: (element: HTMLElement | null) => ({ element }),@@ -113,6 +142,13 @@ export const sceneLayoutLogic = kea<sceneLayoutLogicType>([},],}),+ selectors({+ scenePanelOpen: [+ (s) => [s.scenePanelOpenManual, s.sidePanelOpen, s.selectedTab],+ (scenePanelOpenManual: boolean, sidePanelOpen: boolean, selectedTab: SidePanelTab | null): boolean =>+ scenePanelOpenManual || (sidePanelOpen && selectedTab === SidePanelTab.Info),+ ],+ }),listeners(({ values }) => ({registerScenePanelElement: () => {refreshSceneElementSelectorCaches(values)diff --git a/frontend/src/lib/components/Metalytics/metalyticsLogic.test.ts b/frontend/src/lib/components/Metalytics/metalyticsLogic.test.tsnew file mode 100644index 000000000000..308793277a37--- /dev/null+++ b/frontend/src/lib/components/Metalytics/metalyticsLogic.test.ts@@ -0,0 +1,153 @@+import api from 'lib/api'++import { sidePanelContextLogic } from '~/layout/navigation-3000/sidepanel/sidePanelContextLogic'+import { sidePanelStateLogic } from '~/layout/navigation-3000/sidepanel/sidePanelStateLogic'+import { sceneLayoutLogic } from '~/layout/scenes/sceneLayoutLogic'+import { initKeaTests } from '~/test/init'+import { expectLogic } from '~/test/keaTestUtils'+import { ActivityScope, SidePanelTab } from '~/types'++import { metalyticsLogic } from './metalyticsLogic'++describe('metalyticsLogic', () => {+ beforeEach(() => {+ initKeaTests()+ sidePanelContextLogic.mount()+ jest.spyOn(sidePanelContextLogic.selectors, 'sceneSidePanelContext').mockReturnValue({+ activity_scope: ActivityScope.INSIGHT,+ activity_item_id: 'insight1',+ })+ jest.spyOn(api, 'queryHogQL').mockResolvedValue({ results: [] })+ jest.spyOn(api, 'create').mockResolvedValue({})+ sceneLayoutLogic.mount()+ })++ afterEach(() => jest.restoreAllMocks())++ it.each(['inline', 'actions', 'activity'] as const)(+ 'defers statistics until the %s sidebar opens, including subsequent insight navigation',+ async (panel) => {+ const logic = metalyticsLogic()+ logic.mount()+ await expectLogic(logic).toFinishAllListeners()+ expect(api.queryHogQL).not.toHaveBeenCalled()+ expect(api.create).toHaveBeenCalledWith(expect.stringContaining('/metalytics/'), {+ metric_name: 'viewed',+ instance_id: 'Insight:insight1',+ })++ await expectLogic(logic, () => {+ if (panel === 'inline') {+ sceneLayoutLogic.actions.setScenePanelOpen(true)+ } else {+ sidePanelStateLogic.actions.openSidePanel(+ panel === 'actions' ? SidePanelTab.Info : SidePanelTab.Activity+ )+ }+ }).toFinishAllListeners()+ expect(api.queryHogQL).toHaveBeenCalledTimes(2)++ await expectLogic(logic, () => {+ jest.mocked(sidePanelContextLogic.selectors.sceneSidePanelContext).mockReturnValue({+ activity_scope: ActivityScope.INSIGHT,+ activity_item_id: 'insight2',+ })+ sceneLayoutLogic.actions.setScenePanelIsPresent(true)+ }).toFinishAllListeners()+ expect(api.queryHogQL).toHaveBeenCalledTimes(4)+ expect(+ jest+ .mocked(api.queryHogQL)+ .mock.calls.slice(2)+ .every(([query]) => query.includes('Insight:insight2'))+ ).toBe(true)++ sceneLayoutLogic.actions.setScenePanelOpen(false)+ sidePanelStateLogic.actions.closeSidePanel()+ await expectLogic(logic, () => {+ jest.mocked(sidePanelContextLogic.selectors.sceneSidePanelContext).mockReturnValue({+ activity_scope: ActivityScope.INSIGHT,+ activity_item_id: 'insight3',+ })+ sceneLayoutLogic.actions.setScenePanelIsPresent(true)+ }).toFinishAllListeners()+ expect(api.queryHogQL).toHaveBeenCalledTimes(4)+ }+ )++ it('loads statistics when the insight mounts with the sidebar already open', async () => {+ sceneLayoutLogic.actions.setScenePanelOpen(true)+ const logic = metalyticsLogic()+ logic.mount()+ await expectLogic(logic).toFinishAllListeners()+ expect(api.queryHogQL).toHaveBeenCalledTimes(2)+ })++ it('clears loaded statistics when the panel closes before navigating', async () => {+ jest.mocked(api.queryHogQL)+ .mockResolvedValueOnce({ results: [[10, 2]] })+ .mockResolvedValueOnce({ results: [['previous-user']] })+ sceneLayoutLogic.actions.setScenePanelOpen(true)+ const logic = metalyticsLogic()+ logic.mount()+ await expectLogic(logic).toFinishAllListeners()+ expect(logic.values.viewCount).toEqual({ views: 10, users: 2 })+ expect(logic.values.recentUsers).toEqual(['previous-user'])++ await expectLogic(logic, () => {+ sceneLayoutLogic.actions.setScenePanelOpen(false)+ }).toFinishAllListeners()+ await expectLogic(logic, () => {+ jest.mocked(sidePanelContextLogic.selectors.sceneSidePanelContext).mockReturnValue({+ activity_scope: ActivityScope.INSIGHT,+ activity_item_id: 'insight2',+ })+ sceneLayoutLogic.actions.setScenePanelIsPresent(true)+ })+ .toFinishAllListeners()+ .toMatchValues({ viewCount: null, recentUsers: [], viewCountLoading: false, recentUsersLoading: false })+ expect(api.queryHogQL).toHaveBeenCalledTimes(2)+ })++ it.each([true, false])('discards older responses after navigation with panel open=%s', async (panelOpen) => {+ let resolveOldCount!: () => void+ let resolveOldUsers!: () => void+ jest.mocked(api.queryHogQL)+ .mockImplementationOnce(+ () => new Promise((resolve) => (resolveOldCount = () => resolve({ results: [[100, 10]] })))+ )+ .mockImplementationOnce(+ () => new Promise((resolve) => (resolveOldUsers = () => resolve({ results: [['previous-user']] })))+ )+ .mockResolvedValueOnce({ results: [[20, 3]] })+ .mockResolvedValueOnce({ results: [['current-user']] })+ sceneLayoutLogic.actions.setScenePanelOpen(true)+ const logic = metalyticsLogic()+ logic.mount()+ expect(api.queryHogQL).toHaveBeenCalledTimes(2)++ await expectLogic(logic, () => {+ if (!panelOpen) {+ sceneLayoutLogic.actions.setScenePanelOpen(false)+ }+ jest.mocked(sidePanelContextLogic.selectors.sceneSidePanelContext).mockReturnValue({+ activity_scope: ActivityScope.INSIGHT,+ activity_item_id: 'insight2',+ })+ sceneLayoutLogic.actions.setScenePanelIsPresent(true)+ }).toDispatchActions(['loadViewCountSuccess', 'loadUsersLast30daysSuccess'])++ await expectLogic(logic, () => {+ resolveOldCount()+ resolveOldUsers()+ })+ .toFinishAllListeners()+ .toMatchValues({+ viewCount: panelOpen ? { views: 20, users: 3 } : null,+ recentUsers: panelOpen ? ['current-user'] : [],+ viewCountLoading: false,+ recentUsersLoading: false,+ })+ expect(api.queryHogQL).toHaveBeenCalledTimes(panelOpen ? 4 : 2)+ })+})diff --git a/frontend/src/lib/components/Metalytics/metalyticsLogic.ts b/frontend/src/lib/components/Metalytics/metalyticsLogic.tsindex 694329fce313..49a1b7a87328 100644--- a/frontend/src/lib/components/Metalytics/metalyticsLogic.ts+++ b/frontend/src/lib/components/Metalytics/metalyticsLogic.ts@@ -8,21 +8,28 @@ import { sceneLogic } from 'scenes/sceneLogic'import { teamLogic } from 'scenes/teamLogic'import { sidePanelContextLogic } from '~/layout/navigation-3000/sidepanel/sidePanelContextLogic'+import { sidePanelStateLogic } from '~/layout/navigation-3000/sidepanel/sidePanelStateLogic'import { SidePanelSceneContext } from '~/layout/navigation-3000/sidepanel/types'+import { sceneLayoutLogic } from '~/layout/scenes/sceneLayoutLogic'import { hogql } from '~/queries/utils'+import { ActivityScope, SidePanelTab } from '~/types'import type { OrganizationMemberType } from '../../../types'// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface metalyticsLogicValues {members: OrganizationMemberType[] | null // membersLogic+ scenePanelOpen: boolean // sceneLayoutLogicsceneSidePanelContext: SidePanelSceneContext // sidePanelContextLogic+ selectedTab: SidePanelTab | null // sidePanelStateLogic+ sidePanelOpen: boolean // sidePanelStateLogiccurrentProjectId: number | string // teamLogicinstanceId: string | nullrecentUserMembers: OrganizationMemberType[]recentUsers: string[]recentUsersLoading: booleanscope: string | undefined+ statsInstanceId: string | nullviewCount: {users: numberviews: number@@ -32,7 +39,7 @@ export interface metalyticsLogicValues {// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface metalyticsLogicActions {- loadUsersLast30days: () => any+ loadUsersLast30days: (_: any) => anyloadUsersLast30daysFailure: (error: string,errorObject?: any@@ -47,7 +54,7 @@ export interface metalyticsLogicActions {recentUsers: string[]payload?: any}- loadViewCount: () => any+ loadViewCount: (_: any) => anyloadViewCountFailure: (error: string,errorObject?: any@@ -59,13 +66,13 @@ export interface metalyticsLogicActions {viewCount: {users: numberviews: number- },+ } | null,payload?: any) => {viewCount: {users: numberviews: number- }+ } | nullpayload?: any}}@@ -75,6 +82,13 @@ export interface metalyticsLogicMeta {__keaTypeGenInternalSelectorTypes: {instanceId: (sceneSidePanelContext: SidePanelSceneContext) => string | nullscope: (sceneSidePanelContext: SidePanelSceneContext) => string | undefined+ statsInstanceId: (+ instanceId: string | null,+ scope: string | undefined,+ scenePanelOpen: boolean,+ sidePanelOpen: boolean,+ selectedTab: SidePanelTab | null+ ) => string | nullrecentUserMembers: (recentUsers: string[], members: OrganizationMemberType[] | null) => OrganizationMemberType[]}}@@ -96,6 +110,10 @@ export const metalyticsLogic = kea<metalyticsLogicType>([['members'],teamLogic,['currentProjectId'],+ sceneLayoutLogic,+ ['scenePanelOpen'],+ sidePanelStateLogic,+ ['sidePanelOpen', 'selectedTab'],],})),@@ -103,7 +121,10 @@ export const metalyticsLogic = kea<metalyticsLogicType>([viewCount: [null as { views: number; users: number } | null,{- loadViewCount: async () => {+ loadViewCount: async (_, breakpoint) => {+ if (!values.statsInstanceId) {+ return null+ }const query = hogql`SELECT SUM(count) AS count, COUNT(DISTINCT app_source_id) AS unique_usersFROM app_metrics@@ -116,6 +137,7 @@ export const metalyticsLogic = kea<metalyticsLogicType>([{ scene: currentScene, productKey: 'platform_and_support' },{ refresh: 'async' })+ breakpoint()const result = response.results as number[][] | undefinedreturn {views: result?.[0]?.[0] ?? 0,@@ -127,7 +149,10 @@ export const metalyticsLogic = kea<metalyticsLogicType>([recentUsers: [[] as string[],{- loadUsersLast30days: async () => {+ loadUsersLast30days: async (_, breakpoint) => {+ if (!values.statsInstanceId) {+ return []+ }const query = hogql`SELECT DISTINCT app_source_idFROM app_metrics@@ -142,6 +167,7 @@ export const metalyticsLogic = kea<metalyticsLogicType>([{ scene: currentScene, productKey: 'platform_and_support' },{ refresh: 'async' })+ breakpoint()return (response.results?.map((result) => result[0]) ?? []) as string[]},},@@ -161,6 +187,21 @@ export const metalyticsLogic = kea<metalyticsLogicType>([(sidePanelContext: SidePanelSceneContext) => sidePanelContext?.activity_scope,],+ statsInstanceId: [+ (s) => [s.instanceId, s.scope, s.scenePanelOpen, s.sidePanelOpen, s.selectedTab],+ (+ instanceId: string | null,+ scope: string | undefined,+ scenePanelOpen: boolean,+ sidePanelOpen: boolean,+ selectedTab: SidePanelTab | null+ ): string | null =>+ scope !== ActivityScope.INSIGHT ||+ scenePanelOpen ||+ (sidePanelOpen && selectedTab === SidePanelTab.Activity)+ ? instanceId+ : null,+ ],recentUserMembers: [(s) => [s.recentUsers, s.members],(recentUsers: string[], members: import('../../../types').OrganizationMemberType[] | null) => {@@ -175,11 +216,12 @@ export const metalyticsLogic = kea<metalyticsLogicType>([}),subscriptions(({ actions, values }) => ({+ statsInstanceId: () => {+ actions.loadViewCount(undefined)+ actions.loadUsersLast30days(undefined)+ },instanceId: async (instanceId) => {if (instanceId) {- actions.loadViewCount()- actions.loadUsersLast30days()-void api.create(`/api/projects/${values.currentProjectId}/metalytics/`, {metric_name: 'viewed',instance_id: instanceId,diff --git a/frontend/src/lib/components/Scenes/SceneFile.tsx b/frontend/src/lib/components/Scenes/SceneFile.tsxindex add192d9260a..182d8a54f3b9 100644--- a/frontend/src/lib/components/Scenes/SceneFile.tsx+++ b/frontend/src/lib/components/Scenes/SceneFile.tsx@@ -1,4 +1,4 @@-import { useActions, useValues } from 'kea'+import { useActions, useMountedLogic, useValues } from 'kea'import { IconFolderMove, IconFolderOpen, IconStar, IconStarFilled } from '@posthog/icons'@@ -20,8 +20,10 @@ import { joinPath, splitPath } from '~/layout/panel-layout/ProjectTree/utils'import { ScenePanelLabel } from '~/layout/scenes/SceneLayout'import { moveToLogic } from '../FileSystem/MoveTo/moveToLogic'+import { sceneFileLogic } from './sceneFileLogic'export function SceneFile({ dataAttrKey }: { dataAttrKey: string }): JSX.Element | null {+ useMountedLogic(sceneFileLogic)const { assureVisibility } = useActions(projectTreeLogic({ key: PROJECT_TREE_KEY }))const { showLayoutPanel, setActivePanelIdentifier } = useActions(panelLayoutLogic)const { addShortcutItem, deleteShortcut } = useActions(projectTreeDataLogic)diff --git a/frontend/src/lib/components/Scenes/SceneMenuBarFileItems.tsx b/frontend/src/lib/components/Scenes/SceneMenuBarFileItems.tsxindex 784f3d0e2fea..9369f2c9f8f5 100644--- a/frontend/src/lib/components/Scenes/SceneMenuBarFileItems.tsx+++ b/frontend/src/lib/components/Scenes/SceneMenuBarFileItems.tsx@@ -1,4 +1,4 @@-import { useActions, useValues } from 'kea'+import { useActions, useMountedLogic, useValues } from 'kea'import { IconFolderMove, IconFolderOpen, IconStar, IconStarFilled } from '@posthog/icons'@@ -10,6 +10,7 @@ import { joinPath, splitPath } from '~/layout/panel-layout/ProjectTree/utils'import { SceneMenuBarItem } from '~/layout/scenes/components/SceneMenuBar'import { moveToLogic } from '../FileSystem/MoveTo/moveToLogic'+import { sceneFileLogic } from './sceneFileLogic'type SceneMenuBarFileItemsProps = {/** Used as a prefix on data-attr for testing */@@ -21,6 +22,7 @@ type SceneMenuBarFileItemsProps = {* a <SceneMenuBarMenu label="File">. Returns null if no project tree entry is registered.*/export function SceneMenuBarFileItems({ dataAttrKey }: SceneMenuBarFileItemsProps): JSX.Element | null {+ useMountedLogic(sceneFileLogic)const { assureVisibility } = useActions(projectTreeLogic({ key: PROJECT_TREE_KEY }))const { showLayoutPanel, setActivePanelIdentifier } = useActions(panelLayoutLogic)const { addShortcutItem, deleteShortcut } = useActions(projectTreeDataLogic)diff --git a/frontend/src/lib/components/Scenes/sceneFileLogic.ts b/frontend/src/lib/components/Scenes/sceneFileLogic.tsnew file mode 100644index 000000000000..5463e42eb5e7--- /dev/null+++ b/frontend/src/lib/components/Scenes/sceneFileLogic.ts@@ -0,0 +1,52 @@+import { MakeLogicType, actions, afterMount, connect, kea, listeners, path } from 'kea'+import { subscriptions } from 'kea-subscriptions'++import { projectTreeDataLogic } from '~/layout/panel-layout/ProjectTree/projectTreeDataLogic'++import type { FileSystemEntry } from '../../../queries/schema/schema-general'+import type { ProjectTreeRef } from '../../../types'++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface sceneFileLogicValues {+ projectTreeRef: ProjectTreeRef | null // projectTreeDataLogic+ projectTreeRefEntry: FileSystemEntry | null // projectTreeDataLogic+}++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface sceneFileLogicActions {+ syncTypeAndRef: (+ type: string,+ ref: string+ ) => {+ ref: string+ type: string+ } // projectTreeDataLogic+ loadCurrentItem: () => {+ value: true+ }+}++export type sceneFileLogicType = MakeLogicType<sceneFileLogicValues, sceneFileLogicActions>++export const sceneFileLogic = kea<sceneFileLogicType>([+ path(['lib', 'components', 'Scenes', 'sceneFileLogic']),+ connect({+ values: [projectTreeDataLogic, ['projectTreeRef', 'projectTreeRefEntry']],+ actions: [projectTreeDataLogic, ['syncTypeAndRef']],+ }),+ actions({+ loadCurrentItem: true,+ }),+ listeners(({ actions, values }) => ({+ loadCurrentItem: () => {+ const ref = values.projectTreeRef+ if (ref?.ref && !values.projectTreeRefEntry) {+ actions.syncTypeAndRef(ref.type, ref.ref)+ }+ },+ })),+ subscriptions(({ actions }) => ({+ projectTreeRef: () => actions.loadCurrentItem(),+ })),+ afterMount(({ actions }) => actions.loadCurrentItem()),+])diff --git a/frontend/src/scenes/insights/InsightModals.test.tsx b/frontend/src/scenes/insights/InsightModals.test.tsxnew file mode 100644index 000000000000..6459359580bf--- /dev/null+++ b/frontend/src/scenes/insights/InsightModals.test.tsx@@ -0,0 +1,100 @@+import { act, cleanup, render, waitFor } from '@testing-library/react'++import api from 'lib/api'++import { sidePanelStateLogic } from '~/layout/navigation-3000/sidepanel/sidePanelStateLogic'+import { sceneLayoutLogic } from '~/layout/scenes/sceneLayoutLogic'+import { HogQLQuery, NodeKind } from '~/queries/schema/schema-general'+import { initKeaTests } from '~/test/init'+import { InsightLogicProps, InsightShortId, SidePanelTab } from '~/types'++import * as metricsApi from 'products/data_catalog/frontend/generated/api'+import { metricsLogic } from 'products/data_catalog/frontend/metricsLogic'+import { endpointLogic } from 'products/endpoints/frontend/endpointLogic'++import { InsightModals } from './InsightModals'++jest.mock('lib/components/AddToDashboard/AddToDashboardModal', () => ({ AddToDashboardModal: () => null }))+jest.mock('lib/components/Sharing/SharingModal', () => ({ SharingModal: () => null }))+jest.mock('lib/components/TakeScreenshot/ScreenShotEditor', () => ({ ScreenShotEditor: () => null }))+jest.mock('lib/components/TerraformExporter/TerraformExportModal', () => ({ TerraformExportModal: () => null }))+jest.mock('scenes/dashboard/NewDashboardModal', () => ({ NewDashboardModal: () => null }))+jest.mock('products/subscriptions/frontend/components/Subscriptions/SubscriptionsModal', () => ({+ SubscriptionsModal: () => null,+}))++const insightLogicProps: InsightLogicProps = {+ dashboardItemId: 'insight1' as InsightShortId,+ cachedInsight: {+ id: 1,+ short_id: 'insight1' as InsightShortId,+ saved: true,+ query: { kind: NodeKind.HogQLQuery, query: 'SELECT 1' } as HogQLQuery,+ },+}++describe('InsightModals sidebar data loading', () => {+ beforeEach(() => {+ initKeaTests()+ jest.spyOn(metricsApi, 'dataCatalogMetricsList').mockResolvedValue({+ results: [],+ count: 0,+ next: null,+ previous: null,+ })+ jest.spyOn(api.endpoint, 'list').mockResolvedValue({ results: [], count: 0, next: null })+ sceneLayoutLogic.mount()+ })++ afterEach(() => {+ cleanup()+ jest.restoreAllMocks()+ })++ it.each(['inline', 'actions'] as const)('loads catalogs only when the %s sidebar opens', async (panel) => {+ render(<InsightModals insightLogicProps={insightLogicProps} />)+ expect(metricsApi.dataCatalogMetricsList).not.toHaveBeenCalled()+ expect(api.endpoint.list).not.toHaveBeenCalled()++ act(() => {+ if (panel === 'inline') {+ sceneLayoutLogic.actions.setScenePanelOpen(true)+ } else {+ sidePanelStateLogic.actions.openSidePanel(SidePanelTab.Info)+ }+ })+ await waitFor(() => {+ expect(metricsApi.dataCatalogMetricsList).toHaveBeenCalledTimes(1)+ expect(api.endpoint.list).toHaveBeenCalledTimes(1)+ })+ })++ it('loads catalogs when navigating with the sidebar already open', async () => {+ sceneLayoutLogic.actions.setScenePanelOpen(true)+ render(<InsightModals insightLogicProps={insightLogicProps} />)+ await waitFor(() => {+ expect(metricsApi.dataCatalogMetricsList).toHaveBeenCalledTimes(1)+ expect(api.endpoint.list).toHaveBeenCalledTimes(1)+ })+ })++ it.each(['metric', 'endpoint'] as const)(+ 'loads the %s catalog when its modal opens without the sidebar',+ async (modal) => {+ render(<InsightModals insightLogicProps={insightLogicProps} />)+ act(() => {+ if (modal === 'metric') {+ metricsLogic.actions.openMetricFromInsightModal()+ } else {+ endpointLogic.actions.openCreateFromInsightModal()+ }+ })+ await waitFor(() =>+ expect(+ modal === 'metric' ? metricsApi.dataCatalogMetricsList : api.endpoint.list+ ).toHaveBeenCalledTimes(1)+ )+ expect(modal === 'metric' ? api.endpoint.list : metricsApi.dataCatalogMetricsList).not.toHaveBeenCalled()+ }+ )+})diff --git a/frontend/src/scenes/insights/InsightModals.tsx b/frontend/src/scenes/insights/InsightModals.tsxindex dc5da9e36301..8a857cfc2c61 100644--- a/frontend/src/scenes/insights/InsightModals.tsx+++ b/frontend/src/scenes/insights/InsightModals.tsx@@ -13,6 +13,7 @@ import { insightLogic } from 'scenes/insights/insightLogic'import { insightSceneLogic } from 'scenes/insights/insightSceneLogic'import { urls } from 'scenes/urls'+import { sceneLayoutLogic } from '~/layout/scenes/sceneLayoutLogic'import { EndpointQueryNode, HogQLQuery } from '~/queries/schema/schema-general'import { InsightLogicProps, InsightShortId, ItemMode } from '~/types'@@ -20,7 +21,9 @@ import { areAlertsSupportedForInsight } from 'products/alerts/frontend/logic/insimport { EditAlertModal } from 'products/alerts/frontend/views/EditAlertModal'import { ManageAlertsModal } from 'products/alerts/frontend/views/ManageAlertsModal'import { MetricFromInsightModal } from 'products/data_catalog/frontend/components/MetricFromInsightModal'+import { metricsLogic } from 'products/data_catalog/frontend/metricsLogic'import { EndpointFromInsightModal } from 'products/endpoints/frontend/EndpointFromInsightModal'+import { endpointLogic } from 'products/endpoints/frontend/endpointLogic'import { SubscriptionsModal } from 'products/subscriptions/frontend/components/Subscriptions/SubscriptionsModal'import { insightModalsLogic } from './insightModalsLogic'@@ -170,10 +173,20 @@ function InsightTerraformModalWrapper({ insightLogicProps }: { insightLogicProps)}-function InsightEndpointModalWrapper({ insightLogicProps }: { insightLogicProps: InsightLogicProps }): JSX.Element {+function InsightEndpointModalWrapper({+ insightLogicProps,+}: {+ insightLogicProps: InsightLogicProps+}): JSX.Element | null {const theInsightLogic = insightLogic(insightLogicProps)const { insightProps, insight } = useValues(theInsightLogic)const { insightQuery } = useValues(insightDataLogic(insightProps))+ const { scenePanelOpen } = useValues(sceneLayoutLogic)+ const { createFromInsightModalOpen } = useValues(endpointLogic)++ if (!scenePanelOpen && !createFromInsightModalOpen) {+ return null+ }return (<EndpointFromInsightModal@@ -189,6 +202,12 @@ function InsightMetricModalWrapper({insightLogicProps: InsightLogicProps}): JSX.Element | null {const { insight } = useValues(insightLogic(insightLogicProps))+ const { scenePanelOpen } = useValues(sceneLayoutLogic)+ const { metricFromInsightModalOpen } = useValues(metricsLogic)++ if (!scenePanelOpen && !metricFromInsightModalOpen) {+ return null+ }return (<MetricFromInsightModaldiff --git a/frontend/src/scenes/insights/SidePanel/InsightPanelActions.tsx b/frontend/src/scenes/insights/SidePanel/InsightPanelActions.tsxindex 51b829c6cade..a0ec78d18d0c 100644--- a/frontend/src/scenes/insights/SidePanel/InsightPanelActions.tsx+++ b/frontend/src/scenes/insights/SidePanel/InsightPanelActions.tsx@@ -25,6 +25,7 @@ import { interProjectCopyLogic } from 'scenes/resource-transfer/interProjectCopyimport { urls } from 'scenes/urls'import { ScenePanelActionsSection } from '~/layout/scenes/SceneLayout'+import { sceneLayoutLogic } from '~/layout/scenes/sceneLayoutLogic'import {isDataTableNode,isDataVisualizationNode,@@ -50,6 +51,7 @@ import { openSaveAsCohortDialog } from './insightSidePanelDialogs'const RESOURCE_TYPE = 'insight'export function InsightPanelActions({ insightLogicProps }: { insightLogicProps: InsightLogicProps }): JSX.Element {+ const { scenePanelOpen } = useValues(sceneLayoutLogic)const theInsightLogic = insightLogic(insightLogicProps)const { insightProps, insight, hasDashboardItemId, insightDuplicating } = useValues(theInsightLogic)const { duplicateInsight, setInsightMetadata } = useActions(theInsightLogic)@@ -223,7 +225,9 @@ export function InsightPanelActions({ insightLogicProps }: { insightLogicProps:Create endpoint</ButtonPrimitive>- <CreateMetricFromInsightButton isSavedInsight={isSavedInsight} insightShortId={insight?.short_id} />+ {scenePanelOpen && (+ <CreateMetricFromInsightButton isSavedInsight={isSavedInsight} insightShortId={insight?.short_id} />+ )}{canEditInSqlEditor && (<Linkdiff --git a/frontend/src/scenes/insights/SidePanel/InsightPanelInfo.tsx b/frontend/src/scenes/insights/SidePanel/InsightPanelInfo.tsxindex 4e0d095ffdf9..276d12df814f 100644--- a/frontend/src/scenes/insights/SidePanel/InsightPanelInfo.tsx+++ b/frontend/src/scenes/insights/SidePanel/InsightPanelInfo.tsx@@ -6,12 +6,14 @@ import { SceneActivityIndicator } from 'lib/components/Scenes/SceneUpdateActivitimport { insightLogic } from 'scenes/insights/insightLogic'import { ScenePanelInfoSection } from '~/layout/scenes/SceneLayout'+import { sceneLayoutLogic } from '~/layout/scenes/sceneLayoutLogic'import { tagsModel } from '~/models/tagsModel'import { InsightLogicProps } from '~/types'const RESOURCE_TYPE = 'insight'export function InsightPanelInfo({ insightLogicProps }: { insightLogicProps: InsightLogicProps }): JSX.Element {+ const { scenePanelOpen } = useValues(sceneLayoutLogic)const theInsightLogic = insightLogic(insightLogicProps)const { canEditInsight, insight, isSavingTags } = useValues(theInsightLogic)const { setInsightMetadata } = useActions(theInsightLogic)@@ -27,7 +29,7 @@ export function InsightPanelInfo({ insightLogicProps }: { insightLogicProps: InscanEdit={canEditInsight}loading={isSavingTags}/>- <SceneFile dataAttrKey={RESOURCE_TYPE} />+ {scenePanelOpen && <SceneFile dataAttrKey={RESOURCE_TYPE} />}<SceneActivityIndicatorat={insight.last_modified_at}by={insight.last_modified_by}diff --git a/products/data_catalog/frontend/metricsLogic.test.ts b/products/data_catalog/frontend/metricsLogic.test.tsindex 194ba5e1d89d..ca88a275400c 100644--- a/products/data_catalog/frontend/metricsLogic.test.ts+++ b/products/data_catalog/frontend/metricsLogic.test.ts@@ -77,6 +77,8 @@ describe('metricsLogic', () => {initKeaTests()logic = metricsLogic()logic.mount()+ expect(dataCatalogMetricsList).not.toHaveBeenCalled()+ void logic.values.allMetricsawait expectLogic(logic).toDispatchActions(['loadMetricsSuccess'])})diff --git a/products/data_catalog/frontend/metricsLogic.tsx b/products/data_catalog/frontend/metricsLogic.tsxindex d9c278aa7c05..115dd8537976 100644--- a/products/data_catalog/frontend/metricsLogic.tsx+++ b/products/data_catalog/frontend/metricsLogic.tsx@@ -1,5 +1,5 @@-import { MakeLogicType, actions, afterMount, kea, listeners, path, reducers, selectors } from 'kea'-import { loaders } from 'kea-loaders'+import { MakeLogicType, actions, kea, listeners, path, reducers, selectors } from 'kea'+import { lazyLoaders, loaders } from 'kea-loaders'import { router } from 'kea-router'import api, { ApiConfig, ApiError } from 'lib/api'@@ -252,7 +252,7 @@ export const metricsLogic = kea<metricsLogicType>([closeMetricFromInsightModal: true,createMetricFromInsight: (request: MetricFromInsightRequest) => ({ request }),}),- loaders(({ values }) => ({+ lazyLoaders(() => ({allMetrics: [[] as DataCatalogMetricApi[],{@@ -273,6 +273,8 @@ export const metricsLogic = kea<metricsLogicType>([},},],+ })),+ loaders(({ values }) => ({savedInsights: [[] as SavedInsightOption[],{@@ -561,7 +563,4 @@ export const metricsLogic = kea<metricsLogicType>([}},})),- afterMount(({ actions }) => {- actions.loadMetrics()- }),])diff --git a/products/endpoints/frontend/endpointsLogic.tsx b/products/endpoints/frontend/endpointsLogic.tsxindex 56c855ce30d9..de859e68efeb 100644--- a/products/endpoints/frontend/endpointsLogic.tsx+++ b/products/endpoints/frontend/endpointsLogic.tsx@@ -1,5 +1,5 @@import { MakeLogicType, actions, afterMount, connect, kea, path, reducers, selectors } from 'kea'-import { loaders } from 'kea-loaders'+import { lazyLoaders } from 'kea-loaders'import { urlToAction } from 'kea-router'import api from 'lib/api'@@ -82,7 +82,7 @@ export const endpointsLogic = kea<endpointsLogicType>([setFilters: (filters: Partial<EndpointsFilters>) => ({ filters }),setActiveTab: (activeTab: EndpointsTab) => ({ activeTab }),}),- loaders(() => ({+ lazyLoaders(() => ({allEndpoints: [[] as EndpointType[],{@@ -131,7 +131,6 @@ export const endpointsLogic = kea<endpointsLogicType>([],}),afterMount(({ actions }) => {- actions.loadEndpoints()actions.addProductIntent({product_type: ProductKey.ENDPOINTS,intent_context: ProductIntentContext.ENDPOINTS_VIEWED,