From 489a5acb2fdf324ca062b51b7d97e6affb11e488 Mon Sep 17 00:00:00 2001 From: Vesa Meskanen Date: Thu, 31 Aug 2023 12:09:01 +0300 Subject: [PATCH 1/5] fix: clean up totally confusing function names Search library code declared local functions, which had identical names with the search context hooks, and renamed those hooks inside the local scope to something non-descriptive. This made the code very confusing and hard to understand. Now sensible names are used. --- .../index.js | 58 +++++++++++-------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/digitransit-search-util/packages/digitransit-search-util-execute-search-immidiate/index.js b/digitransit-search-util/packages/digitransit-search-util-execute-search-immidiate/index.js index 3548a6573b..00acc1f790 100644 --- a/digitransit-search-util/packages/digitransit-search-util-execute-search-immidiate/index.js +++ b/digitransit-search-util/packages/digitransit-search-util-execute-search-immidiate/index.js @@ -54,7 +54,7 @@ function getStopsFromGeocoding(stops, URL_PELIAS_PLACE) { }); }); } -function getFavouriteLocations(favourites, input) { +function filterFavouriteLocations(favourites, input) { return Promise.resolve( filterMatchingToInput(favourites, input, ['address', 'name']).map(item => ({ type: 'FavouritePlace', @@ -165,7 +165,7 @@ function getBackSuggestion() { ]); } -function getFavouriteStops(stopsAndStations, input) { +function filterFavouriteStops(stopsAndStations, input) { return stopsAndStations.then(stops => { return filterMatchingToInput(stops, input, [ 'properties.name', @@ -175,7 +175,7 @@ function getFavouriteStops(stopsAndStations, input) { }); } -function getOldSearches(oldSearches, input, dropLayers) { +function filterOldSearches(oldSearches, input, dropLayers) { let matchingOldSearches = filterMatchingToInput(oldSearches, input, [ 'properties.name', 'properties.label', @@ -203,13 +203,15 @@ function getOldSearches(oldSearches, input, dropLayers) { ); } -function hasFavourites(context, locations, stops) { - const favouriteLocations = locations(context); - if (favouriteLocations && favouriteLocations.length > 0) { +function hasFavourites(searchContext) { + const favouriteLocations = searchContext.getFavouriteLocations( + searchContext.context, + ); + if (favouriteLocations?.length > 0) { return true; } - const favouriteStops = stops(context); - return favouriteStops && favouriteStops.length > 0; + const favouriteStops = searchContext.getFavouriteStops(searchContext.context); + return favouriteStops?.length > 0; } const routeLayers = [ @@ -240,9 +242,9 @@ export function getSearchResults( ) { const { getPositions, - getFavouriteLocations: locations, - getOldSearches: prevSearches, - getFavouriteStops: stops, + getFavouriteLocations, + getOldSearches, + getFavouriteStops, parkingAreaSources, getLanguage, getStopAndStationsQuery, @@ -295,7 +297,7 @@ export function getSearchResults( } if ( targets.includes('SelectFromOwnLocations') && - hasFavourites(context, locations, stops) + hasFavourites(searchContext) ) { searchComponents.push(selectFromOwnLocations(input)); } @@ -303,8 +305,10 @@ export function getSearchResults( // eslint-disable-next-line prefer-destructuring const searchParams = geocodingSearchParams; if (sources.includes('Favourite')) { - const favouriteLocations = locations(context); - searchComponents.push(getFavouriteLocations(favouriteLocations, input)); + const favouriteLocations = getFavouriteLocations(context); + searchComponents.push( + filterFavouriteLocations(favouriteLocations, input), + ); if (sources.includes('Back')) { searchComponents.push(getBackSuggestion()); } @@ -328,7 +332,7 @@ export function getSearchResults( ); } if (allSources || sources.includes('History')) { - const locationHistory = prevSearches(context, 'endpoint'); + const locationHistory = getOldSearches(context, 'endpoint'); const dropLayers = [ 'currentPosition', 'selectFromMap', @@ -341,7 +345,9 @@ export function getSearchResults( 'back', ]; dropLayers.push(...routeLayers); - searchComponents.push(getOldSearches(locationHistory, input, dropLayers)); + searchComponents.push( + filterOldSearches(locationHistory, input, dropLayers), + ); } } if (allTargets || targets.includes('ParkingAreas')) { @@ -371,7 +377,7 @@ export function getSearchResults( ); } if (allSources || sources.includes('History')) { - const history = prevSearches(context); + const history = getOldSearches(context); const dropLayers = [ 'currentPosition', 'selectFromMap', @@ -384,13 +390,13 @@ export function getSearchResults( ]; dropLayers.push(...routeLayers); dropLayers.push(...locationLayers); - searchComponents.push(getOldSearches(history, input, dropLayers)); + searchComponents.push(filterOldSearches(history, input, dropLayers)); } } if (allTargets || targets.includes('Stops')) { if (sources.includes('Favourite')) { - const favouriteStops = stops(context); + const favouriteStops = getFavouriteStops(context); let stopsAndStations; if (favouriteStops.every(stop => stop.type === 'station')) { stopsAndStations = getStopsFromGeocoding( @@ -414,7 +420,7 @@ export function getSearchResults( return results; }); } - searchComponents.push(getFavouriteStops(stopsAndStations, input)); + searchComponents.push(filterFavouriteStops(stopsAndStations, input)); } if (allSources || sources.includes('Datasource')) { const geocodingLayers = ['stop', 'station']; @@ -449,7 +455,7 @@ export function getSearchResults( ); } if (allSources || sources.includes('History')) { - const stopHistory = prevSearches(context).filter(item => { + const stopHistory = getOldSearches(context).filter(item => { if (item.properties.gid) { return item.properties.gid.includes('GTFS:'); } @@ -473,12 +479,14 @@ export function getSearchResults( dropLayers.push('bikestation'); } searchComponents.push( - getOldSearches(stopHistory, input, dropLayers).then(result => + filterOldSearches(stopHistory, input, dropLayers).then(result => filterResults ? filterResults(result, mode) : result, ), ); } else { - searchComponents.push(getOldSearches(stopHistory, input, dropLayers)); + searchComponents.push( + filterOldSearches(stopHistory, input, dropLayers), + ); } } } @@ -503,7 +511,7 @@ export function getSearchResults( ), ); if (allSources || sources.includes('History')) { - const routeHistory = prevSearches(context); + const routeHistory = getOldSearches(context); const dropLayers = [ 'currentPosition', 'selectFromMap', @@ -525,7 +533,7 @@ export function getSearchResults( } dropLayers.push(...locationLayers); searchComponents.push( - getOldSearches(routeHistory, input, dropLayers).then(results => + filterOldSearches(routeHistory, input, dropLayers).then(results => filterResults ? filterResults(results, mode, 'Routes') : results, ), ); From 6c66b29112c6b0c2833ee54f4e3d36e62d5b3471 Mon Sep 17 00:00:00 2001 From: Vesa Meskanen Date: Thu, 31 Aug 2023 13:02:04 +0300 Subject: [PATCH 2/5] fix: parking area history search no longer accepts stops and stations --- .../digitransit-search-util-execute-search-immidiate/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/digitransit-search-util/packages/digitransit-search-util-execute-search-immidiate/index.js b/digitransit-search-util/packages/digitransit-search-util-execute-search-immidiate/index.js index 00acc1f790..25926165c9 100644 --- a/digitransit-search-util/packages/digitransit-search-util-execute-search-immidiate/index.js +++ b/digitransit-search-util/packages/digitransit-search-util-execute-search-immidiate/index.js @@ -387,6 +387,8 @@ export function getSearchResults( 'bikestation', 'bikeRentalStation', 'back', + 'stop', + 'station', ]; dropLayers.push(...routeLayers); dropLayers.push(...locationLayers); From 5ba72e3ff34712862867641df459ee5a02d7bdde Mon Sep 17 00:00:00 2001 From: Vesa Meskanen Date: Thu, 31 Aug 2023 13:10:47 +0300 Subject: [PATCH 3/5] chore: bump up versions --- .../digitransit-component-autosuggest-panel/package.json | 4 ++-- .../packages/digitransit-component-autosuggest/package.json | 4 ++-- .../packages/digitransit-component/package.json | 4 ++-- .../package.json | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/digitransit-component/packages/digitransit-component-autosuggest-panel/package.json b/digitransit-component/packages/digitransit-component-autosuggest-panel/package.json index 17240d291a..7e9bc8028d 100644 --- a/digitransit-component/packages/digitransit-component-autosuggest-panel/package.json +++ b/digitransit-component/packages/digitransit-component-autosuggest-panel/package.json @@ -1,6 +1,6 @@ { "name": "@digitransit-component/digitransit-component-autosuggest-panel", - "version": "2.0.6", + "version": "2.0.7", "description": "digitransit-component autosuggest-panel module", "main": "index.js", "files": [ @@ -28,7 +28,7 @@ "author": "Digitransit Authors", "license": "(AGPL-3.0 OR EUPL-1.2)", "peerDependencies": { - "@digitransit-component/digitransit-component-autosuggest": "^1.9.10", + "@digitransit-component/digitransit-component-autosuggest": "^1.9.11", "@digitransit-component/digitransit-component-icon": "^0.2.2", "@hsl-fi/sass": "^0.2.0", "classnames": "2.2.6", diff --git a/digitransit-component/packages/digitransit-component-autosuggest/package.json b/digitransit-component/packages/digitransit-component-autosuggest/package.json index c9f92b32e4..ec797e881f 100644 --- a/digitransit-component/packages/digitransit-component-autosuggest/package.json +++ b/digitransit-component/packages/digitransit-component-autosuggest/package.json @@ -1,6 +1,6 @@ { "name": "@digitransit-component/digitransit-component-autosuggest", - "version": "1.9.10", + "version": "1.9.11", "description": "digitransit-component autosuggest module", "main": "index.js", "files": [ @@ -29,7 +29,7 @@ "author": "Digitransit Authors", "license": "(AGPL-3.0 OR EUPL-1.2)", "dependencies": { - "@digitransit-search-util/digitransit-search-util-execute-search-immidiate": "^1.3.3", + "@digitransit-search-util/digitransit-search-util-execute-search-immidiate": "^1.3.4", "@digitransit-search-util/digitransit-search-util-get-label": "^0.2.0", "@digitransit-search-util/digitransit-search-util-uniq-by-label": "^1.1.0", "@hsl-fi/hooks": "^1.2.3" diff --git a/digitransit-component/packages/digitransit-component/package.json b/digitransit-component/packages/digitransit-component/package.json index b6f508cb4f..f7e4bbc17e 100644 --- a/digitransit-component/packages/digitransit-component/package.json +++ b/digitransit-component/packages/digitransit-component/package.json @@ -14,8 +14,8 @@ "docs": "node -r esm ../../scripts/generate-readmes" }, "dependencies": { - "@digitransit-component/digitransit-component-autosuggest": "^1.9.9", - "@digitransit-component/digitransit-component-autosuggest-panel": "^2.0.5", + "@digitransit-component/digitransit-component-autosuggest": "^1.9.11", + "@digitransit-component/digitransit-component-autosuggest-panel": "^2.0.7", "@digitransit-component/digitransit-component-control-panel": "^1.1.3", "@digitransit-component/digitransit-component-favourite-bar": "1.1.3", "@digitransit-component/digitransit-component-favourite-editing-modal": "^1.1.4", diff --git a/digitransit-search-util/packages/digitransit-search-util-execute-search-immidiate/package.json b/digitransit-search-util/packages/digitransit-search-util-execute-search-immidiate/package.json index 02dc93544c..f260385e6e 100644 --- a/digitransit-search-util/packages/digitransit-search-util-execute-search-immidiate/package.json +++ b/digitransit-search-util/packages/digitransit-search-util-execute-search-immidiate/package.json @@ -1,6 +1,6 @@ { "name": "@digitransit-search-util/digitransit-search-util-execute-search-immidiate", - "version": "1.3.3", + "version": "1.3.4", "description": "digitransit-search-util execute-search-immidiate module", "main": "index.js", "publishConfig": { From 18b63d548beb90c2a99dc06000f69bbc1c78cf87 Mon Sep 17 00:00:00 2001 From: Vesa Meskanen Date: Thu, 31 Aug 2023 13:14:59 +0300 Subject: [PATCH 4/5] fix: bicycle translations to sv --- app/component/EmbeddedSearch/EmbeddedSearch.js | 2 +- app/translations.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/component/EmbeddedSearch/EmbeddedSearch.js b/app/component/EmbeddedSearch/EmbeddedSearch.js index aec9569562..b8fadce573 100644 --- a/app/component/EmbeddedSearch/EmbeddedSearch.js +++ b/app/component/EmbeddedSearch/EmbeddedSearch.js @@ -40,7 +40,7 @@ const translations = { }, sv: { 'own-position': 'Min position', - 'find-bike-route': 'Sök en cyckelrutt', + 'find-bike-route': 'Sök en cykelrutt', 'find-walk-route': 'Sök en promenadsrutt', 'find-route': 'Sök en rutt', 'search-fields-sr-instructions': '', diff --git a/app/translations.js b/app/translations.js index 3fe04edf42..e1dfc6bbe1 100644 --- a/app/translations.js +++ b/app/translations.js @@ -3956,7 +3956,7 @@ const translations = { 'avoid-walking': 'Undvik gång', 'back-button-title': 'Tillbaka till föregående sida', 'back-to-front-page': 'Tillbaka till framsidan ›', - bicycle: 'cyckel', + bicycle: 'cykel', 'bicycle-distance-duration': 'Cykla {duration} ({distance})', 'bicycle-walk-from-transit': 'Ta cykeln från {transportMode} och led cykeln {distance} ({duration})', From be3fdfea465468a57ff739cf517603bd57225377 Mon Sep 17 00:00:00 2001 From: Vesa Meskanen Date: Fri, 1 Sep 2023 11:41:19 +0300 Subject: [PATCH 5/5] fix: sv translations --- app/component/EmbeddedSearch/EmbeddedSearch.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/component/EmbeddedSearch/EmbeddedSearch.js b/app/component/EmbeddedSearch/EmbeddedSearch.js index b8fadce573..1feded154a 100644 --- a/app/component/EmbeddedSearch/EmbeddedSearch.js +++ b/app/component/EmbeddedSearch/EmbeddedSearch.js @@ -40,9 +40,9 @@ const translations = { }, sv: { 'own-position': 'Min position', - 'find-bike-route': 'Sök en cykelrutt', - 'find-walk-route': 'Sök en promenadsrutt', - 'find-route': 'Sök en rutt', + 'find-bike-route': 'Sök cykelrutt', + 'find-walk-route': 'Sök promenadrutt', + 'find-route': 'Sök rutt', 'search-fields-sr-instructions': '', 'search-route': 'Söka rutter', },