feat: US-010 — Projects sidebar tree view and project detail routing
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
34
src/renderer/components/projects/ProjectDetail.tsx
Normal file
34
src/renderer/components/projects/ProjectDetail.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
import { trpc } from '@/lib/trpc';
|
||||
|
||||
type ProjectDetailProps = {
|
||||
projectId: string;
|
||||
};
|
||||
|
||||
export function ProjectDetail({ projectId }: ProjectDetailProps) {
|
||||
const { data: project, isLoading } = trpc.projects.get.useQuery({ id: projectId });
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center h-full text-sm text-muted-foreground">
|
||||
Loading project...
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!project) {
|
||||
return (
|
||||
<div className="flex items-center justify-center h-full text-sm text-muted-foreground">
|
||||
Project not found
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="p-6 max-w-4xl mx-auto">
|
||||
<h1 className="text-2xl font-semibold text-foreground">{project.name}</h1>
|
||||
<p className="text-sm text-muted-foreground mt-1">
|
||||
Project detail view will be implemented in US-013.
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,19 +1,22 @@
|
||||
import { useState, useCallback } from 'react';
|
||||
import { useState, useMemo } from 'react';
|
||||
import {
|
||||
Folder,
|
||||
Circle,
|
||||
ChevronRight,
|
||||
ChevronDown,
|
||||
Plus,
|
||||
MoreHorizontal,
|
||||
Edit2,
|
||||
FolderPlus,
|
||||
Archive,
|
||||
ArchiveRestore,
|
||||
Trash2,
|
||||
AlertTriangle,
|
||||
Search,
|
||||
} from 'lucide-react';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { trpc } from '@/lib/trpc';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Switch } from '@/components/ui/switch';
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
@@ -31,6 +34,21 @@ import {
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from '@/components/ui/alert-dialog';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@/components/ui/select';
|
||||
import {
|
||||
Collapsible,
|
||||
CollapsibleContent,
|
||||
@@ -45,251 +63,126 @@ import {
|
||||
EmptyTitle,
|
||||
} from '@/components/ui/empty';
|
||||
|
||||
type ProjectFlat = {
|
||||
id: string;
|
||||
name: string;
|
||||
parentId: string | null;
|
||||
industry: string | null;
|
||||
createdAt: number;
|
||||
const NO_CLIENT_KEY = '__no_client__';
|
||||
|
||||
type ProjectSidebarProps = {
|
||||
selectedProjectId: string | undefined;
|
||||
onSelectProject: (id: string) => void;
|
||||
};
|
||||
|
||||
type ProjectNode = ProjectFlat & { children: ProjectNode[] };
|
||||
|
||||
function buildTree(projects: ProjectFlat[]): ProjectNode[] {
|
||||
const map = new Map<string, ProjectNode>();
|
||||
for (const c of projects) map.set(c.id, { ...c, children: [] });
|
||||
|
||||
const roots: ProjectNode[] = [];
|
||||
for (const c of projects) {
|
||||
const node = map.get(c.id)!;
|
||||
if (c.parentId) {
|
||||
const parent = map.get(c.parentId);
|
||||
if (parent) parent.children.push(node);
|
||||
else roots.push(node);
|
||||
} else {
|
||||
roots.push(node);
|
||||
}
|
||||
}
|
||||
return roots;
|
||||
}
|
||||
|
||||
type DeleteDialog = {
|
||||
id: string;
|
||||
name: string;
|
||||
stage: 'confirm' | 'cascade-warn';
|
||||
errorMessage?: string;
|
||||
};
|
||||
|
||||
export function ProjectSidebar() {
|
||||
export function ProjectSidebar({ selectedProjectId, onSelectProject }: ProjectSidebarProps) {
|
||||
const utils = trpc.useUtils();
|
||||
const { data: projects = [] } = trpc.clients.list.useQuery();
|
||||
|
||||
const [showArchived, setShowArchived] = useState(false);
|
||||
const [searchQuery, setSearchQuery] = useState('');
|
||||
const [expanded, setExpanded] = useState<Set<string>>(new Set());
|
||||
const [renaming, setRenaming] = useState<{ id: string; value: string } | null>(null);
|
||||
const [deleteDialog, setDeleteDialog] = useState<DeleteDialog | null>(null);
|
||||
const [deleteProjectId, setDeleteProjectId] = useState<{ id: string; name: string } | null>(null);
|
||||
const [editDialog, setEditDialog] = useState<{ id: string; name: string; clientId: string | null } | null>(null);
|
||||
const [editClientValue, setEditClientValue] = useState<string>(NO_CLIENT_KEY);
|
||||
|
||||
// Callback ref: auto-focus + select when rename input mounts
|
||||
const renameInputCallback = useCallback((el: HTMLInputElement | null) => {
|
||||
if (el) {
|
||||
el.focus();
|
||||
el.select();
|
||||
}
|
||||
}, []);
|
||||
const { data: projectList = [] } = trpc.projects.list.useQuery(
|
||||
{ includeArchived: showArchived },
|
||||
);
|
||||
const { data: clientList = [] } = trpc.clients.list.useQuery();
|
||||
|
||||
const createMutation = trpc.clients.create.useMutation({
|
||||
onSuccess: () => { void utils.clients.list.invalidate(); },
|
||||
const createMutation = trpc.projects.create.useMutation({
|
||||
onSuccess: () => { void utils.projects.list.invalidate(); },
|
||||
});
|
||||
|
||||
const updateMutation = trpc.clients.update.useMutation({
|
||||
onSuccess: () => { void utils.clients.list.invalidate(); },
|
||||
const updateMutation = trpc.projects.update.useMutation({
|
||||
onSuccess: () => { void utils.projects.list.invalidate(); },
|
||||
});
|
||||
|
||||
const deleteMutation = trpc.clients.delete.useMutation({
|
||||
onSuccess: (result) => {
|
||||
if ('error' in result) {
|
||||
setDeleteDialog((prev) =>
|
||||
prev ? { ...prev, stage: 'cascade-warn', errorMessage: result.error } : null,
|
||||
);
|
||||
} else {
|
||||
setDeleteDialog(null);
|
||||
void utils.clients.list.invalidate();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
const cascadeDeleteMutation = trpc.clients.deleteWithCascade.useMutation({
|
||||
const deleteMutation = trpc.projects.delete.useMutation({
|
||||
onSuccess: () => {
|
||||
setDeleteDialog(null);
|
||||
void utils.clients.list.invalidate();
|
||||
setDeleteProjectId(null);
|
||||
void utils.projects.list.invalidate();
|
||||
},
|
||||
});
|
||||
|
||||
const tree = buildTree(projects as ProjectFlat[]);
|
||||
// Build a client lookup map
|
||||
const clientMap = useMemo(() => {
|
||||
const m = new Map<string, string>();
|
||||
for (const c of clientList) m.set(c.id, c.name);
|
||||
return m;
|
||||
}, [clientList]);
|
||||
|
||||
function toggleExpanded(id: string) {
|
||||
// Group projects by clientId, filter by search
|
||||
const grouped = useMemo(() => {
|
||||
const lowerSearch = searchQuery.toLowerCase();
|
||||
const filtered = projectList.filter((p) =>
|
||||
!searchQuery || p.name.toLowerCase().includes(lowerSearch),
|
||||
);
|
||||
|
||||
const groups = new Map<string, typeof filtered>();
|
||||
for (const p of filtered) {
|
||||
const key = p.clientId ?? NO_CLIENT_KEY;
|
||||
const arr = groups.get(key);
|
||||
if (arr) arr.push(p);
|
||||
else groups.set(key, [p]);
|
||||
}
|
||||
return groups;
|
||||
}, [projectList, searchQuery]);
|
||||
|
||||
// Auto-expand all groups when searching
|
||||
const effectiveExpanded = useMemo(() => {
|
||||
if (searchQuery) {
|
||||
return new Set([...grouped.keys()]);
|
||||
}
|
||||
return expanded;
|
||||
}, [searchQuery, grouped, expanded]);
|
||||
|
||||
function toggleExpanded(key: string) {
|
||||
setExpanded((prev) => {
|
||||
const next = new Set(prev);
|
||||
next.has(id) ? next.delete(id) : next.add(id);
|
||||
next.has(key) ? next.delete(key) : next.add(key);
|
||||
return next;
|
||||
});
|
||||
}
|
||||
|
||||
function handleNewProject() {
|
||||
createMutation.mutate(
|
||||
{ name: 'New Project' },
|
||||
{
|
||||
onSuccess: (result) => {
|
||||
setRenaming({ id: result.id, value: 'New Project' });
|
||||
},
|
||||
},
|
||||
createMutation.mutate({ name: 'New Project' });
|
||||
}
|
||||
|
||||
function handleArchiveToggle(id: string, currentStatus: string | null) {
|
||||
const newStatus = currentStatus === 'archived' ? 'active' : 'archived';
|
||||
updateMutation.mutate({ id, status: newStatus as 'active' | 'archived' });
|
||||
}
|
||||
|
||||
function handleEditOpen(project: { id: string; name: string; clientId: string | null }) {
|
||||
setEditDialog(project);
|
||||
setEditClientValue(project.clientId ?? NO_CLIENT_KEY);
|
||||
}
|
||||
|
||||
function handleEditSave() {
|
||||
if (!editDialog) return;
|
||||
const newClientId = editClientValue === NO_CLIENT_KEY ? null : editClientValue;
|
||||
updateMutation.mutate(
|
||||
{ id: editDialog.id, clientId: newClientId },
|
||||
{ onSuccess: () => setEditDialog(null) },
|
||||
);
|
||||
}
|
||||
|
||||
function handleNewSubProject(parentId: string) {
|
||||
createMutation.mutate(
|
||||
{ name: 'New Sub-Project', parentId },
|
||||
{
|
||||
onSuccess: (result) => {
|
||||
setExpanded((prev) => new Set([...prev, parentId]));
|
||||
setRenaming({ id: result.id, value: 'New Sub-Project' });
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
function handleRenameStart(id: string, name: string) {
|
||||
setRenaming({ id, value: name });
|
||||
}
|
||||
// Sort groups: client groups first (alphabetically), then "Internal / No Client" last
|
||||
const sortedGroupKeys = useMemo(() => {
|
||||
const keys = [...grouped.keys()];
|
||||
return keys.sort((a, b) => {
|
||||
if (a === NO_CLIENT_KEY) return 1;
|
||||
if (b === NO_CLIENT_KEY) return -1;
|
||||
const nameA = clientMap.get(a) ?? '';
|
||||
const nameB = clientMap.get(b) ?? '';
|
||||
return nameA.localeCompare(nameB);
|
||||
});
|
||||
}, [grouped, clientMap]);
|
||||
|
||||
function handleRenameSave() {
|
||||
if (!renaming) return;
|
||||
const trimmed = renaming.value.trim();
|
||||
if (trimmed) {
|
||||
updateMutation.mutate({ id: renaming.id, name: trimmed });
|
||||
}
|
||||
setRenaming(null);
|
||||
}
|
||||
|
||||
function handleRenameKeyDown(e: React.KeyboardEvent) {
|
||||
if (e.key === 'Enter') handleRenameSave();
|
||||
if (e.key === 'Escape') setRenaming(null);
|
||||
}
|
||||
|
||||
function handleDeleteClick(id: string, name: string) {
|
||||
setDeleteDialog({ id, name, stage: 'confirm' });
|
||||
}
|
||||
|
||||
function handleDeleteConfirm() {
|
||||
if (!deleteDialog) return;
|
||||
deleteMutation.mutate({ id: deleteDialog.id });
|
||||
}
|
||||
|
||||
function handleCascadeDelete() {
|
||||
if (!deleteDialog) return;
|
||||
cascadeDeleteMutation.mutate({ id: deleteDialog.id });
|
||||
}
|
||||
|
||||
function renderNode(node: ProjectNode, depth = 0) {
|
||||
const isExpanded = expanded.has(node.id);
|
||||
const isRenaming = renaming?.id === node.id;
|
||||
const hasChildren = node.children.length > 0;
|
||||
|
||||
return (
|
||||
<Collapsible
|
||||
key={node.id}
|
||||
open={isExpanded}
|
||||
onOpenChange={() => hasChildren && toggleExpanded(node.id)}
|
||||
>
|
||||
<div
|
||||
className="group relative flex items-center h-7 rounded-md text-sm cursor-default hover:bg-accent transition-colors"
|
||||
style={{ paddingLeft: `${8 + depth * 16}px`, paddingRight: '4px' }}
|
||||
>
|
||||
{/* Expand/collapse chevron */}
|
||||
<CollapsibleTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="size-4 p-0 hover:bg-transparent text-muted-foreground"
|
||||
tabIndex={-1}
|
||||
disabled={!hasChildren}
|
||||
>
|
||||
{hasChildren ? (
|
||||
isExpanded ? <ChevronDown className="size-3" /> : <ChevronRight className="size-3" />
|
||||
) : (
|
||||
<span className="size-4 inline-block" />
|
||||
)}
|
||||
</Button>
|
||||
</CollapsibleTrigger>
|
||||
|
||||
<Folder className="size-3.5 shrink-0 text-muted-foreground mr-1.5" />
|
||||
|
||||
{isRenaming ? (
|
||||
<Input
|
||||
ref={renameInputCallback}
|
||||
className="flex-1 min-w-0 h-5 text-sm px-1 py-0"
|
||||
value={renaming.value}
|
||||
onChange={(e) => setRenaming({ id: node.id, value: e.target.value })}
|
||||
onBlur={handleRenameSave}
|
||||
onKeyDown={handleRenameKeyDown}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
/>
|
||||
) : (
|
||||
<span className="flex-1 min-w-0 truncate text-foreground">{node.name}</span>
|
||||
)}
|
||||
|
||||
{/* Kebab menu */}
|
||||
{!isRenaming && (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className={cn(
|
||||
'size-5 p-0 ml-1 text-muted-foreground hover:bg-muted shrink-0',
|
||||
'opacity-0 group-hover:opacity-100 data-[state=open]:opacity-100',
|
||||
)}
|
||||
tabIndex={-1}
|
||||
>
|
||||
<MoreHorizontal className="size-3" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" className="min-w-[152px]">
|
||||
<DropdownMenuItem onClick={() => handleRenameStart(node.id, node.name)}>
|
||||
<Edit2 />
|
||||
Rename
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={() => handleNewSubProject(node.id)}>
|
||||
<FolderPlus />
|
||||
New Sub-Project
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem
|
||||
className="text-destructive focus:text-destructive"
|
||||
onClick={() => handleDeleteClick(node.id, node.name)}
|
||||
>
|
||||
<Trash2 />
|
||||
Delete
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Children */}
|
||||
<CollapsibleContent>
|
||||
{node.children.map((child) => renderNode(child, depth + 1))}
|
||||
</CollapsibleContent>
|
||||
</Collapsible>
|
||||
);
|
||||
}
|
||||
const totalProjects = projectList.length;
|
||||
|
||||
return (
|
||||
<div className="flex flex-col h-full border-r border-border w-60 shrink-0">
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between px-3 py-2.5 shrink-0">
|
||||
<h4 className="text-lg font-semibold text-foreground">
|
||||
Projects
|
||||
</h4>
|
||||
<h4 className="text-lg font-semibold text-foreground">Projects</h4>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
@@ -301,15 +194,41 @@ export function ProjectSidebar() {
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* Search */}
|
||||
<div className="px-3 pb-2 shrink-0">
|
||||
<div className="relative">
|
||||
<Search className="absolute left-2 top-1/2 -translate-y-1/2 size-3.5 text-muted-foreground" />
|
||||
<Input
|
||||
placeholder="Search projects..."
|
||||
className="h-7 text-sm pl-7"
|
||||
value={searchQuery}
|
||||
onChange={(e) => setSearchQuery(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Show archived toggle */}
|
||||
<div className="flex items-center justify-between px-3 pb-2 shrink-0">
|
||||
<label htmlFor="show-archived" className="text-xs text-muted-foreground cursor-pointer">
|
||||
Show archived
|
||||
</label>
|
||||
<Switch
|
||||
id="show-archived"
|
||||
checked={showArchived}
|
||||
onCheckedChange={setShowArchived}
|
||||
className="scale-75"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Project tree */}
|
||||
<div className="flex-1 overflow-y-auto py-1 px-1">
|
||||
{tree.length === 0 ? (
|
||||
{totalProjects === 0 ? (
|
||||
<Empty>
|
||||
<EmptyHeader>
|
||||
<EmptyMedia variant="icon">
|
||||
<Folder />
|
||||
</EmptyMedia>
|
||||
<EmptyTitle>No project yet</EmptyTitle>
|
||||
<EmptyTitle>No projects yet</EmptyTitle>
|
||||
<EmptyDescription>
|
||||
Get started by adding your first project.
|
||||
</EmptyDescription>
|
||||
@@ -326,77 +245,197 @@ export function ProjectSidebar() {
|
||||
</Button>
|
||||
</EmptyContent>
|
||||
</Empty>
|
||||
) : sortedGroupKeys.length === 0 ? (
|
||||
<div className="text-xs text-muted-foreground px-3 py-4 text-center">
|
||||
No projects match your search.
|
||||
</div>
|
||||
) : (
|
||||
tree.map((node) => renderNode(node))
|
||||
sortedGroupKeys.map((groupKey) => {
|
||||
const groupProjects = grouped.get(groupKey) ?? [];
|
||||
const groupName = groupKey === NO_CLIENT_KEY
|
||||
? 'Internal / No Client'
|
||||
: clientMap.get(groupKey) ?? 'Unknown Client';
|
||||
const isOpen = effectiveExpanded.has(groupKey);
|
||||
|
||||
return (
|
||||
<Collapsible
|
||||
key={groupKey}
|
||||
open={isOpen}
|
||||
onOpenChange={() => toggleExpanded(groupKey)}
|
||||
>
|
||||
{/* Client group header */}
|
||||
<CollapsibleTrigger asChild>
|
||||
<div className="flex items-center h-7 rounded-md text-sm cursor-pointer hover:bg-accent transition-colors px-2">
|
||||
{isOpen ? (
|
||||
<ChevronDown className="size-3 shrink-0 text-muted-foreground mr-1" />
|
||||
) : (
|
||||
<ChevronRight className="size-3 shrink-0 text-muted-foreground mr-1" />
|
||||
)}
|
||||
<Folder className="size-3.5 shrink-0 text-muted-foreground mr-1.5" />
|
||||
<span className="flex-1 min-w-0 truncate font-medium text-foreground">
|
||||
{groupName}
|
||||
</span>
|
||||
<span className="text-xs text-muted-foreground ml-1">
|
||||
{groupProjects.length}
|
||||
</span>
|
||||
</div>
|
||||
</CollapsibleTrigger>
|
||||
|
||||
<CollapsibleContent>
|
||||
{groupProjects.map((project) => (
|
||||
<div
|
||||
key={project.id}
|
||||
className={cn(
|
||||
'group relative flex items-center h-7 rounded-md text-sm cursor-pointer hover:bg-accent transition-colors',
|
||||
selectedProjectId === project.id && 'bg-sidebar-accent',
|
||||
project.status === 'archived' && 'opacity-60',
|
||||
)}
|
||||
style={{ paddingLeft: '28px', paddingRight: '4px' }}
|
||||
onClick={() => onSelectProject(project.id)}
|
||||
>
|
||||
<Circle className="size-2.5 shrink-0 text-muted-foreground mr-1.5" />
|
||||
<span className="flex-1 min-w-0 truncate text-foreground">
|
||||
{project.name}
|
||||
</span>
|
||||
|
||||
{/* Context menu */}
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className={cn(
|
||||
'size-5 p-0 ml-1 text-muted-foreground hover:bg-muted shrink-0',
|
||||
'opacity-0 group-hover:opacity-100 data-[state=open]:opacity-100',
|
||||
)}
|
||||
tabIndex={-1}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<MoreHorizontal className="size-3" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" className="min-w-[152px]">
|
||||
<DropdownMenuItem
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
handleEditOpen({
|
||||
id: project.id,
|
||||
name: project.name,
|
||||
clientId: project.clientId,
|
||||
});
|
||||
}}
|
||||
>
|
||||
<Edit2 />
|
||||
Edit Client
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
handleArchiveToggle(project.id, project.status);
|
||||
}}
|
||||
>
|
||||
{project.status === 'archived' ? (
|
||||
<>
|
||||
<ArchiveRestore />
|
||||
Unarchive
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Archive />
|
||||
Archive
|
||||
</>
|
||||
)}
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem
|
||||
className="text-destructive focus:text-destructive"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
setDeleteProjectId({ id: project.id, name: project.name });
|
||||
}}
|
||||
>
|
||||
<Trash2 />
|
||||
Delete
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
))}
|
||||
</CollapsibleContent>
|
||||
</Collapsible>
|
||||
);
|
||||
})
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Delete confirmation — AlertDialog */}
|
||||
{/* Delete confirmation */}
|
||||
<AlertDialog
|
||||
open={!!deleteDialog}
|
||||
open={!!deleteProjectId}
|
||||
onOpenChange={(open) => {
|
||||
if (!open && !deleteMutation.isPending && !cascadeDeleteMutation.isPending) {
|
||||
setDeleteDialog(null);
|
||||
}
|
||||
if (!open && !deleteMutation.isPending) setDeleteProjectId(null);
|
||||
}}
|
||||
>
|
||||
<AlertDialogContent>
|
||||
{deleteDialog?.stage === 'cascade-warn' ? (
|
||||
<>
|
||||
<AlertDialogHeader>
|
||||
<div className="flex items-start gap-3">
|
||||
<AlertTriangle className="size-5 text-amber-500 shrink-0 mt-0.5" />
|
||||
<div>
|
||||
<AlertDialogTitle>Cannot delete safely</AlertDialogTitle>
|
||||
<AlertDialogDescription className="mt-1">
|
||||
{deleteDialog.errorMessage}
|
||||
</AlertDialogDescription>
|
||||
</div>
|
||||
</div>
|
||||
<AlertDialogDescription>
|
||||
Force-delete “{deleteDialog?.name}” along with all its sub-projects?
|
||||
This cannot be undone.
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel disabled={cascadeDeleteMutation.isPending}>
|
||||
Cancel
|
||||
</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
onClick={handleCascadeDelete}
|
||||
disabled={cascadeDeleteMutation.isPending}
|
||||
>
|
||||
{cascadeDeleteMutation.isPending ? 'Deleting\u2026' : 'Force Delete All'}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>
|
||||
Delete “{deleteDialog?.name}”?
|
||||
</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
This action cannot be undone.
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel disabled={deleteMutation.isPending}>
|
||||
Cancel
|
||||
</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
onClick={handleDeleteConfirm}
|
||||
disabled={deleteMutation.isPending}
|
||||
>
|
||||
{deleteMutation.isPending ? 'Deleting\u2026' : 'Delete'}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</>
|
||||
)}
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>
|
||||
Delete “{deleteProjectId?.name}”?
|
||||
</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
This will delete the project. Tasks assigned to this project will become unassigned. This action cannot be undone.
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel disabled={deleteMutation.isPending}>Cancel</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
onClick={() => {
|
||||
if (deleteProjectId) deleteMutation.mutate({ id: deleteProjectId.id });
|
||||
}}
|
||||
disabled={deleteMutation.isPending}
|
||||
>
|
||||
{deleteMutation.isPending ? 'Deleting\u2026' : 'Delete'}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
|
||||
{/* Edit client dialog */}
|
||||
<Dialog
|
||||
open={!!editDialog}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) setEditDialog(null);
|
||||
}}
|
||||
>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Edit Project Client</DialogTitle>
|
||||
<DialogDescription>
|
||||
Assign “{editDialog?.name}” to a client or leave as internal.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<Select value={editClientValue} onValueChange={setEditClientValue}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select a client" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value={NO_CLIENT_KEY}>No Client (Internal)</SelectItem>
|
||||
{clientList.map((c) => (
|
||||
<SelectItem key={c.id} value={c.id}>
|
||||
{c.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={() => setEditDialog(null)}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button onClick={handleEditSave} disabled={updateMutation.isPending}>
|
||||
{updateMutation.isPending ? 'Saving\u2026' : 'Save'}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
120
src/renderer/components/ui/dialog.tsx
Normal file
120
src/renderer/components/ui/dialog.tsx
Normal file
@@ -0,0 +1,120 @@
|
||||
import * as React from "react"
|
||||
import * as DialogPrimitive from "@radix-ui/react-dialog"
|
||||
import { X } from "lucide-react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const Dialog = DialogPrimitive.Root
|
||||
|
||||
const DialogTrigger = DialogPrimitive.Trigger
|
||||
|
||||
const DialogPortal = DialogPrimitive.Portal
|
||||
|
||||
const DialogClose = DialogPrimitive.Close
|
||||
|
||||
const DialogOverlay = React.forwardRef<
|
||||
React.ElementRef<typeof DialogPrimitive.Overlay>,
|
||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<DialogPrimitive.Overlay
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName
|
||||
|
||||
const DialogContent = React.forwardRef<
|
||||
React.ElementRef<typeof DialogPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
<DialogPortal>
|
||||
<DialogOverlay />
|
||||
<DialogPrimitive.Content
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground">
|
||||
<X className="h-4 w-4" />
|
||||
<span className="sr-only">Close</span>
|
||||
</DialogPrimitive.Close>
|
||||
</DialogPrimitive.Content>
|
||||
</DialogPortal>
|
||||
))
|
||||
DialogContent.displayName = DialogPrimitive.Content.displayName
|
||||
|
||||
const DialogHeader = ({
|
||||
className,
|
||||
...props
|
||||
}: React.HTMLAttributes<HTMLDivElement>) => (
|
||||
<div
|
||||
className={cn(
|
||||
"flex flex-col space-y-1.5 text-center sm:text-left",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
DialogHeader.displayName = "DialogHeader"
|
||||
|
||||
const DialogFooter = ({
|
||||
className,
|
||||
...props
|
||||
}: React.HTMLAttributes<HTMLDivElement>) => (
|
||||
<div
|
||||
className={cn(
|
||||
"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
DialogFooter.displayName = "DialogFooter"
|
||||
|
||||
const DialogTitle = React.forwardRef<
|
||||
React.ElementRef<typeof DialogPrimitive.Title>,
|
||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<DialogPrimitive.Title
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"text-lg font-semibold leading-none tracking-tight",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
DialogTitle.displayName = DialogPrimitive.Title.displayName
|
||||
|
||||
const DialogDescription = React.forwardRef<
|
||||
React.ElementRef<typeof DialogPrimitive.Description>,
|
||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<DialogPrimitive.Description
|
||||
ref={ref}
|
||||
className={cn("text-sm text-muted-foreground", className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
DialogDescription.displayName = DialogPrimitive.Description.displayName
|
||||
|
||||
export {
|
||||
Dialog,
|
||||
DialogPortal,
|
||||
DialogOverlay,
|
||||
DialogTrigger,
|
||||
DialogClose,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogFooter,
|
||||
DialogTitle,
|
||||
DialogDescription,
|
||||
}
|
||||
159
src/renderer/components/ui/select.tsx
Normal file
159
src/renderer/components/ui/select.tsx
Normal file
@@ -0,0 +1,159 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as SelectPrimitive from "@radix-ui/react-select"
|
||||
import { Check, ChevronDown, ChevronUp } from "lucide-react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const Select = SelectPrimitive.Root
|
||||
|
||||
const SelectGroup = SelectPrimitive.Group
|
||||
|
||||
const SelectValue = SelectPrimitive.Value
|
||||
|
||||
const SelectTrigger = React.forwardRef<
|
||||
React.ElementRef<typeof SelectPrimitive.Trigger>,
|
||||
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
<SelectPrimitive.Trigger
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"flex h-9 w-full items-center justify-between whitespace-nowrap rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm ring-offset-background data-[placeholder]:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<SelectPrimitive.Icon asChild>
|
||||
<ChevronDown className="h-4 w-4 opacity-50" />
|
||||
</SelectPrimitive.Icon>
|
||||
</SelectPrimitive.Trigger>
|
||||
))
|
||||
SelectTrigger.displayName = SelectPrimitive.Trigger.displayName
|
||||
|
||||
const SelectScrollUpButton = React.forwardRef<
|
||||
React.ElementRef<typeof SelectPrimitive.ScrollUpButton>,
|
||||
React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollUpButton>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<SelectPrimitive.ScrollUpButton
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"flex cursor-default items-center justify-center py-1",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<ChevronUp className="h-4 w-4" />
|
||||
</SelectPrimitive.ScrollUpButton>
|
||||
))
|
||||
SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName
|
||||
|
||||
const SelectScrollDownButton = React.forwardRef<
|
||||
React.ElementRef<typeof SelectPrimitive.ScrollDownButton>,
|
||||
React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollDownButton>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<SelectPrimitive.ScrollDownButton
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"flex cursor-default items-center justify-center py-1",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<ChevronDown className="h-4 w-4" />
|
||||
</SelectPrimitive.ScrollDownButton>
|
||||
))
|
||||
SelectScrollDownButton.displayName =
|
||||
SelectPrimitive.ScrollDownButton.displayName
|
||||
|
||||
const SelectContent = React.forwardRef<
|
||||
React.ElementRef<typeof SelectPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content>
|
||||
>(({ className, children, position = "popper", ...props }, ref) => (
|
||||
<SelectPrimitive.Portal>
|
||||
<SelectPrimitive.Content
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"relative z-50 max-h-[--radix-select-content-available-height] min-w-[8rem] overflow-y-auto overflow-x-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-select-content-transform-origin]",
|
||||
position === "popper" &&
|
||||
"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
|
||||
className
|
||||
)}
|
||||
position={position}
|
||||
{...props}
|
||||
>
|
||||
<SelectScrollUpButton />
|
||||
<SelectPrimitive.Viewport
|
||||
className={cn(
|
||||
"p-1",
|
||||
position === "popper" &&
|
||||
"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
</SelectPrimitive.Viewport>
|
||||
<SelectScrollDownButton />
|
||||
</SelectPrimitive.Content>
|
||||
</SelectPrimitive.Portal>
|
||||
))
|
||||
SelectContent.displayName = SelectPrimitive.Content.displayName
|
||||
|
||||
const SelectLabel = React.forwardRef<
|
||||
React.ElementRef<typeof SelectPrimitive.Label>,
|
||||
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Label>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<SelectPrimitive.Label
|
||||
ref={ref}
|
||||
className={cn("px-2 py-1.5 text-sm font-semibold", className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
SelectLabel.displayName = SelectPrimitive.Label.displayName
|
||||
|
||||
const SelectItem = React.forwardRef<
|
||||
React.ElementRef<typeof SelectPrimitive.Item>,
|
||||
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Item>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
<SelectPrimitive.Item
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<span className="absolute right-2 flex h-3.5 w-3.5 items-center justify-center">
|
||||
<SelectPrimitive.ItemIndicator>
|
||||
<Check className="h-4 w-4" />
|
||||
</SelectPrimitive.ItemIndicator>
|
||||
</span>
|
||||
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
|
||||
</SelectPrimitive.Item>
|
||||
))
|
||||
SelectItem.displayName = SelectPrimitive.Item.displayName
|
||||
|
||||
const SelectSeparator = React.forwardRef<
|
||||
React.ElementRef<typeof SelectPrimitive.Separator>,
|
||||
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Separator>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<SelectPrimitive.Separator
|
||||
ref={ref}
|
||||
className={cn("-mx-1 my-1 h-px bg-muted", className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
SelectSeparator.displayName = SelectPrimitive.Separator.displayName
|
||||
|
||||
export {
|
||||
Select,
|
||||
SelectGroup,
|
||||
SelectValue,
|
||||
SelectTrigger,
|
||||
SelectContent,
|
||||
SelectLabel,
|
||||
SelectItem,
|
||||
SelectSeparator,
|
||||
SelectScrollUpButton,
|
||||
SelectScrollDownButton,
|
||||
}
|
||||
27
src/renderer/components/ui/switch.tsx
Normal file
27
src/renderer/components/ui/switch.tsx
Normal file
@@ -0,0 +1,27 @@
|
||||
import * as React from "react"
|
||||
import * as SwitchPrimitives from "@radix-ui/react-switch"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const Switch = React.forwardRef<
|
||||
React.ElementRef<typeof SwitchPrimitives.Root>,
|
||||
React.ComponentPropsWithoutRef<typeof SwitchPrimitives.Root>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<SwitchPrimitives.Root
|
||||
className={cn(
|
||||
"peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
ref={ref}
|
||||
>
|
||||
<SwitchPrimitives.Thumb
|
||||
className={cn(
|
||||
"pointer-events-none block h-4 w-4 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0"
|
||||
)}
|
||||
/>
|
||||
</SwitchPrimitives.Root>
|
||||
))
|
||||
Switch.displayName = SwitchPrimitives.Root.displayName
|
||||
|
||||
export { Switch }
|
||||
Reference in New Issue
Block a user