add option for workflowCategories

This commit is contained in:
Mary Hipp 2024-01-26 11:23:54 -05:00 committed by psychedelicious
parent de20711637
commit 418cdbabb7
3 changed files with 63 additions and 34 deletions

View File

@ -23,6 +23,8 @@ import React, { lazy, memo, useEffect, useMemo } from 'react';
import { Provider } from 'react-redux'; import { Provider } from 'react-redux';
import { addMiddleware, resetMiddlewares } from 'redux-dynamic-middlewares'; import { addMiddleware, resetMiddlewares } from 'redux-dynamic-middlewares';
import type { ManagerOptions, SocketOptions } from 'socket.io-client'; import type { ManagerOptions, SocketOptions } from 'socket.io-client';
import { WorkflowCategory } from '../../features/nodes/types/workflow';
import { $workflowCategories } from '../store/nanostores/workflowCategories';
const App = lazy(() => import('./App')); const App = lazy(() => import('./App'));
const ThemeLocaleProvider = lazy(() => import('./ThemeLocaleProvider')); const ThemeLocaleProvider = lazy(() => import('./ThemeLocaleProvider'));
@ -45,6 +47,7 @@ interface Props extends PropsWithChildren {
socketOptions?: Partial<ManagerOptions & SocketOptions>; socketOptions?: Partial<ManagerOptions & SocketOptions>;
isDebugging?: boolean; isDebugging?: boolean;
logo?: ReactNode; logo?: ReactNode;
workflowCategories?: WorkflowCategory[];
} }
const InvokeAIUI = ({ const InvokeAIUI = ({
@ -62,6 +65,7 @@ const InvokeAIUI = ({
socketOptions, socketOptions,
isDebugging = false, isDebugging = false,
logo, logo,
workflowCategories,
}: Props) => { }: Props) => {
useEffect(() => { useEffect(() => {
// configure API client token // configure API client token
@ -156,6 +160,16 @@ const InvokeAIUI = ({
}; };
}, [logo]); }, [logo]);
useEffect(() => {
if (workflowCategories) {
$workflowCategories.set(workflowCategories);
}
return () => {
$workflowCategories.set([]);
};
}, [workflowCategories]);
useEffect(() => { useEffect(() => {
if (socketOptions) { if (socketOptions) {
$socketOptions.set(socketOptions); $socketOptions.set(socketOptions);

View File

@ -0,0 +1,4 @@
import { atom } from 'nanostores';
import { WorkflowCategory } from '../../../features/nodes/types/workflow';
export const $workflowCategories = atom<WorkflowCategory[]>(["user", "default"]);

View File

@ -34,6 +34,7 @@ import type {
} from 'services/api/types'; } from 'services/api/types';
import { useDebounce } from 'use-debounce'; import { useDebounce } from 'use-debounce';
import { z } from 'zod'; import { z } from 'zod';
import { $workflowCategories } from '../../../app/store/nanostores/workflowCategories';
const PER_PAGE = 10; const PER_PAGE = 10;
@ -58,10 +59,13 @@ const DIRECTION_OPTIONS: ComboboxOption[] = [
const WorkflowLibraryList = () => { const WorkflowLibraryList = () => {
const { t } = useTranslation(); const { t } = useTranslation();
const [category, setCategory] = useState<WorkflowCategory>('user'); const workflowCategories = useStore($workflowCategories);
const [selectedCategory, setSelectedCategory] =
useState<WorkflowCategory>('user');
const [page, setPage] = useState(0); const [page, setPage] = useState(0);
const [query, setQuery] = useState(''); const [query, setQuery] = useState('');
const projectId = useStore($projectId); const projectId = useStore($projectId);
const orderByOptions = useMemo(() => { const orderByOptions = useMemo(() => {
return projectId return projectId
? ORDER_BY_OPTIONS.filter((option) => option.value !== 'opened_at') ? ORDER_BY_OPTIONS.filter((option) => option.value !== 'opened_at')
@ -75,13 +79,13 @@ const WorkflowLibraryList = () => {
const [debouncedQuery] = useDebounce(query, 500); const [debouncedQuery] = useDebounce(query, 500);
const queryArg = useMemo<Parameters<typeof useListWorkflowsQuery>[0]>(() => { const queryArg = useMemo<Parameters<typeof useListWorkflowsQuery>[0]>(() => {
if (category !== 'default') { if (selectedCategory !== 'default') {
return { return {
page, page,
per_page: PER_PAGE, per_page: PER_PAGE,
order_by, order_by,
direction, direction,
category, category: selectedCategory,
query: debouncedQuery, query: debouncedQuery,
}; };
} }
@ -90,10 +94,10 @@ const WorkflowLibraryList = () => {
per_page: PER_PAGE, per_page: PER_PAGE,
order_by: 'name' as const, order_by: 'name' as const,
direction: 'ASC' as const, direction: 'ASC' as const,
category, category: selectedCategory,
query: debouncedQuery, query: debouncedQuery,
}; };
}, [category, debouncedQuery, direction, order_by, page]); }, [selectedCategory, debouncedQuery, direction, order_by, page]);
const { data, isLoading, isError, isFetching } = const { data, isLoading, isError, isFetching } =
useListWorkflowsQuery(queryArg); useListWorkflowsQuery(queryArg);
@ -154,43 +158,42 @@ const WorkflowLibraryList = () => {
); );
const handleSetCategory = useCallback((category: WorkflowCategory) => { const handleSetCategory = useCallback((category: WorkflowCategory) => {
setCategory(category); setSelectedCategory(category);
setPage(0); setPage(0);
}, []); }, []);
return ( return (
<> <>
<Flex gap={4} alignItems="center" h={10} flexShrink={0} flexGrow={0}> <Flex
<ButtonGroup> gap={4}
<Button alignItems="center"
variant={category === 'user' ? undefined : 'ghost'} h={16}
onClick={handleSetCategory.bind(null, 'user')} flexShrink={0}
isChecked={category === 'user'} flexGrow={0}
justifyContent={'space-between'}
> >
{t('workflows.userWorkflows')} <ButtonGroup alignSelf="flex-end">
</Button> {workflowCategories.map((category) => (
{projectId ? (
<Button <Button
variant={category === 'project' ? undefined : 'ghost'} variant={selectedCategory === category ? undefined : 'ghost'}
onClick={handleSetCategory.bind(null, 'project')} onClick={handleSetCategory.bind(null, category)}
isChecked={category === 'project'} isChecked={selectedCategory === category}
> >
{t('workflows.projectWorkflows')} {t(`workflows.${category}Workflows`)}
</Button> </Button>
) : ( ))}
<Button
variant={category === 'default' ? undefined : 'ghost'}
onClick={handleSetCategory.bind(null, 'default')}
isChecked={category === 'default'}
>
{t('workflows.defaultWorkflows')}
</Button>
)}
</ButtonGroup> </ButtonGroup>
<Spacer /> {selectedCategory !== 'default' && (
{category !== 'default' && (
<> <>
<FormControl isDisabled={isFetching} w={64} minW={56}> <FormControl
isDisabled={isFetching}
sx={{
flexDir: 'column',
alignItems: 'flex-start',
gap: 1,
maxW: 56,
}}
>
<FormLabel>{t('common.orderBy')}</FormLabel> <FormLabel>{t('common.orderBy')}</FormLabel>
<Combobox <Combobox
value={valueOrderBy} value={valueOrderBy}
@ -198,7 +201,15 @@ const WorkflowLibraryList = () => {
onChange={onChangeOrderBy} onChange={onChangeOrderBy}
/> />
</FormControl> </FormControl>
<FormControl isDisabled={isFetching} w={64} minW={56}> <FormControl
isDisabled={isFetching}
sx={{
flexDir: 'column',
alignItems: 'flex-start',
gap: 1,
maxW: 56,
}}
>
<FormLabel>{t('common.direction')}</FormLabel> <FormLabel>{t('common.direction')}</FormLabel>
<Combobox <Combobox
value={valueDirection} value={valueDirection}
@ -208,7 +219,7 @@ const WorkflowLibraryList = () => {
</FormControl> </FormControl>
</> </>
)} )}
<InputGroup w="20rem"> <InputGroup w="20rem" alignSelf="flex-end">
<Input <Input
placeholder={t('workflows.searchWorkflows')} placeholder={t('workflows.searchWorkflows')}
value={query} value={query}