Portal/rsconcept/frontend/src/components/select/ToolbarGraphSelection.tsx

106 lines
3.5 KiB
TypeScript
Raw Normal View History

2024-06-07 20:17:03 +03:00
import clsx from 'clsx';
import {
IconGraphCollapse,
IconGraphCore,
IconGraphExpand,
IconGraphInputs,
2024-08-21 20:20:48 +03:00
IconGraphInverse,
2024-06-07 20:17:03 +03:00
IconGraphMaximize,
IconGraphOutputs,
2024-08-21 20:20:48 +03:00
IconPredecessor,
2024-06-07 20:17:03 +03:00
IconReset
2025-01-28 23:23:03 +03:00
} from '@/components/Icons';
import { CProps } from '@/components/props';
import MiniButton from '@/components/ui/MiniButton';
import { Graph } from '@/models/Graph';
2024-06-07 20:17:03 +03:00
interface ToolbarGraphSelectionProps extends CProps.Styling {
value: number[];
onChange: (newSelection: number[]) => void;
2024-06-07 20:17:03 +03:00
graph: Graph;
2024-08-21 20:20:48 +03:00
isCore: (item: number) => boolean;
2024-12-02 15:58:18 +03:00
isOwned?: (item: number) => boolean;
2024-06-07 20:17:03 +03:00
emptySelection?: boolean;
}
function ToolbarGraphSelection({
2024-06-07 20:17:03 +03:00
className,
graph,
value: selected,
2024-08-21 20:20:48 +03:00
isCore,
isOwned,
onChange,
2024-06-07 20:17:03 +03:00
emptySelection,
...restProps
}: ToolbarGraphSelectionProps) {
2025-02-05 01:27:32 +03:00
function handleSelectCore() {
2024-08-21 20:20:48 +03:00
const core = [...graph.nodes.keys()].filter(isCore);
onChange([...core, ...graph.expandInputs(core)]);
2025-02-05 01:27:32 +03:00
}
2024-08-21 20:20:48 +03:00
2025-02-05 01:27:32 +03:00
function handleSelectOwned() {
if (isOwned) onChange([...graph.nodes.keys()].filter(isOwned));
}
2024-08-21 20:20:48 +03:00
2024-06-07 20:17:03 +03:00
return (
<div className={clsx('cc-icons', className)} {...restProps}>
<MiniButton
titleHtml='Сбросить выделение'
icon={<IconReset size='1.25rem' className='icon-primary' />}
onClick={() => onChange([])}
2024-06-07 20:17:03 +03:00
disabled={emptySelection}
/>
<MiniButton
titleHtml='Выделить все влияющие'
icon={<IconGraphCollapse size='1.25rem' className='icon-primary' />}
onClick={() => onChange([...selected, ...graph.expandAllInputs(selected)])}
2024-06-07 20:17:03 +03:00
disabled={emptySelection}
/>
<MiniButton
titleHtml='Выделить все зависимые'
icon={<IconGraphExpand size='1.25rem' className='icon-primary' />}
onClick={() => onChange([...selected, ...graph.expandAllOutputs(selected)])}
2024-06-07 20:17:03 +03:00
disabled={emptySelection}
/>
<MiniButton
2024-06-18 15:19:04 +03:00
titleHtml='<b>Максимизация</b> <br/>дополнение выделения конституентами, <br/>зависимыми только от выделенных'
2024-06-07 20:17:03 +03:00
icon={<IconGraphMaximize size='1.25rem' className='icon-primary' />}
onClick={() => onChange(graph.maximizePart(selected))}
2024-06-07 20:17:03 +03:00
disabled={emptySelection}
/>
<MiniButton
titleHtml='Выделить поставщиков'
icon={<IconGraphInputs size='1.25rem' className='icon-primary' />}
onClick={() => onChange([...selected, ...graph.expandInputs(selected)])}
2024-06-07 20:17:03 +03:00
disabled={emptySelection}
/>
<MiniButton
titleHtml='Выделить потребителей'
icon={<IconGraphOutputs size='1.25rem' className='icon-primary' />}
onClick={() => onChange([...selected, ...graph.expandOutputs(selected)])}
2024-06-07 20:17:03 +03:00
disabled={emptySelection}
/>
2024-08-21 20:20:48 +03:00
<MiniButton
titleHtml='Инвертировать'
icon={<IconGraphInverse size='1.25rem' className='icon-primary' />}
2025-02-05 01:27:32 +03:00
onClick={() => onChange([...graph.nodes.keys()].filter(item => !selected.includes(item)))}
2024-08-21 20:20:48 +03:00
/>
2024-06-07 20:17:03 +03:00
<MiniButton
titleHtml='Выделить ядро'
icon={<IconGraphCore size='1.25rem' className='icon-primary' />}
2024-08-21 20:20:48 +03:00
onClick={handleSelectCore}
/>
2024-12-02 15:58:18 +03:00
{isOwned ? (
<MiniButton
titleHtml='Выделить собственные'
icon={<IconPredecessor size='1.25rem' className='icon-primary' />}
onClick={handleSelectOwned}
/>
) : null}
2024-06-07 20:17:03 +03:00
</div>
);
}
export default ToolbarGraphSelection;