Skip to content

Commit c080e0f

Browse files
authored
chore: Migrate namespacesState to jotai (#4114)
* Migrate namespacesState to jotai * Remove console.log
1 parent 47b7875 commit c080e0f

File tree

4 files changed

+11
-14
lines changed

4 files changed

+11
-14
lines changed

src/header/NamespaceChooser/NamespaceChooser.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useRecoilValue } from 'recoil';
1+
import { useAtomValue } from 'jotai';
22
import { useTranslation } from 'react-i18next';
33
import { useUrl } from 'hooks/useUrl';
44
import { useMatch, useNavigate } from 'react-router';
@@ -11,7 +11,7 @@ export function NamespaceChooser() {
1111
const { t } = useTranslation();
1212
const navigate = useNavigate();
1313
const { namespaceUrl } = useUrl();
14-
const allNamespaces = useRecoilValue(namespacesState);
14+
const allNamespaces = useAtomValue(namespacesState);
1515
const { navigateSafely } = useFormNavigation();
1616

1717
const { resourceType = '' } =

src/header/NamespaceDropdown/NamespaceDropdown.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useRecoilValue } from 'recoil';
1+
import { useAtomValue } from 'jotai';
22
import { useTranslation } from 'react-i18next';
33

44
import { namespacesState } from 'state/namespacesAtom';
@@ -7,7 +7,7 @@ import { ComboBoxItem } from '@ui5/webcomponents-react';
77

88
export function NamespaceDropdown() {
99
const { t } = useTranslation();
10-
const allNamespaces = useRecoilValue(namespacesState);
10+
const allNamespaces = useAtomValue(namespacesState);
1111

1212
let namespaces = [];
1313

src/hooks/useAvailableNamespaces.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { useEffect } from 'react';
2-
import { useRecoilState, useRecoilValue } from 'recoil';
2+
import { useRecoilValue } from 'recoil';
3+
import { useAtom } from 'jotai';
4+
35
import { useGetList } from 'shared/hooks/BackendAPI/useGet';
46
import { useGetHiddenNamespaces } from 'shared/hooks/useGetHiddenNamespaces';
57
import { namespacesState } from 'state/namespacesAtom';
@@ -9,7 +11,7 @@ import { K8sResource } from 'types';
911
export function useAvailableNamespaces() {
1012
const showHiddenNamespaces = useRecoilValue(showHiddenNamespacesState);
1113
const hiddenNamespaces = useGetHiddenNamespaces();
12-
const [namespaces, setNamespaces] = useRecoilState(namespacesState);
14+
const [namespaces, setNamespaces] = useAtom(namespacesState);
1315

1416
const { data: allNamespaces, error, refetch, silentRefetch } = useGetList()(
1517
'/api/v1/namespaces',

src/state/namespacesAtom.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
import { atom, RecoilState } from 'recoil';
2-
1+
import { atom } from 'jotai';
32
export type NamespacesState = string[] | null;
43

54
const defaultValue = null;
65

7-
export const namespacesState: RecoilState<NamespacesState> = atom<
8-
NamespacesState
9-
>({
10-
key: 'namespacesState',
11-
default: defaultValue,
12-
});
6+
export const namespacesState = atom<NamespacesState>(defaultValue);
7+
namespacesState.debugLabel = 'namespacesState';

0 commit comments

Comments
 (0)