From c0f7e694a2b664d39c0796d616ab49699fb1e9a4 Mon Sep 17 00:00:00 2001 From: Djebran Lezzoum Date: Thu, 11 Jan 2024 22:05:22 +0100 Subject: [PATCH] fix(GroupImmutableSystems): THEEDGE-3782 - Fixes Group details edge Update button (#2135) Fixes https://issues.redhat.com/browse/THEEDGE-3782. When systems to update was selected the Update button was not updated as expected. now the button is enabled when the selected systems are updatable and have the same image set, in all other cases the button is disabled. --- .../GroupSystems/GroupImmutableSystems.js | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/src/components/GroupSystems/GroupImmutableSystems.js b/src/components/GroupSystems/GroupImmutableSystems.js index 40ca4d8a9..2bd89d1e7 100644 --- a/src/components/GroupSystems/GroupImmutableSystems.js +++ b/src/components/GroupSystems/GroupImmutableSystems.js @@ -78,8 +78,14 @@ const GroupImmutableSystems = ({ groupName, groupId, ...props }) => { }; const navigate = useNavigate(); - const canUpdateSelectedDevices = (deviceIds, imageSets) => - deviceIds?.length > 0 && imageSets?.length == 1 ? true : false; + const canUpdateSelectedDevices = (deviceIds, imageSets, updatableDeviceIds) => + deviceIds?.length > 0 && + imageSets?.length === 1 && + updatableDeviceIds?.length > 0 && + // all deviceIds must be in updatableDeviceIds + deviceIds.filter((s) => updatableDeviceIds.includes(s)).length === + deviceIds.length; + const [removeHostsFromGroupModalOpen, setRemoveHostsFromGroupModalOpen] = useState(false); const [currentSystem, setCurrentSystem] = useState([]); @@ -172,9 +178,6 @@ const GroupImmutableSystems = ({ groupName, groupId, ...props }) => { isOpen: true, })); }; - - let imageSet = []; - let deviceIds = []; const bulkSelectConfig = useBulkSelectConfig( selected, null, @@ -185,20 +188,22 @@ const GroupImmutableSystems = ({ groupName, groupId, ...props }) => { groupName ); - //enable disable bulk update based on selection, must refactor useEffect(() => { - if (selected.size > 0 && deviceImageSet?.size > 0) { - return () => { - [...selected.keys()].map((s) => { - const img = deviceImageSet[s]; - if (!imageSet.includes(img)) { - imageSet.push(img); - } - deviceIds.push(s); - }); - setCanUpdate(canUpdateSelectedDevices(deviceIds, imageSet)); - setUpdateImageSet(imageSet); - }; + if (selected.size > 0 && Object.keys(deviceImageSet || {}).length > 0) { + let imageSet = []; + let deviceIds = []; + [...selected.keys()].map((s) => { + const img = deviceImageSet[s]; + + if (!imageSet.includes(img)) { + imageSet.push(img); + } + deviceIds.push(s); + }); + setCanUpdate(canUpdateSelectedDevices(deviceIds, imageSet, deviceData)); + setUpdateImageSet(imageSet); + } else { + setCanUpdate(false); } }, [deviceData, selected, deviceImageSet]); return (