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

Fix/nav details #6170

Merged
merged 27 commits into from
Feb 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
72ef16f
[uiExports][chrome] support uiExports.links
spalger Jan 26, 2016
517bf71
[tabs] persist last urls to sessionStorage
spalger Jan 26, 2016
6892bfa
[appSwitcher] allow hash-based navigation by default, disable on stat…
spalger Jan 26, 2016
1f372bf
[appSwitcher] when tabs match links, use their last Url
spalger Jan 26, 2016
0b56954
[chrome] fix broken test
spalger Jan 26, 2016
90977e6
Merge branch 'master' into implement/exportLinks
spalger Jan 26, 2016
f5ff46a
[chrome/tab] ignore lastUrls that have different basePaths
spalger Jan 26, 2016
8f4b48f
[chrome/Tab] fix tests
spalger Jan 30, 2016
775812a
Merge branch 'master' into implement/exportLinks
spalger Feb 2, 2016
eef94c7
[appSwitcher] es6-ify
spalger Feb 2, 2016
5de1094
[chrome/api/apps] use path getter rather than multiple checks
spalger Feb 2, 2016
b5ca051
[ui/UiApp] dress like a cool kid
spalger Feb 2, 2016
bc4dce1
[ui/uiNav*] es6-ify
spalger Feb 2, 2016
f2c85d9
Merge branch 'design' into implement/exportLinks
simianhacker Feb 8, 2016
a75df51
Change svg to be inkscape compatible
Feb 8, 2016
0a1b516
Add padding around logo
Feb 8, 2016
3abd125
Add drop shadow, hover effect, center icons vertically
Feb 8, 2016
e106eb9
Move logo text up. Reduce width of sidebar to 160px
Feb 8, 2016
d831293
Adding svgs and CSS for nav
simianhacker Feb 9, 2016
f9d9beb
Fix merge
Feb 9, 2016
3100a2f
Add flex container inside app-wrapper, attach shadow to that
Feb 9, 2016
e7c98c0
Fix icons in firefox
Feb 9, 2016
4dbba2f
[Icons] vertically aligned the icons
panda01 Feb 9, 2016
b2e0ff1
Merge remote-tracking branch 'upstream/feature/design' into fix/nav-d…
panda01 Feb 9, 2016
5b1576f
[Tests] Updated the tests with thte proper selector
panda01 Feb 9, 2016
6afcb8c
[AppSwitcher] expanded the less so it's more understandable
panda01 Feb 10, 2016
180aacd
Merge remote-tracking branch 'upstream/feature/design' into fix/nav-d…
panda01 Feb 10, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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