Portal/rsconcept/frontend/src/features/oss/dialogs/DlgCreateOperation/TabInputOperation.tsx

118 lines
3.5 KiB
TypeScript
Raw Normal View History

2024-07-26 00:33:22 +03:00
'use client';
import { useEffect } from 'react';
2024-07-26 00:33:22 +03:00
import { MiniButton } from '@/components/Control';
2024-07-24 22:23:05 +03:00
import { IconReset } from '@/components/Icons';
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;
onChangeAlias: (newValue: string) => void;
2024-07-21 15:17:36 +03:00
title: string;
onChangeTitle: (newValue: string) => void;
2024-07-21 15:17:36 +03:00
comment: string;
onChangeComment: (newValue: string) => void;
2024-07-21 15:17:36 +03:00
attachedID: LibraryItemID | undefined;
onChangeAttachedID: (newValue: LibraryItemID | undefined) => void;
2024-07-26 17:30:37 +03:00
createSchema: boolean;
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,
onChangeAlias,
2024-07-21 15:17:36 +03:00
title,
onChangeTitle,
2024-07-21 15:17:36 +03:00
comment,
onChangeComment,
2024-07-21 15:17:36 +03:00
attachedID,
onChangeAttachedID,
2024-07-26 17:30:37 +03:00
createSchema,
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);
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) {
onChangeAttachedID(undefined);
2024-07-26 17:30:37 +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}
onChange={event => onChangeTitle(event.target.value)}
disabled={attachedID !== undefined}
2024-07-21 15:17:36 +03:00
/>
<div className='flex gap-6'>
<TextInput
id='operation_alias'
label='Сокращение'
2024-08-22 23:23:26 +03:00
className='w-[16rem]'
value={alias}
onChange={event => onChangeAlias(event.target.value)}
disabled={attachedID !== undefined}
/>
2024-07-21 15:17:36 +03:00
<TextArea
id='operation_comment'
label='Описание'
noResize
rows={3}
value={comment}
onChange={event => onChangeComment(event.target.value)}
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' />}
onClick={() => onChangeAttachedID(undefined)}
2024-07-26 17:30:37 +03:00
disabled={attachedID == undefined}
/>
</div>
<Checkbox
value={createSchema}
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
items={sortedItems}
value={attachedID}
itemType={LibraryItemType.RSFORM}
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;