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