Building a Custom Action Button
In NocoBase, actions are buttons within blocks that trigger business logic -- such as "Create", "Edit", "Delete", etc. This example demonstrates how to build custom action buttons using ActionModel and control the scenarios where buttons appear using ActionSceneEnum.
It's recommended to familiarize yourself with the following content for a smoother development experience:
- Writing Your First Plugin -- Plugin creation and directory structure
- Plugin -- Plugin entry point and
load()lifecycle - FlowEngine -> Action Extension -- ActionModel, ActionSceneEnum introduction
- i18n Internationalization -- Translation file conventions and
tExpr()deferred translation usage
Final Result
We'll build three custom action buttons, each corresponding to a different action scenario:
- Collection-level action (
collection) -- Appears in the action bar at the top of the block, next to the "Create" button - Record-level action (
record) -- Appears in the action column of each table row, next to "Edit" and "Delete" - Both (
both) -- Appears in both scenarios
Full source code is available at @nocobase-example/plugin-simple-action. If you want to run it locally:
Let's build this plugin step by step from scratch.
Step 1: Create the Plugin Skeleton
Run the following in the repository root:
For detailed instructions, see Writing Your First Plugin.
Step 2: Create Action Models
Each action needs to declare the scenario it appears in via the static scene property:
Collection-Level Action
Create src/client-v2/models/SimpleCollectionActionModel.tsx:
Record-Level Action
Create src/client-v2/models/SimpleRecordActionModel.tsx:
Both Scenarios
Create src/client-v2/models/SimpleBothActionModel.tsx:
The structure of all three is identical -- the only differences are the static scene value and button text. Each button listens for click events via registerFlow({ on: 'click' }) and uses ctx.message to display a notification so users can see the button is working.
Step 3: Add Multilingual Files
Edit the translation files under the plugin's src/locale/:
Adding language files for the first time requires restarting the application to take effect.
For more about translation file conventions and tExpr() usage, see i18n Internationalization.
Step 4: Register in the Plugin
Edit src/client-v2/plugin.tsx to register with lazy-loading via registerModelLoaders:
Step 5: Enable the Plugin
Once enabled, you can add these custom action buttons from the "Configure Actions" menu in table blocks.
Full Source Code
- @nocobase-example/plugin-simple-action -- Complete example of three action scenarios
Summary
Capabilities used in this example:
Related Links
- Writing Your First Plugin -- Create a plugin skeleton from scratch
- FlowEngine Overview -- FlowModel basic usage
- FlowEngine -> Action Extension -- ActionModel, ActionSceneEnum
- FlowEngine -> Block Extension -- Custom blocks
- FlowEngine -> Field Extension -- Custom field components
- Component vs FlowModel -- When to use FlowModel
- Plugin -- Plugin entry point and load() lifecycle
- i18n Internationalization -- Translation file conventions and tExpr usage
- FlowEngine Complete Documentation -- Complete reference for FlowModel, Flow, Context

