1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-19 13:29:41 +02:00

chore(react): Convert cluster details to react CE (#466)

This commit is contained in:
James Player 2025-02-26 14:13:50 +13:00 committed by GitHub
parent dd98097897
commit 7759d762ab
24 changed files with 829 additions and 345 deletions

View file

@ -20,3 +20,38 @@ export function prepareAnnotations(annotations?: Annotation[]) {
);
return result;
}
/**
* Returns the safe value of the given number or string.
* @param value - The value to get the safe value for.
* @returns The safe value of the given number or string.
*/
export function getSafeValue(value: number | string) {
const valueNumber = Number(value);
if (Number.isNaN(valueNumber)) {
return 0;
}
return valueNumber;
}
/**
* Returns the percentage of the value over the total.
* @param value - The value to calculate the percentage for.
* @param total - The total value to compare the percentage to.
* @returns The percentage of the value over the total, with the '- ' string prefixed, for example '- 50%'.
*/
export function getPercentageString(value: number, total?: number | string) {
const totalNumber = Number(total);
if (
totalNumber === 0 ||
total === undefined ||
total === '' ||
Number.isNaN(totalNumber)
) {
return '';
}
if (value > totalNumber) {
return '- Exceeded';
}
return `- ${Math.round((value / totalNumber) * 100)}%`;
}