Skip to content

Commit 0c243d5

Browse files
committed
refactor(pci-project): static analysis kit
ref: #MANAGER-20320 Signed-off-by: Fabien Henon <[email protected]>
1 parent 7573dd9 commit 0c243d5

File tree

203 files changed

+5240
-5867
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

203 files changed

+5240
-5867
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,4 @@ packages/manager-wiki
5959
lint-runner.js
6060
lint-html-runner.js
6161
lint-cli.js
62+
packages/manager/apps/pci-project

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ packages/manager-ui-kit
1717
packages/manager-wiki
1818
packages/manager-tools/manager-forge-cli
1919
packages/manager-tools/manager-forge-cli/template
20+
packages/manager/apps/pci-project
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { dirname } from 'node:path';
2+
import { fileURLToPath } from 'node:url';
3+
4+
import { a11yEslintConfig } from '@ovh-ux/manager-static-analysis-kit/eslint/a11y';
5+
import {
6+
complexityJsxTsxConfig,
7+
complexityTsJsConfig,
8+
} from '@ovh-ux/manager-static-analysis-kit/eslint/complexity';
9+
import { htmlEslintConfig } from '@ovh-ux/manager-static-analysis-kit/eslint/html';
10+
import { importEslintConfig } from '@ovh-ux/manager-static-analysis-kit/eslint/imports';
11+
import { javascriptEslintConfig } from '@ovh-ux/manager-static-analysis-kit/eslint/javascript';
12+
import { checkFileEslintConfig } from '@ovh-ux/manager-static-analysis-kit/eslint/naming-conventions';
13+
import { prettierEslintConfig } from '@ovh-ux/manager-static-analysis-kit/eslint/prettier';
14+
import { reactEslintConfig } from '@ovh-ux/manager-static-analysis-kit/eslint/react';
15+
import { tailwindJsxConfig } from '@ovh-ux/manager-static-analysis-kit/eslint/tailwind-jsx';
16+
import { tanStackQueryEslintConfig } from '@ovh-ux/manager-static-analysis-kit/eslint/tanstack';
17+
import { vitestEslintConfig } from '@ovh-ux/manager-static-analysis-kit/eslint/tests';
18+
import { typescriptEslintConfig } from '@ovh-ux/manager-static-analysis-kit/eslint/typescript';
19+
20+
const __filename = fileURLToPath(import.meta.url);
21+
const __dirname = dirname(__filename);
22+
23+
export default [
24+
{
25+
files: ['**/*.ts', '**/*.tsx'],
26+
languageOptions: {
27+
parser: '@typescript-eslint/parser',
28+
parserOptions: {
29+
project: ['./tsconfig.json'],
30+
tsconfigRootDir: __dirname,
31+
},
32+
},
33+
},
34+
javascriptEslintConfig,
35+
typescriptEslintConfig,
36+
reactEslintConfig,
37+
a11yEslintConfig,
38+
htmlEslintConfig,
39+
tailwindJsxConfig,
40+
tanStackQueryEslintConfig,
41+
vitestEslintConfig,
42+
prettierEslintConfig,
43+
complexityJsxTsxConfig,
44+
complexityTsJsConfig,
45+
...importEslintConfig,
46+
...checkFileEslintConfig,
47+
{
48+
rules: {
49+
'import/no-nodejs-modules': 'off',
50+
'check-file/filename-naming-convention': 'off',
51+
'import/no-unresolved': 'off',
52+
'react/no-multi-comp': 'off',
53+
'jsx-a11y/click-events-have-key-events': 'off',
54+
'jsx-a11y/no-static-element-interactions': 'off',
55+
'no-undef': 'off',
56+
'import/named': 'off',
57+
'no-unsafe-optional-chaining': 'off',
58+
'@typescript-eslint/no-unsafe-assignment': 'off',
59+
'@typescript-eslint/no-unsafe-call': 'off',
60+
'no-redeclare': 'off',
61+
'no-dupe-else-if': 'off',
62+
'@typescript-eslint/no-unsafe-member-access': 'off',
63+
'@typescript-eslint/no-redundant-type-constituents': 'off',
64+
'@typescript-eslint/no-unsafe-argument': 'off',
65+
'@typescript-eslint/no-unsafe-return': 'off',
66+
'@typescript-eslint/require-await': 'off',
67+
},
68+
},
69+
{
70+
files: ['**/setupTests.tsx', '**/*.spec.tsx', '**/*.spec.ts'],
71+
rules: {
72+
'max-lines-per-function': 'off',
73+
'max-nested-callbacks': 'off',
74+
'max-lines': 'off',
75+
},
76+
},
77+
];

packages/manager/apps/pci-project/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
</strong>
1818
</noscript>
1919
<div id="root"></div>
20-
<script type="module" src="./src/index.tsx"></script>
20+
<script type="module" src="./src/main.tsx"></script>
2121
</body>
2222
</html>

packages/manager/apps/pci-project/package.json

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,8 @@
1414
"scripts": {
1515
"build": "tsc && vite build",
1616
"coverage": "manager-test run --coverage",
17-
"format": "run-p format:*",
18-
"format:css": "yarn run lint:css --fix",
19-
"format:html": "yarn run lint:html && prettier --parser=html --write \"**/*.html\"",
20-
"format:js": "yarn run lint:js --fix",
21-
"format:md": "yarn run lint:md --fix",
22-
"lint": "eslint ./src --ext .js,.jsx,.ts,.tsx",
23-
"lint:css": "stylelint \"**/*.{css,less,scss}\"",
24-
"lint:html": "htmlhint --ignore \"**/dist/**,**/www/**,**/coverage/**,**/screenshot/**,**/docs-api/**\" \"packages/**/*.html\"",
25-
"lint:js": "eslint --cache --quiet --format=pretty .",
26-
"lint:md": "remark -qf . && eslint --quiet --format=pretty --ext .md .",
17+
"lint:modern": "manager-lint --config eslint.config.mjs ./src",
18+
"lint:modern:fix": "manager-lint --fix --config eslint.config.mjs ./src",
2719
"start": "vite",
2820
"test": "manager-test run"
2921
},
@@ -38,7 +30,6 @@
3830
"@ovh-ux/manager-react-components": "^2.39.0",
3931
"@ovh-ux/manager-react-core-application": "*",
4032
"@ovh-ux/manager-react-shell-client": "^0.9.1",
41-
"@ovh-ux/manager-tailwind-config": "*",
4233
"@ovh-ux/request-tagger": "*",
4334
"@ovhcloud/ods-components": "^18.6.3",
4435
"@ovhcloud/ods-themes": "^18.6.3",
@@ -57,9 +48,13 @@
5748
"validator": "^13.15.15"
5849
},
5950
"devDependencies": {
60-
"@testing-library/react": "*",
51+
"@ovh-ux/manager-static-analysis-kit": "0.13.0",
52+
"@ovh-ux/manager-tailwind-config": "*",
53+
"@ovh-ux/manager-tests-setup": "0.4.7",
54+
"@ovh-ux/manager-vite-config": "0.15.0",
55+
"@tanstack/react-query-devtools": "5.51.21",
6156
"@types/validator": "^13.15.2",
62-
"@vitest/coverage-v8": "^2.1.9",
57+
"typescript": "5.9.3",
6358
"vite": "^5.3.3",
6459
"vitest": "^2.1.9"
6560
},

packages/manager/apps/pci-project/src/index.scss renamed to packages/manager/apps/pci-project/src/App.scss

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@ ods-text.font-32::part(text) {
2626
font-size: 32px;
2727
}
2828

29-
.contracts-agreements .contract-link:not(:last-child) {
30-
&::after {
31-
color: var(--ods-color-primary-500);
32-
content: ',';
33-
}
29+
.contracts-agreements .contract-link:not(:last-child)::after {
30+
color: var(--ods-color-primary-500);
31+
content: ',';
3432
}
3533
.contracts-agreements .contract-link::part(link) {
3634
padding: 0.2em;

packages/manager/apps/pci-project/src/App.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
import React, { Suspense, useEffect, useContext } from 'react';
1+
import React, { Suspense, useContext, useEffect } from 'react';
2+
3+
import { RouterProvider, createHashRouter, createRoutesFromElements } from 'react-router-dom';
4+
25
import { QueryClientProvider } from '@tanstack/react-query';
36
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
7+
48
import { ShellContext } from '@ovh-ux/manager-react-shell-client';
5-
import {
6-
RouterProvider,
7-
createHashRouter,
8-
createRoutesFromElements,
9-
} from 'react-router-dom';
10-
import Routes from './routes/routes';
11-
import queryClient from './queryClient';
9+
1210
import FullPageSpinner from './components/full-page-spinner/FullPageSpinner';
11+
import queryClient from './queryClient';
12+
import Routes from './routes/routes';
1313

1414
function App() {
1515
const { shell } = useContext(ShellContext);
1616
const router = createHashRouter(createRoutesFromElements(Routes));
1717

1818
useEffect(() => {
1919
shell.ux.hidePreloader();
20-
}, []);
20+
}, [shell.ux]);
2121

2222
return (
2323
<QueryClientProvider client={queryClient}>

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import { lazy, useMemo } from 'react';
2+
13
import { isDiscoveryProject, useProject } from '@ovh-ux/manager-pci-common';
24
import { RedirectionGuard } from '@ovh-ux/manager-react-components';
3-
import { lazy, useMemo } from 'react';
45

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

910
/**
1011
* ActivationGuard component that protects the activation page route.
@@ -13,21 +14,22 @@ const ActivatePage = lazy(() =>
1314
* @returns RedirectionGuard component with ActivatePage as child
1415
*/
1516
export default function ActivationGuard() {
16-
const { data: project, isLoading } = useProject();
17+
const { data: project, isLoading } = (
18+
useProject as unknown as () => {
19+
data: TProject | undefined;
20+
isLoading: boolean;
21+
}
22+
)();
1723

1824
const isAlreadyActivated = useMemo(() => {
1925
if (!project) {
2026
return false;
2127
}
22-
return !isDiscoveryProject(project);
28+
return !(isDiscoveryProject as (project: TProject) => boolean)(project);
2329
}, [project]);
2430

2531
return (
26-
<RedirectionGuard
27-
condition={isAlreadyActivated}
28-
route=".."
29-
isLoading={isLoading}
30-
>
32+
<RedirectionGuard condition={isAlreadyActivated} route=".." isLoading={isLoading}>
3133
<ActivatePage />
3234
</RedirectionGuard>
3335
);

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

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
import {
2-
isDiscoveryProject,
3-
ResponseAPIError,
4-
TProject,
5-
useProject,
6-
} from '@ovh-ux/manager-pci-common';
1+
import { Navigate } from 'react-router-dom';
2+
73
import { UseQueryResult } from '@tanstack/react-query';
84
import { render, screen, waitFor } from '@testing-library/react';
9-
import { Navigate } from 'react-router-dom';
10-
import { beforeEach, describe, expect, it, vi } from 'vitest';
5+
import { Mock, beforeEach, describe, expect, it, vi } from 'vitest';
6+
7+
import { isDiscoveryProject, useProject } from '@ovh-ux/manager-pci-common';
8+
9+
import { ResponseAPIError, TProject } from '@/types/pci-common.types';
1110
import { createWrapper } from '@/wrapperRenders';
12-
import ActivationGuard from './ActivationGuard';
11+
12+
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,19 +57,17 @@ 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

6769
await waitFor(() => {
68-
expect(
69-
screen.queryByTestId('redirectionGuard_spinner'),
70-
).not.toBeInTheDocument();
70+
expect(screen.queryByTestId('redirectionGuard_spinner')).not.toBeInTheDocument();
7171
expect(screen.getByTestId('activate-page')).toBeInTheDocument();
7272
expect(Navigate).not.toHaveBeenCalled();
7373
});
@@ -79,20 +79,20 @@ describe('ActivationGuard', () => {
7979
planCode: 'project.2018',
8080
} as TProject;
8181

82-
vi.mocked(useProject).mockReturnValue({
82+
(useProject as unknown as Mock).mockReturnValue({
8383
data: activatedProject,
8484
isLoading: false,
8585
} as UseQueryResult<TProject, ResponseAPIError>);
8686

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

8989
render(<ActivationGuard />, { wrapper: createWrapper() });
9090

9191
expect(Navigate).toHaveBeenCalledWith({ to: '..' }, {});
9292
});
9393

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

packages/manager/apps/pci-project/src/components/contracts/Contracts.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import {
2-
OdsCheckbox,
3-
OdsFormField,
4-
OdsLink,
5-
OdsText,
6-
} from '@ovhcloud/ods-components/react';
71
import { useTranslation } from 'react-i18next';
8-
import { CartContract } from '@/data/types/cart.type';
2+
3+
import { OdsCheckbox, OdsFormField, OdsLink, OdsText } from '@ovhcloud/ods-components/react';
4+
5+
import { CartContract } from '@/data/types/Cart.type';
6+
97
import ContractsSkeleton from './ContractsSkeleton';
108

119
type ContractsProps = {
@@ -38,7 +36,7 @@ export default function Contracts({
3836
{isLoading ? (
3937
<ContractsSkeleton />
4038
) : (
41-
<ul className="flex flex-col list-none gap-[8px]">
39+
<ul className="flex list-none flex-col gap-[8px]">
4240
{contracts.map((contract) => (
4341
<li key={contract.url}>
4442
<OdsLink

0 commit comments

Comments
 (0)