From 591e7afb8e78a9b978fae6dc65199b251e8e87ef Mon Sep 17 00:00:00 2001 From: Janne Forsman Date: Fri, 11 Apr 2025 13:58:08 +0300 Subject: [PATCH] fix: FeatureIndex was not reseted when cliking anohter feature from the map without closing previous feature Refs: LIIK-759 --- map-view/src/components/FeatureInfo.tsx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/map-view/src/components/FeatureInfo.tsx b/map-view/src/components/FeatureInfo.tsx index 3dba94e2..b05bd078 100644 --- a/map-view/src/components/FeatureInfo.tsx +++ b/map-view/src/components/FeatureInfo.tsx @@ -44,6 +44,7 @@ interface FeatureInfoProps extends WithStyles, WithTranslation { interface FeatureInfoState { featureIndex: number; realPlanDistance?: number; + features: Feature[]; } class FeatureInfo extends React.Component { @@ -52,9 +53,17 @@ class FeatureInfo extends React.Component { this.state = { featureIndex: 0, realPlanDistance: undefined, + features: props.features, }; } + static getDerivedStateFromProps(props: FeatureInfoProps, state: FeatureInfoState) { + if (props.features !== state.features) { + return { featureIndex: 0, realPlanDistance: undefined, features: props.features }; + } + return null; + } + getAdminLink(feature: Feature) { const app_name = feature["app_name"]; const fid = feature["id_"]; @@ -78,6 +87,7 @@ class FeatureInfo extends React.Component { const { features, classes, onClose, t } = this.props; const { featureIndex } = this.state; const feature = features[featureIndex]; + const fid = feature["id_"]; const featureType = fid.split(".")[0]; const {