Skip to content

Commit 807fab7

Browse files
committed
chore(FR-1558): refactor code related to #4404 (#4409)
This PR - removes the `--ignore-pattern '*.test.*'` flag from ESLint configuration in both `backend.ai-ui` and `react` packages, allowing test files to be properly linted. - Renames `useControllableState` to `useControllableState_deprecated` to prepare for future refactoring - Removes unused parameters and variables from various components - Adds proper React.FC type annotations to components that were missing them - Replaces a potentially unsafe optional chaining with a proper null check in ManageAppsModal - Simplifies the queryVariables in AgentList by removing unnecessary useMemo
1 parent a82d806 commit 807fab7

30 files changed

+98
-109
lines changed

packages/backend.ai-ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"test": "NODE_OPTIONS='--no-deprecation' jest",
2525
"storybook": "storybook dev -p 6006",
2626
"build-storybook": "storybook build",
27-
"lint": "eslint ./src --ignore-pattern '*.test.*' --ignore-pattern '**.graphql.**' --max-warnings=0"
27+
"lint": "eslint ./src --ignore-pattern '**.graphql.**' --max-warnings=0"
2828
},
2929
"eslintConfig": {
3030
"extends": [

react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
"eject": "react-scripts eject",
8383
"relay": "relay-compiler",
8484
"relay:watch": "nodemon --watch schema.graphql --watch client-directives.graphql --exec 'pnpm run relay --watch'",
85-
"lint": "eslint ./src '../resources/i18n/*.json' '../resources/device_metadata.json' --ignore-pattern '*.test.*' --max-warnings=0",
85+
"lint": "eslint ./src '../resources/i18n/*.json' '../resources/device_metadata.json' --max-warnings=0",
8686
"format": "pnpm dlx prettier --check 'src/**/*.{js,jsx,ts,tsx}'",
8787
"format-fix": "pnpm dlx prettier --write './src/**/*.{js,jsx,ts,tsx}'",
8888
"storybook": "storybook dev -p 6006",

react/src/components/AgentList.tsx

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import {
4646
} from 'backend.ai-ui';
4747
import dayjs from 'dayjs';
4848
import _ from 'lodash';
49-
import React, { useState, useDeferredValue, useMemo } from 'react';
49+
import React, { useState, useDeferredValue } from 'react';
5050
import { useTranslation } from 'react-i18next';
5151
import { graphql, useLazyLoadQuery } from 'react-relay';
5252
import { StringParam, useQueryParams, withDefault } from 'use-query-params';
@@ -88,22 +88,13 @@ const AgentList: React.FC<AgentListProps> = ({ tableProps }) => {
8888

8989
const [fetchKey, updateFetchKey] = useFetchKey();
9090

91-
const queryVariables = useMemo(
92-
() => ({
93-
limit: baiPaginationOption.limit,
94-
offset: baiPaginationOption.offset,
95-
filter: queryParams.filter,
96-
order: queryParams.order,
97-
status: queryParams.status,
98-
}),
99-
[
100-
baiPaginationOption.limit,
101-
baiPaginationOption.offset,
102-
queryParams.filter,
103-
queryParams.order,
104-
queryParams.status,
105-
],
106-
);
91+
const queryVariables = {
92+
limit: baiPaginationOption.limit,
93+
offset: baiPaginationOption.offset,
94+
filter: queryParams.filter,
95+
order: queryParams.order,
96+
status: queryParams.status,
97+
};
10798

10899
const deferredQueryVariables = useDeferredValue(queryVariables);
109100
const deferredFetchKey = useDeferredValue(fetchKey);

react/src/components/AnnouncementAlert.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ import Markdown from 'markdown-to-jsx';
77
import React from 'react';
88

99
interface Props extends BAIAlertProps {}
10-
const AnnouncementAlert: React.FC<Props> = ({
11-
style: _style,
12-
...otherProps
13-
}) => {
10+
const AnnouncementAlert: React.FC<Props> = ({ ...otherProps }) => {
1411
const baiClient = useSuspendedBackendaiClient();
1512
const { token } = theme.useToken();
1613
const { data: announcement } = useSuspenseTanQuery({

react/src/components/BAICodeEditor.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import useControllableState from '../hooks/useControllableState';
1+
import useControllableState_deprecated from '../hooks/useControllableState';
22
import { loadLanguage, LanguageName } from '@uiw/codemirror-extensions-langs';
33
import CodeMirror, {
44
ReactCodeMirrorProps,
@@ -23,7 +23,7 @@ const BAICodeEditor: React.FC<BAICodeEditorProps> = ({
2323
lineWrapping = false,
2424
...CodeMirrorProps
2525
}) => {
26-
const [script, setScript] = useControllableState<string>({
26+
const [script, setScript] = useControllableState_deprecated<string>({
2727
defaultValue: '',
2828
value,
2929
onChange,

react/src/components/BAIFetchKeyButton.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import useControllableState from '../hooks/useControllableState';
1+
import useControllableState_deprecated from '../hooks/useControllableState';
22
import { useInterval, useIntervalValue } from '../hooks/useIntervalValue';
33
import { ReloadOutlined } from '@ant-design/icons';
44
import { Button, ButtonProps, Tooltip } from 'antd';
@@ -19,7 +19,6 @@ interface BAIAutoRefetchButtonProps
1919
pauseWhenHidden?: boolean;
2020
}
2121
const BAIFetchKeyButton: React.FC<BAIAutoRefetchButtonProps> = ({
22-
value: _value,
2322
loading,
2423
onChange,
2524
showLastLoadTime,
@@ -31,7 +30,7 @@ const BAIFetchKeyButton: React.FC<BAIAutoRefetchButtonProps> = ({
3130
...buttonProps
3231
}) => {
3332
const { t } = useTranslation();
34-
const [lastLoadTime, setLastLoadTime] = useControllableState(
33+
const [lastLoadTime, setLastLoadTime] = useControllableState_deprecated(
3534
{
3635
value: lastLoadTimeProp,
3736
},

react/src/components/CustomizedImageList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export type CommittedImage = NonNullable<
4040
CustomizedImageListQuery$data['customized_images']
4141
>[number];
4242

43-
const CustomizedImageList = () => {
43+
const CustomizedImageList: React.FC = () => {
4444
const { t } = useTranslation();
4545
const { token } = theme.useToken();
4646
const { message } = App.useApp();

react/src/components/DynamicStepInputNumber.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useUpdatableState } from '../hooks';
2-
import useControllableState from '../hooks/useControllableState';
2+
import useControllableState_deprecated from '../hooks/useControllableState';
33
import { InputNumber, InputNumberProps } from 'antd';
44
import _ from 'lodash';
55
import React, { useEffect } from 'react';
@@ -21,9 +21,12 @@ const DynamicInputNumber: React.FC<DynamicInputNumberProps> = ({
2121
// onChange,
2222
...inputNumberProps
2323
}) => {
24-
const [value, setValue] = useControllableState<number>(inputNumberProps, {
25-
defaultValue: dynamicSteps[0],
26-
});
24+
const [value, setValue] = useControllableState_deprecated<number>(
25+
inputNumberProps,
26+
{
27+
defaultValue: dynamicSteps[0],
28+
},
29+
);
2730

2831
// FIXME: this is a workaround to fix the issue that the value is not updated when the value is controlled
2932
const [key, updateKey] = useUpdatableState('first');

react/src/components/DynamicUnitInputNumber.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { convertToBinaryUnit, parseValueWithUnit, SizeUnit } from '../helper';
2-
import useControllableState from '../hooks/useControllableState';
2+
import useControllableState_deprecated from '../hooks/useControllableState';
33
import { usePrevious } from 'ahooks';
44
import { InputNumber, InputNumberProps, Select, Typography } from 'antd';
55
import _ from 'lodash';
@@ -30,12 +30,11 @@ const DynamicUnitInputNumber: React.FC<DynamicUnitInputNumberProps> = ({
3030
roundStep,
3131
...inputNumberProps
3232
}) => {
33-
const [value, setValue] = useControllableState<string | null | undefined>(
34-
inputNumberProps,
35-
{
36-
defaultValue: '0g',
37-
},
38-
);
33+
const [value, setValue] = useControllableState_deprecated<
34+
string | null | undefined
35+
>(inputNumberProps, {
36+
defaultValue: '0g',
37+
});
3938
const [numValue, _unitFromValue] =
4039
value === null || value === undefined
4140
? [null, null]

react/src/components/DynamicUnitInputNumberWithSlider.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
toFixedFloorWithoutTrailingZeros,
55
} from '../helper';
66
import { useUpdatableState } from '../hooks';
7-
import useControllableState from '../hooks/useControllableState';
7+
import useControllableState_deprecated from '../hooks/useControllableState';
88
import DynamicUnitInputNumber, {
99
DynamicUnitInputNumberProps,
1010
} from './DynamicUnitInputNumber';
@@ -34,12 +34,11 @@ const DynamicUnitInputNumberWithSlider: React.FC<
3434
step = 0.05,
3535
...otherProps
3636
}) => {
37-
const [value, setValue] = useControllableState<string | undefined | null>(
38-
otherProps,
39-
{
40-
defaultValue: '0g',
41-
},
42-
);
37+
const [value, setValue] = useControllableState_deprecated<
38+
string | undefined | null
39+
>(otherProps, {
40+
defaultValue: '0g',
41+
});
4342
const { token } = theme.useToken();
4443
const minGiB = useMemo(() => convertToBinaryUnit(min, 'g', 2), [min]);
4544
const maxGiB = useMemo(() => convertToBinaryUnit(max, 'g', 2), [max]);

0 commit comments

Comments
 (0)