From d9c51cfaece601a628dd6443ec71218ea84e85e0 Mon Sep 17 00:00:00 2001 From: Ugo Palatucci Date: Thu, 16 May 2024 16:33:06 +0200 Subject: [PATCH] CNV-41600: fix removeDuplicatesByName with custom name property --- src/utils/utils/utils.ts | 4 ++-- .../components/StorageUtil/StorageUtil.tsx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/utils/utils.ts b/src/utils/utils/utils.ts index 35c27119e..96241ac59 100644 --- a/src/utils/utils/utils.ts +++ b/src/utils/utils/utils.ts @@ -121,9 +121,9 @@ export const columnSorting = ( return data?.sort(predicate)?.slice(startIndex, endIndex); }; -export const removeDuplicatesByName = (array: any[]) => +export const removeDuplicatesByName = (array: any[], nameProperty = 'name') => array?.reduce((acc, curr) => { - if (!acc.find((item) => item?.name === curr?.name)) acc.push(curr); + if (!acc.find((item) => item?.[nameProperty] === curr?.[nameProperty])) acc.push(curr); return acc; }, []); diff --git a/src/views/virtualmachines/details/tabs/overview/components/VirtualMachinesOverviewTabUtilization/components/StorageUtil/StorageUtil.tsx b/src/views/virtualmachines/details/tabs/overview/components/VirtualMachinesOverviewTabUtilization/components/StorageUtil/StorageUtil.tsx index ac81267db..dbe58dd06 100644 --- a/src/views/virtualmachines/details/tabs/overview/components/VirtualMachinesOverviewTabUtilization/components/StorageUtil/StorageUtil.tsx +++ b/src/views/virtualmachines/details/tabs/overview/components/VirtualMachinesOverviewTabUtilization/components/StorageUtil/StorageUtil.tsx @@ -18,7 +18,7 @@ const StorageUtil: FC = ({ vmi }) => { const [guestAgentData, loaded] = useGuestOS(vmi); const { totalBytes = 0, usedBytes = 0 } = - removeDuplicatesByName(guestAgentData?.fsInfo?.disks)?.reduce( + removeDuplicatesByName(guestAgentData?.fsInfo?.disks, 'diskName')?.reduce( (acc, data) => { acc.totalBytes += data?.totalBytes; acc.usedBytes += data?.usedBytes;