Skip to content

Commit 3f3cfb9

Browse files
authored
chore: Fix eslint error react purity (#4428)
* fix eslint error react purity * Update eslint.config.ts
1 parent 13164fb commit 3f3cfb9

File tree

5 files changed

+19
-23
lines changed

5 files changed

+19
-23
lines changed

eslint.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export default defineConfig(
3838
'react-hooks/set-state-in-effect': 'warn',
3939
'react-hooks/preserve-manual-memoization': 'warn',
4040
'react-hooks/immutability': 'warn',
41-
'react-hooks/purity': 'warn',
4241
'react-hooks/use-memo': 'warn',
4342

4443
// TypeScript

src/shared/components/CertificateDate/CertificateDate.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import { useTranslation } from 'react-i18next';
22
import { FormattedDatetime } from 'shared/components/FormattedDate/FormattedDate';
33
import { Tooltip } from 'shared/components/Tooltip/Tooltip';
44
import { Icon } from '@ui5/webcomponents-react';
5+
import useDateNow from 'shared/hooks/dateNow';
56

67
export function CertificateDate({ date, lang }) {
78
const { t } = useTranslation();
8-
const currentDate = Date.now();
9+
const currentDate = useDateNow(10_000);
910
const dayInMilliseconds = 1000 * 60 * 60 * 24;
1011
const dateDifference = (Date.parse(date) - currentDate) / dayInMilliseconds;
1112
const EXPIRATION_LIMIT = 30;

src/shared/components/MonacoEditorESM/autocompletion/useAutocompleteWorker.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useCallback, useState } from 'react';
2-
import { Uri } from 'monaco-editor';
32
import * as monaco from 'monaco-editor';
3+
import { Uri } from 'monaco-editor';
44
import { configureMonacoYaml } from 'monaco-yaml';
55
import { useGetSchema } from 'hooks/useGetSchema';
66
import YamlWorker from './yaml.worker.js?worker';
@@ -33,7 +33,8 @@ export function useAutocompleteWorker({
3333
readOnly,
3434
schema: predefinedSchema,
3535
}) {
36-
const [schemaId] = useState(predefinedSchemaId || Math.random().toString());
36+
const [randomID] = useState(() => Math.random().toString());
37+
const [schemaId] = useState(predefinedSchemaId || randomID);
3738
// Use schemaId for URI to ensure same resource types share the same schema URI
3839
const schemaUri = `file://kubernetes.io/${schemaId}`;
3940

src/shared/hooks/dateNow.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { useEffect, useState } from 'react';
2+
3+
export default function useDateNow(refreshInterval: number = 1_000) {
4+
const [time, setTime] = useState(() => Date.now());
5+
useEffect(() => {
6+
const handler = () => {
7+
const timeNow = Date.now();
8+
setTime(timeNow);
9+
};
10+
const interval = setInterval(handler, refreshInterval);
11+
return () => clearInterval(interval);
12+
});
13+
return time;
14+
}

tests/integration/fixtures/module-templates-crd.yaml

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -460,22 +460,3 @@ spec:
460460
jsonPath: .metadata.creationTimestamp
461461
conversion:
462462
strategy: None
463-
status:
464-
conditions:
465-
- type: NamesAccepted
466-
status: 'True'
467-
lastTransitionTime: '2025-02-28T11:14:56Z'
468-
reason: NoConflicts
469-
message: no conflicts found
470-
- type: Established
471-
status: 'True'
472-
lastTransitionTime: '2025-02-28T11:14:56Z'
473-
reason: InitialNamesAccepted
474-
message: the initial names have been accepted
475-
acceptedNames:
476-
plural: moduletemplates
477-
singular: moduletemplate
478-
kind: ModuleTemplate
479-
listKind: ModuleTemplateList
480-
storedVersions:
481-
- v1beta2

0 commit comments

Comments
 (0)