-
Notifications
You must be signed in to change notification settings - Fork 456
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not store settings structure in config, always get it from plugin object
- Loading branch information
1 parent
3711ea8
commit 6762c00
Showing
12 changed files
with
137 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import config from 'lib/config' | ||
|
||
export default (pluginName) => config.get('plugins')[pluginName] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import get from './get' | ||
import validate from './validate' | ||
|
||
export default { get, validate } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { every } from 'lodash/fp' | ||
|
||
const VALID_TYPES = new Set([ | ||
'array', | ||
'string', | ||
'number', | ||
'bool', | ||
'option', | ||
]) | ||
|
||
const validSetting = ({ type, options }) => { | ||
// General validation of settings | ||
if (!type || !VALID_TYPES.has(type)) return false | ||
|
||
// Type-specific validations | ||
if (type === 'option') return Array.isArray(options) && options.length | ||
|
||
return true | ||
} | ||
|
||
export default ({ settings }) => { | ||
if (!settings) return true | ||
return every(validSetting)(settings) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
app/main/plugins/core/cerebro/settings/Settings/PluginSettings.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import React, { PropTypes, Component } from 'react' | ||
import config from 'lib/config' | ||
import styles from './styles.css' | ||
import SettingsComponent from './components' | ||
|
||
export default class PluginSettings extends Component { | ||
constructor(props) { | ||
super(props) | ||
this.state = { | ||
values: config.get('plugins')[props.name], | ||
} | ||
this.renderSetting = this.renderSetting.bind(this) | ||
this.changeSetting = this.changeSetting.bind(this) | ||
} | ||
|
||
changeSetting(plugin, label, value) { | ||
const values = { | ||
...this.state.values, | ||
[label]: value, | ||
} | ||
|
||
this.setState({ values }) | ||
config.set('plugins', { | ||
...config.get('plugins'), | ||
[this.props.name]: values, | ||
}) | ||
} | ||
|
||
renderSetting(key) { | ||
const setting = this.props.settings[key] | ||
const { defaultValue, label, ...restProps } = setting | ||
const value = key in this.state.values ? this.state.values[key] : defaultValue | ||
|
||
return ( | ||
<SettingsComponent | ||
key={key} | ||
label={label || key} | ||
value={value} | ||
onChange={newValue => this.changeSetting(this.props.name, key, newValue)} | ||
{...restProps} | ||
/> | ||
) | ||
} | ||
|
||
render() { | ||
return ( | ||
<div className={styles.settingItem}> | ||
<label className={styles.header}>Settings</label> | ||
{Object | ||
.keys(this.props.settings) | ||
.map(this.renderSetting)} | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
PluginSettings.propTypes = { | ||
name: PropTypes.string.isRequired, | ||
settings: PropTypes.object.isRequired, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 0 additions & 48 deletions
48
app/main/plugins/core/cerebro/settings/Settings/external-settings.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters