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

Avoid code repetition

Henriette Darge2b89a7e12b80
diff --git a/app/components/work_packages/date_picker/dialog_content_component.html.erb b/app/components/work_packages/date_picker/dialog_content_component.html.erb
index 1dbb8876476..5d86879e897 100644
--- a/app/components/work_packages/date_picker/dialog_content_component.html.erb
+++ b/app/components/work_packages/date_picker/dialog_content_component.html.erb
@@ -8,9 +8,9 @@
end
collection.with_component(Primer::Alpha::Dialog::Body.new(classes: "Overlay-body_autocomplete_height")) do
- render(Primer::Alpha::UnderlinePanels.new(label: "Test navigation")) do |component|
- component.with_tab(selected: true, id: "todo_1") do |tab|
- tab.with_text { "Dates" }
+ render(Primer::Alpha::UnderlinePanels.new(label: I18n.t("work_packages.datepicker_modal.tabs.aria_label"))) do |component|
+ component.with_tab(selected: true, id: "wp-datepicker-dialog--content-tab--dates") do |tab|
+ tab.with_text { I18n.t("work_packages.datepicker_modal.tabs.dates") }
tab.with_panel do
primer_form_with(
model: work_package,
@@ -98,49 +98,19 @@
end
end
- component.with_tab(id: "todo_2") do |tab|
- tab.with_text { "Predecessors" }
- tab.with_counter(count: follow_relations.count)
- tab.with_panel do
- render(border_box_container(padding: :condensed)) do |component|
- follow_relations.each do |relation|
- component.with_row(scheme: :default) do
- render(WorkPackageRelationsTab::RelationComponent.new(work_package:,
- relation:,
- editable: false))
- end
- end
- end
- end
- end
-
- component.with_tab(id: "todo_3") do |tab|
- tab.with_text { "Successors" }
- tab.with_counter(count: precedes_relations.count)
- tab.with_panel do
- render(border_box_container(padding: :condensed)) do |component|
- precedes_relations.each do |relation|
- component.with_row(scheme: :default) do
- render(WorkPackageRelationsTab::RelationComponent.new(work_package:,
- relation:,
- editable: false))
- end
- end
- end
- end
- end
-
- component.with_tab(id: "todo_3") do |tab|
- tab.with_text { "Children" }
- tab.with_counter(count: children.count)
- tab.with_panel do
- render(border_box_container(padding: :condensed)) do |component|
- children.each do |child|
- component.with_row(scheme: :default) do
- render(WorkPackageRelationsTab::RelationComponent.new(work_package:,
- relation: nil,
- child:,
- editable: false))
+ additional_tabs.each do |tab|
+ component.with_tab(id: "wp-datepicker-dialog--content-tab--#{tab[:key]}") do |tab_content|
+ tab_content.with_text { I18n.t("work_packages.datepicker_modal.tabs.#{tab[:key]}") }
+ tab_content.with_counter(count: tab[:relations].count)
+ tab_content.with_panel do
+ render(border_box_container(padding: :condensed)) do |box|
+ tab[:relations].each do |relation|
+ box.with_row(scheme: :default) do
+ render(WorkPackageRelationsTab::RelationComponent.new(work_package:,
+ relation: (relation unless tab[:is_child_relation?]),
+ child: (relation if tab[:is_child_relation?]),
+ editable: false))
+ end
end
end
end
diff --git a/app/components/work_packages/date_picker/dialog_content_component.rb b/app/components/work_packages/date_picker/dialog_content_component.rb
index fe83b97af4f..e6d6672dc24 100644
--- a/app/components/work_packages/date_picker/dialog_content_component.rb
+++ b/app/components/work_packages/date_picker/dialog_content_component.rb
@@ -27,6 +27,7 @@
#++
# frozen_string_literal: true
+
module WorkPackages
module DatePicker
class DialogContentComponent < ApplicationComponent
@@ -64,6 +65,24 @@ module WorkPackages
!schedule_manually
end
+ def additional_tabs
+ [
+ {
+ key: "predecessors",
+ relations: follow_relations
+ },
+ {
+ key: "successors",
+ relations: precedes_relations
+ },
+ {
+ key: "children",
+ relations: children,
+ is_child_relation?: true
+ }
+ ]
+ end
+
def show_banner?
true # TODO
end
diff --git a/config/locales/en.yml b/config/locales/en.yml
index ee6fbacb738..122b27b5b4f 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -720,6 +720,12 @@ en:
automatic: "Automatic"
manual: "Manual"
show_relations: "Show relations"
+ tabs:
+ aria_label: "Datepicker tabs"
+ children: "Children"
+ dates: "Dates"
+ predecessors: "Predecessors"
+ successors: "Successors"
x_descendants:
one: "One descendant work package"