@@ 31-89 (lines=59) @@ | ||
28 | }) => { |
|
29 | ||
30 | if (typeof dataSource === 'function') { |
|
31 | ||
32 | return (dispatch) => { |
|
33 | ||
34 | dispatch(dismissEditor({ stateKey })); |
|
35 | ||
36 | dispatch( |
|
37 | setLoaderState({ state: true, stateKey }) |
|
38 | ); |
|
39 | ||
40 | dataSource( |
|
41 | {pageIndex, pageSize}, filterFields, sort |
|
42 | ).then((response) => { |
|
43 | ||
44 | if (response && response.data) { |
|
45 | ||
46 | dispatch({ |
|
47 | type: SET_DATA, |
|
48 | data: response.data, |
|
49 | total: response.total, |
|
50 | currentRecords: response.items, |
|
51 | success: true, |
|
52 | stateKey |
|
53 | }); |
|
54 | ||
55 | if (afterAsyncFunc |
|
56 | && typeof afterAsyncFunc === 'function') { |
|
57 | afterAsyncFunc(); |
|
58 | } |
|
59 | } |
|
60 | ||
61 | else { |
|
62 | ||
63 | if (response && !response.data) { |
|
64 | /* eslint-disable no-console */ |
|
65 | console.warn([ |
|
66 | 'A response was recieved but', |
|
67 | 'no data entry was found' |
|
68 | ].join(' ')); |
|
69 | console.warn([ |
|
70 | 'Please see', |
|
71 | 'https://github.com/bencripps/react-redux-grid', |
|
72 | 'for documentation' |
|
73 | ].join(' ')); |
|
74 | /* eslint-enable no-console */ |
|
75 | } |
|
76 | ||
77 | dispatch({ |
|
78 | type: ERROR_OCCURRED, |
|
79 | error: 'Unable to Retrieve Grid Data', |
|
80 | errorOccurred: true, |
|
81 | stateKey |
|
82 | }); |
|
83 | } |
|
84 | ||
85 | dispatch( |
|
86 | setLoaderState({ state: false, stateKey }) |
|
87 | ); |
|
88 | }); |
|
89 | }; |
|
90 | } |
|
91 | }; |
|
92 |
@@ 237-282 (lines=46) @@ | ||
234 | ||
235 | dispatch( |
|
236 | setLoaderState({state: true, stateKey }) |
|
237 | ); |
|
238 | ||
239 | if (typeof dataSource === 'function') { |
|
240 | return dataSource({}, {}, sortParams).then((response) => { |
|
241 | ||
242 | if (response && response.data) { |
|
243 | ||
244 | dispatch({ |
|
245 | type: SET_DATA, |
|
246 | data: response.data, |
|
247 | total: response.total, |
|
248 | currentRecords: response.data, |
|
249 | success: true, |
|
250 | stateKey |
|
251 | }); |
|
252 | ||
253 | } |
|
254 | ||
255 | else { |
|
256 | ||
257 | if (response && !response.data) { |
|
258 | /* eslint-disable no-console */ |
|
259 | console.warn( |
|
260 | `A response was recieved but no data |
|
261 | entry was found` |
|
262 | ); |
|
263 | console.warn( |
|
264 | `Please see |
|
265 | https://github.com/bencripps/react-redux-grid |
|
266 | for documentation` |
|
267 | ); |
|
268 | /* eslint-enable no-console */ |
|
269 | } |
|
270 | ||
271 | dispatch({ |
|
272 | type: ERROR_OCCURRED, |
|
273 | error: 'Unable to Retrieve Grid Data', |
|
274 | errorOccurred: true, |
|
275 | stateKey |
|
276 | }); |
|
277 | } |
|
278 | ||
279 | dispatch( |
|
280 | setLoaderState({state: false, stateKey }) |
|
281 | ); |
|
282 | }); |
|
283 | ||
284 | } |
|
285 |