diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..6dfc09d --- /dev/null +++ b/TODO.md @@ -0,0 +1,54 @@ +## What needs to be done + +### State store inspection + +Would be good to inspect the state store all step attributes and return what is on repository in +a very explanable manner (step attribute and repository value): + +```ruby +state_store.inspect +``` + +### README + +The readme is a mess. + +We need to explain many concepts first: + +* Repository +* State Store +* Step +* Wizard +* Route Strategy +* Steps Processors +* Steps operator +* Inspect +* Logger + +MOST IMPORTANT: Explain data flow: + +* The data flow - devs are confusing +* Explain in ASCII diagram +* Make simple examples + +Explain Navigation flow: + +* DSL Definitions on Wizard#steps_processor +* Method definitions in wizard (although state store is recommended) +* Explain flow_path, saved_path, valid_path +* Explain current_step, next_step, previous_step +* Explain current_step_path, next_step_path, previous_step_path +* Previous path uses flow_path therefore makes sure there are no circular flow + +Explain steps instantiation (if needed): +* flow_steps, saved_steps, valid_steps + +Explain implementing check your answers page: +* Document the CheckAnswersPresenter module +* Show how to create custom presenter classes with row grouping +* Explain format_value override for custom formatting + +We need to enforce the decisions developers needs to make when using the gem and implementing a +wizard. + +Things you need to defined (where to store data? Create one repo for all steps - maybe one - maybe many). diff --git a/lib/dfe/wizard.rb b/lib/dfe/wizard.rb index 1712af3..334f4f6 100644 --- a/lib/dfe/wizard.rb +++ b/lib/dfe/wizard.rb @@ -23,7 +23,7 @@ module DfE # include DfE::Wizard # # def steps_processor - # DfE::Wizard::StepsProcessor::Graph.draw(self) do |graph| + # DfE::Wizard::StepsProcessor::Graph.draw(self, predicate_caller: state_store) do |graph| # graph.add_node :name, NameStep # graph.add_node :email, EmailStep # graph.add_node :review, ReviewStep @@ -109,6 +109,10 @@ module Core end # @!endgroup + # Module for building Check Your Answers pages + # @api public + autoload :CheckAnswersPresenter, 'dfe/wizard/check_answers_presenter' + # @!group Auto generate Documentation for any wizard module Documentation autoload :Generator, 'dfe/wizard/documentation/generator' @@ -325,7 +329,7 @@ def define_step_attributes_in_state_store # # @example # def steps_processor - # DfE::Wizard::StepsProcessor::Graph.draw(self) do |graph| + # DfE::Wizard::StepsProcessor::Graph.draw(self, predicate_caller: state_store) do |graph| # graph.add_node :step1, Step1 # graph.root :step1 # end diff --git a/lib/dfe/wizard/behaviours/step_management.rb b/lib/dfe/wizard/behaviours/step_management.rb index 6799367..f3c0053 100644 --- a/lib/dfe/wizard/behaviours/step_management.rb +++ b/lib/dfe/wizard/behaviours/step_management.rb @@ -287,8 +287,8 @@ def step_definitions # Return all attribute names from all step classes # # Flattens the step definitions to extract every attribute defined across - # all steps in the wizard. Used by StateStore's method_missing to determine - # which method calls should access repository data. + # all steps in the wizard. Used by StateStore to generate accessor methods + # for each attribute. # # Attributes are collected from each step class via its `attribute_names` # class method. Steps without attributes contribute nothing to this list. @@ -311,11 +311,11 @@ def step_definitions # wizard.attribute_names.include?("undefined") # => false # # @note Attribute names are collected lazily during wizard initialization. - # This allows StateStore to build method_missing handlers only for + # This allows StateStore to generate accessor methods only for # attributes actually defined in step classes. # # @see #step_definitions For step class objects themselves - # @see StateStore#method_missing Which uses this list to route method calls + # @see StateStore#define_attribute_accessors Which generates methods from this list # @api public def attribute_names step_definitions.flat_map do |_step_id, step_class| diff --git a/lib/dfe/wizard/check_answers_presenter.rb b/lib/dfe/wizard/check_answers_presenter.rb new file mode 100644 index 0000000..429db23 --- /dev/null +++ b/lib/dfe/wizard/check_answers_presenter.rb @@ -0,0 +1,278 @@ +module DfE + module Wizard + # Module for building Check Your Answers pages. + # + # Include this module in your own presenter class to get helper methods + # for building check your answers pages. You control the structure, grouping, + # and formatting - the module provides the building blocks. + # + # @example Create your own check answers presenter + # class RegisterECTCheckAnswers + # include DfE::Wizard::CheckAnswersPresenter + # + # def teacher_details + # [ + # row_for(:review_ect_details, :correct_full_name), + # row_for(:email_address, :email), + # row_for(:start_date, :start_date), + # ] + # end + # + # def programme_details + # [ + # row_for(:programme_type, :training_programme), + # row_for(:lead_provider, :lead_provider_id), + # ] + # end + # + # # Override to customize formatting + # def format_value(attribute, value) + # case attribute + # when :start_date + # value&.to_fs(:govuk_date) + # else + # value + # end + # end + # end + # + # @example In controller + # @check_answers = RegisterECTCheckAnswers.new(@wizard) + # + # @example In view + # <% @check_answers.teacher_details.each do |row| %> + #