Skip to content

Commit

Permalink
Identify and fix issue with API returning empty array (#679)
Browse files Browse the repository at this point in the history
* integrating rail station graph with tram disruptions

* replaced atcoCode filter with naPTAN

* Empty-Commit

* removed unexpected console statement.

Co-authored-by: Sudheer Kotha <sudheer.kotha@wmca@org.uk>
  • Loading branch information
sudheer-rk and Sudheer Kotha authored Nov 4, 2022
1 parent d6b1e11 commit ca412d9
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions src/customHooks/useFilterLogic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -151,7 +151,6 @@ const useFilterLogic = () => {
}
}
}

return filteredData;
};

Expand Down
4 changes: 4 additions & 0 deletions src/globalState/AutoCompleteContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const AutoCompleteProvider = (props) => {
routeName: null,
stopName: null,
lines: [],
naPTAN: null,
to: null,
},
selectedItemTo: {
Expand All @@ -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
Expand All @@ -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') || '',
},
};

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ca412d9

Please sign in to comment.