Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-9313: Fix fetching ContentInfo on select #1414

Open
wants to merge 3 commits into
base: 4.6
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -424,7 +441,18 @@ export const createDraft = ({ token, siteaccess, accessToken, contentId, instanc
};

export const loadContentInfo = (
{ token, siteaccess, accessToken, contentId, limit = QUERY_LIMIT, offset = 0, signal, instanceUrl = DEFAULT_INSTANCE_URL },
{
token,
siteaccess,
accessToken,
contentId,
noLanguageCode = false,
useAlwaysAvailable = undefined,
limit = QUERY_LIMIT,
offset = 0,
signal,
instanceUrl = DEFAULT_INSTANCE_URL,
},
callback,
) => {
const body = {
Expand All @@ -438,10 +466,17 @@ export const loadContentInfo = (
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
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ const UniversalDiscoveryModule = (props) => {
.join(',');

if (!locationIds) {
return Promise.resolve([]);
return Promise.resolve(null);
Copy link
Contributor Author

@tischsoic tischsoic Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: changed to null, because when data is present we have an object with data (not an array) so resolving sometimes with an object and sometimes with an empty array was confusing.

}

return new Promise((resolve) => {
Expand All @@ -262,10 +262,19 @@ const UniversalDiscoveryModule = (props) => {
return Promise.resolve([]);
}

const contentId = locationsWithoutVersion.map((item) => item.location.ContentInfo.Content._id).join(',');
const contentIds = locationsWithoutVersion.map((item) => item.location.ContentInfo.Content._id).join(',');

return new Promise((resolve) => {
loadContentInfo({ ...restInfo, contentId, signal }, (response) => resolve(response));
loadContentInfo(
{
...restInfo,
noLanguageCode: true,
useAlwaysAvailable: true,
contentId: contentIds,
signal,
},
(response) => resolve(response),
);
});
};
const contentTypesMapGlobal = useMemo(
Expand Down Expand Up @@ -344,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 All @@ -362,7 +380,7 @@ const UniversalDiscoveryModule = (props) => {
Promise.all([loadPermissions(), loadVersions(abortControllerRef.current.signal)]).then((response) => {
const [locationsWithPermissions, locationsWithVersions] = response;

if (!locationsWithPermissions.length && !locationsWithVersions.length) {
if (!locationsWithPermissions?.LocationList.locations.length && !locationsWithVersions.length) {
return;
}

Expand Down
Loading