FIO-8575: Added ability to reload google maps library with correct API key #5683
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Link to Jira Ticket
https://formio.atlassian.net/browse/FIO-8575
Description
Issue: When integrating the Google Maps provider into the address component, the script for Google Maps is loaded with the URL including the API key. However, during the creation of an address component with the Google Maps provider, the library is loaded without an API key due to the preview modal executing the code to load the library. This results in the Google Maps library being loaded without the API key, and subsequent updates to the API key do not affect the already loaded library. Consequently, Google Maps continues to operate without the API key across web pages, unless a full page reload is performed.
Solution: The solution involves a method to verify if the Google Maps library has already been loaded by inspecting the src attribute of the script for the correct API key. If the script is found with an incorrect or missing API key, the method proceeds to remove all Google Maps scripts and clear related global properties. This approach ensures that the library can be correctly reloaded with the updated API key, allowing for changes to the API key to be accurately reflected without necessitating a page reload. This is achieved through a function that checks for the presence of the Google Maps script with the expected API key and, if not found as expected, removes the script and any related global properties to allow for a fresh load with the correct settings.
How has this PR been tested?
Manually.
Checklist: