mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[chrome] Implement app-level lastPath
We have always tracked the lastPath for tabs on the page, which means that clicking from one to the other restores your previous state. Now we are tracking the lastUrls for each app and using them in the appSwitcher so that the appSwitcher properly links to the last state of each app.
This commit is contained in:
parent
1bcd867f49
commit
5d22b9351e
3 changed files with 25 additions and 8 deletions
|
@ -1,4 +1,5 @@
|
|||
var _ = require('lodash');
|
||||
var reEsc = require('lodash').escapeRegExp;
|
||||
var storage = window.sessionStorage;
|
||||
|
||||
function Tab(spec) {
|
||||
|
@ -8,6 +9,7 @@ function Tab(spec) {
|
|||
this.resetWhenActive = !!spec.resetWhenActive;
|
||||
this.lastUrlStoreKey = spec.trackLastPath ? 'lastUrl:' + this.id : null;
|
||||
this.rootUrl = '/' + this.id;
|
||||
this.rootRegExp = new RegExp(`^${reEsc(this.rootUrl)}(/|$|\\?)`);
|
||||
this.lastUrl = this.lastUrlStoreKey && storage.getItem(this.lastUrlStoreKey);
|
||||
|
||||
this.activeIndicatorColor = spec.activeIndicatorColor || null;
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
var _ = require('lodash');
|
||||
var { startsWith } = require('lodash');
|
||||
var Tab = require('ui/chrome/Tab');
|
||||
var format = require('url').format;
|
||||
var parse = _.wrap(require('url').parse, function (parse, path) {
|
||||
var { format, parse } = require('url');
|
||||
var storage = window.sessionStorage;
|
||||
|
||||
parse = _.wrap(parse, function (parse, path) {
|
||||
var parsed = parse(path, true);
|
||||
return {
|
||||
pathname: parsed.pathname,
|
||||
|
@ -42,19 +45,23 @@ function TabCollection() {
|
|||
return activeTab;
|
||||
};
|
||||
|
||||
this.consumeRouteUpdate = function ($location, persist) {
|
||||
var url = parse($location.url(), true);
|
||||
var id = $location.path().split('/')[1] || '';
|
||||
this.consumeRouteUpdate = function (appId, href, path, persist) {
|
||||
var url = parse(href, true);
|
||||
|
||||
tabs.forEach(function (tab) {
|
||||
var active = tab.active = (tab.id === id);
|
||||
var lastUrl = active ? url : parse(tab.lastUrl || tab.rootUrl);
|
||||
tab.active = tab.rootRegExp.test(path);
|
||||
|
||||
var lastUrl = tab.active ? url : parse(tab.lastUrl || tab.rootUrl);
|
||||
lastUrl.query._g = url.query._g;
|
||||
|
||||
if (tab.active) activeTab = tab;
|
||||
if (persist) {
|
||||
tab.persistLastUrl(format(lastUrl));
|
||||
}
|
||||
|
||||
if (tab.active) {
|
||||
storage.setItem(`appLastUrl:${appId}`, href);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
10
src/ui/public/chrome/api/angular.js
vendored
10
src/ui/public/chrome/api/angular.js
vendored
|
@ -44,7 +44,15 @@ module.exports = function (chrome, internals) {
|
|||
chrome.setVisible(!Boolean($location.search().embed));
|
||||
|
||||
// listen for route changes, propogate to tabs
|
||||
var onRouteChange = _.bindKey(internals.tabs, 'consumeRouteUpdate', $location, chrome.getVisible());
|
||||
var onRouteChange = function () {
|
||||
internals.tabs.consumeRouteUpdate(
|
||||
chrome.getAppId(),
|
||||
window.location.href,
|
||||
$location.url(),
|
||||
chrome.getVisible()
|
||||
);
|
||||
};
|
||||
|
||||
$rootScope.$on('$routeChangeSuccess', onRouteChange);
|
||||
$rootScope.$on('$routeUpdate', onRouteChange);
|
||||
onRouteChange();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue