Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

Hide "New from template" when a folder or project has no templates (#1821)

tim-inkeep2f132545429e
diff --git a/.changeset/hide-empty-new-from-template.md b/.changeset/hide-empty-new-from-template.md
new file mode 100644
index 000000000..0e7768ad9
--- /dev/null
+++ b/.changeset/hide-empty-new-from-template.md
@@ -0,0 +1,5 @@
+---
+"@inkeep/open-knowledge": patch
+---
+
+Hide the sidebar "New from template" entry when a folder or the project has no templates. Previously, right-clicking a folder always showed a "New from template" submenu that opened to an empty list, and the project empty-space menu showed the entry greyed-out rather than hidden. Both surfaces now drop the entry entirely when there are no templates to pick, matching the toolbar and the editor empty-state.
diff --git a/packages/app/src/components/FileSidebar.dom.test.tsx b/packages/app/src/components/FileSidebar.dom.test.tsx
index ea113f7b9..050af750e 100644
--- a/packages/app/src/components/FileSidebar.dom.test.tsx
+++ b/packages/app/src/components/FileSidebar.dom.test.tsx
@@ -574,6 +574,18 @@ describe('FileSidebar runtime behavior', () => {
});
});
+ test('toolbar and empty-space menu hide "New from template" when no templates exist', async () => {
+ hasTemplates = false;
+ installBridge();
+ await renderSidebar();
+ await waitFor(() => expect(treeListeners.size).toBe(1));
+
+ expect(screen.queryByRole('button', { name: 'New from template' })).toBeNull();
+ expect(screen.queryByTestId('empty-space-menu-new-from-template')).toBeNull();
+ expect(screen.getByTestId('empty-space-menu-new-file')).toBeTruthy();
+ expect(screen.getByTestId('empty-space-menu-new-folder')).toBeTruthy();
+ });
+
test('View menu state pushes merged visibility and tree smart-hide state to the desktop bridge', async () => {
installBridge();
await renderSidebar();
diff --git a/packages/app/src/components/FileSidebar.tsx b/packages/app/src/components/FileSidebar.tsx
index 08f3e34dc..c53a27358 100644
--- a/packages/app/src/components/FileSidebar.tsx
+++ b/packages/app/src/components/FileSidebar.tsx
@@ -695,22 +695,24 @@ function FileSidebarInner({ onOpenSearch }: FileSidebarProps) {
<SquarePen aria-hidden="true" />
<Trans>New File</Trans>
</ContextMenuItem>
- <ContextMenuSub>
- <ContextMenuSubTrigger
- disabled={!workspace || !rootHasTemplates}
- data-testid="empty-space-menu-new-from-template"
- >
- <FilePlus aria-hidden="true" />
- <Trans>New from template</Trans>
- </ContextMenuSubTrigger>
- <ContextMenuSubContent>
- <TemplateMenuRows
- parentDir=""
- onSelectTemplate={handleEmptySpaceSelectTemplate}
- ItemComponent={ContextMenuItem}
- />
- </ContextMenuSubContent>
- </ContextMenuSub>
+ {rootHasTemplates ? (
+ <ContextMenuSub>
+ <ContextMenuSubTrigger
+ disabled={!workspace}
+ data-testid="empty-space-menu-new-from-template"
+ >
+ <FilePlus aria-hidden="true" />
+ <Trans>New from template</Trans>
+ </ContextMenuSubTrigger>
+ <ContextMenuSubContent>
+ <TemplateMenuRows
+ parentDir=""
+ onSelectTemplate={handleEmptySpaceSelectTemplate}
+ ItemComponent={ContextMenuItem}
+ />
+ </ContextMenuSubContent>
+ </ContextMenuSub>
+ ) : null}
<ContextMenuItem
disabled={!workspace}
onSelect={handleEmptySpaceCreateFolder}
diff --git a/packages/app/src/components/FileTree.create.dom.test.tsx b/packages/app/src/components/FileTree.create.dom.test.tsx
index 2851832cf..8e711a0f0 100644
--- a/packages/app/src/components/FileTree.create.dom.test.tsx
+++ b/packages/app/src/components/FileTree.create.dom.test.tsx
@@ -174,6 +174,15 @@ let createStatus = 200;
let createGate: Promise<void> | null = null;
let createFetchError: Error | null = null;
let fetchCalls: FetchCall[] = [];
+let folderTemplates: Array<{
+ name: string;
+ title?: string;
+ path: string;
+ source_folder: string;
+ scope: 'local' | 'inherited';
+}> = [];
+let folderConfigStatus: 'ready' | 'loading' = 'ready';
+let lastFolderConfigPath: string | null = null;
function jsonResponse(body: unknown, status = 200): Response {
return new Response(JSON.stringify(body), {
@@ -257,6 +266,22 @@ mock.module('@/lib/config-provider', () => ({
}),
}));
+mock.module('@/hooks/use-folder-config', () => ({
+ useFolderConfig: (folderPath: string | null) => {
+ lastFolderConfigPath = folderPath;
+ if (folderConfigStatus === 'loading') {
+ return { state: { status: 'loading' }, refresh: () => {} };
+ }
+ return {
+ state: {
+ status: 'ready',
+ data: { folder: { templates_available: folderTemplates } },
+ },
+ refresh: () => {},
+ };
+ },
+}));
+
mock.module('./handoff/useInstalledAgents', () => ({
useInstalledAgents: () => ({ states: {} }),
}));
@@ -378,6 +403,9 @@ describe('FileTree startCreating addPage symmetry', () => {
createStatus = 200;
createGate = null;
createFetchError = null;
+ folderTemplates = [];
+ folderConfigStatus = 'ready';
+ lastFolderConfigPath = null;
fetchCalls = [];
globalThis.fetch = makeFetchMock() as unknown as typeof fetch;
toastSuccessMock.mockClear();
@@ -424,4 +452,36 @@ describe('FileTree startCreating addPage symmetry', () => {
await waitFor(() => expect(fetchCalls.some((c) => c.url === '/api/create-folder')).toBe(true));
expect(addPageMock).not.toHaveBeenCalled();
});
+
+ test('folder context-menu hides "New from template" when the folder has no templates', async () => {
+ folderTemplates = [];
+ renderFileTree();
+
+ expect(await screen.findByRole('menuitem', { name: /new file/i })).toBeTruthy();
+ expect(screen.queryByRole('menuitem', { name: /new from template/i })).toBeNull();
+ });
+
+ test('folder context-menu shows "New from template" when the folder has templates', async () => {
+ folderTemplates = [
+ {
+ name: 'daily',
+ title: 'Daily',
+ path: 'notes/.ok/templates/daily.md',
+ source_folder: 'notes',
+ scope: 'local',
+ },
+ ];
+ renderFileTree();
+
+ expect(await screen.findByRole('menuitem', { name: /new from template/i })).toBeTruthy();
+ expect(lastFolderConfigPath).toBe('notes');
+ });
+
+ test('folder context-menu keeps "New from template" while folder config is loading', async () => {
+ folderConfigStatus = 'loading';
+ folderTemplates = [];
+ renderFileTree();
+
+ expect(await screen.findByRole('menuitem', { name: /new from template/i })).toBeTruthy();
+ });
});
diff --git a/packages/app/src/components/FileTree.tsx b/packages/app/src/components/FileTree.tsx
index 385b056c4..415b7b6bb 100644
--- a/packages/app/src/components/FileTree.tsx
+++ b/packages/app/src/components/FileTree.tsx
@@ -151,6 +151,7 @@ import { useDocumentContext } from '@/editor/DocumentContext';
import { captureRenameSnapshots } from '@/editor/editor-cache';
import { assetTabId, docTabId, folderTabId, remapPathForFolderRenames } from '@/editor/editor-tabs';
import { useConflicts } from '@/hooks/use-conflicts';
+import { useFolderConfig } from '@/hooks/use-folder-config';
import { useConfigContext } from '@/lib/config-provider';
import { dispatchOpenInTerminal } from '@/lib/dispatch-open-in-terminal';
import {
@@ -555,6 +556,11 @@ function FileTreeMenu({
const showHiddenFiles = mergedConfig?.appearance?.sidebar?.showHiddenFiles ?? false;
const showAllFiles = mergedConfig?.appearance?.sidebar?.showAllFiles ?? false;
const canToggleVisibility = projectLocalBinding !== null;
+ const folderConfig = useFolderConfig(isFolder ? treeDirectoryPathToFolderPath(item.path) : null);
+ const folderHasTemplates =
+ folderConfig.state.status === 'ready'
+ ? (folderConfig.state.data.folder.templates_available?.length ?? 0) > 0
+ : true;
const selectedTreePaths = model.getSelectedPaths();
const selectedDeleteTargets = selectedTreePaths.includes(target.treePath)
? selectedTreePathsToDeleteTargets(selectedTreePaths, documents)
@@ -666,22 +672,24 @@ function FileTreeMenu({
<SquarePen aria-hidden="true" />
<Trans>New File</Trans>
</DropdownMenuItem>
- <DropdownMenuSub>
- <DropdownMenuSubTrigger disabled={anyActionBusy}>
- <FilePlus aria-hidden="true" />
- <Trans>New from template</Trans>
- </DropdownMenuSubTrigger>
- <DropdownMenuSubContent>
- <TemplateMenuRows
- parentDir={treeDirectoryPathToFolderPath(item.path)}
- onSelectTemplate={(templateName) => {
- closeForInlineSurface();
- onCreateFromTemplate(treeDirectoryPathToFolderPath(item.path), templateName);
- }}
- ItemComponent={DropdownMenuItem}
- />
- </DropdownMenuSubContent>
- </DropdownMenuSub>
+ {folderHasTemplates ? (
+ <DropdownMenuSub>
+ <DropdownMenuSubTrigger disabled={anyActionBusy}>
+ <FilePlus aria-hidden="true" />
+ <Trans>New from template</Trans>
+ </DropdownMenuSubTrigger>
+ <DropdownMenuSubContent>
+ <TemplateMenuRows
+ parentDir={treeDirectoryPathToFolderPath(item.path)}
+ onSelectTemplate={(templateName) => {
+ closeForInlineSurface();
+ onCreateFromTemplate(treeDirectoryPathToFolderPath(item.path), templateName);
+ }}
+ ItemComponent={DropdownMenuItem}
+ />
+ </DropdownMenuSubContent>
+ </DropdownMenuSub>
+ ) : null}
<DropdownMenuItem
disabled={anyActionBusy}
onSelect={() => {