Merge pull request #301 from jonvdveen/feat/remove-tag-action
feat: Remove Tag workflow action to complement Add Tag
This commit is contained in:
5 files changed
+29
-5
No files matched your search
@@ -27,6 +27,7 @@ const actionItems: PaletteItem[] = [
|
||||
{ type: "action", subType: "unfavorite", label: "Unfavorite", icon: HeartOff, color: "text-purple-500" },
|
||||
{ type: "action", subType: "archive", label: "Archive", icon: Archive, color: "text-purple-500" },
|
||||
{ type: "action", subType: "tag", label: "Add Tag", icon: Tag, color: "text-purple-500" },
|
||||
{ type: "action", subType: "remove_tag", label: "Remove Tag", icon: Tag, color: "text-purple-500" },
|
||||
];
|
||||
|
||||
function PaletteGroup({ title, items }: { title: string; items: PaletteItem[] }) {
|
||||
|
||||
@@ -115,7 +115,7 @@ export default function ActionConfig({ subType, config, onChange }: ActionConfig
|
||||
);
|
||||
}
|
||||
|
||||
if (subType === "tag") {
|
||||
if (subType === "tag" || subType === "remove_tag") {
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<Label className="text-xs">Tag Name</Label>
|
||||
@@ -125,6 +125,9 @@ export default function ActionConfig({ subType, config, onChange }: ActionConfig
|
||||
value={config.tagName || ""}
|
||||
onChange={(e) => onChange({ ...config, tagName: e.target.value })}
|
||||
/>
|
||||
{subType === "remove_tag" && (
|
||||
<p className="text-[10px] text-muted-foreground">Removes this tag from matched assets. If the tag doesn't exist, nothing happens.</p>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ const actionIcons: Record<string, any> = {
|
||||
unfavorite: HeartOff,
|
||||
archive: Archive,
|
||||
tag: Tag,
|
||||
remove_tag: Tag,
|
||||
};
|
||||
|
||||
const actionLabels: Record<string, string> = {
|
||||
@@ -19,6 +20,7 @@ const actionLabels: Record<string, string> = {
|
||||
unfavorite: "Unfavorite",
|
||||
archive: "Archive",
|
||||
tag: "Add Tag",
|
||||
remove_tag: "Remove Tag",
|
||||
};
|
||||
|
||||
export default function ActionNode({ data, selected }: NodeProps) {
|
||||
@@ -42,7 +44,7 @@ export default function ActionNode({ data, selected }: NodeProps) {
|
||||
{(subType === "add_to_album" || subType === "remove_from_album") && config.albumName && (
|
||||
<p className="text-[10px] text-muted-foreground truncate max-w-[160px]">{config.albumName}</p>
|
||||
)}
|
||||
{subType === "tag" && config.tagName && (
|
||||
{(subType === "tag" || subType === "remove_tag") && config.tagName && (
|
||||
<p className="text-[10px] text-muted-foreground truncate max-w-[160px]">{config.tagName}</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -6,7 +6,7 @@ import { exif } from "@/schema";
|
||||
import { assets } from "@/schema/assets.schema";
|
||||
import { person } from "@/schema/person.schema";
|
||||
import { assetFaces } from "@/schema/assetFaces.schema";
|
||||
import { eq, and, inArray, sql, desc } from "drizzle-orm";
|
||||
import { eq, and, inArray, desc } from "drizzle-orm";
|
||||
import { IUser } from "@/types/user";
|
||||
import { getUserHeaders } from "@/helpers/user.helper";
|
||||
|
||||
@@ -193,6 +193,24 @@ export async function executeAction(
|
||||
}
|
||||
}
|
||||
|
||||
case "remove_tag": {
|
||||
if (!config.tagName) throw new Error("Tag name is required");
|
||||
try {
|
||||
// Look up the tag via Immich's API (same source of truth the "tag"
|
||||
// action creates/gets from) without creating it — removing a tag
|
||||
// that doesn't exist is a no-op, not an error.
|
||||
const tags = await immichFetch("/tags", "GET", undefined, user);
|
||||
const tag = Array.isArray(tags) ? tags.find((t: any) => t.value === config.tagName) : undefined;
|
||||
if (!tag) {
|
||||
return { action: "remove_tag", assetsProcessed: 0 };
|
||||
}
|
||||
await immichFetch(`/tags/${tag.id}/assets`, "DELETE", { ids: assetIds }, user);
|
||||
return { action: "remove_tag", assetsProcessed: assetIds.length };
|
||||
} catch (e: any) {
|
||||
return { action: "remove_tag", assetsProcessed: 0, error: e.message };
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
return { action: subType, assetsProcessed: 0, error: `Unknown action: ${subType}` };
|
||||
}
|
||||
|
||||
@@ -135,11 +135,11 @@ function AnnotatedActionNode({ data }: NodeProps) {
|
||||
const step = data.runStep as any;
|
||||
const icons: Record<string, any> = {
|
||||
create_album: FolderPlus, add_to_album: FolderInput, remove_from_album: FolderMinus,
|
||||
favorite: Heart, unfavorite: HeartOff, archive: Archive, tag: Tag,
|
||||
favorite: Heart, unfavorite: HeartOff, archive: Archive, tag: Tag, remove_tag: Tag,
|
||||
};
|
||||
const labels: Record<string, string> = {
|
||||
create_album: "Create Album", add_to_album: "Add to Album", remove_from_album: "Remove from Album",
|
||||
favorite: "Favorite", unfavorite: "Unfavorite", archive: "Archive", tag: "Add Tag",
|
||||
favorite: "Favorite", unfavorite: "Unfavorite", archive: "Archive", tag: "Add Tag", remove_tag: "Remove Tag",
|
||||
};
|
||||
const Icon = icons[subType] || FolderPlus;
|
||||
const isDryRun = step?.detail?.includes("DRY RUN");
|
||||
|
||||
Reference in new issue
Block a user