Table identity and source DSL
v0.0.1
The identity and source sections of a resource's table block name the table, set the Ash actions it runs, choose what it preloads and turn archive on. The actions, actor_key and master_check you leave out take their value from the domain. See Domain DSL.
identity
Names the table and gives it a base route. Both name and route are required once the table has a column, filter, row action or bulk action. It sits at mishka_gervaz.table.identity.
| Option | Type | Default | Description |
|---|---|---|---|
name | atom | none | Required. Unique table identifier. |
route | String.t | none | Required. Base route for links (used in row actions). |
stream_name | atom | none | Phoenix stream name. Defaults to the name plus _stream. |
The route may hold params, such as "/admin/dashboard/document/sections/:workspace_version_id". They are available as state.path_params, and a param whose name matches an attribute of the resource becomes a filter on the query: nil becomes is_nil(attribute), a list on a scalar attribute becomes attribute in list, and anything else becomes attribute == value. The reader cannot clear a path param filter.
source
Sets the actor and the master check. Its entities set the actions, the preloads and the archive. It sits at mishka_gervaz.table.source.
| Option | Type | Default | Description |
|---|---|---|---|
actor_key | atom | :current_user | Assigns key for current user. Stored in the config. The components take the actor from their current_user assign, and no built-in code reads this key. |
master_check | (any -> any) | none | Function returning true for master users. fn user -> boolean Stored in the config. The built-in access modules do not call it: they treat a user whose site_id is nil as a master. To change the rule, override master_user?/1 in a custom access module. |
actions
Maps the table to Ash actions. Every action named, both elements of a tuple, must exist on the resource with the matching kind. It sits at mishka_gervaz.table.source.actions.
| Option | Type | Default | Description |
|---|---|---|---|
read | atom | {atom, atom} | none | The read action. An atom serves master and tenant users alike. A tuple {master_action, tenant_action} gives each its own. Required on the resource or on the domain. |
get | atom | {atom, atom} | none | The get action, in the same two forms. Required on the resource or the domain once a row is interactive: a selectable row, any bulk action, or a row action of type :destroy, :update, :unarchive, :permanent_destroy or :accordion. |
destroy | atom | {atom, atom} | none | The destroy action, in the same two forms. Required on the resource or the domain once a row action or a bulk action has type :destroy. |
preload
Relationships the table loads, in three tiers. It sits at mishka_gervaz.table.source.preload.
| Option | Type | Default | Description |
|---|---|---|---|
always | list(atom | {atom, atom}) | [] | Relationships to preload for every user. An entry is an atom, or a {source, alias} tuple (also written site: :site_info) that preloads source and exposes it under alias. |
master | list(atom | {atom, atom}) | [] | Extra preloads for master users, in the same two forms. |
tenant | list(atom | {atom, atom}) | [] | Extra preloads for tenant users, in the same two forms. Together with master, it lets each role expose a different relationship under one alias. |
archive
Soft-delete support. The resource needs AshArchival.Resource, and a resource that has it needs an archive block on itself or on its domain. It sits at mishka_gervaz.table.source.archive.
The Default column shows the value Gervaz uses when neither the resource nor the domain sets the key.
| Option | Type | Default | Description |
|---|---|---|---|
enabled | boolean | true | Set false to switch archive off for this resource without removing the block. |
restricted | boolean | false | When true, only master users see the archive toggle. |
visible | boolean | (any -> any) | mfa | true | Controls the archive toggle. Only a boolean acts. Gervaz does not evaluate a function, and the toggle then shows. |
read_action | atom | {atom, atom} | {:master_archived, :archived} | Read archived action. Can be single atom or tuple {master_action, tenant_action}. |
get_action | atom | {atom, atom} | {:master_get_archived, :get_archived} | Get archived action. Can be single atom or tuple. |
restore_action | atom | {atom, atom} | {:master_unarchive, :unarchive} | Restore action. Can be single atom or tuple. |
destroy_action | atom | {atom, atom} | {:master_permanent_destroy, :permanent_destroy} | Permanent destroy action. Can be single atom or tuple. |