feat(dashboard): bulk enable/disable selected API keys on provider page
This commit is contained in:
@@ -863,6 +863,28 @@ export default function ProviderDetailPage() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Enable/disable all selected connections in parallel, keeping the selection.
|
||||||
|
const handleBulkToggleActive = async (newActive) => {
|
||||||
|
const idsToUpdate = [...selectedConnectionIds];
|
||||||
|
if (idsToUpdate.length === 0) return;
|
||||||
|
const settled = await Promise.allSettled(
|
||||||
|
idsToUpdate.map((id) =>
|
||||||
|
fetch(`/api/providers/${id}`, {
|
||||||
|
method: "PUT",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({ isActive: newActive }),
|
||||||
|
}).then((res) => {
|
||||||
|
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
const failed = settled.filter((r) => r.status === "rejected").length;
|
||||||
|
setConnections((prev) =>
|
||||||
|
prev.map((c) => (idsToUpdate.includes(c.id) ? { ...c, isActive: newActive } : c)),
|
||||||
|
);
|
||||||
|
if (failed > 0) alert(`Updated ${idsToUpdate.length - failed} connection(s), ${failed} failed.`);
|
||||||
|
};
|
||||||
|
|
||||||
const handleOAuthSuccess = () => {
|
const handleOAuthSuccess = () => {
|
||||||
fetchConnections();
|
fetchConnections();
|
||||||
setShowOAuthModal(false);
|
setShowOAuthModal(false);
|
||||||
@@ -960,6 +982,9 @@ export default function ProviderDetailPage() {
|
|||||||
|
|
||||||
const selectedConnections = connections.filter((conn) => selectedConnectionIds.includes(conn.id));
|
const selectedConnections = connections.filter((conn) => selectedConnectionIds.includes(conn.id));
|
||||||
const allSelected = connections.length > 0 && selectedConnectionIds.length === connections.length;
|
const allSelected = connections.length > 0 && selectedConnectionIds.length === connections.length;
|
||||||
|
const allSelectedDisabled =
|
||||||
|
selectedConnections.length > 0 &&
|
||||||
|
selectedConnections.every((c) => (c.isActive ?? true) === false);
|
||||||
|
|
||||||
const toggleSelectConnection = (connectionId) => {
|
const toggleSelectConnection = (connectionId) => {
|
||||||
setSelectedConnectionIds((prev) => (
|
setSelectedConnectionIds((prev) => (
|
||||||
@@ -1676,6 +1701,16 @@ export default function ProviderDetailPage() {
|
|||||||
Delete Selected ({selectedConnectionIds.length})
|
Delete Selected ({selectedConnectionIds.length})
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
{selectedConnectionIds.length > 0 && (
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="secondary"
|
||||||
|
icon={allSelectedDisabled ? "toggle_on" : "toggle_off"}
|
||||||
|
onClick={() => handleBulkToggleActive(!allSelectedDisabled)}
|
||||||
|
>
|
||||||
|
{allSelectedDisabled ? "Enable" : "Disable"} Selected ({selectedConnectionIds.length})
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
{selectedConnectionIds.length > 0 && (
|
{selectedConnectionIds.length > 0 && (
|
||||||
<Button
|
<Button
|
||||||
size="sm"
|
size="sm"
|
||||||
|
|||||||
Reference in New Issue
Block a user