PhoenixKitProjects.Web.Widgets.Helpers (PhoenixKitProjects v0.18.0)

Copy Markdown View Source

Shared helpers + frame for the dashboard widgets phoenix_kit_projects contributes to phoenix_kit_dashboards via phoenix_kit_widgets/0.

Each widget is a Phoenix.LiveComponent the dashboards host renders with settings / view / size / scope assigns. These helpers centralize the enablement guard, the lenient project resolver (widgets pick a project by a free-text "project" setting, since a dashboard widget's settings schema is static), the shared card frame, and small formatters.

Summary

Functions

True when the projects module is loaded and enabled.

Format a datetime as YYYY-MM-DD, or .

Pick the effective view: honor the selected view if it's one of valid, else the first valid view. The user's choice is NEVER overridden by size — content self-fits via container-query type scaling instead.

A centered, iconed empty-state body (widgets must never look broken-empty).

A scale-aware self-fit font-size style: the type grows with its cq slot but stays clamped to a consistent px range, so widgets look cohesive at any box size (no comically large list rows, no unreadable KPI labels). The --pk-scale var (set by the dashboards fit hook) keeps the clamp proportional when the board renders scaled down.

A shared widget card frame: header (icon + title + optional link) + body slot.

Format estimated hours compactly (e.g. 12h, 1.5h, ).

Resolve the "project" widget setting (a uuid, exact name, external id, or a name substring) to a %Project{}. Falls back to the first running project (or any project) when the setting is blank, so a freshly-added widget shows data.

Projects.list_projects/0 with the widget no-crash guard: a transient DB error (connection loss, mid-migration missing table) degrades to an empty list — a widget must never crash the host dashboard.

Projects.project_summary/1 with the widget no-crash guard — nil on a DB error, which every consuming widget already renders as its empty state.

The current user's uuid out of the host-provided scope assign, or nil.

The 'projects module is off' placeholder body.

Functions

available?()

@spec available?() :: boolean()

True when the projects module is loaded and enabled.

date(dt)

@spec date(DateTime.t() | nil) :: String.t()

Format a datetime as YYYY-MM-DD, or .

effective_view(view, valid)

@spec effective_view(String.t() | nil, [String.t()]) :: String.t()

Pick the effective view: honor the selected view if it's one of valid, else the first valid view. The user's choice is NEVER overridden by size — content self-fits via container-query type scaling instead.

empty(assigns)

A centered, iconed empty-state body (widgets must never look broken-empty).

Attributes

  • icon (:string) - Defaults to "hero-clipboard-document-list".
  • message (:string) (required)

fit_text(min_px, cq, max_px)

@spec fit_text(number(), String.t(), number()) :: String.t()

A scale-aware self-fit font-size style: the type grows with its cq slot but stays clamped to a consistent px range, so widgets look cohesive at any box size (no comically large list rows, no unreadable KPI labels). The --pk-scale var (set by the dashboards fit hook) keeps the clamp proportional when the board renders scaled down.

frame(assigns)

A shared widget card frame: header (icon + title + optional link) + body slot.

Attributes

  • title (:string) (required)
  • icon (:string) - Defaults to "hero-clipboard-document-list".
  • href (:string) - Defaults to nil.

Slots

  • inner_block (required)
  • actions

hours(h)

@spec hours(number() | nil) :: String.t()

Format estimated hours compactly (e.g. 12h, 1.5h, ).

resolve_project(setting)

@spec resolve_project(term()) :: PhoenixKitProjects.Schemas.Project.t() | nil

Resolve the "project" widget setting (a uuid, exact name, external id, or a name substring) to a %Project{}. Falls back to the first running project (or any project) when the setting is blank, so a freshly-added widget shows data.

safe_list_projects()

@spec safe_list_projects() :: [PhoenixKitProjects.Schemas.Project.t()]

Projects.list_projects/0 with the widget no-crash guard: a transient DB error (connection loss, mid-migration missing table) degrades to an empty list — a widget must never crash the host dashboard.

safe_project_summary(project)

@spec safe_project_summary(PhoenixKitProjects.Schemas.Project.t()) :: map() | nil

Projects.project_summary/1 with the widget no-crash guard — nil on a DB error, which every consuming widget already renders as its empty state.

scope_user_uuid(scope)

@spec scope_user_uuid(term()) :: String.t() | nil

The current user's uuid out of the host-provided scope assign, or nil.

unavailable(assigns)

The 'projects module is off' placeholder body.