Skip to content

Commit 43578d2

Browse files
committed
make FilteredList controlled, such that it can externally persist filter
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
1 parent 63bedc4 commit 43578d2

1 file changed

Lines changed: 61 additions & 28 deletions

File tree

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

Lines changed: 61 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -244,19 +244,26 @@ class SendAccountData extends GenericEditor {
244244
class FilteredList extends React.Component {
245245
static propTypes = {
246246
children: PropTypes.any,
247+
query: PropTypes.string,
248+
onChange: PropTypes.func,
247249
};
248250

249251
constructor(props, context) {
250252
super(props, context);
251253
this.onQuery = this.onQuery.bind(this);
252254

253255
this.state = {
254-
query: '',
256+
query: this.props.query,
255257
};
256258
}
257259

260+
componentWillReceiveProps(nextProps) {
261+
if (this.state.query !== nextProps.query) this.setState({ query: nextProps.query });
262+
}
263+
258264
onQuery(ev) {
259265
this.setState({ query: ev.target.value });
266+
if (this.props.onChange) this.props.onChange(ev.target.value);
260267
}
261268

262269
filterChildren() {
@@ -295,11 +302,16 @@ class RoomStateExplorer extends DevtoolsComponent {
295302

296303
this.onBack = this.onBack.bind(this);
297304
this.editEv = this.editEv.bind(this);
305+
this.onQueryEventType = this.onQueryEventType.bind(this);
306+
this.onQueryStateKey = this.onQueryStateKey.bind(this);
298307

299308
this.state = {
300309
eventType: null,
301310
event: null,
302311
editing: false,
312+
313+
queryEventType: '',
314+
queryStateKey: '',
303315
};
304316
}
305317

@@ -331,6 +343,14 @@ class RoomStateExplorer extends DevtoolsComponent {
331343
this.setState({ editing: true });
332344
}
333345

346+
onQueryEventType(filterEventType) {
347+
this.setState({ queryEventType: filterEventType });
348+
}
349+
350+
onQueryStateKey(filterStateKey) {
351+
this.setState({ queryStateKey: filterStateKey });
352+
}
353+
334354
render() {
335355
if (this.state.event) {
336356
if (this.state.editing) {
@@ -352,41 +372,47 @@ class RoomStateExplorer extends DevtoolsComponent {
352372
</div>;
353373
}
354374

355-
const rows = [];
375+
let list = null;
356376

357377
const classes = 'mx_DevTools_RoomStateExplorer_button';
358378
if (this.state.eventType === null) {
359-
Object.keys(this.roomStateEvents).forEach((evType) => {
360-
const stateGroup = this.roomStateEvents[evType];
361-
const stateKeys = Object.keys(stateGroup);
362-
363-
let onClickFn;
364-
if (stateKeys.length > 1) {
365-
onClickFn = this.browseEventType(evType);
366-
} else if (stateKeys.length === 1) {
367-
onClickFn = this.onViewSourceClick(stateGroup[stateKeys[0]]);
379+
list = <FilteredList query={this.state.queryEventType} onChange={this.onQueryEventType}>
380+
{
381+
Object.keys(this.roomStateEvents).map((evType) => {
382+
const stateGroup = this.roomStateEvents[evType];
383+
const stateKeys = Object.keys(stateGroup);
384+
385+
let onClickFn;
386+
if (stateKeys.length > 1) {
387+
onClickFn = this.browseEventType(evType);
388+
} else if (stateKeys.length === 1) {
389+
onClickFn = this.onViewSourceClick(stateGroup[stateKeys[0]]);
390+
}
391+
392+
return <button className={classes} key={evType} onClick={onClickFn}>
393+
{ evType }
394+
</button>;
395+
})
368396
}
369-
370-
rows.push(<button className={classes} key={evType} onClick={onClickFn}>
371-
{ evType }
372-
</button>);
373-
});
397+
</FilteredList>;
374398
} else {
375-
const evType = this.state.eventType;
376-
const stateGroup = this.roomStateEvents[evType];
377-
Object.keys(stateGroup).forEach((stateKey) => {
378-
const ev = stateGroup[stateKey];
379-
rows.push(<button className={classes} key={stateKey} onClick={this.onViewSourceClick(ev)}>
380-
{ stateKey }
381-
</button>);
382-
});
399+
const stateGroup = this.roomStateEvents[this.state.eventType];
400+
401+
list = <FilteredList query={this.state.queryStateKey} onChange={this.onQueryStateKey}>
402+
{
403+
Object.keys(stateGroup).map((stateKey) => {
404+
const ev = stateGroup[stateKey];
405+
return <button className={classes} key={stateKey} onClick={this.onViewSourceClick(ev)}>
406+
{ stateKey }
407+
</button>;
408+
})
409+
}
410+
</FilteredList>;
383411
}
384412

385413
return <div>
386414
<div className="mx_Dialog_content">
387-
<FilteredList>
388-
{ rows }
389-
</FilteredList>
415+
{ list }
390416
</div>
391417
<div className="mx_Dialog_buttons">
392418
<button onClick={this.onBack}>{ _t('Back') }</button>
@@ -408,11 +434,14 @@ class AccountDataExplorer extends DevtoolsComponent {
408434
this.onBack = this.onBack.bind(this);
409435
this.editEv = this.editEv.bind(this);
410436
this._onChange = this._onChange.bind(this);
437+
this.onQueryEventType = this.onQueryEventType.bind(this);
411438

412439
this.state = {
413440
isRoomAccountData: false,
414441
event: null,
415442
editing: false,
443+
444+
queryEventType: '',
416445
};
417446
}
418447

@@ -448,6 +477,10 @@ class AccountDataExplorer extends DevtoolsComponent {
448477
this.setState({ editing: true });
449478
}
450479

480+
onQueryEventType(queryEventType) {
481+
this.setState({ queryEventType });
482+
}
483+
451484
render() {
452485
if (this.state.event) {
453486
if (this.state.editing) {
@@ -482,7 +515,7 @@ class AccountDataExplorer extends DevtoolsComponent {
482515

483516
return <div>
484517
<div className="mx_Dialog_content">
485-
<FilteredList>
518+
<FilteredList query={this.state.queryEventType} onChange={this.onQueryEventType}>
486519
{ rows }
487520
</FilteredList>
488521
</div>

0 commit comments

Comments
 (0)