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): restore starred folder menus and empty states (#104834)

Marius Andra037f1587f093
diff --git a/docs/published/handbook/engineering/project-structure.md b/docs/published/handbook/engineering/project-structure.md
index c8a784f610b4..3ba1fc314118 100644
--- a/docs/published/handbook/engineering/project-structure.md
+++ b/docs/published/handbook/engineering/project-structure.md
@@ -49,6 +49,8 @@ The PostHog web application, built with React and TypeScript. Uses [Kea](https:/
The app-level Files scene lives in `src/scenes/project-files` and reuses the project tree from `src/layout/panel-layout/ProjectTree`.
Open `/project/<project_id>/files` to browse the project, or add `?folder=Research` to start in a folder.
+Starred folders in the sidebar use the same "New..." menu and "Empty folder" state as project folders.
+Creating an item from a starred folder uses the original folder's full path, including its parent folders.
### `posthog`
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 83ff0b7e2390..51108e66eefd 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -3705,29 +3705,29 @@ snapshots:
layout-apps-and-files--empty-starred--light:
hash: v1.k794b7964.c7c6a37454118fa89d27297f63d5be33f4f96e7a5bac5ad95d0d359db5299f8e.61EBDOwDr7wvR6Iv6IYfVbjRF48Fwp3QxYVHhFTHDhQ
layout-apps-and-files--files--dark:
- hash: v1.k794b7964.0841bb7f32c3939650b6911817dc54b80a7b31f43733934c54429572c975a728.N6E4uDlBVYp3PYku6SioCYXZWDNHIZsGgCyu4K6eLcI
+ hash: v1.k794b7964.b95d0005c1857352aafbef256ddfbf2d2c2ddfc62ee221fe1d79234ac3d352fb.k0bm1OPJ2x-uYL87NNR2kCCGQei4Q_cUWOqAE8SpKus
layout-apps-and-files--files--light:
- hash: v1.k794b7964.0ea82d112a7cb5ae4be349bdae3543a9c6a1cb4ad8054a7d372a988c6cbf91bf.wM47Hp8LXO3CbNbN2V2P77XtiK550Vr2yJneapsKSA4
+ hash: v1.k794b7964.0d13746bd44fe9eadfade31ab1b2f1fbded3b3ca7357cdddbdf3b1a134058293.ODn03zZEmIWDIdIy2Igk7drnpuNs7H4zKl92h18ORKc
layout-apps-and-files--files-dark--dark:
- hash: v1.k794b7964.0841bb7f32c3939650b6911817dc54b80a7b31f43733934c54429572c975a728.3eRQkZzI1WYgFhmfKnBELcQltH4bzjFbpq91jhTaoWo
+ hash: v1.k794b7964.b95d0005c1857352aafbef256ddfbf2d2c2ddfc62ee221fe1d79234ac3d352fb.9u6zdJitJwCrxslqUdCV_7nseBaS_qXtqsLrkkkGcfc
layout-apps-and-files--files-dark--light:
- hash: v1.k794b7964.0ea82d112a7cb5ae4be349bdae3543a9c6a1cb4ad8054a7d372a988c6cbf91bf.o6xHB2Tzxk5_ILPgXSQPzcZ6bOasJlaQf9Otv49bFDg
+ hash: v1.k794b7964.2469554b7f4152e24bb3043def6ac12bb275b85241e985cdf05cc6c9f6399b97.A41yeOyKK09nOELTAK9WB0CXuHNjMO_gu0d7g67C5Ug
layout-apps-and-files--files-empty-starred--dark:
hash: v1.k794b7964.b9273d74f6837673fdf4cc9600ccd5c48186af00b8f11598283aabc3d62487ac.w2j4tEjWEC9_uXf5w8aquZqghIvKvAF8hDftLPXAXOw
layout-apps-and-files--files-empty-starred--light:
hash: v1.k794b7964.2b490c51e5691b5717f9e29e63047b025ec995621359374484117172e466eff1.R2Hc7aQ_SfXjEnE-RtJSEH7tbVoz33BvSh7YrsacsxA
layout-apps-and-files--files-long-tree--dark:
- hash: v1.k794b7964.5cc2e1092e9667c57f102ecf1070616c772db4d57ba919788193eb0347477038.ARdi8ZDKqPZ1BlHmauE23nsAz6QoCjNfDmmQvKtdGyc
+ hash: v1.k794b7964.fe09b826feb2108458093997794ad3dbde8cc7159535fa386882034dcee16444.YVnXJjHGKHDL6QXWBiuI8oW6yx-B1gvdkBF6gp_oT4Y
layout-apps-and-files--files-long-tree--light:
- hash: v1.k794b7964.08f2a0a2f20aa83a4c7d202004f0dba09b18baf8ce1fa56a34847fdcadbfb0e4.Irvc-3kpDfEtzjgkX20mpRjKInyccUd7hre-yjuOPyI
+ hash: v1.k794b7964.ab0000fe925b988f496edadc1b3e8531c15ef5b76e39b067f6c532934fbc7d49.XsqB2m60rxzmbUGutMfc-PGiNYYViJXZK2VnNsFfchA
layout-apps-and-files--files-narrow--dark:
- hash: v1.k794b7964.f749ff197546d3d2f1b88c2018843d79f97e2135ca95acc9083f3503510948a9.WXbLG92Rk8NY0s-MYyvgeKE02kdv5adwyW9XWeWvCkc
+ hash: v1.k794b7964.687bca7b4b144e78f73759c3ccd2bf29251337a1ec7dd5a491bfc56b5b5bf8d7.H18yxPF5420T0Vti58kpSoO1FfvOwoP7AfgDFdOrPAQ
layout-apps-and-files--files-narrow--light:
- hash: v1.k794b7964.90788987cd337a71ffe2691400b5da016b80948ab6c88ce9b8c67d5a44911ea5._oL7iRi6mu1rwOj1pyBfe3-rnfvWpANEBY_UZk8gWXk
+ hash: v1.k794b7964.36a866d1760aaa9f107df7a0e182d697c469a7dd56031c3043754d14b2d43fdf.82zN8Dyud1bpSeo707r160puvow2OybtsQR_26u8yow
layout-apps-and-files--files-recents-collapsed--dark:
- hash: v1.k794b7964.f1a2784553f05553104eee2802be1a6e264d2b850ed068df4168b502bd429b1e.Jx9NaOZ1g0xwily-5UMFdIbVdagpUjidumywyvvpTIs
+ hash: v1.k794b7964.261d77012b9ae69370c8fc907e171cf351d4d4a069ef0d628654012b374ada85.GGqJM1iyAbBUAWvJSRoDsvL21JjxRmgITzP_MbX48jk
layout-apps-and-files--files-recents-collapsed--light:
- hash: v1.k794b7964.a826987843c76568b6d5cfb159428f5bc4556ae1ee9f55ea33752099adfd6123.i31Wes7W6iXfLt9h4_QEExq0Cgzn6J3GFy24C8fVRLI
+ hash: v1.k794b7964.4e320e53190692735eaa2bf1691cb65b4001a0b9abb4414bc1fbbd9cecb01d54.ZL1QWp4U8zDwUSUQP7iXBWQUGlPEhvRx7n7hzvOLTaE
layout-apps-and-files--flag-off--dark:
hash: v1.k794b7964.1d2bc7478dae3a6a9f01dea82d349773021591a51bfc8350ad86a9427400b980.pjx9o1-yZUZYLwWK1yCxPmCE6XmaK2UKX7yX5Bdv1nk
layout-apps-and-files--flag-off--light:
diff --git a/frontend/src/layout/panel-layout/ProjectTree/menus/MenuItems.test.tsx b/frontend/src/layout/panel-layout/ProjectTree/menus/MenuItems.test.tsx
new file mode 100644
index 000000000000..2f13c464e887
--- /dev/null
+++ b/frontend/src/layout/panel-layout/ProjectTree/menus/MenuItems.test.tsx
@@ -0,0 +1,91 @@
+import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
+
+import api from 'lib/api'
+import { FEATURE_FLAGS } from 'lib/constants'
+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
+import { ContextMenu, ContextMenuContent, ContextMenuTrigger } from 'lib/ui/ContextMenu/ContextMenu'
+import { DropdownMenu, DropdownMenuContent } from 'lib/ui/DropdownMenu/DropdownMenu'
+
+import { initKeaTests } from '~/test/init'
+
+import { projectTreeDataLogic } from '../projectTreeDataLogic'
+import { MenuItems } from './MenuItems'
+
+describe('MenuItems', () => {
+ let unmountLogic: () => void
+
+ beforeEach(() => {
+ initKeaTests()
+ featureFlagLogic.actions.setFeatureFlags([FEATURE_FLAGS.SIMPLE_SIDEPANEL], {})
+ jest.spyOn(api.fileSystem, 'list').mockResolvedValue({ count: 0, results: [], users: [] })
+ jest.spyOn(api.fileSystem, 'unfiled').mockResolvedValue(null)
+ jest.spyOn(api.fileSystemShortcuts, 'list').mockResolvedValue({ count: 0, results: [] })
+ jest.spyOn(api.fileSystem, 'create').mockImplementation(async (item) => ({ ...item, id: 'new-folder' }))
+ unmountLogic = projectTreeDataLogic.mount()
+ })
+
+ afterEach(() => {
+ cleanup()
+ unmountLogic()
+ jest.restoreAllMocks()
+ })
+
+ it.each(['context', 'dropdown'] as const)(
+ 'creates folders and resources in the original starred folder through the %s menu',
+ async (type) => {
+ const menu = (
+ <MenuItems
+ type={type}
+ root="shortcuts://"
+ item={{
+ id: 'shortcuts://Ideas',
+ name: 'Ideas',
+ record: { id: 'star-folder', path: 'Ideas', type: 'folder', ref: 'Research/Ideas' },
+ }}
+ />
+ )
+ const { unmount } = render(
+ type === 'context' ? (
+ <ContextMenu>
+ <ContextMenuTrigger>Ideas</ContextMenuTrigger>
+ <ContextMenuContent>{menu}</ContextMenuContent>
+ </ContextMenu>
+ ) : (
+ <DropdownMenu defaultOpen>
+ <DropdownMenuContent>{menu}</DropdownMenuContent>
+ </DropdownMenu>
+ )
+ )
+ if (type === 'context') {
+ fireEvent.contextMenu(screen.getByText('Ideas'))
+ }
+ fireEvent.keyDown(await screen.findByText('New...'), { key: 'ArrowRight' })
+ fireEvent.click(await screen.findByText('Folder'))
+ await waitFor(() =>
+ expect(api.fileSystem.create).toHaveBeenCalledWith(
+ expect.objectContaining({ path: 'Research/Ideas/Untitled folder', type: 'folder' })
+ )
+ )
+ unmount()
+
+ render(
+ type === 'context' ? (
+ <ContextMenu>
+ <ContextMenuTrigger>Ideas</ContextMenuTrigger>
+ <ContextMenuContent>{menu}</ContextMenuContent>
+ </ContextMenu>
+ ) : (
+ <DropdownMenu defaultOpen>
+ <DropdownMenuContent>{menu}</DropdownMenuContent>
+ </DropdownMenu>
+ )
+ )
+ if (type === 'context') {
+ fireEvent.contextMenu(screen.getByText('Ideas'))
+ }
+ fireEvent.keyDown(await screen.findByText('New...'), { key: 'ArrowRight' })
+ fireEvent.click(await screen.findByText('New dashboard'))
+ expect(projectTreeDataLogic.values.lastNewFolder).toBe('Research/Ideas')
+ }
+ )
+})
diff --git a/frontend/src/layout/panel-layout/ProjectTree/menus/MenuItems.tsx b/frontend/src/layout/panel-layout/ProjectTree/menus/MenuItems.tsx
index 968479faef36..48931680ba75 100644
--- a/frontend/src/layout/panel-layout/ProjectTree/menus/MenuItems.tsx
+++ b/frontend/src/layout/panel-layout/ProjectTree/menus/MenuItems.tsx
@@ -158,6 +158,8 @@ export function MenuItems({
const isSimpleSidepanelEnabled = useFeatureFlag('SIMPLE_SIDEPANEL')
const isItemAFolder = item.record?.type === 'folder'
+ const isStarredFolder = isItemAFolder && item.id.startsWith('shortcuts://') && !!item.record?.ref
+ const newMenuItem = isStarredFolder ? { ...item, record: { ...item.record, path: item.record?.ref } } : item
const itemShortcutPath = joinPath([splitPath(item.record?.path).pop() ?? 'Unnamed'])
const isItemAlreadyInShortcut = !isItemAFolder && shortcutNonFolderPaths.has(itemShortcutPath)
const shortcutId =
@@ -232,6 +234,7 @@ export function MenuItems({
) : null}
{(item.record?.protocol === 'project://' && item.record?.type === 'folder') ||
+ isStarredFolder ||
item.id?.startsWith('project-folder-empty/') ? (
<>
<MenuSub key="new">
@@ -247,7 +250,7 @@ export function MenuItems({
</ButtonPrimitive>
</MenuSubTrigger>
<MenuSubContent>
- <NewMenu type={type} item={item} createFolder={createFolder} />
+ <NewMenu type={type} item={newMenuItem} createFolder={createFolder} />
</MenuSubContent>
</MenuSub>
<MenuSeparator />
diff --git a/frontend/src/layout/panel-layout/ProjectTree/projectTreeDataLogic.test.ts b/frontend/src/layout/panel-layout/ProjectTree/projectTreeDataLogic.test.ts
index 53651a32ba55..5dfc492143f6 100644
--- a/frontend/src/layout/panel-layout/ProjectTree/projectTreeDataLogic.test.ts
+++ b/frontend/src/layout/panel-layout/ProjectTree/projectTreeDataLogic.test.ts
@@ -39,6 +39,36 @@ describe('projectTreeDataLogic', () => {
jest.restoreAllMocks()
})
+ it.each(['loaded', 'loading', 'has-more', 'populated'] as const)(
+ 'renders a starred nested folder with %s contents',
+ (state) => {
+ const folder = 'Research/Ideas'
+ logic.actions.loadShortcutsSuccess([{ id: 'star-folder', path: 'Ideas', type: 'folder', ref: folder }])
+ logic.actions.loadFolderSuccess(
+ folder,
+ state === 'populated' ? [{ id: 'note', path: `${folder}/Notes`, type: 'notebook', ref: 'notes' }] : [],
+ state === 'has-more',
+ 0
+ )
+ if (state === 'loading') {
+ logic.actions.loadFolderStart(folder)
+ }
+
+ const [starredFolder] = logic.values.getShortcutTreeItems('', false)
+ expect(starredFolder.id).toBe('shortcuts://Ideas')
+ expect(starredFolder.children).toHaveLength(1)
+ expect(starredFolder.children?.[0]).toMatchObject(
+ state === 'loaded'
+ ? { name: 'Empty folder', type: 'empty-folder', disableSelect: true }
+ : state === 'loading'
+ ? { name: 'Loading...', type: 'loading-indicator' }
+ : state === 'has-more'
+ ? { name: 'Load more...' }
+ : { name: 'Notes', record: { path: `${folder}/Notes` } }
+ )
+ }
+ )
+
it('shows only the products the user added, with nothing injected alongside them', () => {
customProductsLogic.actions.loadCustomProductsSuccess([
{
diff --git a/frontend/src/layout/panel-layout/ProjectTree/projectTreeDataLogic.tsx b/frontend/src/layout/panel-layout/ProjectTree/projectTreeDataLogic.tsx
index 034f3a2a8a3a..89591f7c2c16 100644
--- a/frontend/src/layout/panel-layout/ProjectTree/projectTreeDataLogic.tsx
+++ b/frontend/src/layout/panel-layout/ProjectTree/projectTreeDataLogic.tsx
@@ -1526,6 +1526,14 @@ export const projectTreeDataLogic = kea<projectTreeDataLogicType>([
disableSelect: true,
type: 'loading-indicator',
})
+ } else if (converted.length === 0) {
+ converted.push({
+ id: `shortcuts://-folder-empty/${shortcutTreeItem.id}`,
+ name: 'Empty folder',
+ displayName: <>Empty folder</>,
+ disableSelect: true,
+ type: 'empty-folder',
+ })
}
newShortcutData.push({ ...shortcutTreeItem, children: converted })
diff --git a/frontend/src/layout/panel-layout/navbar/AppsAndFiles.stories.tsx b/frontend/src/layout/panel-layout/navbar/AppsAndFiles.stories.tsx
index 3269a96e4b39..062952b53839 100644
--- a/frontend/src/layout/panel-layout/navbar/AppsAndFiles.stories.tsx
+++ b/frontend/src/layout/panel-layout/navbar/AppsAndFiles.stories.tsx
@@ -25,6 +25,7 @@ const files: FileSystemEntry[] = [
href: '/insights/signup01',
},
{ id: 'folder-2', path: 'Product research', type: 'folder' },
+ { id: 'folder-3', path: 'Product research/Ideas', type: 'folder' },
{
id: 'notebook-1',
path: 'Product research/Onboarding notes',
@@ -38,6 +39,7 @@ const starred: FileSystemEntry[] = [
{ id: 'star-1', path: 'Product analytics', type: 'product_analytics', href: '/insights' },
{ id: 'star-2', path: 'Overview', type: 'dashboard', ref: '1', href: '/dashboard/1' },
{ id: 'star-3', path: 'Product research', type: 'folder', ref: 'Product research' },
+ { id: 'star-4', path: 'Ideas', type: 'folder', ref: 'Product research/Ideas' },
]
function SidebarStory({