[SDC] Onboarding 1710 rebase.
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / licenseModel / entitlementPools / EntitlementPoolsEditorReducer.js
1 /*!
2  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13  * or implied. See the License for the specific language governing
14  * permissions and limitations under the License.
15  */
16 import {actionTypes, defaultState, SP_ENTITLEMENT_POOL_FORM} from './EntitlementPoolsConstants.js';
17 import moment from 'moment';
18 import {DATE_FORMAT} from 'sdc-app/onboarding/OnboardingConstants.js';
19
20 export default (state = {}, action) => {
21         switch (action.type) {
22                 case actionTypes.entitlementPoolsEditor.OPEN:
23                         let entitlementPoolData = {...action.entitlementPool};
24                         let {startDate, expiryDate} = entitlementPoolData;
25                         if (startDate) {
26                                 entitlementPoolData.startDate = moment(startDate, DATE_FORMAT).format(DATE_FORMAT);
27                         }
28                         if (expiryDate) {
29                                 entitlementPoolData.expiryDate = moment(expiryDate, DATE_FORMAT).format(DATE_FORMAT);
30                         }
31                         return {
32                                 ...state,
33                                 formReady: null,
34                                 formName: SP_ENTITLEMENT_POOL_FORM,
35                                 genericFieldInfo: {
36                                         'name' : {
37                                                 isValid: true,
38                                                 errorText: '',
39                                                 validations: [{type: 'required', data: true}, {type: 'maxLength', data: 120}]
40                                         },
41                                         'description' : {
42                                                 isValid: true,
43                                                 errorText: '',
44                                                 validations: [{type: 'required', data: true}, {type: 'maxLength', data: 1000}]
45                                         },
46                                         'manufacturerReferenceNumber' : {
47                                                 isValid: true,
48                                                 errorText: '',
49                                                 validations: [{type: 'required', data: true}, {type: 'maxLength', data: 100}]
50                                         },
51                                         'increments' : {
52                                                 isValid: true,
53                                                 errorText: '',
54                                                 validations: [{type: 'maxLength', data: 120}]
55                                         },
56                                         'operationalScope' : {
57                                                 isValid: true,
58                                                 errorText: '',
59                                                 validations: [{type: 'required', data: true}]
60                                         },
61                                         'thresholdUnits' : {
62                                                 isValid: true,
63                                                 errorText: '',
64                                                 validations: [{type: 'required', data: true}]
65                                         },
66                                         'thresholdValue' : {
67                                                 isValid: true,
68                                                 errorText: '',
69                                                 validations: [{type: 'required', data: true}]
70                                         },
71                                         'entitlementMetric' : {
72                                                 isValid: true,
73                                                 errorText: '',
74                                                 validations: [{type: 'required', data: true}]
75                                         },
76                                         'aggregationFunction' : {
77                                                 isValid: true,
78                                                 errorText: '',
79                                                 validations: [{type: 'required', data: true}]
80                                         },
81                                         'time' : {
82                                                 isValid: true,
83                                                 errorText: '',
84                                                 validations: [{type: 'required', data: true}]
85                                         },
86                                         'startDate': {
87                                                 isValid: true,
88                                                 errorText: '',
89                                                 validations: []
90                                         },
91                                         'expiryDate': {
92                                                 isValid: true,
93                                                 errorText: '',
94                                                 validations: []
95                                         }
96                                 },
97                                 data: action.entitlementPool ? entitlementPoolData : defaultState.ENTITLEMENT_POOLS_EDITOR_DATA
98                         };
99                 case actionTypes.entitlementPoolsEditor.DATA_CHANGED:
100                         return {
101                                 ...state,
102                                 data: {
103                                         ...state.data,
104                                         ...action.deltaData
105                                 }
106                         };
107                 case actionTypes.entitlementPoolsEditor.CLOSE:
108                         return {};
109                 default:
110                         return state;
111         }
112
113 };