()
| 240 | // read-only ModelTable so admins can add/remove operators and change roles. |
| 241 | // Renders under the "Admin" sidebar group of the config-store explorer. |
| 242 | function OperatorsManager() { |
| 243 | const ops = useOperators(); |
| 244 | const upsert = useUpsertOperator(); |
| 245 | const del = useDeleteOperator(); |
| 246 | |
| 247 | const [filter, setFilter] = useState(""); |
| 248 | const [adding, setAdding] = useState(false); |
| 249 | const [deleting, setDeleting] = useState<Operator | null>(null); |
| 250 | // Inline error surface for mutation failures (e.g. 409 last-admin guard). |
| 251 | const [actionError, setActionError] = useState<string | null>(null); |
| 252 | |
| 253 | const rows = useMemo(() => ops.data ?? [], [ops.data]); |
| 254 | const filtered = useMemo(() => { |
| 255 | if (!filter) return rows; |
| 256 | const f = filter.toLowerCase(); |
| 257 | return rows.filter( |
| 258 | (o) => |
| 259 | o.email.toLowerCase().includes(f) || |
| 260 | o.role.toLowerCase().includes(f) || |
| 261 | o.added_by.toLowerCase().includes(f), |
| 262 | ); |
| 263 | }, [rows, filter]); |
| 264 | |
| 265 | const changeRole = async (op: Operator, role: Role) => { |
| 266 | if (role === op.role) return; |
| 267 | setActionError(null); |
| 268 | try { |
| 269 | await upsert.mutateAsync({ email: op.email, role }); |
| 270 | } catch (e) { |
| 271 | setActionError(errMsg(e)); |
| 272 | } |
| 273 | }; |
| 274 | |
| 275 | const confirmDelete = async () => { |
| 276 | if (!deleting) return; |
| 277 | setActionError(null); |
| 278 | try { |
| 279 | await del.mutateAsync(deleting.email); |
| 280 | setDeleting(null); |
| 281 | } catch (e) { |
| 282 | setActionError(errMsg(e)); |
| 283 | } |
| 284 | }; |
| 285 | |
| 286 | return ( |
| 287 | <> |
| 288 | <div className="flex items-center justify-between gap-2 border-b border-border px-4 py-2.5"> |
| 289 | <div className="flex items-center gap-2"> |
| 290 | <ShieldCheck className="h-4 w-4 text-muted-foreground" /> |
| 291 | <span className="text-sm font-medium">Operators</span> |
| 292 | <Badge variant="secondary">{fmtInt(rows.length)}</Badge> |
| 293 | </div> |
| 294 | <div className="flex items-center gap-2"> |
| 295 | <div className="relative"> |
| 296 | <Search className="pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" /> |
| 297 | <Input |
| 298 | value={filter} |
| 299 | onChange={(e) => setFilter(e.target.value)} |
nothing calls this directly
no test coverage detected