import DocPopup from "@/src/components/layouts/doc-popup"; import { Card, CardContent, CardHeader, CardTitle, } from "@/src/components/ui/card"; import { cn } from "@/src/utils/tailwind"; import { useDraggable, useDroppable } from "@dnd-kit/core"; import { type UniqueIdentifier } from "@dnd-kit/core"; import type { CsvColumnPreview } from "@/src/features/datasets/lib/csv/types"; type ImportCardProps = { title: string; columns: CsvColumnPreview[]; onColumnSelect: (columnName: string) => void; onColumnRemove: (columnName: string) => void; id: UniqueIdentifier; className?: string; info?: string; schemaKeys?: string[]; // Schema-driven mode schemaKeyMapping?: Map; // {schemaKey: csvColumn} onSchemaKeyMap?: (schemaKey: string, csvColumn: string) => void; }; function DraggableColumn({ column, parentId, }: { column: CsvColumnPreview; parentId: UniqueIdentifier; }) { const { attributes, listeners, setNodeRef, isDragging } = useDraggable({ id: column.name, data: { column, fromCardId: parentId, }, }); return (
{column.name} {column.inferredType}
); } function SchemaKeyDropZone({ schemaKey, mappedColumn, parentId, }: { schemaKey: string; mappedColumn?: string; parentId: UniqueIdentifier; }) { const dropId = `${parentId}:${schemaKey}`; const { setNodeRef, isOver } = useDroppable({ id: dropId }); return (
{schemaKey} {mappedColumn && ( {mappedColumn} )}
); } export function ImportCard({ title, columns, id, className, info, schemaKeys, schemaKeyMapping, }: ImportCardProps) { const { setNodeRef, isOver } = useDroppable({ id, }); const isSchemaMode = schemaKeys && schemaKeys.length > 0; return ( {title} {info && } {isSchemaMode ? ( // Schema-driven mode: show schema keys as drop zones <> {schemaKeys.map((schemaKey) => ( ))} ) : ( // Freeform mode: show draggable columns <> {columns.length === 0 && id !== "unmapped" ? (
Drag columns here
) : ( columns.map((column) => ( )) )} )}
); }