ConceptPortal-public/rsconcept/frontend/src/components/ui/Synthesis/OperationNode.tsx

92 lines
2.3 KiB
TypeScript
Raw Normal View History

2024-06-21 18:47:46 +03:00
import { memo, type FC, type CSSProperties } from 'react';
import { Handle, Position, type NodeProps } from '@reactflow/core';
import MiniButton from '@/components/ui/MiniButton.tsx';
import { IoGitNetworkSharp } from 'react-icons/io5';
import { useSynthesis } from '@/pages/OssPage/SynthesisContext.tsx';
import { CiSquareRemove } from 'react-icons/ci';
import { VscDebugStart } from "react-icons/vsc";
2024-06-05 21:34:04 +03:00
2024-06-21 18:47:46 +03:00
const sourceHandleStyleA: CSSProperties = { left: 50 };
2024-06-05 21:34:04 +03:00
const sourceHandleStyleB: CSSProperties = {
2024-06-21 18:47:46 +03:00
right: 50,
left: 'auto'
2024-06-05 21:34:04 +03:00
};
2024-06-21 18:47:46 +03:00
interface OperationNodeProps {
id: string;
data: {
label: string;
onDelete: (nodeId: string) => void;
};
xPos: number,
yPos: number,
}
const OperationNode: FC<OperationNodeProps> = ({ id, data, xPos, yPos }) => {
const controller = useSynthesis();
const { label, onDelete } = data;
const handleDelete = () => {
onDelete(id);
};
const handleSubstitution = () =>{
controller.selectNode(id);
controller.showSynthesis();
}
const handleSynthesis = () => {
controller.singleSynthesis(id)
}
return (
<>
<Handle type="target" position={Position.Bottom} />
<div>
<MiniButton className="float-right"
icon={<CiSquareRemove className="icon-red" />}
title="Удалить"
onClick={handleDelete}
color={'red'}
/>
<div>
Тип: <strong>Отождествление</strong>
</div>
<div>
Схема:{' '}
<strong>
</strong>
<MiniButton
className="float-right"
icon={<VscDebugStart className="icon-green" />}
title="Синтез"
onClick={() => handleSynthesis()}
/>
<MiniButton
className="float-right"
icon={<IoGitNetworkSharp className="icon-green" />}
title="Отождествления"
onClick={() => handleSubstitution()}
/>
</div>
</div>
<Handle
type="source"
position={Position.Top}
id="a"
style={sourceHandleStyleA}
/>
<Handle
type="source"
position={Position.Top}
id="b"
style={sourceHandleStyleB}
/>
</>
);
2024-06-05 21:34:04 +03:00
};
export default memo(OperationNode);