drag-and-drop all the things

This commit is contained in:
Alex Gleason committed 2025-12-30 22:00:49 -06:00
1 parent 0192d307c5
commit 38ffe02185
4 files changed
+200 -38

No files matched your search

+66
View File
@@ -0,0 +1,66 @@
import { Bot, GripVertical } from 'lucide-react';
import { ExternalFavicon } from '@/components/ExternalFavicon';
import { ReactNode } from 'react';
import { useSortable } from '@dnd-kit/sortable';
import { CSS } from '@dnd-kit/utilities';
interface DraggableProviderTileProps {
id: string;
icon?: ReactNode;
iconUrl?: string | null;
name: string;
onClick: () => void;
badge?: ReactNode;
}
export function DraggableProviderTile({ id, icon, iconUrl, name, onClick, badge }: DraggableProviderTileProps) {
const {
attributes,
listeners,
setNodeRef,
transform,
transition,
isDragging,
} = useSortable({ id });
const style = {
transform: CSS.Transform.toString(transform),
transition,
opacity: isDragging ? 0.5 : 1,
};
return (
<div ref={setNodeRef} style={style} className="relative group">
<button
onClick={onClick}
className="flex flex-col items-center justify-center gap-2 p-4 rounded-lg border bg-card hover:bg-muted transition-colors text-center h-[120px] w-full relative"
>
{iconUrl ? (
<ExternalFavicon
url={iconUrl}
size={32}
fallback={icon || <Bot size={32} />}
/>
) : (
icon || <Bot size={32} />
)}
<span className="text-sm font-medium line-clamp-2 overflow-hidden max-w-full text-ellipsis">
{name}
</span>
{badge && (
<div className="absolute top-0 right-0">
{badge}
</div>
)}
</button>
<div
{...attributes}
{...listeners}
className="absolute top-1 right-1 p-1 cursor-grab active:cursor-grabbing opacity-0 group-hover:opacity-100 transition-opacity bg-background/80 rounded hover:bg-muted"
title="Drag to reorder"
>
<GripVertical size={16} className="text-muted-foreground" />
</div>
</div>
);
}
+1 -1
View File
@@ -14,7 +14,7 @@ export function ProviderTile({ icon, iconUrl, name, onClick, badge }: ProviderTi
return (
<button
onClick={onClick}
className="flex flex-col items-center justify-center gap-2 p-4 rounded-lg border bg-card hover:bg-muted transition-colors text-center min-h-[100px] relative"
className="flex flex-col items-center justify-center gap-2 p-4 rounded-lg border bg-card hover:bg-muted transition-colors text-center h-[120px] relative"
>
{iconUrl ? (
<ExternalFavicon
+69 -21
View File
@@ -7,6 +7,7 @@ import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/
import { Separator } from '@/components/ui/separator';
import { Skeleton } from '@/components/ui/skeleton';
import { ProviderTile } from '@/components/ProviderTile';
import { DraggableProviderTile } from '@/components/DraggableProviderTile';
import { AddProviderTile } from '@/components/AddProviderTile';
import { AIProviderConfigDialog } from '@/components/AIProviderConfigDialog';
import { AddAIProviderDialog } from '@/components/AddAIProviderDialog';
@@ -23,10 +24,25 @@ import { PluginsSection } from '@/components/PluginsSection';
import { ProjectTemplatesSection } from '@/components/ProjectTemplatesSection';
import { defaultSystemPrompt } from '@/lib/system';
import { ModelInput } from '@/components/ModelInput';
import {
DndContext,
closestCenter,
KeyboardSensor,
PointerSensor,
useSensor,
useSensors,
DragEndEvent,
} from '@dnd-kit/core';
import {
arrayMove,
SortableContext,
sortableKeyboardCoordinates,
rectSortingStrategy,
} from '@dnd-kit/sortable';
export function AISettings() {
const { t } = useTranslation();
const { settings, updateSettings, setProvider, removeProvider, isLoading } = useAISettings();
const { settings, updateSettings, setProvider, removeProvider, setProviders, isLoading } = useAISettings();
const { user } = useCurrentUser();
const { config, defaultConfig, updateConfig } = useAppContext();
const [showAdvanced, setShowAdvanced] = useState(false);
@@ -40,6 +56,26 @@ export function AISettings() {
const [addDialogOpen, setAddDialogOpen] = useState(false);
const [customProviderDialogOpen, setCustomProviderDialogOpen] = useState(false);
// Drag and drop sensors
const sensors = useSensors(
useSensor(PointerSensor),
useSensor(KeyboardSensor, {
coordinateGetter: sortableKeyboardCoordinates,
})
);
const handleDragEnd = (event: DragEndEvent) => {
const { active, over } = event;
if (over && active.id !== over.id) {
const oldIndex = settings.providers.findIndex((p) => p.id === active.id);
const newIndex = settings.providers.findIndex((p) => p.id === over.id);
const newProviders = arrayMove(settings.providers, oldIndex, newIndex);
setProviders(newProviders);
}
};
// Check if system prompt differs from default
const isSystemPromptModified = useMemo(() =>
(config.systemPrompt || defaultSystemPrompt) !== (defaultConfig.systemPrompt || defaultSystemPrompt),
@@ -150,27 +186,39 @@ export function AISettings() {
{settings.providers.length > 0 && (
<div className="space-y-3">
<h4 className="text-sm font-medium">{t('configuredProviders')}</h4>
<div className="grid grid-cols-[repeat(auto-fill,minmax(120px,1fr))] gap-3">
{settings.providers.map((provider) => (
<ProviderTile
key={provider.id}
iconUrl={provider.baseURL}
icon={<Bot size={32} />}
name={provider.name}
onClick={() => handleOpenProviderDialog(provider.id)}
badge={
<CreditsBadge
provider={provider}
onOpenDialog={() => {
setSelectedProviderId(provider.id);
setConfigDialogTab('credits');
setConfigDialogOpen(true);
}}
<DndContext
sensors={sensors}
collisionDetection={closestCenter}
onDragEnd={handleDragEnd}
>
<SortableContext
items={settings.providers.map((p) => p.id)}
strategy={rectSortingStrategy}
>
<div className="grid grid-cols-[repeat(auto-fill,minmax(120px,1fr))] gap-3">
{settings.providers.map((provider) => (
<DraggableProviderTile
key={provider.id}
id={provider.id}
iconUrl={provider.baseURL}
icon={<Bot size={32} />}
name={provider.name}
onClick={() => handleOpenProviderDialog(provider.id)}
badge={
<CreditsBadge
provider={provider}
onOpenDialog={() => {
setSelectedProviderId(provider.id);
setConfigDialogTab('credits');
setConfigDialogOpen(true);
}}
/>
}
/>
}
/>
))}
</div>
))}
</div>
</SortableContext>
</DndContext>
</div>
)}
+64 -16
View File
@@ -13,11 +13,27 @@ import { SettingsPageLayout } from '@/components/SettingsPageLayout';
import type { GitCredential } from '@/contexts/GitSettingsContext';
import { ExternalFavicon } from '@/components/ExternalFavicon';
import { ProviderTile } from '@/components/ProviderTile';
import { DraggableProviderTile } from '@/components/DraggableProviderTile';
import { AddProviderTile } from '@/components/AddProviderTile';
import { GitCredentialConfigDialog } from '@/components/GitCredentialConfigDialog';
import { AddGitCredentialDialog } from '@/components/AddGitCredentialDialog';
import { AddCustomGitCredentialDialog } from '@/components/AddCustomGitCredentialDialog';
import { Separator } from '@/components/ui/separator';
import {
DndContext,
closestCenter,
KeyboardSensor,
PointerSensor,
useSensor,
useSensors,
DragEndEvent,
} from '@dnd-kit/core';
import {
arrayMove,
SortableContext,
sortableKeyboardCoordinates,
rectSortingStrategy,
} from '@dnd-kit/sortable';
interface PresetProvider {
id: string;
@@ -60,6 +76,26 @@ export function GitSettings() {
const [addDialogOpen, setAddDialogOpen] = useState(false);
const [customCredentialDialogOpen, setCustomCredentialDialogOpen] = useState(false);
// Drag and drop sensors
const sensors = useSensors(
useSensor(PointerSensor),
useSensor(KeyboardSensor, {
coordinateGetter: sortableKeyboardCoordinates,
})
);
const handleDragEnd = (event: DragEndEvent) => {
const { active, over } = event;
if (over && active.id !== over.id) {
const oldIndex = settings.credentials.findIndex((c) => c.id === active.id);
const newIndex = settings.credentials.findIndex((c) => c.id === over.id);
const newCredentials = arrayMove(settings.credentials, oldIndex, newIndex);
setCredentials(newCredentials);
}
};
const handleOpenCredentialDialog = (credentialId: string) => {
setSelectedCredentialId(credentialId);
setConfigDialogOpen(true);
@@ -182,23 +218,35 @@ export function GitSettings() {
{settings.credentials.length > 0 && (
<div className="space-y-3">
<h4 className="text-sm font-medium">{t('configuredCredentials')}</h4>
<div className="grid grid-cols-[repeat(auto-fill,minmax(120px,1fr))] gap-3">
{settings.credentials.map((credential) => {
const preset = PRESET_PROVIDERS.find(p => p.origin === credential.origin);
const isCustom = !preset;
<DndContext
sensors={sensors}
collisionDetection={closestCenter}
onDragEnd={handleDragEnd}
>
<SortableContext
items={settings.credentials.map((c) => c.id)}
strategy={rectSortingStrategy}
>
<div className="grid grid-cols-[repeat(auto-fill,minmax(120px,1fr))] gap-3">
{settings.credentials.map((credential) => {
const preset = PRESET_PROVIDERS.find(p => p.origin === credential.origin);
const isCustom = !preset;
return (
<ProviderTile
key={credential.id}
iconUrl={credential.origin}
icon={<GitBranch size={32} />}
name={credential.name}
onClick={() => handleOpenCredentialDialog(credential.id)}
badge={isCustom ? <span className="text-xs px-1.5 py-0.5 bg-muted rounded">{t('custom')}</span> : undefined}
/>
);
})}
</div>
return (
<DraggableProviderTile
key={credential.id}
id={credential.id}
iconUrl={credential.origin}
icon={<GitBranch size={32} />}
name={credential.name}
onClick={() => handleOpenCredentialDialog(credential.id)}
badge={isCustom ? <span className="text-xs px-1.5 py-0.5 bg-muted rounded">{t('custom')}</span> : undefined}
/>
);
})}
</div>
</SortableContext>
</DndContext>
</div>
)}