Skip to content

Commit 14c80f8

Browse files
committed
feat: add refresh method to show interface for record updates
1 parent dff60f0 commit 14c80f8

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

adminforth/spa/src/adminforth.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ class FrontendAPI implements FrontendAPIInterface {
3636
refreshMenuBadges: () => void;
3737
}
3838

39+
public show: {
40+
refresh(): void;
41+
}
42+
3943
closeUserMenuDropdown(): void {
4044
console.log('closeUserMenuDropdown')
4145
}
@@ -73,6 +77,12 @@ class FrontendAPI implements FrontendAPIInterface {
7377
updateFilter: this.updateListFilter.bind(this),
7478
clearFilters: this.clearListFilters.bind(this),
7579
}
80+
81+
this.show = {
82+
refresh: () => {
83+
console.log('show.refresh')
84+
}
85+
}
7686
}
7787

7888
confirm(params: ConfirmParams): Promise<void> {

adminforth/spa/src/views/ShowView.vue

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,4 +281,21 @@ async function startCustomAction(actionId) {
281281
}
282282
}
283283
284+
adminforth.show.refresh = () => {
285+
(async () => {
286+
try {
287+
loading.value = true;
288+
await coreStore.fetchRecord({
289+
resourceId: String(route.params.resourceId),
290+
primaryKey: String(route.params.primaryKey),
291+
source: 'show',
292+
});
293+
} catch (e) {
294+
showErrorTost((e as Error).message);
295+
} finally {
296+
loading.value = false;
297+
}
298+
})();
299+
}
300+
284301
</script>

adminforth/types/FrontendAPI.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ export interface FrontendAPIInterface {
121121
clearFilters(): void;
122122
}
123123

124+
show: {
125+
/**
126+
* Full refresh the current record on the show page. Loader may be shown during fetching.
127+
* Fire-and-forget; you don't need to await it.
128+
*/
129+
refresh(): void;
130+
}
131+
124132
menu: {
125133
/**
126134
* Refreshes the badges in the menu, by recalling the badge function for each menu item

0 commit comments

Comments
 (0)