Skip to content

Commit

Permalink
handleSelection
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmadigan committed Aug 21, 2024
1 parent c22b20f commit 60916a1
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/PickResource.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import React, { useState, useEffect } from 'react';
import React, { useState, useEffect, useCallback } from 'react';
import { Dropdown, DropdownToggle, DropdownItem } from '@patternfly/react-core';

const PickResource = ({ graph, onResourceSelect }) => {
const [isDropdownOpen, setIsDropdownOpen] = useState(false);
const [dropdownItems, setDropdownItems] = useState([]);
const [selectedLabel, setSelectedLabel] = useState('Select a resource');

const handleSelection = useCallback((nodeId) => {
setSelectedLabel(nodeId ? graph.node(nodeId).label : 'Select a resource');
onResourceSelect(nodeId);
setIsDropdownOpen(false);
}, [graph, onResourceSelect]);

useEffect(() => {
if (graph) {
const items = [
Expand All @@ -20,13 +26,7 @@ const PickResource = ({ graph, onResourceSelect }) => {
];
setDropdownItems(items);
}
}, [graph]);

const handleSelection = (nodeId) => {
setSelectedLabel(nodeId ? graph.node(nodeId).label : 'Select a resource');
onResourceSelect(nodeId);
setIsDropdownOpen(false);
};
}, [graph, handleSelection]);

const onToggle = (isOpen) => {
setIsDropdownOpen(isOpen);
Expand Down

0 comments on commit 60916a1

Please sign in to comment.