Portal/rsconcept/frontend/src/features/oss/dialogs/dlg-create-synthesis/tab-arguments.tsx

77 lines
2.5 KiB
TypeScript
Raw Normal View History

2025-02-11 12:34:28 +03:00
import { Controller, useFormContext, useWatch } from 'react-hook-form';
2025-03-12 12:04:23 +03:00
import { Label, TextArea, TextInput } from '@/components/input';
2025-02-12 00:14:18 +03:00
import { useDialogsStore } from '@/stores/dialogs';
import { type ICreateSynthesisDTO } from '../../backend/types';
2025-03-12 11:54:32 +03:00
import { PickMultiOperation } from '../../components/pick-multi-operation';
2025-04-22 13:58:25 +03:00
import { SelectParent } from '../../components/select-parent';
2025-02-12 21:36:03 +03:00
import { type DlgCreateSynthesisProps } from './dlg-create-synthesis';
2024-07-21 15:17:36 +03:00
export function TabArguments() {
const { manager } = useDialogsStore(state => state.props as DlgCreateSynthesisProps);
2025-02-11 12:34:28 +03:00
const {
register,
control,
formState: { errors }
} = useFormContext<ICreateSynthesisDTO>();
2025-02-11 12:34:28 +03:00
const inputs = useWatch({ control, name: 'arguments' });
2025-08-04 22:42:02 +03:00
const references = manager.oss.references.filter(item => inputs.includes(item.target)).map(item => item.reference);
const filtered = manager.oss.operations.filter(item => !references.includes(item.id));
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='Название'
2025-02-11 12:34:28 +03:00
{...register('item_data.title')}
error={errors.item_data?.title}
2024-07-21 15:17:36 +03:00
/>
<div className='flex gap-6'>
2025-04-21 20:35:40 +03:00
<div className='grid gap-1'>
<TextInput
id='operation_alias' //
label='Сокращение'
2025-04-22 13:58:25 +03:00
className='w-80'
2025-04-21 20:35:40 +03:00
{...register('item_data.alias')}
error={errors.item_data?.alias}
/>
<Controller
name='item_data.parent'
control={control}
render={({ field }) => (
2025-04-22 13:58:25 +03:00
<SelectParent
2025-04-28 13:57:39 +03:00
items={manager.oss.blocks}
value={field.value ? manager.oss.blockByID.get(field.value) ?? null : null}
2025-07-03 14:35:26 +03:00
placeholder='Родительский блок'
2025-04-21 20:35:40 +03:00
onChange={value => field.onChange(value ? value.id : null)}
/>
)}
/>
</div>
2024-07-21 15:17:36 +03:00
<TextArea
id='operation_comment'
label='Описание'
noResize
rows={3}
{...register('item_data.description')}
error={errors.item_data?.description}
2024-07-21 15:17:36 +03:00
/>
</div>
2025-03-07 22:04:56 +03:00
<div className='cc-column'>
2024-07-26 21:08:31 +03:00
<Label text={`Выбор аргументов: [ ${inputs.length} ]`} />
2025-02-11 12:34:28 +03:00
<Controller
name='arguments'
control={control}
render={({ field }) => (
2025-08-04 22:42:02 +03:00
<PickMultiOperation items={filtered} value={field.value} onChange={field.onChange} rows={6} />
2025-02-11 12:34:28 +03:00
)}
/>
2025-03-07 22:04:56 +03:00
</div>
2024-12-12 13:17:24 +03:00
</div>
2024-07-21 15:17:36 +03:00
);
}