Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat #1217: Open side panel when new node is added #1563

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ContextMenuItem } from '@patternfly/react-topology';
import { ContextMenuItem, SELECTION_EVENT, useVisualizationController } from '@patternfly/react-topology';
import { FunctionComponent, PropsWithChildren, useCallback, useContext } from 'react';
import { IDataTestID } from '../../../../models';
import { AddStepMode, IVisualizationNode } from '../../../../models/visualization/base-visual-entity';
Expand All @@ -10,9 +10,26 @@
vizNode: IVisualizationNode;
}

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

Check warning on line 14 in packages/ui/src/components/Visualization/Custom/ContextMenu/ItemAddStep.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ui/src/components/Visualization/Custom/ContextMenu/ItemAddStep.tsx#L14

Added line #L14 was not covered by tests
if (node?.data?.vizNode?.data?.path === targetPath) {
return node.data.vizNode;

Check warning on line 16 in packages/ui/src/components/Visualization/Custom/ContextMenu/ItemAddStep.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ui/src/components/Visualization/Custom/ContextMenu/ItemAddStep.tsx#L16

Added line #L16 was not covered by tests
}

if (node?.children) {
for (const child of node.children) {
const result = findVisualizationNode(child, targetPath);

Check warning on line 21 in packages/ui/src/components/Visualization/Custom/ContextMenu/ItemAddStep.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ui/src/components/Visualization/Custom/ContextMenu/ItemAddStep.tsx#L20-L21

Added lines #L20 - L21 were not covered by tests
if (result) return result;
}
}

return null;

Check warning on line 26 in packages/ui/src/components/Visualization/Custom/ContextMenu/ItemAddStep.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ui/src/components/Visualization/Custom/ContextMenu/ItemAddStep.tsx#L26

Added line #L26 was not covered by tests
}

export const ItemAddStep: FunctionComponent<ItemAddStepProps> = (props) => {
const entitiesContext = useContext(EntitiesContext);
const catalogModalContext = useContext(CatalogModalContext);
const controller = useVisualizationController();

const onAddNode = useCallback(async () => {
if (!props.vizNode || !entitiesContext) return;
Expand All @@ -29,7 +46,14 @@

/** Update entity */
entitiesContext.updateEntitiesFromCamelResource();
}, [catalogModalContext, entitiesContext, props.mode, props.vizNode]);

setTimeout(() => {

Check warning on line 50 in packages/ui/src/components/Visualization/Custom/ContextMenu/ItemAddStep.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ui/src/components/Visualization/Custom/ContextMenu/ItemAddStep.tsx#L50

Added line #L50 was not covered by tests
const result = props.vizNode.data.path
? findVisualizationNode(controller.getGraph(), props.vizNode.data.path)
: null;
controller.fireEvent(SELECTION_EVENT, [result?.getNextNode()?.id]);

Check warning on line 54 in packages/ui/src/components/Visualization/Custom/ContextMenu/ItemAddStep.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ui/src/components/Visualization/Custom/ContextMenu/ItemAddStep.tsx#L52-L54

Added lines #L52 - L54 were not covered by tests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few cases in which getNextNode doesn't yield the desired node:

  1. When adding a step in from
  2. Preprending a step from any given node

I'll try to check if we can get the new node id directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I will wait for your changes in lordrip@3d668cd before adding more capabilities

}, 200);
}, [props.vizNode, props.mode, entitiesContext, catalogModalContext, controller]);

return (
<ContextMenuItem onClick={onAddNode} data-testid={props['data-testid']}>
Expand Down
Loading