Skip to content

Commit fbe1c82

Browse files
authored
Merge pull request element-hq#5074 from vector-im/t3chguy/devtools-1
T3chguy/devtools 1
2 parents 8fc6919 + 00976d9 commit fbe1c82

3 files changed

Lines changed: 97 additions & 21 deletions

File tree

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

Lines changed: 94 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,28 @@ class SendCustomEvent extends React.Component {
2323
static propTypes = {
2424
roomId: React.PropTypes.string.isRequired,
2525
onBack: React.PropTypes.func.isRequired,
26+
27+
eventType: React.PropTypes.string.isRequired,
28+
evContent: React.PropTypes.string.isRequired,
29+
};
30+
31+
static defaultProps = {
32+
eventType: '',
33+
evContent: '{\n\n}',
2634
};
2735

2836
constructor(props, context) {
2937
super(props, context);
3038
this._send = this._send.bind(this);
3139
this.onBack = this.onBack.bind(this);
32-
}
40+
this._onChange = this._onChange.bind(this);
3341

34-
state = {
35-
message: null,
36-
};
42+
this.state = {
43+
message: null,
44+
input_eventType: this.props.eventType,
45+
input_evContent: this.props.evContent,
46+
};
47+
}
3748

3849
onBack() {
3950
if (this.state.message) {
@@ -51,13 +62,18 @@ class SendCustomEvent extends React.Component {
5162
}
5263

5364
send(content) {
54-
return MatrixClientPeg.get().sendEvent(this.props.roomId, this.refs.eventType.value, content);
65+
return MatrixClientPeg.get().sendEvent(this.props.roomId, this.state.input_eventType, content);
5566
}
5667

5768
async _send() {
69+
if (this.state.input_eventType === '') {
70+
this.setState({ message: _t('You must specify an event type!') });
71+
return;
72+
}
73+
5874
let message;
5975
try {
60-
const content = JSON.parse(this.refs.evContent.value);
76+
const content = JSON.parse(this.state.input_evContent);
6177
await this.send(content);
6278
message = _t('Event sent!');
6379
} catch (e) {
@@ -67,7 +83,11 @@ class SendCustomEvent extends React.Component {
6783
}
6884

6985
_additionalFields() {
70-
return <div></div>;
86+
return <div/>;
87+
}
88+
89+
_onChange(e) {
90+
this.setState({[`input_${e.target.id}`]: e.target.value});
7191
}
7292

7393
render() {
@@ -87,14 +107,14 @@ class SendCustomEvent extends React.Component {
87107
<label htmlFor="eventType"> { _t('Event Type') } </label>
88108
</div>
89109
<div>
90-
<input id="eventType" ref="eventType" className="mx_TextInputDialog_input" size="64" />
110+
<input id="eventType" onChange={this._onChange} value={this.state.input_eventType} className="mx_TextInputDialog_input" size="64" />
91111
</div>
92112

93113
<div className="mx_TextInputDialog_label">
94114
<label htmlFor="evContent"> { _t('Event Content') } </label>
95115
</div>
96116
<div>
97-
<textarea id="evContent" ref="evContent" className="mx_TextInputDialog_input" defaultValue={"{\n\n}"} cols="63" rows="5" />
117+
<textarea id="evContent" onChange={this._onChange} value={this.state.input_evContent} className="mx_TextInputDialog_input" cols="63" rows="5" />
98118
</div>
99119
</div>
100120
{this._buttons()}
@@ -103,9 +123,29 @@ class SendCustomEvent extends React.Component {
103123
}
104124

105125
class SendCustomStateEvent extends SendCustomEvent {
126+
static propTypes = {
127+
roomId: React.PropTypes.string.isRequired,
128+
onBack: React.PropTypes.func.isRequired,
129+
130+
eventType: React.PropTypes.string.isRequired,
131+
evContent: React.PropTypes.string.isRequired,
132+
stateKey: React.PropTypes.string.isRequired,
133+
};
134+
135+
static defaultProps = {
136+
eventType: '',
137+
evContent: '{\n\n}',
138+
stateKey: '',
139+
};
140+
141+
constructor(props, context) {
142+
super(props, context);
143+
this.state['input_stateKey'] = this.props.stateKey;
144+
}
145+
106146
send(content) {
107-
return MatrixClientPeg.get().sendStateEvent(this.props.roomId, this.refs.eventType.value, content,
108-
this.refs.stateKey.value);
147+
const cli = MatrixClientPeg.get();
148+
return cli.sendStateEvent(this.props.roomId, this.state.input_eventType, content, this.state.input_stateKey);
109149
}
110150

111151
_additionalFields() {
@@ -114,14 +154,15 @@ class SendCustomStateEvent extends SendCustomEvent {
114154
<label htmlFor="stateKey"> { _t('State Key') } </label>
115155
</div>
116156
<div>
117-
<input id="stateKey" ref="stateKey" className="mx_TextInputDialog_input" size="64" />
157+
<input id="stateKey" onChange={this._onChange} value={this.state.input_stateKey} className="mx_TextInputDialog_input" size="64" />
118158
</div>
119159
</div>;
120160
}
121161
}
122162

123163
class RoomStateExplorer extends React.Component {
124164
static propTypes = {
165+
setMode: React.PropTypes.func.isRequired,
125166
roomId: React.PropTypes.string.isRequired,
126167
onBack: React.PropTypes.func.isRequired,
127168
};
@@ -133,9 +174,12 @@ class RoomStateExplorer extends React.Component {
133174
this.roomStateEvents = room.currentState.events;
134175

135176
this.onBack = this.onBack.bind(this);
177+
this.editEv = this.editEv.bind(this);
178+
this.onQuery = this.onQuery.bind(this);
136179
}
137180

138181
state = {
182+
query: '',
139183
eventType: null,
140184
event: null,
141185
};
@@ -148,7 +192,7 @@ class RoomStateExplorer extends React.Component {
148192

149193
onViewSourceClick(event) {
150194
return () => {
151-
this.setState({ event: event.event });
195+
this.setState({ event });
152196
};
153197
}
154198

@@ -162,14 +206,28 @@ class RoomStateExplorer extends React.Component {
162206
}
163207
}
164208

209+
editEv() {
210+
const ev = this.state.event;
211+
this.props.setMode(SendCustomStateEvent, {
212+
eventType: ev.getType(),
213+
evContent: JSON.stringify(ev.getContent(), null, '\t'),
214+
stateKey: ev.getStateKey(),
215+
});
216+
}
217+
218+
onQuery(ev) {
219+
this.setState({ query: ev.target.value });
220+
}
221+
165222
render() {
166223
if (this.state.event) {
167224
return <div className="mx_ViewSource">
168225
<div className="mx_Dialog_content">
169-
<pre>{JSON.stringify(this.state.event, null, 2)}</pre>
226+
<pre>{JSON.stringify(this.state.event.event, null, 2)}</pre>
170227
</div>
171228
<div className="mx_Dialog_buttons">
172229
<button onClick={this.onBack}>{ _t('Back') }</button>
230+
<button onClick={this.editEv}>{ _t('Edit') }</button>
173231
</div>
174232
</div>;
175233
}
@@ -178,6 +236,9 @@ class RoomStateExplorer extends React.Component {
178236

179237
if (this.state.eventType === null) {
180238
Object.keys(this.roomStateEvents).forEach((evType) => {
239+
// Skip this entry if does not contain search query
240+
if (this.state.query && !evType.includes(this.state.query)) return;
241+
181242
const stateGroup = this.roomStateEvents[evType];
182243
const stateKeys = Object.keys(stateGroup);
183244

@@ -196,6 +257,9 @@ class RoomStateExplorer extends React.Component {
196257
const evType = this.state.eventType;
197258
const stateGroup = this.roomStateEvents[evType];
198259
Object.keys(stateGroup).forEach((stateKey) => {
260+
// Skip this entry if does not contain search query
261+
if (this.state.query && !stateKey.includes(this.state.query)) return;
262+
199263
const ev = stateGroup[stateKey];
200264
rows.push(<button className="mx_DevTools_RoomStateExplorer_button" key={stateKey}
201265
onClick={this.onViewSourceClick(ev)}>
@@ -206,6 +270,7 @@ class RoomStateExplorer extends React.Component {
206270

207271
return <div>
208272
<div className="mx_Dialog_content">
273+
<input onChange={this.onQuery} placeholder={_t('Filter results')} size="64" className="mx_TextInputDialog_input mx_DevTools_RoomStateExplorer_query" value={this.state.query} />
209274
{rows}
210275
</div>
211276
<div className="mx_Dialog_buttons">
@@ -223,11 +288,13 @@ export default class DevtoolsDialog extends React.Component {
223288

224289
state = {
225290
mode: null,
291+
modeArgs: {},
226292
};
227293

228294
constructor(props, context) {
229295
super(props, context);
230296
this.onBack = this.onBack.bind(this);
297+
this.setMode = this.setMode.bind(this);
231298
this.onCancel = this.onCancel.bind(this);
232299
}
233300

@@ -237,10 +304,14 @@ export default class DevtoolsDialog extends React.Component {
237304

238305
_setMode(mode) {
239306
return () => {
240-
this.setState({ mode });
307+
this.setMode(mode);
241308
};
242309
}
243310

311+
setMode(mode, modeArgs={}) {
312+
this.setState({ mode, modeArgs });
313+
}
314+
244315
onBack() {
245316
this.setState({ mode: null });
246317
}
@@ -253,7 +324,8 @@ export default class DevtoolsDialog extends React.Component {
253324
let body;
254325

255326
if (this.state.mode) {
256-
body = <this.state.mode {...this.props} onBack={this.onBack} />;
327+
body =
328+
<this.state.mode {...this.props} {...this.state.modeArgs} onBack={this.onBack} setMode={this.setMode} />;
257329
} else {
258330
body = <div>
259331
<div className="mx_Dialog_content">
@@ -268,9 +340,11 @@ export default class DevtoolsDialog extends React.Component {
268340
}
269341

270342
const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog');
271-
return <BaseDialog className="mx_QuestionDialog" onFinished={this.props.onFinished} title={_t('Developer Tools')}>
272-
<div>Room ID: {this.props.roomId}</div>
273-
{ body }
274-
</BaseDialog>;
343+
return (
344+
<BaseDialog className="mx_QuestionDialog" onFinished={this.props.onFinished} title={_t('Developer Tools')}>
345+
<div>Room ID: { this.props.roomId }</div>
346+
{ body }
347+
</BaseDialog>
348+
);
275349
}
276350
}

‎src/i18n/strings/en_EN.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"Favourite": "Favourite",
6060
"Fetching third party location failed": "Fetching third party location failed",
6161
"Files": "Files",
62+
"Filter results": "Filter results",
6263
"Filter room names": "Filter room names",
6364
"Forget": "Forget",
6465
"Forward Message": "Forward Message",
@@ -156,6 +157,7 @@
156157
"You are not receiving desktop notifications": "You are not receiving desktop notifications",
157158
"You are Rioting as a guest. <a>Register</a> or <a>sign in</a> to access more rooms and features!": "You are Rioting as a guest. <a>Register</a> or <a>sign in</a> to access more rooms and features!",
158159
"You might have configured them in a client other than Riot. You cannot tune them in Riot but they still apply": "You might have configured them in a client other than Riot. You cannot tune them in Riot but they still apply",
160+
"You must specify an event type!": "You must specify an event type!",
159161
"Thank you!": "Thank you!",
160162
"Sunday": "Sunday",
161163
"Monday": "Monday",

‎src/skins/vector/css/vector-web/views/dialogs/_DevtoolsDialog.scss‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
.mx_DevTools_RoomStateExplorer_button {
17+
.mx_DevTools_RoomStateExplorer_button, .mx_DevTools_RoomStateExplorer_query {
1818
margin-bottom: 10px;
1919
}

0 commit comments

Comments
 (0)