2025-12-07 19:32:53 +02:00
|
|
|
import React from 'react';
|
2026-03-20 01:01:03 +02:00
|
|
|
import { Button } from '@/components/ui/button';
|
2025-12-07 19:32:53 +02:00
|
|
|
import { Input } from '@/components/ui/input';
|
2026-01-19 02:50:40 +02:00
|
|
|
import { toast } from '@/components/ui';
|
2026-02-24 03:28:30 +02:00
|
|
|
import { isMobileDeviceViaCSS } from '@/lib/device';
|
2025-12-07 19:32:53 +02:00
|
|
|
import {
|
|
|
|
|
Dialog,
|
|
|
|
|
DialogContent,
|
|
|
|
|
DialogDescription,
|
|
|
|
|
DialogFooter,
|
|
|
|
|
DialogHeader,
|
|
|
|
|
DialogTitle,
|
|
|
|
|
} from '@/components/ui/dialog';
|
|
|
|
|
import {
|
|
|
|
|
DropdownMenu,
|
|
|
|
|
DropdownMenuContent,
|
|
|
|
|
DropdownMenuItem,
|
|
|
|
|
DropdownMenuTrigger,
|
|
|
|
|
} from '@/components/ui/dropdown-menu';
|
2025-12-29 17:48:06 +02:00
|
|
|
import { RiAddLine, RiTerminalBoxLine, RiMore2Line, RiDeleteBinLine, RiFileCopyLine, RiRestartLine, RiEditLine } from '@remixicon/react';
|
|
|
|
|
import { useCommandsStore, isCommandBuiltIn, type Command } from '@/stores/useCommandsStore';
|
2026-02-18 20:08:42 +02:00
|
|
|
import { useSkillsStore } from '@/stores/useSkillsStore';
|
2026-04-26 16:24:07 +03:00
|
|
|
import { useShallow } from 'zustand/react/shallow';
|
2025-12-07 19:32:53 +02:00
|
|
|
import { ScrollableOverlay } from '@/components/ui/ScrollableOverlay';
|
|
|
|
|
import { cn } from '@/lib/utils';
|
2026-02-24 03:28:30 +02:00
|
|
|
import { SettingsProjectSelector } from '@/components/sections/shared/SettingsProjectSelector';
|
2026-04-26 14:03:39 +03:00
|
|
|
import { useI18n } from '@/lib/i18n';
|
2025-12-07 19:32:53 +02:00
|
|
|
|
2025-12-28 02:17:09 +02:00
|
|
|
interface CommandsSidebarProps {
|
|
|
|
|
onItemSelect?: () => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const CommandsSidebar: React.FC<CommandsSidebarProps> = ({ onItemSelect }) => {
|
2026-04-26 14:03:39 +03:00
|
|
|
const { t } = useI18n();
|
2025-12-29 17:48:06 +02:00
|
|
|
const [renameDialogCommand, setRenameDialogCommand] = React.useState<Command | null>(null);
|
|
|
|
|
const [renameNewName, setRenameNewName] = React.useState('');
|
2026-02-10 00:27:17 +02:00
|
|
|
const [confirmActionCommand, setConfirmActionCommand] = React.useState<Command | null>(null);
|
|
|
|
|
const [confirmActionType, setConfirmActionType] = React.useState<'delete' | 'reset' | null>(null);
|
|
|
|
|
const [isConfirmActionPending, setIsConfirmActionPending] = React.useState(false);
|
2026-02-24 03:28:30 +02:00
|
|
|
const [openMenuCommand, setOpenMenuCommand] = React.useState<string | null>(null);
|
2025-12-07 19:32:53 +02:00
|
|
|
|
|
|
|
|
const {
|
|
|
|
|
selectedCommandName,
|
|
|
|
|
commands,
|
|
|
|
|
setSelectedCommand,
|
2025-12-29 17:48:06 +02:00
|
|
|
setCommandDraft,
|
|
|
|
|
createCommand,
|
2025-12-07 19:32:53 +02:00
|
|
|
deleteCommand,
|
|
|
|
|
loadCommands,
|
2026-04-26 16:24:07 +03:00
|
|
|
} = 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);
|
2025-12-07 19:32:53 +02:00
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
|
loadCommands();
|
2026-02-18 20:08:42 +02:00
|
|
|
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]);
|
2025-12-07 19:32:53 +02:00
|
|
|
|
2026-02-24 03:28:30 +02:00
|
|
|
const bgClass = 'bg-background';
|
2025-12-28 03:28:13 +02:00
|
|
|
|
2025-12-29 17:48:06 +02:00
|
|
|
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++;
|
2025-12-07 19:32:53 +02:00
|
|
|
}
|
|
|
|
|
|
2025-12-29 17:48:06 +02:00
|
|
|
// Set draft and open the page for editing
|
|
|
|
|
setCommandDraft({ name: newName, scope: 'user' });
|
|
|
|
|
setSelectedCommand(newName);
|
2025-12-30 21:03:16 +02:00
|
|
|
onItemSelect?.();
|
2025-12-07 19:32:53 +02:00
|
|
|
|
2026-02-24 03:28:30 +02:00
|
|
|
|
2025-12-07 19:32:53 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleDeleteCommand = async (command: Command) => {
|
2025-12-29 17:48:06 +02:00
|
|
|
if (isCommandBuiltIn(command)) {
|
2026-04-26 14:03:39 +03:00
|
|
|
toast.error(t('settings.commands.sidebar.toast.builtInCannotDelete'));
|
2025-12-29 17:48:06 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-10 00:27:17 +02:00
|
|
|
setConfirmActionCommand(command);
|
|
|
|
|
setConfirmActionType('delete');
|
2025-12-07 19:32:53 +02:00
|
|
|
};
|
|
|
|
|
|
2025-12-29 17:48:06 +02:00
|
|
|
const handleResetCommand = async (command: Command) => {
|
|
|
|
|
if (!isCommandBuiltIn(command)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-10 00:27:17 +02:00
|
|
|
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') {
|
2026-04-26 14:03:39 +03:00
|
|
|
toast.success(t('settings.commands.sidebar.toast.commandDeleted', { name: confirmActionCommand.name }));
|
2025-12-29 17:48:06 +02:00
|
|
|
} else {
|
2026-04-26 14:03:39 +03:00
|
|
|
toast.success(t('settings.commands.sidebar.toast.commandReset', { name: confirmActionCommand.name }));
|
2025-12-29 17:48:06 +02:00
|
|
|
}
|
2026-02-10 00:27:17 +02:00
|
|
|
closeConfirmActionDialog();
|
|
|
|
|
} else if (confirmActionType === 'delete') {
|
2026-04-26 14:03:39 +03:00
|
|
|
toast.error(t('settings.commands.sidebar.toast.deleteFailed'));
|
2026-02-10 00:27:17 +02:00
|
|
|
} else {
|
2026-04-26 14:03:39 +03:00
|
|
|
toast.error(t('settings.commands.sidebar.toast.resetFailed'));
|
2025-12-29 17:48:06 +02:00
|
|
|
}
|
2026-02-10 00:27:17 +02:00
|
|
|
|
|
|
|
|
setIsConfirmActionPending(false);
|
2025-12-29 17:48:06 +02:00
|
|
|
};
|
|
|
|
|
|
2025-12-07 19:32:53 +02:00
|
|
|
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}`;
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-29 17:48:06 +02:00
|
|
|
// 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,
|
|
|
|
|
});
|
2025-12-07 19:32:53 +02:00
|
|
|
setSelectedCommand(newName);
|
|
|
|
|
|
2026-02-24 03:28:30 +02:00
|
|
|
|
2025-12-07 19:32:53 +02:00
|
|
|
};
|
|
|
|
|
|
2025-12-29 17:48:06 +02:00
|
|
|
const handleOpenRenameDialog = (command: Command) => {
|
|
|
|
|
setRenameNewName(command.name);
|
|
|
|
|
setRenameDialogCommand(command);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleRenameCommand = async () => {
|
|
|
|
|
if (!renameDialogCommand) return;
|
|
|
|
|
|
|
|
|
|
const sanitizedName = renameNewName.trim().replace(/\s+/g, '-');
|
|
|
|
|
|
|
|
|
|
if (!sanitizedName) {
|
2026-04-26 14:03:39 +03:00
|
|
|
toast.error(t('settings.commands.sidebar.toast.commandNameRequired'));
|
2025-12-29 17:48:06 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sanitizedName === renameDialogCommand.name) {
|
|
|
|
|
setRenameDialogCommand(null);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (commands.some((cmd) => cmd.name === sanitizedName)) {
|
2026-04-26 14:03:39 +03:00
|
|
|
toast.error(t('settings.commands.sidebar.toast.commandExists'));
|
2025-12-29 17:48:06 +02:00
|
|
|
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 {
|
2026-04-26 14:03:39 +03:00
|
|
|
toast.error(t('settings.commands.sidebar.toast.removeOldAfterRenameFailed'));
|
2025-12-29 17:48:06 +02:00
|
|
|
}
|
|
|
|
|
} else {
|
2026-04-26 14:03:39 +03:00
|
|
|
toast.error(t('settings.commands.sidebar.toast.renameFailed'));
|
2025-12-29 17:48:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setRenameDialogCommand(null);
|
|
|
|
|
};
|
|
|
|
|
|
2026-02-18 20:08:42 +02:00
|
|
|
const builtInCommands = commandOnlyItems.filter(isCommandBuiltIn);
|
|
|
|
|
const customCommands = commandOnlyItems.filter((cmd) => !isCommandBuiltIn(cmd));
|
2025-12-29 17:48:06 +02:00
|
|
|
|
2025-12-07 19:32:53 +02:00
|
|
|
return (
|
2025-12-28 03:28:13 +02:00
|
|
|
<div className={cn('flex h-full flex-col', bgClass)}>
|
2026-02-24 03:28:30 +02:00
|
|
|
<div className="border-b px-3 pt-4 pb-3">
|
2026-04-26 14:03:39 +03:00
|
|
|
<h2 className="text-base font-semibold text-foreground mb-3">{t('settings.commands.sidebar.title')}</h2>
|
2026-02-24 03:28:30 +02:00
|
|
|
<SettingsProjectSelector className="mb-3" />
|
2025-12-29 17:48:06 +02:00
|
|
|
<div className="flex items-center justify-between gap-2">
|
2026-04-26 14:03:39 +03:00
|
|
|
<span className="typography-meta text-muted-foreground">{t('settings.commands.sidebar.total', { count: commandOnlyItems.length })}</span>
|
2026-03-20 01:01:03 +02:00
|
|
|
<Button size="sm"
|
2025-12-29 17:48:06 +02:00
|
|
|
variant="ghost"
|
2026-02-24 03:28:30 +02:00
|
|
|
className="h-7 w-7 px-0 -my-1 text-muted-foreground"
|
2025-12-29 17:48:06 +02:00
|
|
|
onClick={handleCreateNew}
|
|
|
|
|
>
|
2026-02-24 03:28:30 +02:00
|
|
|
<RiAddLine className="h-3.5 w-3.5" />
|
2026-03-20 01:01:03 +02:00
|
|
|
</Button>
|
2025-12-07 19:32:53 +02:00
|
|
|
</div>
|
2025-12-29 17:48:06 +02:00
|
|
|
</div>
|
2025-12-07 19:32:53 +02:00
|
|
|
|
2025-12-29 17:48:06 +02:00
|
|
|
<ScrollableOverlay outerClassName="flex-1 min-h-0" className="space-y-1 px-3 py-2">
|
2026-02-18 20:08:42 +02:00
|
|
|
{commandOnlyItems.length === 0 ? (
|
2025-12-29 17:48:06 +02:00
|
|
|
<div className="py-12 px-4 text-center text-muted-foreground">
|
|
|
|
|
<RiTerminalBoxLine className="mx-auto mb-3 h-10 w-10 opacity-50" />
|
2026-04-26 14:03:39 +03:00
|
|
|
<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>
|
2025-12-29 17:48:06 +02:00
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
|
|
|
|
{builtInCommands.length > 0 && (
|
2025-12-07 19:32:53 +02:00
|
|
|
<>
|
2025-12-29 17:48:06 +02:00
|
|
|
<div className="px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground">
|
2026-04-26 14:03:39 +03:00
|
|
|
{t('settings.commands.sidebar.section.builtIn')}
|
2025-12-29 17:48:06 +02:00
|
|
|
</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?.();
|
2026-02-24 03:28:30 +02:00
|
|
|
|
2025-12-29 17:48:06 +02:00
|
|
|
}}
|
|
|
|
|
onReset={() => handleResetCommand(command)}
|
|
|
|
|
onDuplicate={() => handleDuplicateCommand(command)}
|
2026-02-24 03:28:30 +02:00
|
|
|
isMenuOpen={openMenuCommand === command.name}
|
|
|
|
|
onMenuOpenChange={(open) => setOpenMenuCommand(open ? command.name : null)}
|
2025-12-29 17:48:06 +02:00
|
|
|
/>
|
|
|
|
|
))}
|
2025-12-07 19:32:53 +02:00
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
|
2025-12-29 17:48:06 +02:00
|
|
|
{customCommands.length > 0 && (
|
|
|
|
|
<>
|
|
|
|
|
<div className="px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground">
|
2026-04-26 14:03:39 +03:00
|
|
|
{t('settings.commands.sidebar.section.custom')}
|
2025-12-29 17:48:06 +02:00
|
|
|
</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?.();
|
2026-02-24 03:28:30 +02:00
|
|
|
|
2025-12-29 17:48:06 +02:00
|
|
|
}}
|
|
|
|
|
onRename={() => handleOpenRenameDialog(command)}
|
|
|
|
|
onDelete={() => handleDeleteCommand(command)}
|
|
|
|
|
onDuplicate={() => handleDuplicateCommand(command)}
|
2026-02-24 03:28:30 +02:00
|
|
|
isMenuOpen={openMenuCommand === command.name}
|
|
|
|
|
onMenuOpenChange={(open) => setOpenMenuCommand(open ? command.name : null)}
|
2025-12-29 17:48:06 +02:00
|
|
|
/>
|
|
|
|
|
))}
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</ScrollableOverlay>
|
|
|
|
|
|
2026-02-10 00:27:17 +02:00
|
|
|
<Dialog
|
|
|
|
|
open={confirmActionCommand !== null && confirmActionType !== null}
|
|
|
|
|
onOpenChange={(open) => {
|
|
|
|
|
if (!open && !isConfirmActionPending) {
|
|
|
|
|
closeConfirmActionDialog();
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<DialogContent className="max-w-md">
|
|
|
|
|
<DialogHeader>
|
2026-04-26 14:03:39 +03:00
|
|
|
<DialogTitle>{confirmActionType === 'delete' ? t('settings.commands.sidebar.dialog.deleteTitle') : t('settings.commands.sidebar.dialog.resetTitle')}</DialogTitle>
|
2026-02-10 00:27:17 +02:00
|
|
|
<DialogDescription>
|
|
|
|
|
{confirmActionType === 'delete'
|
2026-04-26 14:03:39 +03:00
|
|
|
? t('settings.commands.sidebar.dialog.deleteDescription', { name: confirmActionCommand?.name ?? '' })
|
|
|
|
|
: t('settings.commands.sidebar.dialog.resetDescription', { name: confirmActionCommand?.name ?? '' })}
|
2026-02-10 00:27:17 +02:00
|
|
|
</DialogDescription>
|
|
|
|
|
</DialogHeader>
|
|
|
|
|
<DialogFooter>
|
2026-03-20 01:01:03 +02:00
|
|
|
<Button
|
|
|
|
|
size="sm"
|
2026-02-10 00:27:17 +02:00
|
|
|
variant="ghost"
|
|
|
|
|
onClick={closeConfirmActionDialog}
|
|
|
|
|
disabled={isConfirmActionPending}
|
|
|
|
|
>
|
2026-04-26 14:03:39 +03:00
|
|
|
{t('settings.common.actions.cancel')}
|
2026-03-20 01:01:03 +02:00
|
|
|
</Button>
|
|
|
|
|
<Button size="sm" onClick={handleConfirmAction} disabled={isConfirmActionPending}>
|
2026-04-26 14:03:39 +03:00
|
|
|
{confirmActionType === 'delete' ? t('settings.common.actions.delete') : t('settings.common.actions.reset')}
|
2026-03-20 01:01:03 +02:00
|
|
|
</Button>
|
2026-02-10 00:27:17 +02:00
|
|
|
</DialogFooter>
|
|
|
|
|
</DialogContent>
|
|
|
|
|
</Dialog>
|
|
|
|
|
|
2025-12-29 17:48:06 +02:00
|
|
|
{/* Rename Dialog */}
|
|
|
|
|
<Dialog open={renameDialogCommand !== null} onOpenChange={(open) => !open && setRenameDialogCommand(null)}>
|
2025-12-07 19:32:53 +02:00
|
|
|
<DialogContent>
|
|
|
|
|
<DialogHeader>
|
2026-04-26 14:03:39 +03:00
|
|
|
<DialogTitle>{t('settings.commands.sidebar.renameDialog.title')}</DialogTitle>
|
2025-12-07 19:32:53 +02:00
|
|
|
<DialogDescription>
|
2026-04-26 14:03:39 +03:00
|
|
|
{t('settings.commands.sidebar.renameDialog.description', { name: renameDialogCommand?.name ?? '' })}
|
2025-12-07 19:32:53 +02:00
|
|
|
</DialogDescription>
|
|
|
|
|
</DialogHeader>
|
|
|
|
|
<Input
|
2025-12-29 17:48:06 +02:00
|
|
|
value={renameNewName}
|
|
|
|
|
onChange={(e) => setRenameNewName(e.target.value)}
|
2026-04-26 14:03:39 +03:00
|
|
|
placeholder={t('settings.commands.sidebar.renameDialog.placeholder')}
|
2025-12-07 19:32:53 +02:00
|
|
|
className="text-foreground placeholder:text-muted-foreground"
|
|
|
|
|
onKeyDown={(e) => {
|
|
|
|
|
if (e.key === 'Enter') {
|
2025-12-29 17:48:06 +02:00
|
|
|
handleRenameCommand();
|
2025-12-07 19:32:53 +02:00
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
<DialogFooter>
|
2026-03-20 01:01:03 +02:00
|
|
|
<Button
|
|
|
|
|
size="sm"
|
2025-12-07 19:32:53 +02:00
|
|
|
variant="ghost"
|
2025-12-29 17:48:06 +02:00
|
|
|
onClick={() => setRenameDialogCommand(null)}
|
2025-12-07 19:32:53 +02:00
|
|
|
>
|
2026-04-26 14:03:39 +03:00
|
|
|
{t('settings.common.actions.cancel')}
|
2026-03-20 01:01:03 +02:00
|
|
|
</Button>
|
|
|
|
|
<Button size="sm" onClick={handleRenameCommand}>
|
2026-04-26 14:03:39 +03:00
|
|
|
{t('settings.common.actions.rename')}
|
2026-03-20 01:01:03 +02:00
|
|
|
</Button>
|
2025-12-07 19:32:53 +02:00
|
|
|
</DialogFooter>
|
|
|
|
|
</DialogContent>
|
|
|
|
|
</Dialog>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
interface CommandListItemProps {
|
|
|
|
|
command: Command;
|
|
|
|
|
isSelected: boolean;
|
|
|
|
|
onSelect: () => void;
|
2025-12-29 17:48:06 +02:00
|
|
|
onDelete?: () => void;
|
|
|
|
|
onReset?: () => void;
|
|
|
|
|
onRename?: () => void;
|
2025-12-07 19:32:53 +02:00
|
|
|
onDuplicate: () => void;
|
2026-02-24 03:28:30 +02:00
|
|
|
isMenuOpen: boolean;
|
|
|
|
|
onMenuOpenChange: (open: boolean) => void;
|
2025-12-07 19:32:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const CommandListItem: React.FC<CommandListItemProps> = ({
|
|
|
|
|
command,
|
|
|
|
|
isSelected,
|
|
|
|
|
onSelect,
|
|
|
|
|
onDelete,
|
2025-12-29 17:48:06 +02:00
|
|
|
onReset,
|
|
|
|
|
onRename,
|
2025-12-07 19:32:53 +02:00
|
|
|
onDuplicate,
|
2026-02-24 03:28:30 +02:00
|
|
|
isMenuOpen,
|
|
|
|
|
onMenuOpenChange,
|
2025-12-07 19:32:53 +02:00
|
|
|
}) => {
|
2026-04-26 14:03:39 +03:00
|
|
|
const { t } = useI18n();
|
2026-02-24 03:28:30 +02:00
|
|
|
const isMobile = isMobileDeviceViaCSS();
|
2025-12-07 19:32:53 +02:00
|
|
|
return (
|
2025-12-28 02:17:09 +02:00
|
|
|
<div
|
|
|
|
|
className={cn(
|
2026-02-24 03:28:30 +02:00
|
|
|
'group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none',
|
2026-02-01 18:29:34 +02:00
|
|
|
isSelected ? 'bg-interactive-selection' : 'hover:bg-interactive-hover'
|
2025-12-28 02:17:09 +02:00
|
|
|
)}
|
2026-02-24 03:28:30 +02:00
|
|
|
onContextMenu={!isMobile ? (e) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
onMenuOpenChange(true);
|
|
|
|
|
} : undefined}
|
2025-12-28 02:17:09 +02:00
|
|
|
>
|
|
|
|
|
<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>
|
2025-12-29 17:48:06 +02:00
|
|
|
{(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">
|
2026-04-26 14:03:39 +03:00
|
|
|
{isCommandBuiltIn(command) ? t('settings.agents.sidebar.badge.system') : command.scope}
|
2025-12-29 17:48:06 +02:00
|
|
|
</span>
|
|
|
|
|
)}
|
2025-12-28 02:17:09 +02:00
|
|
|
</div>
|
2025-12-07 19:32:53 +02:00
|
|
|
|
2025-12-28 02:17:09 +02:00
|
|
|
{command.description && (
|
|
|
|
|
<div className="typography-micro text-muted-foreground/60 truncate leading-tight">
|
|
|
|
|
{command.description}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</button>
|
2025-12-07 19:32:53 +02:00
|
|
|
|
2026-02-24 03:28:30 +02:00
|
|
|
<DropdownMenu open={isMenuOpen} onOpenChange={onMenuOpenChange}>
|
2025-12-28 02:17:09 +02:00
|
|
|
<DropdownMenuTrigger asChild>
|
2026-03-20 01:01:03 +02:00
|
|
|
<Button size="sm"
|
2025-12-28 02:17:09 +02:00
|
|
|
variant="ghost"
|
2026-02-24 03:28:30 +02:00
|
|
|
className="h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100"
|
2025-12-28 02:17:09 +02:00
|
|
|
>
|
|
|
|
|
<RiMore2Line className="h-3.5 w-3.5" />
|
2026-03-20 01:01:03 +02:00
|
|
|
</Button>
|
2025-12-28 02:17:09 +02:00
|
|
|
</DropdownMenuTrigger>
|
|
|
|
|
<DropdownMenuContent align="end" className="w-fit min-w-20">
|
2025-12-29 17:48:06 +02:00
|
|
|
{onRename && (
|
|
|
|
|
<DropdownMenuItem
|
|
|
|
|
onClick={(e) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
onRename();
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<RiEditLine className="h-4 w-4 mr-px" />
|
2026-04-26 14:03:39 +03:00
|
|
|
{t('settings.common.actions.rename')}
|
2025-12-29 17:48:06 +02:00
|
|
|
</DropdownMenuItem>
|
|
|
|
|
)}
|
|
|
|
|
|
2025-12-28 02:17:09 +02:00
|
|
|
<DropdownMenuItem
|
|
|
|
|
onClick={(e) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
onDuplicate();
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<RiFileCopyLine className="h-4 w-4 mr-px" />
|
2026-04-26 14:03:39 +03:00
|
|
|
{t('settings.common.actions.duplicate')}
|
2025-12-28 02:17:09 +02:00
|
|
|
</DropdownMenuItem>
|
2025-12-07 19:32:53 +02:00
|
|
|
|
2025-12-29 17:48:06 +02:00
|
|
|
{onReset && (
|
|
|
|
|
<DropdownMenuItem
|
|
|
|
|
onClick={(e) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
onReset();
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<RiRestartLine className="h-4 w-4 mr-px" />
|
2026-04-26 14:03:39 +03:00
|
|
|
{t('settings.common.actions.reset')}
|
2025-12-29 17:48:06 +02:00
|
|
|
</DropdownMenuItem>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{onDelete && (
|
|
|
|
|
<DropdownMenuItem
|
|
|
|
|
onClick={(e) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
onDelete();
|
|
|
|
|
}}
|
|
|
|
|
className="text-destructive focus:text-destructive"
|
|
|
|
|
>
|
|
|
|
|
<RiDeleteBinLine className="h-4 w-4 mr-px" />
|
2026-04-26 14:03:39 +03:00
|
|
|
{t('settings.common.actions.delete')}
|
2025-12-29 17:48:06 +02:00
|
|
|
</DropdownMenuItem>
|
|
|
|
|
)}
|
2025-12-28 02:17:09 +02:00
|
|
|
</DropdownMenuContent>
|
|
|
|
|
</DropdownMenu>
|
2025-12-07 19:32:53 +02:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|