2024-07-29 16:56:24 +03:00
|
|
|
'use client';
|
2025-02-12 00:14:38 +03:00
|
|
|
import { Controller, useFormContext } from 'react-hook-form';
|
|
|
|
|
2025-02-10 01:32:55 +03:00
|
|
|
import { FlexColumn } from '@/components/Container';
|
|
|
|
import { Label } from '@/components/Input';
|
2025-02-12 00:14:38 +03:00
|
|
|
import { useDialogsStore } from '@/stores/dialogs';
|
2024-07-29 16:56:24 +03:00
|
|
|
|
2025-02-12 00:14:38 +03:00
|
|
|
import { IOperationUpdateDTO } from '../../backend/api';
|
|
|
|
import { PickMultiOperation } from '../../components/PickMultiOperation';
|
|
|
|
import { DlgEditOperationProps } from './DlgEditOperation';
|
2024-07-29 16:56:24 +03:00
|
|
|
|
2025-02-12 00:14:38 +03:00
|
|
|
function TabArguments() {
|
|
|
|
const { control, setValue } = useFormContext<IOperationUpdateDTO>();
|
|
|
|
const { oss, target } = useDialogsStore(state => state.props as DlgEditOperationProps);
|
|
|
|
const potentialCycle = [target.id, ...oss.graph.expandAllOutputs([target.id])];
|
2024-12-13 21:31:09 +03:00
|
|
|
const filtered = oss.items.filter(item => !potentialCycle.includes(item.id));
|
2025-02-12 00:14:38 +03:00
|
|
|
|
2025-02-12 15:13:37 +03:00
|
|
|
function handleChangeArguments(prev: number[], newValue: number[]) {
|
2025-02-12 00:14:38 +03:00
|
|
|
setValue('arguments', newValue);
|
|
|
|
if (prev.some(id => !newValue.includes(id))) {
|
|
|
|
setValue('substitutions', []);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-29 16:56:24 +03:00
|
|
|
return (
|
2024-12-12 13:19:12 +03:00
|
|
|
<div className='cc-fade-in cc-column'>
|
2024-07-29 16:56:24 +03:00
|
|
|
<FlexColumn>
|
2025-02-12 00:14:38 +03:00
|
|
|
<Controller
|
|
|
|
name='arguments'
|
|
|
|
control={control}
|
|
|
|
render={({ field }) => (
|
|
|
|
<>
|
|
|
|
<Label text={`Выбор аргументов: [ ${field.value.length} ]`} />
|
|
|
|
<PickMultiOperation
|
|
|
|
items={filtered}
|
|
|
|
value={field.value}
|
|
|
|
onChange={newValue => handleChangeArguments(field.value, newValue)}
|
|
|
|
rows={8}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
/>
|
2024-07-29 16:56:24 +03:00
|
|
|
</FlexColumn>
|
2024-12-12 13:19:12 +03:00
|
|
|
</div>
|
2024-07-29 16:56:24 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default TabArguments;
|