Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

[Enhancement] Detecting mapbox token validity (#513)

Giuseppe Macrì3ea828b21400
diff --git a/package.json b/package.json
index cc8704eac..7b408bcb4 100644
--- a/package.json
+++ b/package.json
@@ -47,7 +47,7 @@
"docs": "babel-node ./scripts/documentation.js",
"lint": "eslint src webpack/*.js examples/*.js examples/**/src examples/**/*.js website/*.js website/src --fix",
"web": "(yarn && yarn install:web && yarn start:web)",
- "deploy": "yarn install:web && (cd website && yarn build)",
+ "deploy": "yarn && yarn install:web && (cd website && yarn build)",
"clean": "rm -rf node_modules examples/**/node_modules website/node_modules",
"release:patch": "git add CHANGELOG.md && git commit -m 'updated CHANGELOG.md' && npm version patch && git push origin && git push origin --tags"
},
diff --git a/src/components/kepler-gl.js b/src/components/kepler-gl.js
index cc0d7fee1..d51370ab9 100644
--- a/src/components/kepler-gl.js
+++ b/src/components/kepler-gl.js
@@ -32,6 +32,7 @@ import * as UIStateActions from 'actions/ui-state-actions';
import {EXPORT_IMAGE_ID, DIMENSIONS,
KEPLER_GL_NAME, KEPLER_GL_VERSION, THEME} from 'constants/default-settings';
+import {MISSING_MAPBOX_TOKEN} from 'constants/user-feedbacks';
import SidePanelFactory from './side-panel';
import MapContainerFactory from './map-container';
@@ -41,6 +42,7 @@ import PlotContainerFactory from './plot-container';
import NotificationPanelFactory from './notification-panel';
import {generateHashId} from 'utils/utils';
+import {validateToken} from 'utils/mapbox-utils';
import {theme as basicTheme, themeLT} from 'styles/base';
@@ -104,6 +106,7 @@ function KeplerGlFactory(
};
componentWillMount() {
+ this._validateMapboxToken();
this._loadMapStyle(this.props.mapStyles);
this._handleResize(this.props);
}
@@ -131,6 +134,13 @@ function KeplerGlFactory(
}) : theme === THEME.light ? themeLT : theme
);
+ _validateMapboxToken() {
+ const {mapboxApiAccessToken} = this.props;
+ if (!validateToken(mapboxApiAccessToken)) {
+ Console.warn(MISSING_MAPBOX_TOKEN);
+ }
+ }
+
_handleResize({width, height}) {
if (!Number.isFinite(width) || !Number.isFinite(height)) {
Console.warn('width and height is required');
diff --git a/src/constants/user-feedbacks.js b/src/constants/user-feedbacks.js
new file mode 100644
index 000000000..fcfc963bc
--- /dev/null
+++ b/src/constants/user-feedbacks.js
@@ -0,0 +1,22 @@
+// Copyright (c) 2019 Uber Technologies, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+export const MISSING_MAPBOX_TOKEN = "Mapbox Token not valid. " +
+ "[Click here](https://github.com/keplergl/kepler.gl#mapboxapiaccesstoken-string-required)";
diff --git a/src/utils/mapbox-utils.js b/src/utils/mapbox-utils.js
new file mode 100644
index 000000000..574fb2535
--- /dev/null
+++ b/src/utils/mapbox-utils.js
@@ -0,0 +1,27 @@
+// Copyright (c) 2019 Uber Technologies, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+/**
+ * This method validates mapbox token.
+ * This token provides a simple synchronous validation
+ * @param {string} token the Mapbox token to validate
+ * @return {boolean} true if token is valid, false otherwise
+ */
+export const validateToken = token => (token || '') !== '';
diff --git a/test/browser/components/container-test.js b/test/browser/components/container-test.js
index 9314f5386..74cdcb270 100644
--- a/test/browser/components/container-test.js
+++ b/test/browser/components/container-test.js
@@ -22,6 +22,7 @@
import React from 'react';
import test from 'tape';
import {mount} from 'enzyme';
+import {combineReducers} from 'redux';
import configureStore from 'redux-mock-store';
import {Provider} from 'react-redux';
import sinon from 'sinon';
@@ -30,17 +31,13 @@ import rootReducer from 'reducers/root';
import coreReducer from 'reducers/core';
import {keplerGlInit} from 'actions/actions';
-import {combineReducers} from 'redux';
-
+import Container, {errorMsg} from 'components/container';
const initialCoreState = coreReducer(undefined, keplerGlInit());
-
const initialState = {
keplerGl: {}
};
const mockStore = configureStore();
-import Container, {errorMsg} from 'components/container';
-
test('Components -> Container -> Mount with mint:true', t => {
// mount with empty store
let store = mockStore({});
@@ -141,6 +138,7 @@ test('Components -> Container -> Mount with mint:true', t => {
}
}
};
+
t.deepEqual(
nextState,
expectedState,
@@ -202,8 +200,8 @@ test('Components -> Container -> Mount with mint:false', t => {
);
actions.splice(0, 2);
- let nextState = appReducer({}, expectedActions0);
- let expectedState = {
+ const nextState = appReducer({}, expectedActions0);
+ const expectedState = {
smoothie: {
milkshake: {
...initialCoreState,
@@ -266,8 +264,8 @@ test('Components -> Container -> Mount then rename', t => {
'should register entry'
);
- let nextState = appReducer({}, expectedActions0);
- let expectedState = {
+ const nextState = appReducer({}, expectedActions0);
+ const expectedState = {
smoothie: {
milkshake: {
...initialCoreState,
diff --git a/test/browser/components/kepler-gl-test.js b/test/browser/components/kepler-gl-test.js
index a1e6b3619..8f13d6cf4 100644
--- a/test/browser/components/kepler-gl-test.js
+++ b/test/browser/components/kepler-gl-test.js
@@ -420,6 +420,7 @@ test('Components -> KeplerGl -> Mount -> Load custom map style task', t => {
'Should load map style into reducer and create layer groups'
);
+ // Do not remove this. Necessary for testing flow
const resultState2 = coreReducer(resultState1, actions[1]);
const [task1, ...rest] = drainTasksForTesting();
t.equal(rest.length, 0, 'should dispatch 1 tasks');
diff --git a/website/package.json b/website/package.json
index adbbd78d8..cc6c300ab 100644
--- a/website/package.json
+++ b/website/package.json
@@ -14,7 +14,7 @@
"start": "webpack-dev-server --mode development --env.prod --content-base ./src/static --progress --open",
"start-prod": "webpack-dev-server -p --env.prod --content-base ./src/static --progress --open",
"build-clean": "rm -rf ./dist && mkdir dist",
- "build-static": "cp -r ./src/static/* dist && cd `git rev-parse --show-toplevel`",
+ "build-static": "cp -r ./src/static/* dist",
"build-script": "webpack -p --env.prod",
"build": "npm run build-clean && npm run build-static && npm run build-script",
"lint": "eslint src"
diff --git a/yarn.lock b/yarn.lock
index a5a28d362..247bd26e0 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -3349,9 +3349,9 @@ escodegen@^1.9.1:
optionalDependencies:
source-map "~0.6.1"
-eslint-config-prettier@^3.6.0:
- version "3.6.0"
- resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-3.6.0.tgz#8ca3ffac4bd6eeef623a0651f9d754900e3ec217"
+eslint-config-prettier@^4.3.0:
+ version "4.3.0"
+ resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-4.3.0.tgz#c55c1fcac8ce4518aeb77906984e134d9eb5a4f0"
dependencies:
get-stdin "^6.0.0"
@@ -3378,7 +3378,7 @@ eslint-plugin-babel@^5.3.0:
dependencies:
eslint-rule-composer "^0.3.0"
-eslint-plugin-prettier@^3.0.1:
+eslint-plugin-prettier@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-3.1.0.tgz#8695188f95daa93b0dc54b249347ca3b79c4686d"
dependencies:
@@ -3394,17 +3394,17 @@ eslint-plugin-react@^6.7.1:
jsx-ast-utils "^1.3.4"
object.assign "^4.0.4"
-eslint-plugin-react@~7.12.4:
- version "7.12.4"
- resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-7.12.4.tgz#b1ecf26479d61aee650da612e425c53a99f48c8c"
+eslint-plugin-react@^7.13.0:
+ version "7.13.0"
+ resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-7.13.0.tgz#bc13fd7101de67996ea51b33873cd9dc2b7e5758"
dependencies:
array-includes "^3.0.3"
doctrine "^2.1.0"
has "^1.0.3"
- jsx-ast-utils "^2.0.1"
+ jsx-ast-utils "^2.1.0"
object.fromentries "^2.0.0"
- prop-types "^15.6.2"
- resolve "^1.9.0"
+ prop-types "^15.7.2"
+ resolve "^1.10.1"
eslint-rule-composer@^0.3.0:
version "0.3.0"
@@ -3432,7 +3432,7 @@ eslint-visitor-keys@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz#3f3180fb2e291017716acb4c9d6d5b5c34a6a81d"
-eslint@^5.12.1:
+eslint@^5.16.0:
version "5.16.0"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-5.16.0.tgz#a1e3ac1aae4a3fbd8296fcf8f7ab7314cbb6abea"
dependencies:
@@ -5226,7 +5226,7 @@ jsx-ast-utils@^1.3.4:
version "1.4.1"
resolved "https://registry.yarnpkg.com/jsx-ast-utils/-/jsx-ast-utils-1.4.1.tgz#3867213e8dd79bf1e8f2300c0cfc1efb182c0df1"
-jsx-ast-utils@^2.0.1:
+jsx-ast-utils@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/jsx-ast-utils/-/jsx-ast-utils-2.1.0.tgz#0ee4e2c971fb9601c67b5641b71be80faecf0b36"
dependencies:
@@ -7727,12 +7727,18 @@ [email protected]:
version "1.1.7"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b"
-resolve@^1.1.3, resolve@^1.1.4, resolve@^1.10.0, resolve@^1.3.2, resolve@^1.4.0, resolve@^1.8.1, resolve@^1.9.0:
+resolve@^1.1.3, resolve@^1.1.4, resolve@^1.10.0, resolve@^1.3.2, resolve@^1.4.0, resolve@^1.8.1:
version "1.10.1"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.10.1.tgz#664842ac960795bbe758221cdccda61fb64b5f18"
dependencies:
path-parse "^1.0.6"
+resolve@^1.10.1:
+ version "1.11.0"
+ resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.11.0.tgz#4014870ba296176b86343d50b60f3b50609ce232"
+ dependencies:
+ path-parse "^1.0.6"
+
resolve@~1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.4.0.tgz#a75be01c53da25d934a98ebd0e4c4a7312f92a86"