Skip to content

Commit

Permalink
fix(1094): Keep current visibility when adding a new entity to the ca…
Browse files Browse the repository at this point in the history
…nvas
  • Loading branch information
tplevko committed Nov 15, 2024
1 parent 39c0ffd commit 371de49
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ describe('Test for Multi route actions from the canvas', () => {
cy.addNewRoute();
cy.addNewRoute();

cy.get('[data-testid="flows-list-route-count"]').should('have.text', '1/3');
cy.get('[data-testid="flows-list-route-count"]').should('have.text', '3/3');

cy.toggleRouteVisibility(0);
cy.toggleRouteVisibility(1);

cy.get('[data-testid="flows-list-route-count"]').should('have.text', '3/3');
cy.get('[data-testid="flows-list-route-count"]').should('have.text', '1/3');

cy.toggleRouteVisibility(0);
cy.toggleRouteVisibility(1);
cy.toggleRouteVisibility(2);

cy.get('[data-testid="flows-list-route-count"]').should('have.text', '0/3');
Expand Down
1 change: 0 additions & 1 deletion packages/ui-tests/cypress/support/next-commands/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,4 @@ Cypress.Commands.add('deleteRoute', (index: number) => {
cy.get('.pf-m-danger').click();
}
});
cy.closeFlowsListIfVisible();
});
Original file line number Diff line number Diff line change
Expand Up @@ -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 { IVisualizationNode } from '../../../../models';

export const NewEntity: FunctionComponent = () => {
const { camelResource, updateEntitiesFromCamelResource } = useContext(EntitiesContext)!;
Expand All @@ -13,6 +15,25 @@ export const NewEntity: FunctionComponent = () => {
const menuRef = useRef<HTMLDivElement>(null);
const toggleRef = useRef<HTMLButtonElement>(null);
const groupedEntities = useRef<BaseVisualCamelEntityDefinition>(camelResource.getCanvasEntityList());
const controller = useVisualizationController();

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function findRootVisualization(node: any, newId?: string): IVisualizationNode | null {

Check warning on line 21 in packages/ui/src/components/Visualization/ContextToolbar/NewEntity/NewEntity.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ui/src/components/Visualization/ContextToolbar/NewEntity/NewEntity.tsx#L21

Added line #L21 was not covered by tests
if (node?.children) {
for (const child of node.children) {
const result = (() => {

Check warning on line 24 in packages/ui/src/components/Visualization/ContextToolbar/NewEntity/NewEntity.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ui/src/components/Visualization/ContextToolbar/NewEntity/NewEntity.tsx#L23-L24

Added lines #L23 - L24 were not covered by tests
if (child?.data?.vizNode?.data.entity.id === newId) {
if (child?.data?.vizNode?.data?.isGroup === true) {
return child.data.vizNode;

Check warning on line 27 in packages/ui/src/components/Visualization/ContextToolbar/NewEntity/NewEntity.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ui/src/components/Visualization/ContextToolbar/NewEntity/NewEntity.tsx#L27

Added line #L27 was not covered by tests
}
}
return null;

Check warning on line 30 in packages/ui/src/components/Visualization/ContextToolbar/NewEntity/NewEntity.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ui/src/components/Visualization/ContextToolbar/NewEntity/NewEntity.tsx#L30

Added line #L30 was not covered by tests
})();
if (result) return result;
}
}
return null;

Check warning on line 35 in packages/ui/src/components/Visualization/ContextToolbar/NewEntity/NewEntity.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ui/src/components/Visualization/ContextToolbar/NewEntity/NewEntity.tsx#L35

Added line #L35 was not covered by tests
}

const onSelect = useCallback(
(_event: unknown, entityType: string | number | undefined) => {
Expand All @@ -26,7 +47,11 @@ export const NewEntity: FunctionComponent = () => {
* supported
*/
const newId = camelResource.addNewEntity(entityType as EntityType);
visibleFlowsContext.visualFlowsApi.hideAllFlows();
setTimeout(() => {
const result = findRootVisualization(controller.getGraph(), newId);
controller.fireEvent(SELECTION_EVENT, [result?.id]);

Check warning on line 52 in packages/ui/src/components/Visualization/ContextToolbar/NewEntity/NewEntity.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ui/src/components/Visualization/ContextToolbar/NewEntity/NewEntity.tsx#L51-L52

Added lines #L51 - L52 were not covered by tests
}, 300);

visibleFlowsContext.visualFlowsApi.toggleFlowVisible(newId);
updateEntitiesFromCamelResource();
setIsOpen(false);
Expand Down

0 comments on commit 371de49

Please sign in to comment.