2023-12-13 14:32:57 +03:00
|
|
|
'use client';
|
|
|
|
|
2024-03-15 14:35:06 +03:00
|
|
|
import clsx from 'clsx';
|
2023-12-25 16:53:27 +03:00
|
|
|
import { motion } from 'framer-motion';
|
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';
|
2024-03-17 19:24:12 +03:00
|
|
|
import { ConstituentaID, IConstituenta, IRSForm } from '@/models/rsform';
|
2024-01-06 03:15:02 +03:00
|
|
|
import { animateSideView } from '@/styling/animations';
|
2023-12-13 14:32:57 +03:00
|
|
|
|
2023-12-08 19:24:08 +03:00
|
|
|
import ConstituentsSearch from './ConstituentsSearch';
|
|
|
|
import ConstituentsTable from './ConstituentsTable';
|
|
|
|
|
2023-12-26 14:23:51 +03:00
|
|
|
// Height that should be left to accommodate navigation panel + bottom margin
|
2023-12-08 19:24:08 +03:00
|
|
|
const LOCAL_NAVIGATION_H = '2.1rem';
|
|
|
|
|
|
|
|
// Window width cutoff for expression show
|
|
|
|
const COLUMN_EXPRESSION_HIDE_THRESHOLD = 1500;
|
|
|
|
|
|
|
|
interface ViewConstituentsProps {
|
2023-12-28 14:04:44 +03:00
|
|
|
expression: string;
|
2024-03-15 14:35:06 +03:00
|
|
|
isBottom?: boolean;
|
2023-12-28 14:04:44 +03:00
|
|
|
baseHeight: string;
|
2024-03-17 19:24:12 +03:00
|
|
|
activeID?: ConstituentaID;
|
2023-12-28 14:04:44 +03:00
|
|
|
schema?: IRSForm;
|
2024-03-17 19:24:12 +03:00
|
|
|
onOpenEdit: (cstID: ConstituentaID) => void;
|
2023-12-08 19:24:08 +03:00
|
|
|
}
|
|
|
|
|
2024-03-15 14:35:06 +03:00
|
|
|
function ViewConstituents({ expression, schema, activeID, isBottom, baseHeight, onOpenEdit }: ViewConstituentsProps) {
|
2023-12-08 19:24:08 +03:00
|
|
|
const { noNavigation } = useConceptTheme();
|
2023-12-28 14:04:44 +03:00
|
|
|
|
2023-12-08 19:24:08 +03:00
|
|
|
const [filteredData, setFilteredData] = useState<IConstituenta[]>(schema?.items ?? []);
|
|
|
|
|
2023-12-28 14:04:44 +03:00
|
|
|
const maxHeight = useMemo(() => {
|
|
|
|
const siblingHeight = `${baseHeight} - ${LOCAL_NAVIGATION_H}`;
|
|
|
|
return noNavigation
|
|
|
|
? `calc(min(100vh - 8.2rem, ${siblingHeight}))`
|
|
|
|
: `calc(min(100vh - 11.7rem, ${siblingHeight}))`;
|
2023-12-08 19:24:08 +03:00
|
|
|
}, [noNavigation, baseHeight]);
|
|
|
|
|
2023-12-17 20:19:28 +03:00
|
|
|
return (
|
2023-12-28 14:04:44 +03:00
|
|
|
<motion.div
|
2024-03-15 14:35:06 +03:00
|
|
|
className={clsx(
|
|
|
|
'border', // prettier: split-lines
|
|
|
|
{
|
|
|
|
'mt-[2.25rem]': !isBottom, // prettier: split-lines
|
|
|
|
'mt-3 mx-6': isBottom
|
|
|
|
}
|
|
|
|
)}
|
2023-12-28 14:04:44 +03:00
|
|
|
initial={{ ...animateSideView.initial }}
|
|
|
|
animate={{ ...animateSideView.animate }}
|
|
|
|
exit={{ ...animateSideView.exit }}
|
|
|
|
>
|
|
|
|
<ConstituentsSearch
|
|
|
|
schema={schema}
|
|
|
|
activeID={activeID}
|
|
|
|
activeExpression={expression}
|
|
|
|
setFiltered={setFilteredData}
|
|
|
|
/>
|
|
|
|
<ConstituentsTable
|
2024-03-15 14:35:06 +03:00
|
|
|
maxHeight={isBottom ? '12rem' : maxHeight}
|
2023-12-28 14:04:44 +03:00
|
|
|
items={filteredData}
|
|
|
|
activeID={activeID}
|
|
|
|
onOpenEdit={onOpenEdit}
|
|
|
|
denseThreshold={COLUMN_EXPRESSION_HIDE_THRESHOLD}
|
|
|
|
/>
|
|
|
|
</motion.div>
|
|
|
|
);
|
2023-12-08 19:24:08 +03:00
|
|
|
}
|
|
|
|
|
2023-12-28 14:04:44 +03:00
|
|
|
export default ViewConstituents;
|