GreenAsh.Field (GreenAsh v0.3.0)

Copy Markdown View Source

Introspection of an Ash action -> field specs -> HTML widget type.

From a resource and an action, lists the fillable fields (accepted attributes + arguments) and decides which widget to render for each Ash type. Unrecognized types fall back to a JSON textarea (with a log).

specs/2 is pure introspection and touches no data. Relationship fields need the related records to offer a choice, so that read is a separate step — with_options/2.

Summary

Functions

Decides the HTML widget's type= for a given Ash type.

Options {label, value} for a select widget, or nil if not an enum.

Ordered list of fillable fields for action on resource: first the accepted attributes, then the action's arguments.

Fills in the choices of relationship fields by reading the related records.

Functions

input_type(type, constraints)

Decides the HTML widget's type= for a given Ash type.

options(type, constraints)

Options {label, value} for a select widget, or nil if not an enum.

specs(resource, action)

Ordered list of fillable fields for action on resource: first the accepted attributes, then the action's arguments.

with_options(specs, actor, tenant \\ nil)

Fills in the choices of relationship fields by reading the related records.

Separate from specs/2 because it reads: introspection can say a field points at another resource, but not what is in it. Needs the actor, so the choice is the one that actor is allowed to see.

A field is left exactly as specs/2 built it — a plain id box — whenever a choice cannot honestly be offered: more than 100 records, a resource needing a tenant the console cannot set, or a read the actor may not perform. Better a box you can paste an id into than an empty select that looks like the table is empty.