Skip to content

Commit

Permalink
refactor: change the pickup locations views strings and setting
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine committed Dec 3, 2019
1 parent e8d53d0 commit 4591fb1
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 26 deletions.
40 changes: 29 additions & 11 deletions src/components/Pickup/Pickup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@
<td>
<div>
<button
@click="() => select('list')"
@click="selected = views.list"
v-text="$configBus.strings.pickupLocationsListButton" />
<button
@click="() => select('map')"
@click="selected = views.map"
v-text="$configBus.strings.pickupLocationsMapButton" />
</div>

<transition name="shove">
<keep-alive>
<div :class="$classBase + '__pickup-locations--list'">
<recursive-form
v-if="selected === 'list'"
v-if="selected === views.list"
:option="listOption" />
</div>
</keep-alive>
</transition>
<transition name="shove">
<keep-alive>
<leaflet
v-if="selected === 'map'"
v-if="selected === views.map"
:data="data"
@update="emitUpdate" />
</keep-alive>
Expand All @@ -31,11 +31,14 @@

<script>
import * as EVENTS from '@/config/data/eventConfig';
import { FEATURE_MAX_PAGE_ITEMS, FEATURE_PICKUP_LOCATIONS_MAP } from '@/config/data/settingsConfig';
import * as SETTINGS from '@/config/data/settingsConfig';
import Leaflet from '@/components/Pickup/Map/Leaflet';
import { PICKUP_LOCATION } from '@/config/data/formConfig';
import PickupOption from '@/components/Pickup/PickupOption';
const MAP_VIEW = 'map';
const LIST_VIEW = 'list';
export default {
name: 'Pickup',
components: { Leaflet },
Expand All @@ -47,27 +50,42 @@ export default {
},
data() {
return {
selected: this.$configBus.get(FEATURE_PICKUP_LOCATIONS_MAP) ? 'map' : 'list',
selected: this.getDefaultMapView(),
listOption: {
name: PICKUP_LOCATION,
type: 'radio',
component: PickupOption,
pagination: this.$configBus.get(FEATURE_MAX_PAGE_ITEMS),
pagination: this.$configBus.get(SETTINGS.FEATURE_MAX_PAGE_ITEMS),
choices: this.data.choices,
},
views: {
map: MAP_VIEW,
list: LIST_VIEW,
},
};
},
methods: {
select(item) {
this.selected = item;
},
/**
* @param {Object} event - Event object.
*/
emitUpdate(event) {
this.$configBus.$emit(EVENTS.UPDATE, event);
},
/**
* Get the default map view setting or fall back to default.
*
* @returns {String}
*/
getDefaultMapView() {
const setting = this.$configBus.get(SETTINGS.FEATURE_PICKUP_LOCATIONS_DEFAULT_VIEW);
if (setting && this.views.includes(setting)) {
return setting;
}
return this.views.map;
},
},
};
</script>
2 changes: 1 addition & 1 deletion src/config/data/defaultConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const baseConfig = {
[SETTINGS.PRICE_STANDARD_DELIVERY]: 0,

[SETTINGS.FEATURE_ALLOW_RETRY]: true,
[SETTINGS.FEATURE_PICKUP_LOCATIONS_MAP]: false,
[SETTINGS.FEATURE_PICKUP_LOCATIONS_DEFAULT_VIEW]: 'map',
[SETTINGS.FEATURE_MAX_PAGE_ITEMS]: 5,

/**
Expand Down
2 changes: 1 addition & 1 deletion src/config/data/locales/be/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const config = {
/**
* For the same reason as above, prefer the map view to the list view.
*/
[SETTINGS.FEATURE_PICKUP_LOCATIONS_MAP]: true,
[SETTINGS.FEATURE_PICKUP_LOCATIONS_DEFAULT_VIEW]: true,

/**
* Show more pickup items by default for BE because it doesn't show the distance.
Expand Down
20 changes: 8 additions & 12 deletions src/config/data/settingsConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,21 @@ export const CARRIER_SETTINGS = 'carrierSettings';
*/
export const FEATURE_ALLOW_RETRY = 'allowRetry';

/**
* Enable a map for the pickup locations instead of the default list.
*
* @type {String}
*/
export const FEATURE_PICKUP_LOCATIONS_MAP = 'pickupLocationsMap';

/**
* Tile layer data for use with the pickup locations map.
*
* @type {String}
/*
* The default view of pickup locations.
*/
export const PICKUP_LOCATIONS_MAP_TILE_LAYER_DATA = 'pickupLocationsMapTileLayerData';
export const FEATURE_PICKUP_LOCATIONS_DEFAULT_VIEW = 'pickupLocationsDefaultView';

/*
* Show distance under each pickup location if true. Otherwise shows street name and number.
*/
export const FEATURE_PICKUP_SHOW_DISTANCE = 'pickupShowDistance';

/*
* Tile layer data for use with the pickup locations map.
*/
export const PICKUP_LOCATIONS_MAP_TILE_LAYER_DATA = 'pickupLocationsMapTileLayerData';

/*
* Max amount of pickup locations shown.
*/
Expand Down
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ declare namespace MyParcelDeliveryOptions {

// Feature toggles
allowRetry: Boolean
pickupLocationsDefaultView: 'map' | 'list'
pickupShowDistance: Boolean
pickupLocationsMap: Boolean

pickupLocationsMapTileLayerData: MapTileLayerData
}
Expand Down

0 comments on commit 4591fb1

Please sign in to comment.