Skip to content

Commit

Permalink
fix: Fragment events
Browse files Browse the repository at this point in the history
  • Loading branch information
lee-to committed Dec 26, 2024
1 parent 9d040ec commit a27c8cf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/UI/resources/js/Components/Fragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 3 additions & 0 deletions src/UI/resources/js/Request/Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export default function request(
}

const events = data.events ?? componentRequestData.events

if (events) {
dispatchEvents(events, type, t, componentRequestData.extraProperties)
}
Expand All @@ -112,6 +113,8 @@ export default function request(
}

if (!errorResponse?.response?.data) {
console.error(errorResponse.message)

MoonShine.ui.toast('Unknown Error', 'error')
return
}
Expand Down
4 changes: 4 additions & 0 deletions src/UI/resources/js/Support/DispatchEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a27c8cf

Please sign in to comment.