Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Integrate Project Status Button in Settings form

Alexander Brandon Colesa0c8d92c12aa
diff --git a/app/components/projects/settings/general/show_component.html.erb b/app/components/projects/settings/general/show_component.html.erb
index 0364ec75f0d..17e32a4b582 100644
--- a/app/components/projects/settings/general/show_component.html.erb
+++ b/app/components/projects/settings/general/show_component.html.erb
@@ -58,8 +58,9 @@ See COPYRIGHT and LICENSE files for more details.
concat(
render(
Primer::Forms::FormList.new(
+ Projects::StatusButtonComponent.new(project:, user: current_user),
Projects::Settings::StatusForm.new(f),
- Projects::Settings::Submit.new(f, label: I18n.t("projects.settings.button_update_status"))
+ Projects::Settings::Submit.new(f, label: I18n.t("projects.settings.button_update_status_description"))
)
)
)
diff --git a/app/components/projects/settings/general/show_component.rb b/app/components/projects/settings/general/show_component.rb
index 1828fbc0a4f..fe3bc071186 100644
--- a/app/components/projects/settings/general/show_component.rb
+++ b/app/components/projects/settings/general/show_component.rb
@@ -36,7 +36,7 @@ module Projects
include OpPrimer::ComponentHelpers
include OpTurbo::Streamable
- options :project
+ options :project, :current_user
end
end
end
diff --git a/app/forms/projects/settings/status_form.rb b/app/forms/projects/settings/status_form.rb
index 6d4a8f662f7..0cf03aa266f 100644
--- a/app/forms/projects/settings/status_form.rb
+++ b/app/forms/projects/settings/status_form.rb
@@ -30,30 +30,7 @@
module Projects
module Settings
class StatusForm < ApplicationForm
- include ProjectStatusHelper
-
form do |f|
- f.autocompleter(
- name: :status_code,
- label: attribute_name(:status_code),
- include_blank: true,
- autocomplete_options: {
- decorated: true,
- clearable: false,
- focusDirectly: false,
- data: { qa_field_name: "status" }
- }
- ) do |select|
- [nil, *Project.status_codes.keys].map do |status_code|
- select.option(
- label: project_status_name(status_code),
- value: status_code,
- classes: "project-status--name #{project_status_css_class(status_code)}",
- selected: model.status_code == status_code
- )
- end
- end
-
f.rich_text_area(
name: :status_explanation,
label: attribute_name(:status_explanation),
diff --git a/app/views/projects/settings/general/show.html.erb b/app/views/projects/settings/general/show.html.erb
index 083736a348a..636bb64decb 100644
--- a/app/views/projects/settings/general/show.html.erb
+++ b/app/views/projects/settings/general/show.html.erb
@@ -48,4 +48,4 @@ See COPYRIGHT and LICENSE files for more details.
end
%>
-<%= render Projects::Settings::General::ShowComponent.new(project: @project) %>
+<%= render Projects::Settings::General::ShowComponent.new(project: @project, current_user:) %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 3eaf6d99d02..371959920bc 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -391,7 +391,7 @@ en:
header_status: Project status
header_relations: Project relations
button_update_details: Update details
- button_update_status: Update status
+ button_update_status_description: Update status description
button_update_parent_project: Update parent project
public_warning: >
This project is public.
diff --git a/spec/components/projects/settings/general/show_component_spec.rb b/spec/components/projects/settings/general/show_component_spec.rb
index 53f77b7a423..cb0e4188a54 100644
--- a/spec/components/projects/settings/general/show_component_spec.rb
+++ b/spec/components/projects/settings/general/show_component_spec.rb
@@ -32,9 +32,12 @@ require "rails_helper"
RSpec.describe Projects::Settings::General::ShowComponent, type: :component do
let(:project) { build_stubbed(:project) }
+ let(:user) { build_stubbed(:user) }
+
+ current_user { user }
def render_component(**params)
- render_inline(described_class.new(project:, **params))
+ render_inline(described_class.new(project:, current_user:, **params))
page
end
@@ -67,10 +70,7 @@ RSpec.describe Projects::Settings::General::ShowComponent, type: :component do
describe "Project status" do
it_behaves_like "section with heading", "Project status"
- it "renders fields" do
- expect(render_component).to have_element "opce-autocompleter",
- "data-input-name": "\"project[status_code]\""
-
+ it "renders field" do
expect(render_component).to have_element "opce-ckeditor-augmented-textarea",
"data-test-selector": "augmented-text-area-description"
end
diff --git a/spec/features/projects/edit_settings_spec.rb b/spec/features/projects/edit_settings_spec.rb
index 2eee44cb65a..68f1d40afda 100644
--- a/spec/features/projects/edit_settings_spec.rb
+++ b/spec/features/projects/edit_settings_spec.rb
@@ -40,7 +40,7 @@ RSpec.describe "Projects", "editing settings", :js do
end
shared_let(:project) do
- create(:project, :with_status, name: "Foo project", identifier: "foo-project")
+ create(:project, name: "Foo project", identifier: "foo-project")
end
it "hides the field whose functionality is presented otherwise" do
@@ -117,39 +117,71 @@ RSpec.describe "Projects", "editing settings", :js do
end
describe "editing project status" do
- let(:status_field) { FormFields::SelectFormField.new :status }
-
before do
Pages::Projects::Settings::General.new(project).visit!
end
- it "updates the project status and description" do
+ it "sets the project status" do
within_section "Project status" do
- status_field.select_option "At risk"
- fill_in_rich_text "Project status description", with: "Light-years behind 🥺"
+ click_on "Edit project status"
- click_on "Update status"
+ within :menu, "Not set" do
+ find(:menuitem, "Not started").click
+ end
end
expect_and_dismiss_flash type: :success, message: "Successful update."
within_section "Project status" do
- status_field.expect_selected "AT RISK"
- expect(page).to have_selector :rich_text, "Project status description", text: "Light-years behind 🥺"
+ button = find_button("Edit project status")
+ expect(button).to have_text "Not started"
+ button.click
+
+ expect(find(:menu, "Not started")).to have_selector :menuitem, "Not started", aria: { current: true }
end
end
it "unsets the project status" do
within_section "Project status" do
- status_field.select_option "Not set"
+ click_on "Edit project status"
+
+ within :menu, "Not set" do
+ find(:menuitem, "Finished").click
+ end
+ end
+
+ expect_and_dismiss_flash type: :success, message: "Successful update."
+
+ within_section "Project status" do
+ click_on "Edit project status"
+
+ within :menu, "Finished" do
+ find(:menuitem, "Not set").click
+ end
+ end
+
+ expect_and_dismiss_flash type: :success, message: "Successful update."
+
+ within_section "Project status" do
+ button = find_button("Edit project status")
+ expect(button).to have_text "Not set"
+ button.click
- click_on "Update status"
+ expect(find(:menu, "Not set")).to have_selector :menuitem, "Not set", aria: { current: true }
+ end
+ end
+
+ it "updates the project status description" do
+ within_section "Project status" do
+ fill_in_rich_text "Project status description", with: "Light-years behind 🥺"
+
+ click_on "Update status description"
end
expect_and_dismiss_flash type: :success, message: "Successful update."
within_section "Project status" do
- status_field.expect_selected "NOT SET"
+ expect(page).to have_selector :rich_text, "Project status description", text: "Light-years behind 🥺"
end
end
end
diff --git a/spec/forms/projects/settings/status_form_spec.rb b/spec/forms/projects/settings/status_form_spec.rb
index 8e0683ffa91..920823cb14e 100644
--- a/spec/forms/projects/settings/status_form_spec.rb
+++ b/spec/forms/projects/settings/status_form_spec.rb
@@ -35,19 +35,6 @@ RSpec.describe Projects::Settings::StatusForm, type: :forms do
let(:model) { build_stubbed(:project, status_explanation: "example status info") }
- it "renders status field" do
- expect(page).to have_element "opce-autocompleter", "data-input-name": "\"project[status_code]\""
- expect(page).to have_element "opce-autocompleter", "data-qa-field-name": "status" do |elem|
- expect(elem["data-items"]).to have_json_size(7)
- expect(elem["data-items"]).to include_json(
- %{{"id":null,"name":"Not set","classes":"project-status--name -not-set"}}
- ).including(:id)
- expect(elem["data-items"]).to include_json(
- %{{"id":"on_track","name":"On track","classes":"project-status--name -on-track"}}
- ).including(:id)
- end
- end
-
it "renders status description field" do
expect(page).to have_field "Project status description", with: "example status info", visible: :hidden
expect(page).to have_element "opce-ckeditor-augmented-textarea",