[dev tools] Hide app link when there are no tools (#9489)

* [dev tools] Hide app link when there are no tools

* [dev tools] Add tests for setting app as hidden
This commit is contained in:
Jonathan Budzenski 2016-12-15 20:50:45 -06:00 committed by GitHub
parent cb3219c798
commit 3144994c19
4 changed files with 57 additions and 0 deletions

View file

@ -74,6 +74,7 @@ module.exports = function (kibana) {
description: 'compose visualizations for much win',
icon: 'plugins/kibana/assets/dashboard.svg',
}, {
id: 'kibana:dev_tools',
title: 'Dev Tools',
order: 9001,
url: '/app/kibana#/dev_tools',

View file

@ -0,0 +1,44 @@
import ngMock from 'ng_mock';
import expect from 'expect.js';
import sinon from 'sinon';
import chrome from 'ui/chrome';
import { hideEmptyDevTools } from '../hide_empty_tools';
describe('hide dev tools', function () {
let Private;
let navlinks;
function PrivateWithoutTools() {
return [];
}
function PrivateWithTools() {
return ['tool1', 'tool2'];
}
function isHidden() {
return !!chrome.getNavLinkById('kibana:dev_tools').hidden;
}
beforeEach(function () {
navlinks = {};
sinon.stub(chrome, 'getNavLinkById',function () {
return navlinks;
});
});
it('should hide the app if there are no dev tools', function () {
hideEmptyDevTools(PrivateWithTools);
expect(isHidden()).to.be(false);
});
it('should not hide the app if there are tools', function () {
hideEmptyDevTools(PrivateWithoutTools);
expect(isHidden()).to.be(true);
});
afterEach(function () {
chrome.getNavLinkById.restore();
});
});

View file

@ -0,0 +1,10 @@
import chrome from 'ui/chrome';
import DevToolsRegistryProvider from 'ui/registry/dev_tools';
export function hideEmptyDevTools(Private) {
const hasTools = !!Private(DevToolsRegistryProvider).length;
if (!hasTools) {
const navLink = chrome.getNavLinkById('kibana:dev_tools');
navLink.hidden = true;
}
}

View file

@ -20,6 +20,7 @@ import 'ui/agg_types';
import 'ui/timepicker';
import Notifier from 'ui/notify/notifier';
import 'leaflet';
import { hideEmptyDevTools } from './dev_tools/lib/hide_empty_tools';
routes.enable();
@ -49,3 +50,4 @@ chrome
});
modules.get('kibana').run(Notifier.pullMessageFromUrl);
modules.get('kibana').run(hideEmptyDevTools);