feat: re-add debug button/modal

Fixes #1687
This commit is contained in:
Moritz Stueckler 2019-10-08 20:20:19 +02:00 committed by David Sevilla Martín
parent 898ab9000e
commit f7176cb076
3 changed files with 49 additions and 2 deletions

View File

@ -1,7 +1,9 @@
import ItemList from './utils/ItemList'; import ItemList from './utils/ItemList';
import Alert from './components/Alert'; import Alert from './components/Alert';
import Button from './components/Button';
import ModalManager from './components/ModalManager'; import ModalManager from './components/ModalManager';
import AlertManager from './components/AlertManager'; import AlertManager from './components/AlertManager';
import RequestErrorModal from './components/RequestErrorModal';
import Translator from './Translator'; import Translator from './Translator';
import Store from './Store'; import Store from './Store';
import Session from './Session'; import Session from './Session';
@ -141,7 +143,7 @@ export default class Application {
bootExtensions(extensions) { bootExtensions(extensions) {
Object.keys(extensions).forEach(name => { Object.keys(extensions).forEach(name => {
const extension = extensions[name]; const extension = extensions[name];
const extenders = flattenDeep(extension.extend); const extenders = flattenDeep(extension.extend);
for (const extender of extenders) { for (const extender of extenders) {
@ -330,7 +332,10 @@ export default class Application {
error.alert = new Alert({ error.alert = new Alert({
type: 'error', type: 'error',
children children,
controls: app.forum.attribute('debug') ? [
<Button className="Button Button--link" onclick={this.showDebug.bind(this, error)}>Debug</Button>
] : undefined
}); });
try { try {
@ -345,6 +350,16 @@ export default class Application {
return deferred.promise; return deferred.promise;
} }
/**
* @param {RequestError} error
* @private
*/
showDebug(error) {
this.alerts.dismiss(this.requestErrorAlert);
this.modal.show(new RequestErrorModal({error}));
}
/** /**
* Construct a URL to the route with the given name. * Construct a URL to the route with the given name.
* *

View File

@ -37,6 +37,7 @@ import Placeholder from './components/Placeholder';
import Separator from './components/Separator'; import Separator from './components/Separator';
import Dropdown from './components/Dropdown'; import Dropdown from './components/Dropdown';
import SplitDropdown from './components/SplitDropdown'; import SplitDropdown from './components/SplitDropdown';
import RequestErrorModal from './components/RequestErrorModal';
import FieldSet from './components/FieldSet'; import FieldSet from './components/FieldSet';
import Select from './components/Select'; import Select from './components/Select';
import Navigation from './components/Navigation'; import Navigation from './components/Navigation';
@ -100,6 +101,7 @@ export default {
'components/Separator': Separator, 'components/Separator': Separator,
'components/Dropdown': Dropdown, 'components/Dropdown': Dropdown,
'components/SplitDropdown': SplitDropdown, 'components/SplitDropdown': SplitDropdown,
'components/RequestErrorModal': RequestErrorModal,
'components/FieldSet': FieldSet, 'components/FieldSet': FieldSet,
'components/Select': Select, 'components/Select': Select,
'components/Navigation': Navigation, 'components/Navigation': Navigation,

View File

@ -0,0 +1,30 @@
import Modal from './Modal';
export default class RequestErrorModal extends Modal {
className() {
return 'RequestErrorModal Modal--large';
}
title() {
return this.props.error.xhr
? this.props.error.xhr.status+' '+this.props.error.xhr.statusText
: '';
}
content() {
let responseText;
try {
responseText = JSON.stringify(JSON.parse(this.props.error.responseText), null, 2);
} catch (e) {
responseText = this.props.error.responseText;
}
return <div className="Modal-body">
<pre>
{this.props.error.options.method} {this.props.error.options.url}<br/><br/>
{responseText}
</pre>
</div>;
}
}