Skip to content

Commit

Permalink
fix: clean up Map ID in a generated Quick Builder configuration
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 582027504
  • Loading branch information
awmack authored and copybara-github committed Nov 13, 2023
1 parent d08755d commit bb25e4d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/store_locator/quick_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,14 @@ export function getFeatureSet(configuration: QuickBuilderConfiguration):
} else {
return FeatureSet.BASIC;
}
}

/**
* Sanitizes Quick Builder generated map options.
*/
export function getMapOptions(configuration: QuickBuilderConfiguration):
Partial<google.maps.MapOptions> {
const options = {...(configuration.mapOptions ?? {})};
if (!options.mapId) delete options.mapId;
return options;
}
8 changes: 7 additions & 1 deletion src/store_locator/quick_builder_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// import 'jasmine'; (google3-only)

import {FeatureSet} from './interfaces.js';
import {convertLocations, getFeatureSet} from './quick_builder.js';
import {convertLocations, getFeatureSet, getMapOptions} from './quick_builder.js';

describe('Quick Builder conversion', () => {
it('converts listings from a Quick Builder configuration object', () => {
Expand Down Expand Up @@ -66,4 +66,10 @@ describe('Quick Builder conversion', () => {
}
})).toEqual(FeatureSet.ADVANCED);
});

it('removes mapId from the map options if set to an empty string', () => {
expect(getMapOptions({mapOptions: {maxZoom: 4, mapId: ''}})).toEqual({
maxZoom: 4
});
});
});
4 changes: 2 additions & 2 deletions src/store_locator/store_locator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import type {AdvancedMarkerElement, LatLng, MapElement, Place, PlaceResult} from
import {DistanceInfo, DistanceMeasurer, DistanceSource} from './distances.js';
import type {InternalListing, StoreLocatorListing} from './interfaces.js';
import {FeatureSet, QuickBuilderConfiguration} from './interfaces.js';
import {convertLocations, getFeatureSet} from './quick_builder.js';
import {convertLocations, getFeatureSet, getMapOptions} from './quick_builder.js';
import {storeLocatorStyles} from './store_locator_styles.js';

declare global {
Expand Down Expand Up @@ -239,7 +239,7 @@ export class StoreLocator extends BaseComponent {
configureFromQuickBuilder(configuration: QuickBuilderConfiguration) {
this.listings = convertLocations(configuration);
this.featureSet = getFeatureSet(configuration);
if (configuration.mapOptions) this.mapOptions = configuration.mapOptions;
this.mapOptions = getMapOptions(configuration);
}

/**
Expand Down

0 comments on commit bb25e4d

Please sign in to comment.