Skip to content

Commit d8d4899

Browse files
committed
[#69379] When creating a subitem, return to the parents overview page
1 parent 6881065 commit d8d4899

3 files changed

Lines changed: 20 additions & 8 deletions

File tree

app/components/projects/project_creation_footer_component.rb

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,19 @@ module Projects
3232
class ProjectCreationFooterComponent < ApplicationComponent
3333
include OpPrimer::ComponentHelpers
3434

35-
def initialize(form_identifier:, project:, template:, current_step:)
35+
def initialize(form_identifier:, project:, template:, current_step:, cancel_href:)
3636
@form_identifier = form_identifier
3737
@project = project
3838
@template = template
3939
@current_step = current_step
40+
@cancel_href = cancel_href
4041

4142
super
4243
end
4344

4445
def call
4546
render(StepWizard::FooterComponent.new(form_identifier:, total_steps:, current_step:)) do |footer|
46-
footer.with_cancel_button(href: href_for_cancel_button)
47+
footer.with_cancel_button(href: cancel_href)
4748
footer.with_continue_button(**continue_button_args)
4849
footer.with_submit_button(**submit_button_args)
4950
if show_progress_bar?
@@ -52,7 +53,7 @@ def call
5253
end
5354
end
5455

55-
attr_reader :form_identifier, :project, :template, :current_step
56+
attr_reader :form_identifier, :project, :template, :current_step, :cancel_href
5657

5758
private
5859

@@ -78,9 +79,5 @@ def submit_button_args
7879
def total_steps
7980
template.nil? && project.available_custom_fields.required.any? ? 3 : 2
8081
end
81-
82-
def href_for_cancel_button
83-
project.portfolio? ? portfolios_path : projects_path
84-
end
8582
end
8683
end

app/helpers/workspace_helper.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,16 @@ def new_workspace_title(workspace)
4242
end
4343

4444
def workspace_icon(type) = WORKSPACE_ICON_MAPPING[type]
45+
46+
# Returns a path to which the user should be redirected when cancelling the creation process of
47+
# a workspace item
48+
def workspace_creation_cancel_href(workspace, parent = nil)
49+
if parent.present?
50+
project_overview_path(parent.id)
51+
elsif workspace.portfolio?
52+
portfolios_path
53+
else
54+
projects_path
55+
end
56+
end
4557
end

app/views/projects/new.html.erb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ See COPYRIGHT and LICENSE files for more details.
4242
)
4343
%>
4444
<% else %>
45+
<% cancel_href = workspace_creation_cancel_href(@new_project, @parent) %>
46+
4547
<%= render(StepWizard::PageLayoutComponent.new) do |layout| %>
4648
<%=
4749
layout.with_page_header do
@@ -86,7 +88,8 @@ See COPYRIGHT and LICENSE files for more details.
8688
form_identifier: "project-create-form",
8789
project: @new_project,
8890
template: @template,
89-
current_step: params.fetch(:step, 1).to_i
91+
current_step: params.fetch(:step, 1).to_i,
92+
cancel_href:
9093
)
9194
end
9295
%>

0 commit comments

Comments
 (0)