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

Fix loading of work packages in board autocompleter

Oliver Güntherc7dfd0edae25
diff --git a/frontend/src/app/features/boards/board/add-list-modal/add-list-modal.component.ts b/frontend/src/app/features/boards/board/add-list-modal/add-list-modal.component.ts
index 0352bf7ba95..1efe641f46a 100644
--- a/frontend/src/app/features/boards/board/add-list-modal/add-list-modal.component.ts
+++ b/frontend/src/app/features/boards/board/add-list-modal/add-list-modal.component.ts
@@ -56,7 +56,7 @@ export class AddListModalComponent extends OpModalComponent implements OnInit {
getAutocompleterData = (searchTerm:string):Observable<HalResource[]> => {
// Remove prefix # from search
searchTerm = searchTerm.replace(/^#/, '');
- return this.actionService.loadAvailable( this.active, searchTerm)
+ return this.actionService.loadAvailable(this.active, searchTerm)
.pipe(tap((values) => (this.warnIfNoOptions(values))));
};
diff --git a/frontend/src/app/features/boards/board/board-actions/subtasks/board-subtasks-action.service.ts b/frontend/src/app/features/boards/board/board-actions/subtasks/board-subtasks-action.service.ts
index 87dd5d15a6b..6fc92752d7e 100644
--- a/frontend/src/app/features/boards/board/board-actions/subtasks/board-subtasks-action.service.ts
+++ b/frontend/src/app/features/boards/board/board-actions/subtasks/board-subtasks-action.service.ts
@@ -59,7 +59,7 @@ export class BoardSubtasksActionService extends BoardActionService {
return this
.apiV3Service
.work_packages
- .filtered(filters)
+ .filtered(filters, { pageSize: '-1' })
.get()
.pipe(
map((collection) => collection.elements),
diff --git a/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.html b/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.html
index bb7d38b854f..d6095f1bdf4 100644
--- a/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.html
+++ b/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.html
@@ -10,7 +10,7 @@
[hideSelected]="hideSelected"
[appendTo]="appendTo"
[multiple]="multiple"
- [loading]="isLoading"
+ [loading]="loading$ | async"
[addTag]="addTag"
[virtualScroll]="virtualScroll"
[required]="required"
diff --git a/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.ts b/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.ts
index 63065b0d307..d4d465e5f7f 100644
--- a/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.ts
+++ b/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.ts
@@ -21,8 +21,15 @@ import {
of,
Subject,
merge,
+ BehaviorSubject,
} from 'rxjs';
-import { debounceTime, distinctUntilChanged, switchMap } from 'rxjs/operators';
+import {
+ debounceTime,
+ distinctUntilChanged,
+ filter,
+ switchMap,
+ tap,
+} from 'rxjs/operators';
import { GroupValueFn } from '@ng-select/ng-select/lib/ng-select.component';
import { HalResource } from 'core-app/features/hal/resources/hal-resource';
@@ -85,7 +92,7 @@ export class OpAutocompleterComponent extends UntilDestroyedMixin implements Aft
@Input() public items?:IOPAutocompleterOption[]|HalResource[];
- private items$ = new Subject();
+ private items$ = new BehaviorSubject(null);
@Input() public clearSearchOnAdd?:boolean = true;
@@ -165,7 +172,7 @@ export class OpAutocompleterComponent extends UntilDestroyedMixin implements Aft
@Input() public keyDownFn ? = (_:KeyboardEvent) => true;
- @Input() public typeahead:Subject<string> = new Subject();
+ @Input() public typeahead:BehaviorSubject<string|null> = new BehaviorSubject(null);
// a function for setting the options of ng-select
@Input() public getOptionsFn:(searchTerm:string) => any;
@@ -200,6 +207,8 @@ export class OpAutocompleterComponent extends UntilDestroyedMixin implements Aft
public results$:any;
+ public loading$ = new Subject<boolean>();
+
public isLoading = false;
@ViewChild('ngSelectInstance') ngSelectInstance:NgSelectComponent;
@@ -239,24 +248,35 @@ export class OpAutocompleterComponent extends UntilDestroyedMixin implements Aft
this.ngZone.runOutsideAngular(() => {
setTimeout(() => {
this.results$ = merge(
- (this.items$ || new Subject()),
+ this.items$,
this.typeahead.pipe(
+ filter(() => !!(this.defaultData || this.getOptionsFn)),
+ filter((val) => val !== null),
distinctUntilChanged(),
debounceTime(250),
- (this.defaultData
- ? switchMap((queryString) => this.opAutocompleterService.loadData(queryString, this.resource, this.filters, this.searchKey))
- : this.getOptionsFn
- ? switchMap((queryString) => this.getOptionsFn(queryString))
- : switchMap(() => NEVER)
+ tap(() => this.loading$.next(true)),
+ switchMap((queryString:string) => {
+ if (this.defaultData) {
+ return this.opAutocompleterService.loadData(queryString, this.resource, this.filters, this.searchKey);
+ }
+
+ if (this.getOptionsFn) {
+ return this.getOptionsFn(queryString);
+ }
+
+ return NEVER;
+ }),
+ tap(
+ () => this.loading$.next(false),
+ () => this.loading$.next(false),
),
),
);
if (this.fetchDataDirectly) {
- this.results$ = this.defaultData
- ? (this.opAutocompleterService.loadData('', this.resource, this.filters, this.searchKey))
- : (this.getOptionsFn(''));
+ this.typeahead.next('');
}
+
if (this.openDirectly) {
this.ngSelectInstance.open();
this.ngSelectInstance.focus();
@@ -281,10 +301,9 @@ export class OpAutocompleterComponent extends UntilDestroyedMixin implements Aft
public opened(_:unknown) { // eslint-disable-line no-unused-vars
if (this.openDirectly) {
- this.results$ = this.defaultData
- ? (this.opAutocompleterService.loadData('', this.resource, this.filters, this.searchKey))
- : (this.getOptionsFn(''));
+ this.typeahead.next('');
}
+
this.repositionDropdown();
this.open.emit();
}
diff --git a/lib/api/utilities/page_size_helper.rb b/lib/api/utilities/page_size_helper.rb
index 6a1cd64a02b..385edb93c4d 100644
--- a/lib/api/utilities/page_size_helper.rb
+++ b/lib/api/utilities/page_size_helper.rb
@@ -49,7 +49,10 @@ module API
# * the minimum of the per page options specified in the settings
# * the maximum page size
def resulting_page_size(value, relation = nil)
- [value || relation&.base_class&.per_page || Setting.per_page_options_array.min, maximum_page_size]
+ [
+ resolve_page_size(value) || relation&.base_class&.per_page || Setting.per_page_options_array.min,
+ maximum_page_size
+ ]
.map(&:to_i)
.min
end
diff --git a/spec/lib/api/v3/work_packages/work_package_collection_representer_spec.rb b/spec/lib/api/v3/work_packages/work_package_collection_representer_spec.rb
index f392688152c..73e802003e9 100644
--- a/spec/lib/api/v3/work_packages/work_package_collection_representer_spec.rb
+++ b/spec/lib/api/v3/work_packages/work_package_collection_representer_spec.rb
@@ -350,6 +350,18 @@ describe ::API::V3::WorkPackages::WorkPackageCollectionRepresenter do
end
end
+
+ context 'with a magic page size' do
+ let(:page_size_parameter) { -1 }
+
+ it_behaves_like 'offset-paginated APIv3 collection' do
+ let(:page) { 1 }
+ let(:page_size) { Setting.apiv3_max_page_size }
+ let(:actual_count) { 5 }
+ let(:collection_type) { 'WorkPackageCollection' }
+ end
+ end
+
context 'with a limited page size' do
let(:page_size_parameter) { 2 }