Skip to content

Commit

Permalink
Support legacy notebooks url in validation
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Li <joshuali925@gmail.com>
  • Loading branch information
joshuali925 committed Oct 13, 2021
1 parent cb4fb56 commit 62f905f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
36 changes: 36 additions & 0 deletions dashboards-reports/server/utils/__tests__/validationHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,32 @@ const createReportInput: ReportSchemaType = {
report_definition: createReportDefinitionInput,
};

// this is the url format used before notebooks merged into observability
const createReportDefinitionNotebookLegacyInput: 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: {
configIds: [],
title: 'title',
textDescription: 'text description',
htmlDescription: 'html description'
},
trigger: {
trigger_type: TRIGGER_TYPE.onDemand,
},
}

const createReportDefinitionNotebookInput: ReportDefinitionSchemaType = {
report_params: {
report_name: 'test notebooks report',
Expand Down Expand Up @@ -118,6 +144,16 @@ describe('test input validation', () => {
expect(report).toBeDefined();
});

test('create notebook report definition with legacy base url format', async () => {
const savedObjectIds = [`notebook:${SAMPLE_SAVED_OBJECT_ID}`];
const client = mockOpenSearchClient(savedObjectIds);
const report = await validateReportDefinition(
client,
createReportDefinitionNotebookLegacyInput
);
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);
Expand Down
2 changes: 1 addition & 1 deletion dashboards-reports/server/utils/validationHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,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\/|_dashboards\/)?app\/(dashboards|visualize|discover|observability)([?&]security_tenant=.+|)#\/(notebooks\/|view\/|edit\/)?[^\/]+$/;
export const regexRelativeUrl = /^\/(_plugin\/kibana\/|_dashboards\/)?app\/(dashboards|visualize|discover|observability|notebooks-dashboards\?view=output_only)([?&]security_tenant=.+|)#\/(notebooks\/|view\/|edit\/)?[^\/]+$/;

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

0 comments on commit 62f905f

Please sign in to comment.