Skip to content

Apply sub url tracking utils to visualize and discover#57307

Merged
maryia-lapata merged 15 commits intoelastic:masterfrom
maryia-lapata:url-tracking
Feb 18, 2020
Merged

Apply sub url tracking utils to visualize and discover#57307
maryia-lapata merged 15 commits intoelastic:masterfrom
maryia-lapata:url-tracking

Conversation

@maryia-lapata
Copy link
Copy Markdown
Contributor

This PR applies the new sub url tracking utils from #55818 to the Visualize and Discover plugins.

@maryia-lapata maryia-lapata added Feature:Discover Discover Application Team:Visualizations Team label for Lens, elastic-charts, Graph, legacy editors (TSVB, Visualize, Timelion) t// v8.0.0 release_note:skip Skip the PR/issue when compiling release notes Feature:NP Migration v7.7.0 labels Feb 11, 2020
@elasticmachine
Copy link
Copy Markdown
Contributor

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

@maryia-lapata maryia-lapata marked this pull request as ready for review February 11, 2020 15:08
@maryia-lapata maryia-lapata requested a review from a team February 11, 2020 15:08
Copy link
Copy Markdown
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.

  • In src/legacy/core_plugins/kibana/index.js disableSubUrlTracking: true has to be added to the respective nav links to disable the angular tracker. Otherwise it's also running and updating.
  • In src/legacy/core_plugins/kibana/public/visualize/np_ready/editor/editor.js legacy chrome is called to update the nav link: legacyChrome.trackSubUrlForApp('kibana:visualize', savedVisualizationParsedUrl); Please check whether that's still necessary and remove if not
  • In src/legacy/core_plugins/kibana/public/visualize/np_ready/listing/visualize_listing.js legacy chrome is called to filter out navlinks referencing deleted objects: legacyChrome.untrackNavLinksForDeletedSavedObjects(selectedItems.map(item => item.id)); Please check whether that's still necessary and delete if not. If we still need this we should think about how to do this without legacy chrome

@maryia-lapata
Copy link
Copy Markdown
Contributor Author

  • In src/legacy/core_plugins/kibana/public/visualize/np_ready/editor/editor.js legacy chrome is called to update the nav link: legacyChrome.trackSubUrlForApp('kibana:visualize', savedVisualizationParsedUrl); Please check whether that's still necessary and remove if not
  • In src/legacy/core_plugins/kibana/public/visualize/np_ready/listing/visualize_listing.js legacy chrome is called to filter out navlinks referencing deleted objects: legacyChrome.untrackNavLinksForDeletedSavedObjects(selectedItems.map(item => item.id)); Please check whether that's still necessary and delete if not. If we still need this we should think about how to do this without legacy chrome

I checked 1 and 2 in master and it seems that they don't work.

a) Firstly, linkToLastSubUrl should be truly in app link for both call (trackSubUrlForApp and untrackNavLinksForDeletedSavedObjects)

if (link.linkToLastSubUrl === false) {
return;

b) Secondly, even if I define linkToLastSubUrl as true for visualize (here), it still doesn't work because of a typo (I guess) in

linkToLastSub: 'linkToLastSubUrl' in spec ? spec.linkToLastSubUrl : false,

linkToLastSub -> linkToLastSubUrl.

If I apply a and b, trackSubUrlForApp works (if we create a vis from dashboard, that vis will be opened by clicking on Visualize from nav bar). As for untrackNavLinksForDeletedSavedObjects I don't quite understand the case. We can remove a vis from the listing page, and the function checks if the current url (the listing page) contains a deleted url, that 's never going to happen

if (link.linkToLastSubUrl && urlContainsDeletedId(link.url!)) {

Probably I miss something, but it doesn't make sense for me.

Anyway since the visualize app doesn't have truly linkToLastSubUrl, I think we can remove trackSubUrlForApp and untrackNavLinksForDeletedSavedObjects.

@maryia-lapata maryia-lapata requested a review from a team as a code owner February 12, 2020 10:24
# Conflicts:
#	src/legacy/ui/public/new_platform/new_platform.karma_mock.js
@@ -588,10 +587,6 @@ function VisualizeAppController(
});
// Manually insert a new url so the back button will open the saved visualization.
$window.history.pushState({}, '', savedVisualizationParsedUrl.getRootRelativePath());
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@flash1293 also I noticed that this new history state doesn't trigger history listener:

const urlWithHashes = baseUrl + '#' + location.pathname + location.search;

So in this PR just #/visualize/create link is saved and opens by clicking on Visualize in nav bar.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is strange, because open a visualization after creating it in a dashboard working fine in my PR, but there is the case with the back button works wrong, so you could also check it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@sulemanof I checked again, you're right (probably when I tested before, something was cached). But a saved visualization currently opens just because of the typo (there is a check link.linkToLastSubUrl === false, but linkToLastSubUrl is undefined now due to the typo).

As for the history, I can navigate to a saved visualization by clicking twice on the back button. @flash1293 do you think it's a valid case?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So I tested the current state and everything is working fine for me. When creating a vis within dashboard, it will store the id in the navlink (which is correct) and it will go back to the saved visualization (which is also correct IMHO).

@flash1293
Copy link
Copy Markdown
Contributor

@maryia-lapata

For 2 I agree that it doesn't make sense, let's remove that one.

For 1

So in this PR just #/visualize/create link is saved and opens by clicking on Visualize in nav bar.

That should not happen, it should pick up the saved id. It seems like we havbe to extend the kbn url tracker to expose a function to imperatively set the active url (and call it in this case to update).

Something like this (quick and dirty just to illustrate the approach):

function createKbnUrlTracker() {
// ...
  return {
    // ...
    setActiveUrl(newUrl) {
      const urlWithHashes = baseUrl + '#' + newUrl;
      let urlWithStates = '';
      try {
        urlWithStates = unhashUrl(urlWithHashes);
      } catch (e) {
        toastNotifications.addDanger(e.message);
      }

      activeUrl = getActiveSubUrl(urlWithStates || urlWithHashes);
      storageInstance.setItem(storageKey, activeUrl);
    }
  };
// ...
// editor.js

const newUrl = savedVisualizationParsedUrl.getRootRelativePath();
$window.history.pushState({}, '', newUrl);
urlTracker.setActiveUrl(newUrl);

Maybe @Dosant has a better idea.

@maryia-lapata maryia-lapata requested a review from a team as a code owner February 12, 2020 13:02
Copy link
Copy Markdown
Contributor

@pgayvallet pgayvallet left a comment

Choose a reason for hiding this comment

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

LGTM for platform changes

Comment on lines +29 to +30
...npSetup.plugins,
__LEGACY: {
legacyChrome,
},
npData: npSetup.plugins.data,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why the redundant npData: npSetup.plugins.data ? why not just instance.setup(npSetup.core, npSetup.plugins) and access the data plugin with it's proper data name?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@pgayvallet I will clean this up with #57331

Copy link
Copy Markdown
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 fine for me, left some small comments but no need to review again from my side

__LEGACY: {
legacyChrome,
},
npData: npSetup.plugins.data,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I missunderstood @pgayvallet in my first comment, I thought the import was just moved, but it's in fact a new one. Please just call it data within the plugin, then

instance.setup(npSetup.core, npSetup.plugins);

Is enough. I have a draft PR up to clean up the other shims in the same way

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

elasticmachine and others added 3 commits February 14, 2020 00:53
# Conflicts:
#	src/core/server/legacy/plugins/find_legacy_plugin_specs.ts
#	src/legacy/core_plugins/kibana/public/discover/plugin.ts
#	src/legacy/core_plugins/kibana/public/visualize/legacy.ts
#	src/legacy/core_plugins/kibana/public/visualize/np_ready/application.ts
#	src/legacy/core_plugins/kibana/public/visualize/plugin.ts
updater$: this.appStateUpdater.asObservable(),
navLinkId: 'kibana:visualize',
mount: async (params: AppMountParameters) => {
const [coreStart] = await core.getStartServices();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@lizozom @flash1293
If I'm not wrong we decided to use approach with creating a services.ts file and pass start dependencies using createGetterSetter method.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wasn't aware this is a definitive rule, just an option how to do things - passing down services directly can IMHO be preferable, depending on the situation (e.g. because you don't have to mock out the getters in tests)

Copy link
Copy Markdown
Contributor

@alexwizp alexwizp Feb 17, 2020

Choose a reason for hiding this comment

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

Looks like my comment is not related to this PR but here we pass some dependencies using core.getStartServices(); but some comes from this.startDependencies object.

Is it possible to refactor it in future and do it in a common with other plugins way?

@flash1293
Copy link
Copy Markdown
Contributor

@Dosant can you check this one out for the app arch team review?

@Dosant
Copy link
Copy Markdown
Contributor

Dosant commented Feb 17, 2020

ACK. Reviewing today

@Dosant Dosant self-requested a review February 17, 2020 15:24
Copy link
Copy Markdown
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.

LGTM!
Smoke checked in chrome. Tried both expanded url and hashed urls.

public initializeServices?: () => Promise<{ core: CoreStart; plugins: DiscoverStartPlugins }>;

setup(core: CoreSetup, plugins: DiscoverSetupPlugins): DiscoverSetup {
const { querySyncStateContainer, stop: stopQuerySyncStateContainer } = getQueryStateContainer(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

just fwd: working on improving this #56128

@maryia-lapata
Copy link
Copy Markdown
Contributor Author

@elasticmachine merge upstream

@kibanamachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

History

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

@maryia-lapata maryia-lapata merged commit 5b7734c into elastic:master Feb 18, 2020
@maryia-lapata maryia-lapata deleted the url-tracking branch February 18, 2020 10:55
maryia-lapata added a commit that referenced this pull request Feb 19, 2020
* Apply sub url tracking utils to visualize and discover

* Update query karma mock

* Remove unnecessary chrome legacy calls

* Fix typo

* Add setActiveUrl

* Add unit test for setActiveUrl

* Refactoring

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backported Feature:Discover Discover Application Feature:NP Migration release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Team label for Lens, elastic-charts, Graph, legacy editors (TSVB, Visualize, Timelion) t// v7.7.0 v8.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants