Result builder

Actions can be configured to achieve different results in the GUI.

Most actions will simply perform work and display the default notification, however, other behaviors are possible:

Default behavior

The default behavior, when no exception is thrown in the handler is to display a generic notification.

Traditional Syntax

Using full context methods with customize_collection:

include ForestAdmin::Types

@create_agent.customize_collection('company') do |collection|
  collection.add_action(
    'Mark as live',
    BaseAction.new(scope: ActionScope::SINGLE) do |context|
      # Not using the resultBuilder here will display the generic success notification.
      # (as long as no exception is thrown)
    end
  )
end

DSL Syntax

Using simplified helper methods with collection.action:

Custom notifications

When customizing the notification message, you can use the ForestAdminDatasourceCustomizer::Decorators::Action::ResultBuilder to generate different types of responses.

Traditional Syntax

Using full context methods with customize_collection:

DSL Syntax

Using simplified helper methods with collection.action:

HTML result

You can also return an HTML page to give more feedback to the user who triggered the Action.

File generation

Smart actions can be used to generate or download files.

The example code below will trigger a file download (with the file named filename.txt, containing StringThatWillBeInTheFile using text/plain mime-type).

Redirections

To streamline your operation workflow, it could make sense to redirect to another page after an Action has successfully been executed.

It is possible using the redirectTo function.

The redirection works both for internal (\*.forestadmin.com pages) and external links.

Webhooks

After an action you can set up an HTTP (or HTTPS) callback - a webhook - to forward information to other applications.

Note that the webhook will be triggered from the user's browser, so it will be subject to CORS restrictions.

Its intended use is often to perform a login on a third-party application or to trigger a background job on the current user's behalf.

Last updated

Was this helpful?