feat: Save datapanel state in local storage (#12996)

* Save datapanel state in local storage

* Export string to a constant

* Move local storage helpers to separate file

* Use helper functions in ExploreViewContainer
This commit is contained in:
Kamil Gabryjelski
2021-02-09 01:42:59 +01:00
committed by GitHub
parent 69b0ed663d
commit 2ce79823df
4 changed files with 76 additions and 14 deletions

View File

@@ -30,6 +30,10 @@ import { Global } from '@emotion/core';
import { Tooltip } from 'src/common/components/Tooltip';
import { usePrevious } from 'src/common/hooks/usePrevious';
import Icon from 'src/components/Icon';
import {
getFromLocalStorage,
setInLocalStorage,
} from 'src/utils/localStorageHelpers';
import ExploreChartPanel from './ExploreChartPanel';
import ConnectedControlPanelsContainer from './ControlPanelsContainer';
import SaveModal from './SaveModal';
@@ -379,20 +383,12 @@ function ExploreViewContainer(props) {
}
function getSidebarWidths(key) {
try {
return localStorage.getItem(key) || defaultSidebarsWidth[key];
} catch {
return defaultSidebarsWidth[key];
}
return getFromLocalStorage(key, defaultSidebarsWidth[key]);
}
function setSidebarWidths(key, dimension) {
try {
const newDimension = Number(getSidebarWidths(key)) + dimension.width;
localStorage.setItem(key, newDimension);
} catch {
// Catch in case localStorage is unavailable
}
const newDimension = Number(getSidebarWidths(key)) + dimension.width;
setInLocalStorage(key, newDimension);
}
if (props.standalone) {