-
Notifications
You must be signed in to change notification settings - Fork 593
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11135 from jerolimov/bz2009345-4.7
[release-4.7] Bug 2060451: Fix a crash when the preferred namespace contains just numbers
- Loading branch information
Showing
4 changed files
with
50 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
frontend/packages/console-app/src/components/detect-namespace/useLastNamespace.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { | ||
LAST_NAMESPACE_NAME_USER_SETTINGS_KEY, | ||
LAST_NAMESPACE_NAME_LOCAL_STORAGE_KEY, | ||
} from '@console/shared/src/constants'; | ||
import { useUserSettingsCompatibility } from '@console/shared/src/hooks/useUserSettingsCompatibility'; | ||
|
||
export const useLastNamespace = (): [ | ||
string, | ||
React.Dispatch<React.SetStateAction<string>>, | ||
boolean, | ||
] => { | ||
const [lastNamespace, setLastNamespace, lastNamespaceLoaded] = useUserSettingsCompatibility< | ||
string | ||
>(LAST_NAMESPACE_NAME_USER_SETTINGS_KEY, LAST_NAMESPACE_NAME_LOCAL_STORAGE_KEY); | ||
|
||
// This toString is workaround because the useUserSettings hook returns a number or boolean | ||
// when the saved value represents a number (1234) or boolean (true/false). | ||
// This is a workaround for https://bugzilla.redhat.com/show_bug.cgi?id=2009345. | ||
// We will implement a more generic fix with https://issues.redhat.com/browse/ODC-6514 | ||
return [lastNamespace?.toString(), setLastNamespace, lastNamespaceLoaded]; | ||
}; |
22 changes: 22 additions & 0 deletions
22
...d/packages/console-app/src/components/user-preferences/namespace/usePreferredNamespace.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Dispatch, SetStateAction } from 'react'; | ||
import { useUserSettingsCompatibility } from '@console/shared'; | ||
|
||
const PREFERRED_NAMESPACE_USER_SETTING_KEY: string = 'console.namespace.favorite'; | ||
const PREFERRED_NAMESPACE_NAME_LOCAL_STORAGE_KEY = 'dropdown-storage-namespaces'; | ||
|
||
export const usePreferredNamespace = (): [string, Dispatch<SetStateAction<string>>, boolean] => { | ||
const [ | ||
preferredNamespace, | ||
setPreferredNamespace, | ||
preferredNamespaceLoaded, | ||
] = useUserSettingsCompatibility<string>( | ||
PREFERRED_NAMESPACE_USER_SETTING_KEY, | ||
PREFERRED_NAMESPACE_NAME_LOCAL_STORAGE_KEY, | ||
); | ||
|
||
// This toString is workaround because the useUserSettings hook returns a number or boolean | ||
// when the saved value represents a number (1234) or boolean (true/false). | ||
// This is a workaround for https://bugzilla.redhat.com/show_bug.cgi?id=2009345. | ||
// We will implement a more generic fix with https://issues.redhat.com/browse/ODC-6514 | ||
return [preferredNamespace?.toString(), setPreferredNamespace, preferredNamespaceLoaded]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters