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-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';
|
|
|
|
|
import { useOSS } from '@/context/OssContext';
|
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-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-24 18:11:39 +03:00
|
|
|
|
const model = useOSS();
|
2024-07-14 14:41:05 +03:00
|
|
|
|
|
2024-07-24 18:11:39 +03:00
|
|
|
|
const hasFile = !!model.schema?.operationByID.get(Number(id))?.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>
|
|
|
|
|
<div className='flex-grow text-center text-sm'>{data.label}</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;
|