summaryrefslogtreecommitdiffstats
path: root/openecomp-ui/src/sdc-app/common/reducers/PlainDataReducer.js
diff options
context:
space:
mode:
authorEinav Weiss Keidar <einavw@amdocs.com>2018-03-20 14:45:40 +0200
committerAvi Gaffa <avi.gaffa@amdocs.com>2018-03-20 13:52:31 +0000
commit7fdf733a64670fceefc3ded35cfa581e1c458179 (patch)
treeb3623ac9a331473830cb0167c0b487f2a176427c /openecomp-ui/src/sdc-app/common/reducers/PlainDataReducer.js
parentc7916a4e5955ccc5f0f5252307363b791ec5c7b9 (diff)
Adding Prettier and fixing up eslint version
Issue-ID: SDC-1094 Change-Id: Ie83ad95a03899345dd90235daf0323cbe3bc6afd Signed-off-by: Einav Weiss Keidar <einavw@amdocs.com>
Diffstat (limited to 'openecomp-ui/src/sdc-app/common/reducers/PlainDataReducer.js')
-rw-r--r--openecomp-ui/src/sdc-app/common/reducers/PlainDataReducer.js206
1 files changed, 126 insertions, 80 deletions
diff --git a/openecomp-ui/src/sdc-app/common/reducers/PlainDataReducer.js b/openecomp-ui/src/sdc-app/common/reducers/PlainDataReducer.js
index 49f1e3d415..30497704b4 100644
--- a/openecomp-ui/src/sdc-app/common/reducers/PlainDataReducer.js
+++ b/openecomp-ui/src/sdc-app/common/reducers/PlainDataReducer.js
@@ -13,89 +13,135 @@
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
-import {actionTypes} from './PlainDataReducerConstants.js';
+import { actionTypes } from './PlainDataReducerConstants.js';
import Validator from 'nfvo-utils/Validator.js';
import forOwn from 'lodash/forOwn.js';
-import {other as optionInputOther} from 'nfvo-components/input/validation/InputOptions.jsx';
+import { other as optionInputOther } from 'nfvo-components/input/validation/InputOptions.jsx';
function updateDataAndValidateReducer(state = {}, action) {
- let genericFieldInfoCopy;
- switch (action.type) {
- case actionTypes.DATA_CHANGED:
- let changed = action.deltaData;
- if (!action.formName || (state.formName !== action.formName)) {return {...state};}
- genericFieldInfoCopy = {...state.genericFieldInfo};
- forOwn(changed,(value, key) => {
- if (state.genericFieldInfo[key]) {
- let result = Validator.validate(key, value, state.genericFieldInfo[key].validations, state, action.customValidations);
- genericFieldInfoCopy[key] = {...genericFieldInfoCopy[key], isValid: result.isValid, errorText: result.errorText};
- }
- });
- return {
- ...state,
- formReady: null,
- data: {
- ...state.data,
- ...action.deltaData
- },
- genericFieldInfo: genericFieldInfoCopy
- };
- case actionTypes.VALIDATE_FORM:
- if (!action.formName || (state.formName !== action.formName)) {return {...state};}
- genericFieldInfoCopy = {...state.genericFieldInfo};
- let formReady = true;
- forOwn(state.genericFieldInfo,(value, key) => {
- let val = state.data && state.data[key] ? state.data[key] : '';
- let result = Validator.validate(key, val, state.genericFieldInfo[key].validations, state, {});
- if(val.choice !== undefined) {
- result = Validator.validate(key, val.choice, state.genericFieldInfo[key].validations, state, {});
- }
- if(val.choice !== undefined && val.choice === optionInputOther.OTHER) {
- result = Validator.validate(key, val.other, state.genericFieldInfo[key].validations, state, {});
- }
- genericFieldInfoCopy[key] = {...genericFieldInfoCopy[key], isValid: result.isValid, errorText: result.errorText};
- if (!result.isValid) {
- formReady = false;
- }
- });
- return {
- ...state,
- formReady,
- genericFieldInfo: genericFieldInfoCopy
- };
- case actionTypes.VALIDATE_DATA:
- let specificFields = action.data;
- if (!action.formName || (state.formName !== action.formName)) {return {...state};}
- genericFieldInfoCopy = {...state.genericFieldInfo};
- forOwn(specificFields,(value, key) => {
- let result = Validator.validate(key, value, state.genericFieldInfo[key].validations, state, action.customValidations);
- genericFieldInfoCopy[key] = {...genericFieldInfoCopy[key], isValid: result.isValid, errorText: result.errorText};
- });
- return {
- ...state,
- formReady: null,
- genericFieldInfo: genericFieldInfoCopy
- };
- default:
- return state;
- }
-};
+ let genericFieldInfoCopy;
+ switch (action.type) {
+ case actionTypes.DATA_CHANGED:
+ let changed = action.deltaData;
+ if (!action.formName || state.formName !== action.formName) {
+ return { ...state };
+ }
+ genericFieldInfoCopy = { ...state.genericFieldInfo };
+ forOwn(changed, (value, key) => {
+ if (state.genericFieldInfo[key]) {
+ let result = Validator.validate(
+ key,
+ value,
+ state.genericFieldInfo[key].validations,
+ state,
+ action.customValidations
+ );
+ genericFieldInfoCopy[key] = {
+ ...genericFieldInfoCopy[key],
+ isValid: result.isValid,
+ errorText: result.errorText
+ };
+ }
+ });
+ return {
+ ...state,
+ formReady: null,
+ data: {
+ ...state.data,
+ ...action.deltaData
+ },
+ genericFieldInfo: genericFieldInfoCopy
+ };
+ case actionTypes.VALIDATE_FORM:
+ if (!action.formName || state.formName !== action.formName) {
+ return { ...state };
+ }
+ genericFieldInfoCopy = { ...state.genericFieldInfo };
+ let formReady = true;
+ forOwn(state.genericFieldInfo, (value, key) => {
+ let val = state.data && state.data[key] ? state.data[key] : '';
+ let result = Validator.validate(
+ key,
+ val,
+ state.genericFieldInfo[key].validations,
+ state,
+ {}
+ );
+ if (val.choice !== undefined) {
+ result = Validator.validate(
+ key,
+ val.choice,
+ state.genericFieldInfo[key].validations,
+ state,
+ {}
+ );
+ }
+ if (
+ val.choice !== undefined &&
+ val.choice === optionInputOther.OTHER
+ ) {
+ result = Validator.validate(
+ key,
+ val.other,
+ state.genericFieldInfo[key].validations,
+ state,
+ {}
+ );
+ }
+ genericFieldInfoCopy[key] = {
+ ...genericFieldInfoCopy[key],
+ isValid: result.isValid,
+ errorText: result.errorText
+ };
+ if (!result.isValid) {
+ formReady = false;
+ }
+ });
+ return {
+ ...state,
+ formReady,
+ genericFieldInfo: genericFieldInfoCopy
+ };
+ case actionTypes.VALIDATE_DATA:
+ let specificFields = action.data;
+ if (!action.formName || state.formName !== action.formName) {
+ return { ...state };
+ }
+ genericFieldInfoCopy = { ...state.genericFieldInfo };
+ forOwn(specificFields, (value, key) => {
+ let result = Validator.validate(
+ key,
+ value,
+ state.genericFieldInfo[key].validations,
+ state,
+ action.customValidations
+ );
+ genericFieldInfoCopy[key] = {
+ ...genericFieldInfoCopy[key],
+ isValid: result.isValid,
+ errorText: result.errorText
+ };
+ });
+ return {
+ ...state,
+ formReady: null,
+ genericFieldInfo: genericFieldInfoCopy
+ };
+ default:
+ return state;
+ }
+}
export function createPlainDataReducer(loadReducer) {
- return (state = {}, action) => {
- if(action.type === actionTypes.VALIDATE_DATA ||
- action.type === actionTypes.VALIDATE_FORM ||
- action.type === actionTypes.DATA_CHANGED
- ) {
- return updateDataAndValidateReducer(state, action);
- } else {
- return loadReducer(state, action);
- }
- };
-};
-
-
-
-
-
-
+ return (state = {}, action) => {
+ if (
+ action.type === actionTypes.VALIDATE_DATA ||
+ action.type === actionTypes.VALIDATE_FORM ||
+ action.type === actionTypes.DATA_CHANGED
+ ) {
+ return updateDataAndValidateReducer(state, action);
+ } else {
+ return loadReducer(state, action);
+ }
+ };
+}