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

Add "Collapse All" and "Expand All" actions to control bar in topology view #2886

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"@patternfly/react-styles": "^5.2.1",
"@patternfly/react-table": "^5.2.1",
"@patternfly/react-tokens": "^5.2.1",
"@patternfly/react-topology": "^5.4.0-prerelease.1",
"@patternfly/react-topology": "^5.4.0-prerelease.6",
"@patternfly/react-virtualized-extension": "^5.0.0",
"@types/classnames": "^2.3.1",
"axios": "^1.6.4",
Expand Down
60 changes: 60 additions & 0 deletions frontend/src/concepts/topology/PipelineVisualizationSurface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
useVisualizationController,
VisualizationSurface,
addSpacerNodes,
DEFAULT_SPACER_NODE_TYPE,
DEFAULT_EDGE_TYPE,
} from '@patternfly/react-topology';
import {
EmptyState,
Expand All @@ -18,6 +20,7 @@
EmptyStateHeader,
} from '@patternfly/react-core';
import { ExclamationCircleIcon } from '@patternfly/react-icons';
import { NODE_HEIGHT, NODE_WIDTH } from './const';

type PipelineVisualizationSurfaceProps = {
nodes: PipelineNodeModel[];
Expand Down Expand Up @@ -62,6 +65,55 @@
}
}
}, [controller, nodes]);

const collapseAllCallback = React.useCallback(
(collapseAll: boolean) => {

Check warning on line 70 in frontend/src/concepts/topology/PipelineVisualizationSurface.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/concepts/topology/PipelineVisualizationSurface.tsx#L70

Added line #L70 was not covered by tests
// First, expand/collapse all nodes
if (collapseAll) {
controller.getGraph().collapseAll();
} else {
controller.getGraph().expandAll();

Check warning on line 75 in frontend/src/concepts/topology/PipelineVisualizationSurface.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/concepts/topology/PipelineVisualizationSurface.tsx#L72-L75

Added lines #L72 - L75 were not covered by tests
}
// We must recreate the model based on what is visible
const model = controller.toModel();

Check warning on line 78 in frontend/src/concepts/topology/PipelineVisualizationSurface.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/concepts/topology/PipelineVisualizationSurface.tsx#L78

Added line #L78 was not covered by tests

// Get all the non-spacer nodes, mark them all visible again
const nonSpacerNodes = model
.nodes!.filter((n) => n.type !== DEFAULT_SPACER_NODE_TYPE)
.map((n) => ({

Check warning on line 83 in frontend/src/concepts/topology/PipelineVisualizationSurface.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/concepts/topology/PipelineVisualizationSurface.tsx#L81-L83

Added lines #L81 - L83 were not covered by tests
...n,
visible: true,
}));

// If collapsing, set the size of the collapsed group nodes
if (collapseAll) {
nonSpacerNodes.forEach((node) => {
const newNode = node;
if (node.group && node.collapsed) {
newNode.width = NODE_WIDTH;
newNode.height = NODE_HEIGHT;

Check warning on line 94 in frontend/src/concepts/topology/PipelineVisualizationSurface.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/concepts/topology/PipelineVisualizationSurface.tsx#L89-L94

Added lines #L89 - L94 were not covered by tests
}
});
}
// Determine the new set of nodes, including the spacer nodes
const pipelineNodes = addSpacerNodes(nonSpacerNodes);

Check warning on line 99 in frontend/src/concepts/topology/PipelineVisualizationSurface.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/concepts/topology/PipelineVisualizationSurface.tsx#L99

Added line #L99 was not covered by tests

// Determine the new edges
const edges = getEdgesFromNodes(

Check warning on line 102 in frontend/src/concepts/topology/PipelineVisualizationSurface.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/concepts/topology/PipelineVisualizationSurface.tsx#L102

Added line #L102 was not covered by tests
pipelineNodes,
DEFAULT_SPACER_NODE_TYPE,
DEFAULT_EDGE_TYPE,
DEFAULT_EDGE_TYPE,
);

// Apply the new model and run the layout
controller.fromModel({ nodes: pipelineNodes, edges }, true);
controller.getGraph().layout();
controller.getGraph().fit(80);

Check warning on line 112 in frontend/src/concepts/topology/PipelineVisualizationSurface.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/concepts/topology/PipelineVisualizationSurface.tsx#L110-L112

Added lines #L110 - L112 were not covered by tests
},
[controller],
);

if (error) {
return (
<EmptyState data-id="error-empty-state">
Expand All @@ -81,6 +133,8 @@
<TopologyControlBar
controlButtons={createTopologyControlButtons({
...defaultControlButtonsOptions,
expandAll: !!collapseAllCallback,
collapseAll: !!collapseAllCallback,
zoomInCallback: action(() => {
controller.getGraph().scaleBy(4 / 3);
}),
Expand All @@ -94,6 +148,12 @@
controller.getGraph().reset();
controller.getGraph().layout();
}),
expandAllCallback: action(() => {
collapseAllCallback(false);

Check warning on line 152 in frontend/src/concepts/topology/PipelineVisualizationSurface.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/concepts/topology/PipelineVisualizationSurface.tsx#L151-L152

Added lines #L151 - L152 were not covered by tests
}),
collapseAllCallback: action(() => {
collapseAllCallback(true);

Check warning on line 155 in frontend/src/concepts/topology/PipelineVisualizationSurface.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/concepts/topology/PipelineVisualizationSurface.tsx#L154-L155

Added lines #L154 - L155 were not covered by tests
}),
legend: false,
})}
/>
Expand Down
Loading