Check for existence of failed events before redelivering

This commit is contained in:
Arpit Jalan 2024-06-14 14:32:17 +05:30
parent 500e26d1fe
commit 77408b8ea2
2 changed files with 11 additions and 2 deletions

View File

@ -129,6 +129,11 @@ export default class WebhookEvents extends Component {
this.eventIds = this.events.content.map((event) => event.id); this.eventIds = this.events.content.map((event) => event.id);
this.count = this.events.length; this.count = this.events.length;
if (this.count === 0) {
this.dialog.alert("No events to redeliver.");
return;
}
return this.dialog.yesNoConfirm({ return this.dialog.yesNoConfirm({
message: I18n.t("admin.web_hooks.events.bulk_redeliver_confirm", { message: I18n.t("admin.web_hooks.events.bulk_redeliver_confirm", {
count: this.count, count: this.count,
@ -139,7 +144,11 @@ export default class WebhookEvents extends Component {
`/admin/api/web_hooks/${this.args.webhookId}/events/bulk_redeliver`, `/admin/api/web_hooks/${this.args.webhookId}/events/bulk_redeliver`,
{ type: "POST", data: { event_ids: this.eventIds } } { type: "POST", data: { event_ids: this.eventIds } }
); );
if (json.web_hook_event && json.web_hook_event.length > 0) {
this.args.event.setProperties(json.web_hook_event); this.args.event.setProperties(json.web_hook_event);
} else {
this.dialog.alert("No events to redeliver.");
}
} catch (e) { } catch (e) {
popupAjaxError(e); popupAjaxError(e);
} }

View File

@ -138,7 +138,7 @@ class Admin::WebHooksController < Admin::AdminController
def bulk_redeliver_events def bulk_redeliver_events
limit = 50 limit = 50
offset = params[:offset].to_i offset = params[:offset].to_i
failed_events = @web_hook.web_hook_events.failed.limit(limit).offset(offset) failed_events = @web_hook&.web_hook_events&.failed&.limit(limit)&.offset(offset)
render_serialized(failed_events, AdminWebHookEventSerializer, root: "web_hook_event") render_serialized(failed_events, AdminWebHookEventSerializer, root: "web_hook_event")
end end