Skip to content

Commit 8d19e45

Browse files
jeroen-huizer-conclusiongjulivan
authored andcommitted
fix: make marker key as unique as possible instead of using array-index as key
1 parent c15bb0e commit 8d19e45

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

packages/pluggableWidgets/maps-web/src/components/GoogleMap.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ function GoogleMap(props: GoogleMapsProps): ReactElement {
102102
.concat(currentLocation ? [currentLocation] : [])
103103
.filter(m => !!m)
104104
.map((marker, index) => (
105-
<GoogleMapsMarker key={`marker_${index}`} {...marker} />
105+
<GoogleMapsMarker
106+
key={`marker_${marker.id ?? marker.latitude + "_" + marker.longitude}`}
107+
{...marker}
108+
/>
106109
))}
107110
</GoogleMapComponent>
108111
) : (

packages/pluggableWidgets/maps-web/src/components/LeafletMap.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export function LeafletMap(props: LeafletProps): ReactElement {
8989
{locations
9090
.concat(currentLocation ? [currentLocation] : [])
9191
.filter(m => !!m)
92-
.map((marker, index) => (
92+
.map(marker => (
9393
<MarkerComponent
9494
icon={
9595
marker.url
@@ -100,7 +100,7 @@ export function LeafletMap(props: LeafletProps): ReactElement {
100100
: defaultMarkerIcon
101101
}
102102
interactive={!!marker.title || !!marker.onClick}
103-
key={`marker_${index}`}
103+
key={`marker_${marker.id ?? marker.latitude + "_" + marker.longitude}`}
104104
eventHandlers={{
105105
click: marker.title ? undefined : marker.onClick
106106
}}

packages/pluggableWidgets/maps-web/src/utils/data.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ function fromDatasource(marker: DynamicMarkersType, item: ObjectItem): ModeledMa
3939
longitude,
4040
title: title ? title.get(item).value : "",
4141
action: onClickAttribute ? onClickAttribute.get(item).execute : undefined,
42-
customMarker: marker.customMarkerDynamic?.value?.uri
42+
customMarker: marker.customMarkerDynamic?.value?.uri,
43+
id: item.id
4344
};
4445
}
4546

packages/pluggableWidgets/maps-web/typings/shared.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export interface ModeledMarker {
77
title?: string;
88
customMarker?: string;
99
action?: () => void;
10+
id?: string;
1011
}
1112

1213
export interface Marker {
@@ -15,6 +16,7 @@ export interface Marker {
1516
url: string;
1617
onClick?: () => void;
1718
title?: string;
19+
id?: string;
1820
}
1921

2022
export interface SharedProps extends Dimensions {

0 commit comments

Comments
 (0)