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
4 changes: 4 additions & 0 deletions frontend/src/components/ContentTypeAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export default function ContentTypeAction<T, E>({
identityKey,
normalizeApiRow = (row: any) => row as E,
remoteTestConfig,
viewOnlyColumns,
extraViewActions
}: ContentTypeActionProps<T, E>) {
const { isAdmin, isEditor } = useUserRole();

Expand Down Expand Up @@ -166,6 +168,8 @@ export default function ContentTypeAction<T, E>({
normalizeApiRow={normalizeApiRow}
clearPreview={() => setPreviewRows([])}
remoteTestConfig={remoteTestConfig}
viewOnlyColumns={viewOnlyColumns}
extraViewActions={extraViewActions}
/>
<DuplicateCsvDialog
open={duplicateDialogOpen}
Expand Down
38 changes: 26 additions & 12 deletions frontend/src/components/UploadOrViewDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export default function UploadOrViewDialog<T>({
normalizeApiRow = (row: any) => row,
clearPreview,
remoteTestConfig,
viewOnlyColumns = [],
extraViewActions,
}: UploadOrViewDialogProps<T>) {
const [isUploading, setIsUploading] = useState(false);
const [overwrite, setOverwrite] = useState(false);
Expand Down Expand Up @@ -159,12 +161,23 @@ export default function UploadOrViewDialog<T>({

const columnsWithStatus: ColumnDef<T & { status?: string }>[] =
useMemo(() => {
if (!previewWithExistingData)
return columns as ColumnDef<T & { status?: string }>[];
// Base columns — preview gets these only
const base = columns as ColumnDef<T & { status?: string }>[];

// View-only columns appended before the status column in view mode
const withViewOnly: ColumnDef<T & { status?: string }>[] =
mode === "view"
? [
...base,
...(viewOnlyColumns as ColumnDef<T & { status?: string }>[]),
]
: base;

if (!previewWithExistingData) return withViewOnly;

const helper = createColumnHelper<T & { status?: string }>();
return [
...(columns as ColumnDef<T & { status?: string }>[]),
...withViewOnly,
helper.accessor((row) => row.status, {
id: "status",
header: ({ column }) => (
Expand All @@ -184,7 +197,7 @@ export default function UploadOrViewDialog<T>({
},
}),
] as ColumnDef<T & { status?: string }>[];
}, [columns, previewWithExistingData]);
}, [columns, viewOnlyColumns, mode, previewWithExistingData]);

// handle upload action
const handleUpload = async () => {
Expand Down Expand Up @@ -316,13 +329,13 @@ export default function UploadOrViewDialog<T>({

const filteredRows: Record<string, any>[] = requiredHeaders?.length
? rows.map((row) =>
Object.fromEntries(
requiredHeaders.map((key) => [
key,
(row as Record<string, any>)[key] ?? "",
]),
),
)
Object.fromEntries(
requiredHeaders.map((key) => [
key,
(row as Record<string, any>)[key] ?? "",
]),
),
)
: (rows as Record<string, any>[]);

const csv = Papa.unparse(filteredRows, {
Expand Down Expand Up @@ -427,7 +440,7 @@ export default function UploadOrViewDialog<T>({

{mode === "view" && (
<div className="flex flex-wrap w-full items-center justify-end gap-4">
{remoteTestConfig && (isAdmin) && (
{remoteTestConfig && isAdmin && (
<Button
variant="outline"
className="cursor-pointer"
Expand Down Expand Up @@ -459,6 +472,7 @@ export default function UploadOrViewDialog<T>({
{remoteTestConfig.buttonLabel}
</Button>
)}
{(isAdmin || isEditor) && extraViewActions}
{(isAdmin || isEditor) && (
<Button
onClick={() => onRequestFilePick?.()}
Expand Down
Loading
Loading