import { FileText, UploadCloud, X } from "lucide-react"; import { useCallback } from "react"; import { Link } from "react-router"; import { Button, DismissibleAlert, LoadingFrame, SelectionList, SelectionListItem, SelectionListItemContent, hasScope, quickAccessLaunchState, useDashboardWidgetData, type QuickAccessToolRenderContext } from "@govoplan/core-webui"; import { listFiles } from "../../api/files"; type Props = Pick< QuickAccessToolRenderContext, "settings" | "auth" | "launchContext" | "complete" | "cancel" | "close" >; /** * Bounded file selection. listFiles remains the owner-side authorization * check; the host receives only a versioned reference after explicit choice. */ export default function FileQuickAccess({ settings, auth, launchContext, complete, cancel, close }: Props) { const load = useCallback( async () => (await listFiles(settings, { sort: "recent", page_size: 7 })).files, [settings] ); const { data: files, loading, error } = useDashboardWidgetData(load, 0); const canUpload = hasScope(auth, "files:upload"); return ( {launchContext.activeObject ? (

Select a file for {launchContext.activeObject.label}. Files checks your current access again before showing this list.

) : null} {error ? {error} : null} {(files ?? []).map((file) => ( complete({ contractVersion: "1", outcome: "completed", action: "selected", reference: { ownerModule: "files", kind: "file-version", objectId: file.version_id, tenantId: file.tenant_id, label: file.filename, version: file.version_id, path: `/files?fileId=${encodeURIComponent(file.id)}&versionId=${encodeURIComponent(file.version_id)}` } })} > ))} {!loading && !error && !(files ?? []).length ? (

No authorized files are available.

) : null}
{canUpload ? (
); }