import { useQuery } from '@tanstack/react-query' import { useId } from 'react' import type { BaoClient } from '../../api/bao' import type { EngineDef } from '../../api/engines/registry' import { listRoles } from '../../api/engines/roles' export interface RoleSelection { kindId: string /** A role name, "*" for every role of the kind, or "" for none chosen yet. */ role: string } /** Pick a role of a dynamic engine (or all of them) to grant access to. Lists role names only. */ export function RolePicker({ client, mount, engine, value, onChange, }: { client: BaoClient mount: string engine: EngineDef value: RoleSelection onChange: (v: RoleSelection) => void }) { const id = useId() const kind = engine.roleKinds.find((k) => k.id === value.kindId) ?? engine.roleKinds[0] const roles = useQuery({ queryKey: ['engine-roles', mount, kind.id], queryFn: () => listRoles(client, mount, kind) }) const all = value.role === '*' return (
) }