-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Navbar directive #5940
Navbar directive #5940
Conversation
used anywhere the navbar is being used currently
if ($buttonGroup.length !== 1) throw new Error('navbar must have exactly 1 button group'); | ||
|
||
const extensions = getExtensions($attrs.name); | ||
const controls = $buttonGroup.children().detach().toArray().map(function (button) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this would probably read cleaner if it was broken up a bit. Also, _spread 'em!_
const buttons = $buttonGroup.children().detach().toArray();
const controls = [
...buttons.map((button) => {
return {
order: 0,
$el: $(button)
};
}),
...extensions.map((extension, index) => {
return {
extension,
index,
order: extension.order
};
})
]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oooooh, I hadn't thought about spread that way before. That's hawt!
Made a couple non-required suggestions. LGTM |
LGTM |
Are there any sample navbar injection plugins that we could use as a reference for building our own? |
@blachniet not currently, and also note that the structure is changing with #7508. That PR basically makes it work the same as any other top nav link. Basically, items are are added to the Using this in your plugin requires 2 parts. First, you define your return new kibana.Plugin({
id: 'my-plugin',
require: ['kibana'],
uiExports: {
navbarExtensions: [
'plugins/my-plugin/path/to/definition'
],
},
}); Then in your plugin's const navbarExtensions = require('ui/registry/navbar_extensions');
function myPluginControlProvider() {
return {
appName: 'discover', // the name of the app you want to inject into
key: 'my-plugin-control', // unique key/name for your control
label: 'Click Me', // [optional] label to use, otherwise it uses whatever you put in 'key'
template: '<h1>OH HAI!</h1>', // [optional] markup to inject into the "config" section below the menu
description: 'Dashboard Report', // [optional] aria-label, may get a tooltip in the future, uses 'key' by default
};
}
navbarExtensions.register(myPluginControlProvider); Note that the If you don't need to add controls in the "config" section under the menu, but instead just need to do something once your control is clicked, you use the I hope that's helpful. |
Would it be possible to inject controls to navBar and hide it (Using hideButton()) when viewMode:edit? |
@varundbest, yes it is possible. Inject "getAppState" into your registered function to create the navbar extension and then "getAppState().viewMode === 'edit'" will return true if it is in edit mode. |
Uses navbarExtensions to inject controls into the navbar
<navbar>
into a directive, injecting controls based on itsname
attributeappName
in the registry objectsorder
, default controls are order 0Closes #5198