Skip to content

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

Feat: Implemented Dropbox integration (#312)

Giuseppe Macrì941cc477e86a
diff --git a/.eslintrc b/.eslintrc
index 8ca561a7b..dc98c2933 100644
--- a/.eslintrc
+++ b/.eslintrc
@@ -8,7 +8,9 @@
],
"env": {
- "es6": true
+ "es6": true,
+ "browser": true,
+ "node": true
},
"parser": "babel-eslint",
"plugins": [
diff --git a/README.md b/README.md
index 2fdf562ca..fb62561c0 100644
--- a/README.md
+++ b/README.md
@@ -276,7 +276,7 @@ import {connect} from 'react-redux';
Const MapContainer = props => (
<div>
- <button onClick=() => props.keplerGlDispatch(toggleFullScreen())/>
+ <button onClick={() => props.keplerGlDispatch(toggleFullScreen())}/>
<KeplerGl
id="foo"
/>
diff --git a/examples/demo-app/index.html b/examples/demo-app/index.html
index f3daab553..a098a0b35 100644
--- a/examples/demo-app/index.html
+++ b/examples/demo-app/index.html
@@ -10,6 +10,6 @@
</style>
</head>
<body>
- <script src='bundle.js'></script>
+ <script src="/bundle.js"></script>
</body>
</html>
diff --git a/examples/demo-app/package.json b/examples/demo-app/package.json
index fe13a7811..88e4f7731 100644
--- a/examples/demo-app/package.json
+++ b/examples/demo-app/package.json
@@ -6,10 +6,13 @@
},
"dependencies": {
"d3-request": "^1.0.6",
+ "dropbox": "^4.0.12",
"global": "^4.3.0",
"kepler.gl": "^0.2.1-beta.1",
"lodash.debounce": "^4.0.8",
- "react": "^15.3.1",
+ "lodash.get": "^4.4.2",
+ "react": "^15.6.2",
+ "react-copy-to-clipboard": "^5.0.1",
"react-dom": "^15.6.1",
"react-palm": "^1.1.2",
"react-redux": "^4.4.5",
diff --git a/examples/demo-app/src/actions.js b/examples/demo-app/src/actions.js
index 6d3ace6f2..4e3f97430 100644
--- a/examples/demo-app/src/actions.js
+++ b/examples/demo-app/src/actions.js
@@ -28,6 +28,9 @@ import {
MAP_CONFIG_URL
} from './constants/default-settings';
import {LOADING_METHODS_NAMES} from './constants/default-settings';
+import {AUTH_HANDLERS} from './utils/sharing/authentication';
+import {generateHashId} from './utils/strings';
+import KeplerGlSchema from 'kepler.gl/schemas';
// CONSTANTS
export const INIT = 'INIT';
@@ -37,16 +40,22 @@ export const LOAD_REMOTE_RESOURCE_ERROR = 'LOAD_REMOTE_RESOURCE_ERROR';
export const LOAD_MAP_SAMPLE_FILE = 'LOAD_MAP_SAMPLE_FILE';
export const SET_SAMPLE_LOADING_STATUS = 'SET_SAMPLE_LOADING_STATUS';
+// Sharing
+export const PUSHING_FILE = 'PUSHING_FILE';
+export const CLOUD_LOGIC_SUCCESS = 'CLOUD_LOGIC_SUCCESS';
+
// ACTIONS
-export function switchToLoadingMethod(method) {
- return dispatch => {
- dispatch(setLoadingMethod(method));
- if (method === LOADING_METHODS_NAMES.sample) {
- dispatch(loadSampleConfigurations());
- }
+export function initApp() {
+ return {
+ type: INIT
};
}
+/**
+ * this method set the current loading method
+ * @param {string} method the string id for the loading method to use
+ * @returns {{type: string, method: *}}
+ */
export function setLoadingMethod(method) {
return {
type: SET_LOADING_METHOD,
@@ -54,6 +63,20 @@ export function setLoadingMethod(method) {
};
}
+/**
+ * this action is triggered when user switches between load modal tabs
+ * @param {string} method
+ * @returns {Function}
+ */
+export function switchToLoadingMethod(method) {
+ return (dispatch, getState) => {
+ dispatch(setLoadingMethod(method));
+ if (method === LOADING_METHODS_NAMES.sample && getState().demo.app.sampleMaps.length === 0) {
+ dispatch(loadSampleConfigurations());
+ }
+ };
+}
+
export function loadRemoteResourceSuccess(response, config, options) {
return {
type: LOAD_REMOTE_RESOURCE_SUCCESS,
@@ -111,21 +134,26 @@ function detectResponseError(response) {
*/
export function loadRemoteMap(options) {
return dispatch => {
+ dispatch(setLoadingMapStatus(true));
loadRemoteRawData(options.dataUrl).then(
// In this part we turn the response into a FileBlob
// so we can use it to call loadFiles
- file => dispatch(loadFiles([
- /* eslint-disable no-undef */
- new File([file], options.dataUrl)
- /* eslint-enable no-undef */
- ])),
+ file => {
+ dispatch(loadFiles([
+ /* eslint-disable no-undef */
+ new File([file], options.dataUrl)
+ /* eslint-enable no-undef */
+ ])).then(
+ () => dispatch(setLoadingMapStatus(false))
+ );
+
+ },
error => {
const {target = {}} = error;
const {status, responseText} = target;
dispatch(loadRemoteResourceError({status, message: responseText}, options.dataUrl));
}
);
- dispatch(setLoadingMapStatus(true));
}
}
@@ -305,3 +333,50 @@ export function loadSampleConfigurations(sampleMapId = null) {
}
}
+/**
+ * this action will be triggered when the file is being uploaded
+ * @param isLoading
+ * @param metadata
+ * @returns {{type: string, isLoading: *, metadata: *}}
+ */
+export function setPushingFile(isLoading, metadata) {
+ return {
+ type: PUSHING_FILE,
+ isLoading,
+ metadata
+ };
+}
+
+/**
+ * This method will export the current kepler config file to the choosen cloud platform
+ * @param data
+ * @param handlerName
+ * @returns {Function}
+ */
+export function exportFileToCloud(handlerName = 'dropbox') {
+ const authHandler = AUTH_HANDLERS[handlerName];
+ return (dispatch, getState) => {
+ // extract data from kepler
+ const data = KeplerGlSchema.save(getState().demo.keplerGl.map);
+ const newBlob = new Blob([JSON.stringify(data)], {type: 'application/json'});
+ const file = new File([newBlob], `kepler.gl/keplergl_${generateHashId(6)}.json`);
+ dispatch(setPushingFile(true, {filename: file.name, status: 'uploading', metadata: null}));
+ authHandler.uploadFile({blob: file, isPublic: true, authHandler})
+ // need to perform share as well
+ .then(
+ response => {
+ dispatch(push(`/map?mapUrl=${response.url}`));
+ dispatch(setPushingFile(false, {filename: file.name, status: 'success', metadata: response}));
+ },
+ error => {
+ dispatch(setPushingFile(false, {filename: file.name, status: 'error', error}));
+ }
+ )
+ };
+}
+
+export function setCloudLoginSuccess() {
+ return {
+ type: CLOUD_LOGIC_SUCCESS
+ };
+}
diff --git a/examples/demo-app/src/app.js b/examples/demo-app/src/app.js
index 356e1ce3a..6234aa6a1 100644
--- a/examples/demo-app/src/app.js
+++ b/examples/demo-app/src/app.js
@@ -19,21 +19,27 @@
// THE SOFTWARE.
import React, {Component} from 'react';
-import styled from 'styled-components';
+import {findDOMNode} from 'react-dom';
+import styled, {ThemeProvider} from 'styled-components';
import window from 'global/window';
import {connect} from 'react-redux';
+import {theme} from 'kepler.gl/styles';
import Banner from './components/banner';
import Announcement from './components/announcement';
-
-import {loadRemoteMap, loadSampleConfigurations} from './actions';
import {replaceLoadDataModal} from './factories/load-data-modal';
+import ExportUrlModal from './components/sharing/export-url-modal';
+
+import {
+ exportFileToCloud,
+ loadRemoteMap,
+ loadSampleConfigurations,
+ setCloudLoginSuccess
+} from './actions';
const KeplerGl = require('kepler.gl/components').injectComponents([
replaceLoadDataModal()
]);
-const MAPBOX_TOKEN = process.env.MapboxAccessToken; // eslint-disable-line
-
// Sample data
/* eslint-disable no-unused-vars */
import sampleTripData from './data/sample-trip-data';
@@ -44,10 +50,12 @@ import {updateVisData, addDataToMap} from 'kepler.gl/actions';
import Processors from 'kepler.gl/processors';
/* eslint-enable no-unused-vars */
+const MAPBOX_TOKEN = process.env.MapboxAccessToken; // eslint-disable-line
+
const BannerHeight = 30;
const BannerKey = 'kgHideBanner-iiba';
-const GlobalStyleDiv = styled.div`
+const GlobalStyle = styled.div`
font-family: ff-clan-web-pro, 'Helvetica Neue', Helvetica, sans-serif;
font-weight: 400;
font-size: 0.875em;
@@ -60,6 +68,20 @@ const GlobalStyleDiv = styled.div`
-moz-box-sizing: border-box;
box-sizing: border-box;
}
+
+ ul {
+ margin: 0;
+ padding: 0;
+ }
+
+ li {
+ margin: 0;
+ }
+
+ a {
+ text-decoration: none;
+ color: ${props => props.theme.labelColor};
+ }
`;
class App extends Component {
@@ -81,18 +103,22 @@ class App extends Component {
// Load map using a custom
if (query.mapUrl) {
+ // TODO?: validate map url
this.props.dispatch(loadRemoteMap({dataUrl: query.mapUrl}));
}
+ // event listeners
window.addEventListener('resize', this._onResize);
+
this._onResize();
}
componentDidMount() {
- // delay 2s to show the banner
- // if (!window.localStorage.getItem(BannerKey)) {
- // window.setTimeout(this._showBanner, 3000);
- // }
+ // delay zs to show the banner
+ if (!window.localStorage.getItem(BannerKey)) {
+ window.setTimeout(this._showBanner, 3000);
+ }
+
// load sample data
// this._loadSampleData();
}
@@ -195,40 +221,78 @@ class App extends Component {
);
}
+ _toggleCloudModal = () => {
+ // TODO: this lives only in the demo hence we use the state for now
+ // REFCOTOR using redux
+ this.setState({
+ cloudModalOpen: !this.state.cloudModalOpen
+ });
+ };
+
+ _onExportToCloud = () => {
+ this.props.dispatch(exportFileToCloud())
+ };
+
+ _onCloudLoginSuccess = () => {
+ this.props.dispatch(setCloudLoginSuccess());
+ };
+
render() {
const {showBanner, width, height} = this.state;
+ const {sharing} = this.props.demo;
+ const rootNode = this.root;
return (
- <GlobalStyleDiv>
- <Banner
- show={this.state.showBanner}
- height={BannerHeight}
- bgColor="#82368c"
- onClose={this._hideBanner}
- >
- <Announcement onDisable={this._disableBanner}/>
- </Banner>
- <div
- style={{
- transition: 'margin 1s, height 1s',
- position: 'absolute',
- width: '100%',
- height: showBanner ? `calc(100% - ${BannerHeight}px)` : '100%',
- minHeight: `calc(100% - ${BannerHeight}px)`,
- marginTop: showBanner ? `${BannerHeight}px` : 0
- }}
+ <ThemeProvider theme={theme}>
+ <GlobalStyle
+ // this is to apply the same modal style as kepler.gl core
+ // because styled-components doesn't always return a node
+ // https://github.com/styled-components/styled-components/issues/617
+ innerRef={node => {node ? this.root = node : null}}
>
- <KeplerGl
- mapboxApiAccessToken={MAPBOX_TOKEN}
- id="map"
- /*
- * Specify path to keplerGl state, because it is not mount at the root
- */
- getState={state => state.demo.keplerGl}
- width={width}
- height={height - (showBanner ? BannerHeight : 0)}
- />
- </div>
- </GlobalStyleDiv>
+ <Banner
+ show={this.state.showBanner}
+ height={BannerHeight}
+ bgColor="#82368c"
+ onClose={this._hideBanner}
+ >
+ <Announcement onDisable={this._disableBanner}/>
+ </Banner>
+ {rootNode && (
+ <ExportUrlModal
+ sharing={sharing}
+ isOpen={Boolean(this.state.cloudModalOpen)}
+ onClose={this._toggleCloudModal}
+ onExport={this._onExportToCloud}
+ onCloudLoginSuccess={this._onCloudLoginSuccess}
+ // this is to apply the same modal style as kepler.gl core
+ parentSelector={() => findDOMNode(this.root)}
+ />
+ )}
+ <div
+ style={{
+ transition: 'margin 1s, height 1s',
+ position: 'absolute',
+ width: '100%',
+ height: showBanner ? `calc(100% - ${BannerHeight}px)` : '100%',
+ minHeight: `calc(100% - ${BannerHeight}px)`,
+ marginTop: showBanner ? `${BannerHeight}px` : 0
+ }}
+ >
+ <KeplerGl
+ mapboxApiAccessToken={MAPBOX_TOKEN}
+ id="map"
+ /*
+ * Specify path to keplerGl state, because it is not mount at the root
+ */
+ getState={state => state.demo.keplerGl}
+ width={width}
+ height={height - (showBanner ? BannerHeight : 0)}
+ onSaveMap={this._toggleCloudModal}
+ />
+ </div>
+ </GlobalStyle>
+ </ThemeProvider>
+
);
}
}
diff --git a/examples/demo-app/src/components/icons/dropbox-icon.js b/examples/demo-app/src/components/icons/dropbox-icon.js
new file mode 100644
index 000000000..092bb2020
--- /dev/null
+++ b/examples/demo-app/src/components/icons/dropbox-icon.js
@@ -0,0 +1,52 @@
+// Copyright (c) 2018 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.
+
+import React, {Component} from 'react';
+import {Icons} from 'kepler.gl/components';
+import PropTypes from 'prop-types';
+
+class DropboxIcon extends Component {
+ static propTypes = {
+ /** Set the height of the icon, ex. '16px' */
+ height: PropTypes.string,
+ colors: PropTypes.arrayOf(PropTypes.string)
+ };
+
+ static defaultProps = {
+ height: '16px',
+ predefinedClassName: 'data-ex-icons-dropbox',
+ totalColor: 1
+ };
+
+ render() {
+ return (
+ <Icons.IconWrapper {...this.props} viewBox={"0 0 416 416"} colors={['#0060ff']}>
+ <path
+ className="cr1"
+ d="M348.911,169.42L220.258,91.062l81.133-67.164l128.732,79.217L348.911,169.42z M300.532,317.532
+ l123.547-72.331l-74.31-62.858l-120.961,73.191L300.532,317.532z M201.328,255.534L80.355,182.343L6.06,245.201l123.559,72.331
+ L201.328,255.534z M86.406,307.199v23.251l123.472,75.774V262.414l-81.989,67.168L86.406,307.199z M343.712,307.199l-41.453,22.388
+ l-82.001-67.173v143.811l123.454-75.774V307.199z M209.878,91.062l-81.135-67.164L0,103.115l81.226,66.305L209.878,91.062z"/>
+ </Icons.IconWrapper>
+ );
+ }
+}
+
+export default DropboxIcon;
diff --git a/examples/demo-app/src/components/icons/map-icon.js b/examples/demo-app/src/components/icons/map-icon.js
new file mode 100644
index 000000000..5a28231b6
--- /dev/null
+++ b/examples/demo-app/src/components/icons/map-icon.js
@@ -0,0 +1,67 @@
+// Copyright (c) 2018 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.
+
+import React, {Component} from 'react';
+import {Icons} from 'kepler.gl/components';
+import PropTypes from 'prop-types';
+
+class MapIcon extends Component {
+ static propTypes = {
+ /** Set the height of the icon, ex. '16px' */
+ height: PropTypes.string,
+ colors: PropTypes.arrayOf(PropTypes.string)
+ };
+
+ static defaultProps = {
+ height: '16px',
+ predefinedClassName: 'data-ex-icons-add',
+ totalColor: 1
+ };
+
+ render() {
+ return (
+ <Icons.IconWrapper {...this.props} viewBox={"0 0 602 602"}>
+ <g>
+ <path
+ d="M573.864,323.679l25.6-201.737L409.988,50.046L197.993,151.289L0,67.678l27.935,220.105L2.223,506.009l208.665,39.135
+ l200.136-38.125l189.865,43.823L573.864,323.679z M210.855,522.625L26.64,488.076l23.732-199.335L26.803,103.007l171.761,72.543
+ L410.987,74.083l164.331,62.361l-23.755,187.142l23.648,198.602l-163.764-37.782L210.855,522.625z"/>
+ <path
+ d="M506.021,405.449c-5.509,0-10.604,1.596-15.049,4.167c-17.531-12.832-35.583-27.904-36.47-47.735
+ c-1.217-27.195,15.439-53.227-3.623-78.182c-18.625-24.382-66.301-7.944-84.73-26.264c2.873-4.617,4.593-10.01,4.593-15.844
+ c0-16.671-13.519-30.192-30.187-30.192c-16.68,0-30.192,13.515-30.192,30.192c0,9.561,4.534,17.98,11.467,23.513
+ c-2.907,7.358-4.729,15.167-5.048,23.141c-0.496,12.596,3.121,25.126,0.391,37.634c-2.252,10.391-16.875,9.729-24.757,9.788
+ c-19.875,0.177-48.202-3.57-61.023,10.462c-3.783-2.843-8.207-4.812-13.077-5.621c-2.87-25.848,2.098-51.102-20.824-70.985
+ c-14.736-12.794-38.846-18.344-52.438-32.719c2.873-4.619,4.61-10.031,4.61-15.871c0-16.674-13.515-30.198-30.189-30.198
+ c-16.668,0-30.192,13.515-30.192,30.198c0,16.668,13.515,30.183,30.192,30.183c5.562,0,10.707-1.604,15.179-4.229
+ c10.048,10.083,23.915,16.784,36.892,23.56c16.529,8.627,28.844,19.698,31.108,39.283c1.241,10.734,0.762,21.291,1.46,31.854
+ c-12.135,3.918-20.978,15.16-20.978,28.602c0,16.681,13.515,30.192,30.195,30.192c16.668,0,30.189-13.512,30.189-30.192
+ c0-3.942-0.81-7.701-2.189-11.159c10.024-18.063,56.066-5.745,73.423-11.55c12.644-4.238,17.13-16.083,18.247-28.365
+ c1.063-11.473-2.637-22.757-0.91-34.283c0.686-4.69,1.867-9.224,3.439-13.55c1.644,0.271,3.311,0.502,5.024,0.502
+ c5.308,0,10.22-1.489,14.559-3.904c18.684,18.713,55.768,6.174,79.328,20.271c28.017,16.754-0.792,64.046,8.051,89.309
+ c6.123,17.472,22.13,30.499,37.994,42.232c-2.902,4.64-4.664,10.084-4.664,15.953c0,16.681,13.507,30.192,30.198,30.192
+ c16.657,0,30.192-13.512,30.192-30.192C536.213,418.979,522.689,405.449,506.021,405.449z"/>
+ </g>
+ </Icons.IconWrapper>
+ );
+ }
+}
+
+export default MapIcon;
diff --git a/examples/demo-app/src/components/load-data-modal/load-remote-map.js b/examples/demo-app/src/components/load-data-modal/load-remote-map.js
index bbb271f0f..5f094c579 100644
--- a/examples/demo-app/src/components/load-data-modal/load-remote-map.js
+++ b/examples/demo-app/src/components/load-data-modal/load-remote-map.js
@@ -18,6 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
+// TODO: this will move onto kepler.gl core
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';
diff --git a/examples/demo-app/src/components/sharing/cloud-storage.js b/examples/demo-app/src/components/sharing/cloud-storage.js
new file mode 100644
index 000000000..844af7b25
--- /dev/null
+++ b/examples/demo-app/src/components/sharing/cloud-storage.js
@@ -0,0 +1,172 @@
+// Copyright (c) 2018 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.
+
+import React from 'react';
+import styled from 'styled-components';
+import get from 'lodash.get';
+import {CopyToClipboard} from 'react-copy-to-clipboard';
+import {StyledModalContent} from 'kepler.gl/components';
+import CloudTile from './cloud-tile';
+import StatusPanel from './status-panel';
+import {AUTH_HANDLERS} from '../../utils/sharing/authentication';
+import {KEPLER_DISCLAIMER} from '../../constants/default-settings';
+import {getMapPermalink} from '../../utils/url';
+
+const StyledExportDataSection = styled.div`
+ display: flex;
+ flex-direction: row;
+ margin: 35px 0;
+ width: 100%;
+
+ .description {
+ .title {
+ font-weight: 500;
+ color: ${props => props.theme.textColorLT};
+ font-size: 12px;
+ }
+ .subtitle {
+ color: ${props => props.theme.textColor};
+ font-size: 11px;
+ }
+ }
+
+ .selection {
+ display: flex;
+ flex-wrap: wrap;
+ flex: 1;
+ padding-left: 50px;
+ }
+`;
+
+export const StyledInputLabel = styled.label`
+ font-size: 12px;
+ color: ${props => props.theme.textColorLT};
+ letter-spacing: 0.2px;
+`;
+
+const StyledInput = styled.input`
+ width: 100%;
+ padding: ${props => props.theme.inputPadding};
+ color: ${props => props.error ? 'red' : props.theme.titleColorLT};
+ height: ${props => props.theme.inputBoxHeight};
+ border: 0;
+ outline: 0;
+ font-size: 14px;
+
+ :active,
+ :focus,
+ &.focus,
+ &.active {
+ outline: 0;
+ }
+`;
+
+export const StyledBtn = styled.button`
+ background-color: ${props => props.theme.primaryBtnActBgd};
+ color: ${props => props.theme.primaryBtnActColor};
+ &:focus {
+ outline: none;
+ }
+`;
+
+export const StyleSharingUrl = styled.div`
+ width: 100%;
+ display: flex;
+ margin-bottom: 14px;
+ flex-direction: column;
+`;
+
+const SharingUrl = ({url, message}) => (
+ <StyleSharingUrl>
+ <StyledInputLabel>{message}</StyledInputLabel>
+ <div style={{display: 'flex'}}>
+ <StyledInput type="text" value={url}/>
+ <CopyToClipboard text={url}>
+ <StyledBtn>copy</StyledBtn>
+ </CopyToClipboard>
+ </div>
+
+ </StyleSharingUrl>
+);
+
+const ExportCloudModal = ({
+ isLoading,
+ info,
+ onExport,
+ onCloudLoginSuccess
+}) => {
+ const metaUrl = get(info, ['metadata', 'url']);
+ const sharingLink = metaUrl ? getMapPermalink(metaUrl) : null;
+ return (
+ <div className="export-data-modal">
+ <StyledModalContent>
+ <div style={{width: '100%'}}>
+ <StyledExportDataSection>
+ <div className="description">
+ <div className="title">
+ Save and share current map via URL
+ </div>
+ <div className="subtitle" style={{color: 'red', fontWeight: 500}}>
+ {KEPLER_DISCLAIMER}
+ </div>
+ </div>
+ </StyledExportDataSection>
+
+ <StyledExportDataSection>
+ <div className="description">
+ <div className="title">
+ Data Type
+ </div>
+ <div className="subtitle">
+ Choose the type of data you want to export
+ </div>
+ </div>
+ <div className="selection">
+ {Object.keys(AUTH_HANDLERS).map((name, index) => (
+ <CloudTile
+ key={index}
+ token={AUTH_HANDLERS[name].getAccessToken()}
+ onExport={onExport}
+ onLogin={() => AUTH_HANDLERS[name].handleLogin(onCloudLoginSuccess)}
+ Icon={AUTH_HANDLERS[name].icon}
+ />
+ ))}
+ </div>
+ </StyledExportDataSection>
+ <StyledExportDataSection>
+ <div className="selection">
+ <div style={{margin: 'auto', width: '100%'}}>
+ {isLoading && (
+ <StatusPanel isLoading={isLoading} {...info} />
+ )}
+ {metaUrl && [
+ (<SharingUrl key={0} url={sharingLink} message={'Share your map with other users'}/>),
+ (<SharingUrl key={1} url={metaUrl} message={'Your new saved configuration'}/>)
+ ]}
+ </div>
+ </div>
+ </StyledExportDataSection>
+ </div>
+ </StyledModalContent>
+ </div>
+ )
+};
+
+export default ExportCloudModal;
diff --git a/examples/demo-app/src/components/sharing/cloud-tile.js b/examples/demo-app/src/components/sharing/cloud-tile.js
new file mode 100644
index 000000000..aa176d4f6
--- /dev/null
+++ b/examples/demo-app/src/components/sharing/cloud-tile.js
@@ -0,0 +1,81 @@
+// Copyright (c) 2018 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.
+
+import React from 'react';
+import styled from 'styled-components';
+
+const StyledTileWrapper = styled.div`
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ border-radius: 2px;
+ border: 1px solid ${props => props.selected ? props.theme.primaryBtnBgd : props.theme.selectBorderColorLT};
+ color: ${props => props.selected ? props.theme.primaryBtnBgd : props.theme.selectBorderColorLT};
+ cursor: pointer;
+ font-weight: 500;
+ width: 120px;
+ height: 120px;
+ background-color: #ffffff;
+
+ :hover {
+ color: ${props => props.available && props.theme.primaryBtnBgd};
+ border: 1px solid ${props => props.available && props.theme.primaryBtnBgd};
+ }
+`;
+
+const StyledLabel = styled.div`
+ font-size: 14px;
+ color: ${props => props.theme.textColorLT};
+ letter-spacing: 0.2px;
+ text-align: center;
+ ul {
+ padding-left: 12px;
+ }
+`;
+
+const StyledTile = styled.div`
+ width: 64px;
+ margin: 12px;
+`;
+
+const TileButton = styled.button`
+ background-color: transparent;
+ border-width: 0;
+ cursor: pointer;
+ padding: 0;
+ outline: 0;
+`;
+
+const CloudTile = ({token, onExport, onLogin, Icon}) => {
+ return (
+ <StyledTileWrapper>
+ <StyledTile>
+ <div>
+ <TileButton onClick={token ? onExport : onLogin}>
+ <Icon height="64px" />
+ <StyledLabel>{token ? 'Upload' : 'Login'}</StyledLabel>
+ </TileButton>
+ </div>
+ </StyledTile>
+ </StyledTileWrapper>
+ );
+};
+
+export default CloudTile;
diff --git a/examples/demo-app/src/components/sharing/export-url-modal.js b/examples/demo-app/src/components/sharing/export-url-modal.js
new file mode 100644
index 000000000..759ab3bb2
--- /dev/null
+++ b/examples/demo-app/src/components/sharing/export-url-modal.js
@@ -0,0 +1,48 @@
+// Copyright (c) 2018 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.
+
+import React from 'react';
+import {Modal} from 'kepler.gl/components';
+import CloudStorage from './cloud-storage';
+
+const ExportUrlModal = ({
+ sharing,
+ isOpen,
+ onClose,
+ onExport,
+ onCloudLoginSuccess,
+ parentSelector
+}) => (
+ <Modal
+ isOpen={isOpen}
+ close={onClose}
+ title={'Save / Share your map'}
+ parentSelector={parentSelector}
+ >
+ <CloudStorage
+ isLoading={sharing.isLoading}
+ info={sharing.info}
+ onExport={onExport}
+ onCloudLoginSuccess={onCloudLoginSuccess}
+ />
+ </Modal>
+);
+
+export default ExportUrlModal;
diff --git a/examples/demo-app/src/components/sharing/status-panel.js b/examples/demo-app/src/components/sharing/status-panel.js
new file mode 100644
index 000000000..b527db63f
--- /dev/null
+++ b/examples/demo-app/src/components/sharing/status-panel.js
@@ -0,0 +1,129 @@
+// Copyright (c) 2018 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.
+
+import React from 'react';
+import styled from 'styled-components';
+import MapIcon from '../icons/map-icon';
+
+const containerSize = 128;
+const spinnerBorderSize = 10;
+const tileWrapperSize = containerSize - 2 * spinnerBorderSize;
+const tileSize = containerSize * 0.6;
+
+const spinnerBorderColor = 'rgba(128, 128, 128, 0.2)';
+
+const StyledWrapper = styled.div`
+ font-size: 14px;
+ font-weight: 500;
+ color: #3A414C;
+ display: flex;
+ position: relative;
+ align-items: center;
+ flex-direction: column;
+
+ .title {
+ margin-bottom: 12px;
+ }
+
+ .subtitle {
+ font-size: 12px;
+ }
+`;
+
+const StyledTileWrapper = styled.div`
+ position: relative;
+ width: ${containerSize}px;
+ height: ${containerSize}px;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ text-align: center;
+ margin: 0 auto;
+
+ .loader,
+ .loader:after {
+ border-radius: 50%;
+ width: ${tileWrapperSize}px;
+ height: ${tileWrapperSize}px;
+ }
+ .loader {
+ margin: 0 auto;
+ font-size: 10px;
+ position: absolute;
+ text-indent: -9999em;
+ border: ${spinnerBorderSize}px solid ${spinnerBorderColor};
+ border-left: ${spinnerBorderSize}px solid #D6D6D6;
+ -webkit-transform: translateZ(0);
+ -ms-transform: translateZ(0);
+ transform: translateZ(0);
+ -webkit-animation: load8 2.0s infinite linear;
+ animation: load8 2.0s infinite linear;
+ }
+ @-webkit-keyframes load8 {
+ 0% {
+ -webkit-transform: rotate(0deg);
+ transform: rotate(0deg);
+ }
+ 100% {
+ -webkit-transform: rotate(360deg);
+ transform: rotate(360deg);
+ }
+ }
+ @keyframes load8 {
+ 0% {
+ -webkit-transform: rotate(0deg);
+ transform: rotate(0deg);
+ }
+ 100% {
+ -webkit-transform: rotate(360deg);
+ transform: rotate(360deg);
+ }
+ }
+`;
+
+const StyledTile = styled.div`
+ overflow: hidden;
+ opacity: 0.9;
+ transition: opacity 0.4s ease;
+ line-height: 0;
+ text-align: center;
+ width: ${tileSize}px;
+ height: ${tileSize}px;
+`;
+
+const StatusPanel = ({filename, isLoading, status, metadata}) => (
+ <StyledWrapper>
+ <div className="title">
+ {`${isLoading ? 'Loading' : status} ${filename} onto your cloud account`}
+ </div>
+ <StyledTileWrapper>
+ <div className="loader" />
+ <StyledTile>
+ <MapIcon width="100%" height="100%" />
+ </StyledTile>
+ </StyledTileWrapper>
+ <div className="subtitle">
+ {metadata && metadata.url}
+ </div>
+
+ </StyledWrapper>
+);
+
+export default StatusPanel;
diff --git a/examples/demo-app/src/constants/default-settings.js b/examples/demo-app/src/constants/default-settings.js
index 28cecc66b..0cbd77bb6 100644
--- a/examples/demo-app/src/constants/default-settings.js
+++ b/examples/demo-app/src/constants/default-settings.js
@@ -23,14 +23,20 @@ and segments both use queryRunner */
import keyMirror from 'keymirror';
export const ASSETS_URL = 'https://d1a3f4spazzrp4.cloudfront.net/kepler.gl/';
-
export const DATA_URL = 'https://raw.githubusercontent.com/uber-web/kepler.gl-data/master/';
-
+export const MAP_URI = 'map?mapUrl=';
/*
* If you want to add more samples, feel free to edit the json file on github kepler.gl data repo
*/
export const MAP_CONFIG_URL = `${DATA_URL}samples.json?nocache=${(new Date()).getTime()}`;
+/**
+ * I know this is already defined in Kepler core but it should be defined here
+ * because it belongs to the demo app
+ * @type {string}
+ */
+export const KEPLER_GL_WEBSITE = 'http://kepler.gl/';
+
export const QUERY_TYPES = keyMirror({
file: null,
sample: null
@@ -88,5 +94,6 @@ export const LOADING_SAMPLE_LIST_ERROR_MESSAGE = 'Not able to load sample galler
export const LOADING_SAMPLE_ERROR_MESSAGE = 'Not able to load sample';
export const LOADING_URL_MESSAGE = 'You can use the following formats: CSV | JSON | Kepler.gl config json. Make sure the url contains the file extension.';
export const CORS_LINK = 'https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS';
+export const KEPLER_DISCLAIMER = '* Kepler.gl will save your map data to your personal cloud storage, only people with the URL can access your map and data.';
export const DEFAULT_LOADING_METHOD = LOADING_METHODS[0];
diff --git a/examples/demo-app/src/main.js b/examples/demo-app/src/main.js
index a33de863b..8b5324ea2 100644
--- a/examples/demo-app/src/main.js
+++ b/examples/demo-app/src/main.js
@@ -21,23 +21,38 @@
import React from 'react';
import document from 'global/document';
import {Provider} from 'react-redux';
-import {hashHistory, Router, Route} from 'react-router';
+import {browserHistory, Router, Route} from 'react-router';
import {syncHistoryWithStore} from 'react-router-redux';
import {render} from 'react-dom';
import store from './store';
import App from './app';
-// import {getAppUrlPrefix} from './constants/default-settings';
+import { AUTH_HANDLERS } from "./utils/sharing/authentication";
-const history = syncHistoryWithStore(hashHistory, store);
-// const prefix = getAppUrlPrefix();
-// const path = prefix === '' ? '(:id)' : `${prefix}(/:id)`;
+const history = syncHistoryWithStore(browserHistory, store);
+
+const onEnterCallback = (nextState, transition, callback) => {
+ // TODO: detect auth provider
+ const defaultProvider = 'dropbox';
+ const authProvider = AUTH_HANDLERS[defaultProvider];
+
+ // Check if the current tab was opened by our previous tab
+ if (window.opener) {
+ const { location } = nextState;
+ const token = authProvider.getAccessTokenFromLocation(location);
+ window.opener.postMessage({token}, location.origin);
+ }
+
+ callback();
+};
const Root = () => (
<Provider store={store}>
<Router history={history}>
- <Route name="map" path="/" component={App} />
- <Route name="demo" path="/demo/(:id)" component={App} />
- <Route name="map" path="/map" component={App} />
+ <Route path="/auth" component={App} onEnter={onEnterCallback} />
+ <Route path="/demo/(:id)" component={App} />
+ <Route path="/map" component={App} />
+ <Route path="/" component={App} />
+ <Route path="*" component={App} />
</Router>
</Provider>
);
diff --git a/examples/demo-app/src/reducers.js b/examples/demo-app/src/reducers/index.js
similarity index 85%
rename from examples/demo-app/src/reducers.js
rename to examples/demo-app/src/reducers/index.js
index 05ed7d8a3..6f8c7bdca 100644
--- a/examples/demo-app/src/reducers.js
+++ b/examples/demo-app/src/reducers/index.js
@@ -25,26 +25,18 @@ import keplerGlReducer, {combineUpdaters} from 'kepler.gl/reducers';
import Processor from 'kepler.gl/processors';
import KeplerGlSchema from 'kepler.gl/schemas';
+import sharingReducer from './sharing';
+
import {
INIT,
SET_LOADING_METHOD,
LOAD_MAP_SAMPLE_FILE,
LOAD_REMOTE_RESOURCE_SUCCESS,
- SET_SAMPLE_LOADING_STATUS, LOAD_REMOTE_RESOURCE_ERROR
-} from './actions';
-
-import {DEFAULT_LOADING_METHOD, LOADING_METHODS} from './constants/default-settings';
+ SET_SAMPLE_LOADING_STATUS
+} from '../actions';
-/**
- * Generate a hash string based on number of character
- * @param {number} count
- * @returns {string} hash string
- */
-function generateHashId(count) {
- return Math.random()
- .toString(36)
- .substr(count);
-}
+import {DEFAULT_LOADING_METHOD, LOADING_METHODS} from '../constants/default-settings';
+import { generateHashId } from '../utils/strings';
// INITIAL_APP_STATE
const initialAppState = {
@@ -54,7 +46,7 @@ const initialAppState = {
currentOption: DEFAULT_LOADING_METHOD.options[0],
previousMethod: null,
sampleMaps: [], // this is used to store sample maps fetch from a remote json file
- isMapLoading: false, // determine whether we are loading a sample map
+ isMapLoading: false, // determine whether we are loading a sample map,
error: null // contains error when loading/retrieving data/configuration
// {
// status: null,
@@ -64,7 +56,7 @@ const initialAppState = {
// App reducer
export const appReducer = handleActions({
- [INIT]: (state, action) => ({
+ [INIT]: (state) => ({
...state,
loaded: true
}),
@@ -81,12 +73,6 @@ export const appReducer = handleActions({
[SET_SAMPLE_LOADING_STATUS]: (state, action) => ({
...state,
isMapLoading: action.isMapLoading
- }),
- [LOAD_REMOTE_RESOURCE_ERROR]: (state, action) => ({
- ...state,
- error: action.error,
- currentOption: {dataUrl: action.url},
- isMapLoading: false
})
}, initialAppState);
@@ -95,7 +81,8 @@ export const appReducer = handleActions({
const demoReducer = combineReducers({
// mount keplerGl reducer
keplerGl: keplerGlReducer,
- app: appReducer
+ app: appReducer,
+ sharing: sharingReducer
});
// this can be moved into a action and call kepler.gl action
@@ -105,7 +92,7 @@ const demoReducer = combineReducers({
* @param action {map: resultset, config, map}
* @returns {{app: {isMapLoading: boolean}, keplerGl: {map: (state|*)}}}
*/
-export const loadRemoteFileDataSuccess = (state, action) => {
+export const loadRemoteResourceSuccess = (state, action) => {
// TODO: replace generate with a different function
const datasetId = action.options.id || generateHashId(6);
const {dataUrl} = action.options;
@@ -149,7 +136,7 @@ export const loadRemoteFileDataSuccess = (state, action) => {
};
const composedUpdaters = {
- [LOAD_REMOTE_RESOURCE_SUCCESS]: loadRemoteFileDataSuccess
+ [LOAD_REMOTE_RESOURCE_SUCCESS]: loadRemoteResourceSuccess
};
const composedReducer = (state, action) => {
diff --git a/examples/demo-app/src/reducers/sharing.js b/examples/demo-app/src/reducers/sharing.js
new file mode 100644
index 000000000..d8f676bcf
--- /dev/null
+++ b/examples/demo-app/src/reducers/sharing.js
@@ -0,0 +1,57 @@
+// Copyright (c) 2018 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.
+
+import {handleActions} from 'redux-actions';
+import { AUTH_HANDLERS } from '../utils/sharing/authentication';
+import { CLOUD_LOGIC_SUCCESS, LOAD_REMOTE_RESOURCE_ERROR, PUSHING_FILE } from '../actions';
+
+const readAuthTokens = () => Object.keys(AUTH_HANDLERS)
+ .reduce((tokens, name) => ({
+ ...tokens,
+ [name]: AUTH_HANDLERS[name].getAccessToken()
+ }), {});
+
+const sharingInitialState = {
+ isLoading: false,
+ status: null,
+ info: null,
+ tokens: readAuthTokens()
+};
+
+// file upload reducer
+export const sharingReducer = handleActions({
+ [LOAD_REMOTE_RESOURCE_ERROR]: (state, action) => ({
+ ...state,
+ error: action.error,
+ currentOption: {dataUrl: action.url},
+ isMapLoading: false
+ }),
+ [PUSHING_FILE]: (state, action) => ({
+ ...state,
+ isLoading: action.isLoading,
+ info: action.metadata
+ }),
+ [CLOUD_LOGIC_SUCCESS]: state => ({
+ ...state,
+ tokens: readAuthTokens()
+ })
+}, sharingInitialState);
+
+export default sharingReducer;
diff --git a/examples/demo-app/src/store.js b/examples/demo-app/src/store.js
index c6b08d83b..e52f48f83 100644
--- a/examples/demo-app/src/store.js
+++ b/examples/demo-app/src/store.js
@@ -20,13 +20,13 @@
import {combineReducers, createStore, applyMiddleware, compose} from 'redux';
import {routerReducer, routerMiddleware} from 'react-router-redux';
-import {hashHistory} from 'react-router';
+import {browserHistory} from 'react-router';
import thunk from 'redux-thunk';
import window from 'global/window';
import {taskMiddleware} from 'react-palm/tasks';
-import demoReducer from './reducers';
+import demoReducer from './reducers/index';
const reducers = combineReducers({
demo: demoReducer,
@@ -36,7 +36,7 @@ const reducers = combineReducers({
export const middlewares = [
taskMiddleware,
thunk,
- routerMiddleware(hashHistory)
+ routerMiddleware(browserHistory)
];
export const enhancers = [applyMiddleware(...middlewares)];
diff --git a/examples/demo-app/src/utils/sharing/authentication.js b/examples/demo-app/src/utils/sharing/authentication.js
new file mode 100644
index 000000000..ba4889d54
--- /dev/null
+++ b/examples/demo-app/src/utils/sharing/authentication.js
@@ -0,0 +1,25 @@
+// Copyright (c) 2018 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.
+
+import DropboxHandler from './dropbox';
+
+export const AUTH_HANDLERS = {
+ [DropboxHandler.name]: DropboxHandler
+};
diff --git a/examples/demo-app/src/utils/sharing/dropbox.js b/examples/demo-app/src/utils/sharing/dropbox.js
new file mode 100644
index 000000000..922284664
--- /dev/null
+++ b/examples/demo-app/src/utils/sharing/dropbox.js
@@ -0,0 +1,158 @@
+// Copyright (c) 2018 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.
+
+// DROPBOX
+import {Dropbox} from 'dropbox';
+import {parseQueryString} from '../url';
+import window from 'global/window'
+import DropboxIcon from '../../components/icons/dropbox-icon';
+
+const DROPBOX_CLIEND_ID = process.env.DropboxClientId;
+const NAME = 'dropbox';
+const DOMAIN = 'www.dropbox.com';
+const CORS_FREE_DOMAIN = 'dl.dropboxusercontent.com';
+const dropbox = new Dropbox({clientId: DROPBOX_CLIEND_ID});
+
+/**
+ * Generate auth link url to open to be used to handle OAuth2
+ * @param {string} path
+ */
+function authLink(path = 'auth') {
+ return dropbox.getAuthenticationUrl(
+ `${window.location.origin}/${path}`,
+ btoa(JSON.stringify({handler: 'dropbox', origin: window.location.origin}))
+ )
+}
+
+/**
+ * This method will extract the atuch token from the third party service callback url. Default: Dropbox
+ * @param {object} location the window location provided by react router
+ * @returns {?string} the token extracted from the oauth 2 callback URL
+ */
+function getAccessTokenFromLocation(location) {
+ if (!(location && location.hash.length)) {
+ return null;
+ }
+ // dropbox token usually start with # therefore we want to remore the '#'
+ const query = window.location.hash.substring(1);
+
+ return parseQueryString(query).access_token;
+}
+
+/**
+ *
+ * @param blob to upload
+ * @param name if blob doesn't contain a file name, this field is used
+ * @param isPublic define whether the file will be available pubblicaly once uploaded
+ * @returns {Promise<DropboxTypes.files.FileMetadata>}
+ */
+function uploadFile({blob, name, isPublic = true}) {
+ const promise = dropbox.filesUpload({
+ path: `/keplergl/${blob.name || name}`,
+ contents: blob
+ });
+
+ return !isPublic ? promise : promise.then(shareFile);
+}
+
+/**
+ * It will set access to file to public
+ * @param {Object} metadata metadata response from uploading the file
+ * @returns {Promise<DropboxTypes.sharing.FileLinkMetadataReference | DropboxTypes.sharing.FolderLinkMetadataReference | DropboxTypes.sharing.SharedLinkMetadataReference>}
+ */
+function shareFile(metadata) {
+ return dropbox.sharingCreateSharedLinkWithSettings({
+ path: metadata.path_display || metadata.path_lower
+ }).then(
+ // Update URL to avoid CORS issue
+ // Unfortunately this is not the ideal scenario but it will make sure people
+ // can share dropbox urls with users without the dropbox account (publish on twitter, facebook)
+ result => ({
+ ...result,
+ url: overrideUrl(result.url)
+ })
+ );
+}
+
+/**
+ * Override dropbox sharing url
+ * https://www.dropbox.com/s/bxwwdb81z0jg7pb/keplergl_2018-11-01T23%3A22%3A43.940Z.json?dl=0
+ * ->
+ * https://dl.dropboxusercontent.com/s/bxwwdb81z0jg7pb/keplergl_2018-11-01T23%3A22%3A43.940Z.json
+ * @param metadata
+ * @returns {DropboxTypes.sharing.FileLinkMetadataReference}
+ */
+function overrideUrl(url) {
+ return url ? url.slice(0, url.indexOf('?')).replace(DOMAIN, CORS_FREE_DOMAIN) : null;
+}
+
+/**
+ * This method will handle the oauth flow by performing the following steps:
+ * - Opening a new window
+ * - Subscribe to message channel
+ * - Receive the token when ready
+ * - Close the opened tab
+ */
+function handleLogin(onCloudLoginSuccess) {
+ const link = authLink();
+ const authWindow = window.open(link, '_blank', 'width=800,height=600');
+ const handleToken = e => {
+ // TODO: add security step to validate which domain the message is coming from
+ authWindow.close();
+ window.removeEventListener('message', handleToken);
+ dropbox.setAccessToken(e.data.token);
+ if (window.localStorage) {
+ window.localStorage.setItem('dropbox', JSON.stringify({
+ // dropbox token doesn't expire unless revoked by the user
+ token: e.data.token,
+ timetamp: new Date()
+ }));
+ }
+ onCloudLoginSuccess();
+ };
+ window.addEventListener('message', handleToken);
+}
+
+/**
+ * Provides the current dropbox auth token. If stored in localStorage is set onto dropbox handler and returned
+ * @returns {any}
+ */
+function getAccessToken() {
+ let token = dropbox.getAccessToken();
+ if (!token && window.localStorage) {
+ const jsonString = window.localStorage.getItem('dropbox');
+ token = jsonString && JSON.parse(jsonString).token;
+ if (token) {
+ dropbox.setAccessToken(token);
+ }
+ }
+
+ return (token || '') !== '' ? token : null;
+}
+
+// All sharing providers must implement the following properties
+export default {
+ name: NAME,
+ getAccessTokenFromLocation,
+ handleLogin,
+ uploadFile,
+ getAccessToken,
+ icon: DropboxIcon
+};
diff --git a/examples/demo-app/src/utils/strings.js b/examples/demo-app/src/utils/strings.js
new file mode 100644
index 000000000..eec3f58e0
--- /dev/null
+++ b/examples/demo-app/src/utils/strings.js
@@ -0,0 +1,10 @@
+/**
+ * Generate a hash string based on number of character
+ * @param {number} count
+ * @returns {string} hash string
+ */
+export function generateHashId(count) {
+ return Math.random()
+ .toString(36)
+ .substr(count);
+}
diff --git a/examples/demo-app/src/utils/url.js b/examples/demo-app/src/utils/url.js
new file mode 100644
index 000000000..6447c44fc
--- /dev/null
+++ b/examples/demo-app/src/utils/url.js
@@ -0,0 +1,42 @@
+// Copyright (c) 2018 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.
+
+import {MAP_URI} from '../constants/default-settings';
+
+export function parseQueryString(query) {
+ const searchParams = new URLSearchParams(query);
+ const params = [...searchParams].reduce((queryParams, entry) => ({
+ ...queryParams,
+ ...(entry && entry.length === 2 ?
+ {[entry[0]]: entry[1]} : null
+ )
+ }), {});
+
+ return params;
+}
+
+/**
+ * Returns a permalink with the given map url: kepler.gl/[]
+ * @param mapLink the sharing url used to store the map
+ * @returns {string}
+ */
+export function getMapPermalink(mapLink) {
+ return `${window.location.protocol}//${window.location.host}/${MAP_URI}${mapLink}`
+}
diff --git a/examples/demo-app/webpack.config.js b/examples/demo-app/webpack.config.js
index 1461b1b1f..9e699ee9e 100644
--- a/examples/demo-app/webpack.config.js
+++ b/examples/demo-app/webpack.config.js
@@ -60,9 +60,14 @@ const CONFIG = {
fs: 'empty'
},
+ // to support browser history api and remove the '#' sign
+ devServer: {
+ historyApiFallback: true,
+ },
+
// Optional: Enables reading mapbox token from environment variable
plugins: [
- new webpack.EnvironmentPlugin(['MapboxAccessToken'])
+ new webpack.EnvironmentPlugin(['MapboxAccessToken', 'DropboxClientId'])
]
};
diff --git a/examples/webpack.config.local.js b/examples/webpack.config.local.js
index 42d88bfd3..479da1bb2 100644
--- a/examples/webpack.config.local.js
+++ b/examples/webpack.config.local.js
@@ -74,7 +74,7 @@ function makeLocalDevConfig(EXAMPLE_DIR = LIB_DIR) {
},
// Optional: Enables reading mapbox token from environment variable
plugins: [
- new webpack.EnvironmentPlugin(['MapboxAccessToken'])
+ new webpack.EnvironmentPlugin(['MapboxAccessToken', 'DropboxClientId'])
]
};
}
diff --git a/src/components/common/modal.js b/src/components/common/modal.js
index 1f2e2de0c..1eb1a39a8 100644
--- a/src/components/common/modal.js
+++ b/src/components/common/modal.js
@@ -29,7 +29,7 @@ import {Button} from 'components/common/styled-components';
const ModalContentWrapper = styled.div`
width: 60%;
max-width: 960px;
- padding: 40px 96px;
+ padding: 24px 24px 40px;
position: absolute;
top: 92px;
left: 0;
@@ -51,11 +51,6 @@ const CloseButton = styled.div`
color: ${props => props.theme.titleColorLT};
display: flex;
justify-content: flex-end;
- left: 0;
- padding: 24px;
- position: absolute;
- top: 0;
- width: 100%;
z-index: 10005;
:hover {
@@ -124,7 +119,7 @@ export const ModalFooter = ({
</FooterActionWrapper>
</StyledModalFooter>
);
-}
+};
class ModalDialog extends Component {
static propTypes = {
@@ -160,7 +155,9 @@ class ModalDialog extends Component {
backgroundColor: 'rgba(0, 0, 0, 0.5)',
zIndex: 10000,
overflowY: 'auto',
- position: 'absolute'
+ position: 'absolute',
+ // in case we want to override the modal dialog style
+ ...props.style
}
}}
>
@@ -169,23 +166,26 @@ class ModalDialog extends Component {
cssStyle={props.cssStyle}
footer={props.footer}
>
- {props.close ? (
+ {props.close && (
<CloseButton className="modal--close" onClick={props.close}>
<Delete height="14px" />
</CloseButton>
- ) : null}
- {props.title ? (
- <ModalTitle className="modal--title">{props.title}</ModalTitle>
- ) : null}
- <ModalContent className="content">{props.children}</ModalContent>
- {props.footer ? (
- <ModalFooter
- cancel={props.close}
- confirm={props.onConfirm}
- cancelButton={props.cancelButton}
- confirmButton={props.confirmButton}
- />
- ) : null}
+ )}
+ <div style={{padding: '0px 72px'}}>
+ {props.title && (
+ <ModalTitle className="modal--title">{props.title}</ModalTitle>
+ )}
+ <ModalContent className="content">{props.children}</ModalContent>
+ {props.footer && (
+ <ModalFooter
+ cancel={props.close}
+ confirm={props.onConfirm}
+ cancelButton={props.cancelButton}
+ confirmButton={props.confirmButton}
+ />
+ )}
+ </div>
+
</ModalContentWrapper>
</Modal>
);
diff --git a/src/components/kepler-gl.js b/src/components/kepler-gl.js
index 41c512cf5..b3e60045a 100644
--- a/src/components/kepler-gl.js
+++ b/src/components/kepler-gl.js
@@ -44,6 +44,8 @@ import {generateHashId} from 'utils/utils';
import {theme} from 'styles/base';
+// Maybe we should think about exporting this or creating a variable
+// as part of the base.js theme
const GlobalStyle = styled.div`
font-family: ff-clan-web-pro, 'Helvetica Neue', Helvetica, sans-serif;
font-weight: 400;
@@ -149,6 +151,7 @@ function KeplerGlFactory(
_requestMapStyle = (mapStyle) => {
const {url, id} = mapStyle;
+
const downloadUrl = isValidStyleUrl(url) ?
getStyleDownloadUrl(url, this.props.mapboxApiAccessToken) : url;
diff --git a/src/components/modal-container.js b/src/components/modal-container.js
index 13bca67b9..ad1f2702c 100644
--- a/src/components/modal-container.js
+++ b/src/components/modal-container.js
@@ -361,6 +361,9 @@ export default function ModalContainerFactory(
}
};
break;
+
+ // TODO: add this options once we merge dropbox onto kepelr.gl core
+ // case SAVE_TO_CLOUD_ID
default:
break;
}
diff --git a/src/components/modals/data-table-modal.js b/src/components/modals/data-table-modal.js
index 1f13184ca..625216128 100644
--- a/src/components/modals/data-table-modal.js
+++ b/src/components/modals/data-table-modal.js
@@ -115,6 +115,7 @@ export class DataTableModal extends Component {
}
const activeDataset = datasets[dataId];
+ // TODO: this should be all data
const rows = activeDataset.data;
const columns = activeDataset.fields
.map((field, i) => ({
diff --git a/src/index.js b/src/index.js
index c15c97336..58e3fe5cc 100644
--- a/src/index.js
+++ b/src/index.js
@@ -40,7 +40,7 @@ export * from './components';
export * from './layers';
// Styles
-export * from './styles/base';
+export * from './styles';
// Default export
export {default} from './components';
diff --git a/website/src/content.js b/website/src/content.js
index d38a44c10..65b2941d6 100644
--- a/website/src/content.js
+++ b/website/src/content.js
@@ -177,43 +177,43 @@ export const EXAMPLES = [
title: 'California Earthquakes',
description: 'Location, maginitude and magtype of 2.5+ magnitude earthquakes in california',
image: cdnUrl('examples/cali-earthquakes.png'),
- url: '#/demo/earthquakes'
+ url: '/demo/earthquakes'
},
{
title: 'New York City Cab Rides',
description: 'A small sample of yellow and green taxi trip records in New York City',
image: cdnUrl('examples/ny-taxis.png'),
- url: '#/demo/nyctrips'
+ url: '/demo/nyctrips'
},
{
title: 'San Francisco Elevation Contour',
description: 'Elevation contours of San Francisco mainland and Treasure Island/Yerba Island',
image: cdnUrl('examples/sf-elevation.png'),
- url: '#/demo/sfcontour'
+ url: '/demo/sfcontour'
},
{
title: 'Travel Times from Uber Movement',
description: 'Pittsburgh travel times before and during heavy inclement weather conditions',
image: cdnUrl('examples/movement-pittsburgh.png'),
- url: '#/demo/movement_pittsburgh'
+ url: '/demo/movement_pittsburgh'
},
{
title: 'New york city population',
description: 'This dataset contains the 2010 Census tract population data of NYC',
image: cdnUrl('examples/ny-population.png'),
- url: '#/demo/nyc_census'
+ url: '/demo/nyc_census'
},
{
title: 'San Francisco Street Tree Map',
description: 'A 3d hexbin density map showing every single streets in San Francisco',
image: cdnUrl('examples/sf-street-trees.png'),
- url: '#/demo/sftrees'
+ url: '/demo/sftrees'
},
{
title: 'Commute Patterns in the UK',
description: 'A origin destination map using 3d arcs to show commute patterns of England and Wales residence',
image: cdnUrl('examples/uk-commute.png'),
- url: '#/demo/ukcommute'
+ url: '/demo/ukcommute'
}
];
diff --git a/website/webpack.config.js b/website/webpack.config.js
index 544d173ad..48da3d5cb 100644
--- a/website/webpack.config.js
+++ b/website/webpack.config.js
@@ -89,7 +89,7 @@ const COMMON_CONFIG = {
// Optional: Enables reading mapbox token from environment variable
plugins: [
- new webpack.EnvironmentPlugin(['MapboxAccessToken'])
+ new webpack.EnvironmentPlugin(['MapboxAccessToken', 'DropboxClientId'])
]
};