Bug 1433844 - Storage inspector throws when add item, reload and arrow keys r?pbro draft
authorMichael Ratcliffe <mratcliffe@mozilla.com>
Thu, 26 Apr 2018 15:56:20 +0100
changeset 788482 79c150270b5e6da64827d1b50c06231744b2805b
parent 788336 8d85e4da25463ccdcf902ac5a846773b8b642553
push id107997
push userbmo:mratcliffe@mozilla.com
push dateThu, 26 Apr 2018 15:33:33 +0000
reviewerspbro
bugs1433844
milestone61.0a1
Bug 1433844 - Storage inspector throws when add item, reload and arrow keys r?pbro As far as I am aware, we can't create tests to detect whether an error has been thrown... especially if the error has no side affects. If we really need a test for these simple four fixes you can always insist but I don't think we do. MozReview-Commit-ID: 7j9N1X4jTHY
devtools/client/shared/widgets/TableWidget.js
devtools/client/storage/ui.js
--- a/devtools/client/shared/widgets/TableWidget.js
+++ b/devtools/client/shared/widgets/TableWidget.js
@@ -487,17 +487,24 @@ TableWidget.prototype = {
    * rows.
    */
   onKeydown: function(event) {
     // If we are in edit mode bail out.
     if (this._editableFieldsEngine && this._editableFieldsEngine.isEditing) {
       return;
     }
 
-    let selectedCell = this.tbody.querySelector(".theme-selected");
+    // We need to get the first *visible* selected cell. Some columns are hidden
+    // e.g. because they contain a unique compound key for cookies that is never
+    // displayed in the UI. To do this we get all selected cells and filter out
+    // any that are hidden.
+    const selectedCells = [...this.tbody.querySelectorAll(".theme-selected")]
+                                        .filter(cell => cell.clientWidth > 0);
+    // Select the first visible selected cell.
+    const selectedCell = selectedCells[0];
     if (!selectedCell) {
       return;
     }
 
     let colName;
     let column;
     let visibleCells;
     let index;
--- a/devtools/client/storage/ui.js
+++ b/devtools/client/storage/ui.js
@@ -534,17 +534,22 @@ class StorageUI {
   }
 
   /**
    * Handle changed items received by onEdit
    *
    * @param {object} See onEdit docs
    */
   async handleChangedItems(changed) {
-    let [type, host, db, objectStore] = this.tree.selectedItem;
+    const selectedItem = this.tree.selectedItem;
+    if (!selectedItem) {
+      return;
+    }
+
+    let [type, host, db, objectStore] = selectedItem;
     if (!changed[type] || !changed[type][host] ||
         changed[type][host].length == 0) {
       return;
     }
     try {
       let toUpdate = [];
       for (let name of changed[type][host]) {
         let names = JSON.parse(name);
@@ -911,16 +916,20 @@ class StorageUI {
    * Select handler for the storage tree. Fetches details of the selected item
    * from the storage details and populates the storage tree.
    *
    * @param {array} item
    *        An array of ids which represent the location of the selected item in
    *        the storage tree
    */
   async onHostSelect(item) {
+    if (!item) {
+      return;
+    }
+
     this.table.clear();
     this.hideSidebar();
     this.searchBox.value = "";
 
     let [type, host] = item;
     this.table.host = host;
     this.table.datatype = type;
 
@@ -1218,18 +1227,23 @@ class StorageUI {
   async onRefreshTable() {
     await this.onHostSelect(this.tree.selectedItem);
   }
 
   /**
    * Handles adding an item from the storage
    */
   onAddItem() {
-    let front = this.getCurrentFront();
-    let [, host] = this.tree.selectedItem;
+    const selectedItem = this.tree.selectedItem;
+    if (!selectedItem) {
+      return;
+    }
+
+    const front = this.getCurrentFront();
+    const [, host] = selectedItem;
 
     // Prepare to scroll into view.
     this.table.scrollIntoViewOnUpdate = true;
     this.table.editBookmark = createGUID();
     front.addItem(this.table.editBookmark, host);
   }
 
   /**