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 { InputStyle } from '../../../elements/Input.js'; import { Input2Controller } from '../../../elements/Input2Controller.js'; import { TanStackTable, createTanStackColumnHelper, } from '../../../elements/tanstack_table/index.ts'; 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(props: SpectraColumnsManagerProps) { const { nucleus, onAdd, onDelete, datalist, mapOnChangeValue } = props; const { control, getValues, register } = useFormContext(); const COLUMNS = useMemo(() => { const columnHelper = createTanStackColumnHelper(); return columnHelper.columns([ { header: '#', meta: { style: { width: '25px' } }, accessorFn: (_, index) => index + 1, }, { header: 'Label', meta: { style: { padding: 0 } }, cell: ({ row }) => { const name = getObjectKey(nucleus, row.index, 'label'); return ( ); }, }, { header: 'Column', meta: { style: { padding: 0 } }, cell: ({ row }) => { const column: any = row.original; if (column?.name) { return ( {column?.jpath?.join('.') || column.description} ); } const name = getObjectKey(nucleus, row.index, 'jpath'); return ( ); }, }, { header: 'Format', meta: { style: { padding: 0 } }, cell: ({ row }) => { const column = row.original as any; const name = getObjectKey(nucleus, row.index, 'format'); return ( ); }, }, { header: 'Visible', meta: { style: { width: '30px', textAlign: 'center' } }, cell: ({ row }) => ( ), }, { header: '', meta: { style: { width: '65px' } }, id: 'op-buttons', cell: ({ row }) => { const record: any = row.original; return (
{!record?.name && ( )}
); }, }, ]); }, [control, datalist, mapOnChangeValue, nucleus, onAdd, onDelete, register]); return ( ); }