Skip to content

Commit d8bf57e

Browse files
committed
Add progress reporting to rageshake submission
1 parent 269f9a5 commit d8bf57e

2 files changed

Lines changed: 51 additions & 9 deletions

File tree

‎src/components/views/dialogs/BugReportDialog.js‎

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,18 @@ export default class BugReportDialog extends React.Component {
2626
busy: false,
2727
err: null,
2828
text: "",
29+
progress: null,
2930
};
31+
this._unmounted = false;
3032
this._onSubmit = this._onSubmit.bind(this);
3133
this._onCancel = this._onCancel.bind(this);
3234
this._onTextChange = this._onTextChange.bind(this);
3335
this._onSendLogsChange = this._onSendLogsChange.bind(this);
36+
this._sendProgressCallback = this._sendProgressCallback.bind(this);
37+
}
38+
39+
componentWillUnmount() {
40+
this._unmounted = true;
3441
}
3542

3643
_onCancel(ev) {
@@ -46,17 +53,22 @@ export default class BugReportDialog extends React.Component {
4653
});
4754
return;
4855
}
49-
this.setState({ busy: true, err: null });
56+
this.setState({ busy: true, progress: null, err: null });
57+
this._sendProgressCallback("Loading bug report module");
5058

5159
require(['../../../vector/submit-rageshake'], (s) => {
5260
s(SdkConfig.get().bug_report_endpoint_url, {
5361
userText: userText,
5462
sendLogs: sendLogs,
63+
progressCallback: this._sendProgressCallback,
5564
}).then(() => {
56-
this.setState({ busy: false });
65+
this.setState({ busy: false, progress: null });
5766
this.props.onFinished(false);
5867
}, (err) => {
59-
this.setState({ busy: false, err: `Failed: ${err.message}` });
68+
this.setState({
69+
busy: false, progress: null,
70+
err: `Failed to send report: ${err.message}`,
71+
});
6072
});
6173
});
6274
}
@@ -69,6 +81,13 @@ export default class BugReportDialog extends React.Component {
6981
this.setState({ sendLogs: ev.target.checked });
7082
}
7183

84+
_sendProgressCallback(progress) {
85+
if (this._unmounted) {
86+
return;
87+
}
88+
this.setState({progress: progress});
89+
}
90+
7291
render() {
7392
const Loader = sdk.getComponent("elements.Spinner");
7493

@@ -79,15 +98,23 @@ export default class BugReportDialog extends React.Component {
7998
</div>;
8099
}
81100

82-
const okLabel = this.state.busy ? <Loader /> : 'Send';
83-
84101
let cancelButton = null;
85102
if (!this.state.busy) {
86103
cancelButton = <button onClick={this._onCancel}>
87104
Cancel
88105
</button>;
89106
}
90107

108+
let progress = null;
109+
if (this.state.busy) {
110+
progress = (
111+
<div className="progress">
112+
<Loader />
113+
{this.state.progress} ...
114+
</div>
115+
);
116+
}
117+
91118
return (
92119
<div className="mx_BugReportDialog">
93120
<div className="mx_Dialog_title">
@@ -110,15 +137,17 @@ export default class BugReportDialog extends React.Component {
110137
<input type="checkbox" checked={this.state.sendLogs}
111138
onChange={this._onSendLogsChange} id="mx_BugReportDialog_logs"/>
112139
<label htmlFor="mx_BugReportDialog_logs">Send logs</label>
140+
{progress}
113141
{error}
114142
</div>
115143
<div className="mx_Dialog_buttons">
116144
<button
117145
className="mx_Dialog_primary danger"
118146
onClick={this._onSubmit}
119147
autoFocus={true}
148+
disabled={this.state.busy}
120149
>
121-
{okLabel}
150+
Send
122151
</button>
123152

124153
{cancelButton}

‎src/vector/submit-rageshake.js‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,17 @@ if (!TextEncoder) {
3030

3131
/**
3232
* Send a bug report.
33+
*
3334
* @param {string} bugReportEndpoint HTTP url to send the report to
35+
*
3436
* @param {object} opts optional dictionary of options
37+
*
3538
* @param {string} opts.userText Any additional user input.
39+
*
3640
* @param {boolean} opts.sendLogs True to send logs
41+
*
42+
* @param {function(string)} opts.progressCallback Callback to call with progress updates
43+
*
3744
* @return {Promise} Resolved when the bug report is sent.
3845
*/
3946
export default async function sendBugReport(bugReportEndpoint, opts) {
@@ -42,7 +49,9 @@ export default async function sendBugReport(bugReportEndpoint, opts) {
4249
}
4350

4451
opts = opts || {};
52+
const progressCallback = opts.progressCallback || (() => {});
4553

54+
progressCallback("Collecting app version information");
4655
let version = "UNKNOWN";
4756
try {
4857
version = await PlatformPeg.get().getAppVersion();
@@ -63,6 +72,7 @@ export default async function sendBugReport(bugReportEndpoint, opts) {
6372
body.append('user_agent', userAgent);
6473

6574
if (opts.sendLogs) {
75+
progressCallback("Collecting logs");
6676
const logs = await rageshake.getLogsForReport();
6777
for (let entry of logs) {
6878
// encode as UTF-8
@@ -72,17 +82,20 @@ export default async function sendBugReport(bugReportEndpoint, opts) {
7282
}
7383
}
7484

75-
await _submitReport(bugReportEndpoint, body);
85+
progressCallback("Uploading report");
86+
await _submitReport(bugReportEndpoint, body, progressCallback);
7687
}
7788

78-
function _submitReport(endpoint, body) {
89+
function _submitReport(endpoint, body, progressCallback) {
7990
const deferred = q.defer();
8091

8192
const req = new XMLHttpRequest();
8293
req.open("POST", endpoint);
8394
req.timeout = 5 * 60 * 1000;
8495
req.onreadystatechange = function() {
85-
if (req.readyState === XMLHttpRequest.DONE) {
96+
if (req.readyState === XMLHttpRequest.LOADING) {
97+
progressCallback("Waiting for response from server");
98+
} else if (req.readyState === XMLHttpRequest.DONE) {
8699
on_done();
87100
}
88101
};

0 commit comments

Comments
 (0)