Skip to content

Commit

Permalink
IBX-9313: Fix Version is undefined - languageCode problem
Browse files Browse the repository at this point in the history
  • Loading branch information
tischsoic committed Dec 17, 2024
1 parent 56724ee commit 530e8f9
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const useFindLocationsByParentLocationIdFetch = (locationData, { sortClau
resolve,
);
});
const getFindSuggestionsPromise = () =>
const getFindSuggestionsPromise = (languageCodes) =>
new Promise((resolve) => {
if (suggestionsStorage[locationData.parentLocationId]) {
resolve(suggestionsStorage[locationData.parentLocationId]);
Expand All @@ -52,6 +52,7 @@ export const useFindLocationsByParentLocationIdFetch = (locationData, { sortClau
{
...restInfo,
parentLocationId: locationData.parentLocationId,
languageCodes,
limit,
offset,
},
Expand All @@ -78,23 +79,39 @@ export const useFindLocationsByParentLocationIdFetch = (locationData, { sortClau
}

dispatch({ type: 'FETCH_START' });
Promise.all([getFindLocationsPromise(), getFindSuggestionsPromise()]).then(([locations, suggestions]) => {
if (effectCleaned) {
return;
}
getFindLocationsPromise().then((locations) => {
const languageCodes = locations.subitems.map((subitem) => subitem.location.ContentInfo.Content.mainLanguageCode);

getFindSuggestionsPromise(languageCodes).then((suggestions) => {
if (effectCleaned) {
return;
}

const suggestionsCurrentVersionMap = suggestions.View?.Result.searchHits.searchHit.reduce((contentInfoMap, suggestion) => {
const suggestionLocation = suggestion.value.Location;

const suggestionsResults = suggestions.View?.Result.aggregations[0]?.entries.map(({ key }) => ({
data: getContentTypeDataByHref(key.ContentType._href),
}));
contentInfoMap[suggestionLocation.id] = suggestionLocation.ContentInfo.Content.CurrentVersion;

if (suggestionsResults) {
setSuggestionsStorage((prevState) => ({
...prevState,
[locationData.parentLocationId]: suggestionsResults,
return contentInfoMap;
}, {});

locations.subitems.forEach((subitem) => {
subitem.location.ContentInfo.Content.CurrentVersion = suggestionsCurrentVersionMap[subitem.location.id];
});

const suggestionsResults = suggestions.View?.Result.aggregations[0]?.entries.map(({ key }) => ({
data: getContentTypeDataByHref(key.ContentType._href),
}));
}

dispatch({ type: 'FETCH_END', data: locations });
if (suggestionsResults) {
setSuggestionsStorage((prevState) => ({
...prevState,
[locationData.parentLocationId]: suggestionsResults,
}));
}

dispatch({ type: 'FETCH_END', data: locations });
});
});

return () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@ const ENDPOINT_LOCATION_LIST = '/api/ibexa/v2/module/universal-discovery/locatio
export const QUERY_LIMIT = 50;
export const AGGREGATIONS_LIMIT = 4;

const addLanguageCodeToCreateViewEndpoint = (body) => {
const addLanguageCodeToCreateViewEndpoint = (body, languageCodes = []) => {
const adminUiConfig = getAdminUiConfig();
const viewInputLanguageCodes = languageCodes;

if (adminUiConfig.languages.priority[0]) {
body.ViewInput.languageCode = adminUiConfig.languages.priority[0];
viewInputLanguageCodes.push(adminUiConfig.languages.priority[0]);
}

const uniqueLanguageCodes = [...new Set(viewInputLanguageCodes)];

body.ViewInput.languageCodes = uniqueLanguageCodes;
};

const showErrorNotificationAbortWrapper = (error) => {
Expand Down Expand Up @@ -512,7 +517,16 @@ export const fetchAdminConfig = async ({ token, siteaccess, accessToken, instanc
};

export const findSuggestions = (
{ siteaccess, token, parentLocationId, accessToken, instanceUrl = DEFAULT_INSTANCE_URL, limit = QUERY_LIMIT, offset = 0 },
{
siteaccess,
token,
parentLocationId,
languageCodes,
accessToken,
instanceUrl = DEFAULT_INSTANCE_URL,
limit = QUERY_LIMIT,
offset = 0,
},
callback,
) => {
const body = {
Expand All @@ -536,7 +550,7 @@ export const findSuggestions = (
},
};

addLanguageCodeToCreateViewEndpoint(body);
addLanguageCodeToCreateViewEndpoint(body, languageCodes);

const request = new Request(ENDPOINT_CREATE_VIEW, {
method: 'POST',
Expand Down

0 comments on commit 530e8f9

Please sign in to comment.