'use client'; import clsx from 'clsx'; import { useMemo } from 'react'; import { IconAnimation, IconAnimationOff, IconDestroy, IconEdit2, IconExecute, IconFitImage, IconGrid, IconImage, IconLineStraight, IconLineWave, IconNewItem, IconReset, IconSave } from '@/components/Icons'; import BadgeHelp from '@/components/info/BadgeHelp'; import MiniButton from '@/components/ui/MiniButton'; import { HelpTopic } from '@/models/miscellaneous'; import { OperationType } from '@/models/oss'; import { PARAMETER } from '@/utils/constants'; import { prepareTooltip } from '@/utils/labels'; import { useOssEdit } from '../OssEditContext'; interface ToolbarOssGraphProps { isModified: boolean; showGrid: boolean; edgeAnimate: boolean; edgeStraight: boolean; onCreate: () => void; onDelete: () => void; onEdit: () => void; onExecute: () => void; onFitView: () => void; onSaveImage: () => void; onSavePositions: () => void; onResetPositions: () => void; toggleShowGrid: () => void; toggleEdgeAnimate: () => void; toggleEdgeStraight: () => void; } function ToolbarOssGraph({ isModified, showGrid, edgeAnimate, edgeStraight, onCreate, onDelete, onEdit, onExecute, onFitView, onSaveImage, onSavePositions, onResetPositions, toggleShowGrid, toggleEdgeAnimate, toggleEdgeStraight }: ToolbarOssGraphProps) { const controller = useOssEdit(); const selectedOperation = useMemo( () => controller.schema?.operationByID.get(controller.selected[0]), [controller.selected, controller.schema] ); const readyForSynthesis = useMemo(() => { if (!selectedOperation || selectedOperation.operation_type !== OperationType.SYNTHESIS) { return false; } if (!controller.schema || selectedOperation.result) { return false; } const argumentIDs = controller.schema.graph.expandInputs([selectedOperation.id]); if (!argumentIDs || argumentIDs.length < 2) { return false; } const argumentOperations = argumentIDs.map(id => controller.schema!.operationByID.get(id)!); if (argumentOperations.some(item => item.result === null)) { return false; } return true; }, [selectedOperation, controller.schema]); return (
} disabled={!isModified} onClick={onResetPositions} /> } title='Сбросить вид' onClick={onFitView} /> ) : ( ) } onClick={toggleShowGrid} /> ) : ( ) } onClick={toggleEdgeStraight} /> ) : ( ) } onClick={toggleEdgeAnimate} /> } title='Сохранить изображение' onClick={onSaveImage} />
{controller.isMutable ? (
} disabled={controller.isProcessing || !isModified} onClick={onSavePositions} /> } disabled={controller.isProcessing} onClick={onCreate} /> } disabled={controller.isProcessing || controller.selected.length !== 1 || !readyForSynthesis} onClick={onExecute} /> } disabled={controller.selected.length !== 1 || controller.isProcessing} onClick={onEdit} /> } disabled={controller.selected.length !== 1 || controller.isProcessing} onClick={onDelete} />
) : null}
); } //IconExecute export default ToolbarOssGraph;