API Reference alternera_resource_ui v#0.9.0

Copy Markdown View Source

Modules

The contract of a resource package's own UI: components a package ships for its resources, which the proxy draws in its generated Resources page, in place of it, at a page of the package's own, or as a Workbench tab. docs/WRITING_RESOURCE_PLUGINS.md ("Your own UI") is the guide; the declarations are the ui section of alternera_resource and the alternera_ui section of the domain (Alternera.Resource.Info.ui/1).

An action declared with handler: (action :id, "Label" do handler M … end), for work that is not one Ash action of the resource: call a service, then write many records. An action that is one Ash action declares run: instead and needs no code.

Runs a resource's declared actions for the host: asks for the action's input and confirmation in a dialog, runs it in the background with the viewer's context, and shows the outcome, its message or its error, in that dialog. An action with no input and no confirmation opens the dialog as it starts, to show it running and then its outcome. An action with input stays open for another run (a second conversion); Close ends it. The runner sends no notification of its own: a handler that wants one calls Alternera.Resource.UI.notify/3. Only an outcome whose dialog is gone (closed while it ran, or the host moved on) is said in a notification, as nothing else would show it. An outcome that opens something (open:) closes the dialog. The host mounts one per mounted surface and one on the generated page, with id, ctx (whose resource is the resource the actions belong to) and nothing else.

The declared actions of a resource (action :id, "Label" in its ui): who may run one, what it asks for, and running it. The host's buttons, its dialog (Alternera.Resource.UI.ActionRunner) and the contract kit's harness all run actions through here, so an action behaves the same wherever it is drawn.

Whether a package's declared UI modules are what their declarations say: each one compiled, use Alternera.Resource.UI with the kind its place needs, at a contract version the proxy speaks; each handler exports handle_action/4, each visible function exists. The SDK's verifier cannot see this (a module named in a declaration compiles later), so the proxy checks it at boot and the contract kit in a package's tests.

The building blocks a package's components draw with, beside the proxy's look in Alternera.UIKit: buttons, cards, a table of records, a resource's actions and a field's value as the generated page shows it. use Alternera.Resource.UI imports them.

What every component of a resource package's UI is given, as its ctx assign: who is looking, in which tenant, at what, and where.

What a resource package's UI needs from the proxy at run time, as a behaviour: the page's own way of reading and writing records (Alternera.Resource.UI.Records calls it), and messages between a package's components.

The records a component shows, read and written the way the Resources page does: through the host (Alternera.Resource.UI.Host), with the context's tenant and actor, so the resource's policies decide, the history records the change, a cached resource drops its key, and every error is logged.

The optional callbacks of a surface (use Alternera.Resource.UI, :surface), for one offered as a Workbench item: the Workbench calls them as it calls its own item types.

The test kit for a package's own UI, run with no proxy around.

The endpoint a package's UI tests mount components under, with no proxy around. Alternera.Resource.UI.Test.start!/0 configures and starts it.

The LiveView that plays the host in a package's UI tests: it mounts the component under test (id "subject") and an action runner, does what the component asks the host (put_params, notify, subscribe, …) and tells the test process each request as {:resource_ui, request}. Mounted by Alternera.Resource.UI.Test.live_ui/3.

The host a package's own UI tests run against: records through Ash directly, with the context's tenant and actor, and messages between components within the test node. It is the default of config :alternera_resource_ui, :host, so a package needs no setting. Searching, sorting and paging happen in memory: a test's data is small.