2024-07-26 00:34:08 +03:00
|
|
|
'use client';
|
|
|
|
|
2024-07-26 17:31:57 +03:00
|
|
|
import { useCallback, useEffect } from 'react';
|
2024-07-26 00:34:08 +03:00
|
|
|
|
2024-07-24 22:23:35 +03:00
|
|
|
import { IconReset } from '@/components/Icons';
|
2024-07-21 15:19:57 +03:00
|
|
|
import PickSchema from '@/components/select/PickSchema';
|
2024-07-24 22:23:35 +03:00
|
|
|
import Checkbox from '@/components/ui/Checkbox';
|
2024-07-21 15:19:57 +03:00
|
|
|
import Label from '@/components/ui/Label';
|
2024-07-24 22:23:35 +03:00
|
|
|
import MiniButton from '@/components/ui/MiniButton';
|
2024-07-21 15:19:57 +03:00
|
|
|
import TextArea from '@/components/ui/TextArea';
|
|
|
|
import TextInput from '@/components/ui/TextInput';
|
|
|
|
import AnimateFade from '@/components/wrap/AnimateFade';
|
2024-07-26 00:34:08 +03:00
|
|
|
import { ILibraryItem, LibraryItemID } from '@/models/library';
|
|
|
|
import { IOperationSchema } from '@/models/oss';
|
2024-07-21 15:19:57 +03:00
|
|
|
import { limits, patterns } from '@/utils/constants';
|
|
|
|
|
|
|
|
interface TabInputOperationProps {
|
2024-07-26 00:34:08 +03:00
|
|
|
oss: IOperationSchema;
|
2024-07-21 15:19:57 +03:00
|
|
|
alias: string;
|
|
|
|
setAlias: React.Dispatch<React.SetStateAction<string>>;
|
|
|
|
title: string;
|
|
|
|
setTitle: React.Dispatch<React.SetStateAction<string>>;
|
|
|
|
comment: string;
|
|
|
|
setComment: React.Dispatch<React.SetStateAction<string>>;
|
|
|
|
attachedID: LibraryItemID | undefined;
|
|
|
|
setAttachedID: React.Dispatch<React.SetStateAction<LibraryItemID | undefined>>;
|
2024-07-26 17:31:57 +03:00
|
|
|
createSchema: boolean;
|
|
|
|
setCreateSchema: React.Dispatch<React.SetStateAction<boolean>>;
|
2024-07-21 15:19:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function TabInputOperation({
|
2024-07-26 00:34:08 +03:00
|
|
|
oss,
|
2024-07-21 15:19:57 +03:00
|
|
|
alias,
|
|
|
|
setAlias,
|
|
|
|
title,
|
|
|
|
setTitle,
|
|
|
|
comment,
|
|
|
|
setComment,
|
|
|
|
attachedID,
|
2024-07-24 22:23:35 +03:00
|
|
|
setAttachedID,
|
2024-07-26 17:31:57 +03:00
|
|
|
createSchema,
|
|
|
|
setCreateSchema
|
2024-07-21 15:19:57 +03:00
|
|
|
}: TabInputOperationProps) {
|
2024-07-26 00:34:08 +03:00
|
|
|
const baseFilter = useCallback((item: ILibraryItem) => !oss.schemas.includes(item.id), [oss]);
|
|
|
|
|
2024-07-26 17:31:57 +03:00
|
|
|
useEffect(() => {
|
|
|
|
if (createSchema) {
|
|
|
|
setAttachedID(undefined);
|
|
|
|
}
|
2024-07-30 16:00:09 +03:00
|
|
|
}, [createSchema, setAttachedID]);
|
2024-07-26 17:31:57 +03:00
|
|
|
|
2024-07-21 15:19:57 +03:00
|
|
|
return (
|
|
|
|
<AnimateFade className='cc-column'>
|
|
|
|
<TextInput
|
|
|
|
id='operation_title'
|
|
|
|
label='Полное название'
|
|
|
|
value={title}
|
|
|
|
onChange={event => setTitle(event.target.value)}
|
2024-07-30 16:00:09 +03:00
|
|
|
disabled={attachedID !== undefined}
|
2024-07-21 15:19:57 +03:00
|
|
|
/>
|
|
|
|
<div className='flex gap-6'>
|
2024-07-30 16:00:09 +03:00
|
|
|
<TextInput
|
|
|
|
id='operation_alias'
|
|
|
|
label='Сокращение'
|
|
|
|
className='w-[14rem]'
|
|
|
|
pattern={patterns.library_alias}
|
|
|
|
title={`не более ${limits.library_alias_len} символов`}
|
|
|
|
value={alias}
|
|
|
|
onChange={event => setAlias(event.target.value)}
|
|
|
|
disabled={attachedID !== undefined}
|
|
|
|
/>
|
2024-07-21 15:19:57 +03:00
|
|
|
|
|
|
|
<TextArea
|
|
|
|
id='operation_comment'
|
|
|
|
label='Описание'
|
|
|
|
noResize
|
|
|
|
rows={3}
|
|
|
|
value={comment}
|
|
|
|
onChange={event => setComment(event.target.value)}
|
2024-07-30 16:00:09 +03:00
|
|
|
disabled={attachedID !== undefined}
|
2024-07-24 22:23:35 +03:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
2024-07-26 17:31:57 +03:00
|
|
|
<div className='flex justify-between gap-3 items-center'>
|
|
|
|
<div className='flex gap-3'>
|
|
|
|
<Label text='Загружаемая концептуальная схема' />
|
|
|
|
<MiniButton
|
|
|
|
title='Сбросить выбор схемы'
|
|
|
|
noHover
|
|
|
|
noPadding
|
|
|
|
icon={<IconReset size='1.25rem' className='icon-primary' />}
|
|
|
|
onClick={() => setAttachedID(undefined)}
|
|
|
|
disabled={attachedID == undefined}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<Checkbox
|
|
|
|
value={createSchema}
|
|
|
|
setValue={setCreateSchema}
|
|
|
|
label='Создать новую схему'
|
|
|
|
titleHtml='Создать пустую схему для загрузки'
|
2024-07-21 15:19:57 +03:00
|
|
|
/>
|
|
|
|
</div>
|
2024-07-26 17:31:57 +03:00
|
|
|
{!createSchema ? (
|
|
|
|
<PickSchema
|
|
|
|
value={attachedID} // prettier: split-line
|
|
|
|
onSelectValue={setAttachedID}
|
|
|
|
rows={8}
|
|
|
|
baseFilter={baseFilter}
|
|
|
|
/>
|
|
|
|
) : null}
|
2024-07-21 15:19:57 +03:00
|
|
|
</AnimateFade>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default TabInputOperation;
|