From c59c944a7835dc72b5bfd877c9df52a94231256d Mon Sep 17 00:00:00 2001 From: Tom Cooling Date: Wed, 31 Jan 2018 13:54:55 +0000 Subject: [PATCH 01/10] Remove unused onChange method from auth.js --- src/utils/auth.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/utils/auth.js b/src/utils/auth.js index c553d2a..a7d0098 100644 --- a/src/utils/auth.js +++ b/src/utils/auth.js @@ -83,7 +83,6 @@ const auth = { callback(true); }); }, - onChange() {}, }; module.exports = auth; From fd8a012e9f8cee6fd3b1d83179d7c64f77279e74 Mon Sep 17 00:00:00 2001 From: Tom Cooling Date: Wed, 31 Jan 2018 15:26:21 +0000 Subject: [PATCH 02/10] Add refactored fetch usage for searching - Add accessAPI which is basically a helper to preset some commonly used config for fetch --- src/actions/ApiActions.js | 11 +++++++++-- src/utils/accessAPI.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 src/utils/accessAPI.js diff --git a/src/actions/ApiActions.js b/src/actions/ApiActions.js index 5b82916..0e11c45 100644 --- a/src/actions/ApiActions.js +++ b/src/actions/ApiActions.js @@ -1,5 +1,8 @@ import { SET_RESULTS, SET_FORMATTED_QUERY, SET_SEARCH_ERROR_MESSAGE, SENDING_SEARCH_REQUEST, SET_QUERY, SET_HEADERS } from '../constants/ApiConstants'; -import apiSearch from '../utils/apiSearch'; +import { accessAPI } from '../utils/accessAPI'; +import config from '../config/api-urls'; + +const { REROUTE_URL, API_VERSION } = config; // The search action creator can be used for Match/Range/UBRN searches export function search(query, formQuery, jsonKey) { @@ -10,7 +13,11 @@ export function search(query, formQuery, jsonKey) { dispatch(setQuery(SET_QUERY, query, jsonKey)); const formattedQuery = formQuery(query); dispatch(setFormattedQuery(SET_FORMATTED_QUERY, formattedQuery, jsonKey)); - apiSearch.search(formattedQuery, (success, data) => { + + accessAPI(REROUTE_URL, 'POST', sessionStorage.getItem('accessToken'), JSON.stringify({ + method: 'GET', + endpoint: `${API_VERSION}/${formattedQuery}`, + }), (success, data) => { dispatch(sendingRequest(SENDING_SEARCH_REQUEST, false, jsonKey)); if (success) { // This is a workaround for the API returning 200 {} for no results, should be 404 diff --git a/src/utils/accessAPI.js b/src/utils/accessAPI.js new file mode 100644 index 0000000..3d33bae --- /dev/null +++ b/src/utils/accessAPI.js @@ -0,0 +1,30 @@ +/** + * + * @const accessAPI - This encapsulates common fetch parameters + * + * @param {String} url - URL to fetch from + * @param {String} method - The HTTP method + * @param {String} auth - Either basic authentication or the accessToken + * @param {String} body - The request body (as a JSON string) + * @param {Function} callback - The method to call with the fetch results + * + * @return {Function} + * + */ +export const accessAPI = (url, method, auth, body, callback) => { + return fetch(url, { + method, + headers: { + 'Content-Type': 'application/json', + Authorization: auth, + }, + body, + }).then((response) => { + switch (response.status) { + case 200: return response.json().then((json) => callback(true, { results: json })); + case 401: return callback(false, { message: 'Unable to login.' }); + case 500: return callback(false, { message: 'Unable to login.' }); + default: return callback(false, { message: 'Unable to login.' }); + } + }).catch((err) => callback(false, { message: `Server error: request timed out. ${err}` })); +}; From ca41c367b83513d991d40703b6529072a3683816 Mon Sep 17 00:00:00 2001 From: Tom Cooling Date: Thu, 1 Feb 2018 08:40:20 +0000 Subject: [PATCH 03/10] Add refactored InfoActions with new fetch - Use accessAPI method in InfoActions --- src/actions/ApiActions.js | 8 ++++---- src/actions/InfoActions.js | 24 ++++++++++++++++-------- src/utils/accessAPI.js | 2 +- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/actions/ApiActions.js b/src/actions/ApiActions.js index 0e11c45..924dcf4 100644 --- a/src/actions/ApiActions.js +++ b/src/actions/ApiActions.js @@ -14,21 +14,21 @@ export function search(query, formQuery, jsonKey) { const formattedQuery = formQuery(query); dispatch(setFormattedQuery(SET_FORMATTED_QUERY, formattedQuery, jsonKey)); - accessAPI(REROUTE_URL, 'POST', sessionStorage.getItem('accessToken'), JSON.stringify({ + accessAPI(REROUTE_URL, 'POST', sessionStorage.accessToken, JSON.stringify({ method: 'GET', endpoint: `${API_VERSION}/${formattedQuery}`, }), (success, data) => { dispatch(sendingRequest(SENDING_SEARCH_REQUEST, false, jsonKey)); if (success) { // This is a workaround for the API returning 200 {} for no results, should be 404 - if (Object.keys(data.results).length === 0 && data.results.constructor === Object) { + if (Object.keys(data.json).length === 0 && data.json.constructor === Object) { dispatch(setErrorMessage(SET_SEARCH_ERROR_MESSAGE, '404: No results found.', jsonKey)); } else { if (jsonKey === 'ubrn') { // Wrap the results in an array as we only get {} from the API - dispatch(setResults(SET_RESULTS, [data.results], jsonKey)); + dispatch(setResults(SET_RESULTS, [data.json], jsonKey)); } else { - dispatch(setResults(SET_RESULTS, data.results, jsonKey)); + dispatch(setResults(SET_RESULTS, data.json, jsonKey)); } dispatch(setHeaders(SET_HEADERS, data.response, jsonKey)); } diff --git a/src/actions/InfoActions.js b/src/actions/InfoActions.js index 4c499bd..5c0b2b1 100644 --- a/src/actions/InfoActions.js +++ b/src/actions/InfoActions.js @@ -1,5 +1,8 @@ import { SET_UI_INFO, SET_API_INFO, SENDING_UI_REQUEST, SENDING_API_REQUEST, SET_UI_ERROR_MESSAGE, SET_API_ERROR_MESSAGE } from '../constants/InfoConstants'; -import apiInfo from '../utils/apiInfo'; +import { accessAPI } from '../utils/accessAPI'; +import config from '../config/api-urls'; + +const { AUTH_URL, REROUTE_URL } = config; /** * Get info (version/last updated) from the Node server @@ -7,12 +10,13 @@ import apiInfo from '../utils/apiInfo'; export function getUiInfo() { return (dispatch) => { dispatch(sendingRequest(SENDING_UI_REQUEST, true)); - apiInfo.getUiInfo((success, data) => { + + accessAPI(`${AUTH_URL}/api/info`, 'GET', sessionStorage.accessToken, {}, (success, data) => { dispatch(sendingRequest(SENDING_UI_REQUEST, false)); if (success) { dispatch(setInfo(SET_UI_INFO, { - version: data.version, - lastUpdate: data.lastUpdate, + version: data.json.version, + lastUpdate: data.json.lastUpdate, })); } else { dispatch(setErrorMessage(SET_UI_ERROR_MESSAGE, data.message)); @@ -27,13 +31,17 @@ export function getUiInfo() { export function getApiInfo() { return (dispatch) => { dispatch(sendingRequest(SENDING_API_REQUEST, true)); - apiInfo.getApiInfo((success, data) => { + + accessAPI(REROUTE_URL, 'POST', sessionStorage.accessToken, JSON.stringify({ + method: 'GET', + endpoint: 'version', + }), (success, data) => { dispatch(sendingRequest(SENDING_API_REQUEST, false)); if (success) { dispatch(setInfo(SET_API_INFO, { - version: data.version, - lastApiUpdate: data.lastApiUpdate, - lastDataUpdate: data.lastDataUpdate, + version: data.json.version, + lastApiUpdate: data.json.lastApiUpdate, + lastDataUpdate: data.json.lastDataUpdate, })); } else { dispatch(setErrorMessage(SET_API_ERROR_MESSAGE, data.message)); diff --git a/src/utils/accessAPI.js b/src/utils/accessAPI.js index 3d33bae..56a2b2f 100644 --- a/src/utils/accessAPI.js +++ b/src/utils/accessAPI.js @@ -21,7 +21,7 @@ export const accessAPI = (url, method, auth, body, callback) => { body, }).then((response) => { switch (response.status) { - case 200: return response.json().then((json) => callback(true, { results: json })); + case 200: return response.json().then((json) => callback(true, { json })); case 401: return callback(false, { message: 'Unable to login.' }); case 500: return callback(false, { message: 'Unable to login.' }); default: return callback(false, { message: 'Unable to login.' }); From c6d8a0957b744da12471eceb39ba232b179c2057 Mon Sep 17 00:00:00 2001 From: Tom Cooling Date: Thu, 1 Feb 2018 08:45:25 +0000 Subject: [PATCH 04/10] Refactor login action to use accessAPI --- src/actions/LoginActions.js | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/src/actions/LoginActions.js b/src/actions/LoginActions.js index 3087a11..06e538b 100644 --- a/src/actions/LoginActions.js +++ b/src/actions/LoginActions.js @@ -4,6 +4,10 @@ import { SET_AUTH, SET_CONFETTI, USER_LOGOUT, SENDING_REQUEST, SET_ERROR_MESSAGE import * as errorMessages from '../constants/MessageConstants'; import auth from '../utils/auth'; import { getUiInfo, getApiInfo } from '../actions/InfoActions'; +import { accessAPI } from '../utils/accessAPI'; +import config from '../config/api-urls'; + +const { AUTH_URL } = config; /** * Logs an user in @@ -23,38 +27,28 @@ export function login(username, password) { } const basicAuth = base64.encode(`${username}:${password}`); - auth.login(username, basicAuth, (success, data) => { + + accessAPI(`${AUTH_URL}/auth/login`, 'POST', `Basic ${basicAuth}`, JSON.stringify({ + username, + }), (success, data) => { // When the request is finished, hide the loading indicator dispatch(sendingRequest(false)); dispatch(setAuthState(success)); if (success) { - dispatch(setConfetti(data.showConfetti)); + dispatch(setConfetti(data.json.showConfetti)); // If the login worked, forward the user to the dashboard and clear the form dispatch(setUserState({ username, - role: data.role, - accessToken: data.accessToken, + role: data.json.role, + accessToken: data.json.accessToken, })); - sessionStorage.setItem('accessToken', data.accessToken); + sessionStorage.setItem('accessToken', data.json.accessToken); sessionStorage.setItem('username', username); dispatch(getUiInfo()); dispatch(getApiInfo()); - // We setQuery to {} as a hacky solution to the issue below: - // https://github.com/ONSdigital/bi-ui/issues/3 - // dispatch(setQuery(SET_MATCH_QUERY, {})); - // dispatch(setQuery(SET_RANGE_QUERY, {})); forwardTo('/Home'); } else { - switch (data.type) { - case 'user-doesnt-exist': - dispatch(setErrorMessage(errorMessages.USER_NOT_FOUND)); - return; - case 'password-wrong': - dispatch(setErrorMessage(errorMessages.WRONG_PASSWORD)); - return; - default: - dispatch(setErrorMessage(errorMessages.GENERAL_ERROR)); - } + dispatch(setErrorMessage(errorMessages.GENERAL_ERROR)); } }); }; From fc56ce6dbabd1b72a370f06f5ecf5a1987c9941c Mon Sep 17 00:00:00 2001 From: Tom Cooling Date: Thu, 1 Feb 2018 08:49:33 +0000 Subject: [PATCH 05/10] Add refactored logout LoginAction --- src/actions/LoginActions.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/actions/LoginActions.js b/src/actions/LoginActions.js index 06e538b..f1846a3 100644 --- a/src/actions/LoginActions.js +++ b/src/actions/LoginActions.js @@ -57,9 +57,9 @@ export function login(username, password) { /** * Check the users token */ -export function checkAuth(username, token) { +export function checkAuth() { return (dispatch) => { - auth.checkToken(token, (success, data) => { + accessAPI(`${AUTH_URL}/auth/checkToken`, 'POST', sessionStorage.accessToken, {}, (success, data) => { dispatch(setAuthState(success)); if (!success) { sessionStorage.clear(); @@ -71,11 +71,11 @@ export function checkAuth(username, token) { dispatch(getUiInfo()); dispatch(getApiInfo()); dispatch(setUserState({ - username: data.username, - accessToken: data.newAccessToken, - role: data.role, + username: data.json.username, + accessToken: data.json.accessToken, + role: data.json.role, })); - sessionStorage.setItem('accessToken', data.newAccessToken); + sessionStorage.setItem('accessToken', data.json.accessToken); } }); }; From 96a7a7ea2021f6b7b3297ec9be21e33fbd0f559d Mon Sep 17 00:00:00 2001 From: Tom Cooling Date: Thu, 1 Feb 2018 08:59:00 +0000 Subject: [PATCH 06/10] Add refactored logout action in LoginActions --- src/actions/LoginActions.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/actions/LoginActions.js b/src/actions/LoginActions.js index f1846a3..86dc2f0 100644 --- a/src/actions/LoginActions.js +++ b/src/actions/LoginActions.js @@ -2,7 +2,6 @@ import { browserHistory } from 'react-router'; import base64 from 'base-64'; import { SET_AUTH, SET_CONFETTI, USER_LOGOUT, SENDING_REQUEST, SET_ERROR_MESSAGE, SET_USER_DETAILS } from '../constants/LoginConstants'; import * as errorMessages from '../constants/MessageConstants'; -import auth from '../utils/auth'; import { getUiInfo, getApiInfo } from '../actions/InfoActions'; import { accessAPI } from '../utils/accessAPI'; import config from '../config/api-urls'; @@ -87,7 +86,7 @@ export function checkAuth() { export function logout() { return (dispatch) => { dispatch(sendingRequest(true)); - auth.logout(sessionStorage.accessToken, (success) => { + accessAPI(`${AUTH_URL}/auth/logout`, 'POST', sessionStorage.accessToken, {}, (success, data) => { dispatch(sendingRequest(false)); if (success) { dispatch(setAuthState(false)); From a70f2d0d3b68ffb50689dc638ec51db5b537755a Mon Sep 17 00:00:00 2001 From: Tom Cooling Date: Thu, 1 Feb 2018 09:02:27 +0000 Subject: [PATCH 07/10] Remove unused /utils files - Use default export in accessAPI.js --- src/actions/ApiActions.js | 2 +- src/actions/InfoActions.js | 2 +- src/actions/LoginActions.js | 2 +- src/utils/accessAPI.js | 4 +- src/utils/apiInfo.js | 65 --------------------------- src/utils/apiSearch.js | 40 ----------------- src/utils/auth.js | 88 ------------------------------------- 7 files changed, 6 insertions(+), 197 deletions(-) delete mode 100644 src/utils/apiInfo.js delete mode 100644 src/utils/apiSearch.js delete mode 100644 src/utils/auth.js diff --git a/src/actions/ApiActions.js b/src/actions/ApiActions.js index 924dcf4..9a4e7d4 100644 --- a/src/actions/ApiActions.js +++ b/src/actions/ApiActions.js @@ -1,5 +1,5 @@ import { SET_RESULTS, SET_FORMATTED_QUERY, SET_SEARCH_ERROR_MESSAGE, SENDING_SEARCH_REQUEST, SET_QUERY, SET_HEADERS } from '../constants/ApiConstants'; -import { accessAPI } from '../utils/accessAPI'; +import accessAPI from '../utils/accessAPI'; import config from '../config/api-urls'; const { REROUTE_URL, API_VERSION } = config; diff --git a/src/actions/InfoActions.js b/src/actions/InfoActions.js index 5c0b2b1..a5d5d8b 100644 --- a/src/actions/InfoActions.js +++ b/src/actions/InfoActions.js @@ -1,5 +1,5 @@ import { SET_UI_INFO, SET_API_INFO, SENDING_UI_REQUEST, SENDING_API_REQUEST, SET_UI_ERROR_MESSAGE, SET_API_ERROR_MESSAGE } from '../constants/InfoConstants'; -import { accessAPI } from '../utils/accessAPI'; +import accessAPI from '../utils/accessAPI'; import config from '../config/api-urls'; const { AUTH_URL, REROUTE_URL } = config; diff --git a/src/actions/LoginActions.js b/src/actions/LoginActions.js index 86dc2f0..9cde46a 100644 --- a/src/actions/LoginActions.js +++ b/src/actions/LoginActions.js @@ -3,7 +3,7 @@ import base64 from 'base-64'; import { SET_AUTH, SET_CONFETTI, USER_LOGOUT, SENDING_REQUEST, SET_ERROR_MESSAGE, SET_USER_DETAILS } from '../constants/LoginConstants'; import * as errorMessages from '../constants/MessageConstants'; import { getUiInfo, getApiInfo } from '../actions/InfoActions'; -import { accessAPI } from '../utils/accessAPI'; +import accessAPI from '../utils/accessAPI'; import config from '../config/api-urls'; const { AUTH_URL } = config; diff --git a/src/utils/accessAPI.js b/src/utils/accessAPI.js index 56a2b2f..1f5cc69 100644 --- a/src/utils/accessAPI.js +++ b/src/utils/accessAPI.js @@ -11,7 +11,7 @@ * @return {Function} * */ -export const accessAPI = (url, method, auth, body, callback) => { +const accessAPI = (url, method, auth, body, callback) => { return fetch(url, { method, headers: { @@ -28,3 +28,5 @@ export const accessAPI = (url, method, auth, body, callback) => { } }).catch((err) => callback(false, { message: `Server error: request timed out. ${err}` })); }; + +export default accessAPI; diff --git a/src/utils/apiInfo.js b/src/utils/apiInfo.js deleted file mode 100644 index 83000be..0000000 --- a/src/utils/apiInfo.js +++ /dev/null @@ -1,65 +0,0 @@ -import config from '../config/api-urls'; - -const { AUTH_URL, REROUTE_URL } = config; - -/** - * API lib for getting info (version/last updated etc.) - * @type {Object} - */ -const apiInfo = { - /** - * Gets version/lastUpdate info from the UI. - * @param {Function} callback Called with returned data. - */ - getUiInfo(callback) { - fetch(`${AUTH_URL}/api/info`, { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - 'Authorization': sessionStorage.accessToken, - }, - }).then((response) => { - if (response.status === 200) { - return response.json().then((json) => { - const version = json.version; - const lastUpdate = json.lastUpdate; - callback(true, { version, lastUpdate }); - }); - } - return callback(false, { message: 'Server error: unable to load data.' }); - }).catch(() => { - return callback(false, { message: 'Timeout: unable to load data' }); - }); - }, - /** - * Gets version/lastUpdate info from the API. - * @param {Function} callback Called with returned data. - */ - getApiInfo(callback) { - fetch(`${REROUTE_URL}`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'Authorization': sessionStorage.getItem('accessToken'), - }, - body: JSON.stringify({ - method: 'GET', - endpoint: 'version', - }), - }).then((response) => { - if (response.status === 200) { - return response.json().then((json) => { - const version = json.version; - const lastApiUpdate = json.builtAtString; - const lastDataUpdate = json.lastDataUpdate; - callback(true, { version, lastApiUpdate, lastDataUpdate }); - }); - } - return callback(false, { message: 'Server error: unable to load data.' }); - }).catch(() => { - return callback(false, { message: 'Timeout: unable to load data' }); - }); - }, -}; - -module.exports = apiInfo; diff --git a/src/utils/apiSearch.js b/src/utils/apiSearch.js deleted file mode 100644 index e32e6ad..0000000 --- a/src/utils/apiSearch.js +++ /dev/null @@ -1,40 +0,0 @@ -import config from '../config/api-urls'; - -const { REROUTE_URL, API_VERSION } = config; - -/** - * API lib for searching business-index-api - * @type {Object} - */ -const apiSearch = { - /** - * Searches API for match - * @param {Function} callback Called with returned data. - */ - search(query, callback) { - fetch(`${REROUTE_URL}`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'Authorization': sessionStorage.getItem('accessToken'), - }, - body: JSON.stringify({ - method: 'GET', - endpoint: `${API_VERSION}/${query}`, - }), - }).then((response) => { - if (response.status === 200) { - return response.json().then((json) => { - callback(true, { results: json, response: response.headers, resp: response }); - }); - } else if (response.status >= 500 && response.status < 600) { - return callback(false, { message: 'Server error: unable to load data.', resp: response }); - } - return callback(false, { message: 'Error: record not found.', resp: response }); - }).catch(() => { - return callback(false, { message: 'Timeout: unable to load data.' }); - }); - }, -}; - -module.exports = apiSearch; diff --git a/src/utils/auth.js b/src/utils/auth.js deleted file mode 100644 index a7d0098..0000000 --- a/src/utils/auth.js +++ /dev/null @@ -1,88 +0,0 @@ -import config from '../config/api-urls'; - -const { AUTH_URL } = config; - -/** - * Authentication lib - * @type {Object} - */ -const auth = { - /** - * Logs a user in - * @param {string} username The username of the user - * @param {string} password The password of the user - * @param {Function} callback Called after a user was logged in on the remote server - */ - login(username, basicAuth, callback) { - // Do not need to check if user is already logged in, this is done in - // routes.js before this method is called - - // POST to the backend with username/password - fetch(`${AUTH_URL}/auth/login`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - Authorization: `Basic ${basicAuth}`, - }, - body: JSON.stringify({ username }), - }).then((response) => { - if (response.status === 200) { - return response.json().then((json) => { - // const token: string = json.jToken; - const loginName = json.username; - const accessToken = json.accessToken; - const showConfetti = json.showConfetti; - const role = json.role; - // Send auth request to save token username pair - callback(true, { username: loginName, accessToken, showConfetti, role }); - }); - } - return callback(false, { message: 'Unable to login.' }); - }) - .catch(() => { - return callback(false, { message: 'Server error: request timed out.' }); - }); - }, - checkToken(accessToken, callback) { - fetch(`${AUTH_URL}/auth/checkToken`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'Authorization': sessionStorage.accessToken, - }, - }).then((response) => { - if (response.status === 200) { - return response.json().then((json) => { - const newAccessToken = json.accessToken; - const username = json.username; - const role = json.role; - // Send auth request to save token username pair - callback(true, { username, newAccessToken, role }); - }); - } - return callback(false); - }) - .catch(() => { - return callback(false, { message: 'Server error: request timed out.' }); - }); - }, - /** - * Logs the current user out - */ - logout(accessToken, callback) { - // const token: string = sessionStorage.token; - fetch(`${AUTH_URL}/auth/logout`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'Authorization': sessionStorage.accessToken, - }, - }).then(() => { - // Whatever the response, log the user out. - sessionStorage.clear(); - callback(true); - }); - }, -}; - -module.exports = auth; From 299ecc0a277bf6e2911be94b5d9df45ec7a0afb1 Mon Sep 17 00:00:00 2001 From: Tom Cooling Date: Thu, 1 Feb 2018 09:06:40 +0000 Subject: [PATCH 08/10] Add more informative api request error messages --- src/utils/accessAPI.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/accessAPI.js b/src/utils/accessAPI.js index 1f5cc69..97b3a20 100644 --- a/src/utils/accessAPI.js +++ b/src/utils/accessAPI.js @@ -22,9 +22,9 @@ const accessAPI = (url, method, auth, body, callback) => { }).then((response) => { switch (response.status) { case 200: return response.json().then((json) => callback(true, { json })); - case 401: return callback(false, { message: 'Unable to login.' }); - case 500: return callback(false, { message: 'Unable to login.' }); - default: return callback(false, { message: 'Unable to login.' }); + case 401: return callback(false, { message: 'Authentication problem. Please ensure you are logged in.' }); + case 500: return callback(false, { message: 'Server error. Please contact your system administrator.' }); + default: return callback(false, { message: `${response.status} error.` }); } }).catch((err) => callback(false, { message: `Server error: request timed out. ${err}` })); }; From 8e467408f1256e77ad075ba1a4255a3d39c80302 Mon Sep 17 00:00:00 2001 From: Tom Cooling Date: Thu, 1 Feb 2018 09:11:20 +0000 Subject: [PATCH 09/10] Fix wrong last update usage in Info page --- src/actions/InfoActions.js | 2 +- src/views/TechnicalInformation.js | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/actions/InfoActions.js b/src/actions/InfoActions.js index a5d5d8b..13b19d3 100644 --- a/src/actions/InfoActions.js +++ b/src/actions/InfoActions.js @@ -40,7 +40,7 @@ export function getApiInfo() { if (success) { dispatch(setInfo(SET_API_INFO, { version: data.json.version, - lastApiUpdate: data.json.lastApiUpdate, + lastApiUpdate: data.json.builtAtString, lastDataUpdate: data.json.lastDataUpdate, })); } else { diff --git a/src/views/TechnicalInformation.js b/src/views/TechnicalInformation.js index 32581f6..d115f49 100644 --- a/src/views/TechnicalInformation.js +++ b/src/views/TechnicalInformation.js @@ -2,7 +2,7 @@ import React from 'react'; import { connect } from 'react-redux'; import { TitleAndDescription, BreadCrumb } from 'registers-react-library'; -const TechnicalInformation = ({ username, role, uiVersion, apiVersion, uiLastUpdate, apiLastUpdate }) => { +const TechnicalInformation = ({ uiVersion, apiVersion, uiLastUpdate, apiLastUpdate }) => { const items = [ { name: 'Home', link: '/Home' }, { name: 'Technical Information', link: '' }, @@ -52,8 +52,6 @@ const TechnicalInformation = ({ username, role, uiVersion, apiVersion, uiLastUpd }; TechnicalInformation.propTypes = { - username: React.PropTypes.string.isRequired, - role: React.PropTypes.string.isRequired, uiVersion: React.PropTypes.string.isRequired, apiVersion: React.PropTypes.string.isRequired, uiLastUpdate: React.PropTypes.string.isRequired, @@ -62,12 +60,10 @@ TechnicalInformation.propTypes = { function select(state) { return { - username: state.login.username, - role: state.login.role, uiVersion: state.info.ui.version, apiVersion: state.info.api.version, uiLastUpdate: state.info.ui.lastUpdate, - apiLastUpdate: state.info.ui.lastUpdate, + apiLastUpdate: state.info.api.lastApiUpdate, }; } From cb985716476a858db715394be0ccaa2cf071e1e2 Mon Sep 17 00:00:00 2001 From: Tom Cooling Date: Thu, 1 Feb 2018 11:37:04 +0000 Subject: [PATCH 10/10] Fix Jenkinsfile library branch - Use master, not a deleted branch --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index ca3c913..b3917f3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,5 +1,5 @@ #!groovy -@Library('jenkins-pipeline-shared@feature/new-cf') _ +@Library('jenkins-pipeline-shared@master') _ /* * bi-ui Jenkins Pipeline