@@ 210-240 (lines=31) @@ | ||
207 | }, DataSource, 'mergeIn'); |
|
208 | }; |
|
209 | ||
210 | export const setTreeNodeVisibility = (state, { |
|
211 | id, showTreeRootNode, stateKey |
|
212 | }) => { |
|
213 | ||
214 | const flat = state.getIn([stateKey, 'data']); |
|
215 | const tree = state.getIn([stateKey, 'treeData']); |
|
216 | ||
217 | const currentVisibility = !!flat |
|
218 | .find(node => node.get('_id') === id).get('_hideChildren'); |
|
219 | ||
220 | const path = [-1, ...getTreePathFromId(flat, id)]; |
|
221 | ||
222 | const updatedTree = setTreeValue( |
|
223 | tree, path, { _hideChildren: !currentVisibility } |
|
224 | ); |
|
225 | ||
226 | let updatedList = treeToFlatList(updatedTree); |
|
227 | ||
228 | // remove root-node |
|
229 | if (!showTreeRootNode) { |
|
230 | updatedList = updatedList.shift(); |
|
231 | } |
|
232 | ||
233 | return getUpdatedRecord(state, stateKey, { |
|
234 | data: updatedList, |
|
235 | currentRecords: updatedList, |
|
236 | treeData: updatedTree, |
|
237 | proxy: updatedList, |
|
238 | lastUpdate: generateLastUpdate() |
|
239 | }, DataSource, 'mergeIn'); |
|
240 | }; |
|
241 | ||
242 | export const saveRow = (state, { rowIndex, stateKey, values }) => { |
|
243 | const data = state |
|
@@ 37-64 (lines=28) @@ | ||
34 | }, DataSource); |
|
35 | }; |
|
36 | ||
37 | export const setPartialTreeData = (state, { |
|
38 | data, parentId, showTreeRootNode, stateKey, total |
|
39 | }) => { |
|
40 | ||
41 | const tree = state.getIn([stateKey, 'treeData']); |
|
42 | const flat = state.getIn([stateKey, 'data']); |
|
43 | const pathToNode = [ |
|
44 | -1, ...getTreePathFromId(flat, parentId) |
|
45 | ]; |
|
46 | const updatedTree = setTreeValue( |
|
47 | tree, pathToNode, { children: data } |
|
48 | ); |
|
49 | ||
50 | let updatedFlat = treeToFlatList(updatedTree); |
|
51 | ||
52 | if (!showTreeRootNode) { |
|
53 | updatedFlat = updatedFlat.shift(); |
|
54 | } |
|
55 | ||
56 | return getUpdatedRecord(state, stateKey, { |
|
57 | data: updatedFlat, |
|
58 | currentRecords: updatedFlat, |
|
59 | treeData: updatedTree, |
|
60 | proxy: updatedFlat, |
|
61 | total: total || updatedFlat.count(), |
|
62 | lastUpdate: generateLastUpdate() |
|
63 | }, DataSource, 'mergeIn'); |
|
64 | }; |
|
65 | ||
66 | export const dismissEditor = (state, { stateKey }) => { |
|
67 | const previousData = state.getIn([stateKey, 'data']); |