Skip to content

Commit

Permalink
Change Delivery Request Body for Notifications (opensearch-project#85)
Browse files Browse the repository at this point in the history
* adding opensearch changed api for report definition to save branch
Signed-off-by: David Cui <davidcui@amazon.com>

* change delivery request body, update test cases
Signed-off-by: David Cui <davidcui@amazon.com>

* remove console.log statement, fix DeliveryType type members to use snake case
Signed-off-by: David Cui <davidcui@amazon.com>

* convert all snake case to camel case
Signed-off-by: David Cui <davidcui@amazon.com>

* make configId required in schema
Signed-off-by: David Cui <davidcui@amazon.com>
  • Loading branch information
davidcui1225 authored Jun 16, 2021
1 parent b6e8d74 commit eebbec6
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,10 @@ export function ReportDefinitionDetails(props) {
trigger_params: triggerParams,
} = trigger;
const {
delivery_type: deliveryType,
delivery_params: deliveryParams,
configIds: configIds,
title: title,
textDescription: textDescription,
htmlDescription: htmlDescription
} = delivery;
const {
core_params: {
Expand Down Expand Up @@ -419,17 +421,11 @@ export function ReportDefinitionDetails(props) {
scheduleDetails: triggerParams
? humanReadableScheduleDetails(data.report_definition.trigger)
: `\u2014`,
channel: deliveryType,
status: reportDefinition.status,
opensearchDashboardsRecipients: deliveryParams.opensearch_dashboards_recipients
? deliveryParams.opensearch_dashboards_recipients
: `\u2014`,
emailRecipients:
deliveryType === 'Channel' ? deliveryParams.recipients : `\u2014`,
emailSubject:
deliveryType === 'Channel' ? deliveryParams.title : `\u2014`,
emailBody:
deliveryType === 'Channel' ? deliveryParams.textDescription : `\u2014`,
configIds: configIds,
title: title,
textDescription: textDescription,
htmlDescription: htmlDescription
};
return reportDefinitionDetails;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ interface triggerType {
}

interface deliveryType {
delivery_type: string;
delivery_params: any;
configIds: Array<string>;
title: string;
textDescription: string;
htmlDescription: string;
}

export interface TriggerParamsType {
Expand Down Expand Up @@ -123,8 +125,10 @@ export function CreateReport(props) {
},
},
delivery: {
delivery_type: '',
delivery_params: {},
configIds: [],
title: '',
textDescription: '',
htmlDescription: ''
},
trigger: {
trigger_type: '',
Expand Down
6 changes: 4 additions & 2 deletions public/components/report_definitions/delivery/delivery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ export function ReportDelivery(props: ReportDeliveryProps) {

const defaultCreateDeliveryParams = () => {
reportDefinitionRequest.delivery = {
delivery_type: DELIVERY_TYPE_OPTIONS[0].id,
delivery_params: { opensearch_dashboards_recipients: [] },
configIds: [],
title: '',
textDescription: '',
htmlDescription: ''
};
};

Expand Down
4 changes: 1 addition & 3 deletions server/model/backendModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,10 @@ export type IntervalType = {
};

export type DeliveryType = {
recipients: string[];
deliveryFormat: BACKEND_DELIVERY_FORMAT;
configIds: string[];
title: string;
textDescription: string;
htmlDescription?: string;
channelIds?: string[];
};

export enum BACKEND_DELIVERY_FORMAT {
Expand Down
14 changes: 4 additions & 10 deletions server/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,10 @@ export const triggerSchema = schema.object({
});

export const deliverySchema = schema.object({
delivery_type: schema.oneOf([
schema.literal(DELIVERY_TYPE.opensearchDashboardsUser),
schema.literal(DELIVERY_TYPE.channel),
]),
delivery_params: schema.conditional(
schema.siblingRef('delivery_type'),
DELIVERY_TYPE.opensearchDashboardsUser,
opensearchDashboardsUserSchema,
channelSchema
),
configIds: schema.arrayOf(schema.string()),
title: schema.string(),
textDescription: schema.string(),
htmlDescription: schema.string()
});

export const reportParamsSchema = schema.object({
Expand Down
4 changes: 0 additions & 4 deletions server/routes/reportDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,26 +181,22 @@ export default function (router: IRouter, accessInfo: AccessInfoType) {
fromIndex: number;
maxItems: number;
};

try {
// @ts-ignore
const opensearchReportsClient: ILegacyScopedClusterClient = context.reporting_plugin.opensearchReportsClient.asScoped(
request
);

const opensearchResp = await opensearchReportsClient.callAsCurrentUser(
'opensearch_reports.getReportDefinitions',
{
fromIndex: fromIndex,
maxItems: maxItems || DEFAULT_MAX_SIZE,
}
);

const reportDefinitionsList = backendToUiReportDefinitionsList(
opensearchResp.reportDefinitionDetailsList,
basePath
);

return response.ok({
body: {
data: reportDefinitionsList,
Expand Down
8 changes: 4 additions & 4 deletions server/routes/utils/__tests__/savedSearchReportHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ const input = {
},
},
delivery: {
delivery_type: 'OpenSearch Dashboards user',
delivery_params: {
opensearch_dashboards_recipients: [],
},
configIds: [],
title: 'title',
textDescription: 'text description',
htmlDescription: 'html description'
},
trigger: {
trigger_type: 'On demand',
Expand Down
8 changes: 4 additions & 4 deletions server/routes/utils/__tests__/visualReportHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ const input = {
},
},
delivery: {
delivery_type: 'OpenSearch Dashboards user',
delivery_params: {
opensearch_dashboards_recipients: [],
},
configIds: [],
title: 'title',
textDescription: 'text description',
htmlDescription: 'html description'
},
trigger: {
trigger_type: 'On demand',
Expand Down
18 changes: 6 additions & 12 deletions server/routes/utils/converters/__tests__/backendToUi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,11 @@ const input: BackendReportInstanceType = {
},
},
delivery: {
recipients: ['szhongna@amazon.com'],
deliveryFormat: BACKEND_DELIVERY_FORMAT.embedded,
title: 'test email subject',
textDescription: '- test\n- optional\n- message',
htmlDescription:
'<ul>\n<li>test</li>\n<li>optional</li>\n<li>message</li>\n</ul>',
channelIds: [],
configIds: [],
},
},
},
Expand Down Expand Up @@ -129,15 +127,11 @@ const output = {
},
},
delivery: {
delivery_type: 'Channel',
delivery_params: {
recipients: ['szhongna@amazon.com'],
title: 'test email subject',
textDescription: '- test\n- optional\n- message',
htmlDescription:
'<ul>\n<li>test</li>\n<li>optional</li>\n<li>message</li>\n</ul>',
channelIds: [],
},
title: 'test email subject',
textDescription: '- test\n- optional\n- message',
htmlDescription:
'<ul>\n<li>test</li>\n<li>optional</li>\n<li>message</li>\n</ul>',
configIds: [],
},
time_created: 1605056426053,
last_updated: 1605056426053,
Expand Down
17 changes: 6 additions & 11 deletions server/routes/utils/converters/backendToUi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ export const backendToUiReportDefinition = (

const baseUrl = getBaseUrl(sourceType, sourceId);
const reportSource = getUiReportSource(sourceType);

let uiReportDefinition: ReportDefinitionSchemaType = {
report_params: {
report_name: name,
Expand Down Expand Up @@ -175,7 +174,6 @@ export const backendToUiReportDefinition = (
last_updated: lastUpdatedTimeMs,
status: getUiReportDefinitionStatus(isEnabled),
};

// validate to assign default values to some fields for UI model
uiReportDefinition = reportDefinitionSchema.validate(uiReportDefinition);
uiReportDefinition.report_params.core_params.base_url =
Expand Down Expand Up @@ -370,20 +368,17 @@ const getUiDeliveryParams = (
delivery: DeliveryType | undefined
): DeliverySchemaType => {
const opensearchDashboardsUserDeliveryParams = {
delivery_type: DELIVERY_TYPE.opensearchDashboardsUser,
delivery_params: {
opensearch_dashboards_recipients: [],
},
configIds: [],
title: '',
textDescription: '',
htmlDescription: ''
};

let params: any;
if (delivery) {
const { deliveryFormat, ...rest } = delivery;
const { ...rest } = delivery;
params = {
delivery_type: DELIVERY_TYPE.channel,
delivery_params: {
...rest,
},
...rest
};
} else {
params = opensearchDashboardsUserDeliveryParams;
Expand Down
16 changes: 8 additions & 8 deletions server/utils/__tests__/validationHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ const createReportDefinitionInput: ReportDefinitionSchemaType = {
},
},
delivery: {
delivery_type: DELIVERY_TYPE.opensearchDashboardsUser,
delivery_params: {
opensearch_dashboards_recipients: [],
},
configIds: [],
title: 'title',
textDescription: 'text description',
htmlDescription: 'html description'
},
trigger: {
trigger_type: TRIGGER_TYPE.onDemand,
Expand Down Expand Up @@ -80,10 +80,10 @@ const createReportDefinitionNotebookInput: ReportDefinitionSchemaType = {
},
},
delivery: {
delivery_type: DELIVERY_TYPE.opensearchDashboardsUser,
delivery_params: {
opensearch_dashboards_recipients: [],
},
configIds: [],
title: 'title',
textDescription: 'text description',
htmlDescription: 'html description'
},
trigger: {
trigger_type: TRIGGER_TYPE.onDemand,
Expand Down

0 comments on commit eebbec6

Please sign in to comment.