Skip to content

Commit

Permalink
Address the comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ChengYanJin committed Mar 29, 2024
1 parent 050bc6f commit 20e33ce
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 40 deletions.
18 changes: 8 additions & 10 deletions src/react/next-architecture/ui/AlertProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
useCurrentApp,
} from '@scality/module-federation';
import { useConfigRetriever, useDeployedApps } from './ConfigProvider';
import { QueryObserverResult } from 'react-query';

type PrometheusAlert = {
annotations: Record<string, string>;
Expand Down Expand Up @@ -47,26 +48,23 @@ export type FilterLabels = {
parents?: string[];
selectors?: string[];
} & { [labelName: string]: string };
const alertGlobal: any = {};

type useAlertsType = (
filters: FilterLabels,
) => Omit<QueryObserverResult<Alert[]>, '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,
alertManagerUrl,
children,
}: {
moduleExports: {
'./alerts/alertHooks': {
useAlerts: (filters: FilterLabels) => Alert[];
};
'./alerts/alertHooks': { useAlerts: useAlertsType };
};
alertManagerUrl: string;
children;
Expand Down
11 changes: 4 additions & 7 deletions src/react/ui-elements/Veeam/VeeamCapacityFormSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => (
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/react/ui-elements/Veeam/VeeamCapacityModal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('VeeamCapacityModal', () => {
render(
<VeeamCapacityModal
bucketName={bucketName}
maxCapacity="114748364800"
maxCapacity={114748364800}
status={'success'}
/>,
{
Expand Down
2 changes: 1 addition & 1 deletion src/react/ui-elements/Veeam/VeeamCapacityModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const schema = Joi.object({

type VeeamCapacityModalProps = {
bucketName: string;
maxCapacity: string;
maxCapacity: number;
status: string;
};

Expand Down
10 changes: 6 additions & 4 deletions src/react/ui-elements/Veeam/VeeamCapacityOverviewRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ export const VeeamCapacityOverviewRow = ({
const xml = veeamObject?.Body?.toString();
const regex = /<Capacity>([\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 (
Expand All @@ -58,7 +60,7 @@ export const VeeamCapacityOverviewRow = ({
) : veeamObjectStatus === 'error' ? (
'Error'
) : (
<PrettyBytes bytes={parseInt(capacity)} decimals={0} />
<PrettyBytes bytes={capacity} decimals={0} />
)}
</>
{veeamObjectStatus === 'success' && (
Expand Down
3 changes: 2 additions & 1 deletion src/react/ui-elements/Veeam/VeeamSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ export const VeeamSummary = ({
rightActions={
<Button
variant="primary"
label="Exit"
//TODO: Add flag icon in core-ui
label="Finish"
onClick={() => {
history.push(`/accounts/${accountName}/buckets/${bucketName}`);
}}
Expand Down
6 changes: 3 additions & 3 deletions src/react/ui-elements/Veeam/VeeamWelcomeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ export const VeeamWelcomeModalInternal = (
props: NavbarUpdaterComponentProps,
) => {
const { features } = useConfig();
const { isStorageManager } = useAuthGroups();
const { isStorageManager, isPlatformAdmin } = useAuthGroups();
const { accounts, status } = useAccounts();
const alerts = useAlerts({
const { alerts } = useAlerts({
alertname: TRIAL_LICENSE,
});
const isZeroAccountCreated = status === 'success' && accounts.length === 0;
Expand All @@ -41,7 +41,7 @@ export const VeeamWelcomeModalInternal = (
);
const { isNextLogin } = useNextLogin();
const isTrialLicenseModalDisplayed =
alerts.length > 0 && props.isFirstTimeLogin;
alerts?.length > 0 && props.isFirstTimeLogin && isPlatformAdmin;
/*
We display the Veeam welcome modal only if the following conditions are met:
1. Veeam feature flag is enabled
Expand Down
20 changes: 7 additions & 13 deletions src/react/ui-elements/Veeam/useCapacityUnit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,16 @@ import { unitChoices } from './VeeamConstants';
type Units = 'GiB' | 'TiB' | 'PiB';

export const useCapacityUnit = (
capacity: string,
isEightyPercentCapacity = false,
capacity: number,
): {
capacityValue: string;
capacityUnit: string;
} => {
const pBytesCapacity = prettyBytes(
isEightyPercentCapacity
? 0.8 * parseInt(capacity, 10)
: parseInt(capacity, 10),
{
locale: 'en',
binary: true,
maximumFractionDigits: 0,
},
);
const pBytesCapacity = prettyBytes(capacity, {
locale: 'en',
binary: true,
maximumFractionDigits: 0,
});
const capacityValue = pBytesCapacity.split(' ')[0];
const capacityUnit = `${unitChoices[pBytesCapacity.split(' ')[1] as Units]}`;
return { capacityValue, capacityUnit };
Expand All @@ -29,5 +23,5 @@ export const getCapacityBytes = (
capacityValue: string,
capacityUnit: string,
) => {
return (parseFloat(capacityValue) * parseInt(capacityUnit, 10)).toString();
return (parseInt(capacityValue, 10) * parseInt(capacityUnit, 10)).toString();
};

0 comments on commit 20e33ce

Please sign in to comment.