Skip to content

Commit fe24217

Browse files
fix(ui): image usage checks collection fields
When deleting a board w/ images, the image usage checking logic was not checking image collection fields. This could result in a nonexistent image lingering in a node. We already handle single image fields correctly, it's only the image collection fields taht were affected.
1 parent aee8470 commit fe24217

File tree

1 file changed

+18
-6
lines changed
  • invokeai/frontend/web/src/features/deleteImageModal/store

1 file changed

+18
-6
lines changed

invokeai/frontend/web/src/features/deleteImageModal/store/selectors.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { CanvasState } from 'features/controlLayers/store/types';
44
import { selectDeleteImageModalSlice } from 'features/deleteImageModal/store/slice';
55
import { selectNodesSlice } from 'features/nodes/store/selectors';
66
import type { NodesState } from 'features/nodes/store/types';
7-
import { isImageFieldInputInstance } from 'features/nodes/types/field';
7+
import { isImageFieldCollectionInputInstance, isImageFieldInputInstance } from 'features/nodes/types/field';
88
import { isInvocationNode } from 'features/nodes/types/invocation';
99
import type { UpscaleState } from 'features/parameters/store/upscaleSlice';
1010
import { selectUpscaleSlice } from 'features/parameters/store/upscaleSlice';
@@ -13,11 +13,23 @@ import { some } from 'lodash-es';
1313
import type { ImageUsage } from './types';
1414
// TODO(psyche): handle image deletion (canvas staging area?)
1515
export const getImageUsage = (nodes: NodesState, canvas: CanvasState, upscale: UpscaleState, image_name: string) => {
16-
const isNodesImage = nodes.nodes
17-
.filter(isInvocationNode)
18-
.some((node) =>
19-
some(node.data.inputs, (input) => isImageFieldInputInstance(input) && input.value?.image_name === image_name)
20-
);
16+
const isNodesImage = nodes.nodes.filter(isInvocationNode).some((node) =>
17+
some(node.data.inputs, (input) => {
18+
if (isImageFieldInputInstance(input)) {
19+
if (input.value?.image_name === image_name) {
20+
return true;
21+
}
22+
}
23+
24+
if (isImageFieldCollectionInputInstance(input)) {
25+
if (input.value?.some((value) => value?.image_name === image_name)) {
26+
return true;
27+
}
28+
}
29+
30+
return false;
31+
})
32+
);
2133

2234
const isUpscaleImage = upscale.upscaleInitialImage?.image_name === image_name;
2335

0 commit comments

Comments
 (0)