From a1d397842dcaf74a23616d958bfea57689fb0d5f Mon Sep 17 00:00:00 2001 From: Shijun Sun <30999793+AllForNothing@users.noreply.github.com> Date: Tue, 14 Mar 2023 13:28:12 +0800 Subject: [PATCH] Improve webhook UI (#18325) 1. Add text format for payload data 2. Delete payload_format for Slack Signed-off-by: AllForNothing --- .../add-webhook-form.component.ts | 10 ++++++- .../excutions/executions.component.html | 26 +++++++++++++++---- .../webhook/excutions/executions.component.ts | 6 ++++- .../base/project/webhook/webhook.service.ts | 11 ++++++++ 4 files changed, 46 insertions(+), 7 deletions(-) diff --git a/src/portal/src/app/base/project/webhook/add-webhook-form/add-webhook-form.component.ts b/src/portal/src/app/base/project/webhook/add-webhook-form/add-webhook-form.component.ts index 1e9fd5d96..98464f415 100644 --- a/src/portal/src/app/base/project/webhook/add-webhook-form/add-webhook-form.component.ts +++ b/src/portal/src/app/base/project/webhook/add-webhook-form/add-webhook-form.component.ts @@ -19,6 +19,7 @@ import { PAYLOAD_FORMATS, PAYLOAD_FORMAT_I18N_MAP, ProjectWebhookService, + WebhookType, } from '../webhook.service'; import { compareValue } from '../../../../shared/units/utils'; import { InlineAlertComponent } from '../../../../shared/components/inline-alert/inline-alert.component'; @@ -78,6 +79,7 @@ export class AddWebhookFormComponent implements OnInit, OnDestroy { this._nameSubscription = null; } } + reset() { this.isNameExisting = false; this._nameSubject.next(''); @@ -96,7 +98,7 @@ export class AddWebhookFormComponent implements OnInit, OnDestroy { ) { return false; } - return name.length > 0; + return name?.length > 0; }), switchMap(name => { this.isNameExisting = false; @@ -130,6 +132,9 @@ export class AddWebhookFormComponent implements OnInit, OnDestroy { add() { this.submitting = true; + if (this.webhook?.targets[0]?.type === WebhookType.SLACK) { + delete this.webhook?.targets[0]?.payload_format; + } this.webhookService .CreateWebhookPolicyOfProject({ projectNameOrId: this.projectId.toString(), @@ -150,6 +155,9 @@ export class AddWebhookFormComponent implements OnInit, OnDestroy { save() { this.submitting = true; + if (this.webhook?.targets[0]?.type === WebhookType.SLACK) { + delete this.webhook?.targets[0]?.payload_format; + } this.webhookService .UpdateWebhookPolicyOfProject({ projectNameOrId: this.projectId.toString(), diff --git a/src/portal/src/app/base/project/webhook/excutions/executions.component.html b/src/portal/src/app/base/project/webhook/excutions/executions.component.html index 1b52a17d2..6c6b308cd 100644 --- a/src/portal/src/app/base/project/webhook/excutions/executions.component.html +++ b/src/portal/src/app/base/project/webhook/excutions/executions.component.html @@ -65,15 +65,26 @@ - + {{ eventTypeToText(execution?.extra_attrs?.event_type) }} - {{ - toString(toJson(execution?.extra_attrs?.payload)) - }} + + + {{ + toString( + toJson(execution?.extra_attrs?.payload) + ) + }} + + + {{ execution?.extra_attrs?.payload }} + + +
{{
+                            execution?.extra_attrs?.payload
+                        }}

+                            "
+                            class="abc"
+                            *ngIf="useJsonFormat(execution?.vendor_type)">
                     
diff --git a/src/portal/src/app/base/project/webhook/excutions/executions.component.ts b/src/portal/src/app/base/project/webhook/excutions/executions.component.ts index 12124f1f3..c0bfd14fb 100644 --- a/src/portal/src/app/base/project/webhook/excutions/executions.component.ts +++ b/src/portal/src/app/base/project/webhook/excutions/executions.component.ts @@ -16,7 +16,7 @@ import { EXECUTION_STATUS, TIME_OUT, } from '../../p2p-provider/p2p-provider.service'; -import { ProjectWebhookService } from '../webhook.service'; +import { ProjectWebhookService, VendorType } from '../webhook.service'; @Component({ selector: 'app-executions', @@ -172,4 +172,8 @@ export class ExecutionsComponent implements OnDestroy { eventTypeToText(eventType: any): string { return this.projectWebhookService.eventTypeToText(eventType); } + + useJsonFormat(vendorType: string): boolean { + return vendorType === VendorType.WEBHOOK; + } } diff --git a/src/portal/src/app/base/project/webhook/webhook.service.ts b/src/portal/src/app/base/project/webhook/webhook.service.ts index 3f571fffd..79cbb1b3b 100644 --- a/src/portal/src/app/base/project/webhook/webhook.service.ts +++ b/src/portal/src/app/base/project/webhook/webhook.service.ts @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. import { Injectable } from '@angular/core'; +import { MarkdownPipe } from 'ngx-markdown/src/markdown.pipe'; const EVENT_TYPES_TEXT_MAP = { REPLICATION: 'Replication finished', @@ -36,6 +37,16 @@ export const PAYLOAD_FORMAT_I18N_MAP = { [PAYLOAD_FORMATS[1]]: 'WEBHOOK.CLOUD_EVENT', }; +export enum WebhookType { + HTTP = 'http', + SLACK = 'slack', +} + +export enum VendorType { + WEBHOOK = 'WEBHOOK', + SLACK = 'SLACK', +} + @Injectable() export class ProjectWebhookService { constructor() {}