ConceptPortal-public/rsconcept/frontend/src/pages/RSFormPage/ViewConstituents/ViewConstituents.tsx

68 lines
1.9 KiB
TypeScript
Raw Normal View History

'use client';
import clsx from 'clsx';
import { motion } from 'framer-motion';
import { useMemo, useState } from 'react';
2023-12-08 19:24:08 +03:00
2024-04-01 19:07:20 +03:00
import { useConceptOptions } from '@/context/OptionsContext';
2024-03-17 19:24:12 +03:00
import { ConstituentaID, IConstituenta, IRSForm } from '@/models/rsform';
import { animateSideView } from '@/styling/animations';
2023-12-08 19:24:08 +03:00
import ConstituentsSearch from './ConstituentsSearch';
import ConstituentsTable from './ConstituentsTable';
// Window width cutoff for expression show
const COLUMN_EXPRESSION_HIDE_THRESHOLD = 1500;
interface ViewConstituentsProps {
2023-12-28 14:04:44 +03:00
expression: string;
isBottom?: boolean;
2024-05-23 13:36:16 +03:00
activeCst?: IConstituenta;
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-05-23 13:36:16 +03:00
function ViewConstituents({ expression, schema, activeCst, isBottom, onOpenEdit }: ViewConstituentsProps) {
2024-04-06 14:39:49 +03:00
const { calculateHeight } = useConceptOptions();
2023-12-28 14:04:44 +03:00
2023-12-08 19:24:08 +03:00
const [filteredData, setFilteredData] = useState<IConstituenta[]>(schema?.items ?? []);
const table = useMemo(
() => (
<ConstituentsTable
maxHeight={isBottom ? '12rem' : calculateHeight('8.2rem')}
items={filteredData}
2024-05-23 13:36:16 +03:00
activeCst={activeCst}
onOpenEdit={onOpenEdit}
denseThreshold={COLUMN_EXPRESSION_HIDE_THRESHOLD}
/>
),
2024-05-23 13:36:16 +03:00
[isBottom, filteredData, activeCst, onOpenEdit, calculateHeight]
);
2023-12-17 20:19:28 +03:00
return (
2023-12-28 14:04:44 +03:00
<motion.div
className={clsx(
2024-05-12 13:58:28 +03:00
'border overflow-hidden', // prettier: split-lines
{
2024-05-12 13:58:28 +03:00
'mt-[2.2rem] rounded-l-md rounded-r-none': !isBottom, // prettier: split-lines
'mt-3 mx-6 rounded-md': isBottom
}
)}
2023-12-28 14:04:44 +03:00
initial={{ ...animateSideView.initial }}
animate={{ ...animateSideView.animate }}
exit={{ ...animateSideView.exit }}
>
<ConstituentsSearch
schema={schema}
2024-05-23 13:36:16 +03:00
activeID={activeCst?.id}
2023-12-28 14:04:44 +03:00
activeExpression={expression}
setFiltered={setFilteredData}
/>
{table}
2023-12-28 14:04:44 +03:00
</motion.div>
);
2023-12-08 19:24:08 +03:00
}
2023-12-28 14:04:44 +03:00
export default ViewConstituents;