This PR: - updates the react 16 to react 17 - replaces the underlying library for the map widget - adds clustering of markers - refactor code for map widget's component ## Description Fixes #16946 ## Type of change - Breaking change ## How Has This Been Tested? - Manually ### Test Plan https://github.com/appsmithorg/TestSmith/issues/2149 ### Issues raised during DP testing 1. https://github.com/appsmithorg/appsmith/pull/19315#issuecomment-1378495845 ## Checklist: ### Dev activity - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag ### QA activity: - [ ] Test plan has been approved by relevant developers - [x] Test plan has been peer reviewed by QA - [ ] Cypress test cases have been added and approved by either SDET or manual QA - [ ] Organized project review call with relevant stakeholders after Round 1/2 of QA - [ ] Added Test Plan Approved label after reveiwing all Cypress test Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com> Co-authored-by: Arsalan <arsalanyaldram0211@outlook.com> Co-authored-by: rahulramesha <rahul@appsmith.com>
73 lines
1.7 KiB
TypeScript
73 lines
1.7 KiB
TypeScript
import styled from "styled-components";
|
|
import React, { useRef, useEffect } from "react";
|
|
|
|
type Places = google.maps.places.PlaceResult[] | undefined;
|
|
|
|
type SearchBoxProps = {
|
|
isEnabled: boolean;
|
|
map?: google.maps.Map;
|
|
placeholder?: string;
|
|
updateCenter: (lat: number, long: number) => void;
|
|
};
|
|
|
|
const StyledInput = styled.input`
|
|
position: absolute;
|
|
top: 0%;
|
|
box-sizing: border-box;
|
|
border: 1px solid transparent;
|
|
width: min(90%, 240px);
|
|
height: 32px;
|
|
padding: 0 12px;
|
|
border-radius: 3px;
|
|
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
|
|
font-size: 14px;
|
|
outline: none;
|
|
text-overflow: ellipses;
|
|
left: 0;
|
|
right: 0;
|
|
margin: 24px auto;
|
|
`;
|
|
|
|
const SearchBox = (props: SearchBoxProps) => {
|
|
const { isEnabled, updateCenter } = props;
|
|
const searchBoxRef = useRef<HTMLInputElement>(null);
|
|
const searchBoxObjRef = useRef<google.maps.places.SearchBox>();
|
|
|
|
// initialize search box
|
|
useEffect(() => {
|
|
if (!searchBoxRef.current) return;
|
|
|
|
searchBoxObjRef.current = new window.google.maps.places.SearchBox(
|
|
searchBoxRef.current,
|
|
);
|
|
}, [searchBoxRef]);
|
|
|
|
// add event listeners to search box
|
|
useEffect(() => {
|
|
if (!searchBoxObjRef.current) return;
|
|
|
|
searchBoxObjRef.current?.addListener("places_changed", () => {
|
|
const places: Places = searchBoxObjRef.current?.getPlaces();
|
|
const location = places ? places[0].geometry?.location : undefined;
|
|
|
|
if (location) {
|
|
const lat = location.lat();
|
|
const long = location.lng();
|
|
updateCenter(lat, long);
|
|
}
|
|
});
|
|
}, [updateCenter]);
|
|
|
|
if (!isEnabled) return null;
|
|
|
|
return (
|
|
<StyledInput
|
|
placeholder="Enter location to search"
|
|
ref={searchBoxRef}
|
|
type="text"
|
|
/>
|
|
);
|
|
};
|
|
|
|
export default SearchBox;
|