From ca412d968b9171abdb2c291ed3450307dbcb92b6 Mon Sep 17 00:00:00 2001 From: Sudheer <92720228+sudheer-rk@users.noreply.github.com> Date: Fri, 4 Nov 2022 09:41:31 +0000 Subject: [PATCH] Identify and fix issue with API returning empty array (#679) * integrating rail station graph with tram disruptions * replaced atcoCode filter with naPTAN * Empty-Commit * removed unexpected console statement. Co-authored-by: Sudheer Kotha --- .../TrainAutoComplete/TrainAutocomplete.js | 2 +- .../TramAutoCompleteResult.js | 4 ++-- .../customHooks/useAutoCompleteAPI.js | 2 +- .../customHooks/useGetTramStopByStop.js | 19 +++++++++++-------- src/customHooks/useFilterLogic.js | 3 +-- src/globalState/AutoCompleteContext.js | 4 ++++ 6 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/components/shared/Tray/TrayComponents/AutoComplete/TrainAutoComplete/TrainAutocomplete.js b/src/components/shared/Tray/TrayComponents/AutoComplete/TrainAutoComplete/TrainAutocomplete.js index 0c02eb25..c729e77e 100644 --- a/src/components/shared/Tray/TrayComponents/AutoComplete/TrainAutoComplete/TrainAutocomplete.js +++ b/src/components/shared/Tray/TrayComponents/AutoComplete/TrainAutoComplete/TrainAutocomplete.js @@ -22,7 +22,7 @@ const TrainAutoComplete = ({ to }) => { const selectedService = to ? autoCompleteState.selectedItemTo : autoCompleteState.selectedItem; const { loading, errorInfo, results, getAutoCompleteResults } = useAutoCompleteAPI( - `/rail/v2/station?q=${encodeURI(trainQuery)}`, + `/rail/v2/stations?q=${encodeURI(trainQuery)}`, 'train', trainQuery, to diff --git a/src/components/shared/Tray/TrayComponents/AutoComplete/TramAutoComplete/TramAutoCompleteResult/TramAutoCompleteResult.js b/src/components/shared/Tray/TrayComponents/AutoComplete/TramAutoComplete/TramAutoCompleteResult/TramAutoCompleteResult.js index bb4dcbff..dd352c65 100644 --- a/src/components/shared/Tray/TrayComponents/AutoComplete/TramAutoComplete/TramAutoCompleteResult/TramAutoCompleteResult.js +++ b/src/components/shared/Tray/TrayComponents/AutoComplete/TramAutoComplete/TramAutoCompleteResult/TramAutoCompleteResult.js @@ -15,15 +15,15 @@ const TramAutoCompleteResult = (props) => { if (autoCompleteState.selectedItem.selectedByMap) { autoCompleteDispatch({ type: 'RESET_SELECTED_SERVICES' }); } - autoCompleteDispatch({ type: 'UDPATE_SELECTED_ITEM', payload: { - id: result?.atcoCode, + id: result?.naPTAN, severity: result?.disruptionSeverity || 'success', stopName: result.name, operator: 'MML1', lines: [], + naPTAN: result.naPTAN, to, }, }); diff --git a/src/components/shared/Tray/TrayComponents/AutoComplete/customHooks/useAutoCompleteAPI.js b/src/components/shared/Tray/TrayComponents/AutoComplete/customHooks/useAutoCompleteAPI.js index e0490775..7d70ae89 100644 --- a/src/components/shared/Tray/TrayComponents/AutoComplete/customHooks/useAutoCompleteAPI.js +++ b/src/components/shared/Tray/TrayComponents/AutoComplete/customHooks/useAutoCompleteAPI.js @@ -60,7 +60,7 @@ const useAutoCompleteAPI = (apiPath, mode, query, to) => { )[0]; payload = { - id: result.atcoCode, + id: result.naPTAN, severity: result.disruptionSeverity || 'none', stopName: result.name, operator: result.service, diff --git a/src/components/shared/Tray/TrayComponents/SelectedService/InfoAboutSelectedService/TramInfoAboutSelectedService/customHooks/useGetTramStopByStop.js b/src/components/shared/Tray/TrayComponents/SelectedService/InfoAboutSelectedService/TramInfoAboutSelectedService/customHooks/useGetTramStopByStop.js index 52c9e781..b7cc28f1 100644 --- a/src/components/shared/Tray/TrayComponents/SelectedService/InfoAboutSelectedService/TramInfoAboutSelectedService/customHooks/useGetTramStopByStop.js +++ b/src/components/shared/Tray/TrayComponents/SelectedService/InfoAboutSelectedService/TramInfoAboutSelectedService/customHooks/useGetTramStopByStop.js @@ -39,7 +39,7 @@ const useGetTramStopByStop = () => { (response) => { setLoading(false); // Update selectedItem.lines with inbetween lines to match the user's input - const lines = response.data?.metroStopsBetween || []; + const lines = response.data || []; if (lines.length) { autoCompleteDispatch({ @@ -77,15 +77,18 @@ const useGetTramStopByStop = () => { setLoading(true); // Update loading state to true as we are hitting API startApiTimeout(); axios - .get(`${REACT_APP_API_HOST}/Metro/v2/stopsbetween/${selectedItem.id}/${selectedItemTo.id}`, { - headers: { - 'Ocp-Apim-Subscription-Key': REACT_APP_API_KEY, - }, - cancelToken: source.current.token, // Set token with API call, so we can cancel this call on unmount - }) + .get( + `${REACT_APP_API_HOST}/Metro/v2/stopsbetween/${selectedItem.naPTAN}/${selectedItemTo.naPTAN}`, + { + headers: { + 'Ocp-Apim-Subscription-Key': REACT_APP_API_KEY, + }, + cancelToken: source.current.token, // Set token with API call, so we can cancel this call on unmount + } + ) .then(handleAutoCompleteApiResponse) .catch(handleAutoCompleteApiError); - }, [handleAutoCompleteApiResponse, selectedItem.id, selectedItemTo.id, startApiTimeout]); + }, [handleAutoCompleteApiResponse, selectedItem.naPTAN, selectedItemTo.naPTAN, startApiTimeout]); useEffect(() => { setErrorInfo(null); diff --git a/src/customHooks/useFilterLogic.js b/src/customHooks/useFilterLogic.js index f21e271b..728d31b4 100644 --- a/src/customHooks/useFilterLogic.js +++ b/src/customHooks/useFilterLogic.js @@ -84,7 +84,7 @@ const useFilterLogic = () => { if (stopsAffected && stopsAffected.length > 0) { const lineCodes = selectedItem.lines && selectedItem.lines.length > 0 - ? selectedItem.lines.map((stop) => stop.atcoCode) + ? selectedItem.lines.map((stop) => stop.naPTAN) : [selectedItem.id, selectedItemTo.id]; return disrItem.stopsAffected.some((el) => lineCodes.indexOf(el.atcoCode) > -1); @@ -151,7 +151,6 @@ const useFilterLogic = () => { } } } - return filteredData; }; diff --git a/src/globalState/AutoCompleteContext.js b/src/globalState/AutoCompleteContext.js index e99f847a..8a10abe1 100644 --- a/src/globalState/AutoCompleteContext.js +++ b/src/globalState/AutoCompleteContext.js @@ -25,6 +25,7 @@ export const AutoCompleteProvider = (props) => { routeName: null, stopName: null, lines: [], + naPTAN: null, to: null, }, selectedItemTo: { @@ -35,6 +36,7 @@ export const AutoCompleteProvider = (props) => { stopName: null, routeName: null, lines: [], + naPTAN: null, to: null, }, // The selected location is used to store selected roads address @@ -43,6 +45,7 @@ export const AutoCompleteProvider = (props) => { radius: parseInt(getSearchParam('radius'), 10) || null, lat: getSearchParam('lat') || null, lon: getSearchParam('lon') || null, + naPTAN: getSearchParam('naPTAN') || '', }, }; @@ -132,6 +135,7 @@ export const AutoCompleteProvider = (props) => { setSearchParam('lat', action.payload.lat); setSearchParam('lon', action.payload.lon); setSearchParam('radius', action.payload.radius); + setSearchParam('naPTAN', action.payload.naPTAN); return { ...state,