Skip to content

Commit 0d229f0

Browse files
authored
Merge pull request element-hq#5718 from vector-im/t3chguy/devtools-118247
make FilteredList controlled, such that it can externally persist filter
2 parents b0a3bd6 + 2001245 commit 0d229f0

1 file changed

Lines changed: 59 additions & 35 deletions

File tree

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

Lines changed: 59 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -245,24 +245,22 @@ class SendAccountData extends GenericEditor {
245245
class FilteredList extends React.Component {
246246
static propTypes = {
247247
children: PropTypes.any,
248+
query: PropTypes.string,
249+
onChange: PropTypes.func,
248250
};
249251

250252
constructor(props, context) {
251253
super(props, context);
252254
this.onQuery = this.onQuery.bind(this);
253-
254-
this.state = {
255-
query: '',
256-
};
257255
}
258256

259257
onQuery(ev) {
260-
this.setState({ query: ev.target.value });
258+
if (this.props.onChange) this.props.onChange(ev.target.value);
261259
}
262260

263261
filterChildren() {
264-
if (this.state.query) {
265-
const lowerQuery = this.state.query.toLowerCase();
262+
if (this.props.query) {
263+
const lowerQuery = this.props.query.toLowerCase();
266264
return this.props.children.filter((child) => child.key.toLowerCase().includes(lowerQuery));
267265
}
268266
return this.props.children;
@@ -272,7 +270,7 @@ class FilteredList extends React.Component {
272270
return <div>
273271
<input size="64"
274272
onChange={this.onQuery}
275-
value={this.state.query}
273+
value={this.props.query}
276274
placeholder={_t('Filter results')}
277275
className="mx_TextInputDialog_input mx_DevTools_RoomStateExplorer_query" />
278276
{ this.filterChildren() }
@@ -296,11 +294,16 @@ class RoomStateExplorer extends DevtoolsComponent {
296294

297295
this.onBack = this.onBack.bind(this);
298296
this.editEv = this.editEv.bind(this);
297+
this.onQueryEventType = this.onQueryEventType.bind(this);
298+
this.onQueryStateKey = this.onQueryStateKey.bind(this);
299299

300300
this.state = {
301301
eventType: null,
302302
event: null,
303303
editing: false,
304+
305+
queryEventType: '',
306+
queryStateKey: '',
304307
};
305308
}
306309

@@ -332,6 +335,14 @@ class RoomStateExplorer extends DevtoolsComponent {
332335
this.setState({ editing: true });
333336
}
334337

338+
onQueryEventType(filterEventType) {
339+
this.setState({ queryEventType: filterEventType });
340+
}
341+
342+
onQueryStateKey(filterStateKey) {
343+
this.setState({ queryStateKey: filterStateKey });
344+
}
345+
335346
render() {
336347
if (this.state.event) {
337348
if (this.state.editing) {
@@ -355,41 +366,47 @@ class RoomStateExplorer extends DevtoolsComponent {
355366
</div>;
356367
}
357368

358-
const rows = [];
369+
let list = null;
359370

360371
const classes = 'mx_DevTools_RoomStateExplorer_button';
361372
if (this.state.eventType === null) {
362-
Object.keys(this.roomStateEvents).forEach((evType) => {
363-
const stateGroup = this.roomStateEvents[evType];
364-
const stateKeys = Object.keys(stateGroup);
365-
366-
let onClickFn;
367-
if (stateKeys.length > 1) {
368-
onClickFn = this.browseEventType(evType);
369-
} else if (stateKeys.length === 1) {
370-
onClickFn = this.onViewSourceClick(stateGroup[stateKeys[0]]);
373+
list = <FilteredList query={this.state.queryEventType} onChange={this.onQueryEventType}>
374+
{
375+
Object.keys(this.roomStateEvents).map((evType) => {
376+
const stateGroup = this.roomStateEvents[evType];
377+
const stateKeys = Object.keys(stateGroup);
378+
379+
let onClickFn;
380+
if (stateKeys.length > 1) {
381+
onClickFn = this.browseEventType(evType);
382+
} else if (stateKeys.length === 1) {
383+
onClickFn = this.onViewSourceClick(stateGroup[stateKeys[0]]);
384+
}
385+
386+
return <button className={classes} key={evType} onClick={onClickFn}>
387+
{ evType }
388+
</button>;
389+
})
371390
}
372-
373-
rows.push(<button className={classes} key={evType} onClick={onClickFn}>
374-
{ evType }
375-
</button>);
376-
});
391+
</FilteredList>;
377392
} else {
378-
const evType = this.state.eventType;
379-
const stateGroup = this.roomStateEvents[evType];
380-
Object.keys(stateGroup).forEach((stateKey) => {
381-
const ev = stateGroup[stateKey];
382-
rows.push(<button className={classes} key={stateKey} onClick={this.onViewSourceClick(ev)}>
383-
{ stateKey }
384-
</button>);
385-
});
393+
const stateGroup = this.roomStateEvents[this.state.eventType];
394+
395+
list = <FilteredList query={this.state.queryStateKey} onChange={this.onQueryStateKey}>
396+
{
397+
Object.keys(stateGroup).map((stateKey) => {
398+
const ev = stateGroup[stateKey];
399+
return <button className={classes} key={stateKey} onClick={this.onViewSourceClick(ev)}>
400+
{ stateKey }
401+
</button>;
402+
})
403+
}
404+
</FilteredList>;
386405
}
387406

388407
return <div>
389408
<div className="mx_Dialog_content">
390-
<FilteredList>
391-
{ rows }
392-
</FilteredList>
409+
{ list }
393410
</div>
394411
<div className="mx_Dialog_buttons">
395412
<button onClick={this.onBack}>{ _t('Back') }</button>
@@ -411,11 +428,14 @@ class AccountDataExplorer extends DevtoolsComponent {
411428
this.onBack = this.onBack.bind(this);
412429
this.editEv = this.editEv.bind(this);
413430
this._onChange = this._onChange.bind(this);
431+
this.onQueryEventType = this.onQueryEventType.bind(this);
414432

415433
this.state = {
416434
isRoomAccountData: false,
417435
event: null,
418436
editing: false,
437+
438+
queryEventType: '',
419439
};
420440
}
421441

@@ -451,6 +471,10 @@ class AccountDataExplorer extends DevtoolsComponent {
451471
this.setState({ editing: true });
452472
}
453473

474+
onQueryEventType(queryEventType) {
475+
this.setState({ queryEventType });
476+
}
477+
454478
render() {
455479
if (this.state.event) {
456480
if (this.state.editing) {
@@ -487,7 +511,7 @@ class AccountDataExplorer extends DevtoolsComponent {
487511

488512
return <div>
489513
<div className="mx_Dialog_content">
490-
<FilteredList>
514+
<FilteredList query={this.state.queryEventType} onChange={this.onQueryEventType}>
491515
{ rows }
492516
</FilteredList>
493517
</div>

0 commit comments

Comments
 (0)