Skip to content

Commit

Permalink
Merge pull request #6170 from panda01/fix/nav-details
Browse files Browse the repository at this point in the history
Fix/nav details
  • Loading branch information
panda01 committed Feb 10, 2016
2 parents 40a21b9 + 180aacd commit af5f0b6
Show file tree
Hide file tree
Showing 29 changed files with 462 additions and 133 deletions.
37 changes: 35 additions & 2 deletions src/plugins/kibana/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import ingest from './server/routes/api/ingest';

module.exports = function (kibana) {
return new kibana.Plugin({

id: 'kibana',
config: function (Joi) {
return Joi.object({
enabled: Joi.boolean().default(true),
Expand All @@ -13,7 +13,9 @@ module.exports = function (kibana) {

uiExports: {
app: {
id: 'kibana',
title: 'Kibana',
listed: false,
description: 'the kibana you know and love',
//icon: 'plugins/kibana/settings/sections/about/barcode.svg',
main: 'plugins/kibana/kibana',
Expand All @@ -32,8 +34,39 @@ module.exports = function (kibana) {
return {
kbnDefaultAppId: config.get('kibana.defaultAppId')
};
},
},

links: [
{
title: 'Discover',
order: -1003,
url: '/app/kibana#/discover',
description: 'interactively explore your data',
icon: 'plugins/kibana/assets/discover.svg',
},
{
title: 'Visualize',
order: -1002,
url: '/app/kibana#/visualize',
description: 'design data visualizations',
icon: 'plugins/kibana/assets/visualize.svg',
},
{
title: 'Dashboard',
order: -1001,
url: '/app/kibana#/dashboard',
description: 'compose visualizations for much win',
icon: 'plugins/kibana/assets/dashboard.svg',
},
{
title: 'Settings',
order: 1000,
url: '/app/kibana#/settings',
description: 'define index patterns, change config, and more',
icon: 'plugins/kibana/assets/settings.svg',
}
}
]
},

init: function (server, options) {
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/kibana/public/assets/dashboard.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/plugins/kibana/public/assets/discover.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/plugins/kibana/public/assets/logout.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/plugins/kibana/public/assets/search.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/plugins/kibana/public/assets/settings.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/plugins/kibana/public/assets/visualize.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions src/plugins/kibana/public/kibana.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ routes

chrome
.setBrand({
'logo': 'url(' + kibanaLogoUrl + ') center / 160px 70px no-repeat #e8488b',
'smallLogo': 'url(' + kibanaLogoUrl + ') center / 160px 70px no-repeat #e8488b'
'logo': 'url(' + kibanaLogoUrl + ') 6px 10px / 140px 50px no-repeat #e8488b',
'smallLogo': 'url(' + kibanaLogoUrl + ') 6px 10px / 140px 50px no-repeat #e8488b'
})
.setNavBackground('#222222')
.setTabDefaults({
resetWhenActive: true,
lastUrlStore: window.sessionStore,
lastUrlStore: window.sessionStorage,
activeIndicatorColor: '#656a76'
})
.setTabs([
Expand Down
5 changes: 5 additions & 0 deletions src/plugins/statusPage/public/statusPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,8 @@ const chrome = require('ui/chrome')

ui.refresh();
});

require('ui/modules').get('kibana')
.config(function (appSwitcherEnsureNavigationProvider) {
appSwitcherEnsureNavigationProvider.forceNavigation(true);
});
2 changes: 1 addition & 1 deletion src/ui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ module.exports = async (kbnServer, server, config) => {
server.decorate('reply', 'renderApp', function (app) {
const payload = {
app: app,
nav: uiExports.apps,
nav: uiExports.navLinks.inOrder,
version: kbnServer.version,
buildNum: config.get('pkg.buildNum'),
buildSha: config.get('pkg.buildSha'),
Expand Down
15 changes: 13 additions & 2 deletions src/ui/public/chrome/Tab.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import notify from 'ui/notify';
import _ from 'lodash';
import { escapeRegExp as reEsc } from 'lodash';
import { parse, format } from 'url';
Expand Down Expand Up @@ -28,7 +29,16 @@ export default class Tab {

this.lastUrlStoreKey = `lastUrl:${this.id}`;
this.lastUrlStore = spec.lastUrlStore;
this.lastUrl = this.lastUrlStore ? this.lastUrlStore.getItem(this.lastUrlStoreKey) : null;

this.lastUrl = null;
if (this.lastUrlStore) {
this.lastUrl = this.lastUrlStore.getItem(this.lastUrlStoreKey);
if (this.lastUrl && !this.lastUrl.startsWith(this.rootUrl)) {
notify.log(`Found invalid lastUrl for tab with root url ${this.rootUrl}: "${this.lastUrl}"`);
this.lastUrl = null;
this.lastUrlStore.removeItem(this.lastUrlStoreKey);
}
}
}

href() {
Expand All @@ -54,7 +64,8 @@ export default class Tab {
let lastUrl = this.getLastUrl();

if (!lastUrl.startsWith(rootUrl)) {
throw new Error(`Tab "${id}" has invalid root "${rootUrl}" for last url "${lastUrl}"`);
notify.log(`Tab "${id}" has invalid root "${rootUrl}" for last url "${lastUrl}"`);
lastUrl = rootUrl;
}

return lastUrl.slice(rootUrl.length);
Expand Down
34 changes: 23 additions & 11 deletions src/ui/public/chrome/__tests__/Tab.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sinon from 'auto-release-sinon';
import Tab from '../Tab';
import expect from 'expect.js';
import TabFakeStore from './_TabFakeStore';
Expand Down Expand Up @@ -89,13 +90,24 @@ describe('Chrome Tab', function () {
it('discovers the lastUrl', function () {
const lastUrlStore = new TabFakeStore();
const tab = new Tab({ id: 'foo', lastUrlStore });
expect(tab.lastUrl).to.not.equal('bar');
expect(tab.lastUrl).to.not.equal('/foo/bar');

tab.setLastUrl('bar');
expect(tab.lastUrl).to.equal('bar');
tab.setLastUrl('/foo/bar');
expect(tab.lastUrl).to.equal('/foo/bar');

const tab2 = new Tab({ id: 'foo', lastUrlStore });
expect(tab2.lastUrl).to.equal('bar');
expect(tab2.lastUrl).to.equal('/foo/bar');
});

it('logs a warning about last urls that do not match the rootUrl', function () {
const lastUrlStore = new TabFakeStore();
const tab = new Tab({ id: 'foo', baseUrl: '/bar', lastUrlStore });
tab.setLastUrl('/bar/foo/1');

const stub = sinon.stub(console, 'log');
const tab2 = new Tab({ id: 'foo', baseUrl: '/baz', lastUrlStore });
sinon.assert.calledOnce(stub);
expect(tab2.lastUrl).to.equal(null);
});
});

Expand Down Expand Up @@ -167,14 +179,14 @@ describe('Chrome Tab', function () {
expect(tab.getLastPath()).to.equal('/index');
});

it('throws an error if the lastUrl does not extend the root url', function () {
expect(function () {
const baseUrl = 'http://local:5601/app/visualize#';
const tab = new Tab({ baseUrl });
it('logs a warning if the lastUrl does not extend the root url', function () {
const baseUrl = 'http://local:5601/app/visualize#';
const tab = new Tab({ baseUrl });
sinon.stub(console, 'log');

tab.setLastUrl('http://local:5601/');
tab.getLastPath();
}).to.throwError(/invalid.*root/);
tab.setLastUrl('http://local:5601/');
tab.getLastPath();
sinon.assert.calledOnce(console.log);// eslint-disable-line no-console
});
});

Expand Down
1 change: 1 addition & 0 deletions src/ui/public/chrome/__tests__/_TabFakeStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export default class TabFakeStore {
constructor() { this[store] = new Map(); }
getItem(k) { return this[store].get(k); }
setItem(k, v) { return this[store].set(k, v); }
removeItem(k) { return this[store].delete(k); }
getKeys() { return [ ...this[store].keys() ]; }
getValues() { return [ ...this[store].values() ]; }
}
4 changes: 2 additions & 2 deletions src/ui/public/chrome/api/__tests__/apps.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ describe('Chrome API :: apps', function () {
describe('#getAppUrl()', function () {
it('returns the resolved url of the current app', function () {
const chrome = {};
const app = { url: '/foo' };
const app = { navLink: { url: '/foo' } };
setup(chrome, { app });

const a = document.createElement('a');
a.setAttribute('href', app.url);
a.setAttribute('href', app.navLink.url);
expect(chrome.getAppUrl()).to.equal(a.href);
});

Expand Down
6 changes: 3 additions & 3 deletions src/ui/public/chrome/api/apps.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { resolve } from 'url';

module.exports = function (chrome, internals) {

if (internals.app) {
internals.app.url = resolve(window.location.href, internals.app.url);
if (get(internals, 'app.navLink.url')) {
internals.app.navLink.url = resolve(window.location.href, internals.app.navLink.url);
}

internals.appUrlStore = internals.appUrlStore || window.sessionStorage;
Expand Down Expand Up @@ -35,7 +35,7 @@ module.exports = function (chrome, internals) {
};

chrome.getAppUrl = function () {
return get(internals, ['app', 'url']);
return get(internals, ['app', 'navLink', 'url']);
};

chrome.getInjected = function (name, def) {
Expand Down
44 changes: 30 additions & 14 deletions src/ui/public/chrome/api/nav.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { parse, format } from 'url';
import { startsWith, isString } from 'lodash';
import { startsWith, isString, find } from 'lodash';

export default function (chrome, internals) {
chrome.getNavLinks = function () {
return internals.nav;
};

chrome.getLastSubUrlFor = function (url) {
return internals.appUrlStore.getItem(`lastSubUrl:${url}`);
};

chrome.getBasePath = function () {
return internals.basePath || '';
};
Expand All @@ -34,26 +30,46 @@ export default function (chrome, internals) {
});
};

function lastSubUrlKey(link) {
return `lastSubUrl:${link.url}`;
}

function setLastUrl(link, url) {
link.lastSubUrl = url;
internals.appUrlStore.setItem(lastSubUrlKey(link), url);
}

function refreshLastUrl(link) {
link.lastSubUrl = internals.appUrlStore.getItem(lastSubUrlKey(link));
}

internals.trackPossibleSubUrl = function (url) {
for (const link of internals.nav) {
if (startsWith(url, link.url)) {
link.lastSubUrl = url;
internals.appUrlStore.setItem(`lastSubUrl:${link.url}`, url);
link.active = startsWith(url, link.url);

if (link.active) {
setLastUrl(link, url);
continue;
}

const matchingTab = find(internals.tabs, { rootUrl: link.url });
if (matchingTab) {
setLastUrl(link, matchingTab.getLastUrl());
continue;
}

refreshLastUrl(link);
}
};

internals.nav.forEach(link => {
// convert all link urls to absolute urls

var a = document.createElement('a');
a.setAttribute('href', link.url);
link.url = a.href;
link.lastSubUrl = chrome.getLastSubUrlFor(link.url);

if (link.url === chrome.getAppUrl()) {
link.active = true;
}
});

// simulate a possible change in url to initialize the
// link.active and link.lastUrl properties
internals.trackPossibleSubUrl(document.location.href);
};
Loading

0 comments on commit af5f0b6

Please sign in to comment.