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

Render migration warning banner message when % complete is the only field set

Aaron Contreras1c0780313d71
diff --git a/app/components/work_packages/progress/base_modal_component.rb b/app/components/work_packages/progress/base_modal_component.rb
index c0fafade8e3..23f5e8e65bc 100644
--- a/app/components/work_packages/progress/base_modal_component.rb
+++ b/app/components/work_packages/progress/base_modal_component.rb
@@ -64,6 +64,10 @@ module WorkPackages
end
end
+ def should_display_migration_warning?
+ work_package.done_ratio.present? && work_package.estimated_hours.nil? && work_package.remaining_hours.nil?
+ end
+
private
def map_field(field)
diff --git a/app/components/work_packages/progress/status_based/modal_body_component.html.erb b/app/components/work_packages/progress/status_based/modal_body_component.html.erb
index ef6177f8186..001a3be5e20 100644
--- a/app/components/work_packages/progress/status_based/modal_body_component.html.erb
+++ b/app/components/work_packages/progress/status_based/modal_body_component.html.erb
@@ -11,6 +11,12 @@
<%= render(WorkPackages::ProgressForm.new(f, work_package:, mode:, focused_field:)) %>
<% end %>
+ <% if should_display_migration_warning? %>
+ <% modal_body.with_row(mt: 3) do |_migration_warning| %>
+ <%= render(Primer::Alpha::Banner.new) { t("work_package.progress.modal.migration_warning_text") } %>
+ <% end %>
+ <% end %>
+
<% modal_body.with_row(mt: 3) do |_tooltip| %>
<%= render(Primer::Beta::Text.new(font_weight: :semibold)) { t("work_package.progress.label_note") } %>
<%= render(Primer::Beta::Text.new) { t("work_package.progress.modal.status_based_help_text") } %>
diff --git a/app/components/work_packages/progress/work_based/modal_body_component.html.erb b/app/components/work_packages/progress/work_based/modal_body_component.html.erb
index 15be9bcf372..a1e008dd84b 100644
--- a/app/components/work_packages/progress/work_based/modal_body_component.html.erb
+++ b/app/components/work_packages/progress/work_based/modal_body_component.html.erb
@@ -11,6 +11,12 @@
<%= render(WorkPackages::ProgressForm.new(f, work_package:, mode:, focused_field:)) %>
<% end %>
+ <% if should_display_migration_warning? %>
+ <% modal_body.with_row(mt: 3) do |_migration_warning| %>
+ <%= render(Primer::Alpha::Banner.new) { t("work_package.progress.modal.migration_warning_text") } %>
+ <% end %>
+ <% end %>
+
<% modal_body.with_row(mt: 3) do |_tooltip| %>
<%= render(Primer::Beta::Text.new(font_weight: :semibold)) { t("work_package.progress.label_note") } %>
<%= render(Primer::Beta::Text.new) { t("work_package.progress.modal.work_based_help_text") } %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index f480a474ed2..2f43a0172c3 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -3554,6 +3554,7 @@ Project attributes and sections are defined in the <a href=%{admin_settings_url}
modal:
work_based_help_text: "% Complete is automatically derived from Work and Remaining work."
status_based_help_text: "% Complete is set by work package status."
+ migration_warning_text: "In work-based progress calculation mode, % Complete cannot be manually set and is tied to Work. The existing value has been kept but cannot be edited. Please input Work first."
sharing:
count:
zero: "0 users"
diff --git a/spec/features/work_packages/progress_modal_spec.rb b/spec/features/work_packages/progress_modal_spec.rb
index 395c590edd0..922106c0ff0 100644
--- a/spec/features/work_packages/progress_modal_spec.rb
+++ b/spec/features/work_packages/progress_modal_spec.rb
@@ -412,4 +412,33 @@ RSpec.describe "Progress modal", :js, :with_cuprite do
percent_complete_edit_field.expect_read_only_modal_field
end
end
+
+ describe "When % Complete is set + work and remaining work are unset coming from a migration" do
+ before_all do
+ work_package.estimated_hours = nil
+ work_package.remaining_hours = nil
+ work_package.done_ratio = 5.0
+ work_package.save!(validate: false)
+ end
+
+ shared_examples_for "renders a banner with a warning message" do
+ it "renders a banner with a warning message" do
+ work_package_table.visit_query(progress_query)
+ work_package_table.expect_work_package_listed(work_package)
+
+ work_edit_field = ProgressEditField.new(work_package_row, :estimatedTime)
+ modal = work_edit_field.activate!
+
+ modal.expect_migration_warning_banner
+ end
+ end
+
+ context "on work based mode" do
+ include_examples "renders a banner with a warning message"
+ end
+
+ context "on status based mode", with_settings: { work_package_done_ratio: "status" } do
+ include_examples "renders a banner with a warning message"
+ end
+ end
end
diff --git a/spec/support/edit_fields/progress_edit_field.rb b/spec/support/edit_fields/progress_edit_field.rb
index 99778409eb6..7b6b092b3c1 100644
--- a/spec/support/edit_fields/progress_edit_field.rb
+++ b/spec/support/edit_fields/progress_edit_field.rb
@@ -170,6 +170,13 @@ class ProgressEditField < EditField
end
end
+ def expect_migration_warning_banner
+ within modal_element do
+ expect(page)
+ .to have_text(I18n.t("work_package.progress.modal.migration_warning_text"))
+ end
+ end
+
private
attr_reader :field_name