Apply sub url tracking utils to visualize and discover#57307
Apply sub url tracking utils to visualize and discover#57307maryia-lapata merged 15 commits intoelastic:masterfrom
Conversation
|
Pinging @elastic/kibana-app (Team:KibanaApp) |
flash1293
left a comment
There was a problem hiding this comment.
- In
src/legacy/core_plugins/kibana/index.jsdisableSubUrlTracking: truehas 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.jslegacy 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.jslegacy 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, kibana/src/legacy/ui/public/chrome/api/nav.ts Lines 109 to 110 in 7e753e9 b) Secondly, even if I define linkToLastSub -> linkToLastSubUrl.
If I apply a and b, Probably I miss something, but it doesn't make sense for me. Anyway since the visualize app doesn't have truly |
# 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()); | |||
There was a problem hiding this comment.
@flash1293 also I noticed that this new history state doesn't trigger history listener:
So in this PR just #/visualize/create link is saved and opens by clicking on Visualize in nav bar.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@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?
There was a problem hiding this comment.
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).
|
For 2 I agree that it doesn't make sense, let's remove that one. For 1
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. |
pgayvallet
left a comment
There was a problem hiding this comment.
LGTM for platform changes
| ...npSetup.plugins, | ||
| __LEGACY: { | ||
| legacyChrome, | ||
| }, | ||
| npData: npSetup.plugins.data, |
There was a problem hiding this comment.
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?
flash1293
left a comment
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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
# 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(); |
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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?
|
@Dosant can you check this one out for the app arch team review? |
|
ACK. Reviewing today |
Dosant
left a comment
There was a problem hiding this comment.
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( |
|
@elasticmachine merge upstream |
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
* 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>
This PR applies the new sub url tracking utils from #55818 to the Visualize and Discover plugins.