Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[State Management] State syncing utilities - remove AppState from Dashboard app #54105

Merged
merged 14 commits into from
Jan 21, 2020

Conversation

Dosant
Copy link
Contributor

@Dosant Dosant commented Jan 7, 2020

Summary

Depends on #53582
Part of #44151
Removes AppState from dashboard app and replaces it with state containers and state syncing utilities.

There is also follow up in progress which also removes global state:
#55158

Disclamer

I didn't try to refactor the state management in Dashboard in scope of this (as new state_containers give us more flexibility).
Just tried to replace AppState -> State Containers with minimal changes

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

For maintainers

@streamich streamich mentioned this pull request Jan 13, 2020
30 tasks
@Dosant Dosant force-pushed the dev/state-managment/state-sync-dashboard branch 2 times, most recently from c7a861e to 415095b Compare January 14, 2020 15:37
improve

improve

improve

improve
@Dosant Dosant force-pushed the dev/state-managment/state-sync-dashboard branch from 415095b to 5073715 Compare January 14, 2020 15:45
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app-arch (Team:AppArch)

@Dosant Dosant added the release_note:skip Skip the PR/issue when compiling release notes label Jan 15, 2020
@Dosant Dosant changed the title [WIP][State Management] State syncing utilities - remove AppState from Dashboard app [State Management] State syncing utilities - remove AppState from Dashboard app Jan 15, 2020
@Dosant Dosant marked this pull request as ready for review January 15, 2020 13:41
@Dosant Dosant requested a review from a team January 15, 2020 13:41
@Dosant Dosant requested a review from a team as a code owner January 15, 2020 13:41
@flash1293
Copy link
Contributor

flash1293 commented Jan 16, 2020

Nothing major, but probably worth looking into: If full screen mode is toggled by changing the state in the rison encoded URL parameter, data gets fetched again. I looked into this a bit and it seems like the query object gets changed triggering an angular watcher. In the current setup this doesn't happen for some reason. This could probably be handled by comparing the current state and the deserialized state from the URL and not changing the object reference if the two are deep equal.

Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nits, but dashboard integration LGTM - works great, thanks! There is one difference I noticed but it's not a blocker for merging this. I noticed that requests are triggered in a lot of places when they are not necessary (e.g. when changing "showMargins" setting), but this is also happening on master. I will create a separate issue for that.

…agment/state-sync-dashboard

# Conflicts:
#	src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_state.test.ts
@Dosant
Copy link
Contributor Author

Dosant commented Jan 17, 2020

Nothing major, but probably worth looking into: If full screen mode is toggled by changing the state in the rison encoded URL parameter, data gets fetched again. I looked into this a bit and it seems like the query object gets changed triggering an angular watcher. In the current setup this doesn't happen for some reason. This could probably be handled by comparing the current state and the deserialized state from the URL and not changing the object reference if the two are deep equal.

@flash1293, Good catch! this particular case is fixed by utilising "applyDiff" utility from old state_management in new state syncing utils.

There is one difference I noticed but it's not a blocker for merging this. I noticed that requests are triggered in a lot of places when they are not necessary (e.g. when changing "showMargins" setting), but this is also happening on master. I will create a separate issue for that.

Now it seems like, that it happens only when filters are applied, likely is going to be fixed together with:
#54887

Copy link
Contributor

@lizozom lizozom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and reviewed code LGTM
However, for the protocol, why did this change require adding getPendingUrl and supporting returning undefined from update in kbn_url_storage

@@ -80,7 +84,7 @@ export class FilterStateManager {

private saveState() {
const appState = this.getAppState();
if (appState) appState.save();
if (appState && appState.save) appState.save();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we get an appState without a save method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This filter_state_management is still used in Dashboard (until next pr, where we will remove global state also)
So, as we removed AppState from Dashboard, I change the interface of filter_state_manager to :
https://github.com/elastic/kibana/pull/54105/files/10fe7772a3297f9e5b03591dd9d47a5b8ca9be02#diff-e99af5c3c776f37f6e37ab25d094e3cfR25

And save function is for legacy AppState case, but new state sync utils don't have explicit save() method.

kibana-app-arch automation moved this from In progress to Review in progress Jan 19, 2020
@Dosant
Copy link
Contributor Author

Dosant commented Jan 20, 2020

@lizozom,

However, for the protocol, why did this change require adding getPendingUrl and supporting returning undefined from update in kbn_url_storage

I don't remember exactly the edge case I was fighting, but in a nutshell it was something like this:

const state1 = {...}; // initial state
const state2 = {...}

setState(state2) // transition to state2, the location change was scheduled 
setState(state1) // synchronously transition back to state 1, but location change wasn't scheduled, because comparison inside stateSync util took storageState from current location.

// so we ended up in state1, but url with state2 :(

@Dosant
Copy link
Contributor Author

Dosant commented Jan 20, 2020

retest

@Dosant Dosant added the v8.0.0 label Jan 20, 2020
@Dosant
Copy link
Contributor Author

Dosant commented Jan 21, 2020

@elasticmachine merge upstream

elasticmachine and others added 2 commits January 21, 2020 04:03
…agment/state-sync-dashboard

# Conflicts:
#	src/legacy/core_plugins/data/public/filter/filter_manager/filter_state_manager.ts
@Dosant
Copy link
Contributor Author

Dosant commented Jan 21, 2020

retest

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@Dosant Dosant merged commit 27c8a4b into elastic:master Jan 21, 2020
kibana-app-arch automation moved this from Review in progress to Done in 7.7 Jan 21, 2020
Dosant added a commit to Dosant/kibana that referenced this pull request Jan 21, 2020
Removes AppState from dashboard app and replaces it with state containers and state syncing utilities.
gmmorris added a commit to gmmorris/kibana that referenced this pull request Jan 21, 2020
* master:
  [State Management] remove AppState from Dashboard app (elastic#54105)
  Expose fatalErrors API from the Start contract (elastic#55300)
  [BUG] Data fetching twice on discover timefilter change  (elastic#55279)
  [Mappings editor] Add missing max_shingle_size parameter to search_as_you_type (elastic#55161)
  [Logs UI] Fix z-index of logs page toolbar (elastic#54469)
  removes CTA from Task Manager info message (elastic#55334)
Dosant added a commit that referenced this pull request Jan 22, 2020
Removes AppState from dashboard app and replaces it with state containers and state syncing utilities.

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
@alexh97 alexh97 moved this from Done in current release to Done in previous release in kibana-app-arch Jun 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
kibana-app-arch
  
Done in previous release
Development

Successfully merging this pull request may close these issues.

None yet

5 participants