ConceptPortal-public/rsconcept/frontend/src/dialogs/DlgCreateOperation/TabInputOperation.tsx

121 lines
3.5 KiB
TypeScript
Raw Normal View History

2024-07-26 00:34:08 +03:00
'use client';
import { 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 { useLibrary } from '@/context/LibraryContext';
import { ILibraryItem, LibraryItemID, LibraryItemType } from '@/models/library';
2024-07-26 00:34:08 +03:00
import { IOperationSchema } from '@/models/oss';
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;
onChangeAlias: (newValue: string) => void;
2024-07-21 15:19:57 +03:00
title: string;
onChangeTitle: (newValue: string) => void;
2024-07-21 15:19:57 +03:00
comment: string;
onChangeComment: (newValue: string) => void;
2024-07-21 15:19:57 +03:00
attachedID: LibraryItemID | undefined;
onChangeAttachedID: (newValue: LibraryItemID | undefined) => void;
2024-07-26 17:31:57 +03:00
createSchema: boolean;
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,
onChangeAlias,
2024-07-21 15:19:57 +03:00
title,
onChangeTitle,
2024-07-21 15:19:57 +03:00
comment,
onChangeComment,
2024-07-21 15:19:57 +03:00
attachedID,
onChangeAttachedID,
2024-07-26 17:31:57 +03:00
createSchema,
onChangeCreateSchema
2024-07-21 15:19:57 +03:00
}: TabInputOperationProps) {
const library = useLibrary();
const sortedItems = sortItemsForOSS(oss, library.items);
function baseFilter(item: ILibraryItem) {
return !oss.schemas.includes(item.id);
}
2024-07-26 00:34:08 +03:00
2024-07-26 17:31:57 +03:00
useEffect(() => {
if (createSchema) {
onChangeAttachedID(undefined);
2024-07-26 17:31:57 +03:00
}
}, [createSchema, onChangeAttachedID]);
2024-07-26 17:31:57 +03:00
2024-07-21 15:19:57 +03:00
return (
<div className='cc-fade-in cc-column'>
2024-07-21 15:19:57 +03:00
<TextInput
id='operation_title'
label='Полное название'
value={title}
onChange={event => onChangeTitle(event.target.value)}
disabled={attachedID !== undefined}
2024-07-21 15:19:57 +03:00
/>
<div className='flex gap-6'>
<TextInput
id='operation_alias'
label='Сокращение'
2024-08-22 23:24:10 +03:00
className='w-[16rem]'
value={alias}
onChange={event => onChangeAlias(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 => onChangeComment(event.target.value)}
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={() => onChangeAttachedID(undefined)}
2024-07-26 17:31:57 +03:00
disabled={attachedID == undefined}
/>
</div>
<Checkbox
value={createSchema}
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
items={sortedItems}
value={attachedID}
itemType={LibraryItemType.RSFORM}
onSelectValue={onChangeAttachedID}
2024-07-26 17:31:57 +03:00
rows={8}
baseFilter={baseFilter}
/>
) : null}
</div>
2024-07-21 15:19:57 +03:00
);
}
export default TabInputOperation;