1
|
|
|
import { |
2
|
|
|
ADD_NEW_ROW, |
3
|
|
|
CANCEL_ROW, |
4
|
|
|
DISMISS_EDITOR, |
5
|
|
|
EDIT_ROW, |
6
|
|
|
EDITOR_VALIDATION, |
7
|
|
|
ROW_VALUE_CHANGE, |
8
|
|
|
REMOVE_ROW, |
9
|
|
|
REPOSITION_EDITOR, |
10
|
|
|
SAVE_ROW, |
11
|
|
|
UPDATE_ROW |
12
|
|
|
} from '../../../constants/ActionTypes'; |
13
|
|
|
|
14
|
|
|
import { keyGenerator } from '../../../util/keyGenerator'; |
15
|
|
|
|
16
|
|
|
export const editRow = ({ |
17
|
|
|
rowId, |
18
|
|
|
top, |
19
|
|
|
rowData = {}, |
20
|
|
|
rowIndex, |
21
|
|
|
columns, |
22
|
|
|
isCreate, |
23
|
|
|
stateKey, |
24
|
|
|
editMode = 'inline' |
25
|
|
|
}) => { |
26
|
|
|
|
27
|
|
|
if (!rowId) { |
28
|
|
|
throw new Error('rowId is a required parameter for editRow Action'); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
return { |
32
|
|
|
type: EDIT_ROW, |
33
|
|
|
rowId, |
34
|
|
|
top, |
35
|
|
|
values: rowData, |
36
|
|
|
rowIndex, |
37
|
|
|
columns, |
38
|
|
|
isCreate, |
39
|
|
|
stateKey, |
40
|
|
|
editMode |
41
|
|
|
}; |
42
|
|
|
}; |
43
|
|
|
|
44
|
|
|
export const repositionEditor = ({ top, stateKey, rowId }) => ({ |
45
|
|
|
type: REPOSITION_EDITOR, |
46
|
|
|
rowId, |
47
|
|
|
stateKey, |
48
|
|
|
top |
49
|
|
|
}); |
50
|
|
|
|
51
|
|
|
export const dismissEditor = ({ stateKey }) => ({ |
52
|
|
|
type: DISMISS_EDITOR, stateKey |
53
|
|
|
}); |
54
|
|
|
|
55
|
|
|
export const updateCellValue = ({ |
56
|
|
|
value, name, column, columns, stateKey, rowId |
57
|
|
|
}) => ({ |
58
|
|
|
type: ROW_VALUE_CHANGE, |
59
|
|
|
value, |
60
|
|
|
columnName: name, |
61
|
|
|
column, |
62
|
|
|
columns, |
63
|
|
|
stateKey, |
64
|
|
|
rowId |
65
|
|
|
}); |
66
|
|
|
|
67
|
|
|
export const saveRow = ({ values, rowIndex, stateKey }) => ({ |
68
|
|
|
type: SAVE_ROW, values, rowIndex, stateKey |
69
|
|
|
}); |
70
|
|
|
|
71
|
|
|
export const cancelRow = ({ stateKey }) => ({ |
72
|
|
|
type: CANCEL_ROW, stateKey |
73
|
|
|
}); |
74
|
|
|
|
75
|
|
|
export const removeRow = ({ rowIndex, stateKey }) => ({ |
76
|
|
|
type: REMOVE_ROW, rowIndex, stateKey |
77
|
|
|
}); |
78
|
|
|
|
79
|
|
|
export const setEditorValidation = ({ validationState, stateKey }) => ({ |
80
|
|
|
type: EDITOR_VALIDATION, validationState, stateKey |
81
|
|
|
}); |
82
|
|
|
|
83
|
|
|
export const updateRow = ({ stateKey, rowIndex, values }) => ({ |
84
|
|
|
type: UPDATE_ROW, |
85
|
|
|
stateKey, |
86
|
|
|
rowIndex, |
87
|
|
|
values |
88
|
|
|
}); |
89
|
|
|
|
90
|
|
|
export const addNewRow = ({ |
91
|
|
|
columns, data, stateKey, editMode = 'inline' |
92
|
|
|
}) => (dispatch) => { |
93
|
|
|
const rowId = keyGenerator('row', 0); |
94
|
|
|
const top = 43; |
95
|
|
|
const rowData = data || {}; |
96
|
|
|
const rowIndex = 0; |
97
|
|
|
const isCreate = true; |
98
|
|
|
|
99
|
|
|
dispatch({ type: ADD_NEW_ROW, stateKey, rowId }); |
100
|
|
|
|
101
|
|
|
dispatch( |
102
|
|
|
editRow({ |
103
|
|
|
rowId, |
104
|
|
|
top, |
105
|
|
|
rowData, |
106
|
|
|
rowIndex, |
107
|
|
|
columns, |
108
|
|
|
isCreate, |
109
|
|
|
stateKey, |
110
|
|
|
editMode |
111
|
|
|
}) |
112
|
|
|
); |
113
|
|
|
}; |
114
|
|
|
|