Skip to content

Commit e8874e9

Browse files
author
Bastien Abadie
committed
Use default values in routing for zero coverage
1 parent 9284072 commit e8874e9

File tree

4 files changed

+46
-17
lines changed

4 files changed

+46
-17
lines changed

frontend/src/base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ <h2>
103103
</script>
104104

105105
<script id="menu_browser" type="x-tmpl-mustache">
106-
<a href="#view=zero&third_party=on&cpp=on&js=on=java=on&rust=on">View the zero coverage report</a>
106+
<a href="#view=zero">View the zero coverage report</a>
107107
&bull;
108108
<input type="text" name="revision" placeholder="Mercurial revision" value="{{revision}}"></input>
109109
&bull;

frontend/src/common.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Mustache from 'mustache';
22
import { buildRoute, readRoute, updateRoute } from './route.js';
3+
import {ZERO_COVERAGE_FILTERS} from './zero_coverage_report.js';
34

45
export const REV_LATEST = 'latest';
56

@@ -159,9 +160,15 @@ export async function get_filters() {
159160

160161
// Option handling.
161162

162-
function is_enabled(opt) {
163+
export function is_enabled(opt) {
163164
let route = readRoute();
164-
return route[opt] === 'on';
165+
let value = 'off';
166+
if (route[opt]) {
167+
value = route[opt];
168+
} else if (ZERO_COVERAGE_FILTERS[opt]) {
169+
value = ZERO_COVERAGE_FILTERS[opt].default_value;
170+
}
171+
return value === 'on';
165172
}
166173

167174
function monitor_options() {

frontend/src/route.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export function readRoute() {
2020
if (!out.path) {
2121
out.path = '';
2222
}
23+
2324
return out;
2425
}
2526

frontend/src/zero_coverage_report.js

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,51 @@
1-
import {hide, message, build_navbar, render, filter_third_party, filter_languages, filter_headers, filter_completely_uncovered, filter_last_push_date} from './common.js';
1+
import {hide, message, build_navbar, render, filter_third_party, filter_languages, filter_headers, filter_completely_uncovered, filter_last_push_date, is_enabled} from './common.js';
22
import {buildRoute} from './route.js';
33

4-
const ZERO_COVERAGE_FILTERS = {
5-
'third_party': "Show third-party files",
6-
'headers': 'Show headers',
7-
'completely_uncovered': 'Show completely uncovered files only',
8-
'cpp': 'C/C++',
9-
'js': 'JavaScript',
10-
'java': 'Java',
11-
'rust': 'Rust',
4+
export const ZERO_COVERAGE_FILTERS = {
5+
'third_party': {
6+
name: "Show third-party files",
7+
default_value: 'on',
8+
},
9+
'headers': {
10+
name: 'Show headers',
11+
default_value: 'off',
12+
},
13+
'completely_uncovered': {
14+
name: 'Show completely uncovered files only',
15+
default_value: 'off',
16+
},
17+
'cpp': {
18+
name: 'C/C++',
19+
default_value: 'on',
20+
},
21+
'js': {
22+
name: 'JavaScript',
23+
default_value: 'on',
24+
},
25+
'java': {
26+
name: 'Java',
27+
default_value: 'on',
28+
},
29+
'rust': {
30+
name: 'Rust',
31+
default_value: 'on',
32+
},
1233
};
1334
const ZERO_COVERAGE_PUSHES = {
1435
'all': 'All',
15-
'one_year': '0 &lt; 1 year',
16-
'two_years': '1 &lt; 2 years',
36+
'one_year': '0 < 1 year',
37+
'two_years': '1 < 2 years',
1738
'older_than_two_years': 'Older than 2 years',
1839
}
1940

2041

2142
export function zero_coverage_menu(route){
2243
let context = {
23-
filters: Object.entries(ZERO_COVERAGE_FILTERS).map(([key, message]) => {
44+
filters: Object.entries(ZERO_COVERAGE_FILTERS).map(([key, filter]) => {
2445
return {
2546
key,
26-
message,
27-
checked: route[key] === 'on',
47+
message: filter.name,
48+
checked: is_enabled(key),
2849
}
2950
}),
3051
last_pushes: Object.entries(ZERO_COVERAGE_PUSHES).map(([value, message]) => {

0 commit comments

Comments
 (0)