Skip to content

Commit 6580add

Browse files
committed
Hook up workflows submit to wizard continue button
1 parent c472d63 commit 6580add

9 files changed

Lines changed: 71 additions & 28 deletions

File tree

app/components/work_package_types/wizard/footer_component.html.erb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030
<%= render(
3131
Primer::Beta::Button.new(
3232
type: :submit,
33-
form: WorkPackageTypes::Wizard::FooterComponent::FORM_IDENTIFIER,
34-
scheme: :primary
33+
form: primary_action_form,
34+
scheme: :primary,
35+
**primary_action_arguments
3536
)
3637
) { primary_action_label } %>
3738
</div>

app/components/work_package_types/wizard/footer_component.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,27 @@ def first_step? = current_step == Steps.first
5555

5656
def last_step? = current_step == Steps.last
5757

58+
# The workflows step embeds the shared matrix form, which persists in place through
59+
# its own endpoint. Continue submits that form with the next step, so the endpoint
60+
# persists and then redirects to advance the wizard (see Workflows::TabsController).
61+
# Escaping the matrix's turbo frame turns that redirect into a full navigation.
62+
# Other steps submit the wizard form directly.
63+
def primary_action_form
64+
workflows_step? ? Workflows::StatusMatrixFormComponent::FORM_ID : FORM_IDENTIFIER
65+
end
66+
67+
def primary_action_arguments
68+
return {} unless workflows_step?
69+
70+
{
71+
name: "advance_to_step",
72+
value: Steps.next_after(current_step),
73+
data: { turbo_frame: "_top" }
74+
}
75+
end
76+
77+
def workflows_step? = current_step == :workflows
78+
5879
def current_number = Steps.index(current_step) + 1
5980

6081
def total_steps = Steps.all.size

app/components/work_package_types/wizard/page_component.html.erb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,16 @@
3131
<% end %>
3232
<% end %>
3333
<% else %>
34-
<%# Self-persisting editor: this form only advances to the next step on submit. %>
3534
<%= render(step_body) %>
36-
<%= primer_form_with(
37-
url: step_url,
38-
method: :patch,
39-
html: { id: WorkPackageTypes::Wizard::FooterComponent::FORM_IDENTIFIER }
40-
) do %>
41-
<%= tag.input(type: :hidden, name: :step, value: current_step) %>
35+
<% unless step_submits_own_form? %>
36+
<%# Self-persisting editor: this form only advances to the next step on submit. %>
37+
<%= primer_form_with(
38+
url: step_url,
39+
method: :patch,
40+
html: { id: WorkPackageTypes::Wizard::FooterComponent::FORM_IDENTIFIER }
41+
) do %>
42+
<%= tag.input(type: :hidden, name: :step, value: current_step) %>
43+
<% end %>
4244
<% end %>
4345
<% end %>
4446
<% end %>

app/components/work_package_types/wizard/page_component.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ def reuse_mode_banner
121121
render(WorkPackageTypes::ReuseModeBannerComponent.new(type:, aspect: step_editor.aspect))
122122
end
123123

124+
def step_submits_own_form? = current_step == :workflows
125+
124126
# Editors that self-persist through their own turbo endpoints.
125127
def step_body
126128
case current_step

app/components/work_package_types/wizard/page_component.sass

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,7 @@
5454

5555
&--sidebar
5656
display: none
57+
58+
// The wizard footer's Continue button persists the workflow matrix
59+
.workflow-save-bar
60+
display: none

app/components/workflows/status_matrix_form_component.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,5 +186,6 @@ See COPYRIGHT and LICENSE files for more details.
186186
<% end %>
187187
<% else %>
188188
<%= render Workflows::BlankslateComponent.new(roles: @roles, type: @type, tab: @tab) %>
189+
<%= form_tag(type_creation_wizard_path(@type, step: :workflows), id: form_id, method: :patch) do %><% end %>
189190
<% end %>
190191
<% end %>

app/controllers/workflows/tabs_controller.rb

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,10 @@ def edit
5454
end
5555

5656
def update # rubocop:disable Metrics/AbcSize
57-
success = false
58-
Workflow.transaction do
59-
success = true
60-
base_params = permitted_status_params
61-
indeterminate = permitted_indeterminate_params
62-
@roles.each do |role|
63-
role_params = indeterminate.empty? ? base_params : role_specific_params(base_params, indeterminate, role)
64-
result = Workflows::BulkUpdateService.new(role:, type: @type, tab: @tab)
65-
.call(role_params)
66-
success = false unless result.success?
67-
end
68-
raise ActiveRecord::Rollback unless success
57+
success = persist_matrix
58+
59+
if success && params[:advance_to_step].present?
60+
return redirect_to type_creation_wizard_path(@type, step: params[:advance_to_step]), status: :see_other
6961
end
7062

7163
if success
@@ -199,6 +191,27 @@ def workflows_for_form
199191
@workflows["assignee"] = workflows.select(&:assignee)
200192
end
201193

194+
# A linked type reuses its source's transitions and must never have its own
195+
# rewritten, so it persists nothing and simply reports success.
196+
def persist_matrix
197+
return true if @type.linked?(Type::ConfigurationLink::WORKFLOWS)
198+
199+
success = false
200+
Workflow.transaction do
201+
success = true
202+
base_params = permitted_status_params
203+
indeterminate = permitted_indeterminate_params
204+
@roles.each do |role|
205+
role_params = indeterminate.empty? ? base_params : role_specific_params(base_params, indeterminate, role)
206+
result = Workflows::BulkUpdateService.new(role:, type: @type, tab: @tab)
207+
.call(role_params)
208+
success = false unless result.success?
209+
end
210+
raise ActiveRecord::Rollback unless success
211+
end
212+
success
213+
end
214+
202215
def permitted_status_params
203216
status_params("status")
204217
end

spec/features/types/creation_wizard_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
RSpec.describe "Variant creation wizard", :js, with_flag: { type_variants: true } do
3434
shared_let(:admin) { create(:admin) }
3535
shared_let(:bug_type) { create(:type, name: "Bug", color: create(:color)) }
36+
shared_let(:project_role) { create(:project_role) }
3637

3738
before { login_as(admin) }
3839

@@ -98,6 +99,7 @@ def complete_details_step(name)
9899
expect_step_saved(:project_attributes)
99100

100101
# Step 5 - Workflow
102+
expect(page).to have_css("#workflow_form", visible: :all)
101103
click_on I18n.t(:button_continue)
102104
expect_step_saved(:workflows)
103105

spec/features/types/creation_wizard_workflows_spec.rb

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,18 @@ def visit_workflow_wizard(roles: [], tab: nil)
6363
visit type_creation_wizard_path(type, **params)
6464
end
6565

66-
it "allows adding another workflow" do
66+
it "persists the matrix and advances when clicking 'Continue'" do
6767
visit_workflow_wizard(roles: [role])
6868

6969
expect(page).to have_field workflow_checkbox(1, 0), checked: false
7070
expect(Workflow.where(type_id: type.id, role_id: role.id).count).to be 1
7171

7272
check workflow_checkbox(1, 0)
7373

74-
click_button "Save"
75-
76-
expect_flash(message: "Successful update.")
77-
78-
expect(page).to have_field workflow_checkbox(0, 1), checked: true
79-
expect(page).to have_field workflow_checkbox(1, 0), checked: true
74+
expect(page).to have_no_button "Save"
75+
click_on I18n.t(:button_continue)
8076

77+
expect(page).to have_current_path(type_creation_wizard_path(type, step: :projects))
8178
expect(Workflow.where(type_id: type.id, role_id: role.id).count).to be 2
8279
end
8380

0 commit comments

Comments
 (0)