-
Notifications
You must be signed in to change notification settings - Fork 909
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement persistence without using state container or state sync utils, and it works with both the URL and session storage. Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com>
- Loading branch information
1 parent
bb94a9d
commit c73a62e
Showing
2 changed files
with
48 additions
and
2 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
src/plugins/vis_builder/public/application/utils/state_management/redux_persistence.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { VisBuilderServices } from '../../../types'; | ||
import { getPreloadedState } from './preload'; | ||
import { RootState } from './store'; | ||
|
||
export const loadReduxState = async (services: VisBuilderServices) => { | ||
try { | ||
const serializedState = services.osdUrlStateStorage.get<RootState>('_a'); | ||
if (serializedState === null) { | ||
return await getPreloadedState(services); | ||
} | ||
return serializedState; | ||
} catch (err) { | ||
return await getPreloadedState(services); | ||
} | ||
}; | ||
|
||
export const saveReduxState = ( | ||
{ style, visualization, metadata }, | ||
services: VisBuilderServices | ||
) => { | ||
try { | ||
services.osdUrlStateStorage.set<RootState>( | ||
'_a', | ||
{ style, visualization, metadata }, | ||
{ | ||
replace: true, | ||
} | ||
); | ||
} catch (err) { | ||
return; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters