chore: Refactor localstorage into typesafe version (#17832)

This commit is contained in:
Erik Ritter
2021-12-20 13:58:59 -08:00
committed by GitHub
parent e3b44f4825
commit 6edc183c5f
14 changed files with 202 additions and 98 deletions

View File

@@ -25,8 +25,9 @@ import TableView, { EmptyWrapperType } from 'src/components/TableView';
import { getChartDataRequest } from 'src/chart/chartAction';
import { getClientErrorObject } from 'src/utils/getClientErrorObject';
import {
getFromLocalStorage,
setInLocalStorage,
getItem,
setItem,
LocalStorageKeys,
} from 'src/utils/localStorageHelpers';
import {
CopyToClipboardButton,
@@ -49,10 +50,6 @@ const NULLISH_RESULTS_STATE = {
const DATA_TABLE_PAGE_SIZE = 50;
const STORAGE_KEYS = {
isOpen: 'is_datapanel_open',
};
const DATAPANEL_KEY = 'data';
const TableControlsWrapper = styled.div`
@@ -200,7 +197,7 @@ export const DataTablesPane = ({
[RESULT_TYPES.samples]?: boolean;
}>(NULLISH_RESULTS_STATE);
const [panelOpen, setPanelOpen] = useState(
getFromLocalStorage(STORAGE_KEYS.isOpen, false),
getItem(LocalStorageKeys.is_datapanel_open, false),
);
const formattedData = useMemo(
@@ -283,7 +280,7 @@ export const DataTablesPane = ({
);
useEffect(() => {
setInLocalStorage(STORAGE_KEYS.isOpen, panelOpen);
setItem(LocalStorageKeys.is_datapanel_open, panelOpen);
}, [panelOpen]);
useEffect(() => {