Skip to content

Commit

Permalink
HDDS-12016. Fixed duplicate entries when changing path in DU page (#7657
Browse files Browse the repository at this point in the history
)
  • Loading branch information
devabhishekpal authored Jan 19, 2025
1 parent 3a6b05e commit c006c57
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 189 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import moment from 'moment';
import { notification } from 'antd';
import { CanceledError } from 'axios';

export const getCapacityPercent = (used: number, total: number) => Math.round((used / total) * 100);

Expand Down Expand Up @@ -80,3 +81,31 @@ export const nullAwareLocaleCompare = (a: string, b: string) => {

return a.localeCompare(b);
};

export function removeDuplicatesAndMerge<T>(origArr: T[], updateArr: T[], mergeKey: string): T[] {
return Array.from([...origArr, ...updateArr].reduce(
(accumulator, curr) => accumulator.set(curr[mergeKey as keyof T], curr),
new Map
).values());
}

export const checkResponseError = (responses: Awaited<Promise<any>>[]) => {
const responseError = responses.filter(
(resp) => resp.status === 'rejected'
);

if (responseError.length !== 0) {
responseError.forEach((err) => {
if (err.reason.toString().includes("CanceledError")) {
throw new CanceledError('canceled', "ERR_CANCELED");
}
else {
const reqMethod = err.reason.config.method;
const reqURL = err.reason.config.url
showDataFetchError(
`Failed to ${reqMethod} URL ${reqURL}\n${err.reason.toString()}`
);
}
})
}
}
Loading

0 comments on commit c006c57

Please sign in to comment.