Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
[Chore] Dropbox enhancements (#445)
Giuseppe Macrì222dbe3ce8a1
diff --git a/docs/user-guides/k-save-and-export.md b/docs/user-guides/k-save-and-export.mdindex af87705c6..cb998b3ef 100644--- a/docs/user-guides/k-save-and-export.md+++ b/docs/user-guides/k-save-and-export.md@@ -10,6 +10,8 @@ However, in the demo app, you can:- [Export filtered or unfiltered data as a csv](#export-data).- [Export current map configuration as a `json` file](#export-config), this file does not contain any map data.- [Export current map configuration __AND__ map data as a `json` file](#export-config), which can be loaded back to kepler.gl to reproduce the current map.+- [Export current map to html file](#export-map-as-html)+- [Export current map to Dropbox](#export-dropbox), which can be used to share your maps with other users via permalink## <a href="#export-image">Export Image</a>@@ -45,7 +47,7 @@ To save and export your current map as HTML file, click on __Export Map__ and suKepler.gl is providing with a temporary Mapbox token to use in your html file but we strongly recommend to use your own. The provided token has a limited duration and will be periodically replaced with a new onewithout any notification.-#### How to update an exported map token+### How to update an exported map tokenIn order to edit the mapbox token in your html file you simply need to perform the following steps:1. [Create a new mapbox token](https://docs.mapbox.com/help/how-mapbox-works/access-tokens/) or use your existing one.2. Open the kepler.gl.map file with your favorite text editor.@@ -64,4 +66,11 @@ In order to edit the mapbox token in your html file you simply need to perform tconst MAPBOX_TOKEN = 'pk.eyJ1IjoidWJlcmRh...';```+## <a href="#export-dropbox">Export current Map as HTML</a>++To export the current map into your Dropbox account, click on __Save Map Url__ and select Dropbox as your cloud storage.+Perform the authentication against Dropbox using your credentials. Once the authentication process is completed,+click on __Upload__ and Kepler.gl will push your current map onto your account.++At the end of the process Kepler.gl will automatically generate a permalink for your work you can share with other users.diff --git a/examples/demo-app/src/actions.js b/examples/demo-app/src/actions.jsindex fce392e2e..c31de993f 100644--- a/examples/demo-app/src/actions.js+++ b/examples/demo-app/src/actions.js@@ -359,7 +359,7 @@ export function exportFileToCloud(handlerName = 'dropbox') {// extract data from keplerconst data = KeplerGlSchema.save(getState().demo.keplerGl.map);const newBlob = new Blob([JSON.stringify(data)], {type: 'application/json'});- const file = new File([newBlob], `keplergl_${generateHashId(6)}.json`);+ const file = new File([newBlob], `/keplergl_${generateHashId(6)}.json`);// We are gonna pass the correct auth token to init the cloud providerdispatch(setPushingFile(true, {filename: file.name, status: 'uploading', metadata: null}));authHandler.uploadFile({blob: file, isPublic: true, authHandler})@@ -377,7 +377,14 @@ export function exportFileToCloud(handlerName = 'dropbox') {}export function setCloudLoginSuccess() {- return {- type: CLOUD_LOGIN_SUCCESS+ return dispatch => {+ dispatch({type: CLOUD_LOGIN_SUCCESS}).then(+ () => {+ dispatch(exportFileToCloud());+ },+ () => {+ dispatch(setPushingFile(false, {filename: null, status: 'error', error: 'not able to propagate login successfully'}));+ }+ );};}diff --git a/examples/demo-app/src/app.js b/examples/demo-app/src/app.jsindex 0fb74f896..02192b075 100644--- a/examples/demo-app/src/app.js+++ b/examples/demo-app/src/app.js@@ -28,6 +28,7 @@ import {theme} from 'kepler.gl/styles';import Banner from './components/banner';import Announcement from './components/announcement';import {replaceLoadDataModal} from './factories/load-data-modal';+import {replaceSaveMap} from './factories/save-map';import ExportUrlModal from './components/sharing/export-url-modal';import {AUTH_TOKENS} from './constants/default-settings';import {@@ -38,7 +39,8 @@ import {} from './actions';const KeplerGl = require('kepler.gl/components').injectComponents([- replaceLoadDataModal()+ replaceLoadDataModal(),+ replaceSaveMap()]);// Sample datadiff --git a/examples/demo-app/src/components/sharing/cloud-storage.js b/examples/demo-app/src/components/sharing/cloud-storage.jsindex 8c22e7e90..b50d2c3ea 100644--- a/examples/demo-app/src/components/sharing/cloud-storage.js+++ b/examples/demo-app/src/components/sharing/cloud-storage.js@@ -113,6 +113,8 @@ const ExportCloudModal = ({onCloudLoginSuccess}) => {const metaUrl = get(info, ['metadata', 'url']);+ const error = get(info, ['error']);+ const folderLink = get(info, ['metadata', 'folder_link']);const sharingLink = metaUrl ? getMapPermalink(metaUrl) : null;return (<div className="export-data-modal">@@ -132,10 +134,7 @@ const ExportCloudModal = ({<StyledExportDataSection><div className="description"><div className="title">- Data Type- </div>- <div className="subtitle">- Choose the type of data you want to export+ Upload through Dropbox</div></div><div className="selection">@@ -156,9 +155,14 @@ const ExportCloudModal = ({{isLoading && (<StatusPanel isLoading={isLoading} {...info} />)}+ {error && (+ <div className="subtitle" style={{color: 'red', fontWeight: 500}}>+ {error.error}+ </div>+ )}{metaUrl && [(<SharingUrl key={0} url={sharingLink} message={'Share your map with other users'}/>),- (<SharingUrl key={1} url={metaUrl} message={'Your new saved configuration'}/>)+ (<a href={folderLink} target="_blank" style={{textDecoration: 'underline'}}>Go to your Kepler.gl Dropbox folder</a>)]}</div></div>diff --git a/examples/demo-app/src/constants/default-settings.js b/examples/demo-app/src/constants/default-settings.jsindex c8c1f008e..f4b1ec447 100644--- a/examples/demo-app/src/constants/default-settings.js+++ b/examples/demo-app/src/constants/default-settings.js@@ -94,7 +94,8 @@ export const LOADING_SAMPLE_LIST_ERROR_MESSAGE = 'Not able to load sample gallerexport 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 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. ' ++ 'You can edit/delete the data file in your Dropbox account anytime.';export const DEFAULT_LOADING_METHOD = LOADING_METHODS[0];diff --git a/examples/demo-app/src/factories/save-map.js b/examples/demo-app/src/factories/save-map.jsnew file mode 100644index 000000000..b02281552--- /dev/null+++ b/examples/demo-app/src/factories/save-map.js@@ -0,0 +1,34 @@+// 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.++import {SaveMapFactory} from 'kepler.gl/components';++export const CustomSaveMapFactory = () => {+ const SaveMap = SaveMapFactory();+ SaveMap.defaultProps = {+ ...SaveMap.defaultProps,+ label: 'Share Public URL'+ };+ return SaveMap;+};++export function replaceSaveMap() {+ return [SaveMapFactory, CustomSaveMapFactory]+};diff --git a/examples/demo-app/src/utils/cloud-providers/dropbox.js b/examples/demo-app/src/utils/cloud-providers/dropbox.jsindex 8800dc201..d42196698 100644--- a/examples/demo-app/src/utils/cloud-providers/dropbox.js+++ b/examples/demo-app/src/utils/cloud-providers/dropbox.js@@ -26,6 +26,8 @@ import DropboxIcon from '../../components/icons/dropbox-icon';const NAME = 'dropbox';const DOMAIN = 'www.dropbox.com';+const APP_NAME= 'Kepler.gl%20(managed%20by%20Uber%20Technologies%2C%20Inc.)';+const KEPLER_DROPBOX_FOLDER_LINK = `//${DOMAIN}/home/Apps/${APP_NAME}`;const CORS_FREE_DOMAIN = 'dl.dropboxusercontent.com';const dropbox = new Dropbox();@@ -96,6 +98,7 @@ function shareFile(metadata) {// can share dropbox urls with users without the dropbox account (publish on twitter, facebook)result => ({...result,+ folder_link: KEPLER_DROPBOX_FOLDER_LINK,url: overrideUrl(result.url)}));@@ -122,7 +125,7 @@ function overrideUrl(url) {*/function handleLogin(onCloudLoginSuccess) {const link = authLink();- const authWindow = window.open(link, '_blank', 'width=800,height=600');+ const authWindow = window.open(link, '_blank', 'width=1024,height=716');const handleToken = e => {// TODO: add security step to validate which domain the message is coming fromauthWindow.close();diff --git a/src/components/index.js b/src/components/index.jsindex e51469979..8f85e303c 100644--- a/src/components/index.js+++ b/src/components/index.js@@ -30,7 +30,15 @@ export {default as ModalContainerFactory} from './modal-container';export {default as PlotContainerFactory} from './plot-container';// // side panel factories-export {default as PanelHeaderFactory} from './side-panel/panel-header'+export {+ default as PanelHeaderFactory,+ SaveExportDropdownFactory,+ ExportImageFactory,+ ExportDataFactory,+ ExportConfigFactory,+ ExportMapFactory,+ SaveMapFactory+} from './side-panel/panel-header'export {CollapseButtonFactory, default as SidebarFactory} from './side-panel/side-bar';export {default as PanelToggleFactory} from './side-panel/panel-toggle';@@ -49,6 +57,7 @@ export {default as MapManagerFactory} from './side-panel/map-manager';export {default as LayerGroupSelectorFactory} from './side-panel/map-style-panel/map-layer-selector';export {default as MapStyleSelectorFactory} from './side-panel/map-style-panel/map-style-selector';+// // map container factoriesexport {default as MapPopoverFactory} from './map/map-popover';export {default as MapControlFactory} from './map/map-control';diff --git a/src/components/modal-container.js b/src/components/modal-container.jsindex b649e387f..801cb32f4 100644--- a/src/components/modal-container.js+++ b/src/components/modal-container.js@@ -34,9 +34,9 @@ import DataTableModalFactory from './modals/data-table-modal';import LoadDataModalFactory from './modals/load-data-modal';import ExportImageModalFactory from './modals/export-image-modal';import ExportDataModalFactory from './modals/export-data-modal';+import ExportMapModalFactory from './modals/export-map-modal';import ExportConfigModalFactory from './modals/export-config-modal';import AddMapStyleModalFactory from './modals/add-map-style-modal';-import ExportMapModalFactory from './modals/export-map-modal';// Templateimport {exportMapToHTML} from 'templates/export-map';@@ -76,8 +76,8 @@ ModalContainerFactory.deps = [LoadDataModalFactory,ExportImageModalFactory,ExportDataModalFactory,- ExportConfigModalFactory,ExportMapModalFactory,+ ExportConfigModalFactory,AddMapStyleModalFactory];@@ -87,8 +87,8 @@ export default function ModalContainerFactory(LoadDataModal,ExportImageModal,ExportDataModal,- ExportConfigModal,ExportMapModal,+ ExportConfigModal,AddMapStyleModal) {class ModalWrapper extends Component {@@ -282,7 +282,6 @@ export default function ModalContainerFactory(onConfirm: this._closeModal};break;-case EXPORT_IMAGE_ID:const { ratio, legend, resolution, exporting, imageDataUri } = uiState.exportImage;template = (@@ -312,7 +311,6 @@ export default function ModalContainerFactory(}};break;-case EXPORT_DATA_ID:template = (<ExportDataModal@@ -336,7 +334,6 @@ export default function ModalContainerFactory(}};break;-case EXPORT_CONFIG_ID:const keplerGlConfig = KeplerGlSchema.getConfigToSave({ mapStyle, visState, mapState, uiState }@@ -361,7 +358,6 @@ export default function ModalContainerFactory(}};break;-case ADD_MAP_STYLE_ID:template = (<AddMapStyleModal@@ -385,9 +381,7 @@ export default function ModalContainerFactory(}};break;-case EXPORT_MAP_ID:-template = (<ExportMapModalexportHtml={uiState.exportHtml}@@ -406,9 +400,6 @@ export default function ModalContainerFactory(}};break;-- // TODO: add this options once we merge dropbox onto kepelr.gl core- // case SAVE_TO_CLOUD_IDdefault:break;}diff --git a/src/components/side-panel/panel-header.js b/src/components/side-panel/panel-header.jsindex 4a2785f06..2913179f6 100644--- a/src/components/side-panel/panel-header.js+++ b/src/components/side-panel/panel-header.js@@ -151,72 +151,131 @@ const PanelItem = ({onClose, onClickHandler, label, icon}) => (</div>);-export const SaveExportDropdown = ({- onExportImage,- onExportData,- onExportConfig,- onExportMap,- onSaveMap,- show,- onClose-}) => {- return (- <StyledPanelDropdown show={show} className="save-export-dropdown">- <ClickOutsideCloseDropdown className="save-export-dropdown__inner"- show={show}- onClose={onClose}>- <PanelItem- label="Export Image"- onClickHandler={onExportImage}- onClose={onClose}- icon={(<Picture height="16px" />)}- />-- <PanelItem- label="Export Data"- onClickHandler={onExportData}- onClose={onClose}- icon={(<Files height="16px" />)}- />-- <PanelItem- label="Export Config"- onClickHandler={onExportConfig}- onClose={onClose}- icon={(<CodeAlt height="16px" />)}- />-- <PanelItem- label="Export Map"- onClickHandler={onExportMap}- onClose={onClose}- icon={(<Map height="16px" />)}- />-- {onSaveMap ? (- <PanelItem- label="Save Map Url"- onClickHandler={onSaveMap}+export const ExportImageFactory = () => {+ const ExportImage = (props) => (+ <PanelItem {...props}/>+ );+ ExportImage.defaultProps = {+ label: 'Export Image',+ icon: <Picture />+ };++ return ExportImage;+};++export const ExportDataFactory = () => {+ const ExportData = (props) => (+ <PanelItem {...props}/>+ );+ ExportData.defaultProps = {+ label: 'Export Data',+ icon: <Files />+ };++ return ExportData;+};++export const ExportConfigFactory = () => {+ const ExportConfig = (props) => (+ <PanelItem {...props}/>+ );+ ExportConfig.defaultProps = {+ label: 'Export Config',+ icon: <CodeAlt />+ };++ return ExportConfig;+};++export const ExportMapFactory = () => {+ const ExportMap = (props) => (+ <PanelItem {...props}/>+ );+ ExportMap.defaultProps = {+ label: 'Export Map',+ icon: <Map />+ };++ return ExportMap;+};++export const SaveMapFactory = () => {+ const SaveMap = (props) => (+ <PanelItem {...props}/>+ );+ SaveMap.defaultProps = {+ label: 'Save Map',+ icon: <Share />+ };++ return SaveMap;+};++export const SaveExportDropdownFactory = (+ ExportImage,+ ExportData,+ ExportConfig,+ ExportMap,+ SaveMap) => {+ const SaveExportDropdown = ({+ onExportImage,+ onExportData,+ onExportConfig,+ onExportMap,+ onSaveMap,+ show,+ onClose+ }) => {+ return (+ <StyledPanelDropdown show={show} className="save-export-dropdown">+ <ClickOutsideCloseDropdown className="save-export-dropdown__inner"+ show={show}+ onClose={onClose}>+ <ExportImage+ onClickHandler={onExportImage}onClose={onClose}- icon={(<Share height="16px" />)}/>- ) : null}- </ClickOutsideCloseDropdown>- </StyledPanelDropdown>- );+ <ExportData+ onClickHandler={onExportData}+ onClose={onClose}+ />+ <ExportConfig+ onClickHandler={onExportConfig}+ onClose={onClose}+ />+ <ExportMap+ onClickHandler={onExportMap}+ onClose={onClose}+ />+ {onSaveMap ? (+ <SaveMap+ onClickHandler={onSaveMap}+ onClose={onClose}+ />+ ) : null}+ </ClickOutsideCloseDropdown>+ </StyledPanelDropdown>+ );+ };++ return SaveExportDropdown;};-const defaultActionItems = [- {- id: 'save',- iconComponent: Save,- onClick: () => {},- label: 'Share',- dropdownComponent: SaveExportDropdown- }+SaveExportDropdownFactory.deps = [+ ExportImageFactory,+ ExportDataFactory,+ ExportConfigFactory,+ ExportMapFactory,+ SaveMapFactory+];++PanelHeaderFactory.deps = [+ SaveExportDropdownFactory];-function PanelHeaderFactory() {+function PanelHeaderFactory(+ SaveExportDropdown+) {return class PanelHeader extends Component {static propTypes = {appName: PropTypes.string,@@ -229,7 +288,13 @@ function PanelHeaderFactory() {static defaultProps = {logoComponent: KeplerGlLogo,- actionItems: defaultActionItems+ actionItems: [{+ id: 'save',+ iconComponent: Save,+ onClick: () => {},+ label: 'Share',+ dropdownComponent: SaveExportDropdown+ }]};render() {diff --git a/src/templates/export-map.js b/src/templates/export-map.jsindex 087af5272..8f74f0211 100644--- a/src/templates/export-map.js+++ b/src/templates/export-map.js@@ -38,7 +38,8 @@ export const exportMapToHTML = options => {<script src="https://unpkg.com/[email protected]/dist/redux.js" crossorigin></script><script src="https://unpkg.com/[email protected]/dist/react-redux.min.js" crossorigin></script><script src="https://unpkg.com/[email protected]/dist/styled-components.min.js" crossorigin></script>-+ <script src="https://unpkg.com/[email protected]/dist/umd/react-virtualized.js" crossorigin></script>+<!-- Load Kepler.gl latest version--><script src="https://unpkg.com/kepler.gl/umd/keplergl.min.js" crossorigin></script><!-- You can also specify a specific versions by doing the following -->@@ -98,25 +99,24 @@ export const exportMapToHTML = options => {);}(Redux, enhancers));/** END STORE **/-+/** COMPONENTS **/- const KeplerElement = (function (react, keplerGl, mapboxToken) {- return function(props) {+ const KeplerElement = (function (react, reactVirtualized, keplerGl, mapboxToken) {+ return function() {return react.createElement('div',{style: {position: 'absolute', left: 0, width: '100vw', height: '100vh'}},- react.createElement(- keplerGl.KeplerGl,- {+ React.createElement(reactVirtualized.AutoSizer, null, function (props) {+ return React.createElement(keplerGl.KeplerGl, {mapboxApiAccessToken: mapboxToken,- id: 'map',- width: props.width || 1200,- height: props.height || 800- }- )+ id: "map",+ width: props.width,+ height: props.height+ });+ }))}- }(React, KeplerGl, MAPBOX_TOKEN));+ }(React, ReactVirtualized, KeplerGl, MAPBOX_TOKEN));const app = (function createReactReduxProvider(react, reactRedux, KeplerElement) {return react.createElement(diff --git a/website/package.json b/website/package.jsonindex 1885e6cde..dec0e7ee7 100644--- a/website/package.json+++ b/website/package.json@@ -22,6 +22,7 @@"dependencies": {"classnames": "^2.2.5","global": "^4.3.2",+ "lodash.get": "^4.4.2","prop-types": "^15.6.1","react": "^16.8.4","react-dom": "^16.8.4",diff --git a/website/src/reducers/analytics.js b/website/src/reducers/analytics.jsindex 32ba7a4ce..a0c94c126 100644--- a/website/src/reducers/analytics.js+++ b/website/src/reducers/analytics.js@@ -24,6 +24,7 @@ import {ActionTypes} from 'kepler.gl/actions';import {LOCATION_CHANGE} from 'react-router-redux';import window from 'global/window';import {ALL_FIELD_TYPES} from 'kepler.gl/constants';+import get from 'lodash.get';const getPayload = action => action ? action.payload : null;@@ -83,7 +84,19 @@ const trackingInformation = {[ActionTypes.INTERACTION_CONFIG_CHANGE]: ({config: {id, enabled}}) => ({[id]: enabled}),- [LOCATION_CHANGE]: x => x+ [LOCATION_CHANGE]: x => x,++ // demo app actions+ ['PUSHING_FILE']: (payload) => {+ const size = get(payload, ['metadata', 'metadata', 'size']);+ return {+ isLoading: payload.isLoading,+ status: payload.metadata.status,+ filename: payload.metadata.filename,+ size,+ error: payload.error+ };+ }};const EXCLUDED_ACTIONS = [ActionTypes.LAYER_HOVER, ActionTypes.UPDATE_MAP];@@ -91,6 +104,7 @@ const EXCLUDED_ACTIONS = [ActionTypes.LAYER_HOVER, ActionTypes.UPDATE_MAP];const analyticsMiddleware = store => next => action => {if (window.gtag && !EXCLUDED_ACTIONS.includes(action.type)) {const payload = action.payload || action;+// eslint-disable-next-line no-undefwindow.gtag('event', 'action', {event_category: action.type,@@ -98,7 +112,7 @@ const analyticsMiddleware = store => next => action => {? JSON.stringify(trackingInformation[action.type](payload, store))- : undefined+ : null});}diff --git a/website/webpack.config.js b/website/webpack.config.jsindex f8954d4c0..a94fcfff4 100644--- a/website/webpack.config.js+++ b/website/webpack.config.js@@ -184,13 +184,13 @@ module.exports = env => {logInstruction('You can get the token at https://www.mapbox.com/help/how-access-tokens-work/');throw new Error('Missing Mapbox Access token');}- if (!process.env.MapboxAccessToken) {+ if (!process.env.DropboxClientId) {logError('Error! DropboxClientId is not defined');logInstruction(`Make sure to run "export MapboxExportToken=<token>" before deploy the website`);logInstruction('You can get the token at https://www.dropbox.com/developers');throw new Error('Missing Export DropboxClientId Access token');}- if (!process.env.MapboxAccessToken) {+ if (!process.env.MapboxExportToken) {logError('Error! MapboxExportToken is not defined');logInstruction(`Make sure to run "export MapboxExportToken=<token>" before deploy the website`);logInstruction('You can get the token at https://www.mapbox.com/help/how-access-tokens-work/');