From 663e6026fbbf0ce1c1e96d2dd5b46dcda9bb3e06 Mon Sep 17 00:00:00 2001
From: Matthew Shao <me@matshao.com>
Date: Fri, 21 Jul 2017 22:58:20 +0800
Subject: [web] Add default value suggester in option editor.

---
 web/src/js/components/Modal/OptionModal.jsx | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

(limited to 'web/src/js/components/Modal/OptionModal.jsx')

diff --git a/web/src/js/components/Modal/OptionModal.jsx b/web/src/js/components/Modal/OptionModal.jsx
index 5741ee8c..2a95f43b 100644
--- a/web/src/js/components/Modal/OptionModal.jsx
+++ b/web/src/js/components/Modal/OptionModal.jsx
@@ -2,6 +2,7 @@ import React, { Component } from "react"
 import { connect } from "react-redux"
 import * as modalAction from "../../ducks/ui/modal"
 import Option from "./Option"
+import _ from "lodash"
 
 function PureOptionHelp({help}){
     return <div className="help-block small">{help}</div>;
@@ -18,6 +19,31 @@ const OptionError = connect((state, {name}) => ({
     error: state.ui.optionsEditor[name] && state.ui.optionsEditor[name].error
 }))(PureOptionError);
 
+function PureOptionDefault({value, defaultVal}){
+    if( value === defaultVal ) {
+        return null
+    } else {
+        if (typeof(defaultVal) === 'boolean') {
+            defaultVal = defaultVal ? 'true' : 'false'
+        } else if (Array.isArray(defaultVal)){
+            if (_.isEmpty(_.compact(value)) && // filter the empty string in array
+                _.isEmpty(defaultVal)){
+                return null
+            }
+            defaultVal = '[ ]'
+        } else if (defaultVal === ''){
+            defaultVal = '\"\"'
+        } else if (defaultVal === null){
+            defaultVal = 'null'
+        }
+        return <div className="small">Default: <strong> {defaultVal} </strong> </div>
+    }
+}
+const OptionDefault = connect((state, {name}) => ({
+    value: state.options[name].value,
+    defaultVal: state.options[name].default
+}))(PureOptionDefault)
+
 class PureOptionModal extends Component {
 
     constructor(props, context) {
@@ -53,6 +79,7 @@ class PureOptionModal extends Component {
                                     <div className="col-xs-6">
                                         <Option name={name}/>
                                         <OptionError name={name}/>
+                                        <OptionDefault name={name}/>
                                     </div>
                                 </div>
                             )
-- 
cgit v1.2.3


From 93cd1562def9e5c760b1b1f6a552440a83bae383 Mon Sep 17 00:00:00 2001
From: Matthew Shao <me@matshao.com>
Date: Sat, 22 Jul 2017 21:16:16 +0800
Subject: [web] OptionModal component coverge ++.

---
 web/src/js/components/Modal/OptionModal.jsx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'web/src/js/components/Modal/OptionModal.jsx')

diff --git a/web/src/js/components/Modal/OptionModal.jsx b/web/src/js/components/Modal/OptionModal.jsx
index 2a95f43b..35ba3a2e 100644
--- a/web/src/js/components/Modal/OptionModal.jsx
+++ b/web/src/js/components/Modal/OptionModal.jsx
@@ -19,7 +19,7 @@ const OptionError = connect((state, {name}) => ({
     error: state.ui.optionsEditor[name] && state.ui.optionsEditor[name].error
 }))(PureOptionError);
 
-function PureOptionDefault({value, defaultVal}){
+export function PureOptionDefault({value, defaultVal}){
     if( value === defaultVal ) {
         return null
     } else {
-- 
cgit v1.2.3


From 8c3e988a8c95bae7235d5de4ba8e85e77988c395 Mon Sep 17 00:00:00 2001
From: Matthew Shao <me@matshao.com>
Date: Mon, 24 Jul 2017 20:34:15 +0800
Subject: [web] Add Download/Load button to OptionEditor.

---
 web/src/js/components/Modal/OptionModal.jsx | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

(limited to 'web/src/js/components/Modal/OptionModal.jsx')

diff --git a/web/src/js/components/Modal/OptionModal.jsx b/web/src/js/components/Modal/OptionModal.jsx
index 35ba3a2e..6595717d 100644
--- a/web/src/js/components/Modal/OptionModal.jsx
+++ b/web/src/js/components/Modal/OptionModal.jsx
@@ -1,7 +1,9 @@
 import React, { Component } from "react"
 import { connect } from "react-redux"
 import * as modalAction from "../../ducks/ui/modal"
+import * as optionAction from "../../ducks/options"
 import Option from "./Option"
+import FileChooser from '../../components/common/FileChooser'
 import _ from "lodash"
 
 function PureOptionHelp({help}){
@@ -52,7 +54,7 @@ class PureOptionModal extends Component {
     }
 
     render() {
-        const { hideModal, options } = this.props
+        const { hideModal, options, download, upload } = this.props
         const { title } = this.state
         return (
             <div>
@@ -88,6 +90,17 @@ class PureOptionModal extends Component {
                 </div>
 
                 <div className="modal-footer">
+                    <button type="button" className="btn btn-default" onClick={download}>
+                        <i className="fa fa-download"></i>
+                        Download
+                    </button>
+
+                    <FileChooser
+                        icon="fa-upload"
+                        onOpenFile={file => {upload(file); alert('Option configuration loaded!')}}
+                        text="Load"
+                        className="btn btn-primary"
+                    />
                 </div>
             </div>
         )
@@ -100,5 +113,7 @@ export default connect(
     }),
     {
         hideModal: modalAction.hideModal,
+        download: optionAction.download,
+        upload: optionAction.upload,
     }
 )(PureOptionModal)
-- 
cgit v1.2.3


From c7e41b32abba017210ef5c2dc3961554a9b6b9b3 Mon Sep 17 00:00:00 2001
From: Matthew Shao <me@matshao.com>
Date: Wed, 26 Jul 2017 15:09:11 +0800
Subject: [web] Update options auto dump for frontend.

---
 web/src/js/components/Modal/OptionModal.jsx | 18 +++---------------
 1 file changed, 3 insertions(+), 15 deletions(-)

(limited to 'web/src/js/components/Modal/OptionModal.jsx')

diff --git a/web/src/js/components/Modal/OptionModal.jsx b/web/src/js/components/Modal/OptionModal.jsx
index 6595717d..bc25214a 100644
--- a/web/src/js/components/Modal/OptionModal.jsx
+++ b/web/src/js/components/Modal/OptionModal.jsx
@@ -3,7 +3,6 @@ import { connect } from "react-redux"
 import * as modalAction from "../../ducks/ui/modal"
 import * as optionAction from "../../ducks/options"
 import Option from "./Option"
-import FileChooser from '../../components/common/FileChooser'
 import _ from "lodash"
 
 function PureOptionHelp({help}){
@@ -54,13 +53,14 @@ class PureOptionModal extends Component {
     }
 
     render() {
-        const { hideModal, options, download, upload } = this.props
+        const { hideModal, options, dump } = this.props
         const { title } = this.state
         return (
             <div>
                 <div className="modal-header">
                     <button type="button" className="close" data-dismiss="modal" onClick={() => {
                         hideModal()
+                        dump()
                     }}>
                         <i className="fa fa-fw fa-times"></i>
                     </button>
@@ -90,17 +90,6 @@ class PureOptionModal extends Component {
                 </div>
 
                 <div className="modal-footer">
-                    <button type="button" className="btn btn-default" onClick={download}>
-                        <i className="fa fa-download"></i>
-                        Download
-                    </button>
-
-                    <FileChooser
-                        icon="fa-upload"
-                        onOpenFile={file => {upload(file); alert('Option configuration loaded!')}}
-                        text="Load"
-                        className="btn btn-primary"
-                    />
                 </div>
             </div>
         )
@@ -113,7 +102,6 @@ export default connect(
     }),
     {
         hideModal: modalAction.hideModal,
-        download: optionAction.download,
-        upload: optionAction.upload,
+        dump: optionAction.dump,
     }
 )(PureOptionModal)
-- 
cgit v1.2.3


From 7e5f424c5013a591e71f570b003e34f8e6788869 Mon Sep 17 00:00:00 2001
From: Matthew Shao <me@matshao.com>
Date: Thu, 27 Jul 2017 11:22:02 +0800
Subject: [web] Minor fix for frontend and tests.

---
 web/src/js/components/Modal/OptionModal.jsx | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

(limited to 'web/src/js/components/Modal/OptionModal.jsx')

diff --git a/web/src/js/components/Modal/OptionModal.jsx b/web/src/js/components/Modal/OptionModal.jsx
index bc25214a..82ef8350 100644
--- a/web/src/js/components/Modal/OptionModal.jsx
+++ b/web/src/js/components/Modal/OptionModal.jsx
@@ -52,15 +52,18 @@ class PureOptionModal extends Component {
         this.state = { title: 'Options' }
     }
 
+    componentWillUnmount(){
+        this.props.save()
+    }
+
     render() {
-        const { hideModal, options, dump } = this.props
+        const { hideModal, options } = this.props
         const { title } = this.state
         return (
             <div>
                 <div className="modal-header">
                     <button type="button" className="close" data-dismiss="modal" onClick={() => {
                         hideModal()
-                        dump()
                     }}>
                         <i className="fa fa-fw fa-times"></i>
                     </button>
@@ -102,6 +105,6 @@ export default connect(
     }),
     {
         hideModal: modalAction.hideModal,
-        dump: optionAction.dump,
+        save: optionAction.save,
     }
 )(PureOptionModal)
-- 
cgit v1.2.3

