Hide nav btn on route changes

I create a button for visualize and put it on navigation bar

import { NavBarExtensionsRegistryProvider } from 'ui/registry/navbar_extensions';
import chrome from 'ui/chrome';

function visualizeControlProvider($http) {
   return {
     appName: 'visualize',
     key: 'visualize-extra-button',
     label: 'Extra',
     run: (elm, prop) => {},
     hideButton: false // This is the problem
   };
}

NavBarExtensionsRegistryProvider.register(($http) => {
   return visualizeControlProvider($http);
});

The issue is, I want to dynamically hide the button upon route changes. So I want to hide the button if it's on the grid list view of visualize while show the button when on edit/create mode.

Been trying to use $onRouteChanges, but didn't work

Hey @jetpumz, if you inject the $location service you can use a function for hideButton to determine if it's visible or not.

Something like this should work:

import { NavBarExtensionsRegistryProvider } from 'ui/registry/navbar_extensions';
import chrome from 'ui/chrome';

function visualizeControlProvider($http, $location) {
   return {
     appName: 'visualize',
     key: 'visualize-extra-button',
     label: 'Extra',
     run: (elm, prop) => {},
     hideButton: () => {
       return $location.path() === `/visualize`;
     }
   };
}

NavBarExtensionsRegistryProvider.register(($http) => {
   return visualizeControlProvider($http);
});

Hi @Brandon_Kobel Thanks for the reply, actually I managed to do it using

getAppState()

service that kibana has. But thanks for the feedback !

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.