diff --git a/server/services/src/main/java/org/zanata/rest/editor/service/ProjectService.java b/server/services/src/main/java/org/zanata/rest/editor/service/ProjectService.java index 657ae52b69..29de7b9412 100644 --- a/server/services/src/main/java/org/zanata/rest/editor/service/ProjectService.java +++ b/server/services/src/main/java/org/zanata/rest/editor/service/ProjectService.java @@ -19,7 +19,6 @@ import org.zanata.rest.service.ETagUtils; import org.zanata.rest.editor.service.resource.ProjectResource; import org.zanata.service.ValidationService; -import org.zanata.webtrans.shared.model.ProjectIterationId; import org.zanata.webtrans.shared.model.ValidationAction; import org.zanata.webtrans.shared.model.ValidationId; diff --git a/server/zanata-frontend/src/app/editor/components/SettingOption/index.js b/server/zanata-frontend/src/app/editor/components/SettingOption/index.js index 7a6bdab5c1..24f84bf5a4 100644 --- a/server/zanata-frontend/src/app/editor/components/SettingOption/index.js +++ b/server/zanata-frontend/src/app/editor/components/SettingOption/index.js @@ -8,7 +8,8 @@ class SettingOption extends React.Component { label: PropTypes.string.isRequired, active: PropTypes.bool.isRequired, /* arguments: (string: settingId, bool: active) */ - updateSetting: PropTypes.func.isRequired + updateSetting: PropTypes.func.isRequired, + disabled: PropTypes.bool } updateSetting = (event) => { @@ -16,9 +17,10 @@ class SettingOption extends React.Component { } render () { - const { label, active } = this.props + const { label, active, disabled } = this.props return (  {label} diff --git a/server/zanata-frontend/src/app/editor/components/SettingsOptions/index.js b/server/zanata-frontend/src/app/editor/components/SettingsOptions/index.js index 332aa57409..b473b16bb8 100644 --- a/server/zanata-frontend/src/app/editor/components/SettingsOptions/index.js +++ b/server/zanata-frontend/src/app/editor/components/SettingsOptions/index.js @@ -3,11 +3,12 @@ import React from 'react' import * as PropTypes from 'prop-types' import SettingOption from '../SettingOption' -const SettingsOptions = ({settings, updateSetting}) => { +const SettingsOptions = ({settings, updateSetting, disabled}) => { const checkboxes = settings.map((setting, index) => (
  • )) @@ -27,7 +28,8 @@ SettingsOptions.propTypes = { active: PropTypes.bool.isRequired })).isRequired, /* arguments: (string: settingId, bool: active) */ - updateSetting: PropTypes.func.isRequired + updateSetting: PropTypes.func.isRequired, + disabled: PropTypes.bool } export default SettingsOptions diff --git a/server/zanata-frontend/src/app/editor/containers/SettingsPanel.js b/server/zanata-frontend/src/app/editor/containers/SettingsPanel.js index 5f118eda84..f19561a0c9 100644 --- a/server/zanata-frontend/src/app/editor/containers/SettingsPanel.js +++ b/server/zanata-frontend/src/app/editor/containers/SettingsPanel.js @@ -34,6 +34,12 @@ import { PRINTF_XSI_EXTENSION } from '../reducers/settings-reducer' +// Validator error types +// TODO: convert to tuple +export const ERROR = 'Error' +export const WARNING = 'Warning' +export const OFF = 'Off' + export const SettingsPanel = ({ enterSavesImmediately, syntaxHighligting, @@ -50,6 +56,9 @@ export const SettingsPanel = ({ isRTL }) => { const directionClass = isRTL ? 'rtl' : 'ltr' + const validatorChecked = (validator) => { + return (validator === ERROR || validator === WARNING) + } return (

    @@ -83,37 +92,40 @@ export const SettingsPanel = ({ { id: HTML_XML, label: 'HTML/XML tags', - active: validateHtmlXml + active: validatorChecked(validateHtmlXml), + disabled: validateHtmlXml === ERROR }, { id: JAVA_VARIABLES, label: 'Java variables', - active: validateJavaVariables + active: validatorChecked(validateJavaVariables), + disabled: validateJavaVariables === ERROR }, { id: NEW_LINE, label: 'Leading/trailing newline (\\n)', - active: validateNewLine + active: validatorChecked(validateNewLine), + disabled: validateNewLine === ERROR }, { id: PRINTF_XSI_EXTENSION, label: 'Positional printf (XSI extention)', - active: validatePrintfXsi + active: validatorChecked(validatePrintfXsi) }, { id: PRINTF_VARIABLES, label: 'Printf variables', - active: validatePrintfVariables + active: validatorChecked(validatePrintfVariables) }, { id: TAB, label: 'Tab characters (\\t)', - active: validateTab + active: validatorChecked(validateTab) }, { id: XML_ENTITY, label: 'XML entity reference', - active: validateXmlEntity + active: validatorChecked(validateXmlEntity) } ]} updateSetting={updateValidationSetting} /> @@ -126,13 +138,13 @@ export const SettingsPanel = ({ SettingsPanel.propTypes = { enterSavesImmediately: PropTypes.bool.isRequired, syntaxHighligting: PropTypes.bool.isRequired, - validateHtmlXml: PropTypes.bool.isRequired, - validateNewLine: PropTypes.bool.isRequired, - validateTab: PropTypes.bool.isRequired, - validateJavaVariables: PropTypes.bool.isRequired, - validateXmlEntity: PropTypes.bool.isRequired, - validatePrintfVariables: PropTypes.bool.isRequired, - validatePrintfXsi: PropTypes.bool.isRequired, + validateHtmlXml: PropTypes.string.isRequired, + validateNewLine: PropTypes.string.isRequired, + validateTab: PropTypes.string.isRequired, + validateJavaVariables: PropTypes.string.isRequired, + validateXmlEntity: PropTypes.string.isRequired, + validatePrintfVariables: PropTypes.string.isRequired, + validatePrintfXsi: PropTypes.string.isRequired, hideSettings: PropTypes.func.isRequired, updateSetting: PropTypes.func.isRequired, updateValidationSetting: PropTypes.func.isRequired, diff --git a/server/zanata-frontend/src/app/editor/reducers/settings-reducer.js b/server/zanata-frontend/src/app/editor/reducers/settings-reducer.js index 1c8992242c..380e251d70 100644 --- a/server/zanata-frontend/src/app/editor/reducers/settings-reducer.js +++ b/server/zanata-frontend/src/app/editor/reducers/settings-reducer.js @@ -10,7 +10,8 @@ import { SETTING_UPDATE, SETTINGS_SAVE_REQUEST, SETTINGS_SAVE_SUCCESS, - SETTINGS_SAVE_FAILURE + SETTINGS_SAVE_FAILURE, + VALIDATORS_SUCCESS } from '../actions/settings-action-types' import { SHORTCUTS } from '../actions/key-shortcuts-actions' @@ -20,13 +21,13 @@ export const SUGGESTIONS_DIFF = 'suggestions-diff' export const KEY_SUGGESTIONS_VISIBLE = 'suggestions-visible' /* Validation Options */ -export const HTML_XML = 'html-xml-tags' -export const NEW_LINE = 'leading-trailing-newline' -export const TAB = 'tab-characters' -export const JAVA_VARIABLES = 'java-variables' -export const XML_ENTITY = 'xml-entity-reference' -export const PRINTF_VARIABLES = 'printf-variables' -export const PRINTF_XSI_EXTENSION = 'positional-printf-xsi' +export const HTML_XML = 'HTML_XML' +export const NEW_LINE = 'NEW_LINE' +export const TAB = 'TAB' +export const JAVA_VARIABLES = 'JAVA_VARIABLES' +export const XML_ENTITY = 'XML_ENTITY' +export const PRINTF_VARIABLES = 'PRINTF_VARIABLES' +export const PRINTF_XSI_EXTENSION = 'PRINTF_XSI_EXTENSION' /* Parse values of known settings to appropriate types */ function parseKnownSettings (settings) { @@ -58,6 +59,9 @@ function parseKnownSettings (settings) { /* convenience function to construct an empty setting body */ const newSetting = value => ({ value, saving: false, error: undefined }) +// Default validator value: one of ['Error','Warning','Off'] +export const defaultValidation = 'Off' + export const defaultState = { // state for all settings being requested on app load fetching: false, @@ -72,13 +76,13 @@ export const defaultState = { [SUGGESTIONS_DIFF]: newSetting(true), [KEY_SUGGESTIONS_VISIBLE]: newSetting(true), // Validator options disabled by default - [HTML_XML]: newSetting(false), - [NEW_LINE]: newSetting(false), - [TAB]: newSetting(false), - [JAVA_VARIABLES]: newSetting(false), - [XML_ENTITY]: newSetting(false), - [PRINTF_VARIABLES]: newSetting(false), - [PRINTF_XSI_EXTENSION]: newSetting(false) + [HTML_XML]: newSetting(defaultValidation), + [NEW_LINE]: newSetting(defaultValidation), + [TAB]: newSetting(defaultValidation), + [JAVA_VARIABLES]: newSetting(defaultValidation), + [XML_ENTITY]: newSetting(defaultValidation), + [PRINTF_VARIABLES]: newSetting(defaultValidation), + [PRINTF_XSI_EXTENSION]: newSetting(defaultValidation) } } @@ -160,6 +164,18 @@ export default handleActions({ } }) }, + [VALIDATORS_SUCCESS]: (state, { payload }) => { + const defined = keys(state.settings) + const parsed = parseKnownSettings(payload) + const updates = mapValues(pick(parsed, defined), + value => ({ value: {$set: value} })) + return update(state, { + fetching: {$set: false}, + settings: { + ...updates + } + }) + }, [SETTINGS_FAILURE]: (state, { payload }) => update(state, { fetching: {$set: false}, error: {$set: payload}