2023-08-02 18:24:17 +03:00
|
|
|
|
import { useMemo, useState } from 'react';
|
|
|
|
|
|
2023-11-27 12:11:39 +03:00
|
|
|
|
import Checkbox from '../components/Common/Checkbox';
|
|
|
|
|
import Modal, { ModalProps } from '../components/Common/Modal';
|
2023-11-01 13:47:49 +03:00
|
|
|
|
import { useRSForm } from '../context/RSFormContext';
|
2023-11-23 19:34:37 +03:00
|
|
|
|
import { prefixes } from '../utils/constants';
|
2023-11-01 13:47:49 +03:00
|
|
|
|
import { labelConstituenta } from '../utils/labels';
|
2023-08-02 18:24:17 +03:00
|
|
|
|
|
2023-09-11 17:56:32 +03:00
|
|
|
|
interface DlgDeleteCstProps
|
|
|
|
|
extends Pick<ModalProps, 'hideWindow'> {
|
2023-08-22 22:38:27 +03:00
|
|
|
|
selected: number[]
|
|
|
|
|
onDelete: (items: number[]) => void
|
2023-08-02 18:24:17 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function DlgDeleteCst({ hideWindow, selected, onDelete }: DlgDeleteCstProps) {
|
|
|
|
|
const { schema } = useRSForm();
|
|
|
|
|
|
2023-12-05 01:22:44 +03:00
|
|
|
|
const [expandOut, setExpandOut] = useState(false);
|
2023-08-22 22:38:27 +03:00
|
|
|
|
const expansion: number[] = useMemo(() => schema?.graph.expandOutputs(selected) ?? [], [selected, schema?.graph]);
|
2023-08-02 18:24:17 +03:00
|
|
|
|
|
|
|
|
|
function handleSubmit() {
|
|
|
|
|
hideWindow();
|
|
|
|
|
if (expandOut) {
|
|
|
|
|
onDelete(selected.concat(expansion));
|
|
|
|
|
} else {
|
|
|
|
|
onDelete(selected);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
2023-12-05 01:22:44 +03:00
|
|
|
|
<Modal canSubmit
|
2023-12-04 14:19:54 +03:00
|
|
|
|
title='Удаление конституент'
|
|
|
|
|
submitText={expandOut ? 'Удалить с зависимыми' : 'Удалить'}
|
|
|
|
|
hideWindow={hideWindow}
|
|
|
|
|
onSubmit={handleSubmit}
|
|
|
|
|
>
|
|
|
|
|
<div className='max-w-[60vw] min-w-[30rem]'>
|
|
|
|
|
<p>Выбраны к удалению: <b>{selected.length}</b></p>
|
|
|
|
|
<div className='px-3 border h-[9rem] mt-1 overflow-y-auto whitespace-nowrap'>
|
|
|
|
|
{selected.map(
|
|
|
|
|
(id) => {
|
|
|
|
|
const cst = schema!.items.find(cst => cst.id === id);
|
|
|
|
|
return (cst ?
|
|
|
|
|
<p key={`${prefixes.cst_delete_list}${cst.id}`}>
|
|
|
|
|
{labelConstituenta(cst)}
|
|
|
|
|
</p> : null);
|
|
|
|
|
})}
|
2023-08-02 18:24:17 +03:00
|
|
|
|
</div>
|
2023-12-04 14:19:54 +03:00
|
|
|
|
<p className='mt-4'>Зависимые конституенты: <b>{expansion.length}</b></p>
|
|
|
|
|
<div className='mt-1 mb-3 px-3 border h-[9rem] overflow-y-auto whitespace-nowrap'>
|
|
|
|
|
{expansion.map(
|
|
|
|
|
(id) => {
|
|
|
|
|
const cst = schema!.items.find(cst => cst.id === id);
|
|
|
|
|
return (cst ?
|
|
|
|
|
<p key={`${prefixes.cst_dependant_list}${cst.id}`}>
|
|
|
|
|
{labelConstituenta(cst)}
|
|
|
|
|
</p> : null);
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
|
|
|
|
<Checkbox
|
|
|
|
|
label='Удалить зависимые конституенты'
|
|
|
|
|
value={expandOut}
|
|
|
|
|
setValue={value => setExpandOut(value)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</Modal>);
|
2023-08-02 18:24:17 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default DlgDeleteCst;
|