fix(ui): workspace models bulk actions and search pagination (#26274)
This commit is contained in:
1 file changed
+62
-14
@@ -228,51 +228,97 @@
|
|||||||
await updateUserSettings(localStorage.token, { ui: $settings });
|
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 enableAllHandler = async () => {
|
||||||
const modelsToEnable = (models ?? []).filter((m) => !(m.is_active ?? true));
|
const allModels = await fetchAllWorkspaceModels();
|
||||||
// Optimistic UI update
|
const modelsToEnable = allModels.filter((m) => !(m.is_active ?? true));
|
||||||
modelsToEnable.forEach((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;
|
models = models;
|
||||||
// Sync with server
|
// Sync with server
|
||||||
await Promise.all(modelsToEnable.map((model) => toggleModelById(localStorage.token, model.id)));
|
await Promise.all(modelsToEnable.map((model) => toggleModelById(localStorage.token, model.id)));
|
||||||
|
await getModelList();
|
||||||
};
|
};
|
||||||
|
|
||||||
const disableAllHandler = async () => {
|
const disableAllHandler = async () => {
|
||||||
const modelsToDisable = (models ?? []).filter((m) => m.is_active ?? true);
|
const allModels = await fetchAllWorkspaceModels();
|
||||||
// Optimistic UI update
|
const modelsToDisable = allModels.filter((m) => m.is_active ?? true);
|
||||||
modelsToDisable.forEach((m) => (m.is_active = false));
|
if (modelsToDisable.length === 0) return;
|
||||||
|
// Optimistic UI update for current page
|
||||||
|
(models ?? []).forEach((m) => (m.is_active = false));
|
||||||
models = models;
|
models = models;
|
||||||
// Sync with server
|
// Sync with server
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
modelsToDisable.map((model) => toggleModelById(localStorage.token, model.id))
|
modelsToDisable.map((model) => toggleModelById(localStorage.token, model.id))
|
||||||
);
|
);
|
||||||
|
await getModelList();
|
||||||
};
|
};
|
||||||
|
|
||||||
const showAllHandler = async () => {
|
const showAllHandler = async () => {
|
||||||
const modelsToShow = (models ?? []).filter((m) => m?.meta?.hidden === true);
|
const allModels = await fetchAllWorkspaceModels();
|
||||||
// Optimistic UI update
|
const modelsToShow = allModels.filter((m) => m?.meta?.hidden === true);
|
||||||
modelsToShow.forEach((m) => {
|
if (modelsToShow.length === 0) return;
|
||||||
|
// Optimistic UI update for current page
|
||||||
|
(models ?? []).forEach((m) => {
|
||||||
m.meta = { ...m.meta, hidden: false };
|
m.meta = { ...m.meta, hidden: false };
|
||||||
});
|
});
|
||||||
models = models;
|
models = models;
|
||||||
// Sync with server
|
// Sync with server
|
||||||
await Promise.all(
|
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'));
|
toast.success($i18n.t('All models are now visible'));
|
||||||
};
|
};
|
||||||
|
|
||||||
const hideAllHandler = async () => {
|
const hideAllHandler = async () => {
|
||||||
const modelsToHide = (models ?? []).filter((m) => !(m?.meta?.hidden ?? false));
|
const allModels = await fetchAllWorkspaceModels();
|
||||||
// Optimistic UI update
|
const modelsToHide = allModels.filter((m) => !(m?.meta?.hidden ?? false));
|
||||||
modelsToHide.forEach((m) => {
|
if (modelsToHide.length === 0) return;
|
||||||
|
// Optimistic UI update for current page
|
||||||
|
(models ?? []).forEach((m) => {
|
||||||
m.meta = { ...m.meta, hidden: true };
|
m.meta = { ...m.meta, hidden: true };
|
||||||
});
|
});
|
||||||
models = models;
|
models = models;
|
||||||
// Sync with server
|
// Sync with server
|
||||||
await Promise.all(
|
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'));
|
toast.success($i18n.t('All models are now hidden'));
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -453,6 +499,7 @@
|
|||||||
on:input={() => {
|
on:input={() => {
|
||||||
clearTimeout(searchDebounceTimer);
|
clearTimeout(searchDebounceTimer);
|
||||||
searchDebounceTimer = setTimeout(() => {
|
searchDebounceTimer = setTimeout(() => {
|
||||||
|
page = 1;
|
||||||
getModelList();
|
getModelList();
|
||||||
}, 300);
|
}, 300);
|
||||||
}}
|
}}
|
||||||
@@ -465,6 +512,7 @@
|
|||||||
aria-label={$i18n.t('Clear search')}
|
aria-label={$i18n.t('Clear search')}
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
query = '';
|
query = '';
|
||||||
|
page = 1;
|
||||||
getModelList();
|
getModelList();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in new issue
Block a user