Skip to content

⭐️⭐️⭐️ Open-source, self-hosted alternative to Linear and Plane. Project management and issue tracking where teams and AI agents work side by side to plan and ship products.

refactor(web): let an extending build fold AI Team sections into one menu entry (#764)

Croff55e323ee40cd
diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.md
index 847d9eed..31831c0f 100644
--- a/apps/web/AGENTS.md
+++ b/apps/web/AGENTS.md
@@ -29,9 +29,10 @@ Next.js App Router, SSR (not SPA). Tailwind v4 + shadcn/ui. See root `AGENTS.md`
also decides the page a workspace opens on.
`useProjectSettingsSections(project, core)` returns the project's sections: here the
core's, while the hosted build adds its own at any position or drops some. Those of the
- `ai-team` group are listed in the main sidebar's AI Team group, the others in the settings
- sidebar, which lists the groups in the order their first section comes, each named in
- `nav.groups.<group>`, so a section can open a group of its own. One the build adds
+ `ai-team` group are listed in the main sidebar's AI Team group, those naming the same `menu`
+ as one entry that opens to them, named by the menu's `sections.settings` messages; the others
+ in the settings sidebar, which lists the groups in the order their first section comes, each
+ named in `nav.groups.<group>`, so a section can open a group of its own. One the build adds
carries in `Component` the page `/:team/:projectKey/settings/<slug>` opens, or
`/:team/:projectKey/agents/<slug>` in the AI Team group, which answers 404 only once the
project and every query in flight have loaded.
diff --git a/apps/web/src/components/layout/SidebarAiTeamNav.tsx b/apps/web/src/components/layout/SidebarAiTeamNav.tsx
index 9249f38c..3316533a 100644
--- a/apps/web/src/components/layout/SidebarAiTeamNav.tsx
+++ b/apps/web/src/components/layout/SidebarAiTeamNav.tsx
@@ -1,7 +1,7 @@
import { usePathname } from 'next/navigation';
import { useTranslations } from 'next-intl';
import { aiAgentsPath, aiTeamPath } from '@/utils/paths';
-import { AI_AGENTS_SECTION } from '@/utils/settingsSections';
+import { AI_AGENTS_SECTION, aiTeamEntries, type AiTeamEntry } from '@/utils/settingsSections';
import { useAiTeamSections } from '@/hooks/useSettingsNavGroups';
import { usePermissions } from '@/hooks/usePermissions';
import { useShellRoute } from '@/hooks/useShellRoute';
@@ -13,6 +13,7 @@ import {
SidebarMenu,
} from '@/components/ui/sidebar';
import SidebarNavItem from '@/components/layout/SidebarNavItem';
+import SidebarNavSubmenu from '@/components/layout/SidebarNavSubmenu';
// The AI Team sidebar group: the AI Team sections the viewer may read, then the
// agents of the project, then their runs. Renders nothing when none of them are readable.
@@ -30,23 +31,46 @@ export default function SidebarAiTeamNav({ projectKey }: { projectKey: string |
);
const showAgents = can(AI_AGENTS_SECTION.resource, 'read');
if (sections.length === 0 && !showAgents) return null;
+ const href = (slug: string) => (projectKey ? aiTeamPath(projectKey, slug) : '#');
const sectionItem = (s: (typeof sections)[number]) => (
<SidebarNavItem
key={s.slug}
- href={projectKey ? aiTeamPath(projectKey, s.slug) : '#'}
+ href={href(s.slug)}
icon={s.icon}
label={sectionText(s.slug).label}
active={aiTeamSection === s.slug}
disabled={disabled}
/>
);
+ const listed = sections.filter((s) => s.slug !== 'queue');
+ // A menu opens to links, so with no project to link to each section is an item of its own.
+ const entries: AiTeamEntry[] = projectKey
+ ? aiTeamEntries(listed)
+ : listed.map((section) => ({ section }));
+ const entryItem = (entry: AiTeamEntry) =>
+ 'section' in entry ? (
+ sectionItem(entry.section)
+ ) : (
+ <SidebarNavSubmenu
+ key={`menu:${entry.menu}`}
+ icon={entry.sections[0]!.icon}
+ label={sectionText(entry.menu).label}
+ items={entry.sections.map((s) => ({
+ key: s.slug,
+ href: href(s.slug),
+ icon: s.icon,
+ label: sectionText(s.slug).label,
+ active: aiTeamSection === s.slug,
+ }))}
+ />
+ );
return (
<SidebarGroup>
<SidebarGroupLabel>{t('aiTeam')}</SidebarGroupLabel>
<SidebarGroupContent>
<SidebarMenu>
- {sections.filter((s) => s.slug !== 'queue').map(sectionItem)}
+ {entries.map(entryItem)}
{showAgents && (
<SidebarNavItem
href={projectKey ? aiAgentsPath(projectKey) : '#'}
diff --git a/apps/web/src/utils/settingsSections.test.ts b/apps/web/src/utils/settingsSections.test.ts
new file mode 100644
index 00000000..5d8f8b63
--- /dev/null
+++ b/apps/web/src/utils/settingsSections.test.ts
@@ -0,0 +1,31 @@
+import assert from 'node:assert/strict';
+import { describe, it } from 'node:test';
+import { Bot } from 'lucide-react';
+import { aiTeamEntries, type SettingsSection } from './settingsSections';
+
+const section = (slug: string, menu?: string): SettingsSection => ({
+ slug,
+ icon: Bot,
+ resource: 'ai_agents',
+ group: 'ai-team',
+ menu,
+});
+
+describe('aiTeamEntries', () => {
+ it('folds the sections of one menu into one entry, where the first of them is', () => {
+ const entries = aiTeamEntries([
+ section('schedules'),
+ section('flows', 'flows'),
+ section('reports'),
+ section('flow-runs', 'flows'),
+ ]);
+ assert.deepEqual(
+ entries.map((entry) =>
+ 'section' in entry
+ ? entry.section.slug
+ : `${entry.menu}: ${entry.sections.map((s) => s.slug).join(', ')}`,
+ ),
+ ['schedules', 'flows: flows, flow-runs', 'reports'],
+ );
+ });
+});
diff --git a/apps/web/src/utils/settingsSections.ts b/apps/web/src/utils/settingsSections.ts
index 5fc8a176..708a6fb2 100644
--- a/apps/web/src/utils/settingsSections.ts
+++ b/apps/web/src/utils/settingsSections.ts
@@ -27,12 +27,16 @@ import type { PermissionAction, PermissionResource } from '@/lib/api/endpoints/r
// and 'ai' sections are listed in the main sidebar's AI Team group instead. The name and
// the blurb of a section are messages under `sections.settings`. A section the hosted
// build adds (`useProjectSettingsSections` in `@/cloud`) carries its page in `Component`.
+// AI Team sections naming the same `menu` are listed as one entry that opens to them, named
+// by the `sections.settings` messages of the menu, with the icon of its first section; each
+// keeps its own page.
export type SettingsSection = {
slug: string;
icon: LucideIcon;
resource: PermissionResource;
viewAction?: PermissionAction;
group: string;
+ menu?: string;
Component?: ComponentType;
};
@@ -128,6 +132,31 @@ export const AI_AGENTS_SECTION: SettingsSection = {
group: 'ai',
};
+// The entries of the main sidebar's AI Team group: a section, or the sections of one `menu`,
+// listed where the first of them is.
+export type AiTeamEntry =
+ { section: SettingsSection } | { menu: string; sections: SettingsSection[] };
+
+export function aiTeamEntries(sections: SettingsSection[]): AiTeamEntry[] {
+ const entries: AiTeamEntry[] = [];
+ const menus = new Map<string, SettingsSection[]>();
+ for (const section of sections) {
+ if (!section.menu) {
+ entries.push({ section });
+ continue;
+ }
+ const listed = menus.get(section.menu);
+ if (listed) {
+ listed.push(section);
+ } else {
+ const grouped = [section];
+ menus.set(section.menu, grouped);
+ entries.push({ menu: section.menu, sections: grouped });
+ }
+ }
+ return entries;
+}
+
// The core's AI Team sections; useAiTeamSections adds the hosted build's.
export const AI_TEAM_SECTIONS = SETTINGS_SECTIONS.filter((s) => s.group === 'ai-team');