mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-17 13:55:59 +08:00
fix(BUG): localstorage permission is updated (#477)
This commit is contained in:
parent
bbbb1c1d60
commit
ba0f06f381
@ -1,5 +1,10 @@
|
|||||||
const get = (key: string): string | null => {
|
const get = (key: string): string | null => {
|
||||||
return localStorage.getItem(key);
|
try {
|
||||||
|
const value = localStorage.getItem(key);
|
||||||
|
return value;
|
||||||
|
} catch (e) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default get;
|
export default get;
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
const remove = (key: string): void => {
|
const remove = (key: string): boolean => {
|
||||||
window.localStorage.removeItem(key);
|
try {
|
||||||
|
window.localStorage.removeItem(key);
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default remove;
|
export default remove;
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
const set = (key: string, value: string): void => {
|
const set = (key: string, value: string): boolean => {
|
||||||
localStorage.setItem(key, value);
|
try {
|
||||||
|
localStorage.setItem(key, value);
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default set;
|
export default set;
|
||||||
|
@ -4,8 +4,8 @@ import React, { useCallback, useEffect, useState } from 'react';
|
|||||||
import { getDefaultOption, getOptions, Time } from './config';
|
import { getDefaultOption, getOptions, Time } from './config';
|
||||||
import { Container, Form, FormItem } from './styles';
|
import { Container, Form, FormItem } from './styles';
|
||||||
const { Option } = DefaultSelect;
|
const { Option } = DefaultSelect;
|
||||||
import get from 'api/browser/localstorage/get';
|
import getLocalStorageKey from 'api/browser/localstorage/get';
|
||||||
import set from 'api/browser/localstorage/set';
|
import setLocalStorageKey from 'api/browser/localstorage/set';
|
||||||
import { LOCAL_STORAGE } from 'constants/localStorage';
|
import { LOCAL_STORAGE } from 'constants/localStorage';
|
||||||
import getTimeString from 'lib/getTimeString';
|
import getTimeString from 'lib/getTimeString';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
@ -32,8 +32,8 @@ const DateTimeSelection = ({
|
|||||||
const searchStartTime = params.get('startTime');
|
const searchStartTime = params.get('startTime');
|
||||||
const searchEndTime = params.get('endTime');
|
const searchEndTime = params.get('endTime');
|
||||||
|
|
||||||
const localstorageStartTime = get('startTime');
|
const localstorageStartTime = getLocalStorageKey('startTime');
|
||||||
const localstorageEndTime = get('endTime');
|
const localstorageEndTime = getLocalStorageKey('endTime');
|
||||||
|
|
||||||
const getTime = useCallback((): [number, number] | undefined => {
|
const getTime = useCallback((): [number, number] | undefined => {
|
||||||
if (searchEndTime && searchStartTime) {
|
if (searchEndTime && searchStartTime) {
|
||||||
@ -83,10 +83,10 @@ const DateTimeSelection = ({
|
|||||||
const getDefaultTime = (pathName: string): Time => {
|
const getDefaultTime = (pathName: string): Time => {
|
||||||
const defaultSelectedOption = getDefaultOption(pathName);
|
const defaultSelectedOption = getDefaultOption(pathName);
|
||||||
|
|
||||||
const routes = get(LOCAL_STORAGE.METRICS_TIME_IN_DURATION);
|
const routes = getLocalStorageKey(LOCAL_STORAGE.METRICS_TIME_IN_DURATION);
|
||||||
|
|
||||||
if (routes !== null) {
|
if (routes !== null) {
|
||||||
const routesObject = JSON.parse(routes);
|
const routesObject = JSON.parse(routes || '{}');
|
||||||
const selectedTime = routesObject[pathName];
|
const selectedTime = routesObject[pathName];
|
||||||
|
|
||||||
if (selectedTime) {
|
if (selectedTime) {
|
||||||
@ -102,7 +102,7 @@ const DateTimeSelection = ({
|
|||||||
);
|
);
|
||||||
|
|
||||||
const updateLocalStorageForRoutes = (value: Time): void => {
|
const updateLocalStorageForRoutes = (value: Time): void => {
|
||||||
const preRoutes = get(LOCAL_STORAGE.METRICS_TIME_IN_DURATION);
|
const preRoutes = getLocalStorageKey(LOCAL_STORAGE.METRICS_TIME_IN_DURATION);
|
||||||
if (preRoutes !== null) {
|
if (preRoutes !== null) {
|
||||||
const preRoutesObject = JSON.parse(preRoutes);
|
const preRoutesObject = JSON.parse(preRoutes);
|
||||||
|
|
||||||
@ -111,7 +111,10 @@ const DateTimeSelection = ({
|
|||||||
};
|
};
|
||||||
preRoute[location.pathname] = value;
|
preRoute[location.pathname] = value;
|
||||||
|
|
||||||
set(LOCAL_STORAGE.METRICS_TIME_IN_DURATION, JSON.stringify(preRoute));
|
setLocalStorageKey(
|
||||||
|
LOCAL_STORAGE.METRICS_TIME_IN_DURATION,
|
||||||
|
JSON.stringify(preRoute),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -194,8 +197,8 @@ const DateTimeSelection = ({
|
|||||||
startTimeMoment?.toDate().getTime() || 0,
|
startTimeMoment?.toDate().getTime() || 0,
|
||||||
endTimeMoment?.toDate().getTime() || 0,
|
endTimeMoment?.toDate().getTime() || 0,
|
||||||
]);
|
]);
|
||||||
set('startTime', startTimeMoment.toString());
|
setLocalStorageKey('startTime', startTimeMoment.toString());
|
||||||
set('endTime', endTimeMoment.toString());
|
setLocalStorageKey('endTime', endTimeMoment.toString());
|
||||||
updateLocalStorageForRoutes('custom');
|
updateLocalStorageForRoutes('custom');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -203,10 +206,15 @@ const DateTimeSelection = ({
|
|||||||
|
|
||||||
// this is triggred when we change the routes and based on that we are changing the default options
|
// this is triggred when we change the routes and based on that we are changing the default options
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const metricsTimeDuration = get(LOCAL_STORAGE.METRICS_TIME_IN_DURATION);
|
const metricsTimeDuration = getLocalStorageKey(
|
||||||
|
LOCAL_STORAGE.METRICS_TIME_IN_DURATION,
|
||||||
|
);
|
||||||
|
|
||||||
if (metricsTimeDuration === null) {
|
if (metricsTimeDuration === null) {
|
||||||
set(LOCAL_STORAGE.METRICS_TIME_IN_DURATION, JSON.stringify({}));
|
setLocalStorageKey(
|
||||||
|
LOCAL_STORAGE.METRICS_TIME_IN_DURATION,
|
||||||
|
JSON.stringify({}),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentRoute = location.pathname;
|
const currentRoute = location.pathname;
|
||||||
|
@ -10,10 +10,12 @@ import MetricReducer from 'types/reducer/metrics';
|
|||||||
|
|
||||||
import SkipBoardModal from './SkipOnBoardModal';
|
import SkipBoardModal from './SkipOnBoardModal';
|
||||||
import { Container, Name } from './styles';
|
import { Container, Name } from './styles';
|
||||||
|
import localStorageGet from 'api/browser/localstorage/get';
|
||||||
|
import localStorageSet from 'api/browser/localstorage/set';
|
||||||
|
|
||||||
const Metrics = (): JSX.Element => {
|
const Metrics = (): JSX.Element => {
|
||||||
const [skipOnboarding, setSkipOnboarding] = useState(
|
const [skipOnboarding, setSkipOnboarding] = useState(
|
||||||
localStorage.getItem(SKIP_ONBOARDING) === 'true',
|
localStorageGet(SKIP_ONBOARDING) === 'true',
|
||||||
);
|
);
|
||||||
|
|
||||||
const { services, loading, error } = useSelector<AppState, MetricReducer>(
|
const { services, loading, error } = useSelector<AppState, MetricReducer>(
|
||||||
@ -21,7 +23,7 @@ const Metrics = (): JSX.Element => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const onContinueClick = (): void => {
|
const onContinueClick = (): void => {
|
||||||
localStorage.setItem(SKIP_ONBOARDING, 'true');
|
localStorageSet(SKIP_ONBOARDING, 'true');
|
||||||
setSkipOnboarding(true);
|
setSkipOnboarding(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ import { AppState } from 'store/reducers';
|
|||||||
import AppActions from 'types/actions';
|
import AppActions from 'types/actions';
|
||||||
import { GlobalReducer } from 'types/reducer/globalTime';
|
import { GlobalReducer } from 'types/reducer/globalTime';
|
||||||
import MetricReducer from 'types/reducer/metrics';
|
import MetricReducer from 'types/reducer/metrics';
|
||||||
|
import getLocalStorageKey from 'api/browser/localstorage/get';
|
||||||
|
|
||||||
const Metrics = ({ getService }: MetricsProps): JSX.Element => {
|
const Metrics = ({ getService }: MetricsProps): JSX.Element => {
|
||||||
const { minTime, maxTime, loading, selectedTime } = useSelector<
|
const { minTime, maxTime, loading, selectedTime } = useSelector<
|
||||||
@ -20,7 +21,7 @@ const Metrics = ({ getService }: MetricsProps): JSX.Element => {
|
|||||||
(state) => state.metrics,
|
(state) => state.metrics,
|
||||||
);
|
);
|
||||||
|
|
||||||
const isSkipped = localStorage.getItem(SKIP_ONBOARDING) === 'true';
|
const isSkipped = getLocalStorageKey(SKIP_ONBOARDING) === 'true';
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (loading === false) {
|
if (loading === false) {
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
import { IS_LOGGED_IN } from 'constants/auth';
|
import { IS_LOGGED_IN } from 'constants/auth';
|
||||||
import { Dispatch } from 'redux';
|
import { Dispatch } from 'redux';
|
||||||
import AppActions from 'types/actions';
|
import AppActions from 'types/actions';
|
||||||
|
import setLocalStorageKey from 'api/browser/localstorage/set';
|
||||||
|
|
||||||
export const UserLoggedIn = (): ((dispatch: Dispatch<AppActions>) => void) => {
|
export const UserLoggedIn = (): ((dispatch: Dispatch<AppActions>) => void) => {
|
||||||
return (dispatch: Dispatch<AppActions>): void => {
|
return (dispatch: Dispatch<AppActions>): void => {
|
||||||
localStorage.setItem(IS_LOGGED_IN, 'yes');
|
setLocalStorageKey(IS_LOGGED_IN, 'yes');
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: 'LOGGED_IN',
|
type: 'LOGGED_IN',
|
||||||
|
@ -6,10 +6,11 @@ import {
|
|||||||
TOGGLE_SETTINGS_TABS,
|
TOGGLE_SETTINGS_TABS,
|
||||||
} from 'types/actions/app';
|
} from 'types/actions/app';
|
||||||
import InitialValueTypes from 'types/reducer/app';
|
import InitialValueTypes from 'types/reducer/app';
|
||||||
|
import getLocalStorageKey from 'api/browser/localstorage/get';
|
||||||
|
|
||||||
const InitialValue: InitialValueTypes = {
|
const InitialValue: InitialValueTypes = {
|
||||||
isDarkMode: true,
|
isDarkMode: true,
|
||||||
isLoggedIn: localStorage.getItem(IS_LOGGED_IN) === 'yes',
|
isLoggedIn: getLocalStorageKey(IS_LOGGED_IN) === 'yes',
|
||||||
settingsActiveTab: 'General',
|
settingsActiveTab: 'General',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { SKIP_ONBOARDING } from 'constants/onboarding';
|
import { SKIP_ONBOARDING } from 'constants/onboarding';
|
||||||
|
import getLocalStorage from 'api/browser/localstorage/get';
|
||||||
|
|
||||||
export const isOnboardingSkipped = (): boolean => {
|
export const isOnboardingSkipped = (): boolean => {
|
||||||
return localStorage.getItem(SKIP_ONBOARDING) === 'true';
|
return getLocalStorage(SKIP_ONBOARDING) === 'true';
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user