Skip to content

Commit 400a7cf

Browse files
authored
Merge pull request #175 from vtex/best-pickup-markers
CHK-599: Fix rendering of markers not updating on address change
2 parents 9d116d9 + 2f3a088 commit 400a7cf

27 files changed

+8418
-5010
lines changed

.github/workflows/ci.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: CI
2+
on:
3+
pull_request:
4+
types: [opened, synchronize]
5+
push:
6+
branches: [main]
7+
8+
jobs:
9+
install:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v1
13+
with:
14+
fetch-depth: 0
15+
- name: NodeJS 12.x
16+
uses: actions/setup-node@v1
17+
with:
18+
node-version: 12.x
19+
- run: |
20+
yarn install --frozen-lockfile --check-files
21+
yarn --cwd react install --frozen-lockfile --check-files
22+
- uses: actions/cache@v2
23+
id: cache-build
24+
with:
25+
path: ./*
26+
key: ${{ github.sha }}
27+
28+
test:
29+
runs-on: ubuntu-latest
30+
needs: install
31+
steps:
32+
- name: Restore cache
33+
uses: actions/cache@v2
34+
id: restore-build
35+
with:
36+
path: ./*
37+
key: ${{ github.sha }}
38+
- run: yarn test
39+
40+
lint:
41+
runs-on: ubuntu-latest
42+
needs: install
43+
steps:
44+
- name: Restore cache
45+
uses: actions/cache@v2
46+
id: restore-build
47+
with:
48+
path: ./*
49+
key: ${{ github.sha }}
50+
- run: yarn lint

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
## [Unreleased]
9+
### Changed
10+
- Update to `Maps` component to declaretively render google maps and markers.
11+
12+
### Fixed
13+
- Markers not updating on maps after changing address.
914

1015
## [3.6.0] - 2021-12-10
1116
### Added

package.json

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
"lint-fix": "yarn lint --fix",
1616
"lint:locales": "intl-equalizer",
1717
"lint:ts": "tsc --noEmit -p react/tsconfig.json",
18-
"test": "jest --env=jsdom",
19-
"test:coverage": "jest --env=jsdom --coverage",
20-
"test:watch": "jest --env=jsdom --watch",
18+
"test": "yarn --cwd react test",
19+
"test:coverage": "yarn --cwd react test --coverage",
20+
"test:watch": "yarn --cwd react test --watch",
2121
"prepublishOnly": "npm run symlink:remove && npm run symlink && npm run build && npm run symlink:remove",
2222
"build:link": "npm link && watch 'npm run build' src",
2323
"postreleasy": "npm publish --access public"
@@ -37,36 +37,14 @@
3737
]
3838
},
3939
"devDependencies": {
40-
"@babel/core": "^7.16.0",
41-
"@babel/preset-env": "^7.16.0",
42-
"@babel/preset-react": "^7.16.0",
43-
"@babel/preset-typescript": "^7.16.0",
4440
"@vtex/prettier-config": "^0.3.6",
45-
"babel-jest": "^27.3.1",
46-
"enzyme": "^3.4.1",
47-
"enzyme-adapter-react-16": "^1.2.0",
48-
"enzyme-react-intl": "^2.0.0",
4941
"eslint": "^7",
5042
"eslint-config-vtex": "^14.1.1",
5143
"eslint-config-vtex-react": "^8.2.0",
5244
"husky": "^4.2.3",
53-
"i18n-iso-countries": "^3.5.0",
54-
"identity-obj-proxy": "^3.0.0",
55-
"jest": "^27.3.1",
56-
"jest-enzyme": "^6.0.3",
5745
"lint-staged": "^10.1.1",
58-
"mockdate": "^2.0.2",
5946
"nwb": "^0.23.0",
6047
"prettier": "^2.4.1",
61-
"react": "^16.3.2",
62-
"react-dom": "^16.3.2",
63-
"react-hot-loader": "^3.1.3",
64-
"react-intl": "^2.8.0",
65-
"react-redux": "^5.0.7",
66-
"react-test-renderer": "^16.2.0",
67-
"react-testing-library": "^6.0.0",
68-
"redux": "^4.0.0",
69-
"typescript": "^3.8.3",
70-
"watch": "^1.0.2"
48+
"typescript": "^3.8.3"
7149
}
7250
}

react/ModalState.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ class ModalState extends Component {
257257

258258
this.setSelectedPickupPoint({
259259
pickupPoint: bestPickupOptions[previousIndex],
260-
isSelectedBestPickupPoint: previousIndex < BEST_PICKUPS_AMOUNT,
260+
isBestPickupPoint: previousIndex < BEST_PICKUPS_AMOUNT,
261261
})
262262
}
263263

@@ -272,7 +272,7 @@ class ModalState extends Component {
272272

273273
this.setSelectedPickupPoint({
274274
pickupPoint: bestPickupOptions[nextIndex],
275-
isSelectedBestPickupPoint: nextIndex < BEST_PICKUPS_AMOUNT,
275+
isBestPickupPoint: nextIndex < BEST_PICKUPS_AMOUNT,
276276
})
277277
}
278278

react/PickupPointsModal.js

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import React, { Component } from 'react'
22
import PropTypes from 'prop-types'
33
import debounce from 'lodash/debounce'
4-
import Map from './components/Map'
4+
import { injectIntl, intlShape } from 'react-intl'
5+
import { helpers } from 'vtex.address-form'
6+
7+
import Map from './components/Map.jsx'
58
import CloseButton from './components/CloseButton'
69
import styles from './index.css'
710
import ZoomControls from './components/ZoomControls'
@@ -10,14 +13,16 @@ import ModalState from './ModalState'
1013
import Geolocation from './Geolocation'
1114
import SearchArea from './components/SearchArea'
1215
import SearchOverlay from './assets/components/SearchOverlay'
13-
import { injectIntl, intlShape } from 'react-intl'
1416
import { withGoogleMaps } from './containers/withGoogleMaps'
1517
import { translate } from './utils/i18nUtils'
1618
import { newAddress } from './utils/newAddress'
1719
import { HIDE_MAP, SHOW_MAP } from './constants'
1820
import { getPickupOptionGeolocations } from './utils/pickupUtils'
19-
import { helpers } from 'vtex.address-form'
20-
import { closePickupPointsModalEvent, openPickupPointsModalEvent, searchPickupAddressByGeolocationEvent } from './utils/metrics'
21+
import {
22+
closePickupPointsModalEvent,
23+
openPickupPointsModalEvent,
24+
searchPickupAddressByGeolocationEvent,
25+
} from './utils/metrics'
2126

2227
const { validateField, addValidation } = helpers
2328
const NULL_VALUE = {
@@ -48,7 +53,8 @@ class PickupPointsModal extends Component {
4853
}
4954

5055
componentDidMount() {
51-
const style = document.body.style
56+
const { style } = document.body
57+
5258
style.overflow = 'hidden'
5359
style.position = 'fixed'
5460
style.width = '100%'
@@ -83,6 +89,7 @@ class PickupPointsModal extends Component {
8389
// On mobile browsers trigger the resize event when keyboard is opened
8490
// even though the screen size itself is the same
8591
const isWidthEqual = this.state.innerWidth === window.innerWidth
92+
8693
if (!this.state.isMounted || isWidthEqual) return
8794
this.setState({
8895
isLargeScreen: window.innerWidth > 1023,
@@ -91,15 +98,15 @@ class PickupPointsModal extends Component {
9198
})
9299
}, 200)
93100

94-
updateLocationTab = mapStatus => this.setState({ mapStatus })
101+
updateLocationTab = (mapStatus) => this.setState({ mapStatus })
95102

96103
activatePickupDetails = () =>
97104
this.setState({
98105
isPickupDetailsActive: true,
99106
mapStatus: HIDE_MAP,
100107
})
101108

102-
getPostalCodeValue = address => {
109+
getPostalCodeValue = (address) => {
103110
// TODO move this to Address Form
104111
if (
105112
address &&
@@ -119,7 +126,7 @@ class PickupPointsModal extends Component {
119126
return address.postalCode && address.postalCode.value
120127
}
121128

122-
getValidPostalCode = address => {
129+
getValidPostalCode = (address) => {
123130
if (address.postalCode) {
124131
const postalCodevalue = this.getPostalCodeValue(address)
125132

@@ -149,10 +156,11 @@ class PickupPointsModal extends Component {
149156
visited: null,
150157
}
151158
}
159+
152160
return NULL_VALUE
153161
}
154162

155-
handleAddressChange = address => {
163+
handleAddressChange = (address) => {
156164
const { searchAddress } = this.props
157165

158166
const addressValidated = {
@@ -180,7 +188,8 @@ class PickupPointsModal extends Component {
180188
}
181189

182190
handleCloseModal = () => {
183-
const style = document.body.style
191+
const { style } = document.body
192+
184193
style.overflow = 'auto'
185194
style.position = ''
186195
if (this.state.isLoadingGeolocation) {
@@ -191,6 +200,7 @@ class PickupPointsModal extends Component {
191200
elapsedTime,
192201
})
193202
}
203+
194204
this.props.closePickupPointsModal()
195205
}
196206

@@ -265,25 +275,29 @@ class PickupPointsModal extends Component {
265275
pickupOptions={pickupOptions}
266276
salesChannel={salesChannel}
267277
orderFormId={orderFormId}
268-
selectedPickupPoint={selectedPickupPoint}>
278+
selectedPickupPoint={selectedPickupPoint}
279+
>
269280
<Geolocation
270281
address={searchAddressWithAddressQuery}
271282
askForGeolocation={askForGeolocation}
272283
googleMaps={googleMaps}
273284
onChangeAddress={this.handleAddressChange}
274285
onChangeGeolocationState={this.handleChangeGeolocationLoading}
275-
rules={rules}>
286+
rules={rules}
287+
>
276288
<SearchArea
277289
address={searchAddressWithAddressQuery}
278290
mapStatus={mapStatus}
279291
shouldShow={shouldShowMap}
280292
isLargeScreen={isLargeScreen}
281293
/>
282-
<ZoomControls
283-
isLargeScreen={isLargeScreen}
284-
mapStatus={mapStatus}
285-
shouldShow={shouldShowMap}
286-
/>
294+
{/*
295+
* Used for rendering the <ZoomControls /> component. This is
296+
* currently done this way because the ZoomControls must be a child of <Map />
297+
* to be able to consume the <GoogleMaps /> context, but it must be placed in
298+
* this position for the layout to work
299+
*/}
300+
<div id="controls-wrapper" />
287301

288302
{shouldUseMaps && (
289303
<Map
@@ -301,7 +315,13 @@ class PickupPointsModal extends Component {
301315
selectedPickupPointGeolocation={getPickupOptionGeolocations(
302316
selectedPickupPoint
303317
)}
304-
/>
318+
>
319+
<ZoomControls
320+
isLargeScreen={isLargeScreen}
321+
mapStatus={mapStatus}
322+
shouldShow={shouldShowMap}
323+
/>
324+
</Map>
305325
)}
306326
<SearchOverlay />
307327
<StateHandler

0 commit comments

Comments
 (0)