From ea76e7ede7b4470f6d16b18a7e791c437661c605 Mon Sep 17 00:00:00 2001 From: Malar Kannan Date: Mon, 31 Jul 2017 17:41:42 +0530 Subject: [PATCH] implemented morphexceptions value as stateless --- src/LexInputContainer.tsx | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/src/LexInputContainer.tsx b/src/LexInputContainer.tsx index 9552257..69b2077 100644 --- a/src/LexInputContainer.tsx +++ b/src/LexInputContainer.tsx @@ -138,9 +138,7 @@ function propListInput(params: any) { class PropListInput extends React.Component { 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 { } 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 { }; let dropDownComp = ( { 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); }