Use a Smart Action Intent

Smart Action Intents

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

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

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:

/forest/aCollection.js
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

Ids configured in the action intent will be provided as usual within your context. Please refer to this documentation for more details.

Last updated

Was this helpful?