Portal/rsconcept/frontend/src/pages/OssPage/EditorOssGraph/OperationNode.tsx

82 lines
2.9 KiB
TypeScript
Raw Normal View History

2024-08-19 11:56:46 +03:00
'use client';
2024-06-27 14:43:06 +03:00
import { Handle, Position } from 'reactflow';
2024-08-17 23:43:15 +03:00
import { IconConsolidation, IconRSForm } from '@/components/Icons';
2024-07-26 00:33:22 +03:00
import TooltipOperation from '@/components/info/TooltipOperation';
2024-06-27 14:43:06 +03:00
import MiniButton from '@/components/ui/MiniButton.tsx';
2024-07-24 18:11:28 +03:00
import Overlay from '@/components/ui/Overlay';
2024-07-26 17:30:37 +03:00
import { OssNodeInternal } from '@/models/miscellaneous';
2024-08-19 11:56:46 +03:00
import { PARAMETER, prefixes } from '@/utils/constants';
import { truncateToLastWord } from '@/utils/utils';
2024-06-27 14:43:06 +03:00
import { useOssEdit } from '../OssEditContext';
2024-07-26 17:30:37 +03:00
function OperationNode(node: OssNodeInternal) {
2024-06-27 14:43:06 +03:00
const controller = useOssEdit();
2024-07-26 17:30:37 +03:00
const hasFile = !!node.data.operation.result;
2024-08-19 11:56:46 +03:00
const longLabel = node.data.label.length > PARAMETER.ossLongLabel;
const labelText = truncateToLastWord(node.data.label, PARAMETER.ossTruncateLabel);
2024-06-27 14:43:06 +03:00
2024-07-24 18:11:28 +03:00
const handleOpenSchema = () => {
2024-07-26 17:30:37 +03:00
controller.openOperationSchema(Number(node.id));
2024-06-27 14:43:06 +03:00
};
return (
<>
2024-07-23 23:03:58 +03:00
<Handle type='source' position={Position.Bottom} />
2024-07-24 18:11:28 +03:00
2024-08-19 11:56:46 +03:00
<Overlay position='top-0 right-0' className='flex flex-col gap-1 p-[0.1rem]'>
2024-07-24 18:11:28 +03:00
<MiniButton
2024-08-19 11:56:46 +03:00
icon={<IconRSForm className={hasFile ? 'clr-text-green' : 'clr-text-red'} size='0.75rem' />}
2024-07-24 18:11:28 +03:00
noHover
2024-08-17 12:16:50 +03:00
noPadding
title={hasFile ? 'Связанная КС' : 'Нет связанной КС'}
hideTitle={!controller.showTooltip}
2024-07-28 21:29:46 +03:00
onClick={handleOpenSchema}
2024-07-24 18:11:28 +03:00
disabled={!hasFile}
/>
2024-08-17 12:16:50 +03:00
{node.data.operation.is_consolidation ? (
<MiniButton
2024-08-19 11:56:46 +03:00
icon={<IconConsolidation className='clr-text-primary' size='0.75rem' />}
2024-08-17 12:16:50 +03:00
disabled
noPadding
noHover
2024-08-17 23:43:15 +03:00
titleHtml='<b>Внимание!</b><br />Ромбовидный синтез</br/>Возможны дубликаты конституент'
2024-08-17 12:16:50 +03:00
hideTitle={!controller.showTooltip}
/>
) : null}
2024-07-24 18:11:28 +03:00
</Overlay>
2024-07-26 00:33:22 +03:00
{!node.data.operation.is_owned ? (
<Overlay position='left-[0.2rem] top-[0.1rem]'>
<div className='border rounded-none clr-input h-[1.3rem]'></div>
</Overlay>
) : null}
2024-08-19 11:56:46 +03:00
<div id={`${prefixes.operation_list}${node.id}`} className='h-[34px] w-[144px] flex items-center justify-center'>
<div
className='px-1 text-center'
style={{
fontSize: longLabel ? '12px' : '14px',
lineHeight: longLabel ? '16px' : '20px',
paddingLeft: '4px',
paddingRight: longLabel ? '10px' : '4px'
}}
>
{labelText}
</div>
2024-07-26 21:08:31 +03:00
{controller.showTooltip && !node.dragging ? (
<TooltipOperation anchor={`#${prefixes.operation_list}${node.id}`} node={node} />
) : null}
2024-07-26 00:33:22 +03:00
</div>
2024-06-27 14:43:06 +03:00
2024-07-23 23:03:58 +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-06-27 14:43:06 +03:00
</>
);
}
export default OperationNode;