console: add comment about cloud console local storage behaviour

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/8791
GitOrigin-RevId: 988cd0b925eda34763f6d6778e271deed0cbd8f8
This commit is contained in:
Rikin Kachhia 2023-04-18 15:55:41 +05:30 committed by hasura-bot
parent 83c597987a
commit fd97471936

View File

@ -1,9 +1,22 @@
import globals from '../Globals';
/*
In Hasura cloud, console local storage functions have been monkey-patched to separate out local storage keys
based on project ids. i.e. Hasura cloud dashboard and the different project consoles and do not share the same local
storage keys.
See monkeypatch code: https://github.com/hasura/lux/blob/0845a55/services/cloud/team_console/index.html#L24-L103
To share local storage keys between different project consoles or between cloud dashboard and console, the
localstorage key needs to be added to the `GLOBAL_LS_KEYS` variable in the above file.
*/
/* IMPORTANT: for behaviour on Cloud console, see note at start of file */
export const setLSItem = (key: string, data: string) => {
window.localStorage.setItem(key, data);
};
/* IMPORTANT: for behaviour on Cloud console, see note at start of file */
export const getLSItem = (key: string) => {
if (!key) {
return null;
@ -12,22 +25,7 @@ export const getLSItem = (key: string) => {
return window.localStorage.getItem(key);
};
export const getParsedLSItem = (key: string, defaultVal: any = null) => {
const value = getLSItem(key);
if (!value) {
return defaultVal;
}
try {
const jsonValue = JSON.parse(value);
return jsonValue || defaultVal;
} catch {
return defaultVal;
}
};
/* IMPORTANT: for behaviour on Cloud console, see note at start of file */
export const removeLSItem = (key: string) => {
const value = getLSItem(key);
@ -71,6 +69,22 @@ export const getItemWithExpiry = (key: string) => {
return item.value;
};
export const getParsedLSItem = (key: string, defaultVal: any = null) => {
const value = getLSItem(key);
if (!value) {
return defaultVal;
}
try {
const jsonValue = JSON.parse(value);
return jsonValue || defaultVal;
} catch {
return defaultVal;
}
};
export const listLSKeys = () => {
return Object.keys(window.localStorage);
};