aboutsummaryrefslogtreecommitdiff
path: root/src/App.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/App.js')
-rw-r--r--src/App.js121
1 files changed, 106 insertions, 15 deletions
diff --git a/src/App.js b/src/App.js
index 7e261ca..347d243 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,28 +1,119 @@
1/*
2 * JaCoCo Report Viewer, a web-based coverage report viewer
3 * Copyright (C) 2018 Pacien TRAN-GIRARD
4 * Adam NAILI
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
1import React, { Component } from 'react'; 20import React, { Component } from 'react';
2import logo from './logo.svg'; 21import {Parser} from 'xml2js';
22
23import {Counters, SessionInfo, PackagesCoverage} from './Blocks.js';
3import './App.css'; 24import './App.css';
4 25
5class App extends Component { 26class App extends Component {
27 constructor(props) {
28 super(props);
29 this.state = {
30 report: null,
31 hasError: false
32 };
33 }
34
35 componentDidCatch(error, info) {
36 this.setState({ hasError: true });
37 console.err(error, info);
38 }
39
40 _useReportFile(file) {
41 const fileReader = new FileReader();
42 fileReader.onloadend = (readEvent) => this._useReport(readEvent.target.result);
43 fileReader.readAsText(file);
44 }
45
46 _useReport(xmlString) {
47 const xmlParser = new Parser();
48 xmlParser.parseString(xmlString, (err, result) => this.setState({ report: result.report }));
49 }
50
51 _renderError() {
52 return (
53 <span>
54 Something went wrong while rendering the report.
55 Are the provided files valid?
56 </span>
57 );
58 }
59
60 _renderReport() {
61 return this.state.hasError ? this._renderError(): (<Report report={this.state.report} />);
62 }
63
6 render() { 64 render() {
7 return ( 65 return (
8 <div className="App"> 66 <div className="App">
9 <header className="App-header"> 67 <h1>JaCoCo Report Viewer</h1>
10 <img src={logo} className="App-logo" alt="logo" /> 68
11 <p> 69 <div>
12 Edit <code>src/App.js</code> and save to reload. 70 <label htmlFor="reportFile">XML report: </label>
13 </p> 71 <input id="reportFile" type="file" accept=".xml" onChange={event => this._useReportFile(event.target.files[0])} />
14 <a 72 </div>
15 className="App-link" 73
16 href="https://reactjs.org" 74 <div>
17 target="_blank" 75 <label htmlFor="sourceJar">Source JAR: </label>
18 rel="noopener noreferrer" 76 <input id="sourceJar" type="file" accept=".jar" onChange={event => null} />
19 > 77 </div>
20 Learn React 78
21 </a> 79 <hr />
22 </header> 80 {this._renderReport()}
81 </div>
82 );
83 }
84}
85
86class Report extends Component {
87 _renderNone() {
88 return (<span>Please provide a JaCoCo XML report file to visualise.</span>);
89 }
90
91 _renderReport() {
92 return (
93 <div>
94 <h2>Viewing report: "{this.props.report.$.name}"</h2>
95
96 <section>
97 <h3>Session info</h3>
98 <SessionInfo data={this.props.report.sessioninfo} />
99 </section>
100
101 <section>
102 <h3>Global coverage</h3>
103 <Counters data={this.props.report.counter} />
104 </section>
105
106 <section>
107 <h3>Details</h3>
108 <PackagesCoverage packages={this.props.report.package} />
109 </section>
23 </div> 110 </div>
24 ); 111 );
25 } 112 }
113
114 render() {
115 return this.props.report ? this._renderReport() : this._renderNone();
116 }
26} 117}
27 118
28export default App; 119export default App;