2024-03-18 16:22:27 +03:00
|
|
|
'use client';
|
|
|
|
|
|
|
|
import clsx from 'clsx';
|
2024-03-21 17:48:42 +03:00
|
|
|
import { useEffect, useMemo, useState } from 'react';
|
2024-03-18 16:22:27 +03:00
|
|
|
import { TabList, TabPanel, Tabs } from 'react-tabs';
|
|
|
|
|
|
|
|
import Modal, { ModalProps } from '@/components/ui/Modal';
|
|
|
|
import TabLabel from '@/components/ui/TabLabel';
|
|
|
|
import useRSFormDetails from '@/hooks/useRSFormDetails';
|
|
|
|
import { LibraryItemID } from '@/models/library';
|
2024-07-30 16:00:09 +03:00
|
|
|
import { ICstSubstitute } from '@/models/oss';
|
|
|
|
import { IInlineSynthesisData, IRSForm } from '@/models/rsform';
|
2024-03-18 16:22:27 +03:00
|
|
|
|
2024-06-26 19:47:31 +03:00
|
|
|
import TabConstituents from './TabConstituents';
|
|
|
|
import TabSchema from './TabSchema';
|
|
|
|
import TabSubstitutions from './TabSubstitutions';
|
2024-03-18 16:22:27 +03:00
|
|
|
|
|
|
|
interface DlgInlineSynthesisProps extends Pick<ModalProps, 'hideWindow'> {
|
|
|
|
receiver: IRSForm;
|
2024-03-23 21:42:50 +03:00
|
|
|
onInlineSynthesis: (data: IInlineSynthesisData) => void;
|
2024-03-18 16:22:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export enum TabID {
|
|
|
|
SCHEMA = 0,
|
|
|
|
SELECTIONS = 1,
|
|
|
|
SUBSTITUTIONS = 2
|
|
|
|
}
|
|
|
|
|
|
|
|
function DlgInlineSynthesis({ hideWindow, receiver, onInlineSynthesis }: DlgInlineSynthesisProps) {
|
|
|
|
const [activeTab, setActiveTab] = useState(TabID.SCHEMA);
|
|
|
|
|
|
|
|
const [donorID, setDonorID] = useState<LibraryItemID | undefined>(undefined);
|
|
|
|
const [selected, setSelected] = useState<LibraryItemID[]>([]);
|
2024-07-30 16:00:09 +03:00
|
|
|
const [substitutions, setSubstitutions] = useState<ICstSubstitute[]>([]);
|
2024-03-18 16:22:27 +03:00
|
|
|
|
|
|
|
const source = useRSFormDetails({ target: donorID ? String(donorID) : undefined });
|
|
|
|
|
2024-03-21 17:48:42 +03:00
|
|
|
const validated = useMemo(() => !!source.schema && selected.length > 0, [source.schema, selected]);
|
2024-03-18 16:22:27 +03:00
|
|
|
|
|
|
|
function handleSubmit() {
|
|
|
|
if (!source.schema) {
|
|
|
|
return;
|
|
|
|
}
|
2024-03-23 21:42:50 +03:00
|
|
|
const data: IInlineSynthesisData = {
|
2024-03-18 16:22:27 +03:00
|
|
|
source: source.schema?.id,
|
|
|
|
receiver: receiver.id,
|
|
|
|
items: selected,
|
2024-07-30 16:00:09 +03:00
|
|
|
substitutions: substitutions
|
2024-03-18 16:22:27 +03:00
|
|
|
};
|
|
|
|
onInlineSynthesis(data);
|
|
|
|
}
|
|
|
|
|
2024-03-24 19:25:42 +03:00
|
|
|
useEffect(() => {
|
|
|
|
setSelected(source.schema ? source.schema?.items.map(cst => cst.id) : []);
|
|
|
|
setSubstitutions([]);
|
|
|
|
}, [source.schema]);
|
2024-03-21 17:48:42 +03:00
|
|
|
|
2024-04-30 17:16:45 +03:00
|
|
|
const schemaPanel = useMemo(
|
|
|
|
() => (
|
|
|
|
<TabPanel>
|
2024-06-26 19:47:31 +03:00
|
|
|
<TabSchema selected={donorID} setSelected={setDonorID} />
|
2024-04-30 17:16:45 +03:00
|
|
|
</TabPanel>
|
|
|
|
),
|
|
|
|
[donorID]
|
|
|
|
);
|
2024-04-30 16:06:25 +03:00
|
|
|
const itemsPanel = useMemo(
|
|
|
|
() => (
|
2024-04-30 17:16:45 +03:00
|
|
|
<TabPanel>
|
2024-06-26 19:47:31 +03:00
|
|
|
<TabConstituents
|
2024-04-30 17:16:45 +03:00
|
|
|
schema={source.schema}
|
|
|
|
loading={source.loading}
|
|
|
|
selected={selected}
|
|
|
|
setSelected={setSelected}
|
|
|
|
/>
|
|
|
|
</TabPanel>
|
2024-04-30 16:06:25 +03:00
|
|
|
),
|
|
|
|
[source.schema, source.loading, selected]
|
|
|
|
);
|
|
|
|
const substitutesPanel = useMemo(
|
|
|
|
() => (
|
2024-04-30 17:16:45 +03:00
|
|
|
<TabPanel>
|
2024-06-26 19:47:31 +03:00
|
|
|
<TabSubstitutions
|
2024-04-30 17:16:45 +03:00
|
|
|
receiver={receiver}
|
|
|
|
source={source.schema}
|
|
|
|
selected={selected}
|
|
|
|
loading={source.loading}
|
|
|
|
substitutions={substitutions}
|
|
|
|
setSubstitutions={setSubstitutions}
|
|
|
|
/>
|
|
|
|
</TabPanel>
|
2024-04-30 16:06:25 +03:00
|
|
|
),
|
|
|
|
[source.schema, source.loading, receiver, selected, substitutions]
|
|
|
|
);
|
|
|
|
|
2024-03-18 16:22:27 +03:00
|
|
|
return (
|
|
|
|
<Modal
|
|
|
|
header='Импорт концептуальной схем'
|
|
|
|
submitText='Добавить конституенты'
|
2024-09-10 17:40:58 +03:00
|
|
|
className='w-[40rem] h-[33rem] px-6'
|
2024-03-18 16:22:27 +03:00
|
|
|
hideWindow={hideWindow}
|
|
|
|
canSubmit={validated}
|
|
|
|
onSubmit={handleSubmit}
|
|
|
|
>
|
|
|
|
<Tabs
|
|
|
|
selectedTabClassName='clr-selected'
|
|
|
|
className='flex flex-col'
|
|
|
|
selectedIndex={activeTab}
|
|
|
|
onSelect={setActiveTab}
|
|
|
|
>
|
|
|
|
<TabList className={clsx('mb-3 self-center', 'flex', 'border divide-x rounded-none')}>
|
2024-03-19 19:19:08 +03:00
|
|
|
<TabLabel label='Схема' title='Источник конституент' className='w-[8rem]' />
|
|
|
|
<TabLabel label='Содержание' title='Перечень конституент' className='w-[8rem]' />
|
|
|
|
<TabLabel label='Отождествления' title='Таблица отождествлений' className='w-[8rem]' />
|
2024-03-18 16:22:27 +03:00
|
|
|
</TabList>
|
|
|
|
|
2024-04-30 17:16:45 +03:00
|
|
|
{schemaPanel}
|
|
|
|
{itemsPanel}
|
|
|
|
{substitutesPanel}
|
2024-03-18 16:22:27 +03:00
|
|
|
</Tabs>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default DlgInlineSynthesis;
|