LightningWeb.WorkflowLive.Helpers (Lightning v2.15.0-pre4)

View Source

Helper functions for the Workflow LiveViews.

Summary

Functions

Builds a URL with query parameters based on parameter definitions.

Creates chat-related parameters

Creates code view parameters

Builds a URL to the collaborative editor with converted query parameters.

Creates orthogonal parameters (excludes mode and selection)

Creates a parameter definition with common defaults.

Creates parameters excluding mode and selection

Creates a parameter that pulls from query_params

Creates standard URL parameters (all common params)

Creates URL parameters ignoring v (all common params except version tag)

Creates parameters with custom overrides

Determines if a workflow is enabled based on its triggers. Accepts either a Workflow struct or an Ecto.Changeset.

Creates workflow input run parameters

Generates a tooltip describing the workflow's state. Accepts either a Workflow struct or an Ecto.Changeset.

Functions

broadcast_updated_params(socket, params)

build_url(assigns, params)

Builds a URL with query parameters based on parameter definitions.

Parameters

  • assigns - The assigns from the LiveView
  • params - List of parameter definitions. Each definition is a keyword list with:
    • :name - The parameter name in the URL (required)
    • :value - The value or a function that receives (assigns, params) (required)
    • :when - Condition as boolean or function that receives (assigns, params) (default: true)
    • :transform - Optional transformation function applied to the value

chat_params()

Creates chat-related parameters

code_view_params()

Creates code view parameters

collaborative_editor_url(params, live_action)

Builds a URL to the collaborative editor with converted query parameters.

This function uses a data-driven approach with the @param_mappings configuration to convert classical editor parameters to collaborative editor equivalents.

Conversion Rules

  • a (followed run) → run
  • s (selected step) → job/trigger/edge (context-aware based on selection)
  • m=expandpanel=editor
  • m=workflow_inputpanel=run
  • m=settingspanel=settings
  • Preserves: v, method, w-chat, j-chat, code
  • Skips: panel (collaborative-only)

Parameters

  • params - Route parameters map containing:
    • "project_id" - Project UUID (required)
    • "id" - Workflow UUID (required for :edit, absent for :new)
    • Additional query parameters to preserve (e.g., "s", "m", "v")
  • live_action - Current LiveView action (:new or :edit)

Returns

A complete URL string for the collaborative editor with transformed query parameters

Examples

# Edit existing workflow with query params
iex> collaborative_editor_url(%{
...>   "project_id" => "proj-1",
...>   "id" => "wf-1",
...>   "s" => "job-abc",
...>   "m" => "expand"
...> }, :edit)
"/projects/proj-1/w/wf-1/collaborate?job=job-abc&panel=editor"

# New workflow
iex> collaborative_editor_url(%{
...>   "project_id" => "proj-1"
...> }, :new)
"/projects/proj-1/w/new/collaborate"

# With multiple query params
iex> collaborative_editor_url(%{
...>   "project_id" => "proj-1",
...>   "id" => "wf-1",
...>   "s" => "job-123",
...>   "v" => "42",
...>   "custom" => "value"
...> }, :edit)
"/projects/proj-1/w/wf-1/collaborate?custom=value&job=job-123&v=42"

orthogonal_params()

Creates orthogonal parameters (excludes mode and selection)

param(name, value, opts \\ [])

Creates a parameter definition with common defaults.

params_without_mode_selection()

Creates parameters excluding mode and selection

query_param(name)

Creates a parameter that pulls from query_params

run_workflow(workflow_or_changeset, params, opts)

@spec run_workflow(
  Ecto.Changeset.t(Lightning.Workflows.Workflow.t())
  | Lightning.Workflows.Workflow.t(),
  map(),
  selected_job: map(),
  created_by: map(),
  project: map()
) ::
  {:ok,
   %{
     workorder: Lightning.WorkOrder.t(),
     workflow: Lightning.Workflows.Workflow.t(),
     message: Lightning.Extensions.UsageLimiting.message()
   }}
  | {:error, Ecto.Changeset.t(Lightning.Workflows.Workflow.t())}
  | {:error, Ecto.Changeset.t(Lightning.WorkOrders.Manual.t())}
  | {:error, Lightning.Extensions.UsageLimiting.message()}
  | {:error, :workflow_deleted}

save_workflow(changeset, actor)

@spec save_workflow(
  Ecto.Changeset.t(),
  struct()
) ::
  {:ok, Lightning.Workflows.Workflow.t()}
  | {:error,
     Ecto.Changeset.t()
     | Lightning.Extensions.UsageLimiting.message()
     | :workflow_deleted}

standard_params()

Creates standard URL parameters (all common params)

subscribe_to_params_update(socket_id)

to_latest_params()

Creates URL parameters ignoring v (all common params except version tag)

with_params(overrides \\ [])

Creates parameters with custom overrides

workflow_enabled?(workflow)

Determines if a workflow is enabled based on its triggers. Accepts either a Workflow struct or an Ecto.Changeset.

workflow_input_params(selection_id)

Creates workflow input run parameters

workflow_state_tooltip(changeset)

Generates a tooltip describing the workflow's state. Accepts either a Workflow struct or an Ecto.Changeset.