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

Commit 0e16915

Browse files
committed
Grouping the issues of the subtree
1 parent 235d93c commit 0e16915

1 file changed

Lines changed: 45 additions & 1 deletion

File tree

extension/sidebar-pane.js

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,56 @@ async function _updateSubtree(selectedNode) {
8686
)
8787
}
8888

89+
progressEl.textContent = "Grouping all issues";
90+
const issueGroups = _groupIssues(issues);
91+
8992
progressEl.textContent = "Rendering all issues";
90-
_render(issues, issueListEl);
93+
_render(issueGroups, issueListEl);
9194

9295
subtreeEl.classList.remove("processing");
9396
}
9497

98+
/**
99+
* Group by the issue cause.
100+
* @param {Array} issues
101+
* The issue list which WebCompat library returns. Also the issue in the list
102+
* assume to contain the node information additionaly.
103+
* @return {Array}
104+
* Array of issues grouped. The issue has `nodes` attribute which contains the
105+
* node informations where caused the issue.
106+
*/
107+
function _groupIssues(issues) {
108+
const issueGroups = [];
109+
110+
for (const issue of issues) {
111+
let issueGroup = issueGroups.find(i => {
112+
return i.type === issue.type &&
113+
i.property === issue.property &&
114+
i.element === issue.element &&
115+
i.attribute === issue.attribute &&
116+
i.value === issue.value;
117+
});
118+
119+
if (!issueGroup) {
120+
issueGroup = Object.assign({}, issue, { nodes: [], node: undefined });
121+
issueGroups.push(issueGroup);
122+
}
123+
124+
const isNodeContainedInGroup = issueGroup.nodes.some(n => {
125+
return n.nodeName === issue.node.nodeName &&
126+
n.nodeType === issue.node.nodeType &&
127+
n.id === issue.node.id &&
128+
n.className === issue.node.className;
129+
});
130+
131+
if (!isNodeContainedInGroup) {
132+
issueGroup.nodes.push(issue.node);
133+
}
134+
}
135+
136+
return issueGroups;
137+
}
138+
95139
function _isValidElement({ nodeType, isCustomElement }) {
96140
return nodeType === Node.ELEMENT_NODE && !isCustomElement;
97141
}

0 commit comments

Comments
 (0)