PhoenixKitDashboards.Web.Helpers (PhoenixKitDashboards v0.2.1)

Copy Markdown View Source

Cross-cutting helpers shared by the Dashboards LiveViews.

actor_opts/1 is the canonical way to thread the acting user's uuid into context mutations that accept a trailing opts \ [] (for activity logging).

Summary

Functions

Keyword opts threading the acting user's uuid into context mutations.

The current user's uuid from socket assigns, or nil.

All roles (for pickers); [] when the roles API is unavailable.

Whether actor_uuid may manage (edit/delete) dashboard: own personal ones, or any shared/role one (the admin section is already owner/admin-gated). Takes the actor uuid so socket callers (actor_uuid(socket)) and render-side callers (the current-user uuid) share one rule — replacing the former can_delete? / deletable? / can_manage? triplet.

Translated label for a dashboard scope enum value.

Dynamic translation for catalog DATA (widget names, descriptions, view names, settings labels — plain strings from the provider contract). Falls back to the input when no translation exists, so provider strings pass through.

The current user's role uuids, mapped from the scope's cached role names — used by both LiveViews to resolve role-scoped dashboard visibility. Reuses a @roles assign if present, else queries core once. [] when roles are unavailable.

Whether dashboard is viewable by the socket's user (own personal · any shared/system · role dashboards for the user's roles). The single view rule, shared by the list page and the builder so the two never disagree.

Functions

actor_opts(socket)

@spec actor_opts(Phoenix.LiveView.Socket.t()) :: keyword()

Keyword opts threading the acting user's uuid into context mutations.

Returns [actor_uuid: uuid], or [] when there is no current user (so the context call is unaffected).

actor_uuid(socket)

@spec actor_uuid(Phoenix.LiveView.Socket.t()) :: String.t() | nil

The current user's uuid from socket assigns, or nil.

list_roles()

@spec list_roles() :: [struct()]

All roles (for pickers); [] when the roles API is unavailable.

manageable_by?(dashboard, actor_uuid)

@spec manageable_by?(map(), String.t() | nil) :: boolean()

Whether actor_uuid may manage (edit/delete) dashboard: own personal ones, or any shared/role one (the admin section is already owner/admin-gated). Takes the actor uuid so socket callers (actor_uuid(socket)) and render-side callers (the current-user uuid) share one rule — replacing the former can_delete? / deletable? / can_manage? triplet.

scope_label(other)

@spec scope_label(String.t()) :: String.t()

Translated label for a dashboard scope enum value.

translate_catalog(string)

@spec translate_catalog(String.t() | nil) :: String.t() | nil

Dynamic translation for catalog DATA (widget names, descriptions, view names, settings labels — plain strings from the provider contract). Falls back to the input when no translation exists, so provider strings pass through.

user_role_uuids(socket)

@spec user_role_uuids(Phoenix.LiveView.Socket.t()) :: [String.t()]

The current user's role uuids, mapped from the scope's cached role names — used by both LiveViews to resolve role-scoped dashboard visibility. Reuses a @roles assign if present, else queries core once. [] when roles are unavailable.

viewable_by?(dashboard, socket)

@spec viewable_by?(map(), Phoenix.LiveView.Socket.t()) :: boolean()

Whether dashboard is viewable by the socket's user (own personal · any shared/system · role dashboards for the user's roles). The single view rule, shared by the list page and the builder so the two never disagree.