Skip to content

Commit

Permalink
feat(vcd): remove module code from vcd
Browse files Browse the repository at this point in the history
  desc: use module types, api, hooks and remove vcd duplicates

Signed-off-by: Paul Dickerson <[email protected]>
  • Loading branch information
Paul Dickerson committed Nov 15, 2024
1 parent 8e3b47f commit 18f7602
Show file tree
Hide file tree
Showing 67 changed files with 285 additions and 849 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TVcdCatalog } from '../../src/types/vcd-catalog.interface';
import { VCDCatalog } from '@ovh-ux/manager-module-vcd-api';

export const catalogProductList: TVcdCatalog = [
export const catalogProductList: VCDCatalog = [
{
productName: 'pack-3264',
mandatory: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IVdcOrderableResourceData } from '@/types/vcd-vdc-orderable-resource.interface';
import { VCDOrderableResourceData } from '@ovh-ux/manager-module-vcd-api';
import { Handler } from '../../../../../../playwright-helpers';
import { catalogProductList } from './vcd-catalog.mock';
import { orderableResourceData } from './vdc-orderable-resource.mock';
Expand All @@ -16,7 +16,7 @@ export const getDatacentreOrderMocks = ({
isOrderableResourceKO,
nbOrderableResource = Number.POSITIVE_INFINITY,
}: GetDatacentreOrderMocksParams): Handler[] => {
const selectedOrderableResource: IVdcOrderableResourceData = {
const selectedOrderableResource: VCDOrderableResourceData = {
compute: orderableResourceData.compute.slice(0, nbOrderableResource),
storage: orderableResourceData.storage.slice(0, nbOrderableResource),
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import IVcdDatacentre from '../../src/types/vcd-datacenter.interface';
import { VCDDatacentre } from '@ovh-ux/manager-module-vcd-api';

export const datacentreList: IVcdDatacentre[] = [
export const datacentreList: VCDDatacentre[] = [
{
id: 'vdc-eu-central-waw-adc311b5-0c0b-4071-b48f-b20813868bcf',
resourceStatus: 'READY',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import IVcdOrganization from '../../src/types/vcd-organization.interface';
import { VCDOrganization } from '@ovh-ux/manager-module-vcd-api';

export const organizationList: IVcdOrganization[] = [
export const organizationList: VCDOrganization[] = [
{
currentState: {
apiUrl: 'https://vcd.my.company',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import IVcdCompute from '../../src/types/vcd-compute.interface';
import { VCDCompute } from '@ovh-ux/manager-module-vcd-api';

export const computeList: IVcdCompute[] = [
export const computeList: VCDCompute[] = [
{
id: 'f578c64f-ebec-4c19-a006-c96b1c7c1b95',
resourceStatus: 'READY',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IVdcOrderableResourceData } from '../../src/types/vcd-vdc-orderable-resource.interface';
import { VCDOrderableResourceData } from '@ovh-ux/manager-module-vcd-api';

export const orderableResourceData: IVdcOrderableResourceData = {
export const orderableResourceData: VCDOrderableResourceData = {
compute: [
{
memoryQuota: 64,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import IVcdStorage from '../../src/types/vcd-storage.interface';
import { VCDStorage } from '@ovh-ux/manager-module-vcd-api';

export const storageList: IVcdStorage[] = [
export const storageList: VCDStorage[] = [
{
id: 'fccce864-e1d5-4ab8-ad6a-79ecd295f420',
resourceStatus: 'READY',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import IVcdOrganizationBackup, {
BackupResourceStatus,
} from '../../src/types/vcd-organization-backup.interface';
import { VCDOrganizationBackup } from '@ovh-ux/manager-module-vcd-api';
import { organizationList } from '../vcd-organization/vcd-organization.mock';

export const backupList: IVcdOrganizationBackup[] = [
export const backupList: VCDOrganizationBackup[] = [
{
id: `${organizationList[0].id}-veeam-backup`,
iam: {
Expand All @@ -30,7 +28,7 @@ export const backupList: IVcdOrganizationBackup[] = [
},
updatedAt: '2024-06-14T09:21:21.943Z',
createdAt: '2024-06-14T09:21:21.943Z',
resourceStatus: BackupResourceStatus.READY,
resourceStatus: 'READY',
targetSpec: {
offers: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import {
import { OsdsRadio, OsdsRadioButton } from '@ovhcloud/ods-components/react';
import { ODS_RADIO_BUTTON_SIZE } from '@ovhcloud/ods-components';
import { ODS_THEME_COLOR_INTENT } from '@ovhcloud/ods-common-theming';
import { IVdcOrderableVhostPriced } from '@/types/vcd-vdc-orderable-resource.interface';
import { VCDOrderableVhostPriced } from '@ovh-ux/manager-module-vcd-api';
import { getVdcResourcePriceLabel } from '@/utils/getPricedOrderableResource';
import { useDatacentreOrderContext } from '@/context/DatacentreOrder.context';

export const ComputeOrderSelectCell = (vHost: IVdcOrderableVhostPriced) => {
export const ComputeOrderSelectCell = (vHost: VCDOrderableVhostPriced) => {
const { selectedResource, setSelectedResource } = useDatacentreOrderContext();
return (
<DataGridTextCell>
Expand All @@ -30,11 +30,11 @@ export const ComputeOrderSelectCell = (vHost: IVdcOrderableVhostPriced) => {
);
};

export const ComputeOrderVhostCell = (vHost: IVdcOrderableVhostPriced) => (
export const ComputeOrderVhostCell = (vHost: VCDOrderableVhostPriced) => (
<DataGridTextCell>{vHost.profile}</DataGridTextCell>
);

export const ComputeOrderCpuSpeedCell = (vHost: IVdcOrderableVhostPriced) => {
export const ComputeOrderCpuSpeedCell = (vHost: VCDOrderableVhostPriced) => {
const { t } = useTranslation('hpc-vmware-managed-vcd/datacentres');
return (
<DataGridTextCell>
Expand All @@ -43,7 +43,7 @@ export const ComputeOrderCpuSpeedCell = (vHost: IVdcOrderableVhostPriced) => {
);
};

export const ComputeOrderRamCell = (vHost: IVdcOrderableVhostPriced) => {
export const ComputeOrderRamCell = (vHost: VCDOrderableVhostPriced) => {
const { t } = useTranslation('hpc-vmware-managed-vcd/datacentres/order');
return (
<DataGridTextCell>
Expand All @@ -54,11 +54,11 @@ export const ComputeOrderRamCell = (vHost: IVdcOrderableVhostPriced) => {
);
};

export const ComputeOrderCpuCountCell = (vHost: IVdcOrderableVhostPriced) => (
export const ComputeOrderCpuCountCell = (vHost: VCDOrderableVhostPriced) => (
<DataGridTextCell>{vHost.vCPUCount}</DataGridTextCell>
);

export const ComputeOrderPriceCell = (vHost: IVdcOrderableVhostPriced) => {
export const ComputeOrderPriceCell = (vHost: VCDOrderableVhostPriced) => {
const { t } = useTranslation('hpc-vmware-managed-vcd/datacentres/order');
return (
<DataGridTextCell>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import {
import { OsdsDivider } from '@ovhcloud/ods-components/react';
import React, { useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { icebergListingQueryKey } from '@ovh-ux/manager-module-vcd-api';
import Loading from '@/components/loading/Loading.component';
import TDatagridRoute from '@/types/datagrid-route.type';
import { useAutoRefetch } from '@/data/hooks/useAutoRefetch';
import {
hasResourceUpdatingTargetSpec,
UpdatableResource,
} from '@/utils/refetchConditions';
import { icebergListingQueryKey } from '@/utils/queryKeys';

export type TDatagridContainerProps = {
route: TDatagridRoute;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import {
import { OsdsRadio, OsdsRadioButton } from '@ovhcloud/ods-components/react';
import { ODS_RADIO_BUTTON_SIZE } from '@ovhcloud/ods-components';
import { ODS_THEME_COLOR_INTENT } from '@ovhcloud/ods-common-theming';
import { IVdcOrderableStoragePriced } from '@/types/vcd-vdc-orderable-resource.interface';
import { VCDOrderableStoragePriced } from '@ovh-ux/manager-module-vcd-api';
import { getVdcResourcePriceLabel } from '@/utils/getPricedOrderableResource';
import { useDatacentreOrderContext } from '@/context/DatacentreOrder.context';

export const StorageOrderSelectCell = (storage: IVdcOrderableStoragePriced) => {
export const StorageOrderSelectCell = (storage: VCDOrderableStoragePriced) => {
const { selectedResource, setSelectedResource } = useDatacentreOrderContext();
return (
<DataGridTextCell>
Expand All @@ -30,11 +30,11 @@ export const StorageOrderSelectCell = (storage: IVdcOrderableStoragePriced) => {
);
};

export const StorageOrderTypeCell = (storage: IVdcOrderableStoragePriced) => (
export const StorageOrderTypeCell = (storage: VCDOrderableStoragePriced) => (
<DataGridTextCell>{storage.name}</DataGridTextCell>
);

export const StorageOrderPriceCell = (storage: IVdcOrderableStoragePriced) => {
export const StorageOrderPriceCell = (storage: VCDOrderableStoragePriced) => {
const { t } = useTranslation('hpc-vmware-managed-vcd/datacentres/order');
return (
<DataGridTextCell>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ import {
import { OsdsButton } from '@ovhcloud/ods-components/react';
import { ODS_THEME_COLOR_INTENT } from '@ovhcloud/ods-common-theming';
import { ODS_BUTTON_SIZE, ODS_BUTTON_VARIANT } from '@ovhcloud/ods-components';
import {
useVcdCatalog,
useVcdOrder,
useVdcOrderableResource,
VCDOrderableStoragePriced,
VCDOrderableVhostPriced,
} from '@ovh-ux/manager-module-vcd-api';
import { QuantitySelector } from './QuantitySelector.component';
import { useDatacentreOrderContext } from '@/context/DatacentreOrder.context';
import { useVdcOrderableResource } from '@/data/hooks/useOrderableResource';
import { useVcdCatalog } from '@/data/hooks/useVcdCatalog';
import useVcdOrder from '@/data/hooks/useVcdOrder';
import { validateQuantity } from '@/utils/formValidation';
import { getPricedVdcResources } from '@/utils/getPricedOrderableResource';
import Loading from '../loading/Loading.component';
import {
IVdcOrderableStoragePriced,
IVdcOrderableVhostPriced,
} from '@/types/vcd-vdc-orderable-resource.interface';

type OrderType = 'compute' | 'storage';
type OrderColumns<T extends OrderType> = T extends 'compute'
? DatagridColumn<IVdcOrderableVhostPriced>[]
: DatagridColumn<IVdcOrderableStoragePriced>[];
? DatagridColumn<VCDOrderableVhostPriced>[]
: DatagridColumn<VCDOrderableStoragePriced>[];

interface DatacentreOrderProps<T extends OrderType> {
orderType: T;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React from 'react';
import { useNavigate, useParams } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import useManagedVcdOrganization from '@/data/hooks/useManagedVcdOrganization';
import { useUpdateVcdOrganizationDetails } from '@/data/hooks/useUpdateVcdOrganization';
import { IVcdOrganizationState } from '@/types/vcd-organization.interface';
import {
useVcdOrganization,
useUpdateVcdOrganizationDetails,
VCDOrganizationTargetSpec,
} from '@ovh-ux/manager-module-vcd-api';
import {
validateDescription,
validateOrganizationName,
Expand All @@ -30,7 +32,7 @@ export const UpdateDetailModalHandler = ({
const closeModal = () => navigate('..');
const { addSuccess } = useMessageContext();
const { id } = useParams();
const { data: vcdOrganization } = useManagedVcdOrganization({ id });
const { data: vcdOrganization } = useVcdOrganization({ id });
const { updateDetails, error, isError } = useUpdateVcdOrganizationDetails({
id,
onSuccess: () => {
Expand All @@ -42,7 +44,8 @@ export const UpdateDetailModalHandler = ({
closeModal();
},
});
const currentDetails: IVcdOrganizationState = vcdOrganization.data.targetSpec;
const currentDetails: VCDOrganizationTargetSpec =
vcdOrganization.data.targetSpec;

const getOrganizationDetailKey = (key: OrganizationDetailName) => {
const detailKeys: TOrganizationDetails = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ import React from 'react';
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';
import { OdsHTMLAnchorElementTarget } from '@ovhcloud/ods-common-core';
import IVcdDatacentre from '@/types/vcd-datacenter.interface';
import IVcdOrganization from '@/types/vcd-organization.interface';
import { VCDDatacentre, VCDOrganization } from '@ovh-ux/manager-module-vcd-api';
import { subRoutes } from '@/routes/routes.constant';
import { iamActions } from '@/utils/iam.constants';
import EditableTileItem from '../editable-tile-item/EditableTileItem.component';
import { capitalize } from '@/utils/capitalize';

type TTileProps = {
vcdDatacentre: IVcdDatacentre;
vcdOrganization: IVcdOrganization;
vcdDatacentre: VCDDatacentre;
vcdOrganization: VCDOrganization;
};

export default function DatacentreGenerationInformationTile({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import {
Description,
} from '@ovh-ux/manager-react-components';
import { ODS_ICON_NAME } from '@ovhcloud/ods-components';
import IVcdDatacentre from '@/types/vcd-datacenter.interface';
import { VCDDatacentre } from '@ovh-ux/manager-module-vcd-api';

type TTileProps = {
vcdDatacentre: IVcdDatacentre;
vcdDatacentre: VCDDatacentre;
};

export default function DatacentreUsageTile({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { DashboardTile } from '@ovh-ux/manager-react-components';
import { OsdsChip } from '@ovhcloud/ods-components/react';
import { ODS_THEME_COLOR_INTENT } from '@ovhcloud/ods-common-theming';
import { ODS_CHIP_SIZE } from '@ovhcloud/ods-components';
import { VCDOrganization } from '@ovh-ux/manager-module-vcd-api';
import {
DATA_PROTECTION_BACKUP_TITLE,
DATA_PROTECTION_RECOVERY_TITLE,
} from '@/pages/dashboard/organization/OrganizationDashboard.constants';
import BackupTileItem from './backup-tile-item/BackupTileItem.component';
import IVcdOrganization from '@/types/vcd-organization.interface';

type TTileProps = {
vcdOrganization: IVcdOrganization;
vcdOrganization: VCDOrganization;
};

export default function DataProtectionTile({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@ import {
ShellContext,
ShellContextType,
} from '@ovh-ux/manager-react-shell-client';
import {
ResourceStatus,
useVeeamBackup,
VeeamBackupWithIam,
} from '@ovh-ux/manager-module-vcd-api';
import OrganizationDataProtectionTile from './OrganizationDataProtectionTile.component';
import { useManagedVcdOrganizationBackup } from '../../../data/hooks/useManagedVcdOrganization';
import IVcdOrganizationBackup, {
BackupResourceStatus,
} from '../../../types/vcd-organization-backup.interface';
import { organizationList } from '../../../../mocks/vcd-organization/vcd-organization.mock';

vi.mock('../../../data/hooks/useManagedVcdOrganization', () => ({
useManagedVcdOrganizationBackup: vi.fn(),
vi.mock('@ovh-ux/manager-module-vcd-api', () => ({
useVeeamBackup: vi.fn(),
getBackupIdFromOrganization: vi.fn(),
}));
vi.mocked(useManagedVcdOrganizationBackup).mockReturnValue(
{} as UseQueryResult<ApiResponse<IVcdOrganizationBackup>, ApiError>,
vi.mocked(useVeeamBackup).mockReturnValue(
{} as UseQueryResult<ApiResponse<VeeamBackupWithIam>, ApiError>,
);

const shellContext = {
Expand Down Expand Up @@ -88,9 +90,9 @@ describe('OrganizationDataProtectionTile component unit test suite', () => {

describe('OrganizationDataProtectionTile query state-based behavior unit test suite', () => {
it('should display backupLoading when query isLoading', async () => {
vi.mocked(useManagedVcdOrganizationBackup).mockReturnValue({
vi.mocked(useVeeamBackup).mockReturnValue({
isLoading: true,
} as UseQueryResult<ApiResponse<IVcdOrganizationBackup>, ApiError>);
} as UseQueryResult<ApiResponse<VeeamBackupWithIam>, ApiError>);

// when
await act(async () => renderComponent());
Expand All @@ -101,9 +103,9 @@ describe('OrganizationDataProtectionTile query state-based behavior unit test su
});

it('should display backupError when query isError', async () => {
vi.mocked(useManagedVcdOrganizationBackup).mockReturnValue({
vi.mocked(useVeeamBackup).mockReturnValue({
isError: true,
} as UseQueryResult<ApiResponse<IVcdOrganizationBackup>, ApiError>);
} as UseQueryResult<ApiResponse<VeeamBackupWithIam>, ApiError>);

// when
await act(async () => renderComponent());
Expand All @@ -116,10 +118,10 @@ describe('OrganizationDataProtectionTile query state-based behavior unit test su
});

it('should display noBackup when query isError 404', async () => {
vi.mocked(useManagedVcdOrganizationBackup).mockReturnValue({
vi.mocked(useVeeamBackup).mockReturnValue({
isError: true,
error: { response: { status: 404 } },
} as UseQueryResult<ApiResponse<IVcdOrganizationBackup>, ApiError>);
} as UseQueryResult<ApiResponse<VeeamBackupWithIam>, ApiError>);

// when
await act(async () => renderComponent());
Expand All @@ -130,11 +132,11 @@ describe('OrganizationDataProtectionTile query state-based behavior unit test su
});

it('should display backupStatus when query isSuccess', async () => {
const testStatus = BackupResourceStatus.CREATING;
vi.mocked(useManagedVcdOrganizationBackup).mockReturnValue({
const testStatus: ResourceStatus = 'READY';
vi.mocked(useVeeamBackup).mockReturnValue({
isSuccess: true,
data: { data: { resourceStatus: testStatus } },
} as UseQueryResult<ApiResponse<IVcdOrganizationBackup>, ApiError>);
} as UseQueryResult<ApiResponse<VeeamBackupWithIam>, ApiError>);

// when
await act(async () => renderComponent());
Expand Down
Loading

0 comments on commit 18f7602

Please sign in to comment.