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

remove search filter properly if no text is provided

ulferts26c1ca5d15d5
diff --git a/frontend/src/app/components/filters/query-filters/query-filters.component.html b/frontend/src/app/components/filters/query-filters/query-filters.component.html
index 6ef935d1709..8950478b77d 100644
--- a/frontend/src/app/components/filters/query-filters/query-filters.component.html
+++ b/frontend/src/app/components/filters/query-filters/query-filters.component.html
@@ -17,7 +17,8 @@
</label>
<div class="advanced-filters--filter-value">
- <wp-filter-by-text-input (filterChanged)="filtersChanged.emit($event)">
+ <wp-filter-by-text-input
+ (deactivateFilter)="deactivateFilter($event)">
</wp-filter-by-text-input>
</div>
</li>
diff --git a/frontend/src/app/components/filters/quick-filter-by-text-input/quick-filter-by-text-input.component.ts b/frontend/src/app/components/filters/quick-filter-by-text-input/quick-filter-by-text-input.component.ts
index f8d2eabdec9..b3612e68350 100644
--- a/frontend/src/app/components/filters/quick-filter-by-text-input/quick-filter-by-text-input.component.ts
+++ b/frontend/src/app/components/filters/quick-filter-by-text-input/quick-filter-by-text-input.component.ts
@@ -26,17 +26,17 @@
// See docs/COPYRIGHT.rdoc for more details.
// ++
-import {Component, OnDestroy, Output} from '@angular/core';
+import {Component, OnDestroy, Output, EventEmitter} from '@angular/core';
import {I18nService} from "app/modules/common/i18n/i18n.service";
import {WorkPackageViewFiltersService} from "core-app/modules/work_packages/routing/wp-view-base/view-services/wp-view-filters.service";
-import {componentDestroyed, untilComponentDestroyed} from "ng2-rx-componentdestroyed";
+import {untilComponentDestroyed} from "ng2-rx-componentdestroyed";
import {WorkPackageCacheService} from "app/components/work-packages/work-package-cache.service";
-import {merge, Observable, Subject} from "rxjs";
-import {debounceTime, delay, delayWhen, distinctUntilChanged, map, startWith, tap} from "rxjs/operators";
-import {DebouncedEventEmitter} from "core-components/angular/debounced-event-emitter";
+import {Subject} from "rxjs";
+import {debounceTime, distinctUntilChanged, map, tap} from "rxjs/operators";
import {IsolatedQuerySpace} from "core-app/modules/work_packages/query-space/isolated-query-space";
import {QueryFilterInstanceResource} from "core-app/modules/hal/resources/query-filter-instance-resource";
import {input} from "reactivestates";
+import {QueryFilterResource} from "core-app/modules/hal/resources/query-filter-resource";
@Component({
selector: 'wp-filter-by-text-input',
@@ -44,7 +44,7 @@ import {input} from "reactivestates";
})
export class WorkPackageFilterByTextInputComponent implements OnDestroy {
- @Output() public filterChanged = new DebouncedEventEmitter<QueryFilterInstanceResource[]>(componentDestroyed(this));
+ @Output() public deactivateFilter = new EventEmitter<QueryFilterResource>();
public text = {
createWithDropdown: this.I18n.t('js.work_packages.create.button'),
@@ -53,6 +53,8 @@ export class WorkPackageFilterByTextInputComponent implements OnDestroy {
placeholder: this.I18n.t('js.work_packages.placeholder_filter_by_text')
};
+ private filter:QueryFilterInstanceResource;
+
/** Observable to the current search filter term */
public searchTerm = input<string>('');
@@ -89,19 +91,18 @@ export class WorkPackageFilterByTextInputComponent implements OnDestroy {
debounceTime(500),
)
.subscribe(term => {
- let filters = this.wpTableFilters.current;
+ if (term.length > 0) {
+ this.wpTableFilters.replace('search', filter => {
+ filter.operator = filter.findOperator('**')!;
+ filter.values = [term];
- // Remove the current filter
- _.remove(filters, f => f.id === 'search');
+ this.filter = filter;
+ });
+ } else {
+ this.wpTableFilters.remove(this.filter);
- if (term.length > 0) {
- let searchFilter = this.wpTableFilters.instantiate('search');
- searchFilter.operator = searchFilter.findOperator('**')!;
- searchFilter.values = [term];
- filters.push(searchFilter);
+ this.deactivateFilter.emit(this.filter);
}
-
- this.filterChanged.emit(filters);
});
}
diff --git a/spec/features/search_spec.rb b/spec/features/search_spec.rb
index 72f23c8ba21..01f86fd0f63 100644
--- a/spec/features/search_spec.rb
+++ b/spec/features/search_spec.rb
@@ -45,6 +45,35 @@ describe 'Search', type: :feature, js: true, with_settings: { per_page_options:
end
end
end
+ let(:custom_field_text_value) { 'cf text value' }
+ let!(:custom_field_text) do
+ FactoryBot.create(:text_wp_custom_field,
+ is_filter: is_filter,
+ searchable: searchable).tap do |custom_field|
+ project.work_package_custom_fields << custom_field
+ work_packages.first.type.custom_fields << custom_field
+
+ FactoryBot.create(:work_package_custom_value,
+ custom_field: custom_field,
+ customized: work_packages[0],
+ value: custom_field_text_value)
+ end
+ end
+ let(:custom_field_string_value) { 'cf string value' }
+ let!(:custom_field_string) do
+ FactoryBot.create(:string_wp_custom_field,
+ is_for_all: true,
+ is_filter: is_filter,
+ searchable: searchable).tap do |custom_field|
+ custom_field.save
+ work_packages.first.type.custom_fields << custom_field
+
+ FactoryBot.create(:work_package_custom_value,
+ custom_field: custom_field,
+ customized: work_packages[1],
+ value: custom_field_string_value)
+ end
+ end
let(:query) { 'Subject' }
@@ -60,28 +89,6 @@ describe 'Search', type: :feature, js: true, with_settings: { per_page_options:
end
before do
- custom_field_text = FactoryBot.create(:text_wp_custom_field,
- is_filter: is_filter,
- searchable: searchable)
- project.work_package_custom_fields << custom_field_text
- work_packages.first.type.custom_fields << custom_field_text
-
- custom_field_string = FactoryBot.create(:string_wp_custom_field,
- is_for_all: true,
- is_filter: is_filter,
- searchable: searchable)
- custom_field_string.save
- work_packages.first.type.custom_fields << custom_field_string
-
- FactoryBot.create(:work_package_custom_value,
- custom_field: custom_field_text,
- customized: work_packages[0],
- value: "long text")
-
- FactoryBot.create(:work_package_custom_value,
- custom_field: custom_field_string,
- customized: work_packages[1],
- value: "short text")
project.reload
login_as user
@@ -172,7 +179,7 @@ describe 'Search', type: :feature, js: true, with_settings: { per_page_options:
context 'custom fields searchable' do
it "finds WP global custom fields" do
select_autocomplete(page.find('.top-menu-search--input'),
- query: "text",
+ query: "string",
select_text: "In all projects ↵")
table = Pages::EmbeddedWorkPackagesTable.new(find('.work-packages-embedded-view--container'))
table.ensure_work_package_not_listed!(work_packages[0])
@@ -234,6 +241,15 @@ describe 'Search', type: :feature, js: true, with_settings: { per_page_options:
table.expect_work_package_subject(work_packages[5].subject)
table.ensure_work_package_not_listed!(work_packages.last)
+ # clearing the text filter and searching by a just a custom field works
+ page.find('#filter-by-text-input').set('')
+ filters.add_filter_by(custom_field_string.name,
+ 'is',
+ [custom_field_string_value],
+ "customField#{custom_field_string.id}")
+
+ table.expect_work_package_subject(work_packages[1].subject)
+
# Expect that changing the advanced filters will not affect the global search input.
expect(global_search.input.value).to eq query
@@ -263,11 +279,11 @@ describe 'Search', type: :feature, js: true, with_settings: { per_page_options:
# Expect to find custom field values
# ...for type: text
- global_search.search "long text", submit_with_enter: true
+ global_search.search custom_field_text_value, submit_with_enter: true
table.ensure_work_package_not_listed! work_packages[1]
table.expect_work_package_subject(work_packages[0].subject)
# ... for type: string
- global_search.search "short text", submit_with_enter: true
+ global_search.search custom_field_string_value, submit_with_enter: true
table.ensure_work_package_not_listed! work_packages[0]
table.expect_work_package_subject(work_packages[1].subject)