Web Inspector: Sort by size issues with Cookies and ApplicationCache DataGrids
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Sep 2017 23:46:44 +0000 (23:46 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Sep 2017 23:46:44 +0000 (23:46 +0000)
https://bugs.webkit.org/show_bug.cgi?id=176879
<rdar://problem/34237096>

Patch by Joseph Pecoraro <pecoraro@apple.com> on 2017-09-13
Reviewed by Matt Baker.

* UserInterface/Views/ApplicationCacheFrameContentView.js:
(WI.ApplicationCacheFrameContentView.prototype._sortDataGrid):
(WI.ApplicationCacheFrameContentView.prototype._populateDataGrid):
This uses very dumb DataGridNodes with a pure data object. In that
object `size` is a bytes string not a number. Include the number size
in this data object that can be used during sorting.

* UserInterface/Views/CookieStorageContentView.js:
(WI.CookieStorageContentView.prototype._rebuildTable):
Simplify creation. Also don't reset sort options. Note that here the
DataGridNodes have access to the Cookie object and can already sort size
using the cookie's size (a number) and not the data's size (string).

* UserInterface/Views/DataGrid.js:
(WI.DataGrid.prototype.sortNodes):
(WI.DataGrid.prototype._sortNodesCallback):
If sortNodes was called twice, it would defer the sort and actually
do the sort with the first comparator and not the latest, preferred
comparator. Make it use the latest comparator.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222001 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Views/ApplicationCacheFrameContentView.js
Source/WebInspectorUI/UserInterface/Views/CookieStorageContentView.js
Source/WebInspectorUI/UserInterface/Views/DataGrid.js

index f8e2df4..bc2158d 100644 (file)
@@ -1,3 +1,31 @@
+2017-09-13  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Web Inspector: Sort by size issues with Cookies and ApplicationCache DataGrids
+        https://bugs.webkit.org/show_bug.cgi?id=176879
+        <rdar://problem/34237096>
+
+        Reviewed by Matt Baker.
+
+        * UserInterface/Views/ApplicationCacheFrameContentView.js:
+        (WI.ApplicationCacheFrameContentView.prototype._sortDataGrid):
+        (WI.ApplicationCacheFrameContentView.prototype._populateDataGrid):
+        This uses very dumb DataGridNodes with a pure data object. In that
+        object `size` is a bytes string not a number. Include the number size
+        in this data object that can be used during sorting.
+
+        * UserInterface/Views/CookieStorageContentView.js:
+        (WI.CookieStorageContentView.prototype._rebuildTable):
+        Simplify creation. Also don't reset sort options. Note that here the
+        DataGridNodes have access to the Cookie object and can already sort size
+        using the cookie's size (a number) and not the data's size (string).
+
+        * UserInterface/Views/DataGrid.js:
+        (WI.DataGrid.prototype.sortNodes):
+        (WI.DataGrid.prototype._sortNodesCallback):
+        If sortNodes was called twice, it would defer the sort and actually
+        do the sort with the first comparator and not the latest, preferred
+        comparator. Make it use the latest comparator.
+
 2017-09-13  Nikita Vasilyev  <nvasilyev@apple.com>
 
         Web Inspector: Styles Redesign: display @media section headers
index a662ef6..5e7ba34 100644 (file)
@@ -188,7 +188,7 @@ WI.ApplicationCacheFrameContentView = class ApplicationCacheFrameContentView ext
         var comparator;
         switch (this._dataGrid.sortColumnIdentifier) {
             case "type": comparator = localeCompare.bind(this, "type"); break;
-            case "size": comparator = numberCompare.bind(this, "size"); break;
+            case "size": comparator = numberCompare.bind(this, "sizeNumber"); break;
             case "url":
             default: comparator = localeCompare.bind(this, "url"); break;
         }
@@ -204,7 +204,8 @@ WI.ApplicationCacheFrameContentView = class ApplicationCacheFrameContentView ext
             var data = {
                 url: resource.url,
                 type: resource.type,
-                size: Number.bytesToString(resource.size)
+                size: Number.bytesToString(resource.size),
+                sizeNumber: resource.size,
             };
             var node = new WI.DataGridNode(data);
             this._dataGrid.appendChild(node);
index d7310f2..a2c9c3b 100644 (file)
@@ -115,6 +115,8 @@ WI.CookieStorageContentView = class CookieStorageContentView extends WI.ContentV
             this._dataGrid = new WI.DataGrid(columns, null, this._deleteCallback.bind(this));
             this._dataGrid.columnChooserEnabled = true;
             this._dataGrid.addEventListener(WI.DataGrid.Event.SortChanged, this._sortDataGrid, this);
+            this._dataGrid.sortColumnIdentifier = "name";
+            this._dataGrid.createSettings("cookie-storage-content-view");
 
             this.addSubview(this._dataGrid);
             this._dataGrid.updateLayout();
@@ -126,14 +128,14 @@ WI.CookieStorageContentView = class CookieStorageContentView extends WI.ContentV
         for (var cookie of this._cookies) {
             const checkmark = "\u2713";
             var data = {
-                "name": cookie.name,
-                "value": cookie.value,
-                "domain": cookie.domain || "",
-                "path": cookie.path || "",
-                "expires": "",
-                "size": Number.bytesToString(cookie.size),
-                "http": cookie.httpOnly ? checkmark : "",
-                "secure": cookie.secure ? checkmark : "",
+                name: cookie.name,
+                value: cookie.value,
+                domain: cookie.domain || "",
+                path: cookie.path || "",
+                expires: "",
+                size: Number.bytesToString(cookie.size),
+                http: cookie.httpOnly ? checkmark : "",
+                secure: cookie.secure ? checkmark : "",
             };
 
             if (cookie.type !== WI.CookieType.Request)
@@ -144,9 +146,6 @@ WI.CookieStorageContentView = class CookieStorageContentView extends WI.ContentV
 
             this._dataGrid.appendChild(node);
         }
-
-        this._dataGrid.sortColumnIdentifier = "name";
-        this._dataGrid.createSettings("cookie-storage-content-view");
     }
 
     _filterCookies(cookies)
index 6eb6c72..a02aea1 100644 (file)
@@ -1284,10 +1284,16 @@ WI.DataGrid = class DataGrid extends WI.View
 
     sortNodes(comparator)
     {
+        // FIXME: This should use the layout loop and not its own requestAnimationFrame.
+        this._sortNodesComparator = comparator;
+
         if (this._sortNodesRequestId)
             return;
 
-        this._sortNodesRequestId = window.requestAnimationFrame(this._sortNodesCallback.bind(this, comparator));
+        this._sortNodesRequestId = window.requestAnimationFrame(() => {
+            if (this._sortNodesComparator)
+                this._sortNodesCallback(this._sortNodesComparator);
+        });
     }
 
     sortNodesImmediately(comparator)
@@ -1312,6 +1318,7 @@ WI.DataGrid = class DataGrid extends WI.View
         }
 
         this._sortNodesRequestId = undefined;
+        this._sortNodesComparator = null;
 
         if (this._editing) {
             this._sortAfterEditingCallback = this.sortNodes.bind(this, comparator);