Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
[fix] Fix Save map action for FSQ provider (overwrite logic) (#3006)
Igor Dykhta8fbb3b0b455e
diff --git a/examples/demo-app/src/cloud-providers/foursquare/foursquare-provider.js b/examples/demo-app/src/cloud-providers/foursquare/foursquare-provider.jsindex 647c0fbfe..e62a314e2 100644--- a/examples/demo-app/src/cloud-providers/foursquare/foursquare-provider.js+++ b/examples/demo-app/src/cloud-providers/foursquare/foursquare-provider.js@@ -109,12 +109,16 @@ export default class FoursquareProvider extends Provider {}async uploadMap({mapData, options = {}}) {- // TODO: handle replace- const mode = options.overwrite ? 'overwrite' : 'add';const method = options.overwrite ? 'PUT' : 'POST';const {map, thumbnail} = mapData;- const {title = '', description = '', id} = map.info;+ const {title = '', description = '', loadParams} = map.info;++ const mapIdToOverwrite = options.mapIdToOverwrite || loadParams?.id;+ if(options.overwrite && !mapIdToOverwrite){+ throw new Error("Foursquare storage provider: no map id to overwrite");+ }+const headers = await this.getHeaders();const payload = {name: title,@@ -125,8 +129,22 @@ export default class FoursquareProvider extends Provider {}};+++ // To overwrite map.latestState we have to fetch the map first+ if(options.overwrite){+ const response = await fetch(`${this.apiURL}/v1/maps/${mapIdToOverwrite}`, {+ method: "GET",+ headers+ });++ const data = await response.json();+ payload.latestState = data.latestState;+ payload.latestState.data = map;+ }+const mapResponse = await fetch(- `${this.apiURL}/v1/maps${mode === 'overwrite' ? `/${id}` : ''}`,+ `${this.apiURL}/v1/maps${options.overwrite ? `/${mapIdToOverwrite}` : ''}`,{method,headers,@@ -136,6 +154,7 @@ export default class FoursquareProvider extends Provider {const createdMap = await mapResponse.json();+ if(!options.overwrite){await fetch(`${this.apiURL}/v1/maps/${createdMap.id}/thumbnail`, {method: 'PUT',headers: {@@ -144,8 +163,11 @@ export default class FoursquareProvider extends Provider {},body: thumbnail});+ }- return map;+ // pass through fsq map id+ const newMapData = extractMapFromFSQResponse(createdMap);+ return {...newMapData, info: {...newMapData.info, id: createdMap.id}};}async listMaps() {diff --git a/src/components/src/modal-container.tsx b/src/components/src/modal-container.tsxindex d6838313b..dfbd37c01 100644--- a/src/components/src/modal-container.tsx+++ b/src/components/src/modal-container.tsx@@ -228,12 +228,12 @@ export default function ModalContainerFactory(const toSave = exportMap(this.props);this.props.providerActions.exportFileToCloud({- // @ts-ignoremapData: toSave,provider,options: {isPublic,- overwrite+ overwrite,+ mapIdToOverwrite: this.props.providerState.savedMapId},closeModal,onSuccess: this.props.onExportToCloudSuccess,@@ -250,8 +250,8 @@ export default function ModalContainerFactory(});};- _onOverwriteMap = () => {- this._onSaveMap(true);+ _onOverwriteMap = (provider) => {+ this._onSaveMap(provider, true);};_onShareMapUrl = provider => {diff --git a/src/reducers/src/provider-state-updaters.ts b/src/reducers/src/provider-state-updaters.tsindex ca8abe55f..b4cedeb20 100644--- a/src/reducers/src/provider-state-updaters.ts+++ b/src/reducers/src/provider-state-updaters.ts@@ -49,6 +49,7 @@ export type ProviderState = {currentProvider: string | null;successInfo: any;mapSaved: null | string;+ savedMapId: null | string;initialState?: any;visualizations: MapListItem[];};@@ -60,6 +61,7 @@ export const INITIAL_PROVIDER_STATE: ProviderState = {currentProvider: null,successInfo: {},mapSaved: null,+ savedMapId: null,visualizations: []};@@ -154,7 +156,8 @@ export const exportFileSuccessUpdater = (successInfo: response,...(!options.isPublic? {- mapSaved: provider.name+ mapSaved: provider.name,+ savedMapId: response?.info?.id ?? null}: {})};diff --git a/src/types/actions.d.ts b/src/types/actions.d.tsindex 5d734dfd4..a47d2aeb4 100644--- a/src/types/actions.d.ts+++ b/src/types/actions.d.ts@@ -11,6 +11,7 @@ export type MapData = {export type ExportFileOptions = {isPublic?: boolean;overwrite?: boolean;+ mapIdToOverwrite?: string | null;};export type OnErrorCallBack = (error: Error) => any;export type OnSuccessCallBack = (p: {diff --git a/test/node/reducers/provider-state-test.js b/test/node/reducers/provider-state-test.jsindex fbb8db484..97f067048 100644--- a/test/node/reducers/provider-state-test.js+++ b/test/node/reducers/provider-state-test.js@@ -88,6 +88,7 @@ test('#providerStateReducer -> EXPORT_FILE_TO_CLOUD', t => {successInfo: {},initialState: {},mapSaved: null,+ savedMapId: null,visualizations: []},'Should set isProviderLoading and current provider'@@ -120,6 +121,7 @@ test('#providerStateReducer -> EXPORT_FILE_TO_CLOUD', t => {currentProvider: 'taro',initialState: {},mapSaved: 'taro',+ savedMapId: null,successInfo: {url: 'taro_and_blue'},visualizations: []},@@ -139,6 +141,7 @@ test('#providerStateReducer -> EXPORT_FILE_TO_CLOUD', t => {currentProvider: 'taro',initialState: {},mapSaved: null,+ savedMapId: null,successInfo: {},visualizations: []},@@ -227,6 +230,7 @@ test('#providerStateReducer -> EXPORT_FILE_TO_CLOUD -> onSuccess : onError', t =providerError: null,currentProvider: 'taro',mapSaved: 'taro',+ savedMapId: null,initialState: {},successInfo: {url: 'taro_and_blue'},visualizations: []@@ -256,6 +260,7 @@ test('#providerStateReducer -> EXPORT_FILE_TO_CLOUD -> onSuccess : onError', t =providerError: null,currentProvider: 'taro',mapSaved: 'taro',+ savedMapId: null,initialState: {},successInfo: {url: 'taro_and_blue'},modalId: null,@@ -273,6 +278,7 @@ test('#providerStateReducer -> EXPORT_FILE_TO_CLOUD -> onSuccess : onError', t =providerError: null,currentProvider: 'taro',mapSaved: 'taro',+ savedMapId: null,initialState: {},successInfo: {},modalId: null,@@ -318,6 +324,7 @@ test('#providerStateReducer -> RESET_PROVIDER_STATUS', t => {successInfo: {},initialState: {},mapSaved: null,+ savedMapId: null,visualizations: []},'Should resetProviderStatus'