Skip to content
This repository was archived by the owner on Jul 23, 2024. It is now read-only.

Commit 456b303

Browse files
authored
Merge pull request #19 from firefox-devtools/indicator-for-loading-subtree-with-spinner
fixed #16 - Indicator with spinner for loading subtree
2 parents 495fb6f + 440f3b7 commit 456b303

2 files changed

Lines changed: 73 additions & 18 deletions

File tree

extension/sidebar-pane.html

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,44 @@
122122
.deprecated, .experimental {
123123
font-weight: 600;
124124
}
125+
126+
#subtree aside {
127+
display: none;
128+
padding-block: 12px;
129+
padding-inline: 40px;
130+
}
131+
132+
#subtree.processing aside {
133+
display: block;
134+
}
135+
136+
#subtree.processing ul {
137+
display: none;
138+
}
139+
140+
#subtree aside label {
141+
display: flex;
142+
align-items: center;
143+
}
144+
145+
/* import from devtools/client/themes/common.css */
146+
/* Throbbers */
147+
.devtools-throbber::before {
148+
content: "";
149+
display: inline-block;
150+
vertical-align: bottom;
151+
margin-inline-end: 0.5em;
152+
width: 1em;
153+
height: 1em;
154+
border: 2px solid currentColor;
155+
border-right-color: transparent;
156+
border-radius: 50%;
157+
animation: 1.1s linear throbber-spin infinite;
158+
}
159+
160+
@keyframes throbber-spin {
161+
to { transform: rotate(1turn); }
162+
}
125163
</style>
126164
<script src="experiments/inspectedNode/api-client.js"></script>
127165
<script type="module" src="sidebar-pane.js"></script>
@@ -134,6 +172,9 @@
134172
<section id="subtree">
135173
<header>Issues for the selected element's subtree</header>
136174
<ul></ul>
175+
<aside>
176+
<label class="devtools-throbber"></label>
177+
</aside>
137178
</section>
138179
</body>
139180
</html>

extension/sidebar-pane.js

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ async function _update() {
1515
}
1616

1717
async function _updateSelectedNode(selectedNode) {
18-
const ulEl = document.querySelector("#selected ul");
18+
const issueListEl = document.querySelector("#selected ul");
1919

2020
if (!_isValidElement(selectedNode)) {
21-
_render([], ulEl);
21+
_render([], issueListEl);
2222
return;
2323
}
2424

@@ -34,20 +34,28 @@ async function _updateSelectedNode(selectedNode) {
3434
..._webcompat.getCSSDeclarationBlockIssues(declarations, _targetBrowsers));
3535
}
3636

37-
_render(issues, ulEl);
37+
_render(issues, issueListEl);
3838
}
3939

4040
async function _updateSubtree(selectedNode) {
41-
const ulEl = document.querySelector("#subtree ul");
41+
const subtreeEl = document.getElementById("subtree");
42+
const issueListEl = subtreeEl.querySelector("ul");
4243

4344
if (!_isValidElement(selectedNode)) {
44-
_render([], ulEl);
45+
_render([], issueListEl);
4546
return;
4647
}
4748

4849
const issues = [];
4950

50-
for (const node of await browser.experiments.inspectedNode.getNodesInSubtree()) {
51+
subtreeEl.classList.add("processing");
52+
const progressEl = subtreeEl.querySelector("aside label");
53+
54+
progressEl.textContent = "Getting all descendants of the selected node";
55+
const nodesInSubtree = await browser.experiments.inspectedNode.getNodesInSubtree();
56+
57+
progressEl.textContent = "Getting web compatibility issues for HTML element";
58+
for (const node of nodesInSubtree) {
5159
if (!_isValidElement(node)) {
5260
continue
5361
}
@@ -57,43 +65,49 @@ async function _updateSubtree(selectedNode) {
5765
..._webcompat.getHTMLElementIssues(nodeName, attributes, _targetBrowsers));
5866
}
5967

68+
progressEl.textContent = "Getting all descendants of the selected node";
6069
const declarationBlocks = await browser.experiments.inspectedNode.getStylesInSubtree();
70+
71+
progressEl.textContent = "Getting web compatibility issues for CSS styles";
6172
for (const { declarations } of declarationBlocks) {
6273
issues.push(
6374
..._webcompat.getCSSDeclarationBlockIssues(declarations, _targetBrowsers));
6475
}
6576

66-
_render(issues, ulEl);
77+
progressEl.textContent = "Rendering all issues";
78+
_render(issues, issueListEl);
79+
80+
subtreeEl.classList.remove("processing");
6781
}
6882

6983
function _isValidElement({ nodeType, isCustomElement }) {
7084
return nodeType === Node.ELEMENT_NODE && !isCustomElement;
7185
}
7286

73-
function _render(issues, ulEl) {
74-
ulEl.innerHTML = "";
87+
function _render(issues, issueListEl) {
88+
issueListEl.innerHTML = "";
7589

7690
if (!issues.length) {
77-
const liEl = document.createElement("li");
78-
liEl.textContent = "No issues";
79-
ulEl.appendChild(liEl);
91+
const noIssueEl = document.createElement("li");
92+
noIssueEl.textContent = "No issues";
93+
issueListEl.appendChild(noIssueEl);
8094
} else {
8195
for (const issue of issues) {
82-
ulEl.appendChild(_renderIssue(issue));
96+
issueListEl.appendChild(_renderIssue(issue));
8397
}
8498
}
8599
}
86100

87101
function _renderIssue(issue) {
88-
const liEl = document.createElement("li");
102+
const issueEl = document.createElement("li");
89103
const subjectEl = _renderSubject(issue);
90104
const predicateEl = _renderPredicate(issue);
91-
liEl.appendChild(subjectEl);
92-
liEl.appendChild(predicateEl);
105+
issueEl.appendChild(subjectEl);
106+
issueEl.appendChild(predicateEl);
93107

94-
liEl.classList.add((issue.deprecated ? "warning" : "information"));
108+
issueEl.classList.add((issue.deprecated ? "warning" : "information"));
95109

96-
return liEl;
110+
return issueEl;
97111
}
98112

99113
function _renderSubject(issue) {

0 commit comments

Comments
 (0)