From 60916a15803393bc57f25a257bcc909ad49827ee Mon Sep 17 00:00:00 2001 From: Jason Madigan Date: Wed, 21 Aug 2024 15:45:09 +0100 Subject: [PATCH] handleSelection --- src/PickResource.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/PickResource.js b/src/PickResource.js index 49323a4..594d326 100644 --- a/src/PickResource.js +++ b/src/PickResource.js @@ -1,4 +1,4 @@ -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 }) => { @@ -6,6 +6,12 @@ const PickResource = ({ graph, onResourceSelect }) => { 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 = [ @@ -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);