-
Notifications
You must be signed in to change notification settings - Fork 799
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Contact Info & Map Widget: Remove Geocoding and add map to form #12474
Contact Info & Map Widget: Remove Geocoding and add map to form #12474
Conversation
Thank you for the great PR description! When this PR is ready for review, please apply the Scheduled Jetpack release: September 3, 2019. |
I just noticed that the Customize page will show inconsistent maps when an address is changed. The preview page will show the map for the new address. However, the map in the widget's admin form doesn't update, so it shows the map for the old address. I'll try to think of a solution for this. |
084e01f
to
1af852c
Compare
Following-up on my last comment - I addressed the issue with inconsistent maps on the Customizer page in the latest commit. In this commit, the embedded map is not displayed in the widget admin form on the Customizer page. Since the Customizer preview displays the embedded map, it's not necessary to display the map in the widget admin form. I used the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent work! I'd like to suggest a few changes, and to make things easier I've just submitted this PR to your branch:
kbrown9#1
If you are happy with those changes, you can merge the PR and my changes will be automatically added to your PR here.
Beyond those changes, I think we should take that opportunity to better display error messages in the customizer when something is wrong.
Those could be displayed in the widget settings directly, just like on the old settings screen. They could also be displayed in the widget preview directly, since that's where site owners will check what the map will look like.
Let me know what you think.
Thank you for this review! I think all of these changes look great. I'll work on displaying the error message in the customizer! |
cdf867d
to
7f4b2e0
Compare
@kbrown9 Is this ready for another review? |
@jeherve Yes, it's ready now! I just pushed my last commit. So, I've added three new commits on top of your changes:
Please let me know if you'd prefer a different approach for these error messages! Finally, what's the workflow for handling the commits that are improvements to previous commits? After the review is complete, should the commits be squashed together? |
Excellent, I'll take a look when I can.
Don't worry about it :) I'll squash all the commits when I merge to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like Unit Tests are failing right now:
modules/widgets/contact-info/contact-info-admin.js
line 23 col 9 'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
line 29 col 13 'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
line 30 col 13 'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
line 25 col 17 'ajaxurl' is not defined.
⚠ 4 warnings
The first 3 warnings are an annoying consequence of us still using jshint (see #11915), but I'm afraid we won't be able to merge as long as the tests are failing.
Thanks for the info! I'll get these fixed up. |
15910c9
to
f18d932
Compare
@jeherve - I amended the commit that caused the jshint test failures. The commit passes the tests now! |
Thanks - I was able to reproduce the too-wide map with your instructions. I'll look into this. |
Commit c8544a7 fixes the too-wide map problem by using the |
The Google Maps Geocoding API is used to verify that the given address is valid. However, use of this API has recently caused problems for users. Users need to enable two Google Maps APIs in order to use this widget, which isn't user-friendly. Instead of using the Geocoding API results to verify the address, show the embedded map in the widget's admin form. The user can verify that the address is valid and correct by looking at the map. Also, the user will receive Google Maps' error messages if the API key is not valid. Do not show the embedded map In the Customizer admin form. The embedded map isn't necessary in this form because the embedded map is shown in the Customizer preview.
- A few additional comments help understand when has_good_map is needed. - Use Yoda conditions, we must
This avoids that the map breaks out of the widget area layout when displayed.
- This gives more information to users who entered an API key that is not correct for example, instead of just not displaying any map at all.
* Move the logic for determining whether to update the instance's 'goodmap' value from the 'update()' function to a new function, 'update_goodmap()'. * Instead of calling 'has_good_map()' in the 'form()' function, just check the instance's 'goodmap' value. We've already called 'has_good_map()' and saved the result in the instance's 'goodmap' value, so no need to call "has_good_map()" again.
When the Google Maps API returns an error, display it in the widget in the Customizer preview. The CSS properties for the 'contact-map-api-error' class are intended to match the CSS properties for the admin 'notice-warning' class.
Display API key errors in the Contact Info & Map widget's admin form on the Customizer preview page. This requres an Ajax call, which results in a call to the "has_good_map()" method. The "has_good_map()" method checks the API key by calling the Google Maps API. If the API returns an error, that error is displayed in the admin form on the Customizer page.
Use a nonce to verify that the Ajax request is valid. Also check that the user is allowed to customize before checking the API key from the Ajax request.
Enqueue the contact info stylesheet on widgets.php using the 'admin_enqueue_scripts' hook since widgets.php is an admin page.
c8544a7
to
04cf9ac
Compare
* 7.7 changelog: initial set of changes * Changelog: add #13154 * Changelog: add #13134 * Changelog: add #12699 and many others * Changelog: add #13127 * Changelog: add #13167 * Changelog: add #13225 * Changelog: add #13179 * Changelog: add #13173 * Changelog: add #13232 * Changelog: add #13137 * Changelog: add #13172 * Changelog: add #13182 * Changelog: add #13200 * Changelog: add #13244 * Changelog: add #13267 * Changelog: add #13204 * changelog: add #13205 * Changelog: add #13183 * Changelog: add #13278 * Changelog: add #13162 * Changelog: add #13268 * Changelog: add #13286 * Changelog: add #13273 * Changelog: add #12474 * Changelog: add #13085 * Changelog: add #13266 * Changelog: add #13306 * Changelog: add #13311 * Changelog: add #13302 * Changelog: add #13196 * Changelog: add #12733 * Changelog: add #13261 * Changelog: add #13322 * Changelog: add #13333 * Changelog: add #13335
Fixes #10355
Fixes #12925
Fixes #12913
Changes proposed in this Pull Request:
Remove the use of the Google Maps Geocoding API. The Geocoding API is only used to verify that the address is valid. After these changes are made, users will need to enable only one Google Maps API (Maps Embed API).
Add the Google Maps embedded map to the widget's admin form. This change will allow users to view the maps that will be shown on their site in the admin form. The users will be able to verify that the maps are correct and receive a useful error if the API key is invalid.
Is this a new feature or does it add/remove features to an existing part of Jetpack?
Testing instructions:
Add a new Contact Info & Maps widget (Appearance -> Widgets -> Contact Info & Map), or access an existing Contact Info & Maps widget.
Check the Show Map checkbox to show the API key box and the embedded map.
The embedded map iframe will show this error when an API key is not entered:
Enter an invalid API key. The embedded map iframe will show this error when an invalid API key is entered:
Enter a valid Google Maps API key. (The Embed Maps API must be enabled for the API key.) Save the widget, and the embedded map will be shown in the admin form.
Proposed changelog entry for your changes:
Contact Info Widget: Remove use of the Geocoding API and add an embedded map to the admin form