2023-12-13 14:32:57 +03:00
|
|
|
'use client';
|
|
|
|
|
2023-12-08 19:24:08 +03:00
|
|
|
import { useMemo, useState } from 'react';
|
|
|
|
|
2023-12-13 14:32:57 +03:00
|
|
|
import { useConceptTheme } from '@/context/ThemeContext';
|
|
|
|
import { IConstituenta, IRSForm } from '@/models/rsform';
|
|
|
|
|
2023-12-08 19:24:08 +03:00
|
|
|
import ConstituentsSearch from './ConstituentsSearch';
|
|
|
|
import ConstituentsTable from './ConstituentsTable';
|
|
|
|
|
|
|
|
// Height that should be left to accomodate navigation panel + bottom margin
|
|
|
|
const LOCAL_NAVIGATION_H = '2.1rem';
|
|
|
|
|
|
|
|
// Window width cutoff for expression show
|
|
|
|
const COLUMN_EXPRESSION_HIDE_THRESHOLD = 1500;
|
|
|
|
|
|
|
|
interface ViewConstituentsProps {
|
|
|
|
expression: string
|
|
|
|
baseHeight: string
|
|
|
|
activeID?: number
|
|
|
|
schema?: IRSForm
|
|
|
|
onOpenEdit: (cstID: number) => void
|
|
|
|
}
|
|
|
|
|
|
|
|
function ViewConstituents({ expression, baseHeight, schema, activeID, onOpenEdit }: ViewConstituentsProps) {
|
|
|
|
const { noNavigation } = useConceptTheme();
|
|
|
|
|
|
|
|
const [filteredData, setFilteredData] = useState<IConstituenta[]>(schema?.items ?? []);
|
|
|
|
|
|
|
|
const maxHeight = useMemo(
|
|
|
|
() => {
|
|
|
|
const siblingHeight = `${baseHeight} - ${LOCAL_NAVIGATION_H}`
|
|
|
|
return (noNavigation ?
|
|
|
|
`calc(min(100vh - 8.2rem, ${siblingHeight}))`
|
|
|
|
: `calc(min(100vh - 11.7rem, ${siblingHeight}))`);
|
|
|
|
}, [noNavigation, baseHeight]);
|
|
|
|
|
|
|
|
return (<>
|
|
|
|
<ConstituentsSearch
|
|
|
|
schema={schema}
|
|
|
|
activeID={activeID}
|
|
|
|
activeExpression={expression}
|
|
|
|
setFiltered={setFilteredData}
|
|
|
|
/>
|
2023-12-16 19:20:26 +03:00
|
|
|
<div className='overflow-y-auto text-sm select-none overscroll-none' style={{maxHeight : `${maxHeight}`}}>
|
2023-12-08 19:24:08 +03:00
|
|
|
<ConstituentsTable
|
|
|
|
items={filteredData}
|
|
|
|
activeID={activeID}
|
|
|
|
onOpenEdit={onOpenEdit}
|
|
|
|
denseThreshold={COLUMN_EXPRESSION_HIDE_THRESHOLD}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</>);
|
|
|
|
}
|
|
|
|
|
2023-12-13 14:32:57 +03:00
|
|
|
export default ViewConstituents;
|