diff --git a/packages/ui/src/components/Visualization/Custom/ContextMenu/ItemDisableStep.tsx b/packages/ui/src/components/Visualization/Custom/ContextMenu/ItemDisableStep.tsx index 7459ccc9a..20f49cdd4 100644 --- a/packages/ui/src/components/Visualization/Custom/ContextMenu/ItemDisableStep.tsx +++ b/packages/ui/src/components/Visualization/Custom/ContextMenu/ItemDisableStep.tsx @@ -1,6 +1,6 @@ -import { BanIcon, CheckIcon } from '@patternfly/react-icons'; -import { ContextMenuItem } from '@patternfly/react-topology'; -import { FunctionComponent, PropsWithChildren, useCallback, useContext } from 'react'; +import { BanIcon, CheckIcon, PowerOffIcon } from '@patternfly/react-icons'; +import { ContextMenuItem, useVisualizationController } from '@patternfly/react-topology'; +import { FunctionComponent, PropsWithChildren, useCallback, useContext, useMemo } from 'react'; import { IDataTestID } from '../../../../models'; import { IVisualizationNode } from '../../../../models/visualization/base-visual-entity'; import { EntitiesContext } from '../../../../providers/entities.provider'; @@ -10,11 +10,32 @@ interface ItemDisableStepProps extends PropsWithChildren { vizNode: IVisualizationNode; } +// eslint-disable-next-line @typescript-eslint/no-explicit-any +function findAllDisabledNodes(node: any): IVisualizationNode[] | null { + const allDisabledNodes = []; + if (node?.data?.vizNode?.getComponentSchema()?.definition?.disabled) { + allDisabledNodes.push(node.data.vizNode); + } + if (node?.children) { + for (const child of node.children) { + const result = findAllDisabledNodes(child); + allDisabledNodes.push(...(result || [])); + } + } + return allDisabledNodes; +} + export const ItemDisableStep: FunctionComponent = (props) => { const entitiesContext = useContext(EntitiesContext); + const controller = useVisualizationController(); const isDisabled = !!props.vizNode.getComponentSchema()?.definition?.disabled; + const allDisabledNodes = useMemo(() => { + return findAllDisabledNodes(controller?.getGraph()) || []; + }, [controller]); + const isMultiDisabled = allDisabledNodes.length > 1; + const onToggleDisableNode = useCallback(() => { const newModel = props.vizNode.getComponentSchema()?.definition || {}; setValue(newModel, 'disabled', !isDisabled); @@ -23,17 +44,34 @@ export const ItemDisableStep: FunctionComponent = (props) entitiesContext?.updateEntitiesFromCamelResource(); }, [entitiesContext, isDisabled, props.vizNode]); + const onEnableAllNodes = useCallback(() => { + allDisabledNodes.forEach((node) => { + const newModel = node.getComponentSchema()?.definition || {}; + setValue(newModel, 'disabled', false); + node.updateModel(newModel); + }); + + entitiesContext?.updateEntitiesFromCamelResource(); + }, [allDisabledNodes, entitiesContext]); + return ( - - {isDisabled ? ( - <> - Enable - - ) : ( - <> - Disable - + <> + + {isDisabled ? ( + <> + Enable + + ) : ( + <> + Disable + + )} + + {isDisabled && isMultiDisabled && ( + + Enable All + )} - + ); };