2023-10-08 15:24:41 +03:00
|
|
|
|
import { useEffect, useLayoutEffect, useState } from 'react';
|
2023-07-25 20:27:29 +03:00
|
|
|
|
|
2023-09-11 17:56:32 +03:00
|
|
|
|
import Modal, { ModalProps } from '../../components/Common/Modal';
|
2023-09-14 16:53:38 +03:00
|
|
|
|
import SelectSingle from '../../components/Common/SelectSingle';
|
2023-08-16 18:32:37 +03:00
|
|
|
|
import TextArea from '../../components/Common/TextArea';
|
2023-10-08 15:24:41 +03:00
|
|
|
|
import TextInput from '../../components/Common/TextInput';
|
2023-08-16 18:32:37 +03:00
|
|
|
|
import RSInput from '../../components/RSInput';
|
2023-10-08 15:24:41 +03:00
|
|
|
|
import { CstType,ICstCreateData, IRSForm } from '../../models/rsform';
|
2023-09-21 14:58:01 +03:00
|
|
|
|
import { labelCstType } from '../../utils/labels';
|
2023-10-08 15:24:41 +03:00
|
|
|
|
import { createAliasFor, getCstTypePrefix } from '../../utils/misc';
|
2023-09-29 15:33:32 +03:00
|
|
|
|
import { SelectorCstType } from '../../utils/selectors';
|
2023-07-22 12:24:14 +03:00
|
|
|
|
|
2023-09-11 17:56:32 +03:00
|
|
|
|
interface DlgCreateCstProps
|
|
|
|
|
extends Pick<ModalProps, 'hideWindow'> {
|
2023-08-16 18:32:37 +03:00
|
|
|
|
initial?: ICstCreateData
|
2023-10-08 15:24:41 +03:00
|
|
|
|
schema: IRSForm
|
2023-08-16 18:32:37 +03:00
|
|
|
|
onCreate: (data: ICstCreateData) => void
|
2023-07-22 12:24:14 +03:00
|
|
|
|
}
|
|
|
|
|
|
2023-10-08 15:24:41 +03:00
|
|
|
|
function DlgCreateCst({ hideWindow, initial, schema, onCreate }: DlgCreateCstProps) {
|
2023-07-22 12:24:14 +03:00
|
|
|
|
const [validated, setValidated] = useState(false);
|
2023-08-16 18:32:37 +03:00
|
|
|
|
const [selectedType, setSelectedType] = useState<CstType>(CstType.BASE);
|
2023-10-08 15:24:41 +03:00
|
|
|
|
const [alias, setAlias] = useState('');
|
2023-08-16 18:32:37 +03:00
|
|
|
|
|
|
|
|
|
const [term, setTerm] = useState('');
|
|
|
|
|
const [textDefinition, setTextDefinition] = useState('');
|
|
|
|
|
const [expression, setExpression] = useState('');
|
|
|
|
|
const [convention, setConvention] = useState('');
|
|
|
|
|
|
|
|
|
|
function getData(): ICstCreateData {
|
|
|
|
|
return {
|
|
|
|
|
cst_type: selectedType,
|
|
|
|
|
insert_after: initial?.insert_after ?? null,
|
2023-10-08 15:24:41 +03:00
|
|
|
|
alias: alias,
|
2023-08-16 18:32:37 +03:00
|
|
|
|
convention: convention,
|
|
|
|
|
definition_formal: expression,
|
|
|
|
|
definition_raw: textDefinition,
|
|
|
|
|
term_raw: term
|
2023-09-11 17:56:32 +03:00
|
|
|
|
};
|
2023-08-16 18:32:37 +03:00
|
|
|
|
}
|
2023-07-22 12:24:14 +03:00
|
|
|
|
|
2023-08-27 16:35:17 +03:00
|
|
|
|
const handleSubmit = () => onCreate(getData());
|
2023-07-22 12:24:14 +03:00
|
|
|
|
|
2023-10-08 15:24:41 +03:00
|
|
|
|
useLayoutEffect(() => {
|
2023-08-16 18:32:37 +03:00
|
|
|
|
if (initial) {
|
|
|
|
|
setSelectedType(initial.cst_type);
|
|
|
|
|
setTerm(initial.term_raw);
|
|
|
|
|
setTextDefinition(initial.definition_raw);
|
|
|
|
|
setExpression(initial.definition_formal);
|
|
|
|
|
setConvention(initial.convention);
|
2023-10-08 15:24:41 +03:00
|
|
|
|
setAlias(initial.alias);
|
2023-08-16 18:32:37 +03:00
|
|
|
|
}
|
|
|
|
|
}, [initial]);
|
2023-07-23 21:38:04 +03:00
|
|
|
|
|
2023-10-08 15:24:41 +03:00
|
|
|
|
useLayoutEffect(
|
|
|
|
|
() => {
|
|
|
|
|
setAlias(createAliasFor(selectedType, schema));
|
|
|
|
|
}, [selectedType, schema]);
|
|
|
|
|
|
|
|
|
|
useEffect(
|
|
|
|
|
() => {
|
|
|
|
|
if(alias.length < 2 || alias[0] !== getCstTypePrefix(selectedType)) {
|
|
|
|
|
setValidated(false);
|
|
|
|
|
} else {
|
|
|
|
|
setValidated(!schema.items.find(cst => cst.alias === alias))
|
|
|
|
|
}
|
|
|
|
|
}, [alias, selectedType, schema]);
|
2023-07-23 15:23:01 +03:00
|
|
|
|
|
2023-07-22 12:24:14 +03:00
|
|
|
|
return (
|
2023-07-25 20:27:29 +03:00
|
|
|
|
<Modal
|
2023-07-22 12:24:14 +03:00
|
|
|
|
title='Создание конституенты'
|
2023-07-25 22:29:33 +03:00
|
|
|
|
hideWindow={hideWindow}
|
2023-07-22 12:24:14 +03:00
|
|
|
|
canSubmit={validated}
|
|
|
|
|
onSubmit={handleSubmit}
|
|
|
|
|
>
|
2023-09-15 23:29:52 +03:00
|
|
|
|
<div className='h-fit w-[35rem] px-2 mb-2 flex flex-col justify-stretch gap-3'>
|
2023-10-08 15:24:41 +03:00
|
|
|
|
<div className='flex justify-center w-full gap-6'>
|
2023-09-14 16:53:38 +03:00
|
|
|
|
<SelectSingle
|
2023-09-08 02:15:20 +03:00
|
|
|
|
className='my-2 min-w-[15rem] self-center'
|
2023-09-14 16:53:38 +03:00
|
|
|
|
options={SelectorCstType}
|
2023-09-08 02:15:20 +03:00
|
|
|
|
placeholder='Выберите тип'
|
2023-09-21 14:58:01 +03:00
|
|
|
|
value={selectedType ? { value: selectedType, label: labelCstType(selectedType) } : null}
|
2023-09-08 02:15:20 +03:00
|
|
|
|
onChange={data => setSelectedType(data?.value ?? CstType.BASE)}
|
|
|
|
|
/>
|
2023-10-08 15:24:41 +03:00
|
|
|
|
<TextInput id='alias' label='Имя'
|
|
|
|
|
singleRow
|
|
|
|
|
dimensions='w-[7rem]'
|
|
|
|
|
value={alias}
|
|
|
|
|
onChange={event => setAlias(event.target.value)}
|
|
|
|
|
/>
|
2023-08-16 18:32:37 +03:00
|
|
|
|
</div>
|
|
|
|
|
<TextArea id='term' label='Термин'
|
|
|
|
|
placeholder='Схемный или предметный термин, обозначающий данное понятие или утверждение'
|
|
|
|
|
rows={2}
|
|
|
|
|
value={term}
|
|
|
|
|
spellCheck
|
|
|
|
|
onChange={event => setTerm(event.target.value)}
|
|
|
|
|
/>
|
2023-09-15 23:29:52 +03:00
|
|
|
|
<RSInput id='expression' label='Формальное выражение'
|
2023-10-04 18:46:52 +03:00
|
|
|
|
placeholder='Родоструктурное выражение, задающее формальное определение'
|
2023-09-15 23:29:52 +03:00
|
|
|
|
editable
|
|
|
|
|
height='5.5rem'
|
|
|
|
|
value={expression}
|
|
|
|
|
onChange={value => setExpression(value)}
|
|
|
|
|
/>
|
2023-08-16 18:32:37 +03:00
|
|
|
|
<TextArea id='definition' label='Текстовое определение'
|
|
|
|
|
placeholder='Лингвистическая интерпретация формального выражения'
|
|
|
|
|
rows={2}
|
|
|
|
|
value={textDefinition}
|
|
|
|
|
spellCheck
|
2023-08-27 16:35:17 +03:00
|
|
|
|
onChange={event => setTextDefinition(event.target.value)}
|
2023-08-16 18:32:37 +03:00
|
|
|
|
/>
|
|
|
|
|
<TextArea id='convention' label='Конвенция / Комментарий'
|
|
|
|
|
placeholder='Договоренность об интерпретации неопределяемого понятия
Комментарий к производному понятию'
|
|
|
|
|
rows={2}
|
|
|
|
|
value={convention}
|
|
|
|
|
spellCheck
|
2023-08-27 16:35:17 +03:00
|
|
|
|
onChange={event => setConvention(event.target.value)}
|
2023-07-23 15:23:01 +03:00
|
|
|
|
/>
|
2023-09-08 02:15:20 +03:00
|
|
|
|
</div>
|
2023-07-22 12:24:14 +03:00
|
|
|
|
</Modal>
|
2023-07-29 03:31:21 +03:00
|
|
|
|
);
|
2023-07-22 12:24:14 +03:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-28 00:03:37 +03:00
|
|
|
|
export default DlgCreateCst;
|