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

119 lines
3.6 KiB
TypeScript
Raw Normal View History

2024-07-26 00:33:22 +03:00
'use client';
import { useCallback, useEffect, useMemo } 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';
import AnimateFade from '@/components/wrap/AnimateFade';
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';
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;
setAlias: React.Dispatch<React.SetStateAction<string>>;
title: string;
setTitle: React.Dispatch<React.SetStateAction<string>>;
comment: string;
setComment: React.Dispatch<React.SetStateAction<string>>;
attachedID: LibraryItemID | undefined;
setAttachedID: React.Dispatch<React.SetStateAction<LibraryItemID | undefined>>;
2024-07-26 17:30:37 +03:00
createSchema: boolean;
setCreateSchema: React.Dispatch<React.SetStateAction<boolean>>;
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,
setAlias,
title,
setTitle,
comment,
setComment,
attachedID,
2024-07-24 22:23:05 +03:00
setAttachedID,
2024-07-26 17:30:37 +03:00
createSchema,
setCreateSchema
2024-07-21 15:17:36 +03:00
}: TabInputOperationProps) {
2024-07-26 00:33:22 +03:00
const baseFilter = useCallback((item: ILibraryItem) => !oss.schemas.includes(item.id), [oss]);
const library = useLibrary();
const sortedItems = useMemo(() => sortItemsForOSS(oss, library.items), [oss, library.items]);
2024-07-26 00:33:22 +03:00
2024-07-26 17:30:37 +03:00
useEffect(() => {
if (createSchema) {
setAttachedID(undefined);
}
}, [createSchema, setAttachedID]);
2024-07-26 17:30:37 +03:00
2024-07-21 15:17:36 +03:00
return (
<AnimateFade className='cc-column'>
<TextInput
id='operation_title'
label='Полное название'
value={title}
onChange={event => setTitle(event.target.value)}
disabled={attachedID !== undefined}
2024-07-21 15:17:36 +03:00
/>
<div className='flex gap-6'>
<TextInput
id='operation_alias'
label='Сокращение'
className='w-[14rem]'
value={alias}
onChange={event => setAlias(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 => setComment(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={() => setAttachedID(undefined)}
disabled={attachedID == undefined}
/>
</div>
<Checkbox
value={createSchema}
setValue={setCreateSchema}
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}
2024-07-26 17:30:37 +03:00
onSelectValue={setAttachedID}
rows={8}
baseFilter={baseFilter}
/>
) : null}
2024-07-21 15:17:36 +03:00
</AnimateFade>
);
}
export default TabInputOperation;