From 818e414f4c4cdb6da6bb3020cf2d466e319b9418 Mon Sep 17 00:00:00 2001 From: tplevko Date: Mon, 11 Nov 2024 15:32:22 +0100 Subject: [PATCH] fix(1094): Keep current visibility when adding a new entity to the canvas --- .../ContextToolbar/NewEntity/NewEntity.tsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/ui/src/components/Visualization/ContextToolbar/NewEntity/NewEntity.tsx b/packages/ui/src/components/Visualization/ContextToolbar/NewEntity/NewEntity.tsx index 850a326e1..40c8136ca 100644 --- a/packages/ui/src/components/Visualization/ContextToolbar/NewEntity/NewEntity.tsx +++ b/packages/ui/src/components/Visualization/ContextToolbar/NewEntity/NewEntity.tsx @@ -5,6 +5,8 @@ import { BaseVisualCamelEntityDefinition } from '../../../../models/camel/camel- import { EntityType } from '../../../../models/camel/entities'; import { EntitiesContext } from '../../../../providers/entities.provider'; import { VisibleFlowsContext } from '../../../../providers/visible-flows.provider'; +import { SELECTION_EVENT, useVisualizationController } from '@patternfly/react-topology'; +import { getVisualizationNodesFromGraph } from '../../../../utils'; export const NewEntity: FunctionComponent = () => { const { camelResource, updateEntitiesFromCamelResource } = useContext(EntitiesContext)!; @@ -13,6 +15,7 @@ export const NewEntity: FunctionComponent = () => { const menuRef = useRef(null); const toggleRef = useRef(null); const groupedEntities = useRef(camelResource.getCanvasEntityList()); + const controller = useVisualizationController(); const onSelect = useCallback( (_event: unknown, entityType: string | number | undefined) => { @@ -26,7 +29,14 @@ export const NewEntity: FunctionComponent = () => { * supported */ const newId = camelResource.addNewEntity(entityType as EntityType); - visibleFlowsContext.visualFlowsApi.hideAllFlows(); + setTimeout(() => { + const result = getVisualizationNodesFromGraph( + controller.getGraph(), + (vizNode) => vizNode.data.entity?.id === newId, + ); + controller.fireEvent(SELECTION_EVENT, [result[0]?.id]); + }, 300); + visibleFlowsContext.visualFlowsApi.toggleFlowVisible(newId); updateEntitiesFromCamelResource(); setIsOpen(false);