2024-07-28 21:29:46 +03:00
|
|
|
'use client';
|
|
|
|
|
|
|
|
import clsx from 'clsx';
|
2024-12-13 21:30:49 +03:00
|
|
|
import { useState } from 'react';
|
2024-07-28 21:29:46 +03:00
|
|
|
|
2025-01-23 19:41:31 +03:00
|
|
|
import { useLibrary } from '@/backend/library/useLibrary';
|
2024-07-28 21:29:46 +03:00
|
|
|
import { IconReset } from '@/components/Icons';
|
|
|
|
import PickSchema from '@/components/select/PickSchema';
|
|
|
|
import Label from '@/components/ui/Label';
|
|
|
|
import MiniButton from '@/components/ui/MiniButton';
|
2025-01-16 16:31:03 +03:00
|
|
|
import Modal from '@/components/ui/Modal';
|
2024-08-17 22:30:49 +03:00
|
|
|
import { ILibraryItem, LibraryItemID, LibraryItemType } from '@/models/library';
|
2025-01-16 16:31:03 +03:00
|
|
|
import { IOperation, IOperationSchema, OperationID } from '@/models/oss';
|
2024-08-17 22:30:49 +03:00
|
|
|
import { sortItemsForOSS } from '@/models/ossAPI';
|
2025-01-16 16:31:03 +03:00
|
|
|
import { useDialogsStore } from '@/stores/dialogs';
|
2024-07-28 21:29:46 +03:00
|
|
|
|
2025-01-16 16:31:03 +03:00
|
|
|
export interface DlgChangeInputSchemaProps {
|
2024-07-28 21:29:46 +03:00
|
|
|
oss: IOperationSchema;
|
|
|
|
target: IOperation;
|
2025-01-16 16:31:03 +03:00
|
|
|
onSubmit: (target: OperationID, newSchema: LibraryItemID | undefined) => void;
|
2024-07-28 21:29:46 +03:00
|
|
|
}
|
|
|
|
|
2025-01-16 16:31:03 +03:00
|
|
|
function DlgChangeInputSchema() {
|
|
|
|
const { oss, target, onSubmit } = useDialogsStore(state => state.props as DlgChangeInputSchemaProps);
|
2024-07-28 21:29:46 +03:00
|
|
|
const [selected, setSelected] = useState<LibraryItemID | undefined>(target.result ?? undefined);
|
2025-01-23 19:41:31 +03:00
|
|
|
const { items } = useLibrary();
|
|
|
|
const sortedItems = sortItemsForOSS(oss, items);
|
2024-12-13 21:30:49 +03:00
|
|
|
const isValid = target.result !== selected;
|
2024-07-28 21:29:46 +03:00
|
|
|
|
2024-12-13 21:30:49 +03:00
|
|
|
function baseFilter(item: ILibraryItem) {
|
|
|
|
return !oss.schemas.includes(item.id) || item.id === selected || item.id === target.result;
|
|
|
|
}
|
2024-07-28 21:29:46 +03:00
|
|
|
|
2024-12-13 21:30:49 +03:00
|
|
|
function handleSelectLocation(newValue: LibraryItemID) {
|
2024-07-28 21:29:46 +03:00
|
|
|
setSelected(newValue);
|
2024-12-13 21:30:49 +03:00
|
|
|
}
|
2024-07-28 21:29:46 +03:00
|
|
|
|
2025-02-06 14:09:20 +03:00
|
|
|
function handleSubmit() {
|
|
|
|
onSubmit(target.id, selected);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-07-28 21:29:46 +03:00
|
|
|
return (
|
|
|
|
<Modal
|
|
|
|
overflowVisible
|
|
|
|
header='Выбор концептуальной схемы'
|
|
|
|
submitText='Подтвердить выбор'
|
|
|
|
canSubmit={isValid}
|
2025-02-06 14:09:20 +03:00
|
|
|
onSubmit={handleSubmit}
|
2024-07-28 21:29:46 +03:00
|
|
|
className={clsx('w-[35rem]', 'pb-3 px-6 cc-column')}
|
|
|
|
>
|
|
|
|
<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={() => setSelected(undefined)}
|
|
|
|
disabled={selected == undefined}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<PickSchema
|
2024-08-17 22:30:49 +03:00
|
|
|
items={sortedItems}
|
|
|
|
itemType={LibraryItemType.RSFORM}
|
2024-07-28 21:29:46 +03:00
|
|
|
value={selected} // prettier: split-line
|
2025-02-04 20:35:18 +03:00
|
|
|
onChange={handleSelectLocation}
|
2024-09-12 13:27:06 +03:00
|
|
|
rows={14}
|
2024-07-28 21:29:46 +03:00
|
|
|
baseFilter={baseFilter}
|
|
|
|
/>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default DlgChangeInputSchema;
|