Skip to content

Commit

Permalink
fix for props.selectedLocations
Browse files Browse the repository at this point in the history
  • Loading branch information
tischsoic committed Dec 19, 2024
1 parent 4779908 commit bd86837
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,17 @@ export const findLocationsBySearchQuery = (
};

export const findLocationsById = (
{ token, siteaccess, accessToken, id, limit = QUERY_LIMIT, offset = 0, instanceUrl = DEFAULT_INSTANCE_URL },
{
token,
siteaccess,
accessToken,
id,
noLanguageCode = false,
useAlwaysAvailable = undefined,
limit = QUERY_LIMIT,
offset = 0,
instanceUrl = DEFAULT_INSTANCE_URL,
},
callback,
) => {
const body = {
Expand All @@ -271,10 +281,17 @@ export const findLocationsById = (
limit,
offset,
},
useAlwaysAvailable,
},
};

addLanguageCodeToCreateViewEndpoint(body);
if (useAlwaysAvailable !== undefined) {
body.ViewInput.useAlwaysAvailable = useAlwaysAvailable;
}

if (!noLanguageCode) {
addLanguageCodeToCreateViewEndpoint(body);
}

const request = new Request(`${instanceUrl}${ENDPOINT_CREATE_VIEW}`, {
method: 'POST',
Expand Down Expand Up @@ -430,7 +447,7 @@ export const loadContentInfo = (
accessToken,
contentId,
noLanguageCode = false,
useAlwaysAvailable = false,
useAlwaysAvailable = undefined,
limit = QUERY_LIMIT,
offset = 0,
signal,
Expand All @@ -453,6 +470,10 @@ export const loadContentInfo = (
},
};

if (useAlwaysAvailable !== undefined) {
body.ViewInput.useAlwaysAvailable = useAlwaysAvailable;
}

if (!noLanguageCode) {
addLanguageCodeToCreateViewEndpoint(body);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,15 +353,24 @@ const UniversalDiscoveryModule = (props) => {
return;
}

findLocationsById({ ...restInfo, id: props.selectedLocations.join(','), limit: props.selectedLocations.length }, (locations) => {
const mappedLocation = props.selectedLocations.map((locationId) => {
const location = locations.find(({ id }) => id === parseInt(locationId, 10));
findLocationsById(
{
...restInfo,
noLanguageCode: true,
useAlwaysAvailable: true,
id: props.selectedLocations.join(','),
limit: props.selectedLocations.length,
},
(locations) => {
const mappedLocation = props.selectedLocations.map((locationId) => {
const location = locations.find(({ id }) => id === parseInt(locationId, 10));

return { location };
});
return { location };
});

dispatchSelectedLocationsAction({ type: 'REPLACE_SELECTED_LOCATIONS', locations: mappedLocation });
});
dispatchSelectedLocationsAction({ type: 'REPLACE_SELECTED_LOCATIONS', locations: mappedLocation });
},
);
}, [props.selectedLocations]);

useEffect(() => {
Expand Down

0 comments on commit bd86837

Please sign in to comment.