Skip to content

Commit 1b1cbdf

Browse files
committed
Generate audit list from configJson
1 parent 561efc2 commit 1b1cbdf

File tree

2 files changed

+49
-24
lines changed

2 files changed

+49
-24
lines changed

lighthouse-extension/app/popup.html

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,17 @@ <h2 class="header-titles__url">...</h2>
5252
<aside class="options subpage">
5353
<h2 class="options__title">Options</h2>
5454
<ul class="options__list">
55-
<li><input type="checkbox" id="offline" checked="checked" value="App can load on offline/flaky connections" /><label for="offline">App can load on offline/flaky connections</label></li>
56-
<li><input type="checkbox" id="pageload" checked="checked" value="Page load performance is fast" /><label for="pageload">Page load performance</label></li>
57-
<li><input type="checkbox" id="progressive" checked="checked" value="Site is progressively enhanced" /><label for="progressive">Site is progressively enhanced</label></li>
58-
<li><input type="checkbox" id="secure" checked="checked" value="Network connection is secure" /><label for="secure">Network connection is secure</label></li>
59-
<li><input type="checkbox" id="homescreen" checked="checked" value="User can be prompted to Add to Homescreen" /><label for="homescreen">User can be prompted to Add to Homescreen</label></li>
60-
<li><input type="checkbox" id="splashscreen" checked="checked" value="Installed web app will launch with custom splash screen" /><label for="splashscreen">Installed web app will launch with custom splash screen</label></li>
61-
<li><input type="checkbox" id="brandcolor" checked="checked" value="Address bar matches brand colors" /><label for="brandcolor">Address bar matches brand colors</label></li>
62-
<li><input type="checkbox" id="mobile-friendly" checked="checked" value="Design is mobile-friendly" /><label for="mobile-friendly">Design is mobile-friendly</label></li>
63-
<li>&nbsp;</li>
64-
<li><input type="checkbox" id="bestpractices" checked="checked" value="Best Practices" /><label for="bestpractices">Best Practices</label></li>
65-
<li><input type="checkbox" id="performance" checked="checked" value="Performance Metrics" /><label for="performance">Performance Metrics</label></li>
55+
<li><label><input type="checkbox" checked="checked" value="App can load on offline/flaky connections" />App can load on offline/flaky connections</label></li>
56+
<li><label><input type="checkbox" checked="checked" value="Page load performance is fast" />Page load performance</label></li>
57+
<li><label><input type="checkbox" checked="checked" value="Site is progressively enhanced" />Site is progressively enhanced</label></li>
58+
<li><label><input type="checkbox" checked="checked" value="Network connection is secure" />Network connection is secure</label></li>
59+
<li><label><input type="checkbox" checked="checked" value="User can be prompted to Add to Homescreen" />User can be prompted to Add to Homescreen</label></li>
60+
<li><label><input type="checkbox" checked="checked" value="Installed web app will launch with custom splash screen" />Installed web app will launch with custom splash screen</label></li>
61+
<li><label><input type="checkbox" checked="checked" value="Address bar matches brand colors" />Address bar matches brand colors</label></li>
62+
<li><label><input type="checkbox" checked="checked" value="Design is mobile-friendly" />Design is mobile-friendly</label></li>
63+
<li><label>&nbsp;</li>
64+
<li><label><input type="checkbox" checked="checked" value="Best Practices" /><label for="bestpractices">Best Practices</label></li>
65+
<li><label><input type="checkbox" checked="checked" value="Performance Metrics" /><label for="performance">Performance Metrics</label></li>
6666
</ul>
6767

6868
<button class="button button--link button--go-back" id="go-back">Back</button>

lighthouse-extension/app/src/popup.js

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,19 @@
1717

1818
const configJSON = require('../../../lighthouse-core/config/default.json');
1919
const _flatten = arr => [].concat.apply([], arr);
20-
const aggregations = _flatten([
21-
configJSON.aggregations[0].items,
22-
configJSON.aggregations[1],
23-
configJSON.aggregations[2]
24-
]);
20+
21+
const aggregations = _flatten(
22+
configJSON.aggregations.map(aggregation => {
23+
if (aggregation.items.length > 1) {
24+
return aggregation.items;
25+
}
26+
27+
return {
28+
name: aggregation.name,
29+
criteria: aggregation.items[0].criteria,
30+
};
31+
})
32+
);
2533

2634
document.addEventListener('DOMContentLoaded', _ => {
2735
const background = chrome.extension.getBackgroundPage();
@@ -37,6 +45,7 @@ document.addEventListener('DOMContentLoaded', _ => {
3745

3846
const generateOptionsEl = document.getElementById('configure-options');
3947
const optionsEl = document.body.querySelector('.options');
48+
const optionsList = document.body.querySelector('.options__list');
4049
const goBack = document.getElementById('go-back');
4150

4251
let spinnerAnimation;
@@ -65,19 +74,35 @@ document.addEventListener('DOMContentLoaded', _ => {
6574
const getAuditsOfName = name => {
6675
let aggregation = aggregations.filter(aggregation => aggregation.name === name);
6776

68-
if (!aggregation.length) {
69-
return [];
70-
}
77+
return Object.keys(aggregation[0].criteria);
78+
};
7179

72-
// This checks if we have a a criteria property, it's necessary to check categories like Best Practices
73-
if (!aggregation[0].hasOwnProperty('criteria')) {
74-
aggregation = aggregation[0].items;
75-
}
80+
const createOptionItem = text => {
81+
const input = document.createElement('input');
82+
const attributes = [['type', 'checkbox'], ['checked', 'checked'], ['value', text]];
83+
attributes.forEach(attr => input.setAttribute.apply(input, attr));
7684

77-
return Object.keys(aggregation[0].criteria);
85+
const label = document.createElement('label');
86+
label.appendChild(input);
87+
label.appendChild(document.createTextNode(text));
88+
const listItem = document.createElement('li');
89+
listItem.appendChild(label);
90+
91+
return listItem;
92+
};
93+
94+
const generateOptionsList = list => {
95+
const frag = document.createDocumentFragment();
96+
97+
aggregations.forEach(aggregation => {
98+
frag.appendChild(createOptionItem(aggregation.name));
99+
});
100+
101+
list.appendChild(frag);
78102
};
79103

80104
background.listenForStatus(logstatus);
105+
generateOptionsList(optionsList);
81106

82107
generateReportEl.addEventListener('click', () => {
83108
startSpinner();

0 commit comments

Comments
 (0)