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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[#64348] Remove % from the suggestion list
Tobias Dillmann95b886d65c7c
diff --git a/app/forms/custom_fields/calculated_values/details_form.rb b/app/forms/custom_fields/calculated_values/details_form.rbindex 0394b5d805e..3b81134a4aa 100644--- a/app/forms/custom_fields/calculated_values/details_form.rb+++ b/app/forms/custom_fields/calculated_values/details_form.rb@@ -80,9 +80,12 @@ module CustomFieldsprivatedef formula_suggestions- # Insert operators as plain text nodes instead of tokens, since displaying them as tokens would result- # in too much visual clutter. We still want to offer autocompletion for them.- operators = CustomField::CalculatedValue::MATH_OPERATORS_FOR_FORMULA.map do |op|+ operators = CustomField::CalculatedValue::MATH_OPERATORS_FOR_FORMULA+ # Hide % from the suggestions as it can be used as either modulo or percentage.+ .reject { it == "%" }+ .map do |op|+ # Insert operators as plain text nodes instead of tokens, since displaying them as tokens would result+ # in too much visual clutter. We still want to offer autocompletion for them.{ key: op, label: op, insert_as_text: true }enddiff --git a/app/models/custom_field/calculated_value.rb b/app/models/custom_field/calculated_value.rbindex 396a466f8ee..a4d0ad7bc9c 100644--- a/app/models/custom_field/calculated_value.rb+++ b/app/models/custom_field/calculated_value.rb@@ -73,6 +73,7 @@ module CustomField::CalculatedValueenddef usable_custom_field_references_for_formula+ # TODO: do not suggest other calculated values that lead to recursion.self.class.where(field_format: FIELD_FORMATS_FOR_FORMULA)# Disallow the current custom field to avoid circular referencesdiff --git a/spec/models/custom_field/calculated_value_spec.rb b/spec/models/custom_field/calculated_value_spec.rbindex eaa18579226..61527a6108d 100644--- a/spec/models/custom_field/calculated_value_spec.rb+++ b/spec/models/custom_field/calculated_value_spec.rb@@ -137,6 +137,18 @@ RSpec.describe CustomField::CalculatedValue, with_flag: { calculated_value_projeit_behaves_like "valid formula"end+ context "with a formula using the modulo operator" do+ let(:formula) { "10 % 3" }++ it_behaves_like "valid formula"+ end++ context "with a formula calculating percentages" do+ let(:formula) { "10% * 3" }++ it_behaves_like "valid formula"+ end+context "when omitting leading decimals before a decimal point" dolet(:formula) { "1.5 + .0 - 3.25" }