import { useMutation, useQueryClient } from '@tanstack/react-query' import type { BaoClient } from '../../api/bao' import { revokeAccess } from '../../api/grants' import type { AccessGraph, GraphEdge, GraphNode, PolicyInput } from '../../model/graph' import { parseManagedPolicy, type GrantTarget } from '../../model/managed' import { CapabilityChips } from '../shared/CapabilityChips' import { useConfirm } from '../shared/useConfirm' export type Selection = { kind: 'node'; id: string } | { kind: 'edge'; id: string } interface Props { client: BaoClient full: AccessGraph policies: PolicyInput[] selection: Selection | null onRevoked: () => void } const nodeById = (g: AccessGraph, id: string) => g.nodes.find((n) => n.id === id) const label = (n: GraphNode | undefined) => n?.label ?? '?' /** An identity's name with its kind, so "alice" the user and "alice" the entity read differently. */ function Who({ node }: { node: GraphNode | undefined }) { return ( <> {label(node)} {node?.type === 'identity' && {node.kind}} > ) } function Warnings({ items }: { items: string[] | undefined }) { return items?.map((w) => (
{w}
)) } function NodeDetails({ node, full, policies }: { node: GraphNode; full: AccessGraph; policies: PolicyInput[] }) { const out = full.edges.filter((e) => e.source === node.id) const into = full.edges.filter((e) => e.target === node.id) if (node.type === 'identity') { return ( <>{label(nodeById(full, e.target))}
No policies attached.
)} > ) } if (node.type === 'policy') { const hcl = policies.find((p) => p.name === node.label)?.hcl const status = node.missing ? 'Attached but does not exist' : node.managed ? 'Managed by EnvBao' : 'Not managed by EnvBao (read-only)' return ( <>{status}.
Not attached to anything.
)}{label(nodeById(full, e.target))}
{e.capabilities && No grants.
)} {hcl && ({hcl}
{node.label}
{label(nodeById(full, e.source))}
{e.capabilities && No identity uses this policy.
)}
{label(to)}
This grant is in a policy EnvBao does not manage (or that was edited outside EnvBao), so it can’t be revoked here.
)} {revoke.error &&{revoke.error.message}
} > )} > ) } export function Details({ client, full, policies, selection, onRevoked }: Props) { let body =Select a node or a line to see what it grants.
if (selection?.kind === 'node') { const node = nodeById(full, selection.id) if (node) body =