Class: Plutonium::Wizard::StepAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/plutonium/wizard/step_adapter.rb

Overview

Presents a wizard Step in the shape the existing resource-form pipeline (Plutonium::UI::Form::Resource) consumes from a definition (§7). The form renders a step exactly like a resource/interaction definition by reading:

- `defined_fields`            — empty; a step carries no separate field
                              config, only `input`s.
- `defined_inputs`            — the step's merged inline + imported inputs
                              (`{name => {options:, block:}}`).
- `defined_structured_inputs` — the step's structured inputs.
- `resolve_form_sections`     — the step's resolved form layout (inline
                              `form_layout` or one inherited from `using:`),
                              normalized to ResolvedSections; nil → single
                              grid.

This is the seam that lets a wizard step ride the resource-form rendering path unchanged — seeded from the wizard's typed data (the form object), which is what makes resume/back rehydration (including repeater rows) work.

Constant Summary collapse

STAGING_ONLY_INPUT_OPTIONS =

Options on a file input that are consumed SERVER-SIDE by Wizard::Driving (from the raw step) to stage the upload — never form/HTML concerns. They must be stripped from what the form renders: Phlex rejects a Class-valued uploader: as an attribute, and backend: would otherwise leak as a stray attribute. Driving reads them off step.inputs directly, so removing them here is invisible to staging.

%i[backend uploader].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(step) ⇒ StepAdapter

Returns a new instance of StepAdapter.



31
32
33
# File 'lib/plutonium/wizard/step_adapter.rb', line 31

def initialize(step)
  @step = step
end

Instance Attribute Details

#stepObject (readonly)

Returns the value of attribute step.



35
36
37
# File 'lib/plutonium/wizard/step_adapter.rb', line 35

def step
  @step
end

Instance Method Details

#defined_fieldsObject

The form's per-field config map. A step declares inputs, not fields, so there is no separate field config — return an empty map. The form merges defined_fields[name] (here {}) with defined_inputs[name].



40
# File 'lib/plutonium/wizard/step_adapter.rb', line 40

def defined_fields = {}

#defined_inputsObject

{name => {options:, block:}} — inline + using:-imported inputs, with the server-side staging options stripped so they don't render as HTML attributes.



44
45
46
47
48
49
50
51
# File 'lib/plutonium/wizard/step_adapter.rb', line 44

def defined_inputs
  step.inputs.transform_values do |config|
    options = config[:options]
    next config if options.nil? || STAGING_ONLY_INPUT_OPTIONS.none? { |k| options.key?(k) }

    config.merge(options: options.except(*STAGING_ONLY_INPUT_OPTIONS))
  end
end

#defined_nested_inputsObject

The resource form never imports nested-resource inputs from a wizard step.



57
# File 'lib/plutonium/wizard/step_adapter.rb', line 57

def defined_nested_inputs = {}

#defined_structured_inputsObject

{name => {options:, block:}} — structured (single/repeater) inputs.



54
# File 'lib/plutonium/wizard/step_adapter.rb', line 54

def defined_structured_inputs = step.structured_inputs

#resolve_form_sections(resource_fields) ⇒ Object

Resolve the step's form layout into ordered ResolvedSections (the shape the resource form's resolve_form_layout expects), or nil for a single grid.

The step's form_layout is either:

- inline  → an Array<FormLayout::Section> (unresolved), or
- imported → an Array<FormLayout::ResolvedSection> (already resolved by
the FieldImporter, filtered to imported fields).

Normalize both to ResolvedSections claiming only currently-permitted fields.



71
72
73
74
75
76
77
78
79
# File 'lib/plutonium/wizard/step_adapter.rb', line 71

def resolve_form_sections(resource_fields)
  layout = step.form_layout
  return nil if layout.blank?

  resource_fields = resource_fields.map(&:to_sym)
  return resolve_resolved_sections(layout, resource_fields) if layout.first.is_a?(Plutonium::Definition::FormLayout::ResolvedSection)

  resolve_raw_sections(layout, resource_fields)
end

#submit_and_continueObject

Auto-detect submit-and-continue is disabled for wizards (the wizard owns its own Back/Next/Finish navigation).



61
# File 'lib/plutonium/wizard/step_adapter.rb', line 61

def submit_and_continue = false