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
|
|
|
|
2025-02-10 01:32:16 +03:00
|
|
|
import { MiniButton } from '@/components/Control';
|
2024-07-24 22:23:05 +03:00
|
|
|
import { IconReset } from '@/components/Icons';
|
2025-02-10 01:32:16 +03:00
|
|
|
import { Checkbox, Label, TextArea, TextInput } from '@/components/Input';
|
|
|
|
import { useLibrary } from '@/features/library/backend/useLibrary';
|
|
|
|
import { ILibraryItem, LibraryItemID, LibraryItemType } from '@/features/library/models/library';
|
|
|
|
import { IOperationSchema } from '@/features/oss/models/oss';
|
|
|
|
import { sortItemsForOSS } from '@/features/oss/models/ossAPI';
|
|
|
|
import PickSchema from '@/features/rsform/components/PickSchema';
|
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) {
|
2025-01-23 19:41:31 +03:00
|
|
|
const { items: libraryItems } = useLibrary();
|
|
|
|
const sortedItems = sortItemsForOSS(oss, libraryItems);
|
2024-12-13 21:30:49 +03:00
|
|
|
|
|
|
|
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}
|
2025-02-04 20:35:18 +03:00
|
|
|
onChange={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}
|
2025-02-04 20:35:18 +03:00
|
|
|
onChange={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;
|