From 05e7910e1a3f497b9bdb7c7d45652795fe3d00ad Mon Sep 17 00:00:00 2001 From: Justin Ball Date: Mon, 9 Jan 2017 14:03:27 -0700 Subject: [PATCH 1/2] Adds code to indicate the last page of data has been encountered --- client/js/libs/canvas/middleware.js | 5 +++++ client/js/libs/urls.js | 2 ++ 2 files changed, 7 insertions(+) diff --git a/client/js/libs/canvas/middleware.js b/client/js/libs/canvas/middleware.js index a99fb4e57..b4e715813 100644 --- a/client/js/libs/canvas/middleware.js +++ b/client/js/libs/canvas/middleware.js @@ -36,6 +36,8 @@ function proxyCanvas(store, action, params){ action.body ).then((response, error) => { + let lastPage = false; + if(action.canvas.method == "get" && response.header){ const nextUrl = getNextUrl(response.headers['link']); if(nextUrl){ @@ -43,6 +45,8 @@ function proxyCanvas(store, action, params){ if(params){ proxyCanvas(store, action, params); } + } else { + lastPage = true; } } @@ -50,6 +54,7 @@ function proxyCanvas(store, action, params){ type: action.canvas.type + DONE, payload: response.body, original: action, + lastPage, response, error }); // Dispatch the new data diff --git a/client/js/libs/urls.js b/client/js/libs/urls.js index ac3138abc..cee001928 100644 --- a/client/js/libs/urls.js +++ b/client/js/libs/urls.js @@ -7,6 +7,8 @@ export function getNextUrl(link){ }); if(url){ return url.split(';')[0].replace(/[\<\>\s]/g, ""); + } else { + return null; } } } From 142310c753845f7cc5fc408eb51862049ead20d8 Mon Sep 17 00:00:00 2001 From: Justin Ball Date: Mon, 9 Jan 2017 14:44:59 -0700 Subject: [PATCH 2/2] Fixes for linter --- client/js/libs/canvas/middleware.js | 46 +++++++++++++---------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/client/js/libs/canvas/middleware.js b/client/js/libs/canvas/middleware.js index b4e715813..1f1da96cb 100644 --- a/client/js/libs/canvas/middleware.js +++ b/client/js/libs/canvas/middleware.js @@ -1,22 +1,20 @@ -import _ from "lodash"; -import api from "../api"; -import Network from "../../constants/network"; -import { DONE } from "../../constants/wrapper"; -import { getNextUrl, parseParams } from "../urls"; +import _ from 'lodash'; +import api from '../api'; +import { DONE } from '../../constants/wrapper'; +import { getNextUrl, parseParams } from '../urls'; -const canvasProxyUrl = "api/canvas"; +const canvasProxyUrl = 'api/canvas'; -function checkRequired(action){ - if(action.canvas.required.length > 0){ +function checkRequired(action) { + if (action.canvas.required.length > 0) { const missing = _.difference(action.canvas.required, _.keys(action.params)); - if(missing.length > 0){ + if (missing.length > 0) { throw `Missing required parameter(s): ${missing.join(", ")}`; } } } -function proxyCanvas(store, action, params){ - +function proxyCanvas(store, action, params) { const state = store.getState(); checkRequired(action); @@ -35,15 +33,14 @@ function proxyCanvas(store, action, params){ }, action.body ).then((response, error) => { - let lastPage = false; - if(action.canvas.method == "get" && response.header){ - const nextUrl = getNextUrl(response.headers['link']); - if(nextUrl){ - const params = parseParams(nextUrl); - if(params){ - proxyCanvas(store, action, params); + if (action.canvas.method === 'get' && response.header) { + const nextUrl = getNextUrl(response.headers.link); + if (nextUrl) { + const newParams = parseParams(nextUrl); + if (newParams) { + proxyCanvas(store, action, newParams); } } else { lastPage = true; @@ -51,26 +48,23 @@ function proxyCanvas(store, action, params){ } store.dispatch({ - type: action.canvas.type + DONE, - payload: response.body, + type: action.canvas.type + DONE, + payload: response.body, original: action, lastPage, response, error }); // Dispatch the new data }); - } -const CanvasApi = store => next => action => { - - if(action.canvas){ +const CanvasApi = store => next => (action) => { + if (action.canvas) { proxyCanvas(store, action, {}); } // call the next middleWare next(action); - }; -export { CanvasApi as default }; \ No newline at end of file +export { CanvasApi as default };