Class: LcpRuby::Workflow::TransitionActionBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/lcp_ruby/workflow/transition_action_builder.rb

Class Method Summary collapse

Class Method Details

.build_actions(record, workflow_definition:, user:, evaluator:, presenter_overrides: {}, state_machine: nil) ⇒ Array<Hash>

Builds action hashes for transitions available on a record. Used by ActionSet to inject transition buttons on show/index pages.

Parameters:

  • record (Object)

    the current record

  • workflow_definition (WorkflowDefinition)
  • user (Object)

    current user

  • evaluator (Authorization::PermissionEvaluator)
  • presenter_overrides (Hash) (defaults to: {})

    transition name => override hash (pre-built by ActionSet)

Returns:

  • (Array<Hash>)

    action hashes for rendering



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/lcp_ruby/workflow/transition_action_builder.rb', line 13

def self.build_actions(record, workflow_definition:, user:, evaluator:, presenter_overrides: {}, state_machine: nil)
  machine = state_machine || StateMachine.new(workflow_definition)
  available = machine.available_transitions(record, user: user, evaluator: evaluator)

  available.filter_map do |transition|
    next if transition.system_only?

    override = presenter_overrides[transition.name]
    next if override && override["visible"] == false

    label = resolve_label(workflow_definition, transition)

    action = {
      "name" => transition.name,
      "type" => "transition",
      "label" => label,
      "icon" => override&.dig("icon") || transition.icon,
      "style" => override&.dig("style") || transition.style,
      "confirm" => transition.confirm,
      "confirm_message" => transition.confirm_message,
      "require_comment" => transition.require_comment
    }.compact

    action
  end
end