feat: asset delete in preview, workflow api key auto-generate, UI polish
Add delete with confirm dialog to asset lightbox (always visible, handles deletion internally with local state update). Force dark theme on asset info panel and fix text color inheritance. Add edge-to-edge image display in lightbox by removing slide padding. Show open-in-immich link on hover only. Add workflow page title breadcrumb. Add one-click workflow API key generation that creates the key in Immich and saves it automatically.
This commit is contained in:
1 parent
e0dd64a95e
commit
6a5b2b442a
5 files changed
+175
-36
No files matched your search
@@ -142,7 +142,7 @@ function PersonChip({ person: p, exImmichUrl, isHidden: hidden, onUpdate }: Pers
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<span className={`text-xs font-medium ${hidden ? 'line-through text-muted-foreground' : ''}`}>{p.personName || 'Unknown'}</span>
|
||||
<span className={`text-xs font-medium ${hidden ? 'line-through text-muted-foreground' : 'text-foreground'}`}>{p.personName || 'Unknown'}</span>
|
||||
</button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="w-56 p-3 z-[10000]" side="bottom" align="start">
|
||||
@@ -262,7 +262,7 @@ export default function AssetInfoPanel({ assetId }: AssetInfoPanelProps) {
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="w-[360px] min-w-[360px] bg-background border-l overflow-y-auto p-4">
|
||||
<div className="dark w-[360px] min-w-[360px] bg-background text-foreground border-l overflow-y-auto p-4">
|
||||
<h2 className="text-lg font-semibold mb-4">Info</h2>
|
||||
<div className="animate-pulse space-y-4">
|
||||
<div className="h-4 bg-muted rounded w-3/4" />
|
||||
@@ -275,7 +275,7 @@ export default function AssetInfoPanel({ assetId }: AssetInfoPanelProps) {
|
||||
|
||||
if (!detail) {
|
||||
return (
|
||||
<div className="w-[360px] min-w-[360px] bg-background border-l overflow-y-auto p-4">
|
||||
<div className="dark w-[360px] min-w-[360px] bg-background text-foreground border-l overflow-y-auto p-4">
|
||||
<h2 className="text-lg font-semibold mb-4">Info</h2>
|
||||
<p className="text-sm text-muted-foreground">Unable to load asset details.</p>
|
||||
</div>
|
||||
@@ -296,7 +296,7 @@ export default function AssetInfoPanel({ assetId }: AssetInfoPanelProps) {
|
||||
: null
|
||||
|
||||
return (
|
||||
<div className="w-[360px] min-w-[360px] bg-background border-l overflow-y-auto">
|
||||
<div className="dark w-[360px] min-w-[360px] bg-background text-foreground border-l overflow-y-auto">
|
||||
{/* Header */}
|
||||
<div className="p-4 pb-2">
|
||||
<h2 className="text-lg font-semibold">Info</h2>
|
||||
|
||||
@@ -13,8 +13,19 @@ import { usePhotoSelectionContext } from '@/contexts/PhotoSelectionContext';
|
||||
import { useConfig } from '@/contexts/ConfigContext';
|
||||
import dynamic from 'next/dynamic';
|
||||
import { Heart, Info, Trash2, ExternalLink } from 'lucide-react';
|
||||
import { updateAssets } from '@/handlers/api/asset.handler';
|
||||
import { updateAssets, deleteAssets } from '@/handlers/api/asset.handler';
|
||||
import { toast } from '@/components/ui/use-toast';
|
||||
import {
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogCancel,
|
||||
AlertDialogAction,
|
||||
AlertDialogPortal,
|
||||
AlertDialogOverlay,
|
||||
} from '@/components/ui/alert-dialog';
|
||||
import * as AlertDialogPrimitive from '@radix-ui/react-alert-dialog';
|
||||
|
||||
const AssetInfoPanel = dynamic(() => import('@/components/asset-info/AssetInfoPanel'), { ssr: false });
|
||||
|
||||
@@ -50,6 +61,8 @@ const AssetGrid = forwardRef<AssetGridRef, AssetGridProps>(({ assets, isInternal
|
||||
return false
|
||||
});
|
||||
const [favoriteIds, setFavoriteIds] = useState<Set<string>>(() => new Set(assets.filter(a => a.isFavorite).map(a => a.id)));
|
||||
const [deletedIds, setDeletedIds] = useState<Set<string>>(new Set());
|
||||
const [deleteConfirmOpen, setDeleteConfirmOpen] = useState(false);
|
||||
const { exImmichUrl } = useConfig();
|
||||
// Use context for selection state
|
||||
const { selectedIds, updateContext } = usePhotoSelectionContext();
|
||||
@@ -145,7 +158,7 @@ const AssetGrid = forwardRef<AssetGridRef, AssetGridProps>(({ assets, isInternal
|
||||
};
|
||||
|
||||
const slides = useMemo(() => {
|
||||
return assets.map((asset) => ({
|
||||
return assets.filter((asset) => !deletedIds.has(asset.id)).map((asset) => ({
|
||||
...asset,
|
||||
orientation: 1,
|
||||
src: asset.previewUrl as string,
|
||||
@@ -166,18 +179,20 @@ const AssetGrid = forwardRef<AssetGridRef, AssetGridProps>(({ assets, isInternal
|
||||
}, [assets]);
|
||||
|
||||
const images: AssetPhoto[] = useMemo(() => {
|
||||
return assets.map((p) => ({
|
||||
...p,
|
||||
src: p.url as string,
|
||||
original: p.previewUrl as string,
|
||||
width: p.exifImageWidth as number,
|
||||
height: p.exifImageHeight as number,
|
||||
orientation: 1,
|
||||
isSelected: selectedIds.includes(p.id),
|
||||
isVideo: p.type === "VIDEO",
|
||||
duration: p.duration != null ? String(p.duration) : undefined,
|
||||
}));
|
||||
}, [assets, selectedIds, exImmichUrl]);
|
||||
return assets
|
||||
.filter((p) => !deletedIds.has(p.id))
|
||||
.map((p) => ({
|
||||
...p,
|
||||
src: p.url as string,
|
||||
original: p.previewUrl as string,
|
||||
width: p.exifImageWidth as number,
|
||||
height: p.exifImageHeight as number,
|
||||
orientation: 1,
|
||||
isSelected: selectedIds.includes(p.id),
|
||||
isVideo: p.type === "VIDEO",
|
||||
duration: p.duration != null ? String(p.duration) : undefined,
|
||||
}));
|
||||
}, [assets, selectedIds, deletedIds]);
|
||||
|
||||
const handleEsc = (event: KeyboardEvent) => {
|
||||
if (event.key === "Escape") {
|
||||
@@ -242,20 +257,15 @@ const AssetGrid = forwardRef<AssetGridRef, AssetGridProps>(({ assets, isInternal
|
||||
>
|
||||
<ExternalLink className="h-6 w-6 text-white" />
|
||||
</button>,
|
||||
...(onDeleteAsset ? [
|
||||
<button
|
||||
key="delete"
|
||||
type="button"
|
||||
className="yarl__button"
|
||||
title="Delete"
|
||||
onClick={() => {
|
||||
onDeleteAsset(currentAsset.id);
|
||||
setIndex(-1);
|
||||
}}
|
||||
>
|
||||
<Trash2 className="h-6 w-6 text-white" />
|
||||
</button>,
|
||||
] : []),
|
||||
<button
|
||||
key="delete"
|
||||
type="button"
|
||||
className="yarl__button"
|
||||
title="Delete"
|
||||
onClick={() => setDeleteConfirmOpen(true)}
|
||||
>
|
||||
<Trash2 className="h-6 w-6 text-white" />
|
||||
</button>,
|
||||
];
|
||||
}, [currentAsset, showInfoPanel, onDeleteAsset, onFavoriteAsset, handleOpenInImmich, favoriteIds, handleToggleFavorite]);
|
||||
|
||||
@@ -280,7 +290,7 @@ const AssetGrid = forwardRef<AssetGridRef, AssetGridProps>(({ assets, isInternal
|
||||
render={{
|
||||
slideContainer: ({ children }) => (
|
||||
<div className="flex h-full w-full">
|
||||
<div className="flex-1 flex items-center justify-center overflow-hidden">
|
||||
<div className="flex-1 overflow-hidden">
|
||||
{children}
|
||||
</div>
|
||||
{showInfoPanel && currentAsset && (
|
||||
@@ -295,8 +305,47 @@ const AssetGrid = forwardRef<AssetGridRef, AssetGridProps>(({ assets, isInternal
|
||||
container: {
|
||||
backgroundColor: "rgba(0, 0, 0, 0.95)",
|
||||
},
|
||||
slide: {
|
||||
padding: 0,
|
||||
},
|
||||
}}
|
||||
/>
|
||||
<AlertDialogPrimitive.Root open={deleteConfirmOpen} onOpenChange={setDeleteConfirmOpen}>
|
||||
<AlertDialogPortal>
|
||||
<AlertDialogOverlay className="!z-[10000]" />
|
||||
<AlertDialogPrimitive.Content className="fixed left-[50%] top-[50%] z-[10001] 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">
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Delete asset?</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
This will permanently delete{currentAsset ? ` "${currentAsset.originalFileName}"` : " this asset"}. This action cannot be undone.
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel onClick={() => setDeleteConfirmOpen(false)}>Cancel</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
variant="destructive"
|
||||
onClick={async () => {
|
||||
if (currentAsset) {
|
||||
try {
|
||||
await deleteAssets([currentAsset.id]);
|
||||
setDeletedIds((prev) => new Set(prev).add(currentAsset.id));
|
||||
onDeleteAsset?.(currentAsset.id);
|
||||
toast({ title: "Deleted", description: `"${currentAsset.originalFileName}" deleted.` });
|
||||
setIndex(-1);
|
||||
} catch {
|
||||
toast({ title: "Error", description: "Failed to delete asset.", variant: "destructive" });
|
||||
}
|
||||
}
|
||||
setDeleteConfirmOpen(false);
|
||||
}}
|
||||
>
|
||||
Delete
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogPrimitive.Content>
|
||||
</AlertDialogPortal>
|
||||
</AlertDialogPrimitive.Root>
|
||||
|
||||
<RowsPhotoAlbum
|
||||
photos={images}
|
||||
targetRowHeight={150}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import { ENV } from "@/config/environment";
|
||||
import { appDb } from "@/db";
|
||||
import { settings } from "@/db/schema/settings.schema";
|
||||
import { getCurrentUser } from "@/handlers/serverUtils/user.utils";
|
||||
import { getUserHeaders } from "@/helpers/user.helper";
|
||||
import { and, eq } from "drizzle-orm";
|
||||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
const WORKFLOW_API_KEY_SETTING = "workflow_api_key";
|
||||
const WORKFLOW_KEY_NAME = "Power Tools Workflow Key";
|
||||
const WORKFLOW_PERMISSIONS = [
|
||||
"asset.read",
|
||||
"asset.update",
|
||||
"album.read",
|
||||
"album.create",
|
||||
"album.update",
|
||||
"tag.create",
|
||||
];
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
if (req.method !== "POST") return res.status(405).json({ message: "Method not allowed" });
|
||||
|
||||
const currentUser = await getCurrentUser(req);
|
||||
if (!currentUser) return res.status(401).json({ message: "Unauthorized" });
|
||||
|
||||
// Create a new API key in Immich with workflow permissions
|
||||
const immichRes = await fetch(`${ENV.IMMICH_URL}/api/api-keys`, {
|
||||
method: "POST",
|
||||
headers: getUserHeaders(currentUser, { "Content-Type": "application/json" }),
|
||||
body: JSON.stringify({ name: WORKFLOW_KEY_NAME, permissions: WORKFLOW_PERMISSIONS }),
|
||||
});
|
||||
|
||||
if (!immichRes.ok) {
|
||||
const err = await immichRes.json().catch(() => ({}));
|
||||
return res.status(immichRes.status).json({ message: err.message ?? "Failed to create API key in Immich" });
|
||||
}
|
||||
|
||||
const { secret } = await immichRes.json();
|
||||
|
||||
// Save the secret to the KV settings store as workflow_api_key
|
||||
const [existing] = await appDb
|
||||
.select()
|
||||
.from(settings)
|
||||
.where(and(eq(settings.key, WORKFLOW_API_KEY_SETTING), eq(settings.ownerId, currentUser.id)));
|
||||
|
||||
if (existing) {
|
||||
await appDb.update(settings).set({ value: secret }).where(eq(settings.id, existing.id));
|
||||
} else {
|
||||
await appDb.insert(settings).values({ key: WORKFLOW_API_KEY_SETTING, value: secret, ownerId: currentUser.id });
|
||||
}
|
||||
|
||||
return res.status(200).json({ success: true });
|
||||
}
|
||||
@@ -30,7 +30,8 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { ASSET_THUMBNAIL_PATH } from "@/config/routes";
|
||||
import { IWorkflowRun } from "@/types/workflow";
|
||||
import { ArrowLeft, Play, Save, Clock, Webhook, History, ChevronUp, ChevronDown, Bug, TriangleAlert } from "lucide-react";
|
||||
import { ArrowLeft, Play, Save, Clock, Webhook, History, ChevronUp, ChevronDown, Bug, TriangleAlert, Wand2 } from "lucide-react";
|
||||
import Head from "next/head";
|
||||
import { format } from "date-fns";
|
||||
import Link from "next/link";
|
||||
import Loader from "@/components/ui/loader";
|
||||
@@ -231,6 +232,7 @@ function WorkflowEditorInner() {
|
||||
const [showRuns, setShowRuns] = useState(false);
|
||||
const [expandedRunId, setExpandedRunId] = useState<string | null>(null);
|
||||
const [hasApiKey, setHasApiKey] = useState<boolean | null>(null);
|
||||
const [generatingKey, setGeneratingKey] = useState(false);
|
||||
|
||||
const [nodes, setNodes, onNodesChange] = useNodesState([] as Node[]);
|
||||
const [edges, setEdges, onEdgesChange] = useEdgesState([] as Edge[]);
|
||||
@@ -259,6 +261,19 @@ function WorkflowEditorInner() {
|
||||
.catch(() => setHasApiKey(false));
|
||||
}, [id]);
|
||||
|
||||
const handleGenerateApiKey = async () => {
|
||||
setGeneratingKey(true);
|
||||
try {
|
||||
await API.post("/api/settings/generate-workflow-api-key", {});
|
||||
setHasApiKey(true);
|
||||
hotToast.success("Workflow API key created and saved");
|
||||
} catch (err: any) {
|
||||
hotToast.error(err?.message ?? "Failed to create API key");
|
||||
} finally {
|
||||
setGeneratingKey(false);
|
||||
}
|
||||
};
|
||||
|
||||
const onConnect = useCallback((connection: Connection) => {
|
||||
setEdges((eds) => addEdge({ ...connection, animated: true }, eds));
|
||||
}, [setEdges]);
|
||||
@@ -421,11 +436,16 @@ function WorkflowEditorInner() {
|
||||
|
||||
return (
|
||||
<div className="flex flex-col h-screen">
|
||||
<Head>
|
||||
<title>{workflowName ? `${workflowName} — Workflow` : "Workflow"}</title>
|
||||
</Head>
|
||||
{/* Top bar */}
|
||||
<div className="h-12 border-b flex items-center gap-3 px-4 bg-background shrink-0">
|
||||
<Link href="/workflows" className="text-muted-foreground hover:text-foreground">
|
||||
<ArrowLeft className="h-4 w-4" />
|
||||
</Link>
|
||||
<span className="text-sm text-muted-foreground hidden sm:inline">Workflow</span>
|
||||
<span className="text-muted-foreground hidden sm:inline">/</span>
|
||||
<Input
|
||||
className="h-8 w-64 text-sm font-medium"
|
||||
value={workflowName}
|
||||
@@ -501,9 +521,18 @@ function WorkflowEditorInner() {
|
||||
<li>- <strong>tag.create</strong> — Create and assign tags</li>
|
||||
</ul>
|
||||
</div>
|
||||
<Button
|
||||
size="sm"
|
||||
className="w-full h-7 text-xs"
|
||||
onClick={handleGenerateApiKey}
|
||||
disabled={generatingKey}
|
||||
>
|
||||
<Wand2 className="h-3 w-3 mr-1" />
|
||||
{generatingKey ? "Creating..." : "Generate automatically"}
|
||||
</Button>
|
||||
<Link href="/settings" className="block">
|
||||
<Button size="sm" className="w-full h-7 text-xs">
|
||||
Configure in Settings
|
||||
<Button size="sm" variant="outline" className="w-full h-7 text-xs">
|
||||
Configure manually in Settings
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
@@ -101,6 +101,14 @@
|
||||
}
|
||||
|
||||
|
||||
.react-photo-album--photo a[href] {
|
||||
opacity: 0;
|
||||
transition: opacity 0.15s ease;
|
||||
}
|
||||
.react-photo-album--photo:hover a[href] {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.leaflet-tile-pane {
|
||||
z-index: 1 !important;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user