2026-03-06 17:22:59 +02:00
|
|
|
import React from 'react';
|
|
|
|
|
import {
|
|
|
|
|
DropdownMenu,
|
|
|
|
|
DropdownMenuContent,
|
|
|
|
|
DropdownMenuItem,
|
2026-07-28 12:04:39 +03:00
|
|
|
DropdownMenuLabel,
|
2026-03-20 17:35:06 +07:00
|
|
|
DropdownMenuSeparator,
|
2026-03-06 17:22:59 +02:00
|
|
|
DropdownMenuTrigger,
|
|
|
|
|
} from '@/components/ui/dropdown-menu';
|
|
|
|
|
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';
|
2026-04-20 23:32:32 +03:00
|
|
|
import { cn } from '@/lib/utils';
|
2026-05-13 13:26:15 +03:00
|
|
|
import { Icon } from "@/components/icon/Icon";
|
2026-07-28 12:04:39 +03:00
|
|
|
import { ArrowsMerge } from '@/components/icons/ArrowsMerge';
|
2026-03-06 17:22:59 +02:00
|
|
|
import { useSessionDisplayStore } from '@/stores/useSessionDisplayStore';
|
2026-04-26 14:03:39 +03:00
|
|
|
import { useI18n } from '@/lib/i18n';
|
2026-03-06 17:22:59 +02:00
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
hideDirectoryControls: boolean;
|
2026-05-28 01:13:03 +03:00
|
|
|
showRecentControls: boolean;
|
2026-03-06 17:22:59 +02:00
|
|
|
handleOpenDirectoryDialog: () => void;
|
2026-07-28 12:04:39 +03:00
|
|
|
onOpenScheduled: () => void;
|
|
|
|
|
onOpenMultiRun: () => void;
|
2026-03-22 22:31:29 +02:00
|
|
|
canOpenMultiRun: boolean;
|
2026-07-28 12:04:39 +03:00
|
|
|
onOpenArchive: () => void;
|
2026-03-06 17:22:59 +02:00
|
|
|
headerActionIconClass: string;
|
|
|
|
|
headerActionButtonClass: string;
|
|
|
|
|
isSessionSearchOpen: boolean;
|
|
|
|
|
setIsSessionSearchOpen: (open: boolean | ((prev: boolean) => boolean)) => void;
|
|
|
|
|
sessionSearchInputRef: React.RefObject<HTMLInputElement | null>;
|
|
|
|
|
sessionSearchQuery: string;
|
|
|
|
|
setSessionSearchQuery: (value: string) => void;
|
|
|
|
|
hasSessionSearchQuery: boolean;
|
|
|
|
|
searchMatchCount: number;
|
2026-03-20 17:35:06 +07:00
|
|
|
collapseAllProjects: () => void;
|
|
|
|
|
expandAllProjects: () => void;
|
2026-04-20 23:32:32 +03:00
|
|
|
selectionModeEnabled: boolean;
|
|
|
|
|
onToggleSelectionMode: () => void;
|
2026-03-06 17:22:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export function SidebarHeader(props: Props): React.ReactNode {
|
2026-04-26 14:03:39 +03:00
|
|
|
const { t } = useI18n();
|
2026-03-06 17:22:59 +02:00
|
|
|
const {
|
|
|
|
|
hideDirectoryControls,
|
2026-05-28 01:13:03 +03:00
|
|
|
showRecentControls,
|
2026-03-20 01:01:03 +02:00
|
|
|
handleOpenDirectoryDialog,
|
2026-07-28 12:04:39 +03:00
|
|
|
onOpenScheduled,
|
|
|
|
|
onOpenMultiRun,
|
2026-03-22 22:31:29 +02:00
|
|
|
canOpenMultiRun,
|
2026-07-28 12:04:39 +03:00
|
|
|
onOpenArchive,
|
2026-03-06 17:22:59 +02:00
|
|
|
headerActionIconClass,
|
|
|
|
|
headerActionButtonClass,
|
|
|
|
|
isSessionSearchOpen,
|
|
|
|
|
setIsSessionSearchOpen,
|
|
|
|
|
sessionSearchInputRef,
|
|
|
|
|
sessionSearchQuery,
|
|
|
|
|
setSessionSearchQuery,
|
|
|
|
|
hasSessionSearchQuery,
|
|
|
|
|
searchMatchCount,
|
2026-03-20 17:35:06 +07:00
|
|
|
collapseAllProjects,
|
|
|
|
|
expandAllProjects,
|
2026-04-20 23:32:32 +03:00
|
|
|
selectionModeEnabled,
|
|
|
|
|
onToggleSelectionMode,
|
2026-03-06 17:22:59 +02:00
|
|
|
} = props;
|
|
|
|
|
|
2026-05-03 16:32:14 +03:00
|
|
|
const showRecentSection = useSessionDisplayStore((state) => state.showRecentSection);
|
|
|
|
|
const toggleRecentSection = useSessionDisplayStore((state) => state.toggleRecentSection);
|
2026-07-11 22:43:57 +11:00
|
|
|
const projectSortOrder = useSessionDisplayStore((state) => state.projectSortOrder);
|
|
|
|
|
const setProjectSortOrder = useSessionDisplayStore((state) => state.setProjectSortOrder);
|
2026-07-28 12:04:39 +03:00
|
|
|
const sessionGroupingMode = useSessionDisplayStore((state) => state.sessionGroupingMode);
|
|
|
|
|
const setSessionGroupingMode = useSessionDisplayStore((state) => state.setSessionGroupingMode);
|
|
|
|
|
const stickyZoneHeaders = useSessionDisplayStore((state) => state.stickyZoneHeaders);
|
|
|
|
|
const toggleStickyZoneHeaders = useSessionDisplayStore((state) => state.toggleStickyZoneHeaders);
|
2026-03-06 17:22:59 +02:00
|
|
|
|
|
|
|
|
if (hideDirectoryControls) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
2026-05-20 19:30:10 +03:00
|
|
|
<div className="select-none flex-shrink-0 px-2.5 py-1">
|
|
|
|
|
<div className="flex h-auto min-h-8 flex-col gap-1">
|
|
|
|
|
<div className="flex h-8 items-center justify-between gap-2">
|
2026-07-28 12:04:39 +03:00
|
|
|
{/* Quiet toolbar under the New-session CTA: project/surface entry
|
|
|
|
|
points at left, list controls at right. ml-[3px] compensates the
|
|
|
|
|
icon inset inside the 24px buttons so the first glyph lines up
|
|
|
|
|
with the New-session icon above (16px from the sidebar edge). */}
|
|
|
|
|
<div className="ml-[3px] flex items-center gap-1.5">
|
2026-08-19 00:10:08 +03:00
|
|
|
<Tooltip delayDuration={500}>
|
2026-05-20 19:30:10 +03:00
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={handleOpenDirectoryDialog}
|
2026-07-28 12:04:39 +03:00
|
|
|
className={cn(headerActionButtonClass, 'text-muted-foreground hover:text-foreground hover:bg-transparent')}
|
2026-05-20 19:30:10 +03:00
|
|
|
aria-label={t('sessions.sidebar.header.actions.addProject')}
|
|
|
|
|
>
|
|
|
|
|
<Icon name="folder-add" className={headerActionIconClass} />
|
|
|
|
|
</button>
|
|
|
|
|
</TooltipTrigger>
|
|
|
|
|
<TooltipContent side="bottom" sideOffset={4}><p>{t('sessions.sidebar.header.actions.addProject')}</p></TooltipContent>
|
|
|
|
|
</Tooltip>
|
2026-03-06 17:22:59 +02:00
|
|
|
|
2026-08-19 00:10:08 +03:00
|
|
|
<Tooltip delayDuration={500}>
|
2026-05-28 01:13:03 +03:00
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
2026-07-28 12:04:39 +03:00
|
|
|
onClick={onOpenScheduled}
|
|
|
|
|
className={cn(headerActionButtonClass, 'text-muted-foreground hover:text-foreground hover:bg-transparent')}
|
|
|
|
|
aria-label={t('sessions.sidebar.header.actions.scheduledTasks')}
|
2026-05-28 01:13:03 +03:00
|
|
|
>
|
2026-07-28 12:04:39 +03:00
|
|
|
<Icon name="calendar-schedule" className={headerActionIconClass} />
|
2026-05-28 01:13:03 +03:00
|
|
|
</button>
|
|
|
|
|
</TooltipTrigger>
|
2026-07-28 12:04:39 +03:00
|
|
|
<TooltipContent side="bottom" sideOffset={4}><p>{t('sessions.sidebar.header.actions.scheduledTasks')}</p></TooltipContent>
|
2026-05-28 01:13:03 +03:00
|
|
|
</Tooltip>
|
2026-05-25 15:28:02 +03:00
|
|
|
|
2026-08-19 00:10:08 +03:00
|
|
|
<Tooltip delayDuration={500}>
|
2026-05-20 19:30:10 +03:00
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
2026-07-28 12:04:39 +03:00
|
|
|
onClick={onOpenMultiRun}
|
|
|
|
|
className={cn(headerActionButtonClass, 'text-muted-foreground hover:text-foreground hover:bg-transparent')}
|
2026-05-20 19:30:10 +03:00
|
|
|
aria-label={t('sessions.sidebar.header.actions.newMultiRun')}
|
|
|
|
|
disabled={!canOpenMultiRun}
|
|
|
|
|
>
|
|
|
|
|
<ArrowsMerge className={headerActionIconClass} />
|
|
|
|
|
</button>
|
|
|
|
|
</TooltipTrigger>
|
|
|
|
|
<TooltipContent side="bottom" sideOffset={4}><p>{t('sessions.sidebar.header.actions.newMultiRun')}</p></TooltipContent>
|
|
|
|
|
</Tooltip>
|
2026-04-16 15:55:08 +03:00
|
|
|
|
2026-08-19 00:10:08 +03:00
|
|
|
<Tooltip delayDuration={500}>
|
2026-05-20 19:30:10 +03:00
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
2026-07-28 12:04:39 +03:00
|
|
|
onClick={onOpenArchive}
|
|
|
|
|
className={cn(headerActionButtonClass, 'text-muted-foreground hover:text-foreground hover:bg-transparent')}
|
|
|
|
|
aria-label={t('sessions.sidebar.nav.archive')}
|
2026-05-20 19:30:10 +03:00
|
|
|
>
|
2026-07-28 12:04:39 +03:00
|
|
|
<Icon name="archive" className={headerActionIconClass} />
|
2026-05-20 19:30:10 +03:00
|
|
|
</button>
|
|
|
|
|
</TooltipTrigger>
|
2026-07-28 12:04:39 +03:00
|
|
|
<TooltipContent side="bottom" sideOffset={4}><p>{t('sessions.sidebar.nav.archive')}</p></TooltipContent>
|
2026-05-20 19:30:10 +03:00
|
|
|
</Tooltip>
|
|
|
|
|
</div>
|
2026-03-22 22:31:29 +02:00
|
|
|
|
2026-05-20 19:30:10 +03:00
|
|
|
<div className="flex items-center gap-1.5">
|
2026-08-19 00:10:08 +03:00
|
|
|
<Tooltip delayDuration={500}>
|
2026-05-20 19:30:10 +03:00
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => setIsSessionSearchOpen((prev) => !prev)}
|
2026-07-28 12:04:39 +03:00
|
|
|
className={cn(headerActionButtonClass, 'text-muted-foreground hover:text-foreground hover:bg-transparent')}
|
2026-05-20 19:30:10 +03:00
|
|
|
aria-label={t('sessions.sidebar.header.actions.searchSessions')}
|
|
|
|
|
aria-expanded={isSessionSearchOpen}
|
|
|
|
|
>
|
|
|
|
|
<Icon name="search" className={headerActionIconClass} />
|
|
|
|
|
</button>
|
|
|
|
|
</TooltipTrigger>
|
|
|
|
|
<TooltipContent side="bottom" sideOffset={4}><p>{t('sessions.sidebar.header.actions.searchSessions')}</p></TooltipContent>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
|
2026-08-19 00:10:08 +03:00
|
|
|
<Tooltip delayDuration={500}>
|
2026-05-20 19:30:10 +03:00
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={onToggleSelectionMode}
|
2026-07-28 12:04:39 +03:00
|
|
|
className={cn(headerActionButtonClass, 'text-muted-foreground hover:text-foreground hover:bg-transparent', selectionModeEnabled && 'bg-interactive-hover text-primary')}
|
2026-05-20 19:30:10 +03:00
|
|
|
aria-label={selectionModeEnabled
|
|
|
|
|
? t('sessions.sidebar.header.actions.exitSelection')
|
|
|
|
|
: t('sessions.sidebar.header.actions.selectSessions')}
|
|
|
|
|
aria-pressed={selectionModeEnabled}
|
|
|
|
|
>
|
|
|
|
|
<Icon name="checkbox-multiple" className={headerActionIconClass} />
|
|
|
|
|
</button>
|
|
|
|
|
</TooltipTrigger>
|
|
|
|
|
<TooltipContent side="bottom" sideOffset={4}>
|
|
|
|
|
<p>{selectionModeEnabled
|
|
|
|
|
? t('sessions.sidebar.header.actions.exitSelection')
|
|
|
|
|
: t('sessions.sidebar.header.actions.selectSessions')}</p>
|
|
|
|
|
</TooltipContent>
|
|
|
|
|
</Tooltip>
|
2026-03-06 17:22:59 +02:00
|
|
|
|
2026-07-11 22:43:57 +11:00
|
|
|
<DropdownMenu>
|
2026-08-19 00:10:08 +03:00
|
|
|
<Tooltip delayDuration={500}>
|
2026-07-11 22:43:57 +11:00
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<DropdownMenuTrigger asChild>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
2026-07-28 12:04:39 +03:00
|
|
|
className={cn(headerActionButtonClass, 'text-muted-foreground hover:text-foreground hover:bg-transparent')}
|
|
|
|
|
aria-label={t('sessions.sidebar.header.displayMode.label')}
|
2026-05-20 19:30:10 +03:00
|
|
|
>
|
|
|
|
|
<Icon name="equalizer-2" className={headerActionIconClass} />
|
|
|
|
|
</button>
|
|
|
|
|
</DropdownMenuTrigger>
|
2026-04-20 23:32:32 +03:00
|
|
|
</TooltipTrigger>
|
2026-05-20 19:30:10 +03:00
|
|
|
<TooltipContent side="bottom" sideOffset={4}><p>{t('sessions.sidebar.header.displayMode.label')}</p></TooltipContent>
|
2026-04-20 23:32:32 +03:00
|
|
|
</Tooltip>
|
2026-07-28 12:04:39 +03:00
|
|
|
<DropdownMenuContent align="end" className="min-w-[180px]">
|
|
|
|
|
<DropdownMenuLabel>{t('sessions.sidebar.header.actions.sortProjects')}</DropdownMenuLabel>
|
|
|
|
|
{([
|
|
|
|
|
['manual', 'sessions.sidebar.header.projectSort.manual'],
|
|
|
|
|
['a-z', 'sessions.sidebar.header.projectSort.aToZ'],
|
|
|
|
|
['z-a', 'sessions.sidebar.header.projectSort.zToA'],
|
|
|
|
|
['date-added', 'sessions.sidebar.header.projectSort.dateAdded'],
|
|
|
|
|
['recent', 'sessions.sidebar.header.projectSort.recent'],
|
|
|
|
|
] as const).map(([order, labelKey]) => (
|
|
|
|
|
<DropdownMenuItem
|
|
|
|
|
key={order}
|
|
|
|
|
onClick={() => setProjectSortOrder(order)}
|
|
|
|
|
className="flex items-center justify-between"
|
|
|
|
|
>
|
|
|
|
|
<span>{t(labelKey)}</span>
|
|
|
|
|
{projectSortOrder === order ? <Icon name="check" className="h-4 w-4 text-primary" /> : null}
|
|
|
|
|
</DropdownMenuItem>
|
|
|
|
|
))}
|
|
|
|
|
<DropdownMenuSeparator />
|
|
|
|
|
<DropdownMenuLabel>{t('sessions.sidebar.header.grouping.label')}</DropdownMenuLabel>
|
|
|
|
|
{([
|
|
|
|
|
['by-worktree', 'sessions.sidebar.header.grouping.byWorktree'],
|
|
|
|
|
['flat', 'sessions.sidebar.header.grouping.flat'],
|
|
|
|
|
] as const).map(([mode, labelKey]) => (
|
|
|
|
|
<DropdownMenuItem
|
|
|
|
|
key={mode}
|
|
|
|
|
onClick={() => setSessionGroupingMode(mode)}
|
|
|
|
|
className="flex items-center justify-between"
|
|
|
|
|
>
|
|
|
|
|
<span>{t(labelKey)}</span>
|
|
|
|
|
{sessionGroupingMode === mode ? <Icon name="check" className="h-4 w-4 text-primary" /> : null}
|
|
|
|
|
</DropdownMenuItem>
|
|
|
|
|
))}
|
|
|
|
|
<DropdownMenuSeparator />
|
2026-05-28 01:13:03 +03:00
|
|
|
{showRecentControls ? (
|
2026-07-28 12:04:39 +03:00
|
|
|
<DropdownMenuItem
|
|
|
|
|
onClick={toggleRecentSection}
|
|
|
|
|
className="flex items-center justify-between"
|
|
|
|
|
>
|
|
|
|
|
<span>{t('sessions.sidebar.header.displayMode.showRecent')}</span>
|
|
|
|
|
{showRecentSection ? <Icon name="check" className="h-4 w-4 text-primary" /> : null}
|
|
|
|
|
</DropdownMenuItem>
|
2026-05-28 01:13:03 +03:00
|
|
|
) : null}
|
2026-07-28 12:04:39 +03:00
|
|
|
<DropdownMenuItem
|
|
|
|
|
onClick={toggleStickyZoneHeaders}
|
|
|
|
|
className="flex items-center justify-between"
|
|
|
|
|
>
|
|
|
|
|
<span>{t('sessions.sidebar.header.displayMode.stickyHeaders')}</span>
|
|
|
|
|
{stickyZoneHeaders ? <Icon name="check" className="h-4 w-4 text-primary" /> : null}
|
|
|
|
|
</DropdownMenuItem>
|
2026-05-20 19:30:10 +03:00
|
|
|
<DropdownMenuSeparator />
|
|
|
|
|
<DropdownMenuItem onClick={collapseAllProjects} className="flex items-center gap-2">
|
|
|
|
|
<Icon name="contract-up-down" className="h-4 w-4" />
|
|
|
|
|
<span>{t('sessions.sidebar.header.displayMode.collapseAll')}</span>
|
|
|
|
|
</DropdownMenuItem>
|
|
|
|
|
<DropdownMenuItem onClick={expandAllProjects} className="flex items-center gap-2">
|
|
|
|
|
<Icon name="expand-up-down" className="h-4 w-4" />
|
|
|
|
|
<span>{t('sessions.sidebar.header.displayMode.expandAll')}</span>
|
|
|
|
|
</DropdownMenuItem>
|
|
|
|
|
</DropdownMenuContent>
|
|
|
|
|
</DropdownMenu>
|
2026-03-20 01:01:03 +02:00
|
|
|
</div>
|
2026-05-20 19:30:10 +03:00
|
|
|
</div>
|
2026-03-06 17:22:59 +02:00
|
|
|
|
2026-05-20 19:30:10 +03:00
|
|
|
{isSessionSearchOpen ? (
|
|
|
|
|
<div className="pb-1">
|
|
|
|
|
<div className="mb-1 flex items-center justify-between px-0.5 typography-micro text-muted-foreground/80">
|
|
|
|
|
{hasSessionSearchQuery ? (
|
|
|
|
|
<span>{searchMatchCount === 1
|
|
|
|
|
? t('sessions.sidebar.header.search.matchCountSingle', { count: searchMatchCount })
|
|
|
|
|
: t('sessions.sidebar.header.search.matchCountPlural', { count: searchMatchCount })}</span>
|
|
|
|
|
) : <span />}
|
|
|
|
|
<span>{t('sessions.sidebar.header.search.escapeHint')}</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="relative">
|
|
|
|
|
<Icon name="search" className="pointer-events-none absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
|
|
|
|
|
<input
|
|
|
|
|
ref={sessionSearchInputRef}
|
|
|
|
|
value={sessionSearchQuery}
|
|
|
|
|
onChange={(event) => setSessionSearchQuery(event.target.value)}
|
|
|
|
|
placeholder={t('sessions.sidebar.header.search.placeholder')}
|
|
|
|
|
className="h-8 w-full rounded-md border border-border bg-transparent pl-8 pr-8 typography-ui-label text-foreground outline-none focus-visible:ring-2 focus-visible:ring-primary/50"
|
|
|
|
|
onKeyDown={(event) => {
|
|
|
|
|
if (event.key === 'Escape') {
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
if (hasSessionSearchQuery) {
|
|
|
|
|
setSessionSearchQuery('');
|
|
|
|
|
} else {
|
|
|
|
|
setIsSessionSearchOpen(false);
|
2026-03-20 01:01:03 +02:00
|
|
|
}
|
2026-05-20 19:30:10 +03:00
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
{sessionSearchQuery.length > 0 ? (
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => setSessionSearchQuery('')}
|
|
|
|
|
className="absolute right-1 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50"
|
|
|
|
|
aria-label={t('sessions.sidebar.header.search.clear')}
|
|
|
|
|
>
|
|
|
|
|
<Icon name="close" className="h-3.5 w-3.5" />
|
|
|
|
|
</button>
|
|
|
|
|
) : null}
|
2026-03-20 01:01:03 +02:00
|
|
|
</div>
|
2026-05-20 19:30:10 +03:00
|
|
|
</div>
|
|
|
|
|
) : null}
|
|
|
|
|
</div>
|
2026-03-06 17:22:59 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|