From a12d54afb9c50e6691983fa5b8c63ac1d973c366 Mon Sep 17 00:00:00 2001 From: Jennifer Player Date: Tue, 27 Feb 2024 09:43:02 -0500 Subject: [PATCH 1/2] added add all button to scan models --- invokeai/frontend/web/public/locales/en.json | 1 + .../AddModelPanel/ImportQueue/ImportQueue.tsx | 9 +- .../ImportQueue/ImportQueueItem.tsx | 2 +- .../ScanModels/ScanModelsResults.tsx | 96 ++++++++++++++----- 4 files changed, 82 insertions(+), 26 deletions(-) diff --git a/invokeai/frontend/web/public/locales/en.json b/invokeai/frontend/web/public/locales/en.json index e951a294b5..4745cbb3b9 100644 --- a/invokeai/frontend/web/public/locales/en.json +++ b/invokeai/frontend/web/public/locales/en.json @@ -691,6 +691,7 @@ }, "modelManager": { "active": "active", + "addAll": "Add All", "addCheckpointModel": "Add Checkpoint / Safetensor Model", "addDifference": "Add Difference", "addDiffuserModel": "Add Diffusers", diff --git a/invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/ImportQueue/ImportQueue.tsx b/invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/ImportQueue/ImportQueue.tsx index cd2208c972..cf45f2c913 100644 --- a/invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/ImportQueue/ImportQueue.tsx +++ b/invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/ImportQueue/ImportQueue.tsx @@ -1,5 +1,6 @@ import { Box, Button, Flex, Text } from '@invoke-ai/ui-library'; import { useAppDispatch } from 'app/store/storeHooks'; +import ScrollableContent from 'common/components/OverlayScrollbars/ScrollableContent'; import { addToast } from 'features/system/store/systemSlice'; import { makeToast } from 'features/system/util/makeToast'; import { t } from 'i18next'; @@ -57,9 +58,11 @@ export const ImportQueue = () => { - - {data?.map((model) => )} - + + + {data?.map((model) => )} + + ); diff --git a/invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/ImportQueue/ImportQueueItem.tsx b/invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/ImportQueue/ImportQueueItem.tsx index fa13de0095..14bbe7daeb 100644 --- a/invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/ImportQueue/ImportQueueItem.tsx +++ b/invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/ImportQueue/ImportQueueItem.tsx @@ -121,7 +121,7 @@ export const ImportQueueItem = (props: ModelListItemProps) => { - {(model.status === 'downloading' || model.status === 'waiting') && ( + {(model.status === 'downloading' || model.status === 'waiting' || model.status === 'running') && ( { const { t } = useTranslation(); const [searchTerm, setSearchTerm] = useState(''); + const dispatch = useAppDispatch(); + + const [importMainModel] = useImportMainModelsMutation(); const filteredResults = useMemo(() => { return results.filter((result) => { @@ -31,6 +46,38 @@ export const ScanModelsResults = ({ results }: ScanModelResultsProps) => { setSearchTerm(''); }, []); + const handleAddAll = useCallback(() => { + for (const result of filteredResults) { + if (result.is_installed) { + continue; + } + importMainModel({ source: result.path, config: undefined }) + .unwrap() + .then((_) => { + dispatch( + addToast( + makeToast({ + title: t('toast.modelAddedSimple'), + status: 'success', + }) + ) + ); + }) + .catch((error) => { + if (error) { + dispatch( + addToast( + makeToast({ + title: `${error.data.detail} `, + status: 'error', + }) + ) + ); + } + }); + } + }, [importMainModel, filteredResults, dispatch, t]); + return ( <> @@ -39,27 +86,32 @@ export const ScanModelsResults = ({ results }: ScanModelResultsProps) => { {t('modelManager.scanResults')} - - + + + + - {searchTerm && ( - - } - onClick={clearSearch} - /> - - )} - + {searchTerm && ( + + } + onClick={clearSearch} + /> + + )} + + From 110b0bc8fe69daeb42d0cdd9077d354d550f9367 Mon Sep 17 00:00:00 2001 From: Jennifer Player Date: Tue, 27 Feb 2024 09:48:41 -0500 Subject: [PATCH 2/2] updated to use new import model mutation --- .../AddModelPanel/ScanModels/ScanModelsResults.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/ScanModels/ScanModelsResults.tsx b/invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/ScanModels/ScanModelsResults.tsx index b8c6efd938..960e00c2a6 100644 --- a/invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/ScanModels/ScanModelsResults.tsx +++ b/invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/ScanModels/ScanModelsResults.tsx @@ -16,7 +16,7 @@ import type { ChangeEventHandler } from 'react'; import { useCallback, useMemo, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { PiXBold } from 'react-icons/pi'; -import { type ScanFolderResponse, useImportMainModelsMutation } from 'services/api/endpoints/models'; +import { type ScanFolderResponse, useInstallModelMutation } from 'services/api/endpoints/models'; import { ScanModelResultItem } from './ScanModelResultItem'; @@ -29,7 +29,7 @@ export const ScanModelsResults = ({ results }: ScanModelResultsProps) => { const [searchTerm, setSearchTerm] = useState(''); const dispatch = useAppDispatch(); - const [importMainModel] = useImportMainModelsMutation(); + const [installModel] = useInstallModelMutation(); const filteredResults = useMemo(() => { return results.filter((result) => { @@ -51,7 +51,7 @@ export const ScanModelsResults = ({ results }: ScanModelResultsProps) => { if (result.is_installed) { continue; } - importMainModel({ source: result.path, config: undefined }) + installModel({ source: result.path }) .unwrap() .then((_) => { dispatch( @@ -76,7 +76,7 @@ export const ScanModelsResults = ({ results }: ScanModelResultsProps) => { } }); } - }, [importMainModel, filteredResults, dispatch, t]); + }, [installModel, filteredResults, dispatch, t]); return ( <>