From a27c8cf160cd5b4c13bbb5fef284043ddb3f8d7a Mon Sep 17 00:00:00 2001 From: LT Date: Thu, 26 Dec 2024 10:09:08 +0300 Subject: [PATCH] fix: Fragment events --- src/UI/resources/js/Components/Fragment.js | 6 +++++- src/UI/resources/js/Request/Core.js | 3 +++ src/UI/resources/js/Support/DispatchEvents.js | 4 ++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/UI/resources/js/Components/Fragment.js b/src/UI/resources/js/Components/Fragment.js index a21085706..6ae650d85 100644 --- a/src/UI/resources/js/Components/Fragment.js +++ b/src/UI/resources/js/Components/Fragment.js @@ -15,7 +15,11 @@ export default (asyncUpdateRoute = '') => ({ this.withParams = this.$el?.dataset?.asyncWithParams this.withQueryParams = this.$el?.dataset?.asyncWithQueryParams ?? false }, - async fragmentUpdate(events, callback = {}) { + async fragmentUpdate(events = '', callback = {}) { + if (typeof events !== 'string') { + events = '' + } + if (this.asyncUpdateRoute === '') { return } diff --git a/src/UI/resources/js/Request/Core.js b/src/UI/resources/js/Request/Core.js index 7cb061fab..9f6ea1c41 100644 --- a/src/UI/resources/js/Request/Core.js +++ b/src/UI/resources/js/Request/Core.js @@ -89,6 +89,7 @@ export default function request( } const events = data.events ?? componentRequestData.events + if (events) { dispatchEvents(events, type, t, componentRequestData.extraProperties) } @@ -112,6 +113,8 @@ export default function request( } if (!errorResponse?.response?.data) { + console.error(errorResponse.message) + MoonShine.ui.toast('Unknown Error', 'error') return } diff --git a/src/UI/resources/js/Support/DispatchEvents.js b/src/UI/resources/js/Support/DispatchEvents.js index dee50f48c..455ec096a 100644 --- a/src/UI/resources/js/Support/DispatchEvents.js +++ b/src/UI/resources/js/Support/DispatchEvents.js @@ -3,6 +3,10 @@ export function dispatchEvents(events, type, component, extraProperties = {}) { return } + if (typeof events !== 'string') { + return + } + if (events.includes('{row-id}') && component.$el !== undefined) { const tr = component.$el.closest('tr') events = events.replace(/{row-id}/g, tr?.dataset?.rowKey ?? 0)