'use client'; import clsx from 'clsx'; import { useCallback, useLayoutEffect, useMemo, useState } from 'react'; import ConstituentaBadge from '@/components/info/ConstituentaBadge'; import DataTable, { createColumnHelper, IConditionalStyle, VisibilityState } from '@/components/ui/DataTable'; import { useConceptOptions } from '@/context/OptionsContext'; import useWindowSize from '@/hooks/useWindowSize'; import { ConstituentaID, IConstituenta } from '@/models/rsform'; import { isMockCst } from '@/models/rsformAPI'; import { prefixes } from '@/utils/constants'; import { describeConstituenta } from '@/utils/labels'; interface ConstituentsTableProps { items: IConstituenta[]; activeID?: ConstituentaID; onOpenEdit: (cstID: ConstituentaID) => void; denseThreshold?: number; maxHeight: string; } const columnHelper = createColumnHelper(); function ConstituentsTable({ items, activeID, onOpenEdit, maxHeight, denseThreshold = 9999 }: ConstituentsTableProps) { const { colors } = useConceptOptions(); const windowSize = useWindowSize(); const [columnVisibility, setColumnVisibility] = useState({ expression: true }); useLayoutEffect(() => { setColumnVisibility(prev => { const newValue = (windowSize.width ?? 0) >= denseThreshold; if (newValue === prev['expression']) { return prev; } else { return { expression: newValue }; } }); }, [windowSize, denseThreshold]); const handleRowClicked = useCallback( (cst: IConstituenta) => { if (!isMockCst(cst)) { onOpenEdit(cst.id); } }, [onOpenEdit] ); const columns = useMemo( () => [ columnHelper.accessor('alias', { id: 'alias', header: 'Имя', size: 65, minSize: 65, footer: undefined, cell: props => ( ) }), columnHelper.accessor(cst => describeConstituenta(cst), { id: 'description', header: 'Описание', size: 1000, minSize: 250, maxSize: 1000, cell: props => (
{props.getValue()}
) }), columnHelper.accessor('definition_formal', { id: 'expression', header: 'Выражение', size: 2000, minSize: 0, maxSize: 2000, enableHiding: true, cell: props => (
{props.getValue()}
) }) ], [colors] ); const conditionalRowStyles = useMemo( (): IConditionalStyle[] => [ { when: (cst: IConstituenta) => cst.id === activeID, style: { backgroundColor: colors.bgSelected } }, { when: (cst: IConstituenta) => cst.parent === activeID && cst.id !== activeID, style: { backgroundColor: colors.bgOrange50 } }, { when: (cst: IConstituenta) => activeID !== undefined && cst.children.includes(activeID), style: { backgroundColor: colors.bgGreen50 } } ], [activeID, colors] ); return (

Список конституент пуст

Измените параметры фильтра

} onRowClicked={handleRowClicked} /> ); } export default ConstituentsTable;