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

Provide real debounce for search input to reduce number of requests

Henriette Darge2569788ec923
diff --git a/frontend/src/app/features/team-planner/team-planner/add-work-packages/add-existing-pane.component.html b/frontend/src/app/features/team-planner/team-planner/add-work-packages/add-existing-pane.component.html
index 48611203c4b..6e150bbd12c 100644
--- a/frontend/src/app/features/team-planner/team-planner/add-work-packages/add-existing-pane.component.html
+++ b/frontend/src/app/features/team-planner/team-planner/add-work-packages/add-existing-pane.component.html
@@ -1,7 +1,7 @@
<div class="op-add-existing-pane--search">
<input
- [ngModel]="searchString"
- (ngModelChange)="searchWorkPackages($event)"
+ [ngModel]="searchString.values$() | async"
+ (ngModelChange)="searchStringChanged$.next($event)"
class="op-add-existing-pane--search-input"
data-qa-selector="op-add-existing-pane--search-input"
[placeholder]="text.placeholder"
diff --git a/frontend/src/app/features/team-planner/team-planner/add-work-packages/add-existing-pane.component.ts b/frontend/src/app/features/team-planner/team-planner/add-work-packages/add-existing-pane.component.ts
index 26fdc89cbb5..337dd6f4ff9 100644
--- a/frontend/src/app/features/team-planner/team-planner/add-work-packages/add-existing-pane.component.ts
+++ b/frontend/src/app/features/team-planner/team-planner/add-work-packages/add-existing-pane.component.ts
@@ -2,20 +2,27 @@ import {
ChangeDetectionStrategy,
Component,
ElementRef,
+ HostBinding,
+ OnInit,
ViewChild,
} from '@angular/core';
import { I18nService } from 'core-app/core/i18n/i18n.service';
import { imagePath } from 'core-app/shared/helpers/images/path-helper';
import {
BehaviorSubject,
+ Observable,
of,
+ Subject,
} from 'rxjs';
import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
import { ApiV3FilterBuilder } from 'core-app/shared/helpers/api-v3/api-v3-filter-builder';
import {
catchError,
debounceTime,
+ distinctUntilChanged,
map,
+ switchMap,
+ tap,
} from 'rxjs/operators';
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
import { WorkPackageNotificationService } from 'core-app/features/work-packages/services/notifications/work-package-notification.service';
@@ -24,6 +31,7 @@ import { UrlParamsHelperService } from 'core-app/features/work-packages/componen
import { IsolatedQuerySpace } from 'core-app/features/work-packages/directives/query-space/isolated-query-space';
import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
import { CalendarDragDropService } from 'core-app/features/team-planner/team-planner/calendar-drag-drop.service';
+import { input } from 'reactivestates';
@Component({
selector: 'op-add-existing-pane',
@@ -31,7 +39,9 @@ import { CalendarDragDropService } from 'core-app/features/team-planner/team-pla
styleUrls: ['./add-existing-pane.component.sass'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
-export class AddExistingPaneComponent extends UntilDestroyedMixin {
+export class AddExistingPaneComponent extends UntilDestroyedMixin implements OnInit {
+ @HostBinding('class.op-add-existing-pane') className = true;
+
@ViewChild('container') container:ElementRef;
@ViewChild('container')
@@ -44,7 +54,11 @@ export class AddExistingPaneComponent extends UntilDestroyedMixin {
}
}
- searchString = '';
+ /** Observable to the current search filter term */
+ public searchString = input<string>('');
+
+ /** Input for search requests */
+ public searchStringChanged$:Subject<string> = new Subject<string>();
isEmpty$ = new BehaviorSubject<boolean>(true);
@@ -73,14 +87,29 @@ export class AddExistingPaneComponent extends UntilDestroyedMixin {
super();
}
+ ngOnInit():void {
+ this.searchStringChanged$
+ .pipe(
+ this.untilDestroyed(),
+ distinctUntilChanged(),
+ debounceTime(500),
+ tap((val) => this.searchString.putValue(val)),
+ switchMap((searchString:string) => this.searchWorkPackages(searchString)),
+ ).subscribe((results) => {
+ this.calendarDrag.draggableWorkPackages$.next(results);
+
+ this.isEmpty$.next(results.length === 0);
+ this.isLoading$.next(false);
+ });
+ }
+
// eslint-disable-next-line @angular-eslint/use-lifecycle-interface
ngOnDestroy():void {
super.ngOnDestroy();
this.calendarDrag.destroyDrake();
}
- searchWorkPackages(searchString:string):void {
- this.searchString = searchString;
+ searchWorkPackages(searchString:string):Observable<WorkPackageResource[]> {
this.isLoading$.next(true);
// Return when the search string is empty
@@ -88,7 +117,7 @@ export class AddExistingPaneComponent extends UntilDestroyedMixin {
this.isLoading$.next(false);
this.isEmpty$.next(true);
- return;
+ return of([]);
}
const filters:ApiV3FilterBuilder = new ApiV3FilterBuilder();
@@ -103,7 +132,7 @@ export class AddExistingPaneComponent extends UntilDestroyedMixin {
// Add the existing filter, if any
this.addExistingFilters(filters);
- this
+ return this
.apiV3Service
.withOptionalProject(this.currentProject.id)
.work_packages
@@ -116,21 +145,15 @@ export class AddExistingPaneComponent extends UntilDestroyedMixin {
return of([]);
}),
this.untilDestroyed(),
- )
- .subscribe((results) => {
- this.calendarDrag.draggableWorkPackages$.next(results);
-
- this.isEmpty$.next(results.length === 0);
- this.isLoading$.next(false);
- });
+ );
}
clearInput():void {
- this.searchWorkPackages('');
+ this.searchStringChanged$.next('');
}
get isSearching():boolean {
- return this.searchString !== '';
+ return this.searchString.value !== '';
}
private addExistingFilters(filters:ApiV3FilterBuilder) {
diff --git a/frontend/src/app/features/team-planner/team-planner/planner/team-planner.component.ts b/frontend/src/app/features/team-planner/team-planner/planner/team-planner.component.ts
index b31d7bf1bfb..8652e42190b 100644
--- a/frontend/src/app/features/team-planner/team-planner/planner/team-planner.component.ts
+++ b/frontend/src/app/features/team-planner/team-planner/planner/team-planner.component.ts
@@ -437,7 +437,7 @@ export class TeamPlannerComponent extends UntilDestroyedMixin implements OnInit,
this.halNotification.showSave(result.resource, result.wasNew);
} catch (e) {
this.halNotification.showError(e.resource, changeset.projectedResource);
- this.calendarDrag.handleDropError(changeset.projectedResource );
+ this.calendarDrag.handleDropError(changeset.projectedResource);
info.revert();
}
}
diff --git a/modules/boards/spec/features/support/board_page.rb b/modules/boards/spec/features/support/board_page.rb
index 595aebd2845..2ddc21fb119 100644
--- a/modules/boards/spec/features/support/board_page.rb
+++ b/modules/boards/spec/features/support/board_page.rb
@@ -142,7 +142,7 @@ module Pages
within_list(list_name) do
found = all('[data-qa-selector="op-wp-single-card--content-subject"]')
.map(&:text)
- expected = card_titles.map { |title| title.is_a?(WorkPackage) ? title.subject : title.to_s }
+ expected = card_titles.map { |title| title.is_a?(WorkPackage) ? "##{title.id} #{title.subject}" : title.to_s }
expect(found)
.to match expected
diff --git a/modules/team_planner/spec/features/team_planner_add_existing_work_packages_spec.rb b/modules/team_planner/spec/features/team_planner_add_existing_work_packages_spec.rb
index 807e5cd3d43..c7435561aa7 100644
--- a/modules/team_planner/spec/features/team_planner_add_existing_work_packages_spec.rb
+++ b/modules/team_planner/spec/features/team_planner_add_existing_work_packages_spec.rb
@@ -60,8 +60,8 @@ describe 'Team planner add existing work packages', type: :feature, js: true do
subject: 'Task 2',
parent: first_wp,
assigned_to: other_user,
- start_date: Time.zone.today.prev_week.prev_occurring(:tuesday),
- due_date: Time.zone.today.prev_week.prev_occurring(:thursday)
+ start_date: 10.days.from_now,
+ due_date: 12.days.from_now
end
let!(:third_wp) do
FactoryBot.create :work_package,
@@ -100,7 +100,7 @@ describe 'Team planner add existing work packages', type: :feature, js: true do
sleep 2
# Drag it to the team planner...
- add_existing_pane.drag_wp_by_pixel second_wp, 650, 50
+ add_existing_pane.drag_wp_by_pixel second_wp, 750, 50
team_planner.expect_and_dismiss_toaster(message: "Successful update.")
@@ -117,7 +117,7 @@ describe 'Team planner add existing work packages', type: :feature, js: true do
sleep 2
# Drag it to the team planner...
- add_existing_pane.drag_wp_by_pixel third_wp, 650, -50
+ add_existing_pane.drag_wp_by_pixel third_wp, 750, -50
team_planner.expect_and_dismiss_toaster(message: "Successful update.")
diff --git a/modules/team_planner/spec/support/pages/team_planner.rb b/modules/team_planner/spec/support/pages/team_planner.rb
index e3ba9c577c0..903f94289f4 100644
--- a/modules/team_planner/spec/support/pages/team_planner.rb
+++ b/modules/team_planner/spec/support/pages/team_planner.rb
@@ -158,7 +158,7 @@ module Pages
resizer = is_start_date ? wp_strip.find('.fc-event-resizer-start') : wp_strip.find('.fc-event-resizer-end')
- drag_by_pixel(element: resizer, by_x: number_of_days * 170, by_y: 0) unless resizer.nil?
+ drag_by_pixel(element: resizer, by_x: number_of_days * 200, by_y: 0) unless resizer.nil?
end
def drag_wp_by_pixel(work_package, by_x, by_y)