Skip to content

Commit

Permalink
[dev tools] Hide app link when there are no tools (#9517)
Browse files Browse the repository at this point in the history
Backports PR #9489

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

* Original sha: ace40c4
* Authored by Jonathan Budzenski <[email protected]> on 2016-12-01T18:10:07Z

**Commit 2:**
[dev tools] Add tests for setting app as hidden

* Original sha: 7828524
* Authored by Jonathan Budzenski <[email protected]> on 2016-12-15T21:08:20Z
  • Loading branch information
elastic-jasper authored and jbudz committed Dec 16, 2016
1 parent da4c0b4 commit 38975e2
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/core_plugins/kibana/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,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',
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
});
});
10 changes: 10 additions & 0 deletions src/core_plugins/kibana/public/dev_tools/lib/hide_empty_tools.js
Original file line number Diff line number Diff line change
@@ -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;
}
}
2 changes: 2 additions & 0 deletions src/core_plugins/kibana/public/kibana.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -49,3 +50,4 @@ chrome
});

modules.get('kibana').run(Notifier.pullMessageFromUrl);
modules.get('kibana').run(hideEmptyDevTools);

0 comments on commit 38975e2

Please sign in to comment.