return this.props
.resetValue(definition.key, componentKey)
.then(() => {
- this.props.changeValue(definition.key, definition.defaultValue);
+ this.props.cancelChange(definition.key, componentKey);
this.safeSetState({ success: true, hasError: false });
this.timeout = setTimeout(() => this.safeSetState({ success: false }), 3000);
})
};
handleCheck = () => {
- this.safeSetState({ success: false });
const componentKey = this.props.component ? this.props.component.key : null;
- if (this.props.checkValue(this.props.setting.definition.key, componentKey)) {
- this.safeSetState({ hasError: false });
- } else {
- this.safeSetState({ hasError: true });
- }
+ const hasError = !this.props.checkValue(this.props.setting.definition.key, componentKey);
+ this.safeSetState({ hasError });
};
handleSave = () => {
)}
{!loading &&
+ this.props.validationMessage == null &&
this.state.success && (
<span className="text-success">
<AlertSuccessIcon className="spacer-right" />
/>
)}
- {hasValueChanged &&
- !hasError && (
- <DefinitionChanges onCancel={this.handleCancel} onSave={this.handleSave} />
- )}
+ {hasValueChanged && (
+ <DefinitionChanges
+ enableSave={!hasError}
+ onCancel={this.handleCancel}
+ onSave={this.handleSave}
+ />
+ )}
</div>
</div>
);
import PropTypes from 'prop-types';
import { translate } from '../../../helpers/l10n';
+/*::
+type Props = {
+ enableSave: boolean
+};
+*/
+
export default class DefinitionChanges extends React.PureComponent {
static propTypes = {
onSave: PropTypes.func.isRequired,
render() {
return (
<div className="settings-definition-changes">
- <button className="js-save-changes button-success" onClick={e => this.handleSaveClick(e)}>
- {translate('save')}
- </button>
-
+ {this.props.enableSave && (
+ <button className="js-save-changes button-success" onClick={e => this.handleSaveClick(e)}>
+ {translate('save')}
+ </button>
+ )}
<button
className="js-cancel-changes big-spacer-left button-link"
onClick={e => this.handleCancelChange(e)}>
export function getDefaultValue(setting) {
const parentValue = getParentValue(setting);
- if (parentValue === undefined) {
- return setting.value;
- }
-
if (parentValue == null) {
- return translate('settings.default.no_value');
+ return setting.definition.defaultValue
+ ? setting.definition.defaultValue
+ : translate('settings.default.no_value');
}
if (setting.definition.multiValues) {