From 87ef5f137a09895d11ca6bc979fc36ea2a7543d8 Mon Sep 17 00:00:00 2001 From: David Cui <53581635+davidcui-amzn@users.noreply.github.com> Date: Fri, 8 Jan 2021 16:30:19 -0800 Subject: [PATCH] backport context menu changes to 7.9.1, move dropdown menu location for Discover --- .../components/context_menu/context_menu.js | 28 +- .../context_menu/context_menu_ui.js | 2 +- .../target/public/.kbn-optimizer-cache | 370 +++++++++--------- kibana-reports/target/public/0.plugin.js | 6 +- kibana-reports/target/public/0.plugin.js.map | 2 +- .../opendistro_kibana_reports.plugin.js | 81 ++-- .../opendistro_kibana_reports.plugin.js.map | 2 +- 7 files changed, 262 insertions(+), 229 deletions(-) diff --git a/kibana-reports/public/components/context_menu/context_menu.js b/kibana-reports/public/components/context_menu/context_menu.js index a55d5e61..a15ecae1 100644 --- a/kibana-reports/public/components/context_menu/context_menu.js +++ b/kibana-reports/public/components/context_menu/context_menu.js @@ -227,12 +227,34 @@ $(function () { locationHashChanged(); }); +const isDiscoverNavMenu = (navMenu) => { + return navMenu[0].children.length === 5 && + ($('[data-test-subj="breadcrumb first"]').prop('title') === 'Discover' || + $('[data-test-subj="breadcrumb first last"]').prop('title') === 'Discover') +} + +const isDashboardNavMenu = (navMenu) => { + return (navMenu[0].children.length === 4 || navMenu[0].children.length === 6) && + ($('[data-test-subj="breadcrumb first"]').prop('title') === 'Dashboard') +} + +const isVisualizationNavMenu = (navMenu) => { + return navMenu[0].children.length === 3 + && ($('[data-test-subj="breadcrumb first"]').prop('title') === 'Visualize') +} + + + function locationHashChanged() { const observer = new MutationObserver(function (mutations) { const navMenu = document.querySelectorAll( 'span.kbnTopNavMenu__wrapper > div.euiFlexGroup' ); - if (navMenu && navMenu.length && navMenu[0].children.length > 1) { + if (navMenu && navMenu.length && ( + isDiscoverNavMenu(navMenu) || + isDashboardNavMenu(navMenu) || + isVisualizationNavMenu(navMenu)) + ) { try { if ($('#downloadReport').length) { return; @@ -263,9 +285,9 @@ const getUuidFromUrl = () => ); const isDiscover = () => window.location.href.includes('discover'); -window.onhashchange = function () { +$(window).one('hashchange', function( e ) { locationHashChanged(); -}; +}); /** * for navigating to tabs from Kibana sidebar, it uses history.pushState, which doesn't trigger onHashchange. * https://stackoverflow.com/questions/4570093/how-to-get-notified-about-changes-of-the-history-via-history-pushstate/4585031 diff --git a/kibana-reports/public/components/context_menu/context_menu_ui.js b/kibana-reports/public/components/context_menu/context_menu_ui.js index 1955d4d3..94d07f1b 100644 --- a/kibana-reports/public/components/context_menu/context_menu_ui.js +++ b/kibana-reports/public/components/context_menu/context_menu_ui.js @@ -142,7 +142,7 @@ export const popoverMenuDiscover = (savedObjectAvailable) => {