From 6fd8c599c1345e80ac377c26d7ca2a4584e26ed0 Mon Sep 17 00:00:00 2001 From: G30 <50341825+silentoplayz@users.noreply.github.com> Date: Mon, 29 Jun 2026 13:14:15 -0400 Subject: [PATCH] fix(ui): workspace models bulk actions and search pagination (#26274) --- src/lib/components/workspace/Models.svelte | 76 ++++++++++++++++++---- 1 file changed, 62 insertions(+), 14 deletions(-) diff --git a/src/lib/components/workspace/Models.svelte b/src/lib/components/workspace/Models.svelte index 5731d59279..4c62a6b8ea 100644 --- a/src/lib/components/workspace/Models.svelte +++ b/src/lib/components/workspace/Models.svelte @@ -228,51 +228,97 @@ await updateUserSettings(localStorage.token, { ui: $settings }); }; + const fetchAllWorkspaceModels = async () => { + // Fetch all workspace models across every page + const allModels = []; + let currentPage = 1; + let fetchedTotal = 0; + + while (true) { + const res = await getWorkspaceModels( + localStorage.token, + query, + viewOption, + selectedTag, + null, + null, + currentPage + ); + if (!res || !res.items || res.items.length === 0) break; + allModels.push(...res.items); + fetchedTotal = res.total; + if (allModels.length >= fetchedTotal) break; + currentPage++; + } + + return allModels; + }; + + + const enableAllHandler = async () => { - const modelsToEnable = (models ?? []).filter((m) => !(m.is_active ?? true)); - // Optimistic UI update - modelsToEnable.forEach((m) => (m.is_active = true)); + const allModels = await fetchAllWorkspaceModels(); + const modelsToEnable = allModels.filter((m) => !(m.is_active ?? true)); + if (modelsToEnable.length === 0) return; + // Optimistic UI update for current page + (models ?? []).forEach((m) => (m.is_active = true)); models = models; // Sync with server await Promise.all(modelsToEnable.map((model) => toggleModelById(localStorage.token, model.id))); + await getModelList(); }; const disableAllHandler = async () => { - const modelsToDisable = (models ?? []).filter((m) => m.is_active ?? true); - // Optimistic UI update - modelsToDisable.forEach((m) => (m.is_active = false)); + const allModels = await fetchAllWorkspaceModels(); + const modelsToDisable = allModels.filter((m) => m.is_active ?? true); + if (modelsToDisable.length === 0) return; + // Optimistic UI update for current page + (models ?? []).forEach((m) => (m.is_active = false)); models = models; // Sync with server await Promise.all( modelsToDisable.map((model) => toggleModelById(localStorage.token, model.id)) ); + await getModelList(); }; const showAllHandler = async () => { - const modelsToShow = (models ?? []).filter((m) => m?.meta?.hidden === true); - // Optimistic UI update - modelsToShow.forEach((m) => { + const allModels = await fetchAllWorkspaceModels(); + const modelsToShow = allModels.filter((m) => m?.meta?.hidden === true); + if (modelsToShow.length === 0) return; + // Optimistic UI update for current page + (models ?? []).forEach((m) => { m.meta = { ...m.meta, hidden: false }; }); models = models; // Sync with server await Promise.all( - modelsToShow.map((model) => updateModelById(localStorage.token, model.id, model)) + modelsToShow.map((model) => { + model.meta = { ...model.meta, hidden: false }; + return updateModelById(localStorage.token, model.id, model); + }) ); + await getModelList(); toast.success($i18n.t('All models are now visible')); }; const hideAllHandler = async () => { - const modelsToHide = (models ?? []).filter((m) => !(m?.meta?.hidden ?? false)); - // Optimistic UI update - modelsToHide.forEach((m) => { + const allModels = await fetchAllWorkspaceModels(); + const modelsToHide = allModels.filter((m) => !(m?.meta?.hidden ?? false)); + if (modelsToHide.length === 0) return; + // Optimistic UI update for current page + (models ?? []).forEach((m) => { m.meta = { ...m.meta, hidden: true }; }); models = models; // Sync with server await Promise.all( - modelsToHide.map((model) => updateModelById(localStorage.token, model.id, model)) + modelsToHide.map((model) => { + model.meta = { ...model.meta, hidden: true }; + return updateModelById(localStorage.token, model.id, model); + }) ); + await getModelList(); toast.success($i18n.t('All models are now hidden')); }; @@ -453,6 +499,7 @@ on:input={() => { clearTimeout(searchDebounceTimer); searchDebounceTimer = setTimeout(() => { + page = 1; getModelList(); }, 300); }} @@ -465,6 +512,7 @@ aria-label={$i18n.t('Clear search')} on:click={() => { query = ''; + page = 1; getModelList(); }} >