Alternera.Resource.UI.Context (alternera_resource_ui v0.9.0)

Copy Markdown View Source

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.

  • tenant_id: the tenant.
  • actor: who is looking. Opaque: pass it to Ash as actor: (Alternera.Resource.UI.opts/1) and never match on it; it is the proxy's user, an API key's owner, or a test's stand-in.
  • can_write?: whether the viewer may change records here. It hides write controls; the resource's policies still decide at the write.
  • available?: whether the host serves resources now. The host mounts nothing without it, so a component sees true.
  • package_id: the package the component belongs to.
  • resource: %{name, module, label, lookup_key} of the resource the component belongs to; nil on a package's page or Workbench item.
  • timezone: the viewer's time zone, for showing times.
  • path: the page's own path, for links back to it.
  • place: where the component is mounted: :page (the Resources page or a package page), :workbench (a Workbench tab) or :test (the contract kit's harness).
  • key: the host's name for this mount. The functions in Alternera.Resource.UI put it on what they ask the host, so the host knows which component asked; a component never reads it.

The host builds it from the session; nothing in it comes from a client's parameters.

Summary

Functions

The fields every host passes, in order; a test keeps the host's in step.

The resource field for a resource module.

Types

resource()

@type resource() :: %{
  name: String.t(),
  module: module(),
  label: String.t(),
  lookup_key: atom() | nil
}

t()

@type t() :: %Alternera.Resource.UI.Context{
  actor: term(),
  available?: boolean(),
  can_write?: boolean(),
  key: term(),
  package_id: String.t(),
  path: String.t() | nil,
  place: :page | :workbench | :test,
  resource: resource() | nil,
  tenant_id: String.t(),
  timezone: String.t() | nil
}

Functions

fields()

@spec fields() :: [atom()]

The fields every host passes, in order; a test keeps the host's in step.

resource(module)

@spec resource(module()) :: resource()

The resource field for a resource module.