2024-07-26 00:34:08 +03:00
|
|
|
'use client';
|
|
|
|
|
2024-08-17 22:31:24 +03:00
|
|
|
import { useCallback, useEffect, useMemo } 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-08-17 22:31:24 +03:00
|
|
|
import { useLibrary } from '@/context/LibraryContext';
|
|
|
|
import { ILibraryItem, LibraryItemID, LibraryItemType } from '@/models/library';
|
2024-07-26 00:34:08 +03:00
|
|
|
import { IOperationSchema } from '@/models/oss';
|
2024-08-17 22:31:24 +03:00
|
|
|
import { sortItemsForOSS } from '@/models/ossAPI';
|
2024-07-21 15:19:57 +03:00
|
|
|
|
|
|
|
interface TabInputOperationProps {
|
2024-07-26 00:34:08 +03:00
|
|
|
oss: IOperationSchema;
|
2024-07-21 15:19:57 +03:00
|
|
|
alias: string;
|
2024-11-21 00:26:16 +03:00
|
|
|
onChangeAlias: (newValue: string) => void;
|
2024-07-21 15:19:57 +03:00
|
|
|
title: string;
|
2024-11-21 00:26:16 +03:00
|
|
|
onChangeTitle: (newValue: string) => void;
|
2024-07-21 15:19:57 +03:00
|
|
|
comment: string;
|
2024-11-21 00:26:16 +03:00
|
|
|
onChangeComment: (newValue: string) => void;
|
2024-07-21 15:19:57 +03:00
|
|
|
attachedID: LibraryItemID | undefined;
|
2024-11-21 00:26:16 +03:00
|
|
|
onChangeAttachedID: (newValue: LibraryItemID | undefined) => void;
|
2024-07-26 17:31:57 +03:00
|
|
|
createSchema: boolean;
|
2024-11-21 00:26:16 +03:00
|
|
|
onChangeCreateSchema: (newValue: boolean) => void;
|
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,
|
2024-11-21 00:26:16 +03:00
|
|
|
onChangeAlias,
|
2024-07-21 15:19:57 +03:00
|
|
|
title,
|
2024-11-21 00:26:16 +03:00
|
|
|
onChangeTitle,
|
2024-07-21 15:19:57 +03:00
|
|
|
comment,
|
2024-11-21 00:26:16 +03:00
|
|
|
onChangeComment,
|
2024-07-21 15:19:57 +03:00
|
|
|
attachedID,
|
2024-11-21 00:26:16 +03:00
|
|
|
onChangeAttachedID,
|
2024-07-26 17:31:57 +03:00
|
|
|
createSchema,
|
2024-11-21 00:26:16 +03:00
|
|
|
onChangeCreateSchema
|
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-08-17 22:31:24 +03:00
|
|
|
const library = useLibrary();
|
|
|
|
const sortedItems = useMemo(() => sortItemsForOSS(oss, library.items), [oss, library.items]);
|
2024-07-26 00:34:08 +03:00
|
|
|
|
2024-07-26 17:31:57 +03:00
|
|
|
useEffect(() => {
|
|
|
|
if (createSchema) {
|
2024-11-21 00:26:16 +03:00
|
|
|
onChangeAttachedID(undefined);
|
2024-07-26 17:31:57 +03:00
|
|
|
}
|
2024-11-21 00:26:16 +03:00
|
|
|
}, [createSchema, onChangeAttachedID]);
|
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}
|
2024-11-21 00:26:16 +03:00
|
|
|
onChange={event => onChangeTitle(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='Сокращение'
|
2024-08-22 23:24:10 +03:00
|
|
|
className='w-[16rem]'
|
2024-07-30 16:00:09 +03:00
|
|
|
value={alias}
|
2024-11-21 00:26:16 +03:00
|
|
|
onChange={event => onChangeAlias(event.target.value)}
|
2024-07-30 16:00:09 +03:00
|
|
|
disabled={attachedID !== undefined}
|
|
|
|
/>
|
2024-07-21 15:19:57 +03:00
|
|
|
|
|
|
|
<TextArea
|
|
|
|
id='operation_comment'
|
|
|
|
label='Описание'
|
|
|
|
noResize
|
|
|
|
rows={3}
|
|
|
|
value={comment}
|
2024-11-21 00:26:16 +03:00
|
|
|
onChange={event => onChangeComment(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' />}
|
2024-11-21 00:26:16 +03:00
|
|
|
onClick={() => onChangeAttachedID(undefined)}
|
2024-07-26 17:31:57 +03:00
|
|
|
disabled={attachedID == undefined}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<Checkbox
|
|
|
|
value={createSchema}
|
2024-11-21 00:26:16 +03:00
|
|
|
setValue={onChangeCreateSchema}
|
2024-07-26 17:31:57 +03:00
|
|
|
label='Создать новую схему'
|
|
|
|
titleHtml='Создать пустую схему для загрузки'
|
2024-07-21 15:19:57 +03:00
|
|
|
/>
|
|
|
|
</div>
|
2024-07-26 17:31:57 +03:00
|
|
|
{!createSchema ? (
|
|
|
|
<PickSchema
|
2024-08-17 22:31:24 +03:00
|
|
|
items={sortedItems}
|
|
|
|
value={attachedID}
|
|
|
|
itemType={LibraryItemType.RSFORM}
|
2024-11-21 00:26:16 +03:00
|
|
|
onSelectValue={onChangeAttachedID}
|
2024-07-26 17:31:57 +03:00
|
|
|
rows={8}
|
|
|
|
baseFilter={baseFilter}
|
|
|
|
/>
|
|
|
|
) : null}
|
2024-07-21 15:19:57 +03:00
|
|
|
</AnimateFade>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default TabInputOperation;
|