Skip to content

Commit

Permalink
chore: tune old search cleanup
Browse files Browse the repository at this point in the history
Label can change when searching with or without alternate name
e.g. search steissi gives diffrent labe for same item.
Therefore compare name, street and address directly.
Code rearranged due to strange javascript execution problems.
  • Loading branch information
vesameskanen committed Jul 3, 2023
1 parent 0b3a3d5 commit a2e07e2
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions app/component/WithSearchContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,19 +193,24 @@ export default function withSearchContext(
})
.then(res => {
const newItem = { ...item };
let save = true;
if (res.features?.length > 0) {
let canSave = true;
if (res.features != null && res.features.length > 0) {
// update only position. It is surprising if, say, the name changes at selection.
const geom = res.features[0].geometry;
newItem.geometry.coordinates = geom.coordinates;
if (
newItem.properties.label !== res.features[0].properties.label
newItem.properties.name !== res.features[0].properties.name ||
newItem.properties.street !==
res.features[0].properties.street ||
newItem.properties.housenumber !==
res.features[0].properties.housenumber
) {
save = false;
} else {
// update position
newItem.geometry.coordinates =
res.features[0].geometry.coordinates;
// Item properties have changed unexpectedly. For example,
// an enterprise may have moved to new premises. Remove outdated information.
canSave = false;
}
}
if (save) {
if (canSave) {
this.saveOldSearch(newItem, type, id);
} else {
this.context.executeAction(removeSearch, {
Expand Down

0 comments on commit a2e07e2

Please sign in to comment.