Skip to content

Commit 6f5bf13

Browse files
committed
refactor(pci-project): fix linter issues
ref: #MANAGER-20320 Signed-off-by: Fabien Henon <[email protected]>
1 parent fa96b64 commit 6f5bf13

File tree

15 files changed

+81
-35
lines changed

15 files changed

+81
-35
lines changed

packages/manager/apps/pci-project/src/components/activation-guard/ActivationGuard.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { lazy, useMemo } from 'react';
33
import { isDiscoveryProject, useProject } from '@ovh-ux/manager-pci-common';
44
import { RedirectionGuard } from '@ovh-ux/manager-react-components';
55

6+
import { TProject } from '@/types/pci-common.types';
7+
68
const ActivatePage = lazy(() => import('@/pages/detail/activate/Activate.page'));
79

810
/**
@@ -12,13 +14,18 @@ const ActivatePage = lazy(() => import('@/pages/detail/activate/Activate.page'))
1214
* @returns RedirectionGuard component with ActivatePage as child
1315
*/
1416
export default function ActivationGuard() {
15-
const { data: project, isLoading } = useProject();
17+
const { data: project, isLoading } = (
18+
useProject as unknown as () => {
19+
data: TProject | undefined;
20+
isLoading: boolean;
21+
}
22+
)();
1623

1724
const isAlreadyActivated = useMemo(() => {
1825
if (!project) {
1926
return false;
2027
}
21-
return !isDiscoveryProject(project);
28+
return !(isDiscoveryProject as (project: TProject) => boolean)(project);
2229
}, [project]);
2330

2431
return (

packages/manager/apps/pci-project/src/components/activation-guard/__tests__/ActivationGuard.spec.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Navigate } from 'react-router-dom';
22

33
import { UseQueryResult } from '@tanstack/react-query';
44
import { render, screen, waitFor } from '@testing-library/react';
5-
import { beforeEach, describe, expect, it, vi } from 'vitest';
5+
import { Mock, beforeEach, describe, expect, it, vi } from 'vitest';
66

77
import { isDiscoveryProject, useProject } from '@ovh-ux/manager-pci-common';
88

@@ -12,7 +12,9 @@ import { createWrapper } from '@/wrapperRenders';
1212
import ActivationGuard from '../ActivationGuard';
1313

1414
vi.mock('@ovh-ux/manager-pci-common', async (importOriginal) => {
15-
const actual: typeof import('@ovh-ux/manager-pci-common') = await importOriginal();
15+
const actual = (await importOriginal<
16+
typeof import('@ovh-ux/manager-pci-common')
17+
>()) as unknown as Record<string, unknown>;
1618
return {
1719
...actual,
1820
useProject: vi.fn(),
@@ -38,7 +40,7 @@ describe('ActivationGuard', () => {
3840
});
3941

4042
it('should show spinner when project data is loading', () => {
41-
vi.mocked(useProject).mockReturnValue({
43+
(useProject as unknown as Mock).mockReturnValue({
4244
data: undefined,
4345
isLoading: true,
4446
} as UseQueryResult<TProject, ResponseAPIError>);
@@ -55,12 +57,12 @@ describe('ActivationGuard', () => {
5557
planCode: 'project.discovery',
5658
} as TProject;
5759

58-
vi.mocked(useProject).mockReturnValue({
60+
(useProject as unknown as Mock).mockReturnValue({
5961
data: discoveryProject,
6062
isLoading: false,
6163
} as UseQueryResult<TProject, ResponseAPIError>);
6264

63-
vi.mocked(isDiscoveryProject).mockReturnValue(true);
65+
(isDiscoveryProject as unknown as Mock).mockReturnValue(true);
6466

6567
render(<ActivationGuard />, { wrapper: createWrapper() });
6668

@@ -77,20 +79,20 @@ describe('ActivationGuard', () => {
7779
planCode: 'project.2018',
7880
} as TProject;
7981

80-
vi.mocked(useProject).mockReturnValue({
82+
(useProject as unknown as Mock).mockReturnValue({
8183
data: activatedProject,
8284
isLoading: false,
8385
} as UseQueryResult<TProject, ResponseAPIError>);
8486

85-
vi.mocked(isDiscoveryProject).mockReturnValue(false);
87+
(isDiscoveryProject as unknown as Mock).mockReturnValue(false);
8688

8789
render(<ActivationGuard />, { wrapper: createWrapper() });
8890

8991
expect(Navigate).toHaveBeenCalledWith({ to: '..' }, {});
9092
});
9193

9294
it('should not redirect when project data is undefined', async () => {
93-
vi.mocked(useProject).mockReturnValue({
95+
(useProject as unknown as Mock).mockReturnValue({
9496
data: undefined,
9597
isLoading: false,
9698
} as UseQueryResult<TProject, ResponseAPIError>);

packages/manager/apps/pci-project/src/components/project-validation-guard/ProjectValidationGuard.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import { ReactNode } from 'react';
22

3+
import { UseQueryResult } from '@tanstack/react-query';
4+
35
import { useProject } from '@ovh-ux/manager-pci-common';
46
import { RedirectionGuard } from '@ovh-ux/manager-react-components';
57

68
import { urls } from '@/routes/routes.constant';
9+
import { ResponseAPIError, TProject } from '@/types/pci-common.types';
710

811
export function ProjectValidationGuard({ children }: { children: ReactNode }) {
9-
const { isLoading, isError } = useProject();
12+
const { isLoading, isError } = (
13+
useProject as unknown as () => UseQueryResult<TProject, ResponseAPIError>
14+
)();
1015
return (
1116
<>
1217
<RedirectionGuard condition={isError} isLoading={isLoading} route={urls.root}>

packages/manager/apps/pci-project/src/hooks/home/useProjectIdInLinks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { usePciUrl } from '@ovh-ux/manager-pci-common';
99
* @returns Array of items with links containing actual project ID
1010
*/
1111
export const useProjectIdInLinks = <T extends { link?: string }>(items: T[]): T[] => {
12-
const basePciUrl = usePciUrl(); // Returns '#/pci/projects/{actualId}'
12+
const basePciUrl = (usePciUrl as unknown as () => string)(); // Returns '#/pci/projects/{actualId}'
1313

1414
return useMemo(
1515
() =>

packages/manager/apps/pci-project/src/pages/detail/activate/Activate.page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import DiscoveryVoucher from '@/pages/creation/components/voucher/DiscoveryVouch
3333
import Voucher from '@/pages/creation/components/voucher/Voucher';
3434
import { useWillPayment } from '@/pages/creation/hooks/useWillPayment';
3535
import { useWillPaymentConfig } from '@/pages/creation/hooks/useWillPaymentConfig';
36+
import { TProject } from '@/types/pci-common.types';
3637

3738
import { useProjectActivation } from './hooks/useActivateProject';
3839

@@ -56,7 +57,7 @@ export default function ActivatePage() {
5657
const user = environment.getUser();
5758
const ovhSubsidiary = user.ovhSubsidiary as OvhSubsidiary;
5859

59-
const { data: project } = useProject();
60+
const { data: project } = (useProject as unknown as () => { data: TProject | undefined })();
6061
const hrefProject = useHref('..');
6162

6263
const { mutate: orderProjectItem, data: projectItem } = useOrderProjectItem();

packages/manager/apps/pci-project/src/pages/home/Header.page.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { BaseLayout, ChangelogButton } from '@ovh-ux/manager-react-components';
2020
import { ProjectValidationGuard } from '@/components/project-validation-guard/ProjectValidationGuard';
2121
import { CHANGELOG_LINKS } from '@/constants';
2222
import { useProjectTabs } from '@/hooks/useProjectTabs';
23+
import { TProject } from '@/types/pci-common.types';
2324

2425
import QuotaAlert from './components/QuotaAlert.component';
2526

@@ -33,11 +34,16 @@ export default function ProjectHeader() {
3334
NAMESPACES.FORM,
3435
]);
3536

36-
const hrefProject = usePciUrl();
37-
const { data: project, isLoading } = useProject();
37+
const hrefProject = (usePciUrl as unknown as () => string)();
38+
const { data: project, isLoading } = (
39+
useProject as unknown as () => {
40+
data: TProject | undefined;
41+
isLoading: boolean;
42+
}
43+
)();
3844
const tabs = useProjectTabs();
3945

40-
const isDiscovery = isDiscoveryProject(project);
46+
const isDiscovery = (isDiscoveryProject as (p: TProject | undefined) => boolean)(project);
4147

4248
return (
4349
<ProjectValidationGuard>

packages/manager/apps/pci-project/src/pages/home/Home.page.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ import DocumentationTile from '@/pages/home/components/DocumentationTile.compone
1010
import Others from '@/pages/home/components/Others.component';
1111
import QuickAccess from '@/pages/home/components/QuickAccess.component';
1212
import ActivateProjectModal from '@/pages/home/components/activate-project-modal/ActivateProject';
13+
import { TProject } from '@/types/pci-common.types';
1314

1415
export default function Home() {
15-
const { data: project } = useProject();
16-
const isDiscovery = project ? isDiscoveryProject(project) : false;
16+
const { data: project } = (useProject as unknown as () => { data: TProject | undefined })();
17+
const isDiscovery = project ? (isDiscoveryProject as (p: TProject) => boolean)(project) : false;
1718

1819
return (
1920
<>

packages/manager/apps/pci-project/src/pages/home/components/QuotaAlert.component.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,26 @@ import { ShellContext } from '@ovh-ux/manager-react-shell-client';
1111
import { QUOTA_LIMIT_GUIDES } from '@/constants';
1212
import { useIsQuotaAboveThreshold, useQuotas } from '@/data/hooks/useQuota';
1313
import { useProjectIdFromParams } from '@/hooks/useProjectIdFromParams';
14+
import { TProject } from '@/types/pci-common.types';
1415

1516
export default function QuotaAlert() {
1617
const { t } = useTranslation('home');
1718
const projectId = useProjectIdFromParams();
1819

1920
const { data: quotas, isLoading } = useQuotas(projectId);
2021
const isQuotaAboveThreshold = useIsQuotaAboveThreshold(quotas ?? []);
21-
const { data: project } = useProject(projectId);
22-
const isDiscovery = isDiscoveryProject(project);
22+
const { data: project } = (
23+
useProject as unknown as (id: string | undefined) => {
24+
data: TProject | undefined;
25+
}
26+
)(projectId);
27+
const isDiscovery = (isDiscoveryProject as (p: TProject | undefined) => boolean)(project);
2328
const { ovhSubsidiary } = useContext(ShellContext).environment.getUser();
2429

2530
const quotaGuidesLink =
2631
QUOTA_LIMIT_GUIDES[ovhSubsidiary as OvhSubsidiary] || QUOTA_LIMIT_GUIDES.DEFAULT || '';
2732

28-
const hrefProject = usePciUrl();
33+
const hrefProject = (usePciUrl as unknown as () => string)();
2934
const quotaUrl = `${hrefProject}/quota`;
3035

3136
if (isLoading || !isQuotaAboveThreshold || isDiscovery) {

packages/manager/apps/pci-project/src/pages/home/components/__tests__/QuotaAlert.component.spec.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { render } from '@testing-library/react';
2-
import { beforeEach, describe, expect, it, vi } from 'vitest';
2+
import { Mock, beforeEach, describe, expect, it, vi } from 'vitest';
33

44
import { isDiscoveryProject } from '@ovh-ux/manager-pci-common';
55

@@ -35,7 +35,9 @@ vi.mock('react-i18next', async (importOriginal) => {
3535

3636
// Mock usePciUrl to return the expected URL
3737
vi.mock('@ovh-ux/manager-pci-common', async () => {
38-
const actual = await vi.importActual('@ovh-ux/manager-pci-common');
38+
const actual = (await vi.importActual<typeof import('@ovh-ux/manager-pci-common')>(
39+
'@ovh-ux/manager-pci-common',
40+
)) as unknown as Record<string, unknown>;
3941
return {
4042
...actual,
4143
usePciUrl: vi.fn(() => '#/pci/projects/123'),
@@ -66,7 +68,7 @@ describe('QuotaAlert.component', () => {
6668
isLoading,
6769
} as unknown as ReturnType<typeof useQuotas>);
6870
vi.mocked(useIsQuotaAboveThreshold).mockReturnValue(isAbove);
69-
vi.mocked(isDiscoveryProject).mockReturnValue(isDiscovery);
71+
(isDiscoveryProject as unknown as Mock).mockReturnValue(isDiscovery);
7072
};
7173

7274
it('does not render while quotas are loading', () => {
@@ -75,7 +77,7 @@ describe('QuotaAlert.component', () => {
7577
isLoading: true,
7678
} as unknown as ReturnType<typeof useQuotas>);
7779
vi.mocked(useIsQuotaAboveThreshold).mockReturnValue(false);
78-
vi.mocked(isDiscoveryProject).mockReturnValue(false);
80+
(isDiscoveryProject as unknown as Mock).mockReturnValue(false);
7981

8082
const { container } = render(<QuotaAlert />, { wrapper });
8183
expect(container.firstChild).toBeNull();
@@ -87,7 +89,7 @@ describe('QuotaAlert.component', () => {
8789
isLoading: false,
8890
} as unknown as ReturnType<typeof useQuotas>);
8991
vi.mocked(useIsQuotaAboveThreshold).mockReturnValue(false);
90-
vi.mocked(isDiscoveryProject).mockReturnValue(false);
92+
(isDiscoveryProject as unknown as Mock).mockReturnValue(false);
9193

9294
const { container } = render(<QuotaAlert />, { wrapper });
9395
expect(container.firstChild).toBeNull();
@@ -99,7 +101,7 @@ describe('QuotaAlert.component', () => {
99101
isLoading: false,
100102
} as unknown as ReturnType<typeof useQuotas>);
101103
vi.mocked(useIsQuotaAboveThreshold).mockReturnValue(true);
102-
vi.mocked(isDiscoveryProject).mockReturnValue(true);
104+
(isDiscoveryProject as unknown as Mock).mockReturnValue(true);
103105

104106
const { container } = render(<QuotaAlert />, { wrapper });
105107
expect(container.firstChild).toBeNull();

packages/manager/apps/pci-project/src/pages/home/edit/Edit.page.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@ import {
1111
useIsAValidHdsSupportLevel,
1212
useIsHdsFeatureAvailabilityEnabled,
1313
} from '@/hooks/use-hds/useHds';
14+
import { TProject } from '@/types/pci-common.types';
1415

1516
import GeneralInformationSection from './general-information-section/GeneralInformationSection';
1617
import HdsSection from './hds-section/HdsSection';
1718
import RemoveSection from './remove-section/RemoveSection';
1819

1920
export default function EditPage() {
20-
const { data: project } = useProject();
21+
const { data: project } = (useProject as unknown as () => { data: TProject | undefined })();
2122

22-
const isDiscovery = isDiscoveryProject(project);
23+
const isDiscovery = (isDiscoveryProject as (p: TProject | undefined) => boolean)(project);
2324
const isHdsFeatureAvailabilityEnabled = useIsHdsFeatureAvailabilityEnabled();
2425
const isAValidHdsSupportLevel = useIsAValidHdsSupportLevel();
2526

0 commit comments

Comments
 (0)