Skip to content

Commit

Permalink
IBX-8424: Fixed criterions build for hook useSearchByQueryFetch (#1278)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasOsti authored Jun 27, 2024
1 parent 7bbe496 commit 88dfeae
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { useContext, useCallback, useReducer } from 'react';

import { getAdminUiConfig } from '@ibexa-admin-ui/src/bundle/Resources/public/js/scripts/helpers/context.helper';

import { findLocationsBySearchQuery } from '../services/universal.discovery.service';
import { RestInfoContext, LoadedLocationsMapContext } from '../universal.discovery.module';

Expand All @@ -21,6 +23,7 @@ const searchByQueryReducer = (state, action) => {
};

export const useSearchByQueryFetch = () => {
const { damWidget: damWidgetConfig } = getAdminUiConfig();
const restInfo = useContext(RestInfoContext);
const [, dispatchLoadedLocationsAction] = useContext(LoadedLocationsMapContext);
const [{ isLoading, data }, dispatch] = useReducer(searchByQueryReducer, { isLoading: false, data: {} });
Expand Down Expand Up @@ -75,12 +78,20 @@ export const useSearchByQueryFetch = () => {
const isImageCriterionDataEmpty = !imageCriterionData || Object.keys(imageCriterionData).length === 0;

if (!isImageCriterionDataEmpty) {
const imageCriterion = {
fieldDefIdentifier: 'image',
...imageCriterionData,
const imagesCriterion = damWidgetConfig.image.fieldDefinitionIdentifiers.reduce(
(criterions, fieldDefinitionIdentifier) => [
...criterions,
{
fieldDefIdentifier: fieldDefinitionIdentifier,
...imageCriterionData,
},
],
[],
);

query.OR = {
ImageCriterion: imagesCriterion,
};

query.ImageCriterion = imageCriterion;
}

dispatch({ type: SEARCH_START });
Expand Down

0 comments on commit 88dfeae

Please sign in to comment.