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

Move the SortBy stuff into its own component

Klaus Zanders21589f254219
diff --git a/app/components/_index.sass b/app/components/_index.sass
index 23775f2d3c9..a6a45cf8696 100644
--- a/app/components/_index.sass
+++ b/app/components/_index.sass
@@ -5,4 +5,4 @@
@import "filters_component"
@import "projects/settings/project_custom_field_sections/index_component"
@import "projects/row_component"
-@import "projects/configure_view_modal_component"
+@import "queries/sort_by_component"
diff --git a/app/components/projects/configure_view_modal_component.html.erb b/app/components/projects/configure_view_modal_component.html.erb
index cf87f6a37cb..64aa23ac467 100644
--- a/app/components/projects/configure_view_modal_component.html.erb
+++ b/app/components/projects/configure_view_modal_component.html.erb
@@ -40,19 +40,9 @@
<% tab.with_text { "Sort By" }%>
<% tab.with_panel do %>
<%= render(Primer::OpenProject::FlexLayout.new) do |layout| %>
- <% 3.times do %>
+ <% 3.times do |i| %>
<% layout.with_row do %>
- <%= render(Primer::OpenProject::GridLayout.new(css_class: "op-projects-configure-query-sort-form", tag: :div)) do |grid| %>
- <% grid.with_area("field") do %>
- <%= form.select 'sortBy',options_for_select(["ID", "Name", "Created At"]) %>
- <% end %>
- <% grid.with_area("direction") do %>
- <%= render(Primer::Alpha::SegmentedControl.new("aria-label": "Sort order", hide_labels: true)) do |sort_buttons| %>
- <% sort_buttons.with_item(icon: "sort-asc", label: "sort ascending", selected: true) %>
- <% sort_buttons.with_item(icon: "sort-desc", label: "sort descending") %>
- <% end %>
- <% end %>
- <% end %>
+ <%= render(Queries::SortByComponent.new(order: query.orders[i], available_orders:)) %>
<% end %>
<% end %>
<% end %>
diff --git a/app/components/projects/configure_view_modal_component.rb b/app/components/projects/configure_view_modal_component.rb
index 2b0d92552cb..7fea3b5aa19 100644
--- a/app/components/projects/configure_view_modal_component.rb
+++ b/app/components/projects/configure_view_modal_component.rb
@@ -40,4 +40,13 @@ class Projects::ConfigureViewModalComponent < ApplicationComponent
.selects
.map { |c| { id: c.attribute, name: c.caption } }
end
+
+ def available_orders
+ @available_orders ||= begin
+ selects = ::Queries::Register.orders[query.class].map(&:key)
+ ::Queries::Register.orders[query.class].select do |order|
+ selects.include?(order.key)
+ end
+ end
+ end
end
diff --git a/app/components/queries/sort_by_component.html.erb b/app/components/queries/sort_by_component.html.erb
new file mode 100644
index 00000000000..4a1f6ee8163
--- /dev/null
+++ b/app/components/queries/sort_by_component.html.erb
@@ -0,0 +1,11 @@
+<%= render(Primer::OpenProject::GridLayout.new(css_class: "op-configure-query-sort-form", tag: :div)) do |grid| %>
+ <% grid.with_area("field") do %>
+ <%= select_tag 'sortBy', select_options, include_blank: true %>
+ <% end %>
+ <% grid.with_area("direction") do %>
+ <%= render(Primer::Alpha::SegmentedControl.new("aria-label": "Sort order", hide_labels: true)) do |sort_buttons| %>
+ <% sort_buttons.with_item(icon: "sort-asc", label: "sort ascending", selected: order&.direction == :asc) %>
+ <% sort_buttons.with_item(icon: "sort-desc", label: "sort descending", selected: order&.direction == :desc) %>
+ <% end %>
+ <% end %>
+<% end %>
diff --git a/app/components/queries/sort_by_component.rb b/app/components/queries/sort_by_component.rb
new file mode 100644
index 00000000000..a9258d93b03
--- /dev/null
+++ b/app/components/queries/sort_by_component.rb
@@ -0,0 +1,41 @@
+# frozen_string_literal: true
+
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-2024 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+# ++
+
+class Queries::SortByComponent < ApplicationComponent
+ options :order,
+ :available_orders
+
+ def select_options
+ options_for_select(
+ available_orders.map { |order| [order.key, order.key] },
+ order&.attribute
+ )
+ end
+end
diff --git a/app/components/projects/configure_view_modal_component.sass b/app/components/queries/sort_by_component.sass
similarity index 52%
rename from app/components/projects/configure_view_modal_component.sass
rename to app/components/queries/sort_by_component.sass
index d91955be9fa..e88f92813fc 100644
--- a/app/components/projects/configure_view_modal_component.sass
+++ b/app/components/queries/sort_by_component.sass
@@ -1,7 +1,7 @@
@import 'helpers'
-.op-projects-configure-query-sort-form
+.op-configure-query-sort-form
display: grid
- grid-template-columns: minmax(0, 100%) 8px 1fr
+ grid-template-columns: minmax(0, 100%) 100px
grid-template-areas: "field field direction"
grid-gap: 8px