Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

refactor(settings): replace hand-rolled sidebar with shared TwoPaneNav

Steven Enamakel74145ff8e6e8
diff --git a/app/src/components/settings/layout/SettingsSidebar.tsx b/app/src/components/settings/layout/SettingsSidebar.tsx
index eb5e8d236f..e615612a82 100644
--- a/app/src/components/settings/layout/SettingsSidebar.tsx
+++ b/app/src/components/settings/layout/SettingsSidebar.tsx
@@ -1,8 +1,7 @@
import { useState } from 'react';
-import { cn } from '../../../lib/cn';
import { useT } from '../../../lib/i18n/I18nContext';
-import Button from '../../ui/Button';
+import TwoPaneNav from '../../layout/TwoPaneNav';
import { useSettingsNavigation } from '../hooks/useSettingsNavigation';
import SettingsSearchBar from '../search/SettingsSearchBar';
import { useSettingsSearch } from '../search/useSettingsSearch';
@@ -14,26 +13,16 @@ import {
} from '../settingsRouteRegistry';
import { SETTINGS_NAV_ICONS } from './settingsNavIcons';
-/** A renderable nav row, normalised across grouped entries and search results. */
-interface NavRow {
- id: string;
- label: string;
- route: string;
- /** Accent the row (e.g. Billing) even when inactive. */
- highlight?: boolean;
-}
-
-interface NavSection {
- key: string;
- /** i18n key for the group heading, or null to render no heading (search results). */
- labelKey: string | null;
- rows: NavRow[];
-}
-
/**
* Grouped settings navigation. On wide viewports this is the persistent left
* pane of the two-pane layout; on narrow viewports it doubles as the
* /settings index page (the old drill-down home list).
+ *
+ * Rendered with the shared {@link TwoPaneNav} — the same primitive every other
+ * page's sidebar uses, and the same column it is projected into. It used to
+ * hand-roll an equivalent row list, which drifted the moment either side was
+ * touched: shorter rows (`py-1` vs `py-1.5`), a different group-heading inset,
+ * and a grey icon left sitting on the accent fill of a selected row.
*/
const SettingsSidebar = () => {
const { t } = useT();
@@ -48,116 +37,66 @@ const SettingsSidebar = () => {
const searchResults = useSettingsSearch(searchQuery);
const activeSidebarId = resolveSidebarId(currentRoute);
- const sections: NavSection[] = isSearching
+
+ // `route` is not carried on the nav item, so keep the id → route map beside
+ // the groups and resolve on select.
+ const routeById = new Map<string, string>();
+
+ const groups = isSearching
? [
{
- key: 'results',
- labelKey: null,
- rows: searchResults.map(result => ({
- id: result.entry.id,
- label: result.title,
- route: result.entry.route,
- })),
+ testId: 'settings-search-results',
+ items: searchResults.map(result => {
+ routeById.set(result.entry.id, result.entry.route);
+ return {
+ value: result.entry.id,
+ label: result.title,
+ icon: SETTINGS_NAV_ICONS[result.entry.id] ?? null,
+ testId: `settings-nav-${result.entry.id}`,
+ };
+ }),
},
]
: sidebarGroups().map(group => ({
- key: group.group,
- labelKey: NAV_GROUP_LABEL_KEY[group.group],
- rows: group.entries.map(entry => ({
- id: entry.id,
- label: t(entry.titleKey),
- route: entryRoute(entry),
- highlight: entry.highlight,
- })),
+ label: t(NAV_GROUP_LABEL_KEY[group.group]),
+ testId: `settings-sidebar-group-${group.group}`,
+ items: group.entries.map(entry => {
+ routeById.set(entry.id, entryRoute(entry));
+ return {
+ value: entry.id,
+ label: t(entry.titleKey),
+ icon: SETTINGS_NAV_ICONS[entry.id] ?? null,
+ highlight: entry.highlight,
+ testId: `settings-nav-${entry.id}`,
+ };
+ }),
}));
- const hasRows = sections.some(section => section.rows.length > 0);
- return (
- <nav
- aria-label={t('nav.settings')}
- data-walkthrough="settings-menu"
- className="flex h-full flex-col">
- {/* Full-width search field as a fixed header (no padding). The scroll
- lives on the content below, not on this header. */}
- <SettingsSearchBar value={searchQuery} onValueChange={setSearchQuery} />
-
- {/* px-3 is the shell sidebar's gutter (`SidebarGroup`/`SidebarHeader`).
- This list is projected into that same column, so a narrower inset of
- its own put settings rows and app-nav rows on two different left
- edges. */}
- <div className="min-h-0 flex-1 overflow-y-auto px-3 pb-2">
- {sections.map(section => (
- <div
- key={section.key}
- data-testid={
- section.labelKey ? `settings-sidebar-group-${section.key}` : 'settings-search-results'
- }>
- {section.labelKey && (
- <div className="px-2.5 pb-0.5 pt-2.5">
- <span className="text-[10px] font-semibold uppercase tracking-wider text-content-muted">
- {t(section.labelKey)}
- </span>
- </div>
- )}
- <ul>
- {section.rows.map(row => {
- const active = activeSidebarId === row.id;
- const highlight = !!row.highlight;
- const rowClass = active
- ? // Active rows carry the accent fill, matching
- // `SidebarMenuButton` in the app nav directly above this
- // list — the two render in the same column, so selection
- // has to look the same in both.
- 'bg-primary-500 font-semibold text-content-inverted'
- : highlight
- ? // Highlighted-but-inactive rows (e.g. Billing) accent the
- // text only — this is semantic, so it keeps its colour.
- 'text-primary-700 hover:bg-surface/40 dark:text-primary-300'
- : 'text-content-muted hover:bg-surface/40 hover:text-content-secondary';
- return (
- <li key={row.id}>
- <Button
- type="button"
- variant="tertiary"
- data-testid={`settings-nav-${row.id}`}
- aria-current={active ? 'page' : undefined}
- onClick={() => navigateToSettings(row.route)}
- className={cn(
- 'h-auto w-full justify-start gap-2 rounded-md px-2.5 py-1 text-left text-[14px] font-normal',
- rowClass
- )}>
- <span
- // `active` is tested first so a row that is both active
- // and highlighted renders fully neutral — otherwise the
- // label went neutral while the icon kept the accent.
- className={cn(
- 'shrink-0',
- active
- ? 'text-content-secondary'
- : highlight
- ? 'text-primary-600 dark:text-primary-400'
- : 'text-content-faint'
- )}>
- {SETTINGS_NAV_ICONS[row.id] ?? null}
- </span>
- <span className="truncate">{row.label}</span>
- </Button>
- </li>
- );
- })}
- </ul>
- </div>
- ))}
+ const hasRows = groups.some(group => group.items.length > 0);
- {isSearching && !hasRows && (
+ return (
+ <TwoPaneNav
+ ariaLabel={t('nav.settings')}
+ walkthroughId="settings-menu"
+ // Full-width search field as a fixed header; the scroll lives on the nav
+ // list below it, not on the header.
+ header={<SettingsSearchBar value={searchQuery} onValueChange={setSearchQuery} />}
+ groups={groups}
+ selected={activeSidebarId ?? ''}
+ onSelect={id => {
+ const route = routeById.get(id);
+ if (route) navigateToSettings(route);
+ }}
+ footer={
+ isSearching && !hasRows ? (
<p
data-testid="settings-search-empty"
className="px-2.5 pt-3 text-center text-xs text-content-faint">
{t('settings.settingsSearch.noResults').replace('{query}', searchQuery.trim())}
</p>
- )}
- </div>
- </nav>
+ ) : null
+ }
+ />
);
};