Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ enum ELocationInputEvents {
"SET_CURRENT_LOCATION" = "set-current-location",
"GET_CURRENT_LOCATION" = "get-current-location",
"MOUNT" = "mount",
"SHOW_LOCATION_MODAL_READY" = "show-location-modal-ready",
"SHOW_MODAL" = "show-location-modal",
"HIDE_MODAL" = "hide-location-modal",
"CLICK_EDIT_BUTTON" = "click-edit-button",
Expand Down Expand Up @@ -635,6 +636,23 @@ describe("location-input-group", () => {
// PostalCodeError

//Modal Events
describe("Show Location Modal Ready events", () => {
it("should fire show-location-modal-ready after it is registered", async () => {
const handleShowLocationModalReady = jest.fn();
renderComponent({
eventType: ELocationInputEvents.SHOW_LOCATION_MODAL_READY,
eventListener: (formRef) => () => {
handleShowLocationModalReady();
formRef.dispatchFieldEvent(UI_TYPE, ELocationInputEvents.SHOW_MODAL, COMPONENT_ID);
},
});
await waitFor(() => {
expect(handleShowLocationModalReady).toHaveBeenCalled();
expect(getLocationModal(true)).toBeInTheDocument();
});
});
});

describe("Modal events", () => {
it("should fire show-location-modal event on showing location modal", async () => {
const handleShowReviewModal = jest.fn();
Expand Down
3 changes: 3 additions & 0 deletions src/components/fields/location-field/location-field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ export const LocationField = (props: IGenericFieldProps<ILocationFieldSchema>) =
useEffect(() => {
addFieldEventListener("show-location-modal", id, handleLocationModalShow);

// Signal that the field has registered its listeners and is ready for external triggers.
dispatchFieldEvent("show-location-modal-ready", id);

return () => {
removeFieldEventListener("show-location-modal", id, handleLocationModalShow);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export const LocationSearch = ({
latitude: 1.29994179707526,
longitude: 103.789404349716,
bufferRadius: 1,
abortSignal: reverseGeocodeAborter.current.signal,
abortSignal: reverseGeocodeAborter.current?.signal,
otherFeatures: OneMapBoolean.YES,
getToken,
headers: mapApiHeaders,
Expand Down
9 changes: 9 additions & 0 deletions src/components/fields/location-field/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export type TSetCurrentLocationDetail = TLocationFieldDetail<ILocationCoord>;
export type TLocationFieldErrorDetail = TLocationFieldDetail<TErrorType>;

export type TLocationFieldEvents = {
"show-location-modal-ready": CustomEvent;
"get-current-location": CustomEvent;
"set-current-location": CustomEvent<TSetCurrentLocationDetail>;
error: CustomEvent<TLocationFieldErrorDetail>;
Expand All @@ -116,6 +117,14 @@ export class GeolocationPositionErrorWrapper extends Error {
// =============================================================================
// EVENTS (fired from FEE)
// =============================================================================
/** fired after the location field registers the `show-location-modal` event listener and is ready for external triggers */
function locationFieldEvent(
uiType: "location-field",
type: "show-location-modal-ready",
id: string,
listener: TFieldEventListener,
options?: boolean | AddEventListenerOptions | undefined
): void;
/** fired on showing location modal */
function locationFieldEvent(
uiType: "location-field",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -850,3 +850,10 @@ RefreshLocationAndTriggerGetCurrentLocation.args = {
label: "Refresh current location and trigger get current location",
mapApi: defaultMapApi,
};

export const ShowLocationModalReady = Template("show-location-modal-ready").bind({});
ShowLocationModalReady.args = {
uiType: "location-field",
label: "Show Location Modal Ready",
mapApi: defaultMapApi,
};