implemented morphexceptions value as stateless

master
Malar Kannan 2017-07-31 17:41:42 +05:30
parent c0eedb4555
commit ea76e7ede7
1 changed files with 8 additions and 22 deletions

View File

@ -138,9 +138,7 @@ function propListInput(params: any) {
class PropListInput extends React.Component<any, any> {
constructor(props: any) {
super(props);
let { value } = this.props.params;
let dropOptions = this.dropOptsForVal(value);
this.state = { value, dropOptions, modalOpen: false, exKey: '', exVal: '' };
this.state = { modalOpen: false, exKey: '', exVal: '' };
}
dropOptsForVal(value: any) {
@ -164,21 +162,15 @@ class PropListInput extends React.Component<any, any> {
}
public render() {
let { sh } = this.props.params;
let { sh, value } = this.props.params;
let dropOptions = this.dropOptsForVal(value);
let renderLabel = (label: any) => ({
content: `${label.value.key}-${label.value.value}`,
});
let value = _.filter(this.state.dropOptions, (o: any) => {
return _.some(this.state.value, (v: any) => {
return _.isEqual(v.key, o.value.key);
});
}).map((so) => so.value);
let onCloseModal = (e: any) => {
let except = { key: this.state.exKey, value: this.state.exVal };
let ns = _.concat(this.state.value, except);
let ns = _.concat(value, except);
this.setState({
dropOptions: this.dropOptsForVal(ns),
value: ns,
modalOpen: false,
exKey: '',
exVal: ''
@ -187,19 +179,13 @@ class PropListInput extends React.Component<any, any> {
};
let dropDownComp = (
<Dropdown
options={this.state.dropOptions}
options={dropOptions}
onChange={(e, d) => {
let newValue = d.value as any;
let addedValue = _.difference(newValue, this.state.value) as any;
console.log('added: ', addedValue);
let addedValue = _.difference(newValue, value) as any;
let didAdd = _.size(addedValue) > 0;
let newState = didAdd ? {
exKey: addedValue[0].key,
} : {
exKey: '',
value: newValue
} as any;
this.setState({ ...newState, modalOpen: didAdd });
let exKey = didAdd ? addedValue[0].key : '';
this.setState({ exKey, modalOpen: didAdd });
if (!didAdd) {
sh(newValue);
}