Skip to content

Commit

Permalink
fix(GroupImmutableSystems): THEEDGE-3782 - Fixes Group details edge U…
Browse files Browse the repository at this point in the history
…pdate 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.
  • Loading branch information
ldjebran authored Jan 11, 2024
1 parent 990ef7e commit c0f7e69
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions src/components/GroupSystems/GroupImmutableSystems.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);
Expand Down Expand Up @@ -172,9 +178,6 @@ const GroupImmutableSystems = ({ groupName, groupId, ...props }) => {
isOpen: true,
}));
};

let imageSet = [];
let deviceIds = [];
const bulkSelectConfig = useBulkSelectConfig(
selected,
null,
Expand All @@ -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 (
Expand Down

0 comments on commit c0f7e69

Please sign in to comment.