Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions web/packages/common/src/utils/file.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ describe('triggerDownload', () => {
expect(Blob).toHaveBeenCalledWith([testData]);
});

it('should pass a Blob through untouched so its type survives', () => {
vi.unstubAllGlobals();
const blob = new Blob(['tar bytes'], { type: 'application/x-tar' });

triggerDownload(blob, 'artifacts');

expect(mockCreateObjectURL).toHaveBeenCalledWith(blob);
expect((mockCreateObjectURL.mock.calls[0][0] as Blob).type).toBe('application/x-tar');
});

it('should create an object URL from the Blob', () => {
const testData = 'test file content';
const filename = 'test.txt';
Expand Down
4 changes: 2 additions & 2 deletions web/packages/common/src/utils/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ export function findMessagesArray(
* @param filename - The name to give the downloaded file.
*/
export const triggerDownload = (data: BlobPart, filename: string) => {
// Create a Blob from the data
const blob = new Blob([data]);
// Re-wrapping a Blob would drop its type, and the browser uses that to pick the extension.
const blob = data instanceof Blob ? data : new Blob([data]);

// Create an object URL for the Blob
const blobUrl = URL.createObjectURL(blob);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import type { TableExpandableCellState } from '@nemo/common/src/components/DataView/TableExpandableCell';
import { Button, Flex, Modal, Text } from '@nvidia/foundations-react-core';
import type { FC } from 'react';

interface ExpandedCellModalProps {
readonly cell: TableExpandableCellState | null;
readonly onClose: () => void;
}

export const ExpandedCellModal: FC<ExpandedCellModalProps> = ({ cell, onClose }) => (
<Modal
open={cell !== null}
onOpenChange={(open) => {
if (!open) onClose();
}}
slotHeading={cell?.title ?? 'Cell Content'}
className="w-[90vw] max-w-[1000px]"
slotFooter={
<Flex justify="end" align="center" className="w-full">
<Button kind="tertiary" onClick={onClose}>
Close
</Button>
</Flex>
}
>
<div className="max-h-[70vh] overflow-auto">
<Text kind="body/regular/md" className="whitespace-pre-wrap">
{cell?.content}
</Text>
</div>
</Modal>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import {
Banner,
Panel,
TableBody,
TableDataCell,
TableHead,
TableHeaderCell,
TableRoot,
TableRow,
Text,
} from '@nvidia/foundations-react-core';
import { useDatasetFileContent } from '@studio/api/datasets/useDatasetFileContent';
import { parseArtifactUrl } from '@studio/routes/AnonymizerJobDetailRoute/util';
import { useMemo, type FC } from 'react';

interface FailedRecordsPanelProps {
readonly workspace: string;
readonly artifactUrl: string | undefined;
}

interface FailedRecord {
readonly record_id?: string;
readonly step?: string;
readonly reason?: string;
}

export const FailedRecordsPanel: FC<FailedRecordsPanelProps> = ({ workspace, artifactUrl }) => {
const location = parseArtifactUrl(artifactUrl);

const { data, error } = useDatasetFileContent({
workspace,
name: location?.fileset ?? '',
path: `${location?.basePath}/failed_records.json`,
// A truncated JSON array parses to nothing, hiding every failure.
fullContent: true,
enabled: !!location,
});

const records = useMemo<FailedRecord[]>(() => {
try {
const parsed = JSON.parse(data ?? '[]');
return Array.isArray(parsed) ? (parsed as FailedRecord[]) : [];
} catch {
return [];
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}, [data]);

if (error || !records.length) return null;

return (
<Panel slotHeading={`Failed Records (${records.length})`} elevation="high" density="compact">
<Banner kind="inline" status="warning">
These records were dropped during processing and are absent from the results.
</Banner>
<TableRoot className="bg-transparent w-full mt-density-md" align="left">
<TableHead>
<TableRow>
<TableHeaderCell>Record</TableHeaderCell>
<TableHeaderCell>Step</TableHeaderCell>
<TableHeaderCell>Reason</TableHeaderCell>
</TableRow>
</TableHead>
<TableBody>
{records.map((record, index) => (
<TableRow key={record.record_id ?? index}>
<TableDataCell>
<Text kind="body/regular/sm">{record.record_id ?? '—'}</Text>
</TableDataCell>
<TableDataCell>{record.step ?? '—'}</TableDataCell>
<TableDataCell>{record.reason ?? '—'}</TableDataCell>
</TableRow>
))}
</TableBody>
</TableRoot>
</Panel>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import { KVPair } from '@nemo/common/src/components/KVPair';
import { RelativeTime } from '@nemo/common/src/components/RelativeTime';
import { StatusBadge } from '@nemo/common/src/components/StatusBadge';
import type { RunJob } from '@nemo/sdk/generated/anonymizer/schema';
import { Banner, Grid, Panel, Stack } from '@nvidia/foundations-react-core';
import { EMPTY_FIELD_VALUE } from '@studio/constants/constants';
import { jobSource, jobStrategy } from '@studio/routes/AnonymizerJobDetailRoute/util';
import type { FC } from 'react';

interface JobSummaryPanelProps {
readonly job: RunJob;
}

export const JobSummaryPanel: FC<JobSummaryPanelProps> = ({ job }) => {
const errorMessage = job.error_details?.message as string | undefined;

return (
<Panel slotHeading="Job Details" elevation="high" density="compact">
<Stack gap="density-xl">
<Grid cols={{ base: 1, md: 2 }} gap="density-lg">
<KVPair
label="Status"
value={job.status ? <StatusBadge status={job.status} /> : EMPTY_FIELD_VALUE}
/>
<KVPair label="Strategy" value={jobStrategy(job) ?? EMPTY_FIELD_VALUE} />
<KVPair
label="Created"
value={job.created_at ? <RelativeTime datetime={job.created_at} /> : EMPTY_FIELD_VALUE}
/>
<KVPair
label="Updated"
value={job.updated_at ? <RelativeTime datetime={job.updated_at} /> : EMPTY_FIELD_VALUE}
/>
<KVPair
label="Created by"
value={(job.ownership?.created_by as string | undefined) ?? EMPTY_FIELD_VALUE}
/>
</Grid>
<KVPair label="Source" value={jobSource(job) ?? EMPTY_FIELD_VALUE} />
{errorMessage ? (
<Banner kind="inline" status="error">
{errorMessage}
</Banner>
) : null}
</Stack>
</Panel>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import { triggerDownload } from '@nemo/common/src/utils/file';
import { anonymizerDownloadRunJobResult } from '@nemo/sdk/generated/anonymizer/api';
import type { PlatformJobResultResponse } from '@nemo/sdk/generated/anonymizer/schema';
import { Banner, Button, Flex, Panel, Spinner, Stack, Text } from '@nvidia/foundations-react-core';
import { Download } from 'lucide-react';
import { useState, type FC } from 'react';

interface ResultsPanelProps {
readonly workspace: string;
readonly jobName: string;
readonly results: readonly PlatformJobResultResponse[];
readonly isLoading: boolean;
readonly isTerminal: boolean;
readonly loadError: boolean;
}

export const ResultsPanel: FC<ResultsPanelProps> = ({
workspace,
jobName,
results,
isLoading,
isTerminal,
loadError,
}) => {
const [downloading, setDownloading] = useState<string | null>(null);
const [error, setError] = useState<string | undefined>(undefined);

const download = async (name: string) => {
setDownloading(name);
setError(undefined);
try {
const blob = await anonymizerDownloadRunJobResult(workspace, jobName, name);
triggerDownload(blob, name);
} catch {
setError(`Could not download ${name}`);
} finally {
setDownloading(null);
}
};

return (
<Panel slotHeading="Results" elevation="high" density="compact">
<Stack gap="density-md">
{error ? (
<Banner kind="inline" status="error">
{error}
</Banner>
) : null}
{loadError ? (
<Banner kind="inline" status="error">
Could not load results for this job.
</Banner>
) : isLoading ? (
<Spinner aria-label="Loading results" />
) : results.length ? (
results.map((result) => (
<Flex key={result.name} align="center" justify="between" gap="density-md">
<Text kind="body/regular/md">{result.name}</Text>
<Button
kind="tertiary"
size="small"
disabled={downloading === result.name}
onClick={() => download(result.name)}
>
<Download />
Download
</Button>
</Flex>
))
) : (
<Text kind="body/regular/md">
{isTerminal ? 'This job produced no results.' : 'Results appear once the job finishes.'}
</Text>
)}
</Stack>
</Panel>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import type { TableExpandableCellState } from '@nemo/common/src/components/DataView/TableExpandableCell';
import { Banner, Panel, Spinner, Stack, Text } from '@nvidia/foundations-react-core';
import { ExpandedCellModal } from '@studio/routes/AnonymizerJobDetailRoute/components/ExpandedCellModal';
import { ResultsPreviewTable } from '@studio/routes/AnonymizerJobDetailRoute/components/ResultsPreviewTable';
import { useResultPreview } from '@studio/routes/AnonymizerJobDetailRoute/useResultPreview';
import { useCallback, useState, type FC } from 'react';

interface ResultsPreviewPanelProps {
readonly workspace: string;
readonly artifactUrl: string | undefined;
}

export const ResultsPreviewPanel: FC<ResultsPreviewPanelProps> = ({ workspace, artifactUrl }) => {
const { rows, columns, isLoading, error } = useResultPreview(workspace, artifactUrl);
const [expandedCell, setExpandedCell] = useState<TableExpandableCellState | null>(null);
const closeExpandedCell = useCallback(() => setExpandedCell(null), []);

return (
<Panel slotHeading="Preview" elevation="high" density="compact">
{error ? (
<Banner kind="inline" status="error">
Could not load the result preview.
</Banner>
) : isLoading ? (
<Spinner aria-label="Loading preview" />
) : rows.length ? (
<Stack gap="density-md">
<ResultsPreviewTable rows={rows} columns={columns} onExpand={setExpandedCell} />
<Text kind="body/regular/sm">
Showing the first {rows.length} records. Download the result for the full dataset.
</Text>
</Stack>
) : (
<Text kind="body/regular/md">No preview available for this job.</Text>
)}
<ExpandedCellModal cell={expandedCell} onClose={closeExpandedCell} />
</Panel>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import { StudioDataView } from '@nemo/common/src/components/DataView/StudioDataView';
import {
TableExpandableCell,
type TableExpandableCellState,
} from '@nemo/common/src/components/DataView/TableExpandableCell';
import { useStudioDataViewState } from '@nemo/common/src/hooks/useStudioDataViewState';
import { Text } from '@nvidia/foundations-react-core';
import type { DataFileRow } from '@studio/components/FileRowEditor/types';
import { RESULT_PREVIEW_ROWS } from '@studio/routes/AnonymizerJobDetailRoute/util';
import { memo, useCallback, useMemo, type ComponentProps, type FC } from 'react';

interface ResultsPreviewTableProps {
readonly rows: readonly DataFileRow[];
readonly columns: readonly string[];
readonly onExpand: (cell: TableExpandableCellState) => void;
}

const cellText = (value: unknown): string =>
typeof value === 'object' ? JSON.stringify(value) : String(value);

/** Memoized so opening the expanded-cell modal does not re-render every cell. */
export const ResultsPreviewTable: FC<ResultsPreviewTableProps> = memo(
({ rows, columns, onExpand }) => {
const dataViewState = useStudioDataViewState({ defaultPageSize: RESULT_PREVIEW_ROWS });

const { pageIndex, pageSize } = dataViewState.pagination.state;
const pageRows = useMemo(
() => rows.slice(pageIndex * pageSize, (pageIndex + 1) * pageSize),
[rows, pageIndex, pageSize]
);

const makeColumns = useCallback<
ComponentProps<typeof StudioDataView<DataFileRow>>['makeColumns']
>(
(col) =>
columns.map((column) =>
col.display({
id: column,
header: column,
cell: ({ row }) => {
const value = row.original[column];
return value == null ? (
<Text kind="body/regular/sm" color="secondary">
—
</Text>
) : (
<TableExpandableCell content={cellText(value)} title={column} onExpand={onExpand} />
);
},
})
),
[columns, onExpand]
);

return (
<div className="flex flex-col min-h-[400px] max-h-[640px]">
<StudioDataView<DataFileRow>
dataViewState={dataViewState}
makeColumns={makeColumns}
maxTwoLines={false}
attributes={{ DataViewRoot: { data: pageRows, totalCount: rows.length } }}
/>
</div>
);
}
);

ResultsPreviewTable.displayName = 'ResultsPreviewTable';
Loading
Loading