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

81 lines
2.2 KiB
TypeScript
Raw Normal View History

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