Skip to content

Commit e5591d1

Browse files
Mary Hippmaryhipp
authored andcommitted
allow workflow sort options to be passed in
1 parent 371c187 commit e5591d1

File tree

4 files changed

+45
-8
lines changed

4 files changed

+45
-8
lines changed

invokeai/frontend/web/src/app/components/InvokeAIUI.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ import { $store } from 'app/store/nanostores/store';
1919
import { createStore } from 'app/store/store';
2020
import type { PartialAppConfig } from 'app/types/invokeai';
2121
import Loading from 'common/components/Loading/Loading';
22-
import type { WorkflowTagCategory } from 'features/nodes/store/workflowLibrarySlice';
22+
import type { WorkflowSortOption, WorkflowTagCategory } from 'features/nodes/store/workflowLibrarySlice';
2323
import {
2424
$workflowLibraryCategoriesOptions,
25+
$workflowLibrarySortOptions,
2526
$workflowLibraryTagCategoriesOptions,
2627
DEFAULT_WORKFLOW_LIBRARY_CATEGORIES,
28+
DEFAULT_WORKFLOW_LIBRARY_SORT_OPTIONS,
2729
DEFAULT_WORKFLOW_LIBRARY_TAG_CATEGORIES,
2830
} from 'features/nodes/store/workflowLibrarySlice';
2931
import type { WorkflowCategory } from 'features/nodes/types/workflow';
@@ -55,6 +57,7 @@ interface Props extends PropsWithChildren {
5557
logo?: ReactNode;
5658
workflowCategories?: WorkflowCategory[];
5759
workflowTagCategories?: WorkflowTagCategory[];
60+
workflowSortOptions?: WorkflowSortOption[];
5861
loggingOverrides?: LoggingOverrides;
5962
}
6063

@@ -76,6 +79,7 @@ const InvokeAIUI = ({
7679
logo,
7780
workflowCategories,
7881
workflowTagCategories,
82+
workflowSortOptions,
7983
loggingOverrides,
8084
}: Props) => {
8185
useLayoutEffect(() => {
@@ -221,6 +225,16 @@ const InvokeAIUI = ({
221225
};
222226
}, [workflowTagCategories]);
223227

228+
useEffect(() => {
229+
if (workflowSortOptions) {
230+
$workflowLibrarySortOptions.set(workflowSortOptions);
231+
}
232+
233+
return () => {
234+
$workflowLibrarySortOptions.set(DEFAULT_WORKFLOW_LIBRARY_SORT_OPTIONS);
235+
};
236+
}, [workflowSortOptions]);
237+
224238
useEffect(() => {
225239
if (socketOptions) {
226240
$socketOptions.set(socketOptions);
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import { Flex } from '@invoke-ai/ui-library';
2+
import { useAppSelector } from 'app/store/storeHooks';
3+
import { selectWorkflowLibraryView } from 'features/nodes/store/workflowLibrarySlice';
24
import { useRef } from 'react';
35

46
import { WorkflowSearch } from './WorkflowSearch';
57
import { WorkflowSortControl } from './WorkflowSortControl';
68

79
export const WorkflowLibraryTopNav = () => {
810
const searchInputRef = useRef<HTMLInputElement>(null);
11+
const view = useAppSelector(selectWorkflowLibraryView);
912
return (
1013
<Flex gap={8} justifyContent="space-between">
1114
<WorkflowSearch searchInputRef={searchInputRef} />
12-
<WorkflowSortControl />
15+
{view !== 'recent' && <WorkflowSortControl />}
1316
</Flex>
1417
);
1518
};

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { Flex, FormControl, FormLabel, Select } from '@invoke-ai/ui-library';
2+
import { useStore } from '@nanostores/react';
23
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
34
import {
5+
$workflowLibrarySortOptions,
46
selectWorkflowLibraryDirection,
57
selectWorkflowLibraryOrderBy,
68
workflowLibraryDirectionChanged,
79
workflowLibraryOrderByChanged,
810
} from 'features/nodes/store/workflowLibrarySlice';
911
import type { ChangeEvent } from 'react';
10-
import { useCallback, useMemo } from 'react';
12+
import { useCallback, useEffect, useMemo } from 'react';
1113
import { useTranslation } from 'react-i18next';
1214
import { z } from 'zod';
1315

@@ -24,6 +26,7 @@ export const WorkflowSortControl = () => {
2426

2527
const orderBy = useAppSelector(selectWorkflowLibraryOrderBy);
2628
const direction = useAppSelector(selectWorkflowLibraryDirection);
29+
const sortOptions = useStore($workflowLibrarySortOptions);
2730

2831
const ORDER_BY_LABELS = useMemo(
2932
() => ({
@@ -65,15 +68,23 @@ export const WorkflowSortControl = () => {
6568
[dispatch]
6669
);
6770

71+
useEffect(() => {
72+
if (!sortOptions.includes('opened_at')) {
73+
dispatch(workflowLibraryOrderByChanged('name'));
74+
dispatch(workflowLibraryDirectionChanged('ASC'));
75+
}
76+
}, [sortOptions, dispatch]);
77+
6878
return (
6979
<Flex flexDir="row" gap={6}>
7080
<FormControl orientation="horizontal" gap={0} w="auto">
7181
<FormLabel>{t('common.orderBy')}</FormLabel>
72-
<Select value={orderBy ?? 'opened_at'} onChange={onChangeOrderBy} size="sm">
73-
<option value="opened_at">{ORDER_BY_LABELS['opened_at']}</option>
74-
<option value="created_at">{ORDER_BY_LABELS['created_at']}</option>
75-
<option value="updated_at">{ORDER_BY_LABELS['updated_at']}</option>
76-
<option value="name">{ORDER_BY_LABELS['name']}</option>
82+
<Select value={orderBy ?? sortOptions[0]} onChange={onChangeOrderBy} size="sm">
83+
{sortOptions.map((option) => (
84+
<option key={option} value={option}>
85+
{ORDER_BY_LABELS[option]}
86+
</option>
87+
))}
7788
</Select>
7889
</FormControl>
7990
<FormControl orientation="horizontal" gap={0} w="auto">

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,12 @@ export const $workflowLibraryTagCategoriesOptions = atom<WorkflowTagCategory[]>(
101101
export const $workflowLibraryTagOptions = computed($workflowLibraryTagCategoriesOptions, (tagCategories) =>
102102
tagCategories.flatMap(({ tags }) => tags)
103103
);
104+
105+
export type WorkflowSortOption = 'opened_at' | 'created_at' | 'updated_at' | 'name';
106+
export const DEFAULT_WORKFLOW_LIBRARY_SORT_OPTIONS: WorkflowSortOption[] = [
107+
'opened_at',
108+
'created_at',
109+
'updated_at',
110+
'name',
111+
];
112+
export const $workflowLibrarySortOptions = atom<WorkflowSortOption[]>(DEFAULT_WORKFLOW_LIBRARY_SORT_OPTIONS);

0 commit comments

Comments
 (0)