Skip to content

Commit

Permalink
add defaultSelected(prop) update in DropdownRange and ToggleButton; m…
Browse files Browse the repository at this point in the history
…inor fixes
  • Loading branch information
metagrover committed Jan 3, 2017
1 parent a4fac03 commit e2fcb50
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 10 deletions.
21 changes: 18 additions & 3 deletions app/sensors/MultiDropdownRange.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,39 @@ export class MultiDropdownRange extends Component {
this.state.data = this.props.data.map(item => {
item.value = item.label;
return item;
})
});
this.defaultSelected = this.props.defaultSelected;
this.handleChange = this.handleChange.bind(this);
this.defaultQuery = this.defaultQuery.bind(this);
}

// Set query information
componentDidMount() {
this.setQueryInfo();
if(this.props.defaultSelected) {
if(this.defaultSelected) {
let records = this.state.data.filter((record) => {
return this.props.defaultSelected.indexOf(record.label) > -1 ? true : false;
return this.defaultSelected.indexOf(record.label) > -1 ? true : false;
});
if(records && records.length) {
this.handleChange(records);
}
}
}

componentWillUpdate() {
setTimeout(() => {
if (this.defaultSelected != this.props.defaultSelected) {
this.defaultSelected = this.props.defaultSelected;
let records = this.state.data.filter((record) => {
return this.defaultSelected.indexOf(record.label) > -1 ? true : false;
});
if(records && records.length) {
this.handleChange(records);
}
}
}, 300);
}

// set the query type and input data
setQueryInfo() {
let obj = {
Expand Down
2 changes: 1 addition & 1 deletion app/sensors/Pagination.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {default as React, Component} from 'react';
import classNames from 'classnames';
import { manager } from '../middleware/ChannelManager.js';
var helper = require('../middleware/helper.js');

Expand Down Expand Up @@ -113,7 +114,6 @@ export class Pagination extends Component {
render() {
let title = null;
if(this.props.title) {
titleExists = true;
title = (<h4 className="rbc-title col s12 col-xs-12">{this.props.title}</h4>);
}

Expand Down
19 changes: 17 additions & 2 deletions app/sensors/SingleDropdownRange.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,38 @@ export class SingleDropdownRange extends Component {
selected: null
};
this.type = 'range';
this.defaultSelected = this.props.defaultSelected;
this.handleChange = this.handleChange.bind(this);
this.defaultQuery = this.defaultQuery.bind(this);
}

// Set query information
componentDidMount() {
this.setQueryInfo();
if(this.props.defaultSelected) {
if(this.defaultSelected) {
let records = this.props.data.filter((record) => {
return record.label === this.props.defaultSelected;
return record.label === this.defaultSelected;
});
if(records && records.length) {
this.handleChange(records[0]);
}
}
}

componentWillUpdate() {
setTimeout(() => {
if (this.defaultSelected != this.props.defaultSelected) {
this.defaultSelected = this.props.defaultSelected;
let records = this.props.data.filter((record) => {
return record.label === this.defaultSelected;
});
if(records && records.length) {
this.handleChange(records[0]);
}
}
}, 300);
}

// set the query type and input data
setQueryInfo() {
let obj = {
Expand Down
19 changes: 17 additions & 2 deletions app/sensors/ToggleButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,31 @@ export class ToggleButton extends Component {
selected: []
};
this.type = 'term';
this.defaultSelected = this.props.defaultSelected;
this.handleChange = this.handleChange.bind(this);
this.defaultQuery = this.defaultQuery.bind(this);
}

// Set query information
componentDidMount() {
this.setQueryInfo();
if(this.props.defaultSelected) {
if(this.defaultSelected) {
let records = this.props.data.filter((record) => {
return this.props.defaultSelected.indexOf(record.label) > -1 ? true : false;
return this.defaultSelected.indexOf(record.label) > -1 ? true : false;
});
if(records && records.length) {
records.forEach((singleRecord) => {
this.handleChange(singleRecord);
});
}
}
}

componentWillUpdate() {
if(this.defaultSelected != this.props.defaultSelected) {
this.defaultSelected = this.props.defaultSelected;
let records = this.props.data.filter((record) => {
return this.defaultSelected.indexOf(record.label) > -1 ? true : false;
});
if(records && records.length) {
records.forEach((singleRecord) => {
Expand Down
3 changes: 1 addition & 2 deletions app/stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ storiesOf('ToggleButton', module)
)))
.add('Playground', withReadme(removeFirstLine(ToggleButtonReadme), () => (
<ToggleButtonDefault
title={text('Title', 'Meetup Categories')}
defaultSelected={text('Default Selected', ["Social"])} />
title={text('Title', 'Meetup Categories')} />
)));

storiesOf('TextField', module)
Expand Down

0 comments on commit e2fcb50

Please sign in to comment.