From d0ee8b175446ade70c4653f6796ff094dc69f88c Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Fri, 1 Jul 2016 03:00:13 -0700 Subject: [PATCH 01/19] Method to get nav link by its title + control nav link display state Former-commit-id: 8df249beec21f1cc7e3ed0a39dccda435f379446 --- src/ui/public/chrome/api/__tests__/nav.js | 13 +++++++++++++ src/ui/public/chrome/api/nav.js | 4 ++++ .../directives/app_switcher/app_switcher.html | 5 +++-- .../chrome/directives/app_switcher/app_switcher.js | 12 +++++++++--- .../directives/app_switcher/app_switcher.less | 9 ++++++++- 5 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/ui/public/chrome/api/__tests__/nav.js b/src/ui/public/chrome/api/__tests__/nav.js index 8dffa7e4eebbe..3e728dfc60ead 100644 --- a/src/ui/public/chrome/api/__tests__/nav.js +++ b/src/ui/public/chrome/api/__tests__/nav.js @@ -45,6 +45,19 @@ describe('chrome nav apis', function () { }); }); + describe('#getNavLinkByTitle', () => { + it ('retrieves the correct nav link, given its title', () => { + const nav = [ + { title: 'Discover', url: 'https://localhost:9200/app/kibana#discover' } + ]; + const { chrome, internals } = init({ nav }); + + const navLink = chrome.getNavLinkByTitle('Discover'); + expect(navLink).to.not.be(undefined); + expect(navLink.url).to.be('https://localhost:9200/app/kibana#discover'); + }); + }); + describe('internals.trackPossibleSubUrl()', function () { it('injects the globalState of the current url to all links for the same app', function () { const appUrlStore = new StubBrowserStorage(); diff --git a/src/ui/public/chrome/api/nav.js b/src/ui/public/chrome/api/nav.js index fc815a34163a8..706468029fade 100644 --- a/src/ui/public/chrome/api/nav.js +++ b/src/ui/public/chrome/api/nav.js @@ -6,6 +6,10 @@ export default function (chrome, internals) { return internals.nav; }; + chrome.getNavLinkByTitle = (title) => { + return find(internals.nav, link => link.title === title); + }; + chrome.getBasePath = function () { return internals.basePath || ''; }; diff --git a/src/ui/public/chrome/directives/app_switcher/app_switcher.html b/src/ui/public/chrome/directives/app_switcher/app_switcher.html index 1e0a0d0e665da..9f24453728f5b 100644 --- a/src/ui/public/chrome/directives/app_switcher/app_switcher.html +++ b/src/ui/public/chrome/directives/app_switcher/app_switcher.html @@ -1,8 +1,9 @@