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

Only show active fields and link as a target

Klaus Zanders9e8fb0bb47fa
diff --git a/app/components/queries/sort_by_component.html.erb b/app/components/queries/sort_by_component.html.erb
index 99aedaadca5..4499461d779 100644
--- a/app/components/queries/sort_by_component.html.erb
+++ b/app/components/queries/sort_by_component.html.erb
@@ -3,7 +3,7 @@
<%= render(Primer::OpenProject::FlexLayout.new) do |layout| %>
<% order_limit.times do |i| %>
<% layout.with_row do %>
- <%= render(Queries::SortByFieldComponent.new(order: query.orders[i], available_orders:)) %>
+ <%= render(Queries::SortByFieldComponent.new(order: query.orders[i], available_orders:, index: i)) %>
<% end %>
<% end %>
<% end %>
diff --git a/app/components/queries/sort_by_field_component.html.erb b/app/components/queries/sort_by_field_component.html.erb
index 324ac75d3a7..46292f564b2 100644
--- a/app/components/queries/sort_by_field_component.html.erb
+++ b/app/components/queries/sort_by_field_component.html.erb
@@ -1,4 +1,4 @@
-<%= render(Primer::OpenProject::GridLayout.new(css_class: "op-configure-query-sort-form", tag: :div)) do |grid| %>
+<%= render(Primer::OpenProject::GridLayout.new(css_class: "op-configure-query-sort-form", tag: :div, data: { "sort-by-config-target" => "inputRow"}, style: (display? ? "" : "display:none;"))) do |grid| %>
<% grid.with_area("field") do %>
<%= select_tag 'sort_field', select_options, include_blank: true, form: "none" %>
<% end %>
diff --git a/app/components/queries/sort_by_field_component.rb b/app/components/queries/sort_by_field_component.rb
index d0b67432169..309c73d55b8 100644
--- a/app/components/queries/sort_by_field_component.rb
+++ b/app/components/queries/sort_by_field_component.rb
@@ -30,7 +30,8 @@
class Queries::SortByFieldComponent < ApplicationComponent
options :order,
- :available_orders
+ :available_orders,
+ :index
def select_options
options_for_select(
@@ -39,11 +40,19 @@ class Queries::SortByFieldComponent < ApplicationComponent
)
end
+ def display?
+ active? || index == 0
+ end
+
+ def active?
+ order.present? && available_orders.any? { |o| order.attribute.to_sym == o[:id] }
+ end
+
def order_asc?
- order&.direction == :asc
+ active? && order&.direction == :asc
end
def order_desc?
- order&.direction == :desc
+ active? && order&.direction == :desc
end
end
diff --git a/frontend/src/stimulus/controllers/dynamic/sort-by-config.controller.ts b/frontend/src/stimulus/controllers/dynamic/sort-by-config.controller.ts
index bde4f086f96..2db6be6e045 100644
--- a/frontend/src/stimulus/controllers/dynamic/sort-by-config.controller.ts
+++ b/frontend/src/stimulus/controllers/dynamic/sort-by-config.controller.ts
@@ -33,12 +33,15 @@ import { Controller } from '@hotwired/stimulus';
export default class SortByConfigController extends Controller {
static targets = [
'sortByField',
+ 'inputRow'
];
declare readonly sortByFieldTarget:HTMLInputElement;
+ declare readonly inputRowTargets:HTMLElement[];
connect(): void {
console.log("Hello, we are connected!")
console.log(`Current value of the field: ${this.sortByFieldTarget.value}`)
+ console.log(this.inputRowTargets)
}
}