[Research] Data persistence in current dashboard plugins #2876
Labels
docs
Improvements or additions to documentation
enhancement
New feature or request
research
vis builder
Data persistence
There are four plugins that currently have data persistence ability in opensearch dashboard: dashboard, discover, timeline, and visualize. They are using the following services and mechanisms from opensearch_dashboard_utils plugin to achieve data persistence.
State syncing utils are a set of helpers to sync application state with URL or browser storage(when turning state: storeInSessionStore on in advanced setting, in case of overflowed URL):
Two type of persistence
There are two parts for data persistence:
app state storage key: '_a'
app state is persistent only within the specific app, values will persist when we refresh the page, values will not be persist when we navigate away from the app
for visualize app, the params are:
global state storage key: '_g'
global query state is persistent across the entire application, values will persist when we refresh the page, or when we navigate across visualize, discover, timeline or dashboard page. For example, if we set time range to last 24 hours, and refresh intervals to every 30 min, the same time range and refresh intervals will be applied if we navigate to any of the other pages.
params:
URL breakdown & example
Global state persistence
In plugin.ts, during plugin setup, call createOsdUrlTracker(), listen to history changes and global state changes, then update the nav link URL. This also returns function such as onMountApp(), onUnmountedApp()
const storedUrl = storageInstance.getItem(storageKey)
. (Storage instance is a browser wide session storage instance.) Then it unsubscribes to global state$ and subscribes to URL$. The current app actively listens to history location changes. If there are changes, set the updated URL as the active URLIn app.tsx, call syncQueryStateWithUrl(query, osdUrlStateStorage) to sync '_g' portion of url with global state params
when we first enter the app, there is no initial state in the URL, then we initialize and put the _g key into url
when we enter the app, if there is some initial state in the URL(the previous saved URL in storageInstance), then we retrieve global state from '_g' URL
App state persistence
when we first enter the app, there is no app state in the URL, so we set the default states into URL in createDefaultVisualizeAppState()
osdUrlStateStorage.set(STATE_STORAGE_KEY, initialState, { replace: true });
when we make changes to the app state, the
dirtyStateChange
event emitter will get triggered, then osd state container will call updateStorage() to update the URL state storage, then state container(appState) will also be in sync with URL state storagein useEditorUpdates(), we use the saved appState to load the visualize editor
Refresh
When we refresh the page, both app state and global state should persist:
appState
based on URLappState
to load the visualization with previous saved statesNavigate to another app
When we navigate to another app from the current app, global state should persist:
Diagram
Example storage instance:
The text was updated successfully, but these errors were encountered: