Bug 150959

Summary: Web Inspector: Convert DatabaseContentView to use View base class
Product: WebKit Reporter: Matt Baker <mattbaker>
Component: Web InspectorAssignee: Matt Baker <mattbaker>
Status: RESOLVED FIXED    
Severity: Normal CC: bburg, buildbot, commit-queue, graouts, joepeck, mattbaker, nvasilyev, rniwa, timothy, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: All   
OS: All   
Attachments:
Description Flags
[Patch] Proposed Fix
none
Archive of layout-test-results from ews106 for mac-mavericks-wk2
none
[Image] 'No Results' UI
none
[Patch] Proposed Fix none

Description Matt Baker 2015-11-05 15:09:54 PST
* SUMMARY
Convert DatabaseContentView to use View base class. The prompt element is wrapped in a div for styling purposes, preventing it from being added as a subview. The wrapper can be eliminated with some modifications to the database view CSS.
Comment 1 Radar WebKit Bug Importer 2015-11-05 15:10:30 PST
<rdar://problem/23420787>
Comment 2 Matt Baker 2015-11-05 17:31:50 PST
Created attachment 264905 [details]
[Patch] Proposed Fix
Comment 3 Matt Baker 2015-11-05 17:52:29 PST
DatabaseUserQueryView has static "builder" methods for creating views for error and success queries. This is to avoid having to overload the constructor like this:

class DatabaseUserQueryView
{
    constructor(query, columnNamesOrMessage, values)
    {
        this._query = query;
        if (columnNamesOrMessage instanceof String)
            this._message = columnNamesOrMessage;
        else
            this._dataGrid = WebInspector.DataGrid.createSortableDataGrid(columnNames, values);

        ...
    }
};

let errorResult = new WebInspector.DatabaseUserQueryView(query, errorMessage);
let successResult = new WebInspector.DatabaseUserQueryView(query, columnNames, values);

I'm open to suggestions if someone has a more elegant approach.
Comment 4 Build Bot 2015-11-05 18:12:49 PST
Comment on attachment 264905 [details]
[Patch] Proposed Fix

Attachment 264905 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.webkit.org/results/388238

New failing tests:
fast/hidpi/image-set-background-repeat.html
Comment 5 Build Bot 2015-11-05 18:12:56 PST
Created attachment 264912 [details]
Archive of layout-test-results from ews106 for mac-mavericks-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews106  Port: mac-mavericks-wk2  Platform: Mac OS X 10.9.5
Comment 6 Timothy Hatcher 2015-11-06 07:51:34 PST
Comment on attachment 264905 [details]
[Patch] Proposed Fix

View in context: https://bugs.webkit.org/attachment.cgi?id=264905&action=review

> Source/WebInspectorUI/UserInterface/Views/DatabaseUserQueryView.js:63
> +            queryView._resultElement.appendChild(dataGrid.element);

Can this be a subview? Perhaps addSubview needs the ability to add to a sub-element of a view?
Comment 7 BJ Burg 2015-11-06 10:57:46 PST
Comment on attachment 264905 [details]
[Patch] Proposed Fix

View in context: https://bugs.webkit.org/attachment.cgi?id=264905&action=review

I would prefer that we have separate View subclasses for error and success, since they have different view hierarchies and not much in common. Right?

It is awkward that we use a factory method and then dig into the internals to append a data grid.

> Source/WebInspectorUI/UserInterface/Views/DatabaseUserQueryView.js:26
> +WebInspector.DatabaseUserQueryView = class View extends WebInspector.View

Nit: class DatabaseUserQueryView

> Source/WebInspectorUI/UserInterface/Views/DatabaseUserQueryView.js:35
> +        commandTextElement.className = "database-query-text";

Nit: pls classList.add

> Source/WebInspectorUI/UserInterface/Views/DatabaseUserQueryView.js:61
> +        if (dataGrid) {

Why could this return falsey? In that case, can we do anything useful?
Comment 8 Matt Baker 2015-11-06 11:20:42 PST
Comment on attachment 264905 [details]
[Patch] Proposed Fix

View in context: https://bugs.webkit.org/attachment.cgi?id=264905&action=review

>> Source/WebInspectorUI/UserInterface/Views/DatabaseUserQueryView.js:61
>> +        if (dataGrid) {
> 
> Why could this return falsey? In that case, can we do anything useful?

It returns null if columnNames.length == 0, otherwise you always get a DataGrid. A valid query can return an empty result set, which we should handle by showing a "No results returned" message. Currently the database content view throws out the query result if it's valid but empty.

>> Source/WebInspectorUI/UserInterface/Views/DatabaseUserQueryView.js:63
>> +            queryView._resultElement.appendChild(dataGrid.element);
> 
> Can this be a subview? Perhaps addSubview needs the ability to add to a sub-element of a view?

Having an optional second parameter would be a simple solution. I've also considered adding a "container element" concept to View, which would be useful for views with chrome (scrollbars, etc) that are vulnerable to subclasses naively calling: this.element.removeChildren().
Comment 9 Matt Baker 2015-11-06 11:28:13 PST
(In reply to comment #7)
> Comment on attachment 264905 [details]
> [Patch] Proposed Fix
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=264905&action=review
> 
> I would prefer that we have separate View subclasses for error and success,
> since they have different view hierarchies and not much in common. Right?
> 
> It is awkward that we use a factory method and then dig into the internals
> to append a data grid.

For me the awkward aspect is that clients can bypass the factory and construct a useless DatabaseUserQueryView. It's fine for static factory/builder methods to access the private internals of the class to which they belong. That said, having subclasses that do the work in their constructors is much cleaner. The base class can construct the DOM element tree that they have in common.
Comment 10 Matt Baker 2015-11-06 15:21:23 PST
Created attachment 264961 [details]
[Image] 'No Results' UI

Currently we show nothing when a query succeeds and returns no rows. This is better.
Comment 11 Matt Baker 2015-11-06 16:00:54 PST
Comment on attachment 264905 [details]
[Patch] Proposed Fix

View in context: https://bugs.webkit.org/attachment.cgi?id=264905&action=review

>>> Source/WebInspectorUI/UserInterface/Views/DatabaseUserQueryView.js:63
>>> +            queryView._resultElement.appendChild(dataGrid.element);
>> 
>> Can this be a subview? Perhaps addSubview needs the ability to add to a sub-element of a view?
> 
> Having an optional second parameter would be a simple solution. I've also considered adding a "container element" concept to View, which would be useful for views with chrome (scrollbars, etc) that are vulnerable to subclasses naively calling: this.element.removeChildren().

Allowing more than one View DOM element to host child views complicates View.prototype.insertSubviewBefore. Let's revisit this once View can distinguish between its root element and the element which can host subviews. See https://bugs.webkit.org/show_bug.cgi?id=150982.
Comment 12 Matt Baker 2015-11-06 16:20:00 PST
Created attachment 264972 [details]
[Patch] Proposed Fix
Comment 13 WebKit Commit Bot 2015-11-09 10:43:25 PST
Comment on attachment 264972 [details]
[Patch] Proposed Fix

Clearing flags on attachment: 264972

Committed r192165: <http://trac.webkit.org/changeset/192165>
Comment 14 WebKit Commit Bot 2015-11-09 10:43:31 PST
All reviewed patches have been landed.  Closing bug.