'use client'; import { useCallback, useMemo, useState } from 'react'; import { BiChevronLeft, BiChevronRight, BiFirstPage, BiLastPage, BiX } from 'react-icons/bi'; import { LuLocate, LuLocateOff, LuPower, LuPowerOff, LuReplace } from 'react-icons/lu'; import ConstituentaBadge from '@/components/info/ConstituentaBadge'; import ConstituentaSelector from '@/components/select/ConstituentaSelector'; import DataTable, { createColumnHelper } from '@/components/ui/DataTable'; import Label from '@/components/ui/Label'; import MiniButton from '@/components/ui/MiniButton'; import { useConceptOptions } from '@/context/OptionsContext'; import { IConstituenta, IRSForm, ISubstitution } from '@/models/rsform'; import { describeConstituenta } from '@/utils/labels'; interface SubstitutionsPickerProps { prefixID: string; rows?: number; schema1?: IRSForm; schema2?: IRSForm; filter1?: (cst: IConstituenta) => boolean; filter2?: (cst: IConstituenta) => boolean; items: ISubstitution[]; setItems: React.Dispatch>; } function SubstitutionIcon({ item }: { item: ISubstitution }) { if (item.deleteRight) { if (item.takeLeftTerm) { return ; } else { return ; } } else { if (item.takeLeftTerm) { return ; } else { return ; } } } const columnHelper = createColumnHelper(); function SubstitutionsPicker({ items, schema1, schema2, filter1, filter2, rows, setItems, prefixID }: SubstitutionsPickerProps) { const { colors } = useConceptOptions(); const [leftCst, setLeftCst] = useState(undefined); const [rightCst, setRightCst] = useState(undefined); const [deleteRight, setDeleteRight] = useState(true); const [takeLeftTerm, setTakeLeftTerm] = useState(true); const toggleDelete = () => setDeleteRight(prev => !prev); const toggleTerm = () => setTakeLeftTerm(prev => !prev); function addSubstitution() { if (!leftCst || !rightCst) { return; } const newSubstitution: ISubstitution = { leftCst: leftCst, rightCst: rightCst, deleteRight: deleteRight, takeLeftTerm: takeLeftTerm }; setItems([ newSubstitution, ...items.filter( item => (!item.deleteRight && item.leftCst.id !== leftCst.id) || (item.deleteRight && item.rightCst.id !== rightCst.id) ) ]); } const handleDeleteRow = useCallback( (row: number) => { setItems(prev => { const newItems: ISubstitution[] = []; prev.forEach((item, index) => { if (index !== row) { newItems.push(item); } }); return newItems; }); }, [setItems] ); const columns = useMemo( () => [ columnHelper.accessor(item => describeConstituenta(item.leftCst), { id: 'left_text', header: 'Описание', size: 1000, cell: props =>
{props.getValue()}
}), columnHelper.accessor(item => item.leftCst.alias, { id: 'left_alias', header: 'Имя', size: 65, cell: props => ( ) }), columnHelper.display({ id: 'status', header: '', size: 40, cell: props => }), columnHelper.accessor(item => item.rightCst.alias, { id: 'right_alias', header: 'Имя', size: 65, cell: props => ( ) }), columnHelper.accessor(item => describeConstituenta(item.rightCst), { id: 'right_text', header: 'Описание', size: 1000, cell: props =>
{props.getValue()}
}), columnHelper.display({ id: 'actions', size: 50, minSize: 50, maxSize: 50, cell: props => ( } onClick={() => handleDeleteRow(props.row.index)} /> ) }) ], [handleDeleteRow, colors, prefixID] ); return (
!filter1 || filter1(cst))} value={leftCst} onSelectValue={setLeftCst} />
} disabled={!leftCst || !rightCst} onClick={addSubstitution} />
!filter2 || filter2(cst))} value={rightCst} onSelectValue={setRightCst} />

Список пуст

Добавьте отождествление

} />
); } export default SubstitutionsPicker;