forked from devforth/adminforth
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrontendAPI.ts
More file actions
189 lines (156 loc) · 4.38 KB
/
Copy pathFrontendAPI.ts
File metadata and controls
189 lines (156 loc) · 4.38 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
import type { AdminForthFilterOperators } from "./Common.js";
export type FilterParams = {
/**
* Field of resource to filter
*/
field: string;
/**
* Operator of filter
*/
operator: AdminForthFilterOperators;
/**
* Value of filter
*/
value: string | number | boolean ;
}
export interface FrontendAPIInterface {
/**
* Show a confirmation dialog
*
* The dialog will be displayed to the user
*
* Example:
*
* ```ts
* import adminforth from '@/adminforth'
*
* const isConfirmed = await adminforth.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<void>;
/**
* Show an alert
*
* The alert will be displayed to the user
*
* Example:
*
* ```ts
* import adminforth from '@/adminforth'
*
* adminforth.alert({message: 'Hello', variant: 'success'})
* ```
*
* @param params - The parameters of the alert
*/
alert(params:AlertParams): void;
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.
* Can be used to set filter from charts or other components in pageInjections.
*
* Example:
*
* ```ts
* import adminforth from '@/adminforth'
*
* adminforth.list.setFilter({field: 'name', operator: 'ilike', value: 'john'})
* ```
*
* @param filter - The filter to set
*/
setFilter(filter: FilterParams): void;
/**
* Update a filter in the list
*
* Example:
*
* ```ts
* import adminforth from '@/adminforth';
*
* adminforth.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;
}
menu: {
/**
* Refreshes the badges in the menu, by recalling the badge function for each menu item
*/
refreshMenuBadges(): void;
}
/**
* Close the user menu dropdown
*/
closeUserMenuDropdown(): void;
}
export type ConfirmParams = {
/**
* The message to display in the dialog
*/
message?: string;
/**
* The text to display in the "accept" button
*/
yes?: string;
/**
* The text to display in the "cancel" button
*/
no?: string;
}
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';
}
export enum AlertVariant {
danger = 'danger',
success = 'success',
warning = 'warning',
info = 'info'
}