import { useActionQuery } from "@agent-native/core/client/hooks"; import { ActionQueryError } from "./action-query-error"; import { Badge } from "./ui/badge"; import { Skeleton } from "./ui/skeleton"; import { formatResourceTimestamp } from "./workspace-resource-effective-stack"; function isApprovalRequest(result: any): boolean { return ( result?.status === "pending" && typeof result?.changeType === "string" && result.changeType.startsWith("workspace-resource.") ); } export function workspaceResourceMutationMessage( result: any, fallback: string, ): string { return isApprovalRequest(result) ? "Approval requested" : fallback; } export function ImpactPreview({ operation, resourceId, path, scope, enabled = true, }: { operation: "create" | "update" | "delete"; resourceId?: string; path?: string; scope?: "all" | "selected"; enabled?: boolean; }) { const query = useActionQuery( "preview-workspace-resource-change", { operation, resourceId, path, scope, }, { enabled: enabled && Boolean(resourceId || path) }, ); const { data: impact, isLoading } = query; if (!enabled || (!resourceId && !path)) return null; if (isLoading) { return (
); } if (query.isError) { return ( void query.refetch()} /> ); } const data = impact as any; if (!data) return null; const affectsAllApps = data.affectsAllApps === true; const appCount = data.affectedApps?.count; const overrides = data.overrides ?? { count: 0, items: [] }; const willRequestApproval = data.approval?.willRequestApproval === true; return (
{affectsAllApps ? "All apps impact" : "Selected only"} {willRequestApproval ? ( Approval required ) : null} {overrides.count > 0 ? ( {overrides.count} override{overrides.count === 1 ? "" : "s"} ) : null}

{affectsAllApps ? `This change applies to every workspace app${typeof appCount === "number" ? ` (${appCount} discovered)` : ""}.` : "This change only applies to explicitly granted apps."}{" "} {willRequestApproval ? "It will be queued for approval before it takes effect." : "It will take effect immediately when saved."}

{overrides.count > 0 ? (
{overrides.items.slice(0, 4).map((override: any) => (
{override.label} {formatResourceTimestamp(override.updatedAt)}
))} {overrides.count > 4 ? (
+{overrides.count - 4} more override {overrides.count - 4 === 1 ? "" : "s"}
) : null}
) : null}
); }