Skip to content

Commit

Permalink
support reporting for new discover (#184)
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Li <[email protected]>
  • Loading branch information
joshuali925 authored Sep 15, 2023
1 parent 7b1fe25 commit baafdf1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
15 changes: 10 additions & 5 deletions public/components/context_menu/context_menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

Expand Down Expand Up @@ -87,7 +87,7 @@ const generateInContextReport = async (
};

fetch(
`../api/reporting/generateReport?${new URLSearchParams(
`${getApiPath()}/reporting/generateReport?${new URLSearchParams(
uiSettingsService.getSearchParams()
)}`,
{
Expand Down Expand Up @@ -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')
Expand All @@ -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 &&
Expand Down Expand Up @@ -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',
Expand Down
12 changes: 12 additions & 0 deletions server/utils/__tests__/validationHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,18 @@ 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/data-explorer/discover?security_tenant=private#/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])
Expand Down
2 changes: 1 addition & 1 deletion server/utils/validationHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit baafdf1

Please sign in to comment.