Add bulk actions to Secrets, IP Addresses, and Tailscale devices

One row at a time was tedious for anything beyond a handful of items.
New useSelection hook (id-based Set, so picks made on page 1 survive
moving to page 2 rather than resetting per page) backs a checkbox
column and a bulk-actions bar on each of the three tables:
- Secrets / IP Addresses: bulk delete.
- Tailscale devices: bulk authorize/deauthorize/remove.

No new backend endpoints — each bulk action is a client-side
Promise.allSettled loop over the existing single-item endpoints, so
one failure doesn't block the rest, and the bar reports how many (if
any) failed. Selection clears after a bulk action completes or when
switching Tailscale integrations (device ids aren't comparable across
different tailnets).

Verified the selection hook's Set logic directly (extracted as pure
functions, no React renderer needed): select-all/deselect-all
toggling, individual toggle, and — the case most likely to have a
subtle bug — that selecting items on one page and then selecting
different items on another page keeps both, with toggleAll on either
page only ever touching that page's own ids.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5 committed 2026-09-24 19:13:56 +02:00
1 parent e081eecba4
commit 35979cb043
4 files changed
+216 -3

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
import { useState } from "react";
/** Tracks a set of selected row ids across pages/sorts — selecting on page 1 then moving to page 2 keeps page 1's picks. */
export function useSelection<T extends string | number>() {
const [selected, setSelected] = useState<Set<T>>(new Set());
function toggle(id: T) {
setSelected((prev) => {
const next = new Set(prev);
if (next.has(id)) next.delete(id);
else next.add(id);
return next;
});
}
/** Selects every id in `ids` if any of them aren't already selected, otherwise deselects all of them (standard "select all on this page" checkbox behavior). */
function toggleAll(ids: T[]) {
setSelected((prev) => {
const allSelected = ids.length > 0 && ids.every((id) => prev.has(id));
const next = new Set(prev);
if (allSelected) {
for (const id of ids) next.delete(id);
} else {
for (const id of ids) next.add(id);
}
return next;
});
}
function clear() {
setSelected(new Set());
}
return { selected, toggle, toggleAll, clear, isSelected: (id: T) => selected.has(id), count: selected.size };
}