From eebbec6564a3fd9fad2e2dfbebaa64a017b42521 Mon Sep 17 00:00:00 2001 From: David Cui <53581635+davidcui-amzn@users.noreply.github.com> Date: Wed, 16 Jun 2021 15:24:16 -0700 Subject: [PATCH] Change Delivery Request Body for Notifications (#85) * adding opensearch changed api for report definition to save branch Signed-off-by: David Cui * change delivery request body, update test cases Signed-off-by: David Cui * remove console.log statement, fix DeliveryType type members to use snake case Signed-off-by: David Cui * convert all snake case to camel case Signed-off-by: David Cui * make configId required in schema Signed-off-by: David Cui --- .../report_definition_details.tsx | 20 ++++++++----------- .../create/create_report_definition.tsx | 12 +++++++---- .../report_definitions/delivery/delivery.tsx | 6 ++++-- server/model/backendModel.ts | 4 +--- server/model/index.ts | 14 ++++--------- server/routes/reportDefinition.ts | 4 ---- .../__tests__/savedSearchReportHelper.test.ts | 8 ++++---- .../__tests__/visualReportHelper.test.ts | 8 ++++---- .../converters/__tests__/backendToUi.test.ts | 18 ++++++----------- server/routes/utils/converters/backendToUi.ts | 17 ++++++---------- .../utils/__tests__/validationHelper.test.ts | 16 +++++++-------- 11 files changed, 53 insertions(+), 74 deletions(-) diff --git a/public/components/main/report_definition_details/report_definition_details.tsx b/public/components/main/report_definition_details/report_definition_details.tsx index 694f8d0e..432a5ad3 100644 --- a/public/components/main/report_definition_details/report_definition_details.tsx +++ b/public/components/main/report_definition_details/report_definition_details.tsx @@ -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: { @@ -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; }; diff --git a/public/components/report_definitions/create/create_report_definition.tsx b/public/components/report_definitions/create/create_report_definition.tsx index eda05765..7748432c 100644 --- a/public/components/report_definitions/create/create_report_definition.tsx +++ b/public/components/report_definitions/create/create_report_definition.tsx @@ -73,8 +73,10 @@ interface triggerType { } interface deliveryType { - delivery_type: string; - delivery_params: any; + configIds: Array; + title: string; + textDescription: string; + htmlDescription: string; } export interface TriggerParamsType { @@ -123,8 +125,10 @@ export function CreateReport(props) { }, }, delivery: { - delivery_type: '', - delivery_params: {}, + configIds: [], + title: '', + textDescription: '', + htmlDescription: '' }, trigger: { trigger_type: '', diff --git a/public/components/report_definitions/delivery/delivery.tsx b/public/components/report_definitions/delivery/delivery.tsx index 155f33a2..c83aa9fd 100644 --- a/public/components/report_definitions/delivery/delivery.tsx +++ b/public/components/report_definitions/delivery/delivery.tsx @@ -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: '' }; }; diff --git a/server/model/backendModel.ts b/server/model/backendModel.ts index 49dcf530..ababb662 100644 --- a/server/model/backendModel.ts +++ b/server/model/backendModel.ts @@ -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 { diff --git a/server/model/index.ts b/server/model/index.ts index d03c9925..782aac7e 100644 --- a/server/model/index.ts +++ b/server/model/index.ts @@ -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({ diff --git a/server/routes/reportDefinition.ts b/server/routes/reportDefinition.ts index a753eddc..c4e0d2c4 100644 --- a/server/routes/reportDefinition.ts +++ b/server/routes/reportDefinition.ts @@ -181,13 +181,11 @@ 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', { @@ -195,12 +193,10 @@ export default function (router: IRouter, accessInfo: AccessInfoType) { maxItems: maxItems || DEFAULT_MAX_SIZE, } ); - const reportDefinitionsList = backendToUiReportDefinitionsList( opensearchResp.reportDefinitionDetailsList, basePath ); - return response.ok({ body: { data: reportDefinitionsList, diff --git a/server/routes/utils/__tests__/savedSearchReportHelper.test.ts b/server/routes/utils/__tests__/savedSearchReportHelper.test.ts index 26600fff..6d3b7377 100644 --- a/server/routes/utils/__tests__/savedSearchReportHelper.test.ts +++ b/server/routes/utils/__tests__/savedSearchReportHelper.test.ts @@ -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', diff --git a/server/routes/utils/__tests__/visualReportHelper.test.ts b/server/routes/utils/__tests__/visualReportHelper.test.ts index 6bf6dc6e..e4bda647 100644 --- a/server/routes/utils/__tests__/visualReportHelper.test.ts +++ b/server/routes/utils/__tests__/visualReportHelper.test.ts @@ -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', diff --git a/server/routes/utils/converters/__tests__/backendToUi.test.ts b/server/routes/utils/converters/__tests__/backendToUi.test.ts index 426777c2..895695d4 100644 --- a/server/routes/utils/converters/__tests__/backendToUi.test.ts +++ b/server/routes/utils/converters/__tests__/backendToUi.test.ts @@ -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: '
    \n
  • test
  • \n
  • optional
  • \n
  • message
  • \n
', - channelIds: [], + configIds: [], }, }, }, @@ -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: - '
    \n
  • test
  • \n
  • optional
  • \n
  • message
  • \n
', - channelIds: [], - }, + title: 'test email subject', + textDescription: '- test\n- optional\n- message', + htmlDescription: + '
    \n
  • test
  • \n
  • optional
  • \n
  • message
  • \n
', + configIds: [], }, time_created: 1605056426053, last_updated: 1605056426053, diff --git a/server/routes/utils/converters/backendToUi.ts b/server/routes/utils/converters/backendToUi.ts index 1799dcce..32c261cb 100644 --- a/server/routes/utils/converters/backendToUi.ts +++ b/server/routes/utils/converters/backendToUi.ts @@ -139,7 +139,6 @@ export const backendToUiReportDefinition = ( const baseUrl = getBaseUrl(sourceType, sourceId); const reportSource = getUiReportSource(sourceType); - let uiReportDefinition: ReportDefinitionSchemaType = { report_params: { report_name: name, @@ -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 = @@ -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; diff --git a/server/utils/__tests__/validationHelper.test.ts b/server/utils/__tests__/validationHelper.test.ts index f8ce7a97..41ce3b49 100644 --- a/server/utils/__tests__/validationHelper.test.ts +++ b/server/utils/__tests__/validationHelper.test.ts @@ -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, @@ -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,