import React from 'react'; import { Body, Cell, Checkbox, Row, Table, TableHeader, css, cx, spacing, Label, } from '@mongodb-js/compass-components'; import type { Document } from 'mongodb'; import { SelectFieldType } from './select-field-type'; import { createDebug } from '../utils/logger'; const debug = createDebug('import-preview'); const columnHeaderStyles = css({ display: 'flex', gap: spacing[1], minWidth: spacing[6] * 2, paddingRight: spacing[2], alignItems: 'center', }); const fieldPathHeaderStyles = css({ maxWidth: spacing[7] * 3, overflow: 'hidden', whiteSpace: 'nowrap', textOverflow: 'ellipsis', }); const cellContainerStyles = css({ padding: `${spacing[1]}px ${spacing[2]}px`, }); const cellStyles = css({ maxWidth: spacing[7] * 3, overflow: 'hidden', whiteSpace: 'nowrap', textOverflow: 'ellipsis', }); const cellUncheckedStyles = css({ opacity: 0.4, }); function ImportPreview({ fields, values, onFieldCheckedChanged, setFieldType, loaded, }: { fields: { path: string; type: string; checked: boolean; }[]; values: Document[]; onFieldCheckedChanged: (fieldPath: string, checked: boolean) => void; setFieldType: (fieldPath: string, fieldType: string) => void; loaded: boolean; }) { if (!loaded) { debug('Preview unavailable: not loaded yet'); return null; } if (!Array.isArray(fields) || !Array.isArray(values)) { debug('Preview unavailable: Fields or values is not an array', { fields, values, }); return null; } return ( <> Specify Fields and Types ( ) => onFieldCheckedChanged(field.path, !!e.target.checked) } />
setFieldType(field.path, newType) } />
} /> ))} > {({ datum: values }) => ( {fields.map(({ path }, fieldIndex) => (
{(values[fieldIndex] as unknown as string) === '' ? ( empty string ) : ( values[fieldIndex] )}
))}
)}
); } export { ImportPreview };