Skip to content

Commit 7cb340c

Browse files
committed
feat: allow to set cookie from the bulkActions
1 parent e1c11bd commit 7cb340c

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

adminforth/modules/configValidator.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ export default class ConfigValidator implements IConfigValidator {
249249
icon: 'flowbite:trash-bin-outline',
250250
confirm: 'Are you sure you want to delete selected items?',
251251
allowed: async ({ resource, adminUser, allowedActions }) => { return allowedActions.delete },
252-
action: async ({ selectedIds, adminUser }) => {
252+
action: async ({ selectedIds, adminUser, response }) => {
253253
const connector = this.adminforth.connectors[res.dataSource];
254254

255255
// for now if at least one error, stop and return error
@@ -267,6 +267,7 @@ export default class ConfigValidator implements IConfigValidator {
267267
resource: res as AdminForthResource,
268268
record,
269269
adminUser,
270+
response,
270271
adminforth: this.adminforth
271272
});
272273
if (!error && resp.error) {
@@ -290,6 +291,7 @@ export default class ConfigValidator implements IConfigValidator {
290291
record,
291292
adminUser,
292293
recordId: recordId,
294+
response,
293295
adminforth: this.adminforth,
294296
});
295297
}

adminforth/modules/restApi.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,7 +1448,7 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
14481448
server.endpoint({
14491449
method: 'POST',
14501450
path: '/start_bulk_action',
1451-
handler: async ({ body, adminUser, tr }) => {
1451+
handler: async ({ body, adminUser, tr, response }) => {
14521452
const { resourceId, actionId, recordIds } = body;
14531453
const resource = this.adminforth.config.resources.find((res) => res.resourceId == resourceId);
14541454
if (!resource) {
@@ -1473,13 +1473,13 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
14731473
return { error: await tr(`Action "{actionId}" not allowed`, 'errors', { actionId: action.label }) };
14741474
}
14751475
}
1476-
const response = await action.action({selectedIds: recordIds, adminUser, resource, tr});
1476+
const bulkActionResponse = await action.action({selectedIds: recordIds, adminUser, resource, response, tr});
14771477

14781478
return {
14791479
actionId,
14801480
recordIds,
14811481
resourceId,
1482-
...response
1482+
...bulkActionResponse
14831483
}
14841484
}
14851485
})

adminforth/types/Back.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,8 +1535,8 @@ export interface AdminForthBulkAction extends AdminForthBulkActionCommon {
15351535
* Callback which will be called on backend when user clicks on action button.
15361536
* It should return Promise which will be resolved when action is done.
15371537
*/
1538-
action: ({ resource, selectedIds, adminUser, tr }: {
1539-
resource: AdminForthResource, selectedIds: Array<any>, adminUser: AdminUser, tr: (key: string, category?: string, params?: any) => string
1538+
action: ({ resource, selectedIds, adminUser, response, tr }: {
1539+
resource: AdminForthResource, selectedIds: Array<any>, adminUser: AdminUser, response: IAdminForthHttpResponse, tr: (key: string, category?: string, params?: any) => string
15401540
}) => Promise<{ ok: boolean, error?: string, successMessage?: string }>,
15411541

15421542
/**

0 commit comments

Comments
 (0)