Skip to content

Commit

Permalink
Merge branch '4.6' into ibx-9169-search-content-by-name-trash
Browse files Browse the repository at this point in the history
  • Loading branch information
barw4 authored Nov 6, 2024
2 parents 103d8a4 + 1a90d69 commit b42563c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const useSearchByQueryFetch = () => {
dateCriterion = null,
useAlwaysAvailable = true,
isBookmarked = null,
fieldCriterionData = null,
) => {
const handleFetch = (response) => {
dispatchLoadedLocationsAction({ type: 'CLEAR_LOCATIONS' });
Expand Down Expand Up @@ -86,6 +87,12 @@ export const useSearchByQueryFetch = () => {
query.IsBookmarkedCriterion = true;
}

if (fieldCriterionData) {
query.AND = {
Field: fieldCriterionData,
};
}

const isImageCriterionDataEmpty = !imageCriterionData || Object.keys(imageCriterionData).length === 0;

if (!isImageCriterionDataEmpty) {
Expand Down
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

0 comments on commit b42563c

Please sign in to comment.