Skip to content

Commit

Permalink
Use output_only Parameter for notebook reports (opensearch-project#32)
Browse files Browse the repository at this point in the history
Signed-off-by: David Cui <davidcui@amazon.com>
  • Loading branch information
davidcui1225 authored May 10, 2021
1 parent da058bc commit 457539b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,19 @@ export const getNotebooksBaseUrlCreate = (
if (!fromInContext) {
baseUrl = location.pathname + location.hash;
} else {
baseUrl = '/app/notebooks-dashboards#/';
baseUrl = '/app/notebooks-dashboards?view=output_only#/';
}
if (edit) {
return baseUrl.replace(
`reports-dashboards#/edit/${editDefinitionId}`,
'notebooks-dashboards#/'
'notebooks-dashboards?view=output_only#/'
);
} else if (fromInContext) {
return baseUrl;
}
return baseUrl.replace(
'reports-dashboards#/create',
'notebooks-dashboards#/'
'notebooks-dashboards?view=output_only#/'
);
}

Expand Down
2 changes: 1 addition & 1 deletion server/model/backendModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,5 @@ export const URL_PREFIX_DICT = {
[BACKEND_REPORT_SOURCE.dashboard]: '/app/dashboards#/view/',
[BACKEND_REPORT_SOURCE.savedSearch]: '/app/discover#/view/',
[BACKEND_REPORT_SOURCE.visualization]: '/app/visualize#/edit/',
[BACKEND_REPORT_SOURCE.notebook]: '/app/notebooks-dashboards#/'
[BACKEND_REPORT_SOURCE.notebook]: '/app/notebooks-dashboards?view=output_only#/'
};
35 changes: 35 additions & 0 deletions server/utils/__tests__/validationHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,31 @@ const createReportInput: ReportSchemaType = {
report_definition: createReportDefinitionInput,
};

const createReportDefinitionNotebookInput: ReportDefinitionSchemaType = {
report_params: {
report_name: 'test notebooks report',
report_source: REPORT_TYPE.notebook,
description: 'Hi this is your Notebook on demand',
core_params: {
base_url: `/app/notebooks-dashboards?view=output_only#/${SAMPLE_SAVED_OBJECT_ID}`,
window_width: 1300,
window_height: 900,
report_format: FORMAT.pdf,
time_duration: 'PT5M',
origin: 'http://localhost:5601',
},
},
delivery: {
delivery_type: DELIVERY_TYPE.opensearchDashboardsUser,
delivery_params: {
opensearch_dashboards_recipients: [],
},
},
trigger: {
trigger_type: TRIGGER_TYPE.onDemand,
},
}

describe('test input validation', () => {
test('create report with correct saved object id', async () => {
const savedObjectIds = [`dashboard:${SAMPLE_SAVED_OBJECT_ID}`];
Expand Down Expand Up @@ -93,6 +118,16 @@ describe('test input validation', () => {
expect(report).toBeDefined();
});

test('create notebook report definition with correct base url format', async () => {
const savedObjectIds = [`notebook:${SAMPLE_SAVED_OBJECT_ID}`];
const client = mockOpenSearchClient(savedObjectIds);
const report = await validateReportDefinition(
client,
createReportDefinitionNotebookInput
);
expect(report).toBeDefined();
});

test('create report definition with non-exist saved object id', async () => {
const savedObjectIds = ['dashboard:fake-id'];
const client = mockOpenSearchClient(savedObjectIds);
Expand Down
9 changes: 6 additions & 3 deletions server/utils/validationHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@ import {
import { REPORT_TYPE } from '../../server/routes/utils/constants';

export const isValidRelativeUrl = (relativeUrl: string) => {
const normalizedRelativeUrl = path.posix.normalize(relativeUrl);
let normalizedRelativeUrl = relativeUrl
if (!relativeUrl.includes('notebooks-dashboards')) {
normalizedRelativeUrl = path.posix.normalize(relativeUrl);
}

// check pattern
// ODFE pattern: /app/dashboards#/view/7adfa750-4c81-11e8-b3d7-01146121b73d?_g
// AES pattern: /_plugin/kibana/app/dashboards#/view/7adfa750-4c81-11e8-b3d7-01146121b73d?_g
const isValid = regexRelativeUrl.test(normalizedRelativeUrl);

return isValid;
};

Expand All @@ -52,7 +55,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\/app|app)\/(dashboards|visualize|discover|notebooks-dashboards)(\?security_tenant=.+|)#\/(view\/|edit\/)?[^\/]+$/;
export const regexRelativeUrl = /^\/(_plugin\/kibana\/app|app)\/(dashboards|visualize|discover|notebooks-dashboards\?view=output_only)(\?security_tenant=.+|)#\/(view\/|edit\/)?[^\/]+$/;

export const validateReport = async (
client: ILegacyScopedClusterClient,
Expand Down

0 comments on commit 457539b

Please sign in to comment.