aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2017-11-26 08:25:23 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2017-11-26 11:45:05 +0900
commit256e7372d4a96079b993115eabde8b33d400c7c8 (patch)
tree7644dc397cde50d59fefb139bac8110ed16b3ad0
parent2c46e9d448142c84b802ef8e0e1af53524dc4759 (diff)
settings migration between json and form
-rw-r--r--src/settings/components/form/blacklist-form.jsx2
-rw-r--r--src/settings/components/index.jsx23
2 files changed, 22 insertions, 3 deletions
diff --git a/src/settings/components/form/blacklist-form.jsx b/src/settings/components/form/blacklist-form.jsx
index 9cb547b..4333929 100644
--- a/src/settings/components/form/blacklist-form.jsx
+++ b/src/settings/components/form/blacklist-form.jsx
@@ -34,7 +34,7 @@ class BlacklistForm extends Component {
let name = e.target.name;
let index = e.target.getAttribute('data-index');
- let next = this.props.value.slice();
+ let next = this.props.value ? this.props.value.slice() : [];
if (name === 'url') {
next[index] = e.target.value;
diff --git a/src/settings/components/index.jsx b/src/settings/components/index.jsx
index fb25df6..ae7cd31 100644
--- a/src/settings/components/index.jsx
+++ b/src/settings/components/index.jsx
@@ -6,6 +6,7 @@ import KeymapsForm from './form/keymaps-form';
import BlacklistForm from './form/blacklist-form';
import * as settingActions from 'settings/actions/setting';
import * as validator from 'shared/validators/setting';
+import * as settingsValues from 'shared/settings/values';
class SettingsComponent extends Component {
constructor(props, context) {
@@ -95,7 +96,7 @@ class SettingsComponent extends Component {
label='Use form'
checked={this.state.settings.source === 'form'}
value='form'
- onChange={this.bindValue.bind(this)} />
+ onChange={this.bindSource.bind(this)} />
<Input
type='radio'
@@ -103,7 +104,7 @@ class SettingsComponent extends Component {
label='Use plain JSON'
checked={this.state.settings.source === 'json'}
value='json'
- onChange={this.bindValue.bind(this)} />
+ onChange={this.bindSource.bind(this)} />
{ fields }
</form>
@@ -143,6 +144,24 @@ class SettingsComponent extends Component {
this.setState(next);
this.context.store.dispatch(settingActions.save(next.settings));
}
+
+ bindSource(e) {
+ let from = this.state.settings.source;
+ let to = e.target.value;
+
+ let next = Object.assign({}, this.state);
+ if (from === 'form' && to === 'json') {
+ next.settings.json =
+ settingsValues.jsonFromForm(this.state.settings.form);
+ } else if (from === 'json' && to === 'form') {
+ next.settings.form =
+ settingsValues.formFromJson(this.state.settings.json);
+ }
+ next.settings.source = to;
+
+ this.setState(next);
+ this.context.store.dispatch(settingActions.save(next.settings));
+ }
}
export default SettingsComponent;