LP1803787 Grid context retains selection; lint
authorBill Erickson <berickxx@gmail.com>
Wed, 6 Mar 2019 19:28:44 +0000 (14:28 -0500)
committerJane Sandberg <sandbej@linnbenton.edu>
Mon, 17 Jun 2019 21:21:11 +0000 (14:21 -0700)
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 <berickxx@gmail.com>
Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>
Open-ILS/src/eg2/src/app/share/grid/grid-body.component.ts
Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.html
Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.ts
Open-ILS/src/eg2/src/app/share/grid/grid.ts

index fb3cb74..6a95b35 100644 (file)
@@ -13,7 +13,7 @@ export class GridBodyComponent implements OnInit {
 
     @Input() context: GridContext;
 
 
     @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[];
 
     // when another popover is opened.
     contextMenus: NgbPopover[];
 
@@ -116,7 +116,7 @@ export class GridBodyComponent implements OnInit {
         action.action(this.context.getSelectedRows());
     }
 
         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
     // 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;
         }
 
             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);
         }
 
 
         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());
 
         // not naturally occur via context-click.
         this.contextMenus.forEach(m => m.close());
 
index a5aa235..036597d 100644 (file)
         <ng-container *ngIf="action.separator">
           <div class="dropdown-divider"></div>
         </ng-container>
         <ng-container *ngIf="action.separator">
           <div class="dropdown-divider"></div>
         </ng-container>
-        <ng-container *ngIf="action.group && !action.isGroup">
-          <!-- grouped entries are indented -->
-          <span class="ml-4">{{action.label}}</span>
-        </ng-container>
         <ng-container 
           *ngIf="!action.group && !action.isGroup && !action.separator">
           <span class="ml-2">{{action.label}}</span>
         <ng-container 
           *ngIf="!action.group && !action.isGroup && !action.separator">
           <span class="ml-2">{{action.label}}</span>
index 82c199c..a05aaa5 100644 (file)
@@ -78,6 +78,9 @@ export class GridToolbarComponent implements OnInit {
     }
 
     performAction(action: GridToolbarAction) {
     }
 
     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); }
         const rows = this.gridContext.getSelectedRows();
         action.onClick.emit(rows);
         if (action.action) { action.action(rows); }
index ae61187..cfed24e 100644 (file)
@@ -651,6 +651,13 @@ export class GridContext {
         return selected;
     }
 
         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;
 
     getRowColumnValue(row: any, col: GridColumn): string {
         let val;