Skip to content

Commit 5eda016

Browse files
committed
mgr/dashboard: improve search and pagination behavior
add a throttle to the pagination cycle so that if you repeatedly try to cycle through the page, it increases the delay. Doing this because unlike search the button click to change page is deliberate and the first click to the button should respond immediately. another thing is that the search with a keyword stores every keystroke i do in the search field and then after the debouncce interval it sends all those request one by one. for eg: if i type 222 it waits 1s for the debounce timer and then sends a request to find osd with id 2 first then again 2 and then again 2. Instead it should only send 222 at the end. Fixes: https://tracker.ceph.com/issues/72979 Signed-off-by: Nizamudeen A <[email protected]>
1 parent 66ce55a commit 5eda016

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ export class TableComponent implements AfterViewInit, OnInit, OnChanges, OnDestr
383383
});
384384
}
385385
private previousRows = new Map<string | number, TableItem[]>();
386+
private debouncedSearch = this.reloadData.bind(this);
386387

387388
constructor(
388389
// private ngZone: NgZone,
@@ -539,7 +540,13 @@ export class TableComponent implements AfterViewInit, OnInit, OnChanges, OnDestr
539540
// debounce reloadData method so that search doesn't run api requests
540541
// for every keystroke
541542
if (this.serverSide) {
542-
this.reloadData = _.debounce(this.reloadData, 1000);
543+
this.reloadData = _.throttle(this.reloadData.bind(this), 1000, {
544+
leading: true,
545+
trailing: false
546+
});
547+
this.debouncedSearch = _.debounce(this.reloadData.bind(this), 1000);
548+
} else {
549+
this.debouncedSearch = this.reloadData.bind(this);
543550
}
544551

545552
// ngx-datatable triggers calculations each time mouse enters a row,
@@ -883,7 +890,8 @@ export class TableComponent implements AfterViewInit, OnInit, OnChanges, OnDestr
883890
});
884891
context.pageInfo.offset = this.userConfig.offset;
885892
context.pageInfo.limit = this.userConfig.limit;
886-
context.search = this.userConfig.search;
893+
if (this.serverSide) context.search = this.search;
894+
else context.search = this.userConfig.search;
887895
if (this.userConfig.sorts?.length) {
888896
const sort = this.userConfig.sorts[0];
889897
context.sort = `${sort.dir === 'desc' ? '-' : '+'}${sort.prop}`;
@@ -1239,7 +1247,7 @@ export class TableComponent implements AfterViewInit, OnInit, OnChanges, OnDestr
12391247
this.userConfig.limit = this.limit;
12401248
this.userConfig.search = this.search;
12411249
this.updating = false;
1242-
this.reloadData();
1250+
this.debouncedSearch();
12431251
}
12441252
this.rows = this.data;
12451253
} else {

0 commit comments

Comments
 (0)