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

Navbar directive #5940

Merged
merged 5 commits into from
Jan 22, 2016
Merged

Navbar directive #5940

merged 5 commits into from
Jan 22, 2016

Conversation

w33ble
Copy link
Contributor

@w33ble w33ble commented Jan 19, 2016

Uses navbarExtensions to inject controls into the navbar

  • Turns <navbar> into a directive, injecting controls based on its name attribute
    • Mapped to appName in the registry objects
    • Sorted by order, default controls are order 0
      • Allow controls to be injected before the Kibana defaults

Closes #5198

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) {
Copy link
Contributor

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
    };
  })
]

Copy link
Contributor Author

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!

@spalger
Copy link
Contributor

spalger commented Jan 21, 2016

Made a couple non-required suggestions. LGTM

@spalger spalger assigned w33ble and unassigned spalger Jan 21, 2016
@spalger
Copy link
Contributor

spalger commented Jan 22, 2016

LGTM

w33ble added a commit that referenced this pull request Jan 22, 2016
@w33ble w33ble merged commit f028601 into elastic:master Jan 22, 2016
@tbragin tbragin added the v5.0.0 label Mar 17, 2016
@blachniet
Copy link

Are there any sample navbar injection plugins that we could use as a reference for building our own?

@w33ble
Copy link
Contributor Author

w33ble commented Jul 1, 2016

@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 navbar_extensions registry, and the format is the same as any other kbn_top_nav item. kbn_top_nav_controller is the best source of available parameters for the definition. Here's an example of how it's used in Discover.

Using this in your plugin requires 2 parts. First, you define your navbarExtensions via the uiExports property when you created you Kibana Plugin instance, similar to this:

return new kibana.Plugin({
    id: 'my-plugin',
    require: ['kibana'],

    uiExports: {
      navbarExtensions: [
        'plugins/my-plugin/path/to/definition'
      ],
    },
});

Then in your plugin's public/path/to/definition.js file:

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 name property comes from the attribute on the kbn-top-nav directive. Here's it being used in Discover

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 run property in the definition; the New Search control in Discover is a good example.

I hope that's helpful.

@varunsharma27
Copy link
Contributor

varunsharma27 commented Aug 7, 2017

Would it be possible to inject controls to navBar and hide it (Using hideButton()) when viewMode:edit?
(navbar for dashboardApp)

@trevan
Copy link
Contributor

trevan commented Aug 7, 2017

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants