-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* get webhook deliveries api * bug fix we should perform order-by operation before skip * add webhook deliveries component * i18n * styling and filtering * i18n * define type for webhook delivery error * do not include stacktrace when record error for security reason
- Loading branch information
1 parent
706a248
commit e07a393
Showing
24 changed files
with
674 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
modules/back-end/src/Application/Webhooks/GetWebhookDeliveryList.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using Application.Bases.Models; | ||
using Domain.Webhooks; | ||
|
||
namespace Application.Webhooks; | ||
|
||
public class GetWebhookDeliveryList : IRequest<PagedResult<WebhookDelivery>> | ||
{ | ||
public Guid WebhookId { get; set; } | ||
|
||
public WebhookDeliveryFilter Filter { get; set; } | ||
} | ||
|
||
public class GetWebhookDeliveryListHandler : IRequestHandler<GetWebhookDeliveryList, PagedResult<WebhookDelivery>> | ||
{ | ||
private readonly IWebhookService _service; | ||
|
||
public GetWebhookDeliveryListHandler(IWebhookService service) | ||
{ | ||
_service = service; | ||
} | ||
|
||
public async Task<PagedResult<WebhookDelivery>> Handle(GetWebhookDeliveryList request, CancellationToken cancellationToken) | ||
{ | ||
var deliveries = await _service.GetDeliveriesAsync(request.WebhookId, request.Filter); | ||
return deliveries; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
modules/back-end/src/Application/Webhooks/WebhookDeliveryFilter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Application.Bases.Models; | ||
|
||
namespace Application.Webhooks; | ||
|
||
public class WebhookDeliveryFilter : PagedRequest | ||
{ | ||
public string Event { get; set; } | ||
|
||
public bool? Success { get; set; } | ||
|
||
public DateTime? NotBefore { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...es/front-end/src/app/core/components/webhook-deliveries/webhook-deliveries.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<nz-drawer | ||
nzClosable="false" | ||
[nzExtra]="extra" | ||
[nzVisible]="visible" | ||
nzTitle="Webhook deliveries" | ||
i18n-nzTitle="@@integrations.webhooks.webhook-deliveries" | ||
[nzWidth]="1000" | ||
(nzOnClose)="onClose()"> | ||
<ng-container *nzDrawerContent> | ||
<div class="searches"> | ||
<span i18n="@@integrations.webhooks.webhook-deliveries-tip" class="tip">Webhook deliveries sent to your endpoint in the past 15 days.</span> | ||
<nz-select nzShowSearch nzAllowClear nzPlaceHolder="Filter by event" [(ngModel)]="filter.event" (ngModelChange)="doSearch()"> | ||
<nz-option *ngFor="let event of events" [nzValue]="event" [nzLabel]="event"></nz-option> | ||
</nz-select> | ||
<nz-segmented [nzOptions]="statuses" (nzValueChange)="onStatusChange($event)"></nz-segmented> | ||
</div> | ||
<nz-table | ||
#table nzSize="small" | ||
[nzShowTotal]="totalTemplate" | ||
[nzData]="deliveries.items" | ||
[nzFrontPagination]="false" | ||
[nzLoading]="isLoading" | ||
[nzTotal]="deliveries.totalCount" | ||
[nzPageSize]="filter.pageSize" | ||
[(nzPageIndex)]="filter.pageIndex" | ||
(nzPageIndexChange)="loadDeliveries()" | ||
> | ||
<thead> | ||
<tr> | ||
<th i18n="@@common.status">Status</th> | ||
<th i18n="@@integrations.webhooks.events">Events</th> | ||
<th i18n="@@common.happened-at">Happened At</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<ng-container *ngFor="let item of table.data"> | ||
<tr> | ||
<td (click)="expandRow(item.id)"> | ||
<i class="animated" nz-icon nzType="right" [nzRotate]="isRowExpanded(item.id) ? 90 : 0"></i> | ||
<nz-tag *ngIf="item.success" nzColor="success"> | ||
<span nz-icon nzType="check-circle"></span> | ||
{{ item.response?.statusCode ?? 200 }} | ||
</nz-tag> | ||
<nz-tag *ngIf="!item.success" nzColor="error"> | ||
<span nz-icon nzType="close-circle"></span> | ||
{{ item.response?.statusCode ?? 'ERROR' }} | ||
</nz-tag> | ||
</td> | ||
<td> | ||
<span>{{item.events}}</span> | ||
</td> | ||
<td>{{item.startedAt | date: 'YYYY/MM/dd HH:mm'}}</td> | ||
</tr> | ||
<tr [nzExpand]="isRowExpanded(item.id)"> | ||
<webhook-delivery [delivery]="item"></webhook-delivery> | ||
</tr> | ||
</ng-container> | ||
</tbody> | ||
<ng-template #totalTemplate let-total> | ||
<span class="total"><strong>{{ total }}</strong> results</span> | ||
</ng-template> | ||
</nz-table> | ||
</ng-container> | ||
<ng-template #extra> | ||
<i (click)="onClose()" nz-icon nzType="icons:icon-close"></i> | ||
</ng-template> | ||
</nz-drawer> |
26 changes: 26 additions & 0 deletions
26
...es/front-end/src/app/core/components/webhook-deliveries/webhook-deliveries.component.less
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
@import "variables"; | ||
|
||
.searches { | ||
display: flex; | ||
justify-content: flex-end; | ||
align-items: center; | ||
gap: 12px; | ||
margin-bottom: 12px; | ||
|
||
.tip { | ||
margin-right: auto; | ||
font-size: 14px; | ||
} | ||
|
||
nz-select { | ||
width: 250px; | ||
} | ||
} | ||
|
||
nz-tag { | ||
padding: 0 8px; | ||
} | ||
|
||
.total { | ||
font-size: 14px; | ||
} |
91 changes: 91 additions & 0 deletions
91
modules/front-end/src/app/core/components/webhook-deliveries/webhook-deliveries.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { Component, EventEmitter, Input, Output } from '@angular/core'; | ||
import { | ||
PagedWebhookDelivery, | ||
Webhook, | ||
WebhookDeliveryFilter, | ||
WebhookEvents | ||
} from "@features/safe/integrations/webhooks/webhooks"; | ||
import { Subject } from "rxjs"; | ||
import { WebhookService } from "@services/webhook.service"; | ||
import { NzMessageService } from "ng-zorro-antd/message"; | ||
import { debounceTime, finalize } from "rxjs/operators"; | ||
|
||
@Component({ | ||
selector: 'webhook-deliveries', | ||
templateUrl: './webhook-deliveries.component.html', | ||
styleUrls: ['./webhook-deliveries.component.less'] | ||
}) | ||
export class WebhookDeliveriesComponent { | ||
@Input() | ||
visible: boolean; | ||
private _webhook: Webhook; | ||
@Input() | ||
set webhook(value: Webhook) { | ||
this._webhook = value; | ||
if (value) { | ||
this.loadDeliveries(); | ||
} | ||
} | ||
@Output() | ||
close: EventEmitter<void> = new EventEmitter(); | ||
|
||
isLoading: boolean = true; | ||
deliveries: PagedWebhookDelivery = { | ||
totalCount: 0, | ||
items: [] | ||
}; | ||
filter: WebhookDeliveryFilter = new WebhookDeliveryFilter(); | ||
search$ = new Subject<void>(); | ||
|
||
constructor(private webhookService: WebhookService, private message: NzMessageService) { | ||
this.search$.pipe(debounceTime(250)).subscribe(() => this.loadDeliveries()); | ||
} | ||
|
||
events: string[] = WebhookEvents.map(e => e.value); | ||
statuses: string[] = ['All', 'Succeeded', 'Failed']; | ||
|
||
loadDeliveries() { | ||
this.isLoading = true; | ||
this.webhookService.getDeliveries(this._webhook.id, this.filter) | ||
.pipe(finalize(() => this.isLoading = false)) | ||
.subscribe({ | ||
next: deliveries => { | ||
this.deliveries = deliveries; | ||
this.expandedRowId = deliveries.items.length > 0 ? deliveries.items[0].id : ''; | ||
}, | ||
error: () => this.message.error($localize`:@@common.loading-failed-try-again:Loading failed, please try again`), | ||
}); | ||
} | ||
|
||
|
||
doSearch() { | ||
this.filter.pageIndex = 1; | ||
this.search$.next(); | ||
} | ||
|
||
onStatusChange(index: number) { | ||
const status = this.statuses[index]; | ||
this.filter.success = status === 'All' ? null : status === 'Succeeded'; | ||
this.doSearch(); | ||
} | ||
|
||
expandedRowId: string = ''; | ||
expandRow(id: string): void { | ||
this.expandedRowId = this.expandedRowId === id ? '' : id; | ||
} | ||
isRowExpanded(id: string): boolean { | ||
return this.expandedRowId === id; | ||
} | ||
|
||
onClose() { | ||
// reset status | ||
this.filter = new WebhookDeliveryFilter(); | ||
this.deliveries = { | ||
totalCount: 0, | ||
items: [] | ||
}; | ||
|
||
this.visible = false; | ||
this.close.emit(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.