From 1656d2e8f295b81cbe248891fe2d6e1c4e6e5201 Mon Sep 17 00:00:00 2001 From: Andrew Watkins Date: Thu, 5 Oct 2017 17:24:15 -0700 Subject: [PATCH] Normalize dashboard time ranges on load and save to localStorage --- ui/src/localStorage.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/ui/src/localStorage.js b/ui/src/localStorage.js index 0f21658e9c..689825ed88 100644 --- a/ui/src/localStorage.js +++ b/ui/src/localStorage.js @@ -1,3 +1,5 @@ +import normalizer from 'src/normalizers/dashboardTime' + export const loadLocalStorage = errorsQueue => { try { const serializedState = localStorage.getItem('state') @@ -12,8 +14,22 @@ export const loadLocalStorage = errorsQueue => { console.log(errorText) // eslint-disable-line no-console errorsQueue.push(errorText) - window.localStorage.removeItem('state') - return {} + if (!state.dashTimeV1) { + window.localStorage.removeItem('state') + return {} + } + + const ranges = normalizer(state.dashTimeV1.ranges) + const dashTimeV1 = {ranges} + + window.localStorage.setItem( + 'state', + JSON.stringify({ + dashTimeV1, + }) + ) + + return {dashTimeV1} } delete state.VERSION @@ -34,10 +50,11 @@ export const saveToLocalStorage = ({ dataExplorerQueryConfigs, timeRange, dataExplorer, - dashTimeV1, + dashTimeV1: {ranges}, }) => { try { const appPersisted = Object.assign({}, {app: {persisted}}) + const dashTimeV1 = {ranges: normalizer(ranges)} window.localStorage.setItem( 'state',