import { Checkbox, Classes } from '@blueprintjs/core'; import type { SpectraTableColumn } from '@zakodium/nmrium-core'; import { useMemo } from 'react'; import { useFormContext } from 'react-hook-form'; import { FaPlus, FaRegTrashAlt } from 'react-icons/fa'; import { Button } from 'react-science/ui'; import type { CellProps } from 'react-table'; import type { InputStyle } from '../../../elements/Input.js'; import { Input2Controller } from '../../../elements/Input2Controller.js'; import type { Column } from '../../../elements/ReactTable/ReactTable.js'; import ReactTable from '../../../elements/ReactTable/ReactTable.js'; import { convertPathArrayToString } from '../../../utility/convertPathArrayToString.js'; const inputStyle: InputStyle = { input: { width: '100%', fontSize: '1.1em', textAlign: 'start', backgroundColor: 'transparent', }, inputWrapper: { padding: '0.25rem 0.5rem', borderRadius: 0, borderColor: 'white', }, }; function getObjectKey( nucleus: string, index: number, key: keyof SpectraTableColumn, ) { return `nuclei.${nucleus}.columns.${index}.${key}`; } interface SpectraColumnsManagerProps { nucleus: string; onAdd: (nucleus: string, index: number) => void; onDelete: (nucleus: string, index: number) => void; datalist?: string[]; mapOnChangeValue: (value: string) => string; } export function SpectraColumnsManager({ nucleus, onAdd, onDelete, datalist, mapOnChangeValue, }: SpectraColumnsManagerProps) { const { control, getValues, register } = useFormContext(); const COLUMNS = useMemo>>( () => [ { Header: '#', style: { width: '25px' }, accessor: (_, index) => index + 1, }, { Header: 'Label', style: { padding: 0 }, Cell: ({ row }: CellProps) => { const name = getObjectKey(nucleus, row.index, 'label'); return ( ); }, }, { Header: 'Column', style: { padding: 0 }, Cell: ({ row }: CellProps) => { const column: any = row.original; if (column?.name) { return ( {column?.jpath?.join('.') || column.description} ); } const name = getObjectKey(nucleus, row.index, 'jpath'); return ( ); }, }, { Header: 'Visible', style: { width: '30px', textAlign: 'center' }, Cell: ({ row }: CellProps) => ( ), }, { Header: '', style: { width: '65px' }, id: 'op-buttons', Cell: ({ row }: CellProps) => { const record: any = row.original; return (
{!record?.name && ( )}
); }, }, ], [control, datalist, mapOnChangeValue, nucleus, onAdd, onDelete, register], ); return ( ); }