Skip to content

Commit

Permalink
fix: added customPath to SearchSectionForm doSearch function to set q…
Browse files Browse the repository at this point in the history
…uery.path
  • Loading branch information
sabrina-bongiovanni committed Nov 10, 2023
1 parent 570f842 commit 3fa9f55
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/components/ItaliaTheme/Search/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ const getSearchParamsURL = (
if (activeSections.length > 0) {
pathQuery = { 'path.query': activeSections };
} else if (customPath?.length > 0) {
console.log('la paath query è custompath :)');
pathQuery = { 'path.query': customPath };
} else if (baseUrl?.length > 0) {
pathQuery = {
Expand Down
38 changes: 31 additions & 7 deletions src/components/ItaliaTheme/View/Commons/SearchSectionForm.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { defineMessages, useIntl } from 'react-intl';
import { useSelector } from 'react-redux';
import React, { useState } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import React, { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import { Button } from 'design-react-kit';
import { flattenToAppURL } from '@plone/volto/helpers';
import { getSearchFilters } from 'design-comuni-plone-theme/actions';
import { SearchUtils } from 'design-comuni-plone-theme/components';
import { Icon } from 'design-comuni-plone-theme/components/ItaliaTheme';

Expand All @@ -27,6 +27,32 @@ const messages = defineMessages({
});

const SearchSectionForm = ({ content }) => {
const dispatch = useDispatch();
const path = content['@id'];
const searchFilters = useSelector(
(state) => state?.searchFilters?.result?.sections,
);

useEffect(() => {
if (!searchFilters || Object.keys(searchFilters).length === 0)
dispatch(getSearchFilters());
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const customPath = [];

const sections = searchFilters?.[0]?.items ?? [];

sections.forEach((section) => {
if (!section.items) {
return;
} else {
if (path === section['@id']) {
customPath.push(section.items.map((item) => item['@id']));
}
}
});

const intl = useIntl();

const subsite = useSelector((state) => state.subsite?.data);
Expand All @@ -44,13 +70,11 @@ const SearchSectionForm = ({ content }) => {
{},
null,
null,
null,
customPath.length > 0 ? customPath : null,
subsite,
intl.locale,
false,
) +
'&custom_path=' +
flattenToAppURL(content['@id']);
);
}
};
return (
Expand Down

0 comments on commit 3fa9f55

Please sign in to comment.