From 131d1c74c996253bdf444a9482fffc23dba21e74 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 3 Aug 2017 00:59:40 +0100 Subject: [PATCH] add room state explorer to devtools --- .../views/dialogs/DevtoolsDialog.js | 91 ++++++++++++++++++- 1 file changed, 90 insertions(+), 1 deletion(-) diff --git a/src/components/views/dialogs/DevtoolsDialog.js b/src/components/views/dialogs/DevtoolsDialog.js index c4248fa92b..9a518fd041 100644 --- a/src/components/views/dialogs/DevtoolsDialog.js +++ b/src/components/views/dialogs/DevtoolsDialog.js @@ -152,6 +152,89 @@ class SendCustomStateEvent extends React.Component { } } +class RoomStateExplorer extends React.Component { + static propTypes = { + roomId: React.PropTypes.string.isRequired, + onFinished: React.PropTypes.func.isRequired, + onBack: React.PropTypes.func.isRequired, + }; + + constructor(props, context) { + super(props, context); + + this.onBack = this.onBack.bind(this); + } + + state = { + eventType: null, + }; + + browseEventType(eventType) { + const self = this; + return () => { + self.setState({ eventType }); + }; + } + + onViewSourceClick(ev) { + const ViewSource = sdk.getComponent('structures.ViewSource'); + return () => { + Modal.createDialog(ViewSource, { + content: ev, + }, 'mx_Dialog_viewsource'); + }; + } + + onBack() { + if (this.state.eventType === null) { + this.props.onBack(); + } else { + this.setState({ eventType: null }); + } + } + + render() { + const room = MatrixClientPeg.get().getRoom(this.props.roomId); + const roomStateEvents = room.currentState.events; + + const rows = []; + + if (this.state.eventType === null) { + Object.keys(roomStateEvents).forEach((evType) => { + const stateGroup = roomStateEvents[evType]; + const keys = Object.keys(stateGroup); + + if (keys.length > 1) { + rows.push(); + } else if (keys.length === 1) { + rows.push(); + } + }); + } else { + const evType = this.state.eventType; + const stateGroup = roomStateEvents[evType]; + Object.keys(stateGroup).forEach((stateKey) => { + const ev = stateGroup[stateKey]; + rows.push(); + }); + } + + return
+
+
+ Room ID: {this.props.roomId} +
+
+ {rows} +
+
+
+ +
+
; + } +} + export default class DevtoolsDialog extends React.Component { static propTypes = { roomId: React.PropTypes.string.isRequired, @@ -164,6 +247,7 @@ export default class DevtoolsDialog extends React.Component { constructor(props, context) { super(props, context); + this.onBack = this.onBack.bind(this); this.onCancel = this.onCancel.bind(this); } @@ -177,6 +261,10 @@ export default class DevtoolsDialog extends React.Component { }; } + onBack() { + this.setState({ mode: null }); + } + onCancel() { this.props.onFinished(false); } @@ -185,12 +273,13 @@ export default class DevtoolsDialog extends React.Component { let body; if (this.state.mode) { - body = ; + body = ; } else { body =
+