Skip to main content

AdminForthBulkAction

AdminForthBulkAction: object

Type declaration

action()

action: ({ resource, selectedIds, adminUser }) => Promise<object>

Callback which will be called on backend when user clicks on action button. It should return Promise which will be resolved when action is done.

Parameters

ParameterType
{ resource, selectedIds, adminUser }object
{ resource, selectedIds, adminUser }.adminUserAdminUser
{ resource, selectedIds, adminUser }.resourceAdminForthResource
{ resource, selectedIds, adminUser }.selectedIdsany[]

Returns

Promise<object>

error?

optional error: string

ok

ok: boolean

successMessage?

optional successMessage: string

allowed()?

optional allowed: ({ resource, adminUser, selectedIds, allowedActions }) => Promise<boolean>

Allowed callback called to check whether action is allowed for user.

  1. It called first time when user goes to list view. If callback returns false, action button will be hidden on list view.
  2. This same callback called second time when user clicks an action button. If callback returns false, action will not be executed. In second time selectedIds will be passed to callback (because checkbox for items are selected), so you can use this to make additional checks ( for example to check if user has permission for certain records ).

Example:

allowed: async ({ resource, adminUser, selectedIds }) => {
if (adminUser.dbUser.role !== 'superadmin') {
return false;
}
return true;
}

Parameters

ParameterTypeDescription
{ resource, adminUser, selectedIds, allowedActions }object-
{ resource, adminUser, selectedIds, allowedActions }.adminUserAdminUserAdmin user object
{ resource, adminUser, selectedIds, allowedActions }.allowedActionsAllowedActionsResolved

Allowed standard actions for current user resolved by calling allowedActions callbacks if they are passed. You can use this variable to rely on standard actions permissions. E.g. if you have custom actions "Mark as read", you might want to allow it only for users who have "edit" action allowed:

Example:

options: {

bulkActions: [

{

label: 'Mark as read',

action: async ({ resource, recordIds }) => {

await markAsRead(recordIds);

},

allowed: ({ allowedActions }) => allowedActions.edit,

}

],

allowedActions: {

edit: ({ resource, adminUser, recordIds }) => {

return adminUser.dbUser.role === 'superadmin';

}

}

}

{ resource, adminUser, selectedIds, allowedActions }.resourceAdminForthResource-
{ resource, adminUser, selectedIds, allowedActions }.selectedIds?any[]recordIds will be passed only once user tries to perform bulk action by clicking on button

Returns

Promise<boolean>

confirm?

optional confirm: string

Confirmation message which will be displayed to user before action is executed.

icon?

optional icon: string

Icon for action button which will be displayed in the list view

id?

optional id: string

label

label: string

Label for action button which will be displayed in the list view

state

state: string

successMessage?

optional successMessage: string

Success message which will be displayed to user after action is executed.