Skip to content

State Management 👉 New Platform #44151

@streamich

Description

@streamich

ui/state_management migration plan

Overview

Today, apps rely on AppState and GlobalState in the ui/state_management module to deal with internal (app) and shared (global) state. These classes give apps an ability to read/write state, when is then synced to the URL as well as sessionStorage. They also react to changes in the URL and automatically update state & emit events when changes occur.

Screenshot 2019-11-20 16 25 38

In the new platform, we don't have the concept of global state, and each app will be responsible for managing its own state and "opting in" to syncing with the URL and/or sessionStorage, as discussed in #39855.

The overall migration strategy outlined in this issue boils down to a few static utilities that live in src/plugins/kibana_utils:

  1. kibana_utils/state_containers: These are redux-like state containers that apps can use to manage their state and respond to updates.
  2. kibana_utils/storage: A lightweight wrapper around the getters/setters for both local & session storage.
  3. new - kibana_utils/state_management/url, kibana_utils/state_management/state_hash, kibana_utils/state_management/state_encoder: Utilities for interacting with urls by hashing/unhashing and dealing with rison encoding/decoding
  4. new - kibana_utils/state_sync: Replacement for appState that handles syncing an app's state with url/storage, as well as updating state containers based on shared "global" state changes from other services, such as filters & timepicker.

Screenshot 2019-11-20 16 25 45

state_hashing

Utility functions to create hash url from state and vice versa

state_storage

Handles storing/retrieving hashed items into sessionStorage and clearing stale items

app_state

Provides a way to make state auto-persist to url/sessionStorage on change by letting apps read/write state

POC in progress:

  1. Basic [POC] Application state syncing utility. #51692
  2. Advanced cases: [State Management] State syncing utilities #53582

POC:

Implementation:

global_state

Same as app state, only for data that is to be shared between apps

state

Base class for both App & Global State; provides logic to read/write the state (from/to url/sessionStorage)

state_monitor_factory

Watches for state changes & emits events

  • state syncing utils cover it, need to be removed together with AppState and GlobalState later

state_management_config_provider

Allows apps to configure state management by enabling/disabling

  • remove; should not be necessary as apps can work directly with the new state syncing utility and manage configuration on their own

migrate apps to use state_containers and new utility functions - as a good example on how to use

Utilities and docs for syncing with data services

Support other apps with migrating away from GlobalState & AppState

When everything is migrated - remove AppState & GlobalState & state_monitor_factory

New Work

Parent issue: #31968

Metadata

Metadata

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions