-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathFrontendAPI.ts
More file actions
241 lines (206 loc) · 7.22 KB
/
Copy pathFrontendAPI.ts
File metadata and controls
241 lines (206 loc) · 7.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
import type { AdminForthFilterOperators, FilterParams } from "./Common.js";
export interface FrontendAPIInterface {
/**
* Show a confirmation dialog
*
* The dialog will be displayed to the user
*
* Example:
*
* ```ts
*import { useAdminforth } from '@/adminforth';
*
* const { confirm } = useAdminforth();
* const isConfirmed = await confirm({message: 'Are you sure?', yes: 'Yes', no: 'No'})
* if (isConfirmed) {
* your code...
* }
* ```
*
* @param params - The parameters of the dialog
* @returns A promise that resolves when the user confirms the dialog
*/
confirm(params: ConfirmParams): Promise<boolean>;
/**
* Show an alert
*
* The alert will be displayed to the user
*
* Example:
*
* ```ts
* import { useAdminforth } from '@/adminforth';
* const { alert } = useAdminforth();
*
* alert({message: 'Hello', variant: 'success'})
* ```
*
* @param params - The parameters of the alert
*/
alert(params:AlertParams): void | Promise<string> | string;
list: {
/**
* Full refresh the list. Loader will be shown during fetching data. Will fully reload table data from the server. If new data available, it will be shown in the list.
*/
refresh(): Promise<{ error? : string }>;
/**
* Silently Refresh existing rows in the list (without loader).
* Should be called when table data already loaded, otherwise method will return an error.
* If new data available, it will not appear in the list.
*/
silentRefresh(): Promise<{ error? : string }>;
/**
* Refresh a specific row in the list without loader, row should be already shown in the list, otherwise method will return an error
*/
silentRefreshRow (pk: any): Promise<{ error? : string }>;
/**
* Close the three dots dropdown
*/
closeThreeDotsDropdown(): void;
/**
* Set a filter in the list.
* Works only when user located on the list page. If filter already exists, it will be replaced with the new one.
* Can be used to set filter from charts or other components in pageInjections.
*
* Filters are automatically marked as hidden (won't count in badge) if:
* - Column has showIn.filter: false
*
* Example:
*
* ```ts
* import { useAdminforth } from '@/adminforth';
*
* const { list } = useAdminforth();
* // Regular filter (will show in badge if column.showIn.filter !== false)
* list.setFilter({field: 'name', operator: 'ilike', value: 'john'})
*
* // Hidden filter (won't show in badge if column.showIn.filter === false)
* list.setFilter({field: 'internal_status', operator: 'eq', value: 'active'})
* ```
*
* Please note that you can set/update filter even for fields which have showIn.filter=false in resource configuration.
* Also you can set filter for virtual columns. For example Universal search plugin calls updateFilter for virtual column which has showIn.filter=false (because we dont want to show this column in filter dropdown, plugin renders its own filter UI)
*
* @param filter - The filter to set
*/
setFilter(filter: FilterParams): void;
/**
* @deprecated does the same as setFilter, kept for backward compatibility, will be removed in 2.0.0
*
* Update a filter in the list
*
* Filters visibility in badge is automatically determined by column configuration:
* - Hidden if column has showIn.filter: false
*
* Example:
*
* ```ts
* import { useAdminforth } from '@/adminforth';
* const { list } = useAdminforth();
* list.updateFilter({field: 'name', operator: 'ilike', value: 'john'})
* ```
*
* @param filter - The filter to update
*/
updateFilter(filter: FilterParams): void;
/**
* Clear all filters from the list
*/
clearFilters(): void;
}
show: {
/**
* Full refresh the current record on the show page. Loader may be shown during fetching.
* Fire-and-forget; you don't need to await it.
*/
refresh(): void;
}
menu: {
/**
* Refreshes the menu tree and frontend configuration by fetching the latest backend config.
*/
refresh(): Promise<void>;
/**
* Refreshes the badges in the menu, by recalling the badge function for each menu item
*/
refreshMenuBadges(): void;
}
/**
* Close the user menu dropdown
*/
closeUserMenuDropdown(): void;
/**
* Run save interceptors for a specific resource or all resources if no resourceId is provided
*/
runSaveInterceptors(params: { action: 'create'|'edit'; values: any; resource: any; resourceId: string; }): Promise<{ ok: boolean; error?: string | null; extra?: any; }>;
/**
* Clear save interceptors for a specific resource or all resources if no resourceId is provided
*
* @param resourceId - The resource ID to clear interceptors for
*/
clearSaveInterceptors(resourceId?: string): void;
/**
* Register a save interceptor for a specific resource
*/
registerSaveInterceptor(handler: (ctx: { action: 'create'|'edit'; values: any; resource: any; }) => Promise<{ ok: boolean; error?: string | null; extra?: any; }>): void;
}
export type ConfirmParams = {
/**
* The title to display in the dialog
*/
title?: string;
/**
* The message to display in the dialog as a warning that action is irreversible
*/
guardMessage?: string;
/**
* The message to display in the dialog
*/
message?: string;
/**
* Message to display in the dialog as HTML (can be used instead of message)
*/
messageHtml?: string;
/**
* The text to display in the "accept" button
*/
yes?: string;
/**
* The text to display in the "cancel" button
*/
no?: string;
/**
* When true, the dialog renders in red/danger style (destructive actions like delete).
* When false or omitted, the dialog renders in primary color (neutral confirmations).
*/
dangerous?: boolean;
}
export type AlertParams = {
/**
* The message to display in the alert
*/
message?: string;
/**
* The message to display in the alert as HTML (can be used instead of message)
*/
messageHtml?: string;
/**
* The variant of the alert
*/
variant?: AlertVariant | keyof typeof AlertVariant;
/**
* The timeout of the alert in seconds or 'unlimited' to keep the alert open until the user closes it.
* Default is 10 seconds;
*/
timeout?: number | 'unlimited';
/**
* Optional buttons to display in the alert
*/
buttons?: {value: any, label: string}[];
}
export enum AlertVariant {
danger = 'danger',
success = 'success',
warning = 'warning',
info = 'info'
}