Bug 1433844 - Storage inspector throws when add item, reload and arrow keys r=pbro
authorMichael Ratcliffe <mratcliffe@mozilla.com>
Thu, 26 Apr 2018 15:56:20 +0100
changeset 472113 5c04c625cfa622ae45a0fbf8dbf6943b470a9c87
parent 472112 61ef0409797103377777cdd32f6c6d1b1470b748
child 472114 4bb7dc02d40530cfcd3575268c9dc2aece3c9733
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspbro
bugs1433844
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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);
   }
 
   /**