Skip to content

Examples

Resource transfer surfaces

Use authorized host import, export, and reference creation surfaces.

Example type Recipe

Overview

Resource transfer surfaces

These examples show the public host controls for authorized Resource import, export and creating a missing reference. Choose the surface for the actual workflow; they are separate entry points, not steps to render together. The App supplies a real Resource key, server-authorized meta.resource_transfer, endpoints, and completion behavior. Components do not grant permissions. Revalidate authorization and inputs on the server, and refresh the affected list after a confirmed import.

Import and export guide · Resource Transfer contracts

Included files

Code example
TSX
import type { ResourceCreateCompletionInput, ResourceTransferMeta } from "@nexia/sdk";
import {
    NxDatasetExportWorkspace,
    NxDatasetImportWorkspace,
    NxInlineResourceCreate,
    NxResourceImportDialog,
    NxResourceTransferActions,
} from "@nexia/sdk/host";

/** The metadata must come from this Resource's authorized list response. */
export function TransferActions({ meta, onImported }: {
    meta: ResourceTransferMeta | null;
    onImported: () => void | Promise<void>;
}) {
    return <NxResourceTransferActions transferMeta={meta} onImported={onImported} />;
}

/** Render only after the server grants import and supplies all three URLs. */
export function ImportDialog({ meta, open, onClose, onImported }: {
    meta: ResourceTransferMeta | null;
    open: boolean;
    onClose: () => void;
    onImported: () => void | Promise<void>;
}) {
    if (!meta?.allowed.import || !meta.actions.preview || !meta.actions.import || !meta.actions.template) return null;
    return <NxResourceImportDialog open={open} onClose={onClose}
        previewUrl={meta.actions.preview} importUrl={meta.actions.import}
        templateUrl={meta.actions.template} formats={meta.import_formats ?? meta.formats}
        onImported={onImported} />;
}

/** Routes and keys must belong to the Resource the current actor can access. */
export function DatasetImport({ resourceKey }: { resourceKey: string }) {
    return <NxDatasetImportWorkspace resourceKey={resourceKey} />;
}

export function DatasetExport({ resourceKey, legalEntityPublicId }: {
    resourceKey: string;
    legalEntityPublicId: string | null;
}) {
    return <NxDatasetExportWorkspace resourceKey={resourceKey} legalEntityPublicId={legalEntityPublicId} />;
}

/** The caller owns the draft and resumes it only after the host confirms creation. */
export function CreateMissingReference({ route, onClose, onCreated }: {
    route: string;
    onClose: () => void;
    onCreated: (result: ResourceCreateCompletionInput) => void;
}) {
    return <NxInlineResourceCreate route={route} title="Create missing reference"
        onClose={onClose} onCreated={onCreated} />;
}
Example source: docs/developers/examples/resource-transfer-ui/README.md