PhoenixKitProjects.Web.Widgets.Helpers (PhoenixKitProjects v0.17.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.

A single-row instance renders dense (tighter frame, smaller title).

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. small? lets a widget force its most compact view.

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

A shared widget card frame: header (icon + title + optional link) + body slot. compact (a single-row instance) tightens the paddings so the minimum box fits without a scrollbar.

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.

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

A widget is small (force compact) when narrower than w or shorter than h.

The 'projects module is off' placeholder body.

Functions

available?()

@spec available?() :: boolean()

True when the projects module is loaded and enabled.

compact?(size)

@spec compact?(map() | nil) :: boolean()

A single-row instance renders dense (tighter frame, smaller title).

date(dt)

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

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

effective_view(view, valid, small? \\ false)

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

Pick the effective view: honor the selected view if it's one of valid, else the first valid view. small? lets a widget force its most compact view.

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)

frame(assigns)

A shared widget card frame: header (icon + title + optional link) + body slot. compact (a single-row instance) tightens the paddings so the minimum box fits without a scrollbar.

Attributes

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

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.

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.

small?(size, w, h)

@spec small?(map() | nil, integer(), integer()) :: boolean()

A widget is small (force compact) when narrower than w or shorter than h.

unavailable(assigns)

The 'projects module is off' placeholder body.