Skip to content

Commit d88f36b

Browse files
feat(ui): use updated boards data
- Update tooltips to use counts in the DTO - Remove unused `getBoardImagesTotal` and `getBoardAssetsTotal` queries, which were just abusing the list endpoint to get totals... - Remove extraneous optimistic update in invocation complete listener
1 parent 994a8f7 commit d88f36b

File tree

7 files changed

+49
-64
lines changed

7 files changed

+49
-64
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { useTranslation } from 'react-i18next';
2+
3+
type Props = {
4+
imageCount: number;
5+
assetCount: number;
6+
isArchived: boolean;
7+
};
8+
9+
export const BoardTotalsTooltip = ({ imageCount, assetCount, isArchived }: Props) => {
10+
const { t } = useTranslation();
11+
return `${t('boards.imagesWithCount', { count: imageCount })}, ${t('boards.assetsWithCount', { count: assetCount })}${isArchived ? ` (${t('boards.archived')})` : ''}`;
12+
};

Diff for: invokeai/frontend/web/src/features/gallery/components/Boards/BoardsList/GalleryBoard.tsx

+14-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import IAIDroppable from 'common/components/IAIDroppable';
1717
import type { AddToBoardDropData } from 'features/dnd/types';
1818
import { AutoAddBadge } from 'features/gallery/components/Boards/AutoAddBadge';
1919
import BoardContextMenu from 'features/gallery/components/Boards/BoardContextMenu';
20-
import { BoardTooltip } from 'features/gallery/components/Boards/BoardsList/BoardTooltip';
20+
import { BoardTotalsTooltip } from 'features/gallery/components/Boards/BoardsList/BoardTotalsTooltip';
2121
import {
2222
selectAutoAddBoardId,
2323
selectAutoAssignBoardOnClick,
@@ -119,7 +119,18 @@ const GalleryBoard = ({ board, isSelected }: GalleryBoardProps) => {
119119
return (
120120
<BoardContextMenu board={board}>
121121
{(ref) => (
122-
<Tooltip label={<BoardTooltip board={board} />} openDelay={1000} placement="left" closeOnScroll p={2}>
122+
<Tooltip
123+
label={
124+
<BoardTotalsTooltip
125+
imageCount={board.image_count}
126+
assetCount={board.asset_count}
127+
isArchived={Boolean(board.archived)}
128+
/>
129+
}
130+
openDelay={1000}
131+
placement="left"
132+
closeOnScroll
133+
>
123134
<Flex
124135
position="relative"
125136
ref={ref}
@@ -167,7 +178,7 @@ const GalleryBoard = ({ board, isSelected }: GalleryBoardProps) => {
167178
</Editable>
168179
{autoAddBoardId === board.board_id && !editingDisclosure.isOpen && <AutoAddBadge />}
169180
{board.archived && !editingDisclosure.isOpen && <Icon as={PiArchiveBold} fill="base.300" />}
170-
{!editingDisclosure.isOpen && <Text variant="subtext">{board.image_count}</Text>}
181+
{!editingDisclosure.isOpen && <Text variant="subtext">{board.image_count + board.asset_count}</Text>}
171182

172183
<IAIDroppable data={droppableData} dropLabel={t('unifiedCanvas.move')} />
173184
</Flex>

Diff for: invokeai/frontend/web/src/features/gallery/components/Boards/BoardsList/NoBoardBoard.tsx

+16-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
44
import IAIDroppable from 'common/components/IAIDroppable';
55
import type { RemoveFromBoardDropData } from 'features/dnd/types';
66
import { AutoAddBadge } from 'features/gallery/components/Boards/AutoAddBadge';
7-
import { BoardTooltip } from 'features/gallery/components/Boards/BoardsList/BoardTooltip';
7+
import { BoardTotalsTooltip } from 'features/gallery/components/Boards/BoardsList/BoardTotalsTooltip';
88
import NoBoardBoardContextMenu from 'features/gallery/components/Boards/NoBoardBoardContextMenu';
99
import {
1010
selectAutoAddBoardId,
@@ -14,7 +14,7 @@ import {
1414
import { autoAddBoardIdChanged, boardIdSelected } from 'features/gallery/store/gallerySlice';
1515
import { memo, useCallback, useMemo } from 'react';
1616
import { useTranslation } from 'react-i18next';
17-
import { useGetBoardImagesTotalQuery } from 'services/api/endpoints/boards';
17+
import { useGetUncategorizedImageCountsQuery } from 'services/api/endpoints/boards';
1818
import { useBoardName } from 'services/api/hooks/useBoardName';
1919

2020
interface Props {
@@ -27,11 +27,7 @@ const _hover: SystemStyleObject = {
2727

2828
const NoBoardBoard = memo(({ isSelected }: Props) => {
2929
const dispatch = useAppDispatch();
30-
const { imagesTotal } = useGetBoardImagesTotalQuery('none', {
31-
selectFromResult: ({ data }) => {
32-
return { imagesTotal: data?.total ?? 0 };
33-
},
34-
});
30+
const { data } = useGetUncategorizedImageCountsQuery();
3531
const autoAddBoardId = useAppSelector(selectAutoAddBoardId);
3632
const autoAssignBoardOnClick = useAppSelector(selectAutoAssignBoardOnClick);
3733
const boardSearchText = useAppSelector(selectBoardSearchText);
@@ -60,7 +56,18 @@ const NoBoardBoard = memo(({ isSelected }: Props) => {
6056
return (
6157
<NoBoardBoardContextMenu>
6258
{(ref) => (
63-
<Tooltip label={<BoardTooltip board={null} />} openDelay={1000} placement="left" closeOnScroll>
59+
<Tooltip
60+
label={
61+
<BoardTotalsTooltip
62+
imageCount={data?.image_count ?? 0}
63+
assetCount={data?.asset_count ?? 0}
64+
isArchived={false}
65+
/>
66+
}
67+
openDelay={1000}
68+
placement="left"
69+
closeOnScroll
70+
>
6471
<Flex
6572
position="relative"
6673
ref={ref}
@@ -91,7 +98,7 @@ const NoBoardBoard = memo(({ isSelected }: Props) => {
9198
{boardName}
9299
</Text>
93100
{autoAddBoardId === 'none' && <AutoAddBadge />}
94-
<Text variant="subtext">{imagesTotal}</Text>
101+
<Text variant="subtext">{(data?.image_count ?? 0) + (data?.asset_count ?? 0)}</Text>
95102
<IAIDroppable data={droppableData} dropLabel={t('unifiedCanvas.move')} />
96103
</Flex>
97104
</Tooltip>

Diff for: invokeai/frontend/web/src/services/api/endpoints/boards.ts

+6-42
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
import { ASSETS_CATEGORIES, IMAGE_CATEGORIES } from 'features/gallery/store/types';
2-
import type {
3-
BoardDTO,
4-
CreateBoardArg,
5-
ListBoardsArgs,
6-
OffsetPaginatedResults_ImageDTO_,
7-
UpdateBoardArg,
8-
} from 'services/api/types';
9-
import { getListImagesUrl } from 'services/api/util';
1+
import type { BoardDTO, CreateBoardArg, ListBoardsArgs, S, UpdateBoardArg } from 'services/api/types';
102

113
import type { ApiTagDescription } from '..';
124
import { api, buildV1Url, LIST_TAG } from '..';
@@ -55,38 +47,11 @@ export const boardsApi = api.injectEndpoints({
5547
keepUnusedDataFor: 0,
5648
}),
5749

58-
getBoardImagesTotal: build.query<{ total: number }, string | undefined>({
59-
query: (board_id) => ({
60-
url: getListImagesUrl({
61-
board_id: board_id ?? 'none',
62-
categories: IMAGE_CATEGORIES,
63-
is_intermediate: false,
64-
limit: 0,
65-
offset: 0,
66-
}),
67-
method: 'GET',
50+
getUncategorizedImageCounts: build.query<S['UncategorizedImageCounts'], void>({
51+
query: () => ({
52+
url: buildBoardsUrl('uncategorized/counts'),
6853
}),
69-
providesTags: (result, error, arg) => [{ type: 'BoardImagesTotal', id: arg ?? 'none' }, 'FetchOnReconnect'],
70-
transformResponse: (response: OffsetPaginatedResults_ImageDTO_) => {
71-
return { total: response.total };
72-
},
73-
}),
74-
75-
getBoardAssetsTotal: build.query<{ total: number }, string | undefined>({
76-
query: (board_id) => ({
77-
url: getListImagesUrl({
78-
board_id: board_id ?? 'none',
79-
categories: ASSETS_CATEGORIES,
80-
is_intermediate: false,
81-
limit: 0,
82-
offset: 0,
83-
}),
84-
method: 'GET',
85-
}),
86-
providesTags: (result, error, arg) => [{ type: 'BoardAssetsTotal', id: arg ?? 'none' }, 'FetchOnReconnect'],
87-
transformResponse: (response: OffsetPaginatedResults_ImageDTO_) => {
88-
return { total: response.total };
89-
},
54+
providesTags: ['UncategorizedImageCounts', { type: 'Board', id: LIST_TAG }, { type: 'Board', id: 'none' }],
9055
}),
9156

9257
/**
@@ -124,9 +89,8 @@ export const boardsApi = api.injectEndpoints({
12489

12590
export const {
12691
useListAllBoardsQuery,
127-
useGetBoardImagesTotalQuery,
128-
useGetBoardAssetsTotalQuery,
12992
useCreateBoardMutation,
13093
useUpdateBoardMutation,
13194
useListAllImageNamesForBoardQuery,
95+
useGetUncategorizedImageCountsQuery,
13296
} = boardsApi;

Diff for: invokeai/frontend/web/src/services/api/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const tagTypes = [
4646
// This is invalidated on reconnect. It should be used for queries that have changing data,
4747
// especially related to the queue and generation.
4848
'FetchOnReconnect',
49+
'UncategorizedImageCounts',
4950
] as const;
5051
export type ApiTagDescription = TagDescription<(typeof tagTypes)[number]>;
5152
export const LIST_TAG = 'LIST';

Diff for: invokeai/frontend/web/src/services/api/types.ts

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export type AppDependencyVersions = S['AppDependencyVersions'];
3737
export type ImageDTO = S['ImageDTO'];
3838
export type BoardDTO = S['BoardDTO'];
3939
export type ImageCategory = S['ImageCategory'];
40-
export type OffsetPaginatedResults_ImageDTO_ = S['OffsetPaginatedResults_ImageDTO_'];
4140

4241
// Models
4342
export type ModelType = S['ModelType'];

Diff for: invokeai/frontend/web/src/services/events/onInvocationComplete.tsx

-9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { stagingAreaImageStaged } from 'features/controlLayers/store/canvasStagi
66
import { boardIdSelected, galleryViewChanged, imageSelected, offsetChanged } from 'features/gallery/store/gallerySlice';
77
import { $nodeExecutionStates, upsertExecutionState } from 'features/nodes/hooks/useExecutionState';
88
import { zNodeStatus } from 'features/nodes/types/invocation';
9-
import { boardsApi } from 'services/api/endpoints/boards';
109
import { getImageDTOSafe, imagesApi } from 'services/api/endpoints/images';
1110
import type { ImageDTO, S } from 'services/api/types';
1211
import { getCategories, getListImagesUrl } from 'services/api/util';
@@ -31,14 +30,6 @@ export const buildOnInvocationComplete = (getState: () => RootState, dispatch: A
3130
return;
3231
}
3332

34-
// update the total images for the board
35-
dispatch(
36-
boardsApi.util.updateQueryData('getBoardImagesTotal', imageDTO.board_id ?? 'none', (draft) => {
37-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
38-
draft.total += 1;
39-
})
40-
);
41-
4233
dispatch(
4334
imagesApi.util.invalidateTags([
4435
{ type: 'Board', id: imageDTO.board_id ?? 'none' },

0 commit comments

Comments
 (0)