Files
goldenChart/frontend/src/components/strategyEditor/MultiSelectionDeleteButton.tsx
T
2026-05-24 06:20:18 +09:00

52 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { useCallback } from 'react';
import { getNodesBounds, useReactFlow, useStore } from '@xyflow/react';
import { START_NODE_ID } from '../../utils/strategyFlowLayout';
type Props = {
onDelete: () => void;
};
export function MultiSelectionDeleteButton({ onDelete }: Props) {
const { getNodes, flowToScreenPosition } = useReactFlow();
const selectionKey = useStore(useCallback((state) => {
const selected = state.nodes.filter(n => n.selected && n.id !== START_NODE_ID);
if (selected.length < 2) return null;
return selected
.map(n => `${n.id}:${Math.round(n.position.x)}:${Math.round(n.position.y)}`)
.join('|');
}, []));
if (!selectionKey) return null;
const selectedNodes = getNodes().filter(n => n.selected && n.id !== START_NODE_ID);
if (selectedNodes.length < 2) return null;
const bounds = getNodesBounds(selectedNodes);
const anchor = flowToScreenPosition({
x: bounds.x + bounds.width,
y: bounds.y,
});
return (
<button
type="button"
className="se-selection-delete"
title="선택 항목 모두 삭제 (Logic Expression에서 제외)"
style={{
position: 'absolute',
left: anchor.x + 6,
top: anchor.y - 6,
transform: 'translate(0, -100%)',
}}
onMouseDown={(e) => e.stopPropagation()}
onClick={(e) => {
e.stopPropagation();
onDelete();
}}
>
×
</button>
);
}