import React from 'react'; import PropTypes from 'prop-types'; import _ from 'underscore'; import _str from 'underscore.string'; import { ConfigLike, ConfigSchemaLike } from '../types'; /* This component renders input controls for a subtree of the Mailspring config-schema and reads/writes current values using the `config` prop, which is expected to be an instance of the config provided by `ConfigPropContainer`. The config schema follows the JSON Schema standard: http://json-schema.org/ */ interface ConfigSchemaItemProps { keyName?: string; keyPath: string; config: ConfigLike; configSchema: ConfigSchemaLike; } class ConfigSchemaItem extends React.Component { static displayName = 'ConfigSchemaItem'; static propTypes = { config: PropTypes.object, configSchema: PropTypes.object, keyName: PropTypes.string, keyPath: PropTypes.string, }; _appliesToPlatform() { if (!this.props.configSchema.platform) { return true; } else if (this.props.configSchema.platforms.indexOf(process.platform) !== -1) { return true; } return false; } _onChangeChecked = event => { this.props.config.toggle(this.props.keyPath); event.target.blur(); }; _onChangeValue = event => { this.props.config.set(this.props.keyPath, event.target.value); event.target.blur(); }; render() { if (!this._appliesToPlatform()) return false; // In the future, we may add an option to reveal "advanced settings" if (this.props.configSchema.advanced) return false; let note = this.props.configSchema.note ? (
{this.props.configSchema.note}
) : null; if (this.props.configSchema.type === 'object') { return (
{_str.humanize(this.props.keyName)}
{Object.entries(this.props.configSchema.properties).map(([key, value]) => ( ))} {note}
); } else if (this.props.configSchema.enum) { return (
{note}
); } else if (this.props.configSchema.type === 'boolean') { return (
{note}
); } return ; } } export default ConfigSchemaItem;