mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
Merge branch 'main' into feat/install_docs_update
This commit is contained in:
commit
c003967eaa
@ -14,10 +14,12 @@ import { $openAPISchemaUrl } from 'app/store/nanostores/openAPISchemaUrl';
|
||||
import { $projectId } from 'app/store/nanostores/projectId';
|
||||
import { $queueId, DEFAULT_QUEUE_ID } from 'app/store/nanostores/queueId';
|
||||
import { $store } from 'app/store/nanostores/store';
|
||||
import { $workflowCategories } from 'app/store/nanostores/workflowCategories';
|
||||
import { createStore } from 'app/store/store';
|
||||
import type { PartialAppConfig } from 'app/types/invokeai';
|
||||
import Loading from 'common/components/Loading/Loading';
|
||||
import AppDndContext from 'features/dnd/components/AppDndContext';
|
||||
import type { WorkflowCategory } from 'features/nodes/types/workflow';
|
||||
import type { PropsWithChildren, ReactNode } from 'react';
|
||||
import React, { lazy, memo, useEffect, useMemo } from 'react';
|
||||
import { Provider } from 'react-redux';
|
||||
@ -45,6 +47,7 @@ interface Props extends PropsWithChildren {
|
||||
socketOptions?: Partial<ManagerOptions & SocketOptions>;
|
||||
isDebugging?: boolean;
|
||||
logo?: ReactNode;
|
||||
workflowCategories?: WorkflowCategory[];
|
||||
}
|
||||
|
||||
const InvokeAIUI = ({
|
||||
@ -62,6 +65,7 @@ const InvokeAIUI = ({
|
||||
socketOptions,
|
||||
isDebugging = false,
|
||||
logo,
|
||||
workflowCategories,
|
||||
}: Props) => {
|
||||
useEffect(() => {
|
||||
// configure API client token
|
||||
@ -156,6 +160,16 @@ const InvokeAIUI = ({
|
||||
};
|
||||
}, [logo]);
|
||||
|
||||
useEffect(() => {
|
||||
if (workflowCategories) {
|
||||
$workflowCategories.set(workflowCategories);
|
||||
}
|
||||
|
||||
return () => {
|
||||
$workflowCategories.set([]);
|
||||
};
|
||||
}, [workflowCategories]);
|
||||
|
||||
useEffect(() => {
|
||||
if (socketOptions) {
|
||||
$socketOptions.set(socketOptions);
|
||||
|
@ -0,0 +1,7 @@
|
||||
import type { WorkflowCategory } from 'features/nodes/types/workflow';
|
||||
import { atom } from 'nanostores';
|
||||
|
||||
export const $workflowCategories = atom<WorkflowCategory[]>([
|
||||
'user',
|
||||
'default',
|
||||
]);
|
@ -11,10 +11,10 @@ import {
|
||||
Input,
|
||||
InputGroup,
|
||||
InputRightElement,
|
||||
Spacer,
|
||||
} from '@invoke-ai/ui';
|
||||
import { useStore } from '@nanostores/react';
|
||||
import { $projectId } from 'app/store/nanostores/projectId';
|
||||
import { $workflowCategories } from 'app/store/nanostores/workflowCategories';
|
||||
import {
|
||||
IAINoContentFallback,
|
||||
IAINoContentFallbackWithSpinner,
|
||||
@ -58,10 +58,13 @@ const DIRECTION_OPTIONS: ComboboxOption[] = [
|
||||
|
||||
const WorkflowLibraryList = () => {
|
||||
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 [query, setQuery] = useState('');
|
||||
const projectId = useStore($projectId);
|
||||
|
||||
const orderByOptions = useMemo(() => {
|
||||
return projectId
|
||||
? ORDER_BY_OPTIONS.filter((option) => option.value !== 'opened_at')
|
||||
@ -75,13 +78,13 @@ const WorkflowLibraryList = () => {
|
||||
const [debouncedQuery] = useDebounce(query, 500);
|
||||
|
||||
const queryArg = useMemo<Parameters<typeof useListWorkflowsQuery>[0]>(() => {
|
||||
if (category !== 'default') {
|
||||
if (selectedCategory !== 'default') {
|
||||
return {
|
||||
page,
|
||||
per_page: PER_PAGE,
|
||||
order_by,
|
||||
direction,
|
||||
category,
|
||||
category: selectedCategory,
|
||||
query: debouncedQuery,
|
||||
};
|
||||
}
|
||||
@ -90,10 +93,10 @@ const WorkflowLibraryList = () => {
|
||||
per_page: PER_PAGE,
|
||||
order_by: 'name' as const,
|
||||
direction: 'ASC' as const,
|
||||
category,
|
||||
category: selectedCategory,
|
||||
query: debouncedQuery,
|
||||
};
|
||||
}, [category, debouncedQuery, direction, order_by, page]);
|
||||
}, [selectedCategory, debouncedQuery, direction, order_by, page]);
|
||||
|
||||
const { data, isLoading, isError, isFetching } =
|
||||
useListWorkflowsQuery(queryArg);
|
||||
@ -154,43 +157,43 @@ const WorkflowLibraryList = () => {
|
||||
);
|
||||
|
||||
const handleSetCategory = useCallback((category: WorkflowCategory) => {
|
||||
setCategory(category);
|
||||
setSelectedCategory(category);
|
||||
setPage(0);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Flex gap={4} alignItems="center" h={10} flexShrink={0} flexGrow={0}>
|
||||
<ButtonGroup>
|
||||
<Button
|
||||
variant={category === 'user' ? undefined : 'ghost'}
|
||||
onClick={handleSetCategory.bind(null, 'user')}
|
||||
isChecked={category === 'user'}
|
||||
>
|
||||
{t('workflows.userWorkflows')}
|
||||
</Button>
|
||||
{projectId ? (
|
||||
<Flex
|
||||
gap={4}
|
||||
alignItems="center"
|
||||
h={16}
|
||||
flexShrink={0}
|
||||
flexGrow={0}
|
||||
justifyContent="space-between"
|
||||
>
|
||||
<ButtonGroup alignSelf="flex-end">
|
||||
{workflowCategories.map((category) => (
|
||||
<Button
|
||||
variant={category === 'project' ? undefined : 'ghost'}
|
||||
onClick={handleSetCategory.bind(null, 'project')}
|
||||
isChecked={category === 'project'}
|
||||
key={category}
|
||||
variant={selectedCategory === category ? undefined : 'ghost'}
|
||||
onClick={handleSetCategory.bind(null, category)}
|
||||
isChecked={selectedCategory === category}
|
||||
>
|
||||
{t('workflows.projectWorkflows')}
|
||||
{t(`workflows.${category}Workflows`)}
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
variant={category === 'default' ? undefined : 'ghost'}
|
||||
onClick={handleSetCategory.bind(null, 'default')}
|
||||
isChecked={category === 'default'}
|
||||
>
|
||||
{t('workflows.defaultWorkflows')}
|
||||
</Button>
|
||||
)}
|
||||
))}
|
||||
</ButtonGroup>
|
||||
<Spacer />
|
||||
{category !== 'default' && (
|
||||
{selectedCategory !== '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>
|
||||
<Combobox
|
||||
value={valueOrderBy}
|
||||
@ -198,7 +201,15 @@ const WorkflowLibraryList = () => {
|
||||
onChange={onChangeOrderBy}
|
||||
/>
|
||||
</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>
|
||||
<Combobox
|
||||
value={valueDirection}
|
||||
@ -208,7 +219,7 @@ const WorkflowLibraryList = () => {
|
||||
</FormControl>
|
||||
</>
|
||||
)}
|
||||
<InputGroup w="20rem">
|
||||
<InputGroup w="20rem" alignSelf="flex-end">
|
||||
<Input
|
||||
placeholder={t('workflows.searchWorkflows')}
|
||||
value={query}
|
||||
|
Loading…
Reference in New Issue
Block a user