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.

OptionTypeDefaultDescription
nameatomnoneRequired. Unique table identifier.
routeString.tnoneRequired. Base route for links (used in row actions).
stream_nameatomnonePhoenix 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.

OptionTypeDefaultDescription
actor_keyatom:current_userAssigns 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)noneFunction 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.

OptionTypeDefaultDescription
readatom | {atom, atom}noneThe 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.
getatom | {atom, atom}noneThe 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.
destroyatom | {atom, atom}noneThe 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.

OptionTypeDefaultDescription
alwayslist(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.
masterlist(atom | {atom, atom})[]Extra preloads for master users, in the same two forms.
tenantlist(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.

OptionTypeDefaultDescription
enabledbooleantrueSet false to switch archive off for this resource without removing the block.
restrictedbooleanfalseWhen true, only master users see the archive toggle.
visibleboolean | (any -> any) | mfatrueControls the archive toggle. Only a boolean acts. Gervaz does not evaluate a function, and the toggle then shows.
read_actionatom | {atom, atom}{:master_archived, :archived}Read archived action. Can be single atom or tuple {master_action, tenant_action}.
get_actionatom | {atom, atom}{:master_get_archived, :get_archived}Get archived action. Can be single atom or tuple.
restore_actionatom | {atom, atom}{:master_unarchive, :unarchive}Restore action. Can be single atom or tuple.
destroy_actionatom | {atom, atom}{:master_permanent_destroy, :permanent_destroy}Permanent destroy action. Can be single atom or tuple.