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

Fix enable/disable node state on browser resize. #13042

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 13 additions & 12 deletions awx/ui/src/screens/TopologyView/MeshGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,13 @@ const Loader = styled(ContentLoading)`
width: 100%;
background: white;
`;
function MeshGraph({ data, showLegend, zoom, setShowZoomControls }) {
const [storedNodes, setStoredNodes] = useState(null);
function MeshGraph({
data,
showLegend,
zoom,
setShowZoomControls,
storedNodes,
}) {
const [isNodeSelected, setIsNodeSelected] = useState(false);
const [selectedNode, setSelectedNode] = useState(null);
const [simulationProgress, setSimulationProgress] = useState(null);
Expand Down Expand Up @@ -100,19 +105,14 @@ function MeshGraph({ data, showLegend, zoom, setShowZoomControls }) {
// update mesh when user toggles enabled/disabled slider
useEffect(() => {
if (instance?.id) {
const updatedNodes = storedNodes.map((n) =>
const updatedNodes = storedNodes.current.map((n) =>
n.id === instance.id ? { ...n, enabled: instance.enabled } : n
);
setStoredNodes(updatedNodes);
storedNodes.current = updatedNodes;
updateNodeSVG(storedNodes.current);
}
}, [instance]); // eslint-disable-line react-hooks/exhaustive-deps

useEffect(() => {
if (storedNodes) {
updateNodeSVG(storedNodes);
}
}, [storedNodes]);

const draw = () => {
let width;
let height;
Expand All @@ -137,6 +137,9 @@ function MeshGraph({ data, showLegend, zoom, setShowZoomControls }) {
const mesh = svg.append('g').attr('class', 'mesh');

const graph = data;
if (storedNodes?.current) {
graph.nodes = storedNodes.current;
}

/* WEB WORKER */
const worker = webWorker();
Expand All @@ -162,7 +165,6 @@ function MeshGraph({ data, showLegend, zoom, setShowZoomControls }) {
}

function ended({ nodes, links }) {
setStoredNodes(nodes);
// Remove loading screen
d3.select('.simulation-loader').style('visibility', 'hidden');
setShowZoomControls(true);
Expand Down Expand Up @@ -247,7 +249,6 @@ function MeshGraph({ data, showLegend, zoom, setShowZoomControls }) {
.attr('fill', DEFAULT_NODE_COLOR)
.attr('stroke-dasharray', (d) => (d.enabled ? `1 0` : `5`))
.attr('stroke', DEFAULT_NODE_STROKE_COLOR);

// node type labels
node
.append('text')
Expand Down
5 changes: 4 additions & 1 deletion awx/ui/src/screens/TopologyView/TopologyView.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useCallback, useState } from 'react';
import React, { useEffect, useCallback, useState, useRef } from 'react';
import { t } from '@lingui/macro';
import { PageSection, Card, CardBody } from '@patternfly/react-core';
import ContentError from 'components/ContentError';
Expand All @@ -10,6 +10,7 @@ import useZoom from './utils/useZoom';
import { CHILDSELECTOR, PARENTSELECTOR } from './constants';

function TopologyView() {
const storedNodes = useRef(null);
const [showLegend, setShowLegend] = useState(true);
const [showZoomControls, setShowZoomControls] = useState(false);
const {
Expand All @@ -20,6 +21,7 @@ function TopologyView() {
} = useRequest(
useCallback(async () => {
const { data } = await MeshAPI.read();
storedNodes.current = data.nodes;
return {
meshData: data,
};
Expand Down Expand Up @@ -64,6 +66,7 @@ function TopologyView() {
showLegend={showLegend}
zoom={zoom}
setShowZoomControls={setShowZoomControls}
storedNodes={storedNodes}
/>
)}
</CardBody>
Expand Down