From a5b7c599ed1810b82c8b2a22704453474814e216 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 6 Mar 2019 14:28:44 -0500 Subject: [PATCH] LP1803787 Grid context retains selection; lint During right-click (context-menu click) if the currently focused row is already selected, avoid modifying the selection. If it's not, then select the focused row only. Minor lint, etc. repairs. Signed-off-by: Bill Erickson Signed-off-by: Jane Sandberg --- .../eg2/src/app/share/grid/grid-body.component.ts | 12 ++++++++---- .../src/app/share/grid/grid-toolbar.component.html | 4 ---- .../eg2/src/app/share/grid/grid-toolbar.component.ts | 3 +++ Open-ILS/src/eg2/src/app/share/grid/grid.ts | 7 +++++++ 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid-body.component.ts b/Open-ILS/src/eg2/src/app/share/grid/grid-body.component.ts index fb3cb742cc..6a95b35d3d 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid-body.component.ts +++ b/Open-ILS/src/eg2/src/app/share/grid/grid-body.component.ts @@ -13,7 +13,7 @@ export class GridBodyComponent implements OnInit { @Input() context: GridContext; - // Track the context menus so we can manually close them + // Track the context menus so we can manually close them // when another popover is opened. contextMenus: NgbPopover[]; @@ -116,7 +116,7 @@ export class GridBodyComponent implements OnInit { action.action(this.context.getSelectedRows()); } - // Apply row selection, track the new menu if needed, + // Apply row selection, track the new menu if needed, // manually close any existing open menus, open selected menu. onRowContextClick($event, row: any, contextMenu: NgbPopover) { $event.preventDefault(); // prevent browser context menu @@ -126,14 +126,18 @@ export class GridBodyComponent implements OnInit { return; } - this.handleRowClick($event, row); + if (!this.context.rowIsSelected(row)) { + // If the focused row is not selected, select it. + // Otherwise, avoid modifying the row selection. + this.context.selectOneRow(this.context.getRowIndex(row)); + } const existing = this.contextMenus.filter(m => m === contextMenu)[0]; if (!existing) { this.contextMenus.push(contextMenu); } - // Force any previously opened menus to close, which does + // Force any previously opened menus to close, which does // not naturally occur via context-click. this.contextMenus.forEach(m => m.close()); 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 a5aa235400..036597db97 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 @@ -48,10 +48,6 @@ - - - {{action.label}} - {{action.label}} diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.ts b/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.ts index 82c199c36b..a05aaa5ea2 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.ts +++ b/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.ts @@ -78,6 +78,9 @@ export class GridToolbarComponent implements OnInit { } performAction(action: GridToolbarAction) { + if (action.isGroup || action.separator) { + return; // These don't perform actions + } const rows = this.gridContext.getSelectedRows(); action.onClick.emit(rows); if (action.action) { action.action(rows); } 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 ae611875c3..cfed24e7a0 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid.ts +++ b/Open-ILS/src/eg2/src/app/share/grid/grid.ts @@ -651,6 +651,13 @@ export class GridContext { return selected; } + rowIsSelected(row: any): boolean { + const index = this.getRowIndex(row); + return this.rowSelector.selected().filter( + idx => idx === index + ).length > 0; + } + getRowColumnValue(row: any, col: GridColumn): string { let val; -- 2.43.2