ConceptPortal-public/rsconcept/frontend/src/features/oss/dialogs/DlgEditOperation/TabArguments.tsx

51 lines
1.7 KiB
TypeScript
Raw Normal View History

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';
import { FlexColumn } from '@/components/Container';
import { Label } from '@/components/Input';
2025-02-12 00:14:38 +03:00
import { LibraryItemID } from '@/features/library/models/library';
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])];
const filtered = oss.items.filter(item => !potentialCycle.includes(item.id));
2025-02-12 00:14:38 +03:00
function handleChangeArguments(prev: LibraryItemID[], newValue: LibraryItemID[]) {
setValue('arguments', newValue);
if (prev.some(id => !newValue.includes(id))) {
setValue('substitutions', []);
}
}
2024-07-29 16:56:24 +03:00
return (
<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}
defaultValue={[]}
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>
</div>
2024-07-29 16:56:24 +03:00
);
}
export default TabArguments;