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(canvas): define layer filter launch policy

joshistoast859c8051e520
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/layerPropertiesOperation.test.ts b/invokeai/frontend/webv2/src/workbench/widgets/layers/layerPropertiesOperation.test.ts
index 693a1beac9..52ba17f07a 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/layerPropertiesOperation.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/layerPropertiesOperation.test.ts
@@ -2,11 +2,89 @@ import { describe, expect, it, vi } from 'vitest';
import {
closeLayerPropertiesForOperation,
+ getLayerFilterLaunchDisabledReason,
+ getLayerFilterLaunchReasonKey,
getLayerPropertiesOwnershipKey,
isLayerPropertiesOpen,
runLayerFilterOperation,
} from './layerPropertiesOperation';
+describe('getLayerFilterLaunchDisabledReason', () => {
+ it.each([
+ {
+ expected: 'not-ready',
+ input: { hasEngine: false, hasExportableContent: false, isEnabled: true, isLocked: false },
+ scenario: 'missing engine',
+ },
+ {
+ expected: 'disabled',
+ input: { hasEngine: true, hasExportableContent: true, isEnabled: false, isLocked: false },
+ scenario: 'disabled layer',
+ },
+ {
+ expected: 'locked',
+ input: { hasEngine: true, hasExportableContent: true, isEnabled: true, isLocked: true },
+ scenario: 'locked layer',
+ },
+ {
+ expected: 'empty',
+ input: { hasEngine: true, hasExportableContent: false, isEnabled: true, isLocked: false },
+ scenario: 'empty layer',
+ },
+ {
+ expected: null,
+ input: { hasEngine: true, hasExportableContent: true, isEnabled: true, isLocked: false },
+ scenario: 'eligible layer',
+ },
+ ] as const)('returns $expected for $scenario', ({ expected, input }) => {
+ expect(getLayerFilterLaunchDisabledReason(input)).toBe(expected);
+ });
+
+ it.each([
+ ['empty', 'widgets.layers.actions.empty'],
+ ['missing', 'widgets.layers.actions.missing'],
+ ['disabled', 'widgets.layers.actions.disabled'],
+ ['locked', 'widgets.layers.actions.locked'],
+ ['unsupported', 'widgets.layers.actions.unsupported'],
+ ['not-ready', 'widgets.layers.actions.notReady'],
+ ] as const)('maps %s to %s', (reason, key) => {
+ expect(getLayerFilterLaunchReasonKey(reason)).toBe(key);
+ });
+});
+
+describe('runLayerFilterOperation callbacks', () => {
+ it('notifies only the success callback for a started launch', () => {
+ const onOperationStarted = vi.fn();
+ const onOperationRejected = vi.fn();
+
+ expect(runLayerFilterOperation(() => 'started', onOperationStarted, onOperationRejected)).toBe('started');
+ expect(onOperationStarted).toHaveBeenCalledOnce();
+ expect(onOperationRejected).not.toHaveBeenCalled();
+ });
+
+ it.each(['missing', 'disabled', 'locked', 'unsupported', 'not-ready'] as const)(
+ 'notifies rejection for %s without closing properties',
+ (result) => {
+ const onOperationStarted = vi.fn();
+ const onOperationRejected = vi.fn();
+
+ expect(runLayerFilterOperation(() => result, onOperationStarted, onOperationRejected)).toBe(result);
+ expect(onOperationStarted).not.toHaveBeenCalled();
+ expect(onOperationRejected).toHaveBeenCalledOnce();
+ expect(onOperationRejected).toHaveBeenCalledWith(result);
+ }
+ );
+
+ it('does not report rejection when no engine supplied a launch result', () => {
+ const onOperationStarted = vi.fn();
+ const onOperationRejected = vi.fn();
+
+ expect(runLayerFilterOperation(() => undefined, onOperationStarted, onOperationRejected)).toBeUndefined();
+ expect(onOperationStarted).not.toHaveBeenCalled();
+ expect(onOperationRejected).not.toHaveBeenCalled();
+ });
+});
+
describe('closeLayerPropertiesForOperation', () => {
it('uses separate ownership across editing-lock transitions so trigger state cannot reopen after cancel', () => {
expect(getLayerPropertiesOwnershipKey(false)).not.toBe(getLayerPropertiesOwnershipKey(true));
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/layerPropertiesOperation.ts b/invokeai/frontend/webv2/src/workbench/widgets/layers/layerPropertiesOperation.ts
index 9229ccd344..0ef74e6f3b 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/layerPropertiesOperation.ts
+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/layerPropertiesOperation.ts
@@ -5,6 +5,49 @@ interface LayerPropertiesOpenOwnership {
triggerOpen: boolean;
}
+export type LayerFilterLaunchRejectedResult = Exclude<StartFilterOperationResult, 'started'>;
+export type LayerFilterLaunchDisabledReason = LayerFilterLaunchRejectedResult | 'empty';
+
+export interface LayerFilterLaunchEligibilityInput {
+ hasEngine: boolean;
+ hasExportableContent: boolean;
+ isEnabled: boolean;
+ isLocked: boolean;
+}
+
+const LAYER_FILTER_LAUNCH_REASON_KEYS: Record<LayerFilterLaunchDisabledReason, string> = {
+ disabled: 'widgets.layers.actions.disabled',
+ empty: 'widgets.layers.actions.empty',
+ locked: 'widgets.layers.actions.locked',
+ missing: 'widgets.layers.actions.missing',
+ 'not-ready': 'widgets.layers.actions.notReady',
+ unsupported: 'widgets.layers.actions.unsupported',
+};
+
+export const getLayerFilterLaunchDisabledReason = ({
+ hasEngine,
+ hasExportableContent,
+ isEnabled,
+ isLocked,
+}: LayerFilterLaunchEligibilityInput): LayerFilterLaunchDisabledReason | null => {
+ if (!hasEngine) {
+ return 'not-ready';
+ }
+ if (!isEnabled) {
+ return 'disabled';
+ }
+ if (isLocked) {
+ return 'locked';
+ }
+ if (!hasExportableContent) {
+ return 'empty';
+ }
+ return null;
+};
+
+export const getLayerFilterLaunchReasonKey = (reason: LayerFilterLaunchDisabledReason): string =>
+ LAYER_FILTER_LAUNCH_REASON_KEYS[reason];
+
export const getLayerPropertiesOwnershipKey = (editingLocked: boolean): 'editable' | 'locked' =>
editingLocked ? 'locked' : 'editable';
@@ -19,11 +62,14 @@ export const closeLayerPropertiesForOperation = ({ requestToken }: LayerProperti
export const runLayerFilterOperation = (
launch: () => StartFilterOperationResult | undefined,
- onOperationStarted: () => void
+ onOperationStarted: () => void,
+ onOperationRejected?: (result: LayerFilterLaunchRejectedResult) => void
): StartFilterOperationResult | undefined => {
const result = launch();
if (result === 'started') {
onOperationStarted();
+ } else if (result !== undefined) {
+ onOperationRejected?.(result);
}
return result;
};