Skip to content

Commit

Permalink
feat(vcd)(post-ga): add VDC usage tile (#13831)
Browse files Browse the repository at this point in the history
ref: MANAGER-15243

Signed-off-by: Paul Dickerson <[email protected]>
Co-authored-by: Paul Dickerson <[email protected]>
  • Loading branch information
2 people authored and chipp972 committed Nov 13, 2024
1 parent ba5d567 commit b8b4cba
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"managed_vcd_vdc_quota_value": "{{quota}} Go",
"managed_vcd_vdc_vcpu_speed": "Vitesse vCPU",
"managed_vcd_vdc_vcpu_value": "{{speed}} GHz",
"managed_vcd_vdc_id": "ID"
"managed_vcd_vdc_id": "ID",
"managed_vcd_vdc_usage": "Usage"
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,6 @@ export default function DatacentreGenerationInformationTile({
</Description>
),
},
{
id: 'cpuCount',
label: tVdc('managed_vcd_vdc_vcpu_count'),
value: (
<Description>
{vcdDatacentre?.currentState?.vCPUCount?.toString()}
</Description>
),
},
{
id: 'ramCount',
label: tVdc('managed_vcd_vdc_ram_count'),
Expand All @@ -76,17 +67,6 @@ export default function DatacentreGenerationInformationTile({
</Description>
),
},
{
id: 'vcpuSpeed',
label: tVdc('managed_vcd_vdc_vcpu_speed'),
value: (
<Description>
{tVdc('managed_vcd_vdc_vcpu_value', {
speed: vcdDatacentre?.currentState?.vCPUSpeed,
})}
</Description>
),
},
{
id: 'interface',
label: t('managed_vcd_dashboard_management_interface'),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React from 'react';
import { useTranslation } from 'react-i18next';
import {
ActionMenu,
DashboardTile,
Description,
} from '@ovh-ux/manager-react-components';
import { ODS_ICON_NAME } from '@ovhcloud/ods-components';
import IVcdDatacentre from '@/types/vcd-datacenter.interface';

type TTileProps = {
vcdDatacentre: IVcdDatacentre;
};

export default function DatacentreUsageTile({
vcdDatacentre,
}: Readonly<TTileProps>) {
const { t } = useTranslation('hpc-vmware-managed-vcd/datacentres');

return (
<div>
<DashboardTile
title={t('managed_vcd_vdc_usage')}
items={[
{
id: 'vcpuSpeed',
label: t('managed_vcd_vdc_vcpu_speed'),
value: (
<div className="flex items-center justify-between">
<Description>
{t('managed_vcd_vdc_vcpu_value', {
speed: vcdDatacentre?.currentState.vCPUSpeed,
})}
</Description>
<ActionMenu
items={[]}
icon={ODS_ICON_NAME.ELLIPSIS_VERTICAL}
isCompact
/>
</div>
),
},
{
id: 'vcpuCount',
label: t('managed_vcd_vdc_vcpu_count'),
value: (
<Description>{vcdDatacentre?.currentState.vCPUCount}</Description>
),
},
]}
/>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import React from 'react';
import { vi } from 'vitest';
import { render } from '@testing-library/react';
import {
ODS_THEME_TYPOGRAPHY_LEVEL,
ODS_THEME_TYPOGRAPHY_SIZE,
} from '@ovhcloud/ods-common-theming';
import DatacentreUsageTile from './DatacentreUsageTile.component';
import { datacentreList } from '../../../../mocks/vcd-organization/vcd-datacentre.mock';

type TTileItem = {
label: HTMLElement;
value: HTMLElement;
};

const testVDC = datacentreList[0];

vi.mock('react-i18next', () => ({
useTranslation: () => ({
t: (key: string, options: Record<string, unknown>) => {
if (key === 'managed_vcd_vdc_vcpu_value') {
return `${options.speed} GHz`;
}
return key;
},
}),
}));

describe('DatacentreUsageTile component unit test suite', () => {
it('should define all sections with correct typo', () => {
// when
const { getByText } = render(
<DatacentreUsageTile vcdDatacentre={testVDC} />,
);

// then
const usageTitle = getByText('managed_vcd_vdc_usage');
expect(usageTitle).toBeVisible();

// and
const tileItems: TTileItem[] = [
{
label: getByText('managed_vcd_vdc_vcpu_speed'),
value: getByText(`${testVDC.currentState.vCPUSpeed} GHz`),
},
{
label: getByText('managed_vcd_vdc_vcpu_count'),
value: getByText(testVDC.currentState.vCPUCount),
},
];

tileItems.forEach((item: TTileItem) => {
expect(item.label).toBeVisible();
expect(item.value).toBeVisible();

expect(item.label).toHaveAttribute(
'size',
ODS_THEME_TYPOGRAPHY_SIZE._200,
);
expect(item.label).toHaveAttribute(
'level',
ODS_THEME_TYPOGRAPHY_LEVEL.heading,
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import useManagedVcdOrganization from '@/data/hooks/useManagedVcdOrganization';
import { useManagedVcdDatacentre } from '@/data/hooks/useManagedVcdDatacentres';
import Loading from '@/components/loading/Loading.component';
import Errors from '@/components/error/Error.component';
import DatacentreUsageTile from '@/components/tiles/datacentre-usage-tile/DatacentreUsageTile.component';

export default function DatacentresGeneralInformationPage() {
const { id, vdcId } = useParams();
Expand Down Expand Up @@ -40,8 +41,9 @@ export default function DatacentresGeneralInformationPage() {
vcdDatacentre={vcdDatacentre?.data}
vcdOrganization={vcdOrganization?.data}
/>
<Outlet />
<DatacentreUsageTile vcdDatacentre={vcdDatacentre?.data} />
</div>
<Outlet />
</React.Suspense>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import OrganizationOptionsTile from '@/components/tiles/organization-options-til
import OrganizationDataProtectionTile from '@/components/tiles/organization-data-tile/OrganizationDataProtectionTile.component';
import OrganizationServiceManagementTile from '@/components/tiles/organization-service-tile/OrganizationServiceManagementTile.component';

function GeneralInformation() {
export default function GeneralInformation() {
const { id } = useParams();
const {
data: vcdOrganization,
Expand Down Expand Up @@ -47,12 +47,8 @@ function GeneralInformation() {
vcdOrganization={vcdOrganization?.data}
/>
</div>
<div>
<OrganizationServiceManagementTile />
</div>
<OrganizationServiceManagementTile />
<Outlet />
</div>
);
}

export default GeneralInformation;

0 comments on commit b8b4cba

Please sign in to comment.