@imposium-hub/components 1.42.4 → 1.43.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,108 @@
1
+ import batchActions from '../actions/active-batch';
2
+
3
+ const initialState : any = {
4
+ loading: true,
5
+ updating: false,
6
+ associationOptions : {},
7
+ page: 1,
8
+ data: {}
9
+ };
10
+
11
+ const FRESH_COLUMN : any = {
12
+ name: 'New Column',
13
+ type: 'Static',
14
+ from_import: 1,
15
+ detail: null
16
+ };
17
+
18
+ const getNFreshColumns = (state : any) => {
19
+ return state.data.columns.filter((col : any) => (col.name.includes(FRESH_COLUMN.name))).length;
20
+ };
21
+
22
+ const activeBatch = (state = initialState, action) : any => {
23
+ let nFreshCols : number;
24
+ let freshCol : any;
25
+
26
+ switch (action.type) {
27
+ case batchActions.TOGGlE_LOADING:
28
+ return {
29
+ ...state,
30
+ loading: action.toggle
31
+ };
32
+ case batchActions.TOGGLE_UPDATING:
33
+ return {
34
+ ...state,
35
+ updating: action.toggle
36
+ };
37
+ case batchActions.ADD_COLUMN:
38
+ if (typeof action.columnData !== 'undefined') {
39
+ return {
40
+ ...state,
41
+ data: {
42
+ ...state.data,
43
+ columns: [...state.data.columns, action.columnData]
44
+ }
45
+ };
46
+ } else {
47
+ nFreshCols = getNFreshColumns(state);
48
+ if (!nFreshCols) {
49
+ freshCol = {...FRESH_COLUMN};
50
+ } else {
51
+ freshCol = {...FRESH_COLUMN, name: FRESH_COLUMN.name + ` (${nFreshCols})`};
52
+ }
53
+
54
+ return {
55
+ ...state,
56
+ data: {
57
+ ...state.data,
58
+ columns: [...state.data.columns, freshCol]
59
+ }
60
+ }; }
61
+ case batchActions.REPLACE_ASSOCIATION_OPTIONS:
62
+ return {
63
+ ...state,
64
+ associationOptions: {...action.associationOptions}
65
+ };
66
+ case batchActions.UPDATE_ASSOCIATION:
67
+ return {
68
+ ...state,
69
+ data: {
70
+ ...state.data,
71
+ columns: state.data.columns.map((col : any, i : number) => {
72
+ if (action.colIndex === i) {
73
+ if (action.newType === 'Static') {
74
+ return {
75
+ ...col,
76
+ type: action.newType,
77
+ detail: null
78
+ };
79
+ } else {
80
+ return {
81
+ ...col,
82
+ type: action.newType,
83
+ detail: action.newAssociation,
84
+ from_import: (action.newType === 'EGC') ? 0 : 1,
85
+ };
86
+ }
87
+ }
88
+
89
+ return col;
90
+ })
91
+ }
92
+ };
93
+ case batchActions.SET_BATCH:
94
+ return {
95
+ ...state,
96
+ data: {...action.batch}
97
+ };
98
+ case batchActions.SET_PAGE:
99
+ return {
100
+ ...state,
101
+ page: action.page
102
+ };
103
+ default:
104
+ return state;
105
+ }
106
+ };
107
+
108
+ export default activeBatch;