Skip to content

Commit

Permalink
Web Inspector: Infos and Debugs buttons don't appear in Console tab u…
Browse files Browse the repository at this point in the history
…ntil new console messages are displayed

rdar://122923625
https://bugs.webkit.org/show_bug.cgi?id=268881

Reviewed by Devin Rousso.

The original code hides the Infos and Debugs scope bar items until
the console receives the first message coming a non-default channel.

Make it so that the Infos and Debugs buttons' visibility syncs with
with whether there are messages with those two levels respectively,
regardless of what channels the messages came from.

Call the Infos and Debugs buttons "conditionally visible" and make a
group for their IDs. This way the code controlling their visibility
becomes more extendable.

Also clean up some unused dead code near the primary changes.

* Source/WebInspectorUI/UserInterface/Views/LogContentView.js:
(WI.LogContentView.prototype._scopeFromMessageLevel):
  - The levels Infos and Debugs no longer depend on
    _hasNonDefaultLogChannelMessage.

(WI.LogContentView.prototype._messageAdded):
(WI.LogContentView.prototype._logCleared):
(WI.LogContentView.prototype._scopeBarSelectionDidChange):
(WI.LogContentView.prototype._showOrHideConditionallyVisibleScopeBarItemsAsNeeded):
  - Show or hide the conditionally-visible buttons as needed.

(WI.LogContentView):
  - In the constructor, hide the newly created Infos and Debugs buttons
    if they're unselected.

(WI.LogContentView.prototype._messageSourceBarSelectionDidChange):
(WI.LogContentView.prototype._scopeBarSelectionDidChange):
  - Clean up unused local variable `items`.

Canonical link: https://commits.webkit.org/275914@main
  • Loading branch information
the-chenergy authored and rcaliman-apple committed Mar 11, 2024
1 parent 1cc0435 commit eaa47ea
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions Source/WebInspectorUI/UserInterface/Views/LogContentView.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,18 @@ WI.LogContentView = class LogContentView extends WI.ContentView
new WI.ScopeBarItem(WI.LogContentView.Scopes.Errors, WI.UIString("Errors"), {className: "errors"}),
new WI.ScopeBarItem(WI.LogContentView.Scopes.Warnings, WI.UIString("Warnings"), {className: "warnings"}),
new WI.ScopeBarItem(WI.LogContentView.Scopes.Logs, WI.UIString("Logs"), {className: "logs"}),
new WI.ScopeBarItem(WI.LogContentView.Scopes.Infos, WI.UIString("Infos"), {className: "infos", hidden: true}),
new WI.ScopeBarItem(WI.LogContentView.Scopes.Debugs, WI.UIString("Debugs"), {className: "debugs", hidden: true}),
new WI.ScopeBarItem(WI.LogContentView.Scopes.Infos, WI.UIString("Infos"), {className: "infos"}),
new WI.ScopeBarItem(WI.LogContentView.Scopes.Debugs, WI.UIString("Debugs"), {className: "debugs"}),
];
this._scopeBar = new WI.ScopeBar("log-scope-bar", scopeBarItems, scopeBarItems[0]);
this._scopeBar.visibilityPriority = WI.NavigationItem.VisibilityPriority.Low;
this._scopeBar.addEventListener(WI.ScopeBar.Event.SelectionChanged, this._scopeBarSelectionDidChange, this);

this._scopesWithMessages = new Set;
this._showOrHideConditionallyVisibleScopeBarItemsAsNeeded();

this._hasNonDefaultLogChannelMessage = false;

if (WI.ConsoleManager.supportsLogChannels()) {
let messageChannelBarItems = [
new WI.ScopeBarItem(WI.LogContentView.Scopes.AllChannels, WI.UIString("All Sources")),
Expand Down Expand Up @@ -486,9 +490,9 @@ WI.LogContentView = class LogContentView extends WI.ContentView
case WI.ConsoleMessage.MessageLevel.Log:
return WI.LogContentView.Scopes.Logs;
case WI.ConsoleMessage.MessageLevel.Info:
return this._hasNonDefaultLogChannelMessage ? WI.LogContentView.Scopes.Infos : WI.LogContentView.Scopes.Logs;
return WI.LogContentView.Scopes.Infos;
case WI.ConsoleMessage.MessageLevel.Debug:
return this._hasNonDefaultLogChannelMessage ? WI.LogContentView.Scopes.Debugs : WI.LogContentView.Scopes.Logs;
return WI.LogContentView.Scopes.Debugs;
}
console.assert(false, "This should not be reached.");

Expand All @@ -504,10 +508,13 @@ WI.LogContentView = class LogContentView extends WI.ContentView
if (!this._hasNonDefaultLogChannelMessage && WI.consoleManager.customLoggingChannels.some((channel) => channel.source === message.source)) {
this._hasNonDefaultLogChannelMessage = true;
this.dispatchEventToListeners(WI.ContentView.Event.NavigationItemsDidChange);
this._scopeBar.item(WI.LogContentView.Scopes.Infos).hidden = false;
this._scopeBar.item(WI.LogContentView.Scopes.Debugs).hidden = false;
}

let scope = this._scopeFromMessageLevel(message.level);
this._scopesWithMessages.add(scope);
if (WI.LogContentView.ConditionallyVisibleScopes.has(scope))
this._scopeBar.item(scope).hidden = false;

this._logViewController.appendConsoleMessage(message);
}

Expand Down Expand Up @@ -872,6 +879,9 @@ WI.LogContentView = class LogContentView extends WI.ContentView
this.performSearch(this._currentSearchQuery);

this._showHiddenMessagesBannerIfNeeded();

this._scopesWithMessages.clear();
this._showOrHideConditionallyVisibleScopeBarItemsAsNeeded();
}

_showConsoleTab()
Expand Down Expand Up @@ -907,24 +917,17 @@ WI.LogContentView = class LogContentView extends WI.ContentView

_messageSourceBarSelectionDidChange(event)
{
let items = this._messageSourceBar.selectedItems;
if (items.some((item) => item.id === WI.LogContentView.Scopes.AllChannels))
items = this._messageSourceBar.items;

this._filterMessageElements(this._allMessageElements());

this._showHiddenMessagesBannerIfNeeded();
}

_scopeBarSelectionDidChange(event)
{
let items = this._scopeBar.selectedItems;
if (items.some((item) => item.id === WI.LogContentView.Scopes.All))
items = this._scopeBar.items;

this._filterMessageElements(this._allMessageElements());

this._showHiddenMessagesBannerIfNeeded();
this._showOrHideConditionallyVisibleScopeBarItemsAsNeeded();
}

_filterMessageElements(messageElements)
Expand Down Expand Up @@ -1333,6 +1336,14 @@ WI.LogContentView = class LogContentView extends WI.ContentView
if (this.element.firstChild !== this._hiddenMessagesBannerElement)
this.element.insertAdjacentElement("afterbegin", this._hiddenMessagesBannerElement);
}

_showOrHideConditionallyVisibleScopeBarItemsAsNeeded()
{
for (let scope of WI.LogContentView.ConditionallyVisibleScopes) {
let item = this._scopeBar.item(scope);
item.hidden = !item.selected && !this._scopesWithMessages.has(scope);
}
}
};

WI.LogContentView.Scopes = {
Expand All @@ -1350,6 +1361,11 @@ WI.LogContentView.Scopes = {
WebRTC: "log-webrtc",
};

WI.LogContentView.ConditionallyVisibleScopes = new Set([
WI.LogContentView.Scopes.Infos,
WI.LogContentView.Scopes.Debugs,
]);

WI.LogContentView.ItemWrapperStyleClassName = "console-item";
WI.LogContentView.FilteredOutStyleClassName = "filtered-out";
WI.LogContentView.SelectedStyleClassName = "selected";
Expand Down

0 comments on commit eaa47ea

Please sign in to comment.