* Group settings navigation menu Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Revert "Group settings navigation menu" This reverts commit 5983a4e82074b8dab1084af1cadd803ba28ea65d. * Standardize settings layout feedback Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Fix settings save status timer typing Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Retain settings save status Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Report color mode save state Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Match Appearance settings to two-column layout Rebuild Appearance into Color mode & Theme, Localization, and Density & type sections with responsive two-column grids, consistent section headers, page description, and green save status. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Migrate settings pages to SettingsPageLayout and SettingsSection Replace ScrollableOverlay/max-w-3xl shells with the shared settings layout primitives across entity and static settings pages, normalize section headers, and add settings.page.behavior.description locales. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Unify remaining settings pages on shared section chrome Wire Appearance, Projects, and Remote Instances through SettingsSection/SettingsPageLayout so every settings surface shares the same header, divider, and page shell treatment. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Align settings UI with OpenChamber design system kit Apply kit geometry and control specs: 840px content width, 32/48 padding, fixed 260/280 sidebars, radius/spacing tokens, settings select height, stepper dimensions, and shared field/link typography. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Migrate OpenChamberVisualSettings to shared settings primitives Replace ad-hoc radio/checkbox/chip/field layouts with SettingsSection shared chrome for Appearance, Density, Navigation, Chat/behavior, and Privacy while preserving handlers and data-settings-item anchors. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Migrate settings pages to shared field/checkbox/radio primitives Unify Defaults, Notifications, Behavior, Git, Session Retention, Passkeys, OpenCode CLI, Commands, About, Keyboard Shortcuts, and Desktop Network on SettingsFieldRow / SettingsCheckboxRow / SettingsRadioGroup / SettingsChipGroup for consistent grid, spacing, and DRY layout. Also remove the GitPage double SettingsSection wrap around GitHubSettings. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Unify remaining settings pages onto shared field primitives Migrate Agents, Snippets, Skills, Usage, MCP identity rows and selects to SettingsFieldRow/CheckboxRow/ChipGroup and SETTINGS_SELECT_*; align page titles; light-touch Voice/Tunnel/Providers/Plugins without rewriting complex OAuth, permissions, or tunnel flows. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Polish settings section dividers and transport helper text Slightly stronger section borders for clearer group separation, and keep message-stream transport description under the chip control. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Fix settings grid alignment, control heights, and Chat section titles Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Tighten settings grid: flat Chat 2x2 and full-width stacked selects Message options use a flat two-column grid so row headers share a baseline. Stacked selects fill their column; field-row selects keep a fixed sm:w-56 width. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Align mixed settings controls to shared FieldRow/CheckboxRow grid Separate FieldRows from CheckboxRows with SettingsInset, move enum radios into ControlGroups, and convert misplaced StackedFields to full-width FieldRows so left edges no longer clash. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Translate Behavior response-style preset labels for es and pl Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Group settings nav into categories and improve icons/order Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Fix settings layout: fewer hrs, shared control widths, chat transport section Remove SettingsInset top borders, align App install/Density controls to full cluster width, give Message Stream Transport its own Chat section, and fold Sessions Small Model into the first section to cut extra dividers. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Align Voice and MCP settings labels with shared heading classes Swap form field labels to SETTINGS_FIELD_LABEL_CLASS and use SettingsGroupTitle for MCP control-group headings (manual auth fallback, request headers). Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Differentiate settings heading levels by context Page titles are larger and quieter than section titles; group and field labels use dedicated shared classes so hierarchy is consistent across settings surfaces without ad-hoc typography mixes. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Use shared settings title classes in SettingsView home Wire home and unavailable headings through the shared L1/L2 class constants so they stay aligned with SettingsPageLayout. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Keep settings number steppers from stretching +/- buttons Density & type NumberInputs no longer flex-grow across the row, and NumberInput locks minus/plus to fixed width so the plus side cannot inflate when the control is placed in a full-width cluster. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Place spacing and input-bar offset on their own row Density & type now lays out as font families, then font sizes, then Spacing Density / Input Bar Offset on the row below. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Regroup settings nav and improve Voice layout Drop Advanced/Usage/Git nav categories: Voice and About under Interface, Usage under OpenCode, Git under Workspace. Voice provider chips and STT model cards use shared settings primitives with roomier spacing and a two-column model grid. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Space out chat feature groups in visual settings * Polish settings: save-state wiring, container-query layouts, unified dropdown triggers - Wire shared save indicator into Behavior page saves and git identity CRUD - Convert settings layout primitives and page rows from viewport to container queries so narrow panes stack instead of clipping - Unify custom dropdown triggers (model/agent/provider pickers) and remaining page selects on the settings control size - Bump global radius scale by 1px; align variant input with select size - Migrate stray raw controls (MCP OAuth checkbox, worktree remove button, git identity dialog rows, skills dialog labels) onto shared primitives - Make settings nav items span full sidebar width; trim nav to 240px * Add General settings page, regroup nav, cap control widths, promote chat feature headers * Mobile settings nav: plain background and touch-sized rows * Hide secondary settings descriptions behind clickable info hints * Move quota credentials to Usage, navigation settings to General, rename External Tunnel * Quiet settings save indicator: silent success, delayed spinner, visible errors * Rewrite settings-ui-patterns skill around shared primitives and refactored conventions * Remove settings starter page; open last visited page, defaulting to General * Settings polish: spacing, control sizes, trigger widths, readable model names, device dates * Centralize dropdown trigger chrome, settings nav polish, mobile-only input bar offset * Fix global line-height regression, auto-hide first-section divider, shortcut row spacing * Global line-height 1.45, align scheduled tasks header button with select * Hide editor toolbar and About in VS Code, animate chat render preview outside desktop dialog * Rebuild agent tool permissions on source-of-truth model Edit the agent's own permission map verbatim (inherit vs explicit actions, pattern rules only for pattern-capable keys), save permission-only, drop the server-side non-wildcard re-merge that resurrected deleted rules, and surface session-granted rules as read-only. * Agents model parameters polish: row spacing, variant dropdown, unified widths, dash for unset numbers --------- Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> Co-authored-by: Bohdan Triapitsyn <artmore@protonmail.com>
478 lines
17 KiB
TypeScript
478 lines
17 KiB
TypeScript
import React from 'react';
|
|
import { Button } from '@/components/ui/button';
|
|
import { Input } from '@/components/ui/input';
|
|
import { toast } from '@/components/ui';
|
|
import { isMobileDeviceViaCSS } from '@/lib/device';
|
|
import {
|
|
Dialog,
|
|
DialogContent,
|
|
DialogDescription,
|
|
DialogFooter,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
} from '@/components/ui/dialog';
|
|
import {
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuTrigger,
|
|
} from '@/components/ui/dropdown-menu';
|
|
import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuTrigger } from '@/components/ui/context-menu';
|
|
import { useCommandsStore, isCommandBuiltIn, type Command } from '@/stores/useCommandsStore';
|
|
import { useSkillsStore } from '@/stores/useSkillsStore';
|
|
import { useShallow } from 'zustand/react/shallow';
|
|
import { ScrollableOverlay } from '@/components/ui/ScrollableOverlay';
|
|
import { cn } from '@/lib/utils';
|
|
import { SettingsProjectSelector } from '@/components/sections/shared/SettingsProjectSelector';
|
|
import { Icon } from "@/components/icon/Icon";
|
|
import { useI18n } from '@/lib/i18n';
|
|
import { SETTINGS_PANEL_TITLE_CLASS } from '@/components/sections/shared/SettingsSection';
|
|
|
|
interface CommandsSidebarProps {
|
|
onItemSelect?: () => void;
|
|
}
|
|
|
|
export const CommandsSidebar: React.FC<CommandsSidebarProps> = ({ onItemSelect }) => {
|
|
const { t } = useI18n();
|
|
const [renameDialogCommand, setRenameDialogCommand] = React.useState<Command | null>(null);
|
|
const [renameNewName, setRenameNewName] = React.useState('');
|
|
const [confirmActionCommand, setConfirmActionCommand] = React.useState<Command | null>(null);
|
|
const [confirmActionType, setConfirmActionType] = React.useState<'delete' | 'reset' | null>(null);
|
|
const [isConfirmActionPending, setIsConfirmActionPending] = React.useState(false);
|
|
const [openMenuCommand, setOpenMenuCommand] = React.useState<string | null>(null);
|
|
|
|
const {
|
|
selectedCommandName,
|
|
commands,
|
|
setSelectedCommand,
|
|
setCommandDraft,
|
|
createCommand,
|
|
deleteCommand,
|
|
loadCommands,
|
|
} = useCommandsStore(useShallow((s) => ({
|
|
selectedCommandName: s.selectedCommandName,
|
|
commands: s.commands,
|
|
setSelectedCommand: s.setSelectedCommand,
|
|
setCommandDraft: s.setCommandDraft,
|
|
createCommand: s.createCommand,
|
|
deleteCommand: s.deleteCommand,
|
|
loadCommands: s.loadCommands,
|
|
})));
|
|
const skills = useSkillsStore((s) => s.skills);
|
|
const loadSkills = useSkillsStore((s) => s.loadSkills);
|
|
|
|
React.useEffect(() => {
|
|
loadCommands();
|
|
loadSkills();
|
|
}, [loadCommands, loadSkills]);
|
|
|
|
const skillNames = React.useMemo(() => new Set(skills.map((skill) => skill.name)), [skills]);
|
|
const commandOnlyItems = React.useMemo(
|
|
() => commands.filter((command) => !skillNames.has(command.name)),
|
|
[commands, skillNames],
|
|
);
|
|
|
|
React.useEffect(() => {
|
|
if (!selectedCommandName) {
|
|
return;
|
|
}
|
|
|
|
if (skillNames.has(selectedCommandName)) {
|
|
setSelectedCommand(null);
|
|
}
|
|
}, [selectedCommandName, setSelectedCommand, skillNames]);
|
|
|
|
const bgClass = 'bg-background';
|
|
|
|
const handleCreateNew = () => {
|
|
// Generate unique name
|
|
const baseName = 'new-command';
|
|
let newName = baseName;
|
|
let counter = 1;
|
|
while (commands.some((c) => c.name === newName)) {
|
|
newName = `${baseName}-${counter}`;
|
|
counter++;
|
|
}
|
|
|
|
// Set draft and open the page for editing
|
|
setCommandDraft({ name: newName, scope: 'user' });
|
|
setSelectedCommand(newName);
|
|
onItemSelect?.();
|
|
|
|
};
|
|
|
|
const handleDeleteCommand = async (command: Command) => {
|
|
if (isCommandBuiltIn(command)) {
|
|
toast.error(t('settings.commands.sidebar.toast.builtInCannotDelete'));
|
|
return;
|
|
}
|
|
|
|
setConfirmActionCommand(command);
|
|
setConfirmActionType('delete');
|
|
};
|
|
|
|
const handleResetCommand = async (command: Command) => {
|
|
if (!isCommandBuiltIn(command)) {
|
|
return;
|
|
}
|
|
|
|
setConfirmActionCommand(command);
|
|
setConfirmActionType('reset');
|
|
};
|
|
|
|
const closeConfirmActionDialog = () => {
|
|
setConfirmActionCommand(null);
|
|
setConfirmActionType(null);
|
|
};
|
|
|
|
const handleConfirmAction = async () => {
|
|
if (!confirmActionCommand || !confirmActionType) {
|
|
return;
|
|
}
|
|
|
|
setIsConfirmActionPending(true);
|
|
const success = await deleteCommand(confirmActionCommand.name);
|
|
|
|
if (success) {
|
|
if (confirmActionType === 'delete') {
|
|
toast.success(t('settings.commands.sidebar.toast.commandDeleted', { name: confirmActionCommand.name }));
|
|
} else {
|
|
toast.success(t('settings.commands.sidebar.toast.commandReset', { name: confirmActionCommand.name }));
|
|
}
|
|
closeConfirmActionDialog();
|
|
} else if (confirmActionType === 'delete') {
|
|
toast.error(t('settings.commands.sidebar.toast.deleteFailed'));
|
|
} else {
|
|
toast.error(t('settings.commands.sidebar.toast.resetFailed'));
|
|
}
|
|
|
|
setIsConfirmActionPending(false);
|
|
};
|
|
|
|
const handleDuplicateCommand = (command: Command) => {
|
|
const baseName = command.name;
|
|
let copyNumber = 1;
|
|
let newName = `${baseName}-copy`;
|
|
|
|
while (commands.some((c) => c.name === newName)) {
|
|
copyNumber++;
|
|
newName = `${baseName}-copy-${copyNumber}`;
|
|
}
|
|
|
|
// Set draft with prefilled values from source command
|
|
setCommandDraft({
|
|
name: newName,
|
|
scope: command.scope || 'user',
|
|
description: command.description,
|
|
template: command.template,
|
|
agent: command.agent,
|
|
model: command.model,
|
|
});
|
|
setSelectedCommand(newName);
|
|
|
|
};
|
|
|
|
const handleOpenRenameDialog = (command: Command) => {
|
|
setRenameNewName(command.name);
|
|
setRenameDialogCommand(command);
|
|
};
|
|
|
|
const handleRenameCommand = async () => {
|
|
if (!renameDialogCommand) return;
|
|
|
|
const sanitizedName = renameNewName.trim().replace(/\s+/g, '-');
|
|
|
|
if (!sanitizedName) {
|
|
toast.error(t('settings.commands.sidebar.toast.commandNameRequired'));
|
|
return;
|
|
}
|
|
|
|
if (sanitizedName === renameDialogCommand.name) {
|
|
setRenameDialogCommand(null);
|
|
return;
|
|
}
|
|
|
|
if (commands.some((cmd) => cmd.name === sanitizedName)) {
|
|
toast.error(t('settings.commands.sidebar.toast.commandExists'));
|
|
return;
|
|
}
|
|
|
|
// Create new command with new name and all existing config
|
|
const success = await createCommand({
|
|
name: sanitizedName,
|
|
description: renameDialogCommand.description,
|
|
template: renameDialogCommand.template,
|
|
agent: renameDialogCommand.agent,
|
|
model: renameDialogCommand.model,
|
|
});
|
|
|
|
if (success) {
|
|
// Delete old command
|
|
const deleteSuccess = await deleteCommand(renameDialogCommand.name);
|
|
if (deleteSuccess) {
|
|
toast.success(`Command renamed to "${sanitizedName}"`);
|
|
setSelectedCommand(sanitizedName);
|
|
} else {
|
|
toast.error(t('settings.commands.sidebar.toast.removeOldAfterRenameFailed'));
|
|
}
|
|
} else {
|
|
toast.error(t('settings.commands.sidebar.toast.renameFailed'));
|
|
}
|
|
|
|
setRenameDialogCommand(null);
|
|
};
|
|
|
|
const builtInCommands = commandOnlyItems.filter(isCommandBuiltIn);
|
|
const customCommands = commandOnlyItems.filter((cmd) => !isCommandBuiltIn(cmd));
|
|
|
|
return (
|
|
<div className={cn('flex h-full flex-col', bgClass)}>
|
|
<div className="border-b px-3 pt-4 pb-3">
|
|
<h2 className={`${SETTINGS_PANEL_TITLE_CLASS} mb-3`}>{t('settings.commands.sidebar.title')}</h2>
|
|
<SettingsProjectSelector className="mb-3" />
|
|
<div className="flex items-center justify-between gap-2">
|
|
<span className="typography-meta text-muted-foreground">{t('settings.commands.sidebar.total', { count: commandOnlyItems.length })}</span>
|
|
<Button size="sm"
|
|
data-settings-item="commands.create"
|
|
variant="ghost"
|
|
className="h-7 w-7 px-0 -my-1 text-muted-foreground"
|
|
onClick={handleCreateNew}
|
|
>
|
|
<Icon name="add" className="h-3.5 w-3.5" />
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
|
|
<ScrollableOverlay outerClassName="flex-1 min-h-0" className="space-y-1 px-3 py-2">
|
|
{commandOnlyItems.length === 0 ? (
|
|
<div className="py-12 px-4 text-center text-muted-foreground">
|
|
<Icon name="terminal-box" className="mx-auto mb-3 h-10 w-10 opacity-50" />
|
|
<p className="typography-ui-label font-medium">{t('settings.commands.sidebar.empty.title')}</p>
|
|
<p className="typography-meta mt-1 opacity-75">{t('settings.commands.sidebar.empty.description')}</p>
|
|
</div>
|
|
) : (
|
|
<>
|
|
{builtInCommands.length > 0 && (
|
|
<>
|
|
<div className="px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground">
|
|
{t('settings.commands.sidebar.section.builtIn')}
|
|
</div>
|
|
{[...builtInCommands].sort((a, b) => a.name.localeCompare(b.name)).map((command) => (
|
|
<CommandListItem
|
|
key={command.name}
|
|
command={command}
|
|
isSelected={selectedCommandName === command.name}
|
|
onSelect={() => {
|
|
setSelectedCommand(command.name);
|
|
onItemSelect?.();
|
|
|
|
}}
|
|
onReset={() => handleResetCommand(command)}
|
|
onDuplicate={() => handleDuplicateCommand(command)}
|
|
isMenuOpen={openMenuCommand === command.name}
|
|
onMenuOpenChange={(open) => setOpenMenuCommand(open ? command.name : null)}
|
|
/>
|
|
))}
|
|
</>
|
|
)}
|
|
|
|
{customCommands.length > 0 && (
|
|
<>
|
|
<div className="px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground">
|
|
{t('settings.commands.sidebar.section.custom')}
|
|
</div>
|
|
{[...customCommands].sort((a, b) => a.name.localeCompare(b.name)).map((command) => (
|
|
<CommandListItem
|
|
key={command.name}
|
|
command={command}
|
|
isSelected={selectedCommandName === command.name}
|
|
onSelect={() => {
|
|
setSelectedCommand(command.name);
|
|
onItemSelect?.();
|
|
|
|
}}
|
|
onRename={() => handleOpenRenameDialog(command)}
|
|
onDelete={() => handleDeleteCommand(command)}
|
|
onDuplicate={() => handleDuplicateCommand(command)}
|
|
isMenuOpen={openMenuCommand === command.name}
|
|
onMenuOpenChange={(open) => setOpenMenuCommand(open ? command.name : null)}
|
|
/>
|
|
))}
|
|
</>
|
|
)}
|
|
</>
|
|
)}
|
|
</ScrollableOverlay>
|
|
|
|
<Dialog
|
|
open={confirmActionCommand !== null && confirmActionType !== null}
|
|
onOpenChange={(open) => {
|
|
if (!open && !isConfirmActionPending) {
|
|
closeConfirmActionDialog();
|
|
}
|
|
}}
|
|
>
|
|
<DialogContent className="max-w-md">
|
|
<DialogHeader>
|
|
<DialogTitle>{confirmActionType === 'delete' ? t('settings.commands.sidebar.dialog.deleteTitle') : t('settings.commands.sidebar.dialog.resetTitle')}</DialogTitle>
|
|
<DialogDescription>
|
|
{confirmActionType === 'delete'
|
|
? t('settings.commands.sidebar.dialog.deleteDescription', { name: confirmActionCommand?.name ?? '' })
|
|
: t('settings.commands.sidebar.dialog.resetDescription', { name: confirmActionCommand?.name ?? '' })}
|
|
</DialogDescription>
|
|
</DialogHeader>
|
|
<DialogFooter>
|
|
<Button
|
|
size="sm"
|
|
variant="ghost"
|
|
onClick={closeConfirmActionDialog}
|
|
disabled={isConfirmActionPending}
|
|
>
|
|
{t('settings.common.actions.cancel')}
|
|
</Button>
|
|
<Button size="sm" onClick={handleConfirmAction} disabled={isConfirmActionPending}>
|
|
{confirmActionType === 'delete' ? t('settings.common.actions.delete') : t('settings.common.actions.reset')}
|
|
</Button>
|
|
</DialogFooter>
|
|
</DialogContent>
|
|
</Dialog>
|
|
|
|
{/* Rename Dialog */}
|
|
<Dialog open={renameDialogCommand !== null} onOpenChange={(open) => !open && setRenameDialogCommand(null)}>
|
|
<DialogContent>
|
|
<DialogHeader>
|
|
<DialogTitle>{t('settings.commands.sidebar.renameDialog.title')}</DialogTitle>
|
|
<DialogDescription>
|
|
{t('settings.commands.sidebar.renameDialog.description', { name: renameDialogCommand?.name ?? '' })}
|
|
</DialogDescription>
|
|
</DialogHeader>
|
|
<Input
|
|
value={renameNewName}
|
|
onChange={(e) => setRenameNewName(e.target.value)}
|
|
placeholder={t('settings.commands.sidebar.renameDialog.placeholder')}
|
|
className="text-foreground placeholder:text-muted-foreground"
|
|
onKeyDown={(e) => {
|
|
if (e.key === 'Enter') {
|
|
handleRenameCommand();
|
|
}
|
|
}}
|
|
/>
|
|
<DialogFooter>
|
|
<Button
|
|
size="sm"
|
|
variant="ghost"
|
|
onClick={() => setRenameDialogCommand(null)}
|
|
>
|
|
{t('settings.common.actions.cancel')}
|
|
</Button>
|
|
<Button size="sm" onClick={handleRenameCommand}>
|
|
{t('settings.common.actions.rename')}
|
|
</Button>
|
|
</DialogFooter>
|
|
</DialogContent>
|
|
</Dialog>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
interface CommandListItemProps {
|
|
command: Command;
|
|
isSelected: boolean;
|
|
onSelect: () => void;
|
|
onDelete?: () => void;
|
|
onReset?: () => void;
|
|
onRename?: () => void;
|
|
onDuplicate: () => void;
|
|
isMenuOpen: boolean;
|
|
onMenuOpenChange: (open: boolean) => void;
|
|
}
|
|
|
|
const CommandListItem: React.FC<CommandListItemProps> = ({
|
|
command,
|
|
isSelected,
|
|
onSelect,
|
|
onDelete,
|
|
onReset,
|
|
onRename,
|
|
onDuplicate,
|
|
isMenuOpen,
|
|
onMenuOpenChange,
|
|
}) => {
|
|
const { t } = useI18n();
|
|
const isMobile = isMobileDeviceViaCSS();
|
|
const [isContextMenuOpen, setIsContextMenuOpen] = React.useState(false);
|
|
const renderMenuItems = (Item: React.ElementType) => (
|
|
<>
|
|
{onRename && (
|
|
<Item onClick={(e: React.MouseEvent) => { e.stopPropagation(); onRename(); }}>
|
|
<Icon name="edit" className="h-4 w-4 mr-px" />
|
|
{t('settings.common.actions.rename')}
|
|
</Item>
|
|
)}
|
|
<Item onClick={(e: React.MouseEvent) => { e.stopPropagation(); onDuplicate(); }}>
|
|
<Icon name="file-copy" className="h-4 w-4 mr-px" />
|
|
{t('settings.common.actions.duplicate')}
|
|
</Item>
|
|
{onReset && (
|
|
<Item onClick={(e: React.MouseEvent) => { e.stopPropagation(); onReset(); }}>
|
|
<Icon name="restart" className="h-4 w-4 mr-px" />
|
|
{t('settings.common.actions.reset')}
|
|
</Item>
|
|
)}
|
|
{onDelete && (
|
|
<Item onClick={(e: React.MouseEvent) => { e.stopPropagation(); onDelete(); }} className="text-destructive focus:text-destructive">
|
|
<Icon name="delete-bin" className="h-4 w-4 mr-px" />
|
|
{t('settings.common.actions.delete')}
|
|
</Item>
|
|
)}
|
|
</>
|
|
);
|
|
return (
|
|
<ContextMenu open={isContextMenuOpen} onOpenChange={setIsContextMenuOpen}>
|
|
<ContextMenuTrigger render={<div className={cn('group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none', isSelected ? 'bg-interactive-selection' : 'hover:bg-interactive-hover')} onContextMenu={!isMobile ? (e) => { e.preventDefault(); setIsContextMenuOpen(true); } : undefined} />}>
|
|
<div className="flex min-w-0 flex-1 items-center">
|
|
<button
|
|
onClick={onSelect}
|
|
className="flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50"
|
|
tabIndex={0}
|
|
>
|
|
<div className="flex items-center gap-2">
|
|
<span className="typography-ui-label font-normal truncate text-foreground">
|
|
/{command.name}
|
|
</span>
|
|
{(command.scope || isCommandBuiltIn(command)) && (
|
|
<span className="typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50">
|
|
{isCommandBuiltIn(command) ? t('settings.agents.sidebar.badge.system') : command.scope}
|
|
</span>
|
|
)}
|
|
</div>
|
|
|
|
{command.description && (
|
|
<div className="typography-micro text-muted-foreground/60 truncate leading-tight">
|
|
{command.description}
|
|
</div>
|
|
)}
|
|
</button>
|
|
|
|
<DropdownMenu open={isMenuOpen} onOpenChange={(open) => { if (open) setIsContextMenuOpen(false); onMenuOpenChange(open); }}>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button size="sm"
|
|
variant="ghost"
|
|
className="h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100"
|
|
>
|
|
<Icon name="more-2" className="h-3.5 w-3.5" />
|
|
</Button>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent align="end" className="w-fit min-w-20">
|
|
{renderMenuItems(DropdownMenuItem)}
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
</div>
|
|
</ContextMenuTrigger>
|
|
<ContextMenuContent className="w-fit min-w-20">
|
|
{renderMenuItems(ContextMenuItem)}
|
|
</ContextMenuContent>
|
|
</ContextMenu>
|
|
);
|
|
};
|