Browse Source

Fix clearing endpoint fields while validating

When creating a new endpoint, the input fields would be temporarily
cleared while the endpoint was validating.
Sergiu Miclea 8 years ago
parent
commit
b8d4ea5d74
2 changed files with 9 additions and 7 deletions
  1. 5 5
      src/components/organisms/Endpoint/index.jsx
  2. 4 2
      src/utils/ObjectUtils.js

+ 5 - 5
src/components/organisms/Endpoint/index.jsx

@@ -129,8 +129,8 @@ class Endpoint extends React.Component<Props, State> {
   closeTimeout: TimeoutID
   closeTimeout: TimeoutID
   contentPluginRef: DefaultContentPlugin
   contentPluginRef: DefaultContentPlugin
   isValidateButtonEnabled: boolean
   isValidateButtonEnabled: boolean
-  providerStoreObserver: any
-  endpointStoreObserver: any
+  providerStoreObserver: () => void
+  endpointValidationObserver: () => void
 
 
   constructor() {
   constructor() {
     super()
     super()
@@ -149,7 +149,7 @@ class Endpoint extends React.Component<Props, State> {
     this.providerStoreObserver = observe(ProviderStore, 'connectionInfoSchema', () => {
     this.providerStoreObserver = observe(ProviderStore, 'connectionInfoSchema', () => {
       this.props.onResizeUpdate(this.scrollableRef)
       this.props.onResizeUpdate(this.scrollableRef)
     })
     })
-    this.endpointStoreObserver = observe(EndpointStore, 'validation', () => {
+    this.endpointValidationObserver = observe(EndpointStore, 'validation', () => {
       this.componentWillReceiveProps(this.props)
       this.componentWillReceiveProps(this.props)
     })
     })
   }
   }
@@ -192,7 +192,7 @@ class Endpoint extends React.Component<Props, State> {
     clearTimeout(this.closeTimeout)
     clearTimeout(this.closeTimeout)
     KeyboardManager.removeKeyDown('endpoint')
     KeyboardManager.removeKeyDown('endpoint')
     this.providerStoreObserver()
     this.providerStoreObserver()
-    this.endpointStoreObserver()
+    this.endpointValidationObserver()
   }
   }
 
 
   getEndpointType() {
   getEndpointType() {
@@ -295,7 +295,7 @@ class Endpoint extends React.Component<Props, State> {
 
 
     EndpointStore.add(this.state.endpoint).then(() => {
     EndpointStore.add(this.state.endpoint).then(() => {
       let endpoint = EndpointStore.endpoints[0]
       let endpoint = EndpointStore.endpoints[0]
-      this.setState({ isNew: false, endpoint })
+      this.setState({ isNew: false, endpoint: ObjectUtils.flatten(endpoint) })
       NotificationStore.notify('Validating endpoint ...')
       NotificationStore.notify('Validating endpoint ...')
       EndpointStore.validate(endpoint)
       EndpointStore.validate(endpoint)
     })
     })

+ 4 - 2
src/utils/ObjectUtils.js

@@ -12,8 +12,10 @@ You should have received a copy of the GNU Affero General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 */
 
 
+// @flow
+
 class ObjectUtils {
 class ObjectUtils {
-  static flatten(object) {
+  static flatten(object: any): any {
     let result = {}
     let result = {}
 
 
     Object.keys(object).forEach(k => {
     Object.keys(object).forEach(k => {
@@ -33,7 +35,7 @@ class ObjectUtils {
     return result
     return result
   }
   }
 
 
-  static skipField(object, fieldName) {
+  static skipField(object: any, fieldName: string) {
     let result = {}
     let result = {}
 
 
     if (Object.keys(object).length === 0) {
     if (Object.keys(object).length === 0) {