add ability to jump from RSE to Send Custom State Event prefilled

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
pull/5074/head
Michael Telatynski 2017-09-18 11:27:31 +01:00
parent 821ab6c13e
commit af450df513
No known key found for this signature in database
GPG Key ID: 3F879DA5AD802A5E
1 changed files with 55 additions and 11 deletions

View File

@ -23,6 +23,14 @@ class SendCustomEvent extends React.Component {
static propTypes = { static propTypes = {
roomId: React.PropTypes.string.isRequired, roomId: React.PropTypes.string.isRequired,
onBack: React.PropTypes.func.isRequired, onBack: React.PropTypes.func.isRequired,
eventType: React.PropTypes.string.isRequired,
evContent: React.PropTypes.string.isRequired,
};
static defaultProps = {
eventType: '',
evContent: '{\n\n}',
}; };
constructor(props, context) { constructor(props, context) {
@ -33,8 +41,8 @@ class SendCustomEvent extends React.Component {
this.state = { this.state = {
message: null, message: null,
input_eventType: '', input_eventType: this.props.eventType,
input_evContent: '{\n\n}', input_evContent: this.props.evContent,
}; };
} }
@ -115,9 +123,24 @@ class SendCustomEvent extends React.Component {
} }
class SendCustomStateEvent extends SendCustomEvent { class SendCustomStateEvent extends SendCustomEvent {
static propTypes = {
roomId: React.PropTypes.string.isRequired,
onBack: React.PropTypes.func.isRequired,
eventType: React.PropTypes.string.isRequired,
evContent: React.PropTypes.string.isRequired,
stateKey: React.PropTypes.string.isRequired,
};
static defaultProps = {
eventType: '',
evContent: '{\n\n}',
stateKey: '',
};
constructor(props, context) { constructor(props, context) {
super(props, context); super(props, context);
this.state['input_stateKey'] = ''; this.state['input_stateKey'] = this.props.stateKey;
} }
send(content) { send(content) {
@ -139,6 +162,7 @@ class SendCustomStateEvent extends SendCustomEvent {
class RoomStateExplorer extends React.Component { class RoomStateExplorer extends React.Component {
static propTypes = { static propTypes = {
setMode: React.PropTypes.func.isRequired,
roomId: React.PropTypes.string.isRequired, roomId: React.PropTypes.string.isRequired,
onBack: React.PropTypes.func.isRequired, onBack: React.PropTypes.func.isRequired,
}; };
@ -150,6 +174,7 @@ class RoomStateExplorer extends React.Component {
this.roomStateEvents = room.currentState.events; this.roomStateEvents = room.currentState.events;
this.onBack = this.onBack.bind(this); this.onBack = this.onBack.bind(this);
this.editEv = this.editEv.bind(this);
} }
state = { state = {
@ -165,7 +190,7 @@ class RoomStateExplorer extends React.Component {
onViewSourceClick(event) { onViewSourceClick(event) {
return () => { return () => {
this.setState({ event: event.event }); this.setState({ event });
}; };
} }
@ -179,14 +204,24 @@ class RoomStateExplorer extends React.Component {
} }
} }
editEv() {
const ev = this.state.event;
this.props.setMode(SendCustomStateEvent, {
eventType: ev.getType(),
evContent: JSON.stringify(ev.getContent(), null, '\t'),
stateKey: ev.getStateKey(),
});
}
render() { render() {
if (this.state.event) { if (this.state.event) {
return <div className="mx_ViewSource"> return <div className="mx_ViewSource">
<div className="mx_Dialog_content"> <div className="mx_Dialog_content">
<pre>{JSON.stringify(this.state.event, null, 2)}</pre> <pre>{JSON.stringify(this.state.event.event, null, 2)}</pre>
</div> </div>
<div className="mx_Dialog_buttons"> <div className="mx_Dialog_buttons">
<button onClick={this.onBack}>{ _t('Back') }</button> <button onClick={this.onBack}>{ _t('Back') }</button>
<button onClick={this.editEv}>{ _t('Edit') }</button>
</div> </div>
</div>; </div>;
} }
@ -240,11 +275,13 @@ export default class DevtoolsDialog extends React.Component {
state = { state = {
mode: null, mode: null,
modeArgs: {},
}; };
constructor(props, context) { constructor(props, context) {
super(props, context); super(props, context);
this.onBack = this.onBack.bind(this); this.onBack = this.onBack.bind(this);
this.setMode = this.setMode.bind(this);
this.onCancel = this.onCancel.bind(this); this.onCancel = this.onCancel.bind(this);
} }
@ -254,10 +291,14 @@ export default class DevtoolsDialog extends React.Component {
_setMode(mode) { _setMode(mode) {
return () => { return () => {
this.setState({ mode }); this.setMode(mode);
}; };
} }
setMode(mode, modeArgs={}) {
this.setState({ mode, modeArgs });
}
onBack() { onBack() {
this.setState({ mode: null }); this.setState({ mode: null });
} }
@ -270,7 +311,8 @@ export default class DevtoolsDialog extends React.Component {
let body; let body;
if (this.state.mode) { if (this.state.mode) {
body = <this.state.mode {...this.props} onBack={this.onBack} />; body =
<this.state.mode {...this.props} {...this.state.modeArgs} onBack={this.onBack} setMode={this.setMode} />;
} else { } else {
body = <div> body = <div>
<div className="mx_Dialog_content"> <div className="mx_Dialog_content">
@ -285,9 +327,11 @@ export default class DevtoolsDialog extends React.Component {
} }
const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog'); const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog');
return <BaseDialog className="mx_QuestionDialog" onFinished={this.props.onFinished} title={_t('Developer Tools')}> return (
<BaseDialog className="mx_QuestionDialog" onFinished={this.props.onFinished} title={_t('Developer Tools')}>
<div>Room ID: { this.props.roomId }</div> <div>Room ID: { this.props.roomId }</div>
{ body } { body }
</BaseDialog>; </BaseDialog>
);
} }
} }