| @@ 30-96 (lines=67) @@ | ||
| 27 | afterAsyncFunc |
|
| 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: PAGE_REMOTE, |
|
| 48 | pageIndex: pageIndex, |
|
| 49 | stateKey |
|
| 50 | }); |
|
| 51 | ||
| 52 | dispatch({ |
|
| 53 | type: SET_DATA, |
|
| 54 | data: response.data, |
|
| 55 | total: response.total, |
|
| 56 | currentRecords: response.items, |
|
| 57 | success: true, |
|
| 58 | stateKey |
|
| 59 | }); |
|
| 60 | ||
| 61 | if (afterAsyncFunc |
|
| 62 | && typeof afterAsyncFunc === 'function') { |
|
| 63 | afterAsyncFunc(); |
|
| 64 | } |
|
| 65 | } |
|
| 66 | ||
| 67 | else { |
|
| 68 | ||
| 69 | if (response && !response.data) { |
|
| 70 | /* eslint-disable no-console */ |
|
| 71 | console.warn([ |
|
| 72 | 'A response was recieved but', |
|
| 73 | 'no data entry was found' |
|
| 74 | ].join(' ')); |
|
| 75 | console.warn([ |
|
| 76 | 'Please see', |
|
| 77 | 'https://github.com/bencripps/react-redux-grid', |
|
| 78 | 'for documentation' |
|
| 79 | ].join(' ')); |
|
| 80 | /* eslint-enable no-console */ |
|
| 81 | } |
|
| 82 | ||
| 83 | dispatch({ |
|
| 84 | type: ERROR_OCCURRED, |
|
| 85 | error: 'Unable to Retrieve Grid Data', |
|
| 86 | errorOccurred: true, |
|
| 87 | stateKey |
|
| 88 | }); |
|
| 89 | } |
|
| 90 | ||
| 91 | dispatch( |
|
| 92 | setLoaderState({ state: false, stateKey }) |
|
| 93 | ); |
|
| 94 | }); |
|
| 95 | }; |
|
| 96 | } |
|
| 97 | }; |
|
| 98 | ||
| 99 | export const setPageAsync = ({ |
|
| @@ 240-289 (lines=50) @@ | ||
| 237 | dispatch( |
|
| 238 | setLoaderState({state: true, stateKey }) |
|
| 239 | ); |
|
| 240 | ||
| 241 | if (typeof dataSource === 'function') { |
|
| 242 | return dataSource( |
|
| 243 | { pageIndex, pageSize }, |
|
| 244 | filterFields, |
|
| 245 | sortParams |
|
| 246 | ).then((response) => { |
|
| 247 | ||
| 248 | if (response && response.data) { |
|
| 249 | ||
| 250 | dispatch({ |
|
| 251 | type: SET_DATA, |
|
| 252 | data: response.data, |
|
| 253 | total: response.total, |
|
| 254 | currentRecords: response.data, |
|
| 255 | success: true, |
|
| 256 | stateKey |
|
| 257 | }); |
|
| 258 | ||
| 259 | } |
|
| 260 | ||
| 261 | else { |
|
| 262 | ||
| 263 | if (response && !response.data) { |
|
| 264 | /* eslint-disable no-console */ |
|
| 265 | console.warn( |
|
| 266 | `A response was recieved but no data |
|
| 267 | entry was found` |
|
| 268 | ); |
|
| 269 | console.warn( |
|
| 270 | `Please see |
|
| 271 | https://github.com/bencripps/react-redux-grid |
|
| 272 | for documentation` |
|
| 273 | ); |
|
| 274 | /* eslint-enable no-console */ |
|
| 275 | } |
|
| 276 | ||
| 277 | dispatch({ |
|
| 278 | type: ERROR_OCCURRED, |
|
| 279 | error: 'Unable to Retrieve Grid Data', |
|
| 280 | errorOccurred: true, |
|
| 281 | stateKey |
|
| 282 | }); |
|
| 283 | } |
|
| 284 | ||
| 285 | dispatch( |
|
| 286 | setLoaderState({state: false, stateKey }) |
|
| 287 | ); |
|
| 288 | }); |
|
| 289 | ||
| 290 | } |
|
| 291 | ||
| 292 | return Api({ |
|