Skip to content

[ADD] html_builder: convert s_google_map #4242

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

Merged
merged 5 commits into from
Apr 18, 2025

Conversation

Zynton
Copy link

@Zynton Zynton commented Mar 24, 2025

Conversion of the Google Maps ("s_google_map") snippet.

@robodoo
Copy link

robodoo commented Mar 24, 2025

This PR targets the un-managed branch odoo-dev/odoo:master-mysterious-egg, it needs to be retargeted before it can be merged.

@Zynton Zynton force-pushed the mysterious-egg-gmaps-age branch 16 times, most recently from c69d4b5 to fe40bfa Compare March 25, 2025 16:12
@FrancoisGe FrancoisGe force-pushed the master-mysterious-egg branch from f468b7f to 80b3d5d Compare March 27, 2025 12:21
@ged-odoo ged-odoo force-pushed the master-mysterious-egg branch from 27a1402 to 8c6b756 Compare March 27, 2025 20:00
@Zynton Zynton force-pushed the mysterious-egg-gmaps-age branch 11 times, most recently from 50652bf to fc4217f Compare April 1, 2025 07:12
@Zynton Zynton force-pushed the mysterious-egg-gmaps-age branch 6 times, most recently from 7fb25ce to f5b6b0a Compare April 7, 2025 08:24
Comment on lines 41 to 44
this.googleMapsAutocomplete = new google.maps.places.Autocomplete(
inputEl,
{ types: [ "geocode" ] },
);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How it works with the history ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a history of stuff that's in the sidebar?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I m not sure. What we want to do exactly with this inputEl. What happens when you type a char or you press enter ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just that Google's API asks for an Input element to initialize its autocomplete feature on. So when I call google.maps.places.Autocomplete with that element it attaches its feature to it and now when I type it makes places suggestions. If I type enter it closes the suggestion dropdown. If I select one of the suggestions Google triggers a "place_changed" event, which I listen to to update the state.
I checked and nothing happens in the history when I do any of these things. That seems correct to me, except for the address change which should actually trigger a step. What I should probably do is add a history step in the commitPlace function.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There, I did that and it works perfectly.

@Zynton Zynton force-pushed the mysterious-egg-gmaps-age branch 2 times, most recently from 76e0bc9 to 1c3e7c7 Compare April 7, 2025 09:42
Comment on lines 53 to 54
this.mapsAPI = google?.maps;
this.placesAPI = google?.maps.places;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a difference between window.google?.maps and google?.maps. If not, why you do need to store them in this instead of directly calling google?.maps ?

Copy link
Author

@Zynton Zynton Apr 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get an error when window.google is not defined and I try to do google?.maps: google is not defined. I store it on this for convenience, it's not really needed.

},
],
builder_actions: this.getActions(),
on_snippet_dropped_handlers: ({ snippetEl }) => this.loadGoogleMaps(snippetEl),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really needed? The normalize_handlers should catch it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it was but I'll test again.

Comment on lines +21 to +33
gMapsAPIKeyProm = new Promise(async resolve => {
const data = await rpc('/website/google_maps_api_key');
resolve(JSON.parse(data).google_maps_api_key || '');
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gMapsAPIKeyProm = rpc('/website/google_maps_api_key').then(
  data => JSON.parse(data).google_maps_api_key || ''
);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a file I duplicated from website.

@divy-odoo divy-odoo force-pushed the master-mysterious-egg branch from 4648461 to 2d7aa09 Compare April 8, 2025 12:19
@Zynton Zynton force-pushed the mysterious-egg-gmaps-age branch 4 times, most recently from 8297be0 to 8dbfd0d Compare April 10, 2025 14:41
@Zynton Zynton force-pushed the mysterious-egg-gmaps-age branch 3 times, most recently from daf794e to c944779 Compare April 17, 2025 12:42
Steps to reproduce:

- Activate developer mode
- Install website Google Maps module
- Navigate to Website in edit mode
- Drop the google maps snippet
- Enter a correct API key
- The dialog closes but the snippet is removed

This is due to a promise not resolved when confirming the API key.

closes odoo#204845

X-original-commit: 61ede67
Signed-off-by: Benjamin Vray (bvr) <[email protected]>
Signed-off-by: Serge Bayet (seba) <[email protected]>
@Zynton Zynton force-pushed the mysterious-egg-gmaps-age branch 2 times, most recently from bdf1424 to 235699e Compare April 17, 2025 14:27
Zynton added 4 commits April 17, 2025 16:37
This is a departure from the original implementation. It ensures things
are done in proper order in the case of an API error. It also addresses
a specific broken case:

1. Drop a Google Maps snippet
2. Enter an API key with billing, static and javascript, but no places
3. Try again with the same key
4. Now the snippet is removed, so insert it again -> the snippet is blank.

This is because the google_maps_service (like the website_map_service it
copies), when an API key is found, resolves its promise in a callback
triggered by Google's API when calling it via `loadJS`. But the second
time, the URL was cached so we never actually fetch the URL and the
callback is never triggered, leading to the promise remaining
unfulfilled forever. This returns the old promise if requesting the same
url a second time.
@Zynton Zynton force-pushed the mysterious-egg-gmaps-age branch from 235699e to d1d4fc8 Compare April 17, 2025 14:37
@FrancoisGe FrancoisGe merged commit 3fe5119 into master-mysterious-egg Apr 18, 2025
@FrancoisGe FrancoisGe deleted the mysterious-egg-gmaps-age branch April 18, 2025 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants