ConceptPortal-public/rsconcept/frontend/src/pages/OssPage/EditorOssGraph/OperationNode.tsx

56 lines
1.6 KiB
TypeScript
Raw Normal View History

2024-07-14 14:41:05 +03:00
import { Handle, Position } from 'reactflow';
2024-07-24 18:11:39 +03:00
import { IconRSForm } from '@/components/Icons';
2024-07-26 00:34:08 +03:00
import TooltipOperation from '@/components/info/TooltipOperation';
2024-07-14 14:41:05 +03:00
import MiniButton from '@/components/ui/MiniButton.tsx';
2024-07-24 18:11:39 +03:00
import Overlay from '@/components/ui/Overlay';
2024-07-26 00:34:08 +03:00
import { IOperation } from '@/models/oss';
import { prefixes } from '@/utils/constants';
2024-07-14 14:41:05 +03:00
import { useOssEdit } from '../OssEditContext';
interface OperationNodeProps {
id: string;
2024-07-23 23:04:21 +03:00
data: {
label: string;
2024-07-26 00:34:08 +03:00
operation: IOperation;
2024-07-23 23:04:21 +03:00
};
2024-07-14 14:41:05 +03:00
}
2024-07-23 23:04:21 +03:00
function OperationNode({ id, data }: OperationNodeProps) {
2024-07-14 14:41:05 +03:00
const controller = useOssEdit();
2024-07-26 00:34:08 +03:00
const hasFile = !!data.operation.result;
2024-07-14 14:41:05 +03:00
2024-07-24 18:11:39 +03:00
const handleOpenSchema = () => {
controller.openOperationSchema(Number(id));
2024-07-14 14:41:05 +03:00
};
return (
<>
2024-07-23 23:04:21 +03:00
<Handle type='source' position={Position.Bottom} />
2024-07-24 18:11:39 +03:00
<Overlay position='top-[-0.2rem] right-[-0.2rem]' className='cc-icons'>
<MiniButton
icon={<IconRSForm className={hasFile ? 'clr-text-green' : 'clr-text-red'} size='0.75rem' />}
noHover
title='Связанная КС'
onClick={() => {
handleOpenSchema();
}}
disabled={!hasFile}
/>
</Overlay>
2024-07-26 00:34:08 +03:00
<div id={`${prefixes.operation_list}${id}`} className='flex-grow text-center text-sm'>
{data.label}
<TooltipOperation anchor={`#${prefixes.operation_list}${id}`} data={data.operation} />
</div>
2024-07-14 14:41:05 +03:00
2024-07-23 23:04:21 +03:00
<Handle type='target' position={Position.Top} id='left' style={{ left: 40 }} />
<Handle type='target' position={Position.Top} id='right' style={{ right: 40, left: 'auto' }} />
2024-07-14 14:41:05 +03:00
</>
);
}
export default OperationNode;