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