From ce029eb965051259f27dbf43a004788b66cb25ad Mon Sep 17 00:00:00 2001 From: Joshua Li Date: Fri, 15 Sep 2023 16:57:43 +0000 Subject: [PATCH 1/2] support reporting for new discover Signed-off-by: Joshua Li --- public/components/context_menu/context_menu.js | 2 +- server/utils/__tests__/validationHelper.test.ts | 8 ++++++++ server/utils/validationHelper.ts | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/public/components/context_menu/context_menu.js b/public/components/context_menu/context_menu.js index 95c50d4d..92bed631 100644 --- a/public/components/context_menu/context_menu.js +++ b/public/components/context_menu/context_menu.js @@ -278,7 +278,7 @@ const isVisualizationNavMenu = (navMenu) => { function locationHashChanged() { const observer = new MutationObserver(function (mutations) { const navMenu = document.querySelectorAll( - 'span.osdTopNavMenu__wrapper > nav.euiHeaderLinks > div.euiHeaderLinks__list' + 'nav.euiHeaderLinks > div.euiHeaderLinks__list' ); if ( navMenu && diff --git a/server/utils/__tests__/validationHelper.test.ts b/server/utils/__tests__/validationHelper.test.ts index 3c2cb7b7..44caecae 100644 --- a/server/utils/__tests__/validationHelper.test.ts +++ b/server/utils/__tests__/validationHelper.test.ts @@ -215,6 +215,14 @@ describe('test input validation', () => { '/_dashboards/app/visualize&security_tenant=/.%2e/.%2e/.%2e/.%2e/_dashboards?#/view/id', false, ], + [ + '/app/data-explorer/discover/#/view/571aaf70-4c88-11e8-b3d7-01146121b73d', + true, + ], + [ + '/app/discoverLegacy#/view/571aaf70-4c88-11e8-b3d7-01146121b73d', + true, + ], ]; expect(urls.map((url) => isValidRelativeUrl(url[0]))).toEqual( urls.map((url) => url[1]) diff --git a/server/utils/validationHelper.ts b/server/utils/validationHelper.ts index bb2ee323..1700caf9 100644 --- a/server/utils/validationHelper.ts +++ b/server/utils/validationHelper.ts @@ -37,7 +37,7 @@ export const isValidRelativeUrl = (relativeUrl: string) => { export const regexDuration = /^(-?)P(?=\d|T\d)(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)([DW]))?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+(?:\.\d+)?)S)?)?$/; export const regexEmailAddress = /\S+@\S+\.\S+/; export const regexReportName = /^[\w\-\s\(\)\[\]\,\_\-+]+$/; -export const regexRelativeUrl = /^\/(_plugin\/kibana\/|_dashboards\/)?app\/(dashboards|visualize|discover|observability-dashboards|observability-notebooks|notebooks-dashboards\?view=output_only(&security_tenant=.+)?)(\?security_tenant=.+)?#\/(notebooks\/|view\/|edit\/)?[^\/]+$/; +export const regexRelativeUrl = /^\/(_plugin\/kibana\/|_dashboards\/)?app\/(dashboards|visualize|discover|discoverLegacy|data-explorer\/discover\/|observability-dashboards|observability-notebooks|notebooks-dashboards\?view=output_only(&security_tenant=.+)?)(\?security_tenant=.+)?#\/(notebooks\/|view\/|edit\/)?[^\/]+$/; export const validateReport = async ( client: ILegacyScopedClusterClient, From a654f3b4bc321dba30f982f2770d825424d88ca2 Mon Sep 17 00:00:00 2001 From: Joshua Li Date: Fri, 15 Sep 2023 17:22:08 +0000 Subject: [PATCH 2/2] fixup! support reporting for new discover Signed-off-by: Joshua Li --- public/components/context_menu/context_menu.js | 13 +++++++++---- server/utils/__tests__/validationHelper.test.ts | 4 ++++ server/utils/validationHelper.ts | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/public/components/context_menu/context_menu.js b/public/components/context_menu/context_menu.js index 92bed631..36cc142f 100644 --- a/public/components/context_menu/context_menu.js +++ b/public/components/context_menu/context_menu.js @@ -53,7 +53,7 @@ const generateInContextReport = async ( reportSource = 'Dashboard'; } else if (/\/app\/visualize/.test(baseUrl)) { reportSource = 'Visualization'; - } else if (/\/app\/discover/.test(baseUrl)) { + } else if (/\/app\/(discover|data-explorer)/.test(baseUrl)) { reportSource = 'Saved search'; } @@ -87,7 +87,7 @@ const generateInContextReport = async ( }; fetch( - `../api/reporting/generateReport?${new URLSearchParams( + `${getApiPath()}/reporting/generateReport?${new URLSearchParams( uiSettingsService.getSearchParams() )}`, { @@ -254,7 +254,7 @@ const checkURLParams = async () => { const isDiscoverNavMenu = (navMenu) => { return ( - navMenu[0].children.length === 5 && + navMenu[0].children.length === 6 && ($('[data-test-subj="breadcrumb first"]').prop('title') === 'Discover' || $('[data-test-subj="breadcrumb first last"]').prop('title') === 'Discover') @@ -335,8 +335,13 @@ window.onpopstate = history.onpushstate = () => { locationHashChanged(); }; +const getApiPath = () => { + if (window.location.href.includes('/data-explorer/discover')) return '../../api' + return '../api' +} + async function getTenantInfoIfExists() { - const res = await fetch(`../api/v1/multitenancy/tenant`, { + const res = await fetch(`${getApiPath()}/v1/multitenancy/tenant`, { headers: { 'Content-Type': 'application/json', 'osd-xsrf': 'reporting', diff --git a/server/utils/__tests__/validationHelper.test.ts b/server/utils/__tests__/validationHelper.test.ts index 44caecae..798409ad 100644 --- a/server/utils/__tests__/validationHelper.test.ts +++ b/server/utils/__tests__/validationHelper.test.ts @@ -219,6 +219,10 @@ describe('test input validation', () => { '/app/data-explorer/discover/#/view/571aaf70-4c88-11e8-b3d7-01146121b73d', true, ], + [ + '/app/data-explorer/discover?security_tenant=private#/view/571aaf70-4c88-11e8-b3d7-01146121b73d', + true, + ], [ '/app/discoverLegacy#/view/571aaf70-4c88-11e8-b3d7-01146121b73d', true, diff --git a/server/utils/validationHelper.ts b/server/utils/validationHelper.ts index 1700caf9..08fa1b4a 100644 --- a/server/utils/validationHelper.ts +++ b/server/utils/validationHelper.ts @@ -37,7 +37,7 @@ export const isValidRelativeUrl = (relativeUrl: string) => { export const regexDuration = /^(-?)P(?=\d|T\d)(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)([DW]))?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+(?:\.\d+)?)S)?)?$/; export const regexEmailAddress = /\S+@\S+\.\S+/; export const regexReportName = /^[\w\-\s\(\)\[\]\,\_\-+]+$/; -export const regexRelativeUrl = /^\/(_plugin\/kibana\/|_dashboards\/)?app\/(dashboards|visualize|discover|discoverLegacy|data-explorer\/discover\/|observability-dashboards|observability-notebooks|notebooks-dashboards\?view=output_only(&security_tenant=.+)?)(\?security_tenant=.+)?#\/(notebooks\/|view\/|edit\/)?[^\/]+$/; +export const regexRelativeUrl = /^\/(_plugin\/kibana\/|_dashboards\/)?app\/(dashboards|visualize|discover|discoverLegacy|data-explorer\/discover\/?|observability-dashboards|observability-notebooks|notebooks-dashboards\?view=output_only(&security_tenant=.+)?)(\?security_tenant=.+)?#\/(notebooks\/|view\/|edit\/)?[^\/]+$/; export const validateReport = async ( client: ILegacyScopedClusterClient,