disable undo and empty name validation
[sdc/sdc-workflow-designer.git] / workflow-designer-ui / src / main / frontend / src / features / version / inputOutput / inputOutputValidations.js
1 /*
2 * Copyright © 2018 European Support Limited
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 or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 export const getValidationsError = dataRows => {
18     const error = {};
19
20     const groupBy = dataRows.reduce((result, value, key) => {
21         const groupKey = value.name.toLowerCase();
22
23         if (groupKey) {
24             if (result.hasOwnProperty(groupKey)) {
25                 result[groupKey].push(key);
26             } else {
27                 result[groupKey] = [key];
28             }
29         }
30         return result;
31     }, {});
32
33     error.alreadyExists = Object.keys(groupBy).reduce((result, value) => {
34         if (groupBy[value].length > 1) {
35             result = [...result, ...groupBy[value]];
36         }
37
38         return result;
39     }, []);
40
41     error.emptyName = dataRows.reduce((result, value, key) => {
42         const name = value.name;
43
44         if (!name) {
45             result.push(key);
46         }
47
48         return result;
49     }, []);
50
51     error.invalidCharacters = dataRows.reduce((result, value, key) => {
52         const groupKey = value.name;
53
54         if (groupKey) {
55             if (!/^[\w\s\d]+$/.test(groupKey)) {
56                 result.push(key);
57             }
58         }
59
60         return result;
61     }, []);
62
63     return error;
64 };