Portal/rsconcept/frontend/src/features/oss/dialogs/dlg-create-block/tab-block-children.tsx

48 lines
1.6 KiB
TypeScript
Raw Normal View History

2025-04-21 20:35:40 +03:00
'use client';
import { useFormContext, useWatch } from 'react-hook-form';
import { Label } from '@/components/input';
import { useDialogsStore } from '@/stores/dialogs';
import { type ICreateBlockDTO } from '../../backend/types';
import { PickContents } from '../../components/pick-contents';
import { type DlgCreateBlockProps } from './dlg-create-block';
export function TabBlockChildren() {
const { setValue, control } = useFormContext<ICreateBlockDTO>();
2025-04-28 13:57:39 +03:00
const { manager } = useDialogsStore(state => state.props as DlgCreateBlockProps);
2025-04-29 21:30:54 +03:00
const parent = useWatch({ control, name: 'item_data.parent' });
2025-04-21 20:35:40 +03:00
const children_blocks = useWatch({ control, name: 'children_blocks' });
const children_operations = useWatch({ control, name: 'children_operations' });
2025-04-29 21:30:54 +03:00
const exclude = parent ? [-parent, ...manager.oss.hierarchy.expandAllInputs([-parent]).filter(id => id < 0)] : [];
2025-04-21 20:35:40 +03:00
const value = [...children_blocks.map(id => -id), ...children_operations];
function handleChangeSelected(newValue: number[]) {
setValue(
'children_blocks',
newValue.filter(id => id < 0).map(id => -id),
{ shouldValidate: true }
);
setValue(
'children_operations',
newValue.filter(id => id > 0),
{ shouldValidate: true }
);
}
return (
<div className='cc-fade-in cc-column'>
<Label text={`Выбор содержания: [ ${value.length} ]`} />
2025-04-28 13:57:39 +03:00
<PickContents
schema={manager.oss}
2025-04-29 21:30:54 +03:00
exclude={exclude}
2025-04-28 13:57:39 +03:00
value={value}
onChange={newValue => handleChangeSelected(newValue)}
rows={10}
/>
2025-04-21 20:35:40 +03:00
</div>
);
}