Documentation / @zerotal/admin / index / Action
Class: Action
Defined in: admin/src/actions/Action.ts:66
Constructors
Constructor
new Action(
key):Action
Defined in: admin/src/actions/Action.ts:91
Parameters
key
string
Returns
Action
Methods
make()
staticmake(key):Action
Defined in: admin/src/actions/Action.ts:95
Parameters
key
string
Returns
Action
label()
label(
label):this
Defined in: admin/src/actions/Action.ts:101
Parameters
label
string
Returns
this
icon()
icon(
name):this
Defined in: admin/src/actions/Action.ts:106
Parameters
name
string
Returns
this
color()
color(
color):this
Defined in: admin/src/actions/Action.ts:111
Parameters
color
Returns
this
iconButton()
iconButton(
value?):this
Defined in: admin/src/actions/Action.ts:117
Render as an icon-only square button (row actions).
Parameters
value?
boolean = true
Returns
this
danger()
danger(
value?):this
Defined in: admin/src/actions/Action.ts:123
Style as destructive (red). Shorthand for .color("destructive").
Parameters
value?
boolean = true
Returns
this
requiresConfirmation()
requiresConfirmation(
message?):this
Defined in: admin/src/actions/Action.ts:132
Require a confirmation dialog before the handler runs (Flow confirm).
Parameters
message?
string = "Are you sure?"
Returns
this
url()
url(
fn):this
Defined in: admin/src/actions/Action.ts:138
Make this a link action that navigates to the resolved URL.
Parameters
fn
(ctx) => string
Returns
this
formUsing()
formUsing(
fn):this
Defined in: admin/src/actions/Action.ts:151
Build the modal's fields from what it currently holds, rather than fixing them upfront.
This is what lets a modal have a second step: an import shows a file picker, and once a file is there, a mapping row per column in it. The fields are recomputed on every render, so the modal follows the data.
Parameters
fn
(data, resource) => Field[]
Returns
this
fieldsFor()
fieldsFor(
data,resource):Field[]
Defined in: admin/src/actions/Action.ts:157
The fields to render for the modal's current state.
Parameters
data
Record<string, unknown>
resource
typeof Resource
Returns
Field[]
run()
run(
fn):this
Defined in: admin/src/actions/Action.ts:163
Make this a callback action that runs fn on the server.
Parameters
fn
Returns
this
excludeAttributes()
excludeAttributes(
keys):this
Defined in: admin/src/actions/Action.ts:173
Attributes a replicateAction leaves behind, on top of the primary key and timestamps it always drops. Use it for anything that must stay unique — a slug, an invoice number, an external id.
Parameters
keys
string[]
Returns
this
beforeReplicaSaved()
beforeReplicaSaved(
fn):this
Defined in: admin/src/actions/Action.ts:179
Adjust a replica's data just before it is created.
Parameters
fn
(data) => Record<string, unknown>
Returns
this
form()
form(
fields):this
Defined in: admin/src/actions/Action.ts:195
Open a modal form before running. The submitted (validated) values arrive on
ctx.data:
action("ban").label("Ban user").icon("shield").color("destructive") .form([ textarea("reason").label("Reason").required() ]) .run(async ({ record, resource, data, page }) => { await resource.update(record!.id, { banned: true, ban_reason: data!.reason }); page.flash("User banned."); });
Parameters
fields
Field[]
Returns
this
modalHeading()
modalHeading(
text):this
Defined in: admin/src/actions/Action.ts:201
Heading shown at the top of the action's modal (defaults to the label).
Parameters
text
string
Returns
this
modalSubmitLabel()
modalSubmitLabel(
text):this
Defined in: admin/src/actions/Action.ts:207
Submit-button label inside the modal (defaults to the action label).
Parameters
text
string
Returns
this
hasForm()
hasForm():
boolean
Defined in: admin/src/actions/Action.ts:213
True when this action opens a modal form.
Returns
boolean
successMessage()
successMessage(
message):this
Defined in: admin/src/actions/Action.ts:219
Flash this message after a successful callback action.
Parameters
message
string
Returns
this
visible()
visible(
fn):this
Defined in: admin/src/actions/Action.ts:225
Conditionally show the action for a given record.
Parameters
fn
Returns
this
authorize()
authorize(
fn):this
Defined in: admin/src/actions/Action.ts:234
Permission gate — ANDed with visible. Decoupled from any specific auth
package: pass a predicate (e.g. () => Auth.can("update", record)).
Parameters
fn
Returns
this
getLabel()
getLabel():
string
Defined in: admin/src/actions/Action.ts:247
Returns
string
isLink()
isLink():
boolean
Defined in: admin/src/actions/Action.ts:251
Returns
boolean
isVisibleFor()
isVisibleFor(
record,ctx):boolean
Defined in: admin/src/actions/Action.ts:255
Parameters
record
AdminRecord | undefined
ctx
Returns
boolean
href()
href(
ctx):string|null
Defined in: admin/src/actions/Action.ts:261
Parameters
ctx
Returns
string | null
execute()
execute(
ctx):Promise<void>
Defined in: admin/src/actions/Action.ts:266
Run the callback (applies the success flash unless the handler redirected).
Parameters
ctx
Returns
Promise<void>