ConceptPortal-public/rsconcept/frontend/src/dialogs/DlgEditReference/DlgEditReference.tsx

105 lines
3.0 KiB
TypeScript
Raw Normal View History

'use client';
import clsx from 'clsx';
2024-04-30 17:16:45 +03:00
import { useMemo, useState } from 'react';
2023-12-01 22:50:43 +03:00
import { TabList, TabPanel, Tabs } from 'react-tabs';
2024-05-16 22:39:28 +03:00
import BadgeHelp from '@/components/info/BadgeHelp';
import Modal from '@/components/ui/Modal';
import Overlay from '@/components/ui/Overlay';
import TabLabel from '@/components/ui/TabLabel';
import { ReferenceType } from '@/models/language';
2023-12-26 14:23:51 +03:00
import { HelpTopic } from '@/models/miscellaneous';
import { IRSForm } from '@/models/rsform';
2024-06-09 20:41:33 +03:00
import { PARAMETER } from '@/utils/constants';
import { labelReferenceType } from '@/utils/labels';
2023-12-01 22:50:43 +03:00
import EntityTab from './EntityTab';
import SyntacticTab from './SyntacticTab';
export interface IReferenceInputState {
2023-12-28 14:04:44 +03:00
type: ReferenceType;
refRaw?: string;
text?: string;
mainRefs: string[];
basePosition: number;
}
interface DlgEditReferenceProps {
2023-12-28 14:04:44 +03:00
hideWindow: () => void;
schema: IRSForm;
2023-12-28 14:04:44 +03:00
initial: IReferenceInputState;
onSave: (newRef: string) => void;
}
2023-12-01 22:50:43 +03:00
export enum TabID {
ENTITY = 0,
SYNTACTIC = 1
}
function DlgEditReference({ hideWindow, schema, initial, onSave }: DlgEditReferenceProps) {
2023-12-01 22:50:43 +03:00
const [activeTab, setActiveTab] = useState(initial.type === ReferenceType.ENTITY ? TabID.ENTITY : TabID.SYNTACTIC);
2023-12-01 22:50:43 +03:00
const [reference, setReference] = useState('');
const [isValid, setIsValid] = useState(false);
2023-12-28 14:04:44 +03:00
2023-12-01 22:50:43 +03:00
const handleSubmit = () => onSave(reference);
2023-12-28 14:04:44 +03:00
2024-04-30 17:16:45 +03:00
const entityPanel = useMemo(
() => (
<TabPanel>
<EntityTab initial={initial} schema={schema} setReference={setReference} setIsValid={setIsValid} />
</TabPanel>
),
[initial, schema]
);
const syntacticPanel = useMemo(
() => (
<TabPanel>
<SyntacticTab initial={initial} setReference={setReference} setIsValid={setIsValid} />
</TabPanel>
),
[initial]
);
return (
2023-12-28 14:04:44 +03:00
<Modal
header='Редактирование ссылки'
submitText='Сохранить ссылку'
hideWindow={hideWindow}
canSubmit={isValid}
onSubmit={handleSubmit}
2024-06-09 20:41:33 +03:00
className='w-[40rem] px-6 min-h-[35rem]'
>
2024-06-09 20:41:33 +03:00
<Overlay position='top-0 right-0'>
<BadgeHelp
topic={HelpTopic.TERM_CONTROL}
className={clsx(PARAMETER.TOOLTIP_WIDTH, 'sm:max-w-[40rem]')}
offset={14}
/>
2023-12-28 14:04:44 +03:00
</Overlay>
<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-06-09 20:41:33 +03:00
<TabLabel title='Отсылка на термин в заданной словоформе' label={labelReferenceType(ReferenceType.ENTITY)} />
<TabLabel
2023-12-28 14:04:44 +03:00
title='Установление синтаксической связи с отсылкой на термин'
label={labelReferenceType(ReferenceType.SYNTACTIC)}
/>
</TabList>
2024-04-30 17:16:45 +03:00
{entityPanel}
{syntacticPanel}
2023-12-28 14:04:44 +03:00
</Tabs>
</Modal>
);
}
2023-12-28 14:04:44 +03:00
export default DlgEditReference;