Row and bulk actions
A row action shows up in a row's menu, under your plugin's name. Use it to copy a row as JSON, open it in another tool or mark it archived. Add bulk and it also appears on the selection toolbar, where it runs on every selected row.
Declare it
{
"permissions": { "data": "write", "clipboard": true },
"contributes": {
"rowActions": [
{ "id": "copy-json", "title": "Copy as JSON", "icon": "braces" },
{ "id": "copy-csv", "title": "Copy as CSV", "icon": "sheet", "bulk": true },
{
"id": "archive",
"title": "Archive",
"icon": "archive",
"bulk": true,
"write": true
}
]
}
}| Field | What it does |
|---|---|
bulk | Also shows the action on the selection toolbar, called with every selected row. |
write | Marks the action as one that changes data. Flare refuses it unless permissions.data is write. |
icon | A Lucide icon name, shown beside the title. |
Write the action
An action gets the records it runs on and the container they're in, plus ctx. From a row's menu that's one record. From the toolbar it's the whole selection. Return a message and Flare shows it:
import { definePlugin } from '@flare/plugin';
export default definePlugin({
rowActions: {
'copy-json': async ({ records }, ctx) => {
const values = records.map((record) => record.values);
await ctx.copy(JSON.stringify(values.length === 1 ? values[0] : values, null, 2));
return { message: `Copied ${records.length} as JSON` };
},
},
});Each record is a DataRecord with an id, a path and its values by field. Copying needs the clipboard permission.
Change data
Write through ctx.data. Flare handles the change like one the user made, so production asks first and Activity records it. Scopes and permissions has the details.
import { definePlugin, PluginError } from '@flare/plugin';
export default definePlugin({
rowActions: {
archive: async ({ records, container }, ctx) => {
try {
for (const { id } of records) {
await ctx.data.update(container, id, { archived: true });
}
return { message: `Archived ${records.length}`, tone: 'positive' };
} catch (error) {
// The user said no on production: nothing was changed, and nothing is wrong.
if (error instanceof PluginError && error.code === 'WRITE_CANCELLED') return;
throw error;
}
},
},
});If the user declines, the call rejects with a PluginError whose code is WRITE_CANCELLED. Catch it and return quietly. Flare shows any other error to the user and writes it to the plugin's log.
Mark every write
Set "write": true on any action that can change data, even if it only writes sometimes. Users then know from the manifest, before they install, that the plugin can change records.
Where it appears
Actions appear in the row menu of every table: SQL tables, Redis keys, query results and the Firestore workspace. They're grouped under your plugin's name. Actions with bulk also appear on the selection toolbar when one or more rows are selected. If you set engines, they only appear on those databases.