From: Bill Erickson <berickxx@gmail.com> Date: Tue, 25 Jun 2019 14:44:57 +0000 (-0400) Subject: LP1832148 Clear selection for deleted grid rows X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=649ddb2d71f39ab0abc8bda48f3c05de6b522140;p=evergreen%2Fequinox.git LP1832148 Clear selection for deleted grid rows Ignore rows which are no longer present in the grid when displaying the "X selected" rows label along the top of the Angular grid. Additionally, teach the grid to clear selected indexes for rows that are no longer present for a bit of low-impact release of memory. Signed-off-by: Bill Erickson <berickxx@gmail.com> Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu> --- diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.html b/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.html index be7b19cb7e..d75ef88b60 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.html +++ b/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.html @@ -30,7 +30,7 @@ <div class="flex-1"></div> <div class="font-sm font-italic d-flex flex-column-reverse mr-2"> - {{gridContext.rowSelector.selected().length}} selected + {{gridContext.getSelectedRows().length}} selected </div> <div ngbDropdown class="mr-1" placement="bottom-right"> <button ngbDropdownToggle [disabled]="!gridContext.toolbarActions.length" diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid.ts b/Open-ILS/src/eg2/src/app/share/grid/grid.ts index ae681694d8..e7c7f711b6 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid.ts +++ b/Open-ILS/src/eg2/src/app/share/grid/grid.ts @@ -383,8 +383,11 @@ export class GridRowSelector { } // Returns the list of selected index values. - // in some contexts (template checkboxes) the value for an index is + // In some contexts (template checkboxes) the value for an index is // set to false to deselect instead of having it removed (via deselect()). + // NOTE GridRowSelector has no knowledge of when a row is no longer + // present in the grid. Use GridContext.getSelectedRows() to get + // list of selected rows that are still present in the grid. selected() { return Object.keys(this.indexes).filter( ind => Boolean(this.indexes[ind])); @@ -640,14 +643,22 @@ export class GridContext { // Returns all selected rows, regardless of whether they are // currently visible in the grid display. + // De-selects previously selected rows which are no longer + // present in the grid. getSelectedRows(): any[] { const selected = []; + const deleted = []; + this.rowSelector.selected().forEach(index => { const row = this.getRowByIndex(index); if (row) { selected.push(row); + } else { + deleted.push(index); } }); + + this.rowSelector.deselect(deleted); return selected; }