diff --git a/src/react/next-architecture/ui/AlertProvider.tsx b/src/react/next-architecture/ui/AlertProvider.tsx index f290370a0..205252553 100644 --- a/src/react/next-architecture/ui/AlertProvider.tsx +++ b/src/react/next-architecture/ui/AlertProvider.tsx @@ -7,6 +7,7 @@ import { useCurrentApp, } from '@scality/module-federation'; import { useConfigRetriever, useDeployedApps } from './ConfigProvider'; +import { QueryObserverResult } from 'react-query'; type PrometheusAlert = { annotations: Record; @@ -47,16 +48,15 @@ export type FilterLabels = { parents?: string[]; selectors?: string[]; } & { [labelName: string]: string }; -const alertGlobal: any = {}; + +type useAlertsType = ( + filters: FilterLabels, +) => Omit, 'data'> & { alerts?: Alert[] }; +const alertGlobal: { hooks?: { useAlerts: useAlertsType } } = {}; + export const useAlerts = (filters: FilterLabels) => { return alertGlobal.hooks.useAlerts(filters); }; -export const useHighestSeverityAlerts = (filters: FilterLabels) => { - return alertGlobal.hooks?.useHighestSeverityAlerts(filters); -}; -export const useAlertLibrary = () => { - return alertGlobal.hooks; -}; const InternalAlertProvider = ({ moduleExports, @@ -64,9 +64,7 @@ const InternalAlertProvider = ({ children, }: { moduleExports: { - './alerts/alertHooks': { - useAlerts: (filters: FilterLabels) => Alert[]; - }; + './alerts/alertHooks': { useAlerts: useAlertsType }; }; alertManagerUrl: string; children; diff --git a/src/react/ui-elements/Veeam/VeeamCapacityFormSection.tsx b/src/react/ui-elements/Veeam/VeeamCapacityFormSection.tsx index 7ac92c334..7f1c4903f 100644 --- a/src/react/ui-elements/Veeam/VeeamCapacityFormSection.tsx +++ b/src/react/ui-elements/Veeam/VeeamCapacityFormSection.tsx @@ -18,13 +18,13 @@ type XCoreConfig = { }; }; }; - +type ClusterCapacityStatus = 'idle' | 'loading' | 'success' | 'error'; type UseClusterCapacityHooks = ( xCoreConfig: XCoreConfig, token?: string, ) => { - clusterCapacity: string | undefined; - clusterCapacityStatus: string; + clusterCapacity: number; + clusterCapacityStatus: ClusterCapacityStatus; }; const VeeamCapacityTooltip = () => ( @@ -56,12 +56,9 @@ export const VeeamCapacityFormWithXcore = ({ token, ); const { setValue } = useFormContext(); - const { capacityValue, capacityUnit } = useCapacityUnit( - clusterCapacity || '0', - true, + clusterCapacityStatus === 'success' ? clusterCapacity * 0.8 : 0, ); - useEffect(() => { if (clusterCapacityStatus === 'success') { setValue('capacity', capacityValue); diff --git a/src/react/ui-elements/Veeam/VeeamCapacityModal.test.tsx b/src/react/ui-elements/Veeam/VeeamCapacityModal.test.tsx index 93b686cfe..1c6d0f048 100644 --- a/src/react/ui-elements/Veeam/VeeamCapacityModal.test.tsx +++ b/src/react/ui-elements/Veeam/VeeamCapacityModal.test.tsx @@ -38,7 +38,7 @@ describe('VeeamCapacityModal', () => { render( , { diff --git a/src/react/ui-elements/Veeam/VeeamCapacityModal.tsx b/src/react/ui-elements/Veeam/VeeamCapacityModal.tsx index ae0b55ca8..8a88240b3 100644 --- a/src/react/ui-elements/Veeam/VeeamCapacityModal.tsx +++ b/src/react/ui-elements/Veeam/VeeamCapacityModal.tsx @@ -30,7 +30,7 @@ const schema = Joi.object({ type VeeamCapacityModalProps = { bucketName: string; - maxCapacity: string; + maxCapacity: number; status: string; }; diff --git a/src/react/ui-elements/Veeam/VeeamCapacityOverviewRow.tsx b/src/react/ui-elements/Veeam/VeeamCapacityOverviewRow.tsx index 8df389382..d55f2fd6d 100644 --- a/src/react/ui-elements/Veeam/VeeamCapacityOverviewRow.tsx +++ b/src/react/ui-elements/Veeam/VeeamCapacityOverviewRow.tsx @@ -40,12 +40,14 @@ export const VeeamCapacityOverviewRow = ({ const xml = veeamObject?.Body?.toString(); const regex = /([\s\S]*?)<\/Capacity>/; const matches = xml?.match(regex); - const capacity = + const capacity = parseInt( new DOMParser() ?.parseFromString(xml || '', 'application/xml') ?.querySelector('Capacity')?.textContent || - matches?.[1] || - '0'; + matches?.[1] || + '0', + 10, + ); if (isSOSAPIEnabled) { return ( @@ -58,7 +60,7 @@ export const VeeamCapacityOverviewRow = ({ ) : veeamObjectStatus === 'error' ? ( 'Error' ) : ( - + )} {veeamObjectStatus === 'success' && ( diff --git a/src/react/ui-elements/Veeam/VeeamSummary.tsx b/src/react/ui-elements/Veeam/VeeamSummary.tsx index b5f4e50f3..65b6a372e 100644 --- a/src/react/ui-elements/Veeam/VeeamSummary.tsx +++ b/src/react/ui-elements/Veeam/VeeamSummary.tsx @@ -78,7 +78,8 @@ export const VeeamSummary = ({ rightActions={