Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

fix(ui): honest uninstall confirmations with workflow counts

joshistoast8a4a76d22a06
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.json
index fb8709659c..2bceca01f8 100644
--- a/invokeai/frontend/webv2/public/locales/en.json
+++ b/invokeai/frontend/webv2/public/locales/en.json
@@ -1238,8 +1238,14 @@
"tryDifferentSearch": "Try a different search.",
"uninstall": "Uninstall",
"uninstallBody": "Remove this pack from the custom nodes directory? A restart is required for removal to fully apply.",
+ "uninstallBodyWithWorkflows_one": "Remove this pack from the custom nodes directory? {{count}} workflow imported by this pack will also be deleted. A restart is required for removal to fully apply.",
+ "uninstallBodyWithWorkflows_other": "Remove this pack from the custom nodes directory? {{count}} workflows imported by this pack will also be deleted. A restart is required for removal to fully apply.",
+ "uninstallFailed": "Uninstall failed",
"uninstallPack": "Uninstall Node Pack",
"uninstallTitle": "Uninstall {{name}}?",
+ "uninstalledDescription": "Restart InvokeAI for node removal to take full effect.",
+ "uninstalledTitle": "Node pack uninstalled",
+ "couldNotUninstall": "Could not uninstall the node pack.",
"uninstalled": "Uninstalled"
},
"launchpad": {
diff --git a/invokeai/frontend/webv2/src/features/nodes/data/api.test.ts b/invokeai/frontend/webv2/src/features/nodes/data/api.test.ts
index 3eccaa814d..981e4fd947 100644
--- a/invokeai/frontend/webv2/src/features/nodes/data/api.test.ts
+++ b/invokeai/frontend/webv2/src/features/nodes/data/api.test.ts
@@ -65,3 +65,23 @@ describe('custom node data adapter', () => {
});
});
});
+
+describe('getPackWorkflowCount', () => {
+ it('queries the pack tag and extracts its count', async () => {
+ adapter.requestJson.mockResolvedValue({ 'node-pack:my-pack': 3 });
+ const { getPackWorkflowCount } = await import('./api');
+ const controller = new AbortController();
+
+ await expect(getPackWorkflowCount('my-pack', controller.signal)).resolves.toBe(3);
+ expect(adapter.requestJson).toHaveBeenCalledWith('/api/v1/workflows/counts_by_tag?tags=node-pack%3Amy-pack', {
+ signal: controller.signal,
+ });
+ });
+
+ it('returns zero when the tag is absent from the response', async () => {
+ adapter.requestJson.mockResolvedValue({});
+ const { getPackWorkflowCount } = await import('./api');
+
+ await expect(getPackWorkflowCount('my-pack')).resolves.toBe(0);
+ });
+});
diff --git a/invokeai/frontend/webv2/src/features/nodes/data/api.ts b/invokeai/frontend/webv2/src/features/nodes/data/api.ts
index 7ace1957db..d7d8ce18a3 100644
--- a/invokeai/frontend/webv2/src/features/nodes/data/api.ts
+++ b/invokeai/frontend/webv2/src/features/nodes/data/api.ts
@@ -41,3 +41,20 @@ export const uninstallCustomNodePack = (packName: string, signal?: AbortSignal):
/** The body's status is prose (e.g. "No custom nodes directory found.") — callers must not assume success. */
export const reloadCustomNodes = (signal?: AbortSignal): Promise<{ status: string }> =>
requestJson<{ status: string }>(`${CUSTOM_NODES_BASE}/reload`, { method: 'POST', signal });
+
+/**
+ * Workflows imported by a pack, counted by its `node-pack:<name>` tag. A
+ * best-effort number for the uninstall confirmation: uninstall deletes by the
+ * manifest-recorded IDs, while this counts by tag, so retagged workflows can
+ * make the two diverge slightly. (Calling the workflows router from here
+ * follows the models feature's relationshipsApi precedent.)
+ */
+export const getPackWorkflowCount = async (packName: string, signal?: AbortSignal): Promise<number> => {
+ const tag = `node-pack:${packName}`;
+ const counts = await requestJson<Record<string, number>>(
+ `/api/v1/workflows/counts_by_tag?tags=${encodeURIComponent(tag)}`,
+ { signal }
+ );
+
+ return counts[tag] ?? 0;
+};
diff --git a/invokeai/frontend/webv2/src/features/nodes/ui/detail/NodePackDetail.tsx b/invokeai/frontend/webv2/src/features/nodes/ui/detail/NodePackDetail.tsx
index 7de2ef8129..b09d82663d 100644
--- a/invokeai/frontend/webv2/src/features/nodes/ui/detail/NodePackDetail.tsx
+++ b/invokeai/frontend/webv2/src/features/nodes/ui/detail/NodePackDetail.tsx
@@ -3,9 +3,9 @@ import type { NodePackInfo } from '@features/nodes/core/catalog';
import { Badge, Box, Flex, HStack, Icon, Spinner, Stack, Text } from '@chakra-ui/react';
import { isProblemPack } from '@features/nodes/core/library';
-import { useNodePackActions } from '@features/nodes/ui/shared/useNodePackActions';
+import { UninstallPackDialog } from '@features/nodes/ui/shared/UninstallPackDialog';
import { ensureInvocationTemplatesLoaded, useInvocationTemplatesSelector } from '@features/workflow/react';
-import { Button, ConfirmDialog } from '@platform/ui';
+import { Button } from '@platform/ui';
import { EmptyState } from '@platform/ui/EmptyState';
import { BlocksIcon, TriangleAlertIcon, Trash2Icon } from 'lucide-react';
import { useEffect, useMemo, useState } from 'react';
@@ -99,40 +99,18 @@ export const NodePackDetail = ({ onUninstalled, pack }: { onUninstalled: () => v
const UninstallButton = ({ onUninstalled, pack }: { onUninstalled: () => void; pack: NodePackInfo }) => {
const { t } = useTranslation();
- const { uninstall } = useNodePackActions();
const [isConfirmOpen, setIsConfirmOpen] = useState(false);
- const [isUninstalling, setIsUninstalling] = useState(false);
-
- const handleUninstall = async () => {
- setIsUninstalling(true);
-
- try {
- await uninstall(pack, onUninstalled);
- } finally {
- setIsUninstalling(false);
- }
- };
return (
<>
- <Button
- colorPalette="red"
- flexShrink={0}
- loading={isUninstalling}
- size="xs"
- variant="outline"
- onClick={() => setIsConfirmOpen(true)}
- >
+ <Button colorPalette="red" flexShrink={0} size="xs" variant="outline" onClick={() => setIsConfirmOpen(true)}>
<Icon as={Trash2Icon} boxSize="3" />
{t('nodes.uninstall')}
</Button>
- <ConfirmDialog
- body={t('nodes.uninstallBody')}
- confirmLabel={t('nodes.uninstallPack')}
- isOpen={isConfirmOpen}
- title={t('nodes.uninstallTitle', { name: pack.name })}
+ <UninstallPackDialog
+ pack={isConfirmOpen ? pack : null}
onClose={() => setIsConfirmOpen(false)}
- onConfirm={handleUninstall}
+ onUninstalled={onUninstalled}
/>
</>
);
diff --git a/invokeai/frontend/webv2/src/features/nodes/ui/library/NodePackContextMenu.tsx b/invokeai/frontend/webv2/src/features/nodes/ui/library/NodePackContextMenu.tsx
index d71cbfafdf..80a8f4ce7e 100644
--- a/invokeai/frontend/webv2/src/features/nodes/ui/library/NodePackContextMenu.tsx
+++ b/invokeai/frontend/webv2/src/features/nodes/ui/library/NodePackContextMenu.tsx
@@ -2,9 +2,10 @@
import type { NodePackInfo } from '@features/nodes/core/catalog';
import { Icon, Menu, Portal } from '@chakra-ui/react';
-import { useNodePackActions } from '@features/nodes/ui/shared/useNodePackActions';
-import { ConfirmDialog, MenuContent } from '@platform/ui';
-import { Trash2Icon } from 'lucide-react';
+import { UninstallPackDialog } from '@features/nodes/ui/shared/UninstallPackDialog';
+import { useNotify } from '@features/nodes/ui/useNodesNotify';
+import { MenuContent } from '@platform/ui';
+import { ClipboardCopyIcon, Trash2Icon } from 'lucide-react';
import { useState } from 'react';
import { useTranslation } from 'react-i18next';
@@ -24,10 +25,19 @@ export const NodePackContextMenu = ({
target: NodePackContextMenuTarget | null;
}) => {
const { t } = useTranslation();
- const { uninstall } = useNodePackActions();
+ const notify = useNotify();
const [pendingUninstall, setPendingUninstall] = useState<NodePackInfo | null>(null);
const pack = target?.pack ?? null;
+ const handleCopyPath = async (path: string) => {
+ try {
+ await navigator.clipboard.writeText(path);
+ notify.success(t('nodes.pathCopied'));
+ } catch {
+ notify.error(t('common.couldNotCopy'));
+ }
+ };
+
return (
<>
<Menu.Root
@@ -49,6 +59,11 @@ export const NodePackContextMenu = ({
<Menu.Positioner>
{pack ? (
<MenuContent minW="12rem">
+ <Menu.Item value="copy-path" onClick={() => void handleCopyPath(pack.path)}>
+ <Icon as={ClipboardCopyIcon} boxSize="3.5" />
+ <Menu.ItemText fontSize="xs">{t('nodes.copyPath')}</Menu.ItemText>
+ </Menu.Item>
+ <Menu.Separator />
<Menu.Item color="fg.error" value="uninstall" onClick={() => setPendingUninstall(pack)}>
<Icon as={Trash2Icon} boxSize="3.5" />
<Menu.ItemText fontSize="xs">{t('nodes.uninstall')}</Menu.ItemText>
@@ -58,19 +73,10 @@ export const NodePackContextMenu = ({
</Menu.Positioner>
</Portal>
</Menu.Root>
- <ConfirmDialog
- body={t('nodes.uninstallBody')}
- confirmLabel={t('nodes.uninstallPack')}
- isOpen={pendingUninstall !== null}
- title={t('nodes.uninstallTitle', { name: pendingUninstall?.name ?? t('nodes.nodePack') })}
+ <UninstallPackDialog
+ pack={pendingUninstall}
onClose={() => setPendingUninstall(null)}
- onConfirm={async () => {
- if (!pendingUninstall) {
- return;
- }
-
- await uninstall(pendingUninstall, onUninstalled);
- }}
+ onUninstalled={onUninstalled}
/>
</>
);
diff --git a/invokeai/frontend/webv2/src/features/nodes/ui/shared/UninstallPackDialog.tsx b/invokeai/frontend/webv2/src/features/nodes/ui/shared/UninstallPackDialog.tsx
new file mode 100644
index 0000000000..1be0e1874e
--- /dev/null
+++ b/invokeai/frontend/webv2/src/features/nodes/ui/shared/UninstallPackDialog.tsx
@@ -0,0 +1,67 @@
+/* eslint-disable react-perf/jsx-no-new-function-as-prop */
+import type { NodePackInfo } from '@features/nodes/core/catalog';
+
+import { getPackWorkflowCount } from '@features/nodes/data/api';
+import { useNodePackActions } from '@features/nodes/ui/shared/useNodePackActions';
+import { captureAccountScope, isAccountScopeCurrent } from '@platform/state/accountLifecycle';
+import { ConfirmDialog } from '@platform/ui';
+import { useEffect, useState } from 'react';
+import { useTranslation } from 'react-i18next';
+
+/**
+ * Shared uninstall confirmation. Uninstalling also deletes the workflows the
+ * pack imported at install time, so the dialog fetches a best-effort count
+ * (by the pack's workflow tag) and says so — the count degrades to the
+ * generic copy when the fetch fails or returns zero.
+ */
+export const UninstallPackDialog = ({
+ onClose,
+ onUninstalled,
+ pack,
+}: {
+ onClose: () => void;
+ onUninstalled?: (packName: string) => void;
+ pack: NodePackInfo | null;
+}) => {
+ const { t } = useTranslation();
+ const { uninstall } = useNodePackActions();
+ // Keyed by pack name so a count fetched for one pack never leaks into
+ // another's dialog; no reset needed when the target changes.
+ const [countState, setCountState] = useState<{ count: number; packName: string } | null>(null);
+
+ useEffect(() => {
+ if (pack === null) {
+ return;
+ }
+
+ const owner = captureAccountScope();
+
+ getPackWorkflowCount(pack.name, owner.signal)
+ .then((count) => {
+ if (isAccountScopeCurrent(owner)) {
+ setCountState({ count, packName: pack.name });
+ }
+ })
+ .catch(() => undefined);
+ }, [pack]);
+
+ const workflowCount = countState !== null && countState.packName === pack?.name ? countState.count : 0;
+
+ return (
+ <ConfirmDialog
+ body={
+ workflowCount > 0 ? t('nodes.uninstallBodyWithWorkflows', { count: workflowCount }) : t('nodes.uninstallBody')
+ }
+ confirmLabel={t('nodes.uninstallPack')}
+ isOpen={pack !== null}
+ title={t('nodes.uninstallTitle', { name: pack?.name ?? t('nodes.nodePack') })}
+ onClose={onClose}
+ onConfirm={async () => {
+ if (pack) {
+ await uninstall(pack, onUninstalled);
+ onClose();
+ }
+ }}
+ />
+ );
+};
diff --git a/invokeai/frontend/webv2/src/features/nodes/ui/shared/useNodePackActions.ts b/invokeai/frontend/webv2/src/features/nodes/ui/shared/useNodePackActions.ts
index b17fd4c536..1c91bcc9e0 100644
--- a/invokeai/frontend/webv2/src/features/nodes/ui/shared/useNodePackActions.ts
+++ b/invokeai/frontend/webv2/src/features/nodes/ui/shared/useNodePackActions.ts
@@ -4,36 +4,33 @@ import { uninstallCustomNodePack } from '@features/nodes/data/api';
import { addCustomNodeInstallLogEntry } from '@features/nodes/data/installLogStore';
import { refreshCustomNodePacks, removeCustomNodePackFromStore } from '@features/nodes/data/nodesStore';
import { useNotify } from '@features/nodes/ui/useNodesNotify';
-import {
- assertAccountScopeCurrent,
- captureAccountScope,
- isAccountScopeCurrent,
-} from '@platform/state/accountLifecycle';
+import { useScopedAction } from '@platform/react/useScopedAction';
+import { assertAccountScopeCurrent } from '@platform/state/accountLifecycle';
import { getApiErrorMessage } from '@platform/transport/http';
+import { useTranslation } from 'react-i18next';
export const useNodePackActions = () => {
+ const { t } = useTranslation();
const notify = useNotify();
+ const { isBusy: isUninstalling, run } = useScopedAction();
- const uninstall = async (pack: NodePackInfo, onUninstalled?: (packName: string) => void) => {
- const owner = captureAccountScope();
+ const uninstall = (pack: NodePackInfo, onUninstalled?: (packName: string) => void) =>
+ run(
+ async (owner) => {
+ const result = await uninstallCustomNodePack(pack.name, owner.signal);
- try {
- const result = await uninstallCustomNodePack(pack.name, owner.signal);
-
- assertAccountScopeCurrent(owner);
- removeCustomNodePackFromStore(pack.name);
- addCustomNodeInstallLogEntry({ message: result.message, name: result.name, status: 'uninstalled' });
- notify.success('Node pack uninstalled', 'Restart InvokeAI for node removal to take full effect.');
- onUninstalled?.(pack.name);
- } catch (error) {
- if (!isAccountScopeCurrent(owner)) {
- return;
+ assertAccountScopeCurrent(owner);
+ removeCustomNodePackFromStore(pack.name);
+ addCustomNodeInstallLogEntry({ message: result.message, name: result.name, status: 'uninstalled' });
+ notify.success(t('nodes.uninstalledTitle'), t('nodes.uninstalledDescription'));
+ onUninstalled?.(pack.name);
+ },
+ (_message, error) => {
+ notify.error(t('nodes.uninstallFailed'), getApiErrorMessage(error, t('nodes.couldNotUninstall')));
+ // The scope is current when onError runs; resync with the backend.
+ void refreshCustomNodePacks();
}
+ );
- notify.error('Uninstall failed', getApiErrorMessage(error, 'Could not uninstall the node pack.'));
- await refreshCustomNodePacks(owner);
- }
- };
-
- return { uninstall };
+ return { isUninstalling, uninstall };
};