Skip to content

Commit

Permalink
fixing some eslint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmadigan committed Aug 20, 2024
1 parent f9b430a commit 8c79b22
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions src/PolicyTopology.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useRef, useCallback, useState } from 'react';
import * as d3 from 'd3';
import { graphviz } from 'd3-graphviz';
import 'd3-graphviz';
import graphlib from 'graphlib';
import * as dot from 'graphlib-dot';
import { Dropdown, DropdownToggle, DropdownItem, Title, Button } from '@patternfly/react-core';
Expand All @@ -14,24 +14,6 @@ const PolicyTopology = ({ dotString }) => {
const [dropdownItems, setDropdownItems] = useState([]);
const [selectedLabel, setSelectedLabel] = useState('');

useEffect(() => {
const g = dot.read(dotString);
graphRef.current = g;
setFilteredDot(dotString);

const items = [
<DropdownItem key="reset" component="button" onClick={() => handleNodeSelection(null)}>
-
</DropdownItem>,
...g.nodes().map(node => (
<DropdownItem key={node} component="button" onClick={() => handleNodeSelection(node)}>
{g.node(node).label}
</DropdownItem>
)),
];
setDropdownItems(items);
}, [dotString]);

const handleNodeSelection = useCallback((nodeId) => {
const graph = graphRef.current;
if (!graph) {
Expand Down Expand Up @@ -89,11 +71,25 @@ const PolicyTopology = ({ dotString }) => {
setFilteredDot(filteredDotString);
}, [dotString]);

const onToggle = (isOpen) => {
setIsDropdownOpen(isOpen);
};
useEffect(() => {
const g = dot.read(dotString);
graphRef.current = g;
setFilteredDot(dotString);

const items = [
<DropdownItem key="reset" component="button" onClick={() => handleNodeSelection(null)}>
-
</DropdownItem>,
...g.nodes().map(node => (
<DropdownItem key={node} component="button" onClick={() => handleNodeSelection(node)}>
{g.node(node).label}
</DropdownItem>
)),
];
setDropdownItems(items);
}, [dotString, handleNodeSelection]);

const handleNodeClick = (event) => {
const handleNodeClick = useCallback((event) => {
const nodeElement = event.target.closest('g.node');
if (!nodeElement) {
console.error('No node element found');
Expand All @@ -102,13 +98,16 @@ const PolicyTopology = ({ dotString }) => {
const nodeId = nodeElement.querySelector('title').textContent;
console.log(`Node clicked: ${nodeId}`);
handleNodeSelection(nodeId);
}, [handleNodeSelection]);

const onToggle = (isOpen) => {
setIsDropdownOpen(isOpen);
};

const resetGraph = () => {
setSelectedLabel('Select a resource');
setFilteredDot(dotString);
};

useEffect(() => {
if (containerRef.current && filteredDot) {
const renderGraph = () => {
Expand Down

0 comments on commit 8c79b22

Please sign in to comment.