Skip to content

Commit

Permalink
feat(vrack-services): refactor codebase to follow best practices
Browse files Browse the repository at this point in the history
ref: MANAGER-16503

Signed-off-by: Quentin Pavy <[email protected]>
  • Loading branch information
Quentin Pavy committed Jan 6, 2025
1 parent da641d0 commit 5620f56
Show file tree
Hide file tree
Showing 86 changed files with 394 additions and 460 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PathParams } from 'msw';
import { AllowedServicesResponse, Status, Task } from '../../src/data/api.type';
import vrackServicesList from '../vrack-services/get-vrack-services.json';
import { AllowedServicesResponse, Status, Task } from '@/types';

export const getAllowedServicesResponse = (
nbEligibleVrackServices: number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { useNavigate } from 'react-router-dom';
import { handleClick } from '@ovh-ux/manager-react-components';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { ApiError } from '@ovh-ux/manager-core-api';
import { getVrackListQueryKey } from '@/data';
import { getVrackListQueryKey } from '@/data/api';
import { DeliveringMessages } from '@/components/DeliveringMessages.component';
import { MessagesContext } from './feedback-messages/Messages.context';
import { LoadingText } from './LoadingText.component';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useTranslation } from 'react-i18next';
import { ODS_THEME_COLOR_INTENT } from '@ovhcloud/ods-common-theming';
import { ODS_SPINNER_SIZE } from '@ovhcloud/ods-components';
import { OsdsSpinner, OsdsChip } from '@ovhcloud/ods-components/react';
import { ProductStatus } from '@/data';
import { ProductStatus } from '@/types';

const colorByProductStatus = {
[ProductStatus.ACTIVE]: ODS_THEME_COLOR_INTENT.success,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ProductStatusChip,
ProductStatusChipProps,
} from './ProductStatusChip.component';
import { ProductStatus } from '@/data';
import { ProductStatus } from '@/types';

const renderComponent = ({ productStatus }: ProductStatusChipProps) => {
return render(<ProductStatusChip productStatus={productStatus} />);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import { useNavigate } from 'react-router-dom';
import { OsdsLink } from '@ovhcloud/ods-components/react';
import { ODS_THEME_COLOR_INTENT } from '@ovhcloud/ods-common-theming';
import { EditButton } from './EditButton.component';
import { VrackServicesWithIAM, getDisplayName, isEditable } from '@/data';
import { urls } from '@/routes/routes.constants';
import { InfoIcon } from './InfoIcon.component';
import { isEditable, getDisplayName } from '@/utils/vrack-services';
import { VrackServicesWithIAM } from '@/types';

export type DisplayNameProps = {
isListing?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { describe, expect, it } from 'vitest';
import { render } from '@testing-library/react';
import { DisplayName } from '@/components/display-name/DisplayName.component';
import vrackServicesList from '../../../mocks/vrack-services/get-vrack-services.json';
import { VrackServicesWithIAM } from '@/data';
import '@testing-library/jest-dom';
import { VrackServicesWithIAM } from '@/types';

const defaultVs = vrackServicesList[0] as VrackServicesWithIAM;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
ODS_SPINNER_SIZE,
} from '@ovhcloud/ods-components';
import { useTranslation } from 'react-i18next';
import { ResourceStatus, VrackServicesWithIAM, getDisplayName } from '@/data';
import { ResourceStatus, VrackServicesWithIAM } from '@/types';
import { getDisplayName } from '@/utils/vrack-services';

export type InfoInconProps = {
className?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ import {
} from '@ovhcloud/ods-components';
import { ODS_THEME_COLOR_INTENT } from '@ovhcloud/ods-common-theming';
import { useTranslation } from 'react-i18next';
import {
useVrackServicesList,
ResourceStatus,
VrackServicesWithIAM,
getDisplayName,
} from '@/data';
import { useVrackServicesList } from '@/data/hooks';
import { ResourceStatus, VrackServicesWithIAM } from '@/types';
import { getDisplayName } from '@/utils/vrack-services';

const shouldDisplayMessage = (vs: VrackServicesWithIAM) =>
vs.resourceStatus !== ResourceStatus.READY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { ApiError, ApiResponse } from '@ovh-ux/manager-core-api';
import { UseQueryResult } from '@tanstack/react-query';
import { OperationMessages } from './OperationMessages.component';
import vrackServicesList from '../../../mocks/vrack-services/get-vrack-services.json';
import { VrackServicesWithIAM, useVrackServicesList } from '@/data';
import { useVrackServicesList } from '@/data/hooks';
import { VrackServicesWithIAM } from '@/types';

/** Render */

Expand All @@ -16,8 +17,8 @@ const renderComponent = ({ id }: { id?: string }) => {
/** END RENDER */

/** MOCKS */
vi.mock('@/data', async (importOriginal) => {
const original: typeof import('@/data') = await importOriginal();
vi.mock('@/data/hooks', async (importOriginal) => {
const original: typeof import('@/data/hooks') = await importOriginal();
return {
...original,
useVrackServicesList: vi.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { OdsHTMLAnchorElementTarget } from '@ovhcloud/ods-common-core';
import { ODS_THEME_COLOR_INTENT } from '@ovhcloud/ods-common-theming';
import { MessageData, MessagesContext } from './Messages.context';
import { useVrackServicesList } from '@/data';
import { useVrackServicesList } from '@/data/hooks';

export const SuccessMessage: React.FC<Partial<MessageData>> = ({
id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { render, waitFor } from '@testing-library/react';
import { ApiError, ApiResponse } from '@ovh-ux/manager-core-api';
import { UseQueryResult } from '@tanstack/react-query';
import vrackServicesList from '../../../mocks/vrack-services/get-vrack-services.json';
import { VrackServicesWithIAM, useVrackServicesList } from '@/data';
import { useVrackServicesList } from '@/data/hooks';
import { SuccessMessages } from './SuccessMessage.component';
import { MessagesContext, MessagesContextType } from './Messages.context';
import { VrackServicesWithIAM } from '@/types';

/** Render */
const mockContextMessage = {
Expand All @@ -33,8 +34,8 @@ const renderComponent = ({ id }: { id?: string }) => {
/** END RENDER */

/** MOCKS */
vi.mock('@/data', async (importOriginal) => {
const original: typeof import('@/data') = await importOriginal();
vi.mock('@/data/hooks', async (importOriginal) => {
const original: typeof import('@/data/hooks') = await importOriginal();
return {
...original,
useVrackServicesList: vi.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ import {
DashboardLayout,
DashboardLayoutProps,
} from './DashboardLayout.component';
import { VrackServicesWithIAM, useVrackServicesList } from '@/data';
import { useVrackServicesList } from '@/data/hooks';
import vrackServicesList from '../../../mocks/vrack-services/get-vrack-services.json';
import { VrackServicesWithIAM } from '@/types';

const queryClient = new QueryClient();

vi.mock('@/data', async (importOriginal) => {
const original: typeof import('@/data') = await importOriginal();
vi.mock('@/data/hooks', async (importOriginal) => {
const original: typeof import('@/data/hooks') = await importOriginal();
return {
...original,
useVrackServicesList: vi.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { ODS_THEME_COLOR_INTENT } from '@ovhcloud/ods-common-theming';
import { OsdsLink } from '@ovhcloud/ods-components/react';
import { ActionMenu, DataGridTextCell } from '@ovh-ux/manager-react-components';
import { ShellContext } from '@ovh-ux/manager-react-shell-client';
import { VrackServicesWithIAM, isEditable } from '@/data';
import { useVrackMenuItems } from './useVrackMenuItems.hook';
import { VrackServicesWithIAM } from '@/types';
import { isEditable } from '@/utils/vrack-services';

export type VrackIdProps = { isListing?: boolean } & VrackServicesWithIAM;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
ShellContextType,
} from '@ovh-ux/manager-react-shell-client';
import { VrackId } from './VrackId.component';
import { VrackServicesWithIAM } from '@/data';
import vrackServicesList from '../../../mocks/vrack-services/get-vrack-services.json';
import { VrackServicesWithIAM } from '@/types';

const defaultVs = vrackServicesList[5] as VrackServicesWithIAM;
const vsWithoutVrack = vrackServicesList[0] as VrackServicesWithIAM;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import {
useOvhTracking,
} from '@ovh-ux/manager-react-shell-client';
import { useNavigate } from 'react-router-dom';
import { VrackServicesWithIAM, isEditable } from '@/data';
import { urls } from '@/routes/routes.constants';
import { VrackServicesWithIAM } from '@/types';
import { isEditable } from '@/utils/vrack-services';

export type UseVrackMenuItemsParams = {
vs: VrackServicesWithIAM;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { apiClient } from '@ovh-ux/manager-core-api';
import { VrackTask } from './vrack.type';
import { VrackTask } from '@/types';

export type DissociateVrackServicesParams = {
/** The internal name of your vrack */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './dissociateVrackServicesFromVrack';
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { apiClient } from '@ovh-ux/manager-core-api';
import { EligibleManagedService } from '@/types';

export const getEligibleManagedServiceListQueryKey = (
vrackServicesId: string,
) => [`get/vrackServices/resource/${vrackServicesId}/eligibleManagedService`];

/**
* List all managed services eligible to the requested vRack Services
*/
export const getEligibleManagedServiceList = async (vrackServicesId: string) =>
apiClient.v2.get<EligibleManagedService[]>(
`/vrackServices/resource/${vrackServicesId}/eligibleManagedService`,
);
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { apiClient } from '@ovh-ux/manager-core-api';
import { IAMResource } from './iam.type';
import { IAMResource } from '@/types';

export const getIamResourceQueryKey = (resourceURNList: string[]) => [
`get/iam/resource/${resourceURNList.join(',')}`,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export * from './vrackServicesResource';
export * from './vrackServicesResourceList';
export * from './iamResource';
export * from './elegibleManagedServiceList';
export * from './vrackList';
export * from './vrackAllowedServices';
export * from './vrackServicesReferenceRegionList';
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { apiClient } from '@ovh-ux/manager-core-api';
import {
AllowedServicesResponse,
GetVrackAllowedServicesParams,
} from '@/types';

export const getVrackAllowedServicesQueryKey = ({
vrack,
serviceFamily,
}: GetVrackAllowedServicesParams) => [
`get/vrack/${vrack}/allowedServices${serviceFamily || ''}`,
];

/**
* allowedServices operations : List all services allowed in this vrack
*/
export const getVrackAllowedServices = async ({
vrack,
serviceFamily,
}: GetVrackAllowedServicesParams) =>
apiClient.v6.get<AllowedServicesResponse>(
`/vrack/${vrack}/allowedServices${
serviceFamily ? `?serviceFamily=${serviceFamily}` : ''
}`,
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { apiClient } from '@ovh-ux/manager-core-api';

export const getVrackListQueryKey = ['get/vrack'];

export const getVrackList = () => apiClient.v6.get<string[]>('/vrack');
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { apiClient } from '@ovh-ux/manager-core-api';
import { Region } from '@/types';

export const getvrackServicesReferenceRegionListQueryKey = [
'get/vrackServices/reference/region',
];

/**
* List all vRack Services regions
*/
export const getvrackServicesReferenceRegionList = () =>
apiClient.v2.get<Region[]>('/vrackServices/reference/region');
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { apiClient } from '@ovh-ux/manager-core-api';
import { VrackServicesWithIAM } from '@/types';

export const getVrackServicesResourceQueryKey = (vrackServicesId: string) => [
`get/vrackServices/resource/${vrackServicesId}`,
];

/**
* Get the vRack Services
*/
export const getVrackServicesResource = async (vrackServicesId: string) =>
apiClient.v2.get<VrackServicesWithIAM>(
`/vrackServices/resource/${vrackServicesId}`,
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { apiClient } from '@ovh-ux/manager-core-api';
import {
GetVrackServicesResourceListParams,
VrackServicesWithIAM,
} from '@/types';

export const getVrackServicesResourceListQueryKey = [
'get/vrackServices/resource',
];

/**
* Operations on vRack Services : List all vRack Services
*/
export const getVrackServicesResourceList = async ({
cursor,
}: GetVrackServicesResourceListParams = {}) =>
apiClient.v2.get<VrackServicesWithIAM[]>('/vrackServices/resource', {
headers: {
'X-Pagination-Cursor': cursor,
},
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from './get';
export * from './put';
export * from './post';
export * from './delete';
export * from './vrack.type';
export * from './hooks';
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { apiClient } from '@ovh-ux/manager-core-api';
import { Task } from '../api.type';

export type AssociateVrackServicesParams = {
/** The internal name of your vrack */
vrack: string;
/** vrackServices service name */
vrackServices: string;
};
import { AssociateVrackServicesParams, Task } from '@/types';

export const associateVrackServicesQueryKey = (vrackServicesId: string) => [
`associateVrackServices-${vrackServicesId}`,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './associateVrackServices';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './updateVrackServices';
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { apiClient } from '@ovh-ux/manager-core-api';
import {
UpdateVrackServicesParams,
VrackServices,
} from './vrack-services.type';
import { UpdateVrackServicesParams, VrackServices } from '@/types';

export const updateVrackServicesQueryKey = (vrackServicesId: string) => [
'put/vrackServices/resource',
Expand Down
8 changes: 8 additions & 0 deletions packages/manager/apps/vrack-services/src/data/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export * from './useVrackServicesList';
export * from './useVrackServices';
export * from './useUpdateVrackServices';
export * from './useServiceList';
export * from './useAssociateVrack';
export * from './useDissociateVrack';
export * from './useAllowedVrackList';
export * from './useVrackList';
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { UseQueryOptions, useQueries, useQuery } from '@tanstack/react-query';
import { ApiError, ApiResponse } from '@ovh-ux/manager-core-api';
import {
getVrackList,
getVrackListQueryKey,
getVrackAllowedServices,
getVrackAllowedServicesQueryKey,
} from '../get';
import { AllowedServicesResponse } from '../../api.type';
getVrackList,
getVrackListQueryKey,
} from '@/data/api';
import { AllowedServicesResponse } from '@/types';

/**
* @returns List of allowed vRack to be associated to a vRack Services
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import React from 'react';
import { useTask } from '@ovh-ux/manager-react-components';
import { useMutation } from '@tanstack/react-query';
import { ApiError, ApiResponse } from '@ovh-ux/manager-core-api';
import { Task } from '../../api.type';
import { Task } from '@/types';
import {
associateVrackServices,
associateVrackServicesQueryKey,
} from '../post';
} from '@/data/api';

export type UseAssociateVrackParams = {
vrackServicesId: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import React from 'react';
import { useTask } from '@ovh-ux/manager-react-components';
import { useMutation } from '@tanstack/react-query';
import { ApiError, ApiResponse } from '@ovh-ux/manager-core-api';
import { VrackTask } from '../vrack.type';
import { useVrackService } from '@/data/hooks';
import { VrackTask } from '@/types';
import {
dissociateVrackServices,
dissociateVrackServicesQueryKey,
} from '../delete';
import { useVrackService } from '@/data/vrack-services';
} from '@/data/api';

export type UseDissociateVrackParams = {
vrackServicesId: string;
Expand Down
Loading

0 comments on commit 5620f56

Please sign in to comment.