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

[Visualize] Remove legacy appState in visualize #57330

Merged
merged 15 commits into from
Feb 20, 2020

Conversation

sulemanof
Copy link
Contributor

@sulemanof sulemanof commented Feb 11, 2020

Summary

Remove legacy appState in visualize and use new platform utilities for state management

Resolves #56492

  • remove usage of legacy AppState in visualize;
  • replace AppState.makeStateful method with a local makeStateful utility. This is used to create an instnace of PersistedState for the uiState object, and seems is was used only in visualize (it's also used in discover now, but will be removed), so could be safely removed with the AppState class;
  • use createStateContainer utility for app state management;
  • use createKbnUrlStateStorage utility for url state management;
  • use syncState to bound the appState and the url state updates;

Also resolves #55084

Manipulating with history back/forward :

fix_history_changes

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@sulemanof sulemanof added Feature:NP Migration release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.7.0 v8.0.0 labels Feb 12, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app (Team:KibanaApp)

@sulemanof sulemanof marked this pull request as ready for review February 12, 2020 12:08
@sulemanof sulemanof requested a review from a team February 12, 2020 12:08
@sulemanof sulemanof requested a review from a team as a code owner February 12, 2020 12:08
@sulemanof
Copy link
Contributor Author

@Bargs I would kindly ask you to test the query functionality due to this changes! 😊

stateMonitor = stateMonitorFactory.create($state, stateDefaults);
stateMonitor.ignoreProps(['vis.listeners']).onChange(status => {
$appStatus.dirty = status.dirty || !savedVis.id;
});
Copy link
Member

Choose a reason for hiding this comment

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

Since you've removed the stateMonitor (which is good), I might be wrong but $appStatus.dirty is just initialized and no longer changed?

Copy link
Contributor Author

@sulemanof sulemanof Feb 13, 2020

Choose a reason for hiding this comment

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

Hey, yeah!
I left one initializing reference to it intentionally!
I would highlight the thing about the $appStatus, because I didn't find a proper case how should it work!
So, if someone has a vision about how should this work, he can mention it here.
If it's redundant, I'll remove it!

Copy link
Member

Choose a reason for hiding this comment

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

I'll take a closer look here

Copy link
Member

@kertal kertal Feb 14, 2020

Choose a reason for hiding this comment

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

$appStatus.isDirty is used when you want to share a visualization, but it has not been saved before, or there were changes after saving.

const hasUnsavedChanges = $appStatus.dirty;

isDirty: hasUnappliedChanges || hasUnsavedChanges,

When you then try to generate a report you get the following message:

"Please save your work before generating a report."

So $appStatus.isDirty should be set to true, when the visualization was not saved, or it was saved and the appState changed.
It should be set to false once the visualization was saved. And this persisted state is the state that you need to check agains for further changes that modify $appStatus.isDirty

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kertal thanks for the deep explanation!
Applied dirty state checker due to current code

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.

This looks really good! Found two small things but overall great work!


$state.linked = false;
$scope.linked = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

When testing the link/unlink saved search did not work when using browser back/forward buttons - probably because the linked state is saved outside of the state? Would it make sense to also put it in app state? Looks like it is currently part of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! Updated!

@kertal kertal requested a review from Dosant February 14, 2020 10:55
@flash1293
Copy link
Contributor

Noticed a small bug - when pinning a filter, you have to hit the back button twice to get back to the old non-pinned status - it seems like it's writing two history entries for this case. Maybe that's because it is half angular / half utils state management - also fine with fixing it when migrating global state, but we should create an issue in this case to make sure not to forget it.

…p_state

# Conflicts:
#	src/legacy/core_plugins/kibana/public/visualize/np_ready/editor/editor.js
@sulemanof
Copy link
Contributor Author

Noticed a small bug - when pinning a filter, you have to hit the back button twice to get back to the old non-pinned status - it seems like it's writing two history entries for this case. Maybe that's because it is half angular / half utils state management - also fine with fixing it when migrating global state, but we should create an issue in this case to make sure not to forget it.

Good catch @flash1293 !
I've created an issue to track this, will manage it while migrating the GlobalState.

@flash1293
Copy link
Contributor

flash1293 commented Feb 18, 2020

@sulemanof about the linked saved search:

It seems like this doesn't work completely - it is putting the link back in place, but it's not updating the search source behind the scenes. The filters are just gone.

Example (saved search filtering by category "Womens clothing"):
Screenshot 2020-02-18 at 14 32 46

after unlinking saved search (correct behavior)
Screenshot 2020-02-18 at 14 32 51

after pressing back button (changed results, seems like the filters aren't put back in place):
Screenshot 2020-02-18 at 14 32 57

Not sure whether that ever worked because it seems like the unlink function is triggering quite some side effects that are probably difficult to roll back, but if it's an easy fix we should definitely include it. If it's difficult to fix let's just revert to the old state and have it living outside of history, that would be less confusing. Sorry in that cause for bringing it up.

@flash1293
Copy link
Contributor

Besides the problem above everything else works as expected for me.

…p_state

# Conflicts:
#	src/legacy/core_plugins/kibana/public/visualize/legacy_imports.ts
@sulemanof
Copy link
Contributor Author

sulemanof commented Feb 19, 2020

Hey @flash1293
The point you have mentioned abot the linked search really worth a fix!
Since this behavior is not caused by this PR and after a short look inside I don't have an easy fix (at least it will be more than couple LOC), I've created a separate issue #57977 to track it and to create a purposeful PR, which could also cause further discussing; this also will be mentioned as a separate task for git history.
I think this will also help reviewers to concentrate on a particular case.
I'll be happy to take care of it, but not to block current PR and to minimize next merge conflicts here.
Are you OK with that? Thanks =)

@flash1293
Copy link
Contributor

@sulemanof Sounds good to me, thanks for creating the issue.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

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

Copy link
Contributor

@Dosant Dosant left a comment

Choose a reason for hiding this comment

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

Code looks good to me,
Tested some advanced cases like switching between hashed / expanded url format, navigating between vis / dashboard and using recently viewed items - didn't notice any issues.


export function useVisualizeAppState({ useHash, stateDefaults }: Arguments) {
const history = createHashHistory();
const kbnUrlStateStorage = createKbnUrlStateStorage({
Copy link
Contributor

Choose a reason for hiding this comment

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

Just for info: to fix pinned/unpinned filter, it will be important that global state syncing uses the same kbnUrlStateStorage as app state syncing.

@kertal kertal self-requested a review February 20, 2020 09:27
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.

Tested and works as expected, LGTM 👍

Copy link
Member

@kertal kertal left a comment

Choose a reason for hiding this comment

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

Code LGTM, "dirty" state is handled correctly, great work! tested locally in Chrome

@sulemanof sulemanof merged commit 0b64411 into elastic:master Feb 20, 2020
@sulemanof sulemanof deleted the shim/visualize_app_state branch February 20, 2020 10:40
mbondyra added a commit to mbondyra/kibana that referenced this pull request Feb 20, 2020
* master: (136 commits)
  [Visualize] Remove legacy appState in visualize (elastic#57330)
  Use static time for tsvb rollup test (elastic#57701)
  [SIEM] Fix ResizeObserver polyfill (elastic#58046)
  [SIEM][Detection Engine] Fixes return codes where some were rule_id instead of id
  skip flaky suite (elastic#56816)
  skip flaky suite (elastic#58059)
  skip flaky suite (elastic#45348)
  migrates notification server routes to NP (elastic#57906)
  Moved all of the show/hide toggles outside of ordered lists. (elastic#57163)
  [APM] NP Migration - Moves plugin server files out of legacy (elastic#57532)
  [Maps][Telemetry] Migrate Maps telemetry to NP (elastic#55055)
  Embeddable add panel examples (elastic#57319)
  Fix useRequest to support query change (elastic#57723)
  Allow custom paths in plugin generator (elastic#57766)
  [SIEM][Case] Merge header components (elastic#57816)
  [ML] New Platform server shim: update job audit messages routes (elastic#57925)
  [kbn/optimizer] emit success event from reducer when all bundles cached (elastic#57945)
  [APM] Don’t include UI filters when fetching a specific transaction (elastic#57934)
  Upgrade yargs (elastic#57720)
  skip flaky suite (elastic#57762) (elastic#57997) (elastic#57998)
  ...

# Conflicts:
#	src/plugins/advanced_settings/public/management_app/components/field/__snapshots__/field.test.tsx.snap
#	src/plugins/advanced_settings/public/management_app/components/field/field.tsx
#	x-pack/plugins/translations/translations/ja-JP.json
#	x-pack/plugins/translations/translations/zh-CN.json
sulemanof added a commit that referenced this pull request Feb 20, 2020
* Remove legacy appState in visualize

* Read query and linked prop from scope

* Fix persisted state instance

* Fix functional tests

* Bound url updates with an editor

* Some improvements

* Fix comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backported Feature:NP Migration release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.7.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove AppState in Visualize Back button doesn’t work in Visualize
6 participants