Skip to content

Commit 66a4738

Browse files
authored
Merge pull request element-hq#3648 from vector-im/rav/rageshake_progress
Progress updates for rageshake uploads
2 parents a34b5ab + 2590730 commit 66a4738

2 files changed

Lines changed: 64 additions & 16 deletions

File tree

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

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ limitations under the License.
1616

1717
import React from 'react';
1818
import sdk from 'matrix-react-sdk';
19-
import submit_rageshake from '../../../vector/submit-rageshake';
2019
import SdkConfig from 'matrix-react-sdk/lib/SdkConfig';
2120

2221
export default class BugReportDialog extends React.Component {
@@ -27,11 +26,18 @@ export default class BugReportDialog extends React.Component {
2726
busy: false,
2827
err: null,
2928
text: "",
29+
progress: null,
3030
};
31+
this._unmounted = false;
3132
this._onSubmit = this._onSubmit.bind(this);
3233
this._onCancel = this._onCancel.bind(this);
3334
this._onTextChange = this._onTextChange.bind(this);
3435
this._onSendLogsChange = this._onSendLogsChange.bind(this);
36+
this._sendProgressCallback = this._sendProgressCallback.bind(this);
37+
}
38+
39+
componentWillUnmount() {
40+
this._unmounted = true;
3541
}
3642

3743
_onCancel(ev) {
@@ -47,15 +53,27 @@ export default class BugReportDialog extends React.Component {
4753
});
4854
return;
4955
}
50-
this.setState({ busy: true, err: null });
51-
submit_rageshake(SdkConfig.get().bug_report_endpoint_url, {
52-
userText: userText,
53-
sendLogs: sendLogs,
54-
}).then(() => {
55-
this.setState({ busy: false });
56-
this.props.onFinished(false);
57-
}, (err) => {
58-
this.setState({ busy: false, err: `Failed: ${err.message}` });
56+
this.setState({ busy: true, progress: null, err: null });
57+
this._sendProgressCallback("Loading bug report module");
58+
59+
require(['../../../vector/submit-rageshake'], (s) => {
60+
s(SdkConfig.get().bug_report_endpoint_url, {
61+
userText: userText,
62+
sendLogs: sendLogs,
63+
progressCallback: this._sendProgressCallback,
64+
}).then(() => {
65+
if (!this._unmounted) {
66+
this.setState({ busy: false, progress: null });
67+
this.props.onFinished(false);
68+
}
69+
}, (err) => {
70+
if (!this._unmounted) {
71+
this.setState({
72+
busy: false, progress: null,
73+
err: `Failed to send report: ${err.message}`,
74+
});
75+
}
76+
});
5977
});
6078
}
6179

@@ -67,6 +85,13 @@ export default class BugReportDialog extends React.Component {
6785
this.setState({ sendLogs: ev.target.checked });
6886
}
6987

88+
_sendProgressCallback(progress) {
89+
if (this._unmounted) {
90+
return;
91+
}
92+
this.setState({progress: progress});
93+
}
94+
7095
render() {
7196
const Loader = sdk.getComponent("elements.Spinner");
7297

@@ -77,15 +102,23 @@ export default class BugReportDialog extends React.Component {
77102
</div>;
78103
}
79104

80-
const okLabel = this.state.busy ? <Loader /> : 'Send';
81-
82105
let cancelButton = null;
83106
if (!this.state.busy) {
84107
cancelButton = <button onClick={this._onCancel}>
85108
Cancel
86109
</button>;
87110
}
88111

112+
let progress = null;
113+
if (this.state.busy) {
114+
progress = (
115+
<div className="progress">
116+
<Loader />
117+
{this.state.progress} ...
118+
</div>
119+
);
120+
}
121+
89122
return (
90123
<div className="mx_BugReportDialog">
91124
<div className="mx_Dialog_title">
@@ -108,15 +141,17 @@ export default class BugReportDialog extends React.Component {
108141
<input type="checkbox" checked={this.state.sendLogs}
109142
onChange={this._onSendLogsChange} id="mx_BugReportDialog_logs"/>
110143
<label htmlFor="mx_BugReportDialog_logs">Send logs</label>
144+
{progress}
111145
{error}
112146
</div>
113147
<div className="mx_Dialog_buttons">
114148
<button
115149
className="mx_Dialog_primary danger"
116150
onClick={this._onSubmit}
117151
autoFocus={true}
152+
disabled={this.state.busy}
118153
>
119-
{okLabel}
154+
Send
120155
</button>
121156

122157
{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)