Skip to content

Commit 20f902b

Browse files
committed
Pass the active filter when constructing the additional_attributes for the autocompleters.
Previously the inactive filter was passed to the additional_attributes, this leading to values not being initialized correctly from the active filters.
1 parent d2841d2 commit 20f902b

File tree

5 files changed

+24
-150
lines changed

5 files changed

+24
-150
lines changed

Diff for: app/components/filter/filter_component.rb

+6-8
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,16 @@ def show_filters_section?
4343
# Returns filters, active and inactive.
4444
# In case a filter is active, the active one will be preferred over the inactive one.
4545
def each_filter
46-
allowed_filters.each do |filter|
47-
active_filter = query.find_active_filter(filter.name)
48-
additional_attributes = additional_filter_attributes(filter)
46+
allowed_filters.each do |allowed_filter|
47+
active_filter = query.find_active_filter(allowed_filter.name)
48+
filter = active_filter || allowed_filter
4949

50-
yield active_filter.presence || filter, active_filter.present?, additional_attributes
50+
yield filter, active_filter.present?, additional_filter_attributes(filter)
5151
end
5252
end
5353

5454
def allowed_filters
55-
query
56-
.available_advanced_filters
55+
query.available_advanced_filters
5756
end
5857

5958
def value_hidden_class(selected_operator)
@@ -99,8 +98,7 @@ def custom_field_list_autocomplete_options(filter)
9998
else
10099
{ items: filter.allowed_values.map { |name, id| { name:, id: } } }
101100
end
102-
103-
autocomplete_options.merge(options)
101+
autocomplete_options.merge(options).merge(model: filter.values)
104102
end
105103

106104
def list_autocomplete_options(filter)

Diff for: app/views/filters/_autocomplete.html.erb

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
multiple: true,
1212
multipleAsSeparateInputs: false,
1313
inputValue: filter.values,
14-
model: filter.values,
1514
appendTo: "body",
1615
id: "#{filter.name}_value",
1716
hiddenFieldAction: "change->filter--filters-form#autocompleteSendForm"

Diff for: spec/features/projects/persisted_lists_spec.rb

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# -- copyright
24
# OpenProject is an open source project management software.
35
# Copyright (C) the OpenProject GmbH
@@ -450,7 +452,6 @@
450452

451453
it "keep the query active when applying orders, page and column changes" do
452454
projects_page.visit!
453-
454455
# The user can select the list but cannot see another user's list
455456
projects_page.set_sidebar_filter(my_projects_list.name)
456457
projects_page.expect_no_sidebar_filter(another_users_projects_list.name)
@@ -551,6 +552,15 @@
551552
development_project) # Because it is on the second page
552553
end
553554

555+
it "shows the saved filter values in the filter section" do
556+
my_projects_list.where("project_status_code", "=", Project.status_codes["on_track"])
557+
my_projects_list.save!
558+
559+
projects_page.visit!
560+
projects_page.set_sidebar_filter(my_projects_list.name)
561+
projects_page.expect_filter_set("project_status_code", value: "On track")
562+
end
563+
554564
it "cannot access another user`s list" do
555565
visit projects_path(query_id: another_users_projects_list.id)
556566

Diff for: spec/support/components/common/filters.rb

+7-2
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,16 @@ def expect_filters_container_hidden
3939
expect(page).to have_css(".op-filters-form", visible: :hidden)
4040
end
4141

42-
def expect_filter_set(filter_name)
42+
def expect_filter_set(filter_name, value: nil)
4343
if filter_name == "name_and_identifier"
4444
expect(page.find_by_id(filter_name).value).not_to be_empty
45+
elsif value
46+
within("li[data-filter-name='#{filter_name}']:not(.hidden)", visible: :hidden) do
47+
expect(page).to have_css(".advanced-filters--filter-value", text: value, visible: :all)
48+
end
4549
else
46-
expect(page).to have_css("li[data-filter-name='#{filter_name}']:not(.hidden)", visible: :hidden)
50+
expect(page)
51+
.to have_css("li[data-filter-name='#{filter_name}']:not(.hidden)", visible: :hidden)
4752
end
4853
end
4954

Diff for: spec/support/pages/projects/index.rb

-138
Original file line numberDiff line numberDiff line change
@@ -158,26 +158,6 @@ def expect_page_sizes(model:)
158158
end
159159
end
160160

161-
def expect_filters_container_toggled
162-
expect(page).to have_css(".op-filters-form")
163-
end
164-
165-
def expect_filters_container_hidden
166-
expect(page).to have_css(".op-filters-form", visible: :hidden)
167-
end
168-
169-
def expect_filter_set(filter_name)
170-
if filter_name == "name_and_identifier"
171-
expect(page.find_by_id(filter_name).value).not_to be_empty
172-
else
173-
expect(page).to have_css("li[data-filter-name='#{filter_name}']:not(.hidden)", visible: :hidden)
174-
end
175-
end
176-
177-
def expect_filter_count(count)
178-
expect(page).to have_css('[data-test-selector="filters-button-counter"]', text: count)
179-
end
180-
181161
def expect_filter_available(filter_name)
182162
expect(page).to have_select("add_filter_select", with_options: [filter_name])
183163
end
@@ -256,20 +236,6 @@ def filter_by_name_and_identifier(value, send_keys: false)
256236
wait_for_reload
257237
end
258238

259-
def set_filter(name, human_name, human_operator = nil, values = [], send_keys: false)
260-
if name == "name_and_identifier"
261-
set_simple_filter(name, values, send_keys:)
262-
else
263-
set_advanced_filter(name, human_name, human_operator, values, send_keys:)
264-
end
265-
end
266-
267-
def set_simple_filter(_name, values, send_keys: false)
268-
return unless values.any?
269-
270-
set_name_and_identifier_filter(values, send_keys:) # This is the only one simple filter at the moment.
271-
end
272-
273239
def set_advanced_filter(name, human_name, human_operator = nil, values = [], send_keys: false)
274240
selected_filter = select_filter(name, human_name)
275241
apply_operator(name, human_operator)
@@ -290,69 +256,6 @@ def set_advanced_filter(name, human_name, human_operator = nil, values = [], sen
290256
end
291257
end
292258

293-
def expect_autocomplete_options_for(custom_field, options, grouping: nil, results_selector: "body")
294-
selected_filter = select_filter(custom_field.column_name, custom_field.name)
295-
296-
within(selected_filter) do
297-
find('[data-filter-autocomplete="true"]').click
298-
end
299-
300-
Array(options).each do |option|
301-
expect_ng_option(selected_filter, option, grouping:, results_selector:)
302-
end
303-
end
304-
305-
def expect_user_autocomplete_options_for(custom_field, expected_options)
306-
selected_filter = select_filter(custom_field.column_name, custom_field.name)
307-
308-
within(selected_filter) do
309-
find('[data-filter-autocomplete="true"]').click
310-
end
311-
options = visible_user_auto_completer_options
312-
313-
expect(options).to eq(expected_options)
314-
end
315-
316-
def apply_operator(name, human_operator)
317-
select(human_operator, from: "operator") unless boolean_filter?(name)
318-
end
319-
320-
def select_filter(name, human_name)
321-
select human_name, from: "add_filter_select"
322-
page.find("li[data-filter-name='#{name}']")
323-
end
324-
325-
def remove_filter(name)
326-
if name == "name_and_identifier"
327-
page.find_by_id("name_and_identifier").find(:xpath, "following-sibling::button").click
328-
else
329-
page.find("li[data-filter-name='#{name}'] .filter_rem").click
330-
end
331-
end
332-
333-
def set_toggle_filter(values)
334-
should_active = values.first == "yes"
335-
is_active = page.has_selector? '[data-test-selector="spot-switch-handle"][data-qa-active]'
336-
337-
if should_active != is_active
338-
page.find('[data-test-selector="spot-switch-handle"]').click
339-
end
340-
341-
if should_active
342-
expect(page).to have_css('[data-test-selector="spot-switch-handle"][data-qa-active]')
343-
else
344-
expect(page).to have_css('[data-test-selector="spot-switch-handle"]:not([data-qa-active])')
345-
end
346-
end
347-
348-
def set_name_and_identifier_filter(values, send_keys: false)
349-
if send_keys
350-
find_field("name_and_identifier").send_keys values.first
351-
else
352-
fill_in "name_and_identifier", with: values.first
353-
end
354-
end
355-
356259
def set_date_filter(human_operator, values, send_keys: false)
357260
case human_operator
358261
when "on", "less than days ago", "more than days ago", "days ago"
@@ -372,39 +275,6 @@ def set_date_filter(human_operator, values, send_keys: false)
372275
end
373276
end
374277

375-
def set_autocomplete_filter(values, clear: true)
376-
element = find('[data-filter-autocomplete="true"]')
377-
378-
ng_select_clear(element, raise_on_missing: false) if clear
379-
380-
Array(values).each do |query|
381-
select_autocomplete element,
382-
query:,
383-
results_selector: "body"
384-
end
385-
end
386-
387-
def set_list_filter(values)
388-
value_select = find('.single-select select[name="value"]')
389-
value_select.select values.first
390-
end
391-
392-
def open_filters
393-
retry_block do
394-
toggle_filters_section
395-
expect(page).to have_css(".op-filters-form.-expanded")
396-
page.find_field("Add filter", visible: true)
397-
end
398-
end
399-
400-
def filters_toggle
401-
page.find('[data-test-selector="filter-component-toggle"]')
402-
end
403-
404-
def toggle_filters_section
405-
filters_toggle.click
406-
end
407-
408278
def set_columns(*columns)
409279
open_configure_view
410280

@@ -671,14 +541,6 @@ def boolean_filter?(filter)
671541
%w[active member_of favored public templated].include?(filter.to_s)
672542
end
673543

674-
def autocomplete_filter?(filter)
675-
filter.has_css?('[data-filter-autocomplete="true"]', wait: 0)
676-
end
677-
678-
def date_filter?(filter)
679-
filter[:"data-filter-type"] == "date"
680-
end
681-
682544
def date_time_filter?(filter)
683545
filter[:"data-filter-type"] == "datetime_past"
684546
end

0 commit comments

Comments
 (0)