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-8714: Add languageCode to the v2/views request #1375

Merged
merged 4 commits into from
Nov 5, 2024
Merged
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
@@ -1,4 +1,5 @@
import { getRequestHeaders, getRequestMode } from '../../../../../Resources/public/js/scripts/helpers/request.helper.js';
import { getRequestHeaders, getRequestMode } from '@ibexa-admin-ui/src/bundle/Resources/public/js/scripts/helpers/request.helper.js';
import { getAdminUiConfig } from '@ibexa-admin-ui/src/bundle/Resources/public/js/scripts/helpers/context.helper';
import { showErrorNotification } from '../../common/services/notification.service';
import { handleRequestResponse, handleRequestResponseStatus } from '../../common/helpers/request.helper.js';

Expand All @@ -16,6 +17,14 @@ 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 adminUiConfig = getAdminUiConfig();

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

const showErrorNotificationAbortWrapper = (error) => {
if (error?.name === 'AbortError') {
return;
Expand Down Expand Up @@ -191,7 +200,7 @@ export const findLocationsBySearchQuery = (
},
callback,
) => {
const body = JSON.stringify({
const body = {
ViewInput: {
identifier: `udw-locations-by-search-query-${query.FullTextCriterion}`,
public: false,
Expand All @@ -212,7 +221,10 @@ export const findLocationsBySearchQuery = (
offset,
},
},
});
};

addLanguageCodeToCreateViewEndpoint(body);

const abortController = new AbortController();
const request = new Request(`${instanceUrl}${ENDPOINT_CREATE_VIEW}`, {
method: 'POST',
Expand All @@ -222,7 +234,7 @@ export const findLocationsBySearchQuery = (
accessToken,
extraHeaders: HEADERS_CREATE_VIEW,
}),
body,
body: JSON.stringify(body),
mode: getRequestMode({ instanceUrl }),
credentials: 'same-origin',
signal: abortController.signal,
Expand Down Expand Up @@ -251,7 +263,7 @@ export const findLocationsById = (
{ token, siteaccess, accessToken, id, limit = QUERY_LIMIT, offset = 0, instanceUrl = DEFAULT_INSTANCE_URL },
callback,
) => {
const body = JSON.stringify({
const body = {
ViewInput: {
identifier: `udw-locations-by-id-${id}`,
public: false,
Expand All @@ -263,7 +275,9 @@ export const findLocationsById = (
offset,
},
},
});
};

addLanguageCodeToCreateViewEndpoint(body);

const request = new Request(`${instanceUrl}${ENDPOINT_CREATE_VIEW}`, {
method: 'POST',
Expand All @@ -273,7 +287,7 @@ export const findLocationsById = (
accessToken,
extraHeaders: HEADERS_CREATE_VIEW,
}),
body,
body: JSON.stringify(body),
mode: getRequestMode({ instanceUrl }),
credentials: 'same-origin',
});
Expand All @@ -292,7 +306,7 @@ export const findContentInfo = (
{ token, siteaccess, accessToken, contentId, limit = QUERY_LIMIT, offset = 0, instanceUrl = DEFAULT_INSTANCE_URL },
callback,
) => {
const body = JSON.stringify({
const body = {
ViewInput: {
identifier: `udw-load-content-info-${contentId}`,
public: false,
Expand All @@ -304,7 +318,10 @@ export const findContentInfo = (
offset,
},
},
});
};

addLanguageCodeToCreateViewEndpoint(body);

const request = new Request(`${instanceUrl}${ENDPOINT_CREATE_VIEW}`, {
method: 'POST',
headers: getRequestHeaders({
Expand All @@ -313,7 +330,7 @@ export const findContentInfo = (
accessToken,
extraHeaders: HEADERS_CREATE_VIEW,
}),
body,
body: JSON.stringify(body),
mode: getRequestMode({ instanceUrl }),
credentials: 'same-origin',
});
Expand Down Expand Up @@ -413,7 +430,7 @@ export const loadContentInfo = (
{ token, siteaccess, accessToken, contentId, limit = QUERY_LIMIT, offset = 0, signal, instanceUrl = DEFAULT_INSTANCE_URL },
callback,
) => {
const body = JSON.stringify({
const body = {
ViewInput: {
identifier: `udw-load-content-info-${contentId}`,
public: false,
Expand All @@ -425,7 +442,10 @@ export const loadContentInfo = (
offset,
},
},
});
};

addLanguageCodeToCreateViewEndpoint(body);

const request = new Request(`${instanceUrl}${ENDPOINT_CREATE_VIEW}`, {
method: 'POST',
headers: getRequestHeaders({
Expand All @@ -434,7 +454,7 @@ export const loadContentInfo = (
accessToken,
extraHeaders: HEADERS_CREATE_VIEW,
}),
body,
body: JSON.stringify(body),
mode: getRequestMode({ instanceUrl }),
credentials: 'same-origin',
});
Expand Down Expand Up @@ -495,7 +515,7 @@ export const findSuggestions = (
{ siteaccess, token, parentLocationId, accessToken, instanceUrl = DEFAULT_INSTANCE_URL, limit = QUERY_LIMIT, offset = 0 },
callback,
) => {
const body = JSON.stringify({
const body = {
ViewInput: {
identifier: 'view_with_aggregation',
LocationQuery: {
Expand All @@ -514,7 +534,10 @@ export const findSuggestions = (
],
},
},
});
};

addLanguageCodeToCreateViewEndpoint(body);

const request = new Request(ENDPOINT_CREATE_VIEW, {
method: 'POST',
headers: getRequestHeaders({
Expand All @@ -525,7 +548,7 @@ export const findSuggestions = (
...HEADERS_CREATE_VIEW,
},
}),
body,
body: JSON.stringify(body),
mode: getRequestMode({ instanceUrl }),
credentials: 'same-origin',
});
Expand Down
Loading