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(gallery): harden canvas import feedback

joshistoast97e7501f765e
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.json
index 3f28d0c58c..caab451537 100644
--- a/invokeai/frontend/webv2/public/locales/en.json
+++ b/invokeai/frontend/webv2/public/locales/en.json
@@ -978,7 +978,8 @@
"failed": "Couldn't add images to canvas",
"inpaintMask": "Inpaint Mask",
"newLayerFromImage": "New Layer from Image",
- "partial": "Added {{successCount}} images; {{failedCount}} could not be prepared.",
+ "partial_one": "Added {{successCount}} image; {{failedCount}} could not be prepared.",
+ "partial_other": "Added {{successCount}} images; {{failedCount}} could not be prepared.",
"raster": "Raster Layer",
"regionalGuidance": "Regional Guidance",
"regionalReference": "Regional Reference Image",
diff --git a/invokeai/frontend/webv2/src/workbench/canvas-operations/canvasImportNotice.test.ts b/invokeai/frontend/webv2/src/workbench/canvas-operations/canvasImportNotice.test.ts
index 14ec531f9b..e7951b20c3 100644
--- a/invokeai/frontend/webv2/src/workbench/canvas-operations/canvasImportNotice.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/canvas-operations/canvasImportNotice.test.ts
@@ -13,7 +13,7 @@ describe('getCanvasImportNotice', () => {
});
});
- it('maps a partial import to one aggregate notice', () => {
+ it('maps one successful partial import with the exact pluralization interpolation', () => {
expect(
getCanvasImportNotice({
failedImageNames: ['failed-1.png', 'failed-2.png'],
@@ -22,7 +22,21 @@ describe('getCanvasImportNotice', () => {
})
).toEqual({
kind: 'info',
- options: { failedCount: 2, successCount: 1 },
+ options: { count: 1, failedCount: 2, successCount: 1 },
+ titleKey: 'widgets.canvas.import.partial',
+ });
+ });
+
+ it('maps multiple successful partial imports with the exact pluralization interpolation', () => {
+ expect(
+ getCanvasImportNotice({
+ failedImageNames: ['failed.png'],
+ layerIds: ['layer-1', 'layer-2'],
+ status: 'imported',
+ })
+ ).toEqual({
+ kind: 'info',
+ options: { count: 2, failedCount: 1, successCount: 2 },
titleKey: 'widgets.canvas.import.partial',
});
});
diff --git a/invokeai/frontend/webv2/src/workbench/canvas-operations/canvasImportNotice.ts b/invokeai/frontend/webv2/src/workbench/canvas-operations/canvasImportNotice.ts
index 62f91daa2a..81b7cff372 100644
--- a/invokeai/frontend/webv2/src/workbench/canvas-operations/canvasImportNotice.ts
+++ b/invokeai/frontend/webv2/src/workbench/canvas-operations/canvasImportNotice.ts
@@ -9,7 +9,7 @@ export interface CanvasImportNotice {
| 'widgets.canvas.import.staleDocument'
| 'widgets.canvas.import.staleProject'
| 'widgets.canvas.import.success';
- options?: { count: number } | { failedCount: number; successCount: number };
+ options?: { count: number } | { count: number; failedCount: number; successCount: number };
}
const assertNever = (value: never): never => {
@@ -22,7 +22,11 @@ export const getCanvasImportNotice = (result: ImportGalleryImagesResult): Canvas
if (result.failedImageNames.length > 0) {
return {
kind: 'info',
- options: { failedCount: result.failedImageNames.length, successCount: result.layerIds.length },
+ options: {
+ count: result.layerIds.length,
+ failedCount: result.failedImageNames.length,
+ successCount: result.layerIds.length,
+ },
titleKey: 'widgets.canvas.import.partial',
};
}
diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/canvasImportError.test.ts b/invokeai/frontend/webv2/src/workbench/image-actions/canvasImportError.test.ts
new file mode 100644
index 0000000000..c30fee61b7
--- /dev/null
+++ b/invokeai/frontend/webv2/src/workbench/image-actions/canvasImportError.test.ts
@@ -0,0 +1,27 @@
+import { describe, expect, it, vi } from 'vitest';
+
+import { recordCanvasImportError } from './canvasImportError';
+
+describe('recordCanvasImportError', () => {
+ it('dispatches one localized diagnostic error and no notice', () => {
+ const dispatch = vi.fn();
+
+ recordCanvasImportError({
+ dispatch,
+ error: new Error('resize backend failed'),
+ localizedMessage: "Couldn't add images to canvas",
+ projectId: 'project-1',
+ });
+
+ expect(dispatch).toHaveBeenCalledTimes(1);
+ expect(dispatch).toHaveBeenCalledWith({
+ area: 'image-actions',
+ context: { error: 'resize backend failed' },
+ message: "Couldn't add images to canvas",
+ namespace: 'gallery',
+ projectId: 'project-1',
+ type: 'recordError',
+ });
+ expect(dispatch.mock.calls.some(([action]) => action.type === 'recordNotice')).toBe(false);
+ });
+});
diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/canvasImportError.ts b/invokeai/frontend/webv2/src/workbench/image-actions/canvasImportError.ts
new file mode 100644
index 0000000000..f558b7a82f
--- /dev/null
+++ b/invokeai/frontend/webv2/src/workbench/image-actions/canvasImportError.ts
@@ -0,0 +1,25 @@
+import type { WorkbenchAction } from '@workbench/workbenchState';
+import type { Dispatch } from 'react';
+
+const toErrorMessage = (error: unknown): string => (error instanceof Error ? error.message : String(error));
+
+export const recordCanvasImportError = ({
+ dispatch,
+ error,
+ localizedMessage,
+ projectId,
+}: {
+ dispatch: Dispatch<WorkbenchAction>;
+ error: unknown;
+ localizedMessage: string;
+ projectId?: string;
+}): void => {
+ dispatch({
+ area: 'image-actions',
+ context: { error: toErrorMessage(error) },
+ message: localizedMessage,
+ namespace: 'gallery',
+ projectId,
+ type: 'recordError',
+ });
+};
diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/useImageActions.ts b/invokeai/frontend/webv2/src/workbench/image-actions/useImageActions.ts
index d31273b831..ea4b5d38f7 100644
--- a/invokeai/frontend/webv2/src/workbench/image-actions/useImageActions.ts
+++ b/invokeai/frontend/webv2/src/workbench/image-actions/useImageActions.ts
@@ -30,6 +30,7 @@ import { useWorkbenchStore } from '@workbench/WorkbenchContext';
import { useEffect, useMemo, type Dispatch } from 'react';
import { useTranslation } from 'react-i18next';
+import { recordCanvasImportError } from './canvasImportError';
import { executeImageRecall, getCurrentGenerateValues } from './executeImageRecall';
import {
EMPTY_IMAGE_RECALL_CAPABILITIES,
@@ -287,11 +288,11 @@ export const useImageActions = ({
openWorkbenchWidget('canvas', { preferredRegions: ['center'], requireCenterView: true });
}
} catch (error: unknown) {
- dispatch({
- kind: 'error',
- message: toErrorMessage(error),
- title: t('widgets.canvas.import.failed'),
- type: 'recordNotice',
+ recordCanvasImportError({
+ dispatch,
+ error,
+ localizedMessage: t('widgets.canvas.import.failed'),
+ projectId,
});
}
},