Skip to main content

What are smart action intents ?

Action intents allows you to redirect your operators from the outside worlds directly to a specific action, by using an url. This means that your actions can now be accessed directly using a link (saving many clicks), link for which you can specify few parameters so can pre-compute your form with custom values for instance. All of our action types are supported (Global, Bulk and Single)

Building a smart action intent

Get to the index of the collection you want to share an action from, and retrieve its URl. For instance, given a project aProject, an environment anEnvironment, a team aTeam and a collection aCollection, the url should look similar to this: https://app.forestadmin.com/aProject/anEnvironment/aTeam/data/aCollection/index Base on that url, you can configure the action intent with 3 parameters:
  • actionIntent of type string, being the name of the action you want to redirect to.
  • actionIntentIds of type array of string, being the IDs of the records you want to execute the action for.
  • actionIntentParams of type JSON object, being the params you want to send along your action intent
Please do note that actionIntentIds and actionIntentParams should be a valid JSON structure
Here is an example of all of these parameters combined: https://app.forestadmin.com/aProject/anEnvironment/aTeam/data/aCollection/index?actionIntent=anActionName&actionIntentIds=[1,2]&actionIntentParams={"firstParam":"firstValue","secondParam":"secondValue"}

How to use actionIntentParams

actionIntentParams should be a valid JSON object
Your parameters provided to the action intent will be passed to your agent over change and load hooks, allowing you to compute any value for your fields based on the provided parameters. You can access those parameters like such:
const { collection } = require('forest-express-sequelize');
const { customers } = require('../models');

collection('aCollection', {
  actions: [{
    name: 'anAction',
    type: 'single',
    fields: [{
      field: 'aField',
      type: 'String',
      hook: 'onValueChange',
    }],
    hooks: {
      change: {
        onValueChange: ({ fields, request }) => {
          const actionIntentParams = request.body.data.attributes.action_intent_params;
          
          ...
          
          return fields;
        }
      },
      load: async ({ fields, request }) => {
        const actionIntentParams = request.body.data.attibutes.action_intent_params;
        
        ...
        
        return fields;
      },
    },
  }],
  ...
});

How to use actionIntentIds

actionIntentIds should be a valid JSON array, or a single id. It is also worth noting that for global action, any provided ids will be skipped. Also, action of type single should be having a single id provided, and bulk action should be passed having many provided
Ids configured in the action intent will be provided as usual within your context. Please refer to this documentation for more details.