Skip to content

Commit c78eac6

Browse files
Mary Hipppsychedelicious
authored andcommitted
update workflow tag/categories so that we can pass in 1+ selected tags to start with
1 parent 05de3b7 commit c78eac6

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

invokeai/frontend/web/src/features/nodes/components/sidePanel/workflow/WorkflowLibrary/WorkflowLibrarySideNav.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
import { NewWorkflowButton } from 'features/workflowLibrary/components/NewWorkflowButton';
2828
import { UploadWorkflowButton } from 'features/workflowLibrary/components/UploadWorkflowButton';
2929
import { OverlayScrollbarsComponent } from 'overlayscrollbars-react';
30-
import { memo, useCallback, useMemo } from 'react';
30+
import { memo, useCallback, useEffect, useMemo } from 'react';
3131
import { useTranslation } from 'react-i18next';
3232
import { PiArrowCounterClockwiseBold, PiUsersBold } from 'react-icons/pi';
3333
import { useDispatch } from 'react-redux';
@@ -43,6 +43,8 @@ export const WorkflowLibrarySideNav = () => {
4343
dispatch(workflowLibraryTagsReset());
4444
}, [dispatch]);
4545

46+
useEffect(() => {}, [selectedTags, dispatch]);
47+
4648
return (
4749
<Flex h="full" minH={0} overflow="hidden" flexDir="column" w={64} gap={0}>
4850
<Flex flexDir="column" w="full" pb={2}>
@@ -121,7 +123,7 @@ const useCountForIndividualTag = (tag: string) => {
121123
const queryArg = useMemo(
122124
() =>
123125
({
124-
tags: allTags,
126+
tags: allTags.map((tag) => tag.label),
125127
categories: ['default'],
126128
}) satisfies Parameters<typeof useGetCountsByTagQuery>[0],
127129
[allTags]
@@ -146,7 +148,7 @@ const useCountForTagCategory = (tagCategory: WorkflowTagCategory) => {
146148
const queryArg = useMemo(
147149
() =>
148150
({
149-
tags: allTags,
151+
tags: allTags.map((tag) => tag.label),
150152
categories: ['default'], // We only allow filtering by tag for default workflows
151153
}) satisfies Parameters<typeof useGetCountsByTagQuery>[0],
152154
[allTags]
@@ -159,7 +161,7 @@ const useCountForTagCategory = (tagCategory: WorkflowTagCategory) => {
159161
return { count: 0 };
160162
}
161163
return {
162-
count: tagCategory.tags.reduce((acc, tag) => acc + (data[tag] ?? 0), 0),
164+
count: tagCategory.tags.reduce((acc, tag) => acc + (data[tag.label] ?? 0), 0),
163165
};
164166
},
165167
}) satisfies Parameters<typeof useGetCountsByTagQuery>[1],
@@ -197,6 +199,15 @@ WorkflowLibraryViewButton.displayName = 'NavButton';
197199
const TagCategory = memo(({ tagCategory }: { tagCategory: WorkflowTagCategory }) => {
198200
const { t } = useTranslation();
199201
const count = useCountForTagCategory(tagCategory);
202+
const dispatch = useAppDispatch();
203+
204+
useEffect(() => {
205+
for (const tag of tagCategory.tags) {
206+
if (tag.selected) {
207+
dispatch(workflowLibraryTagToggled(tag.label));
208+
}
209+
}
210+
}, [count, tagCategory.tags, dispatch]);
200211

201212
if (count === 0) {
202213
return null;
@@ -209,7 +220,7 @@ const TagCategory = memo(({ tagCategory }: { tagCategory: WorkflowTagCategory })
209220
</Text>
210221
<Flex flexDir="column" gap={2} pl={4}>
211222
{tagCategory.tags.map((tag) => (
212-
<TagCheckbox key={tag} tag={tag} />
223+
<TagCheckbox key={tag.label} tag={tag.label} />
213224
))}
214225
</Flex>
215226
</Flex>

invokeai/frontend/web/src/features/nodes/store/workflowLibrarySlice.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,21 @@ export const selectWorkflowLibraryView = createWorkflowLibrarySelector(({ view }
9292
export const DEFAULT_WORKFLOW_LIBRARY_CATEGORIES = ['user', 'default'] satisfies WorkflowCategory[];
9393
export const $workflowLibraryCategoriesOptions = atom<WorkflowCategory[]>(DEFAULT_WORKFLOW_LIBRARY_CATEGORIES);
9494

95-
export type WorkflowTagCategory = { categoryTKey: string; tags: string[] };
95+
export type WorkflowTagCategory = { categoryTKey: string; tags: Array<{ label: string; selected?: boolean }> };
9696
export const DEFAULT_WORKFLOW_LIBRARY_TAG_CATEGORIES: WorkflowTagCategory[] = [
97-
{ categoryTKey: 'Industry', tags: ['Architecture', 'Fashion', 'Game Dev', 'Food'] },
98-
{ categoryTKey: 'Common Tasks', tags: ['Upscaling', 'Text to Image', 'Image to Image'] },
99-
{ categoryTKey: 'Model Architecture', tags: ['SD1.5', 'SDXL', 'SD3.5', 'FLUX'] },
100-
{ categoryTKey: 'Tech Showcase', tags: ['Control', 'Reference Image'] },
97+
{
98+
categoryTKey: 'Industry',
99+
tags: [{ label: 'Architecture' }, { label: 'Fashion' }, { label: 'Game Dev' }, { label: 'Food' }],
100+
},
101+
{
102+
categoryTKey: 'Common Tasks',
103+
tags: [{ label: 'Upscaling' }, { label: 'Text to Image' }, { label: 'Image to Image' }],
104+
},
105+
{
106+
categoryTKey: 'Model Architecture',
107+
tags: [{ label: 'SD1.5' }, { label: 'SDXL' }, { label: 'SD3.5' }, { label: 'FLUX' }],
108+
},
109+
{ categoryTKey: 'Tech Showcase', tags: [{ label: 'Control' }, { label: 'Reference Image' }] },
101110
];
102111
export const $workflowLibraryTagCategoriesOptions = atom<WorkflowTagCategory[]>(
103112
DEFAULT_WORKFLOW_LIBRARY_TAG_CATEGORIES

0 commit comments

Comments
 (0)