Skip to content

Commit 4fc294d

Browse files
authored
Merge pull request #160 from swaroopar/feature/knip
add knip check
2 parents 18c741b + bc8ce81 commit 4fc294d

24 files changed

+8165
-3661
lines changed

.github/workflows/xpanse.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@ jobs:
1717
steps:
1818
- name: Checkout
1919
uses: actions/checkout@v3
20-
- name: Install EsLint
20+
- name: Install all required NPM packages
2121
working-directory: ./
22-
run: npm install [email protected]
22+
run: npm install
2323
- name: Run EsLint
2424
working-directory: ./
2525
run: npx eslint . --ext .js,.jsx,.ts,.tsx --config package.json --max-warnings=0
26+
- name: Run knip
27+
working-directory: ./
28+
run: npx knip
2629
- name: Run unit tests
30+
working-directory: ./
2731
run: npm run test

package-lock.json

+8,092-3,401
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+29-8
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
"@axa-fr/react-oidc": "^6.24.1",
99
"@tanstack/react-query": "^4.29.25",
1010
"antd": "^5.7.0",
11+
"echarts": "5.4.3",
1112
"echarts-for-react": "^3.0.2",
12-
"moment": "^2.29.4",
13+
"rc-menu": "~9.10.0",
14+
"rc-tabs": "12.9.0",
1315
"react": "^18.2.0",
1416
"react-dom": "^18.2.0",
1517
"react-router-dom": "^6.14.1",
1618
"react-timer-hook": "^3.0.7",
17-
"web-vitals": "^2.1.4",
1819
"yaml": "^2.2.2"
1920
},
2021
"scripts": {
@@ -37,20 +38,25 @@
3738
],
3839
"plugins": [
3940
"react",
40-
"@typescript-eslint"
41+
"@typescript-eslint",
42+
"@tanstack/query",
43+
"require-explicit-generics"
4144
],
4245
"rules": {
4346
"react/jsx-uses-react": "error",
4447
"react/jsx-uses-vars": "error",
4548
"no-undef": "off",
46-
"@typescript-eslint/no-inferrable-types": "off"
49+
"@typescript-eslint/no-inferrable-types": "off",
50+
"@tanstack/query/exhaustive-deps": "error",
51+
"@tanstack/query/prefer-query-object-syntax": "error"
4752
},
4853
"ignorePatterns": [
4954
"src/xpanse-api/**",
5055
"/public/OidcServiceWorker.js",
5156
"/public/inject.js",
5257
"build",
53-
"node_modules"
58+
"node_modules",
59+
"/public/OidcTrustedDomains.js"
5460
],
5561
"root": true,
5662
"parser": "@typescript-eslint/parser",
@@ -75,7 +81,6 @@
7581
"@tanstack/eslint-plugin-query": "^4.29.25",
7682
"@testing-library/jest-dom": "^5.16.5",
7783
"@testing-library/react": "^13.4.0",
78-
"@testing-library/user-event": "^13.5.0",
7984
"@types/jest": "^27.5.2",
8085
"@types/node": "^16.18.12",
8186
"@types/react": "^18.2.0",
@@ -84,14 +89,15 @@
8489
"@typescript-eslint/parser": "^5.59.2",
8590
"env-cmd": "^10.1.0",
8691
"eslint": "^8.45.0",
87-
"eslint-config-prettier": "^8.8.0",
92+
"eslint-config-prettier": "^9.0.0",
93+
"eslint-config-react-app": "7.0.1",
8894
"eslint-plugin-prettier": "^5.0.0",
8995
"eslint-plugin-react": "^7.32.2",
9096
"eslint-plugin-require-explicit-generics": "^0.4.2",
91-
"fork-ts-checker-webpack-plugin": "^6.5.3",
9297
"jest": "^29.6.1",
9398
"jest-environment-jsdom": "^29.6.1",
9499
"openapi-typescript-codegen": "^0.25.0",
100+
"knip": "^2.19.3",
95101
"prettier": "3.0.0",
96102
"react-scripts": "5.0.1",
97103
"ts-jest": "^29.1.1",
@@ -101,5 +107,20 @@
101107
"react-scripts": {
102108
"typescript": "^5"
103109
}
110+
},
111+
"knip": {
112+
"ignore": [
113+
"src/xpanse-api/**",
114+
"public/OidcServiceWorker.js",
115+
"public/inject.js",
116+
"src/config/index.d.ts",
117+
"src/react-app-env.d.ts",
118+
"public/OidcTrustedDomains.js"
119+
],
120+
"ignoreDependencies": [
121+
"eslint-config-prettier",
122+
"@babel/plugin-proposal-private-property-in-object",
123+
"openapi-typescript-codegen"
124+
]
104125
}
105126
}

src/components/content/catalog/services/catalogProps.ts

+1-17
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,4 @@
1-
import { Region, UserAvailableServiceVo } from '../../../../xpanse-api/generated';
2-
3-
export interface CategoryOclParam {
4-
name: string;
5-
versions: VersionOclParam[];
6-
}
7-
8-
export interface VersionOclParam {
9-
version: string;
10-
cloudProvider: ProviderOclParam[];
11-
}
12-
13-
export interface ProviderOclParam {
14-
name: UserAvailableServiceVo.csp;
15-
regions: Region[];
16-
details: UserAvailableServiceVo[];
17-
}
1+
import { UserAvailableServiceVo } from '../../../../xpanse-api/generated';
182

193
export const getServiceMapper = (
204
userAvailableServiceList: UserAvailableServiceVo[]

src/components/content/monitor/MetricChartsPerRow.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import { Select } from 'antd';
7-
import { useEffect, useState } from 'react';
7+
import React, { useEffect, useState } from 'react';
88
import { chartsPerRowCountList, chartsPerRowWithTwo } from './metricProps';
99

1010
export const MetricChartsPerRow = ({
@@ -15,7 +15,7 @@ export const MetricChartsPerRow = ({
1515
isLoading: boolean;
1616
optionLength: number;
1717
getMetricChartsPerRow: (currentMetricChartsPerRow: string) => void;
18-
}): JSX.Element => {
18+
}): React.JSX.Element => {
1919
const [chartsPerRow, setChartsPerRow] = useState<string>(chartsPerRowWithTwo);
2020
const [chartsPerRowOptions, setChartsPerRowOptions] = useState<{ value: string; label: string }[]>([]);
2121
const handleChangeChartsPerRow = (value: string) => {

src/components/content/monitor/Monitor.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* SPDX-FileCopyrightText: Huawei Inc.
44
*/
55

6-
import 'echarts/lib/chart/bar';
76
import '../../../styles/monitor.css';
87
import { MonitorOutlined } from '@ant-design/icons';
98
import { Button, Col, Empty, Form, Input, Row, Select } from 'antd';

src/components/content/monitor/MonitorChart.tsx

+11-18
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@ import {
2121
import React, { useEffect, useRef, useState } from 'react';
2222
import { MonitorMetricsType } from './MonitorMetricsType';
2323
import { ApiError, Metric, MonitorService, Response } from '../../../xpanse-api/generated';
24-
import * as echarts from 'echarts/core';
2524
import {
2625
fetchMonitorMetricDataTimeInterval,
2726
fetchOnlyLastKnownMonitorMetricDataTimeInterval,
2827
monitorMetricQueueSize,
2928
} from '../../utils/constants';
30-
import moment from 'moment';
3129
import { MetricOptionDataByChartsPerRow } from './MetricOptionDataByChartsPerRow';
3230
import { useQuery } from '@tanstack/react-query';
31+
import { EChartsCoreOption } from 'echarts';
3332

3433
export const MonitorChart = ({
3534
serviceId,
@@ -54,7 +53,7 @@ export const MonitorChart = ({
5453
) => void;
5554
getIsLoading: (isLoading: boolean) => void;
5655
getOptionLength: (optionLength: number) => void;
57-
}): JSX.Element => {
56+
}): React.JSX.Element => {
5857
const [activeMonitorMetricType, setActiveMonitorMetricType] = useState<string>(
5958
Metric.monitorResourceType.CPU.valueOf()
6059
);
@@ -68,7 +67,7 @@ export const MonitorChart = ({
6867
const [monitorMetricsQueue, setMonitorMetricsQueue] = useState<MetricQueueParams[]>([]);
6968

7069
const [chartsTitle, setChartsTitle] = useState<{ Id: string; metricTitle: string; metricSubTitle: string }[]>([]);
71-
const [options, setOptions] = useState<echarts.EChartsCoreOption[]>([]);
70+
const [options, setOptions] = useState<EChartsCoreOption[]>([]);
7271

7372
const tipMessageInfo = useRef<string>('');
7473
const tipDescriptionInfo = useRef<string[]>([]);
@@ -96,7 +95,9 @@ export const MonitorChart = ({
9695
const onlyLastKnownMetricQueryFn = () =>
9796
MonitorService.getMetrics(serviceId, undefined, undefined, undefined, undefined, undefined, true);
9897

99-
const onlyLastKnownMetricQuery = useQuery(onlyLastKnownMetricQueryKey, onlyLastKnownMetricQueryFn, {
98+
const onlyLastKnownMetricQuery = useQuery({
99+
queryKey: onlyLastKnownMetricQueryKey,
100+
queryFn: onlyLastKnownMetricQueryFn,
100101
refetchInterval: isRefreshOnlyLastKnownMetric ? fetchOnlyLastKnownMonitorMetricDataTimeInterval : false,
101102
refetchIntervalInBackground: isRefreshOnlyLastKnownMetric,
102103
refetchOnWindowFocus: false,
@@ -117,7 +118,9 @@ export const MonitorChart = ({
117118
false
118119
);
119120

120-
const monitorMetricQuery = useQuery(monitorMetricQueryKey, monitorMetricQueryFn, {
121+
const monitorMetricQuery = useQuery({
122+
queryKey: monitorMetricQueryKey,
123+
queryFn: monitorMetricQueryFn,
121124
refetchInterval: isRefreshMonitorMetric ? fetchMonitorMetricDataTimeInterval : false,
122125
refetchIntervalInBackground: isRefreshMonitorMetric,
123126
refetchOnWindowFocus: false,
@@ -294,7 +297,7 @@ export const MonitorChart = ({
294297

295298
const currentMetricProps: Map<string, MetricProps[]> = getCurrentMetricProps(metricProps);
296299
const currentChartsTitle: { Id: string; metricTitle: string; metricSubTitle: string }[] = [];
297-
const currentOptions: echarts.EChartsCoreOption[] = [];
300+
const currentOptions: EChartsCoreOption[] = [];
298301

299302
currentMetricProps.forEach((metricProps, vmId) => {
300303
currentChartsTitle.push({
@@ -308,7 +311,7 @@ export const MonitorChart = ({
308311
),
309312
metricSubTitle: metricProps[0].vmName,
310313
});
311-
const option: echarts.EChartsCoreOption = {
314+
const option: EChartsCoreOption = {
312315
tooltip: {
313316
trigger: 'axis',
314317
position: function (pt: number[]) {
@@ -320,11 +323,6 @@ export const MonitorChart = ({
320323
show: true,
321324
},
322325
},
323-
valueFormatter: function (params: number) {
324-
return `${params} ${
325-
metricProps[0].unit === Metric.unit.PERCENTAGE ? '%' : metricProps[0].unit.valueOf()
326-
}`;
327-
},
328326
},
329327
xAxis: {
330328
type: 'time',
@@ -333,11 +331,6 @@ export const MonitorChart = ({
333331
show: true,
334332
fontSize: 10,
335333
rotate: 40,
336-
formatter: function (value: Date) {
337-
const date = moment(value).format('YYYY-MM-DD');
338-
const time = moment(value).format('HH:mm:ss');
339-
return date + '\n' + time;
340-
},
341334
},
342335
axisTick: {
343336
show: true,

src/components/content/monitor/metricProps.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export interface MetricProps {
1818
timeStamp: number;
1919
}
2020

21-
export interface MetricRequestParams {
21+
interface MetricRequestParams {
2222
from: number;
2323

2424
to: number;
@@ -33,12 +33,12 @@ export interface MetricQueueParams {
3333
export const chartsPerRowCountList: string[] = ['2', '3', '4', '6', '8', '12'];
3434
export const chartsPerRowWithTwo: string = '2';
3535
export const lastMinuteRadioButtonKeyId: number = 1;
36-
export const lastHourRadioButtonKeyId: number = 2;
37-
export const threeHoursRadioButtonKeyId: number = 3;
38-
export const twelveHoursRadioButtonKeyId: number = 4;
39-
export const twentyFourHoursRadioButtonKeyId: number = 5;
40-
export const sevenDaysRadioButtonKeyId: number = 6;
41-
export const thirtyDaysRadioButtonKeyId: number = 7;
36+
const lastHourRadioButtonKeyId: number = 2;
37+
const threeHoursRadioButtonKeyId: number = 3;
38+
const twelveHoursRadioButtonKeyId: number = 4;
39+
const twentyFourHoursRadioButtonKeyId: number = 5;
40+
const sevenDaysRadioButtonKeyId: number = 6;
41+
const thirtyDaysRadioButtonKeyId: number = 7;
4242

4343
export const timePeriodList: string[] = [
4444
'Last minute',

src/components/content/order/create/CreateService.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ function CreateService(): React.JSX.Element {
113113
const [loadingError, setLoadingError] = useState<JSX.Element | undefined>(undefined);
114114

115115
const availableServicesQuery = useQuery({
116-
queryKey: ['listAvailableServices', categoryName, serviceName],
116+
queryKey: ['listAvailableServices', categoryName, serviceName, selectCsp],
117117
queryFn: () =>
118118
ServiceCatalogService.listAvailableServices(
119119
categoryName as UserAvailableServiceVo.category,

src/components/content/order/create/OrderSubmit.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ function OrderSubmit(props: OrderSubmitProps): JSX.Element {
206206
);
207207
}
208208

209-
export function OrderSubmitPage(): JSX.Element {
209+
function OrderSubmitPage(): JSX.Element {
210210
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-member-access
211211
return OrderSubmit(useLocation().state.props);
212212
}

src/components/content/order/formElements/CheckBox.tsx

-29
This file was deleted.

src/components/content/order/formElements/CommonTypes.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55

66
import { ChangeEvent } from 'react';
7-
import { CheckboxChangeEvent } from 'antd/lib/checkbox';
87
import {
98
Billing,
109
CreateRequest,
@@ -18,13 +17,8 @@ import { OrderSubmitProps } from '../create/OrderSubmit';
1817

1918
export type TextInputEventHandler = (event: ChangeEvent<HTMLInputElement>) => void;
2019
export type NumberInputEventHandler = (value: number | string | null) => void;
21-
export type CheckBoxOnChangeHandler = (e: CheckboxChangeEvent) => void;
2220
export type SwitchOnChangeHandler = (checked: boolean) => void;
23-
export type ParamOnChangeHandler =
24-
| TextInputEventHandler
25-
| NumberInputEventHandler
26-
| CheckBoxOnChangeHandler
27-
| SwitchOnChangeHandler;
21+
export type ParamOnChangeHandler = TextInputEventHandler | NumberInputEventHandler | SwitchOnChangeHandler;
2822

2923
export interface DeployParam {
3024
name: string;

src/components/content/order/formElements/CspLogo.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import AWSLogo from '../../../../img/Aws_Logo.png';
55
import OpenStackLogo from '../../../../img/OpenStack_Logo.png';
66
import GoogleLogo from '../../../../img/Google_Logo.png';
77
import FlexibleEngineLogo from '../../../../img/FlexibleEngine_Logo.png';
8-
import XpanseLogo from '../../../../img/Eclipse_Xpanse_Logo.png';
98
import ScsLogo from '../../../../img/scs.png';
109

1110
export { HuaWeiLogo };
@@ -15,5 +14,4 @@ export { AWSLogo };
1514
export { OpenStackLogo };
1615
export { GoogleLogo };
1716
export { FlexibleEngineLogo };
18-
export { XpanseLogo };
1917
export { ScsLogo };

src/components/content/order/orderStatus/DeploymentFailed.tsx

-17
This file was deleted.

0 commit comments

Comments
 (0)