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

support reporting for new discover #184

Merged
merged 2 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading