This is the official documentation of Forest Admin Cloud.
Actions allow users to trigger custom HTTP API calls, encapsulating custom business logic or initiating workflows on third-party tools. These actions are shown as buttons on the admin panel and are connected to specific collections to make sure they are related to the data being handled.
Before proceeding with this section to learn how to create an action using Code customization, it is recommended to first create your action using UI Customization, which is quicker and easier. This section aims to provide you with the most flexibility in creating actions, including advanced customization options.
Ensure you update the collection and action names as needed.
src/index.ts
importtype{Agent}from'@forestadmin/forest-cloud';import{Schema}from'../typings';exportdefaultfunctioncustomizeAgent(agent:Agent<Schema>){agent.customizeCollection('users',collection=>collection.addAction('Ban user',{scope:'Single',execute:asynccontext=>{ // Your business logic here.},}), );}
To make the code easier to read, all the code snippets below should be wrapped in the following code.
Creating an Action
First, you need to call the customizeCollection() method on the agent.
Arguments:
name*String: The name of the collection to customize.
handle*Function: A function that has the collection instance as an argument to start customizing it.
Next, you can invoke the addAction() method on the collection instance to create an action in Forest Admin:
Arguments:
name*String: The name of the action.
definition*Object: A JavaScript object that contains the definition of the action: