2024-07-26 00:33:22 +03:00
|
|
|
'use client';
|
|
|
|
|
2024-12-13 21:30:49 +03:00
|
|
|
import { useEffect } from 'react';
|
2024-07-26 00:33:22 +03:00
|
|
|
|
2024-07-24 22:23:05 +03:00
|
|
|
import { IconReset } from '@/components/Icons';
|
2024-07-21 15:17:36 +03:00
|
|
|
import PickSchema from '@/components/select/PickSchema';
|
2024-07-24 22:23:05 +03:00
|
|
|
import Checkbox from '@/components/ui/Checkbox';
|
2024-07-21 15:17:36 +03:00
|
|
|
import Label from '@/components/ui/Label';
|
2024-07-24 22:23:05 +03:00
|
|
|
import MiniButton from '@/components/ui/MiniButton';
|
2024-07-21 15:17:36 +03:00
|
|
|
import TextArea from '@/components/ui/TextArea';
|
|
|
|
import TextInput from '@/components/ui/TextInput';
|
2024-08-17 22:30:49 +03:00
|
|
|
import { useLibrary } from '@/context/LibraryContext';
|
|
|
|
import { ILibraryItem, LibraryItemID, LibraryItemType } from '@/models/library';
|
2024-07-26 00:33:22 +03:00
|
|
|
import { IOperationSchema } from '@/models/oss';
|
2024-08-17 22:30:49 +03:00
|
|
|
import { sortItemsForOSS } from '@/models/ossAPI';
|
2024-07-21 15:17:36 +03:00
|
|
|
|
|
|
|
interface TabInputOperationProps {
|
2024-07-26 00:33:22 +03:00
|
|
|
oss: IOperationSchema;
|
2024-07-21 15:17:36 +03:00
|
|
|
alias: string;
|
2024-11-21 00:26:04 +03:00
|
|
|
onChangeAlias: (newValue: string) => void;
|
2024-07-21 15:17:36 +03:00
|
|
|
title: string;
|
2024-11-21 00:26:04 +03:00
|
|
|
onChangeTitle: (newValue: string) => void;
|
2024-07-21 15:17:36 +03:00
|
|
|
comment: string;
|
2024-11-21 00:26:04 +03:00
|
|
|
onChangeComment: (newValue: string) => void;
|
2024-07-21 15:17:36 +03:00
|
|
|
attachedID: LibraryItemID | undefined;
|
2024-11-21 00:26:04 +03:00
|
|
|
onChangeAttachedID: (newValue: LibraryItemID | undefined) => void;
|
2024-07-26 17:30:37 +03:00
|
|
|
createSchema: boolean;
|
2024-11-21 00:26:04 +03:00
|
|
|
onChangeCreateSchema: (newValue: boolean) => void;
|
2024-07-21 15:17:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function TabInputOperation({
|
2024-07-26 00:33:22 +03:00
|
|
|
oss,
|
2024-07-21 15:17:36 +03:00
|
|
|
alias,
|
2024-11-21 00:26:04 +03:00
|
|
|
onChangeAlias,
|
2024-07-21 15:17:36 +03:00
|
|
|
title,
|
2024-11-21 00:26:04 +03:00
|
|
|
onChangeTitle,
|
2024-07-21 15:17:36 +03:00
|
|
|
comment,
|
2024-11-21 00:26:04 +03:00
|
|
|
onChangeComment,
|
2024-07-21 15:17:36 +03:00
|
|
|
attachedID,
|
2024-11-21 00:26:04 +03:00
|
|
|
onChangeAttachedID,
|
2024-07-26 17:30:37 +03:00
|
|
|
createSchema,
|
2024-11-21 00:26:04 +03:00
|
|
|
onChangeCreateSchema
|
2024-07-21 15:17:36 +03:00
|
|
|
}: TabInputOperationProps) {
|
2024-08-17 22:30:49 +03:00
|
|
|
const library = useLibrary();
|
2024-12-13 21:30:49 +03:00
|
|
|
const sortedItems = sortItemsForOSS(oss, library.items);
|
|
|
|
|
|
|
|
function baseFilter(item: ILibraryItem) {
|
|
|
|
return !oss.schemas.includes(item.id);
|
|
|
|
}
|
2024-07-26 00:33:22 +03:00
|
|
|
|
2024-07-26 17:30:37 +03:00
|
|
|
useEffect(() => {
|
|
|
|
if (createSchema) {
|
2024-11-21 00:26:04 +03:00
|
|
|
onChangeAttachedID(undefined);
|
2024-07-26 17:30:37 +03:00
|
|
|
}
|
2024-11-21 00:26:04 +03:00
|
|
|
}, [createSchema, onChangeAttachedID]);
|
2024-07-26 17:30:37 +03:00
|
|
|
|
2024-07-21 15:17:36 +03:00
|
|
|
return (
|
2024-12-12 13:17:24 +03:00
|
|
|
<div className='cc-fade-in cc-column'>
|
2024-07-21 15:17:36 +03:00
|
|
|
<TextInput
|
|
|
|
id='operation_title'
|
|
|
|
label='Полное название'
|
|
|
|
value={title}
|
2024-11-21 00:26:04 +03:00
|
|
|
onChange={event => onChangeTitle(event.target.value)}
|
2024-07-30 15:59:37 +03:00
|
|
|
disabled={attachedID !== undefined}
|
2024-07-21 15:17:36 +03:00
|
|
|
/>
|
|
|
|
<div className='flex gap-6'>
|
2024-07-30 15:59:37 +03:00
|
|
|
<TextInput
|
|
|
|
id='operation_alias'
|
|
|
|
label='Сокращение'
|
2024-08-22 23:23:26 +03:00
|
|
|
className='w-[16rem]'
|
2024-07-30 15:59:37 +03:00
|
|
|
value={alias}
|
2024-11-21 00:26:04 +03:00
|
|
|
onChange={event => onChangeAlias(event.target.value)}
|
2024-07-30 15:59:37 +03:00
|
|
|
disabled={attachedID !== undefined}
|
|
|
|
/>
|
2024-07-21 15:17:36 +03:00
|
|
|
|
|
|
|
<TextArea
|
|
|
|
id='operation_comment'
|
|
|
|
label='Описание'
|
|
|
|
noResize
|
|
|
|
rows={3}
|
|
|
|
value={comment}
|
2024-11-21 00:26:04 +03:00
|
|
|
onChange={event => onChangeComment(event.target.value)}
|
2024-07-30 15:59:37 +03:00
|
|
|
disabled={attachedID !== undefined}
|
2024-07-24 22:23:05 +03:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
2024-07-26 17:30:37 +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' />}
|
2024-11-21 00:26:04 +03:00
|
|
|
onClick={() => onChangeAttachedID(undefined)}
|
2024-07-26 17:30:37 +03:00
|
|
|
disabled={attachedID == undefined}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<Checkbox
|
|
|
|
value={createSchema}
|
2024-11-21 00:26:04 +03:00
|
|
|
setValue={onChangeCreateSchema}
|
2024-07-26 17:30:37 +03:00
|
|
|
label='Создать новую схему'
|
|
|
|
titleHtml='Создать пустую схему для загрузки'
|
2024-07-21 15:17:36 +03:00
|
|
|
/>
|
|
|
|
</div>
|
2024-07-26 17:30:37 +03:00
|
|
|
{!createSchema ? (
|
|
|
|
<PickSchema
|
2024-08-17 22:30:49 +03:00
|
|
|
items={sortedItems}
|
|
|
|
value={attachedID}
|
|
|
|
itemType={LibraryItemType.RSFORM}
|
2024-11-21 00:26:04 +03:00
|
|
|
onSelectValue={onChangeAttachedID}
|
2024-07-26 17:30:37 +03:00
|
|
|
rows={8}
|
|
|
|
baseFilter={baseFilter}
|
|
|
|
/>
|
|
|
|
) : null}
|
2024-12-12 13:17:24 +03:00
|
|
|
</div>
|
2024-07-21 15:17:36 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default TabInputOperation;
|