Skip to content

Commit

Permalink
Merge branch 'main' into padding-select-facet
Browse files Browse the repository at this point in the history
  • Loading branch information
ichim-david authored Oct 16, 2023
2 parents 4f97d1e + 753e79e commit 6f9ec22
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 22 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@

<!-- towncrier release notes start -->

## 17.2.0 (2023-10-16)

### Feature

- add cypress test for search block via url - @ionlizarazu [#5298](https://github.com/plone/volto/issues/5298)

### Bugfix

- Fix adding multiple path criteria in search and listing blocks. @davisagli [#5317](https://github.com/plone/volto/issues/5317)


## 17.1.1 (2023-10-13)

### Bugfix
Expand Down
32 changes: 27 additions & 5 deletions cypress/tests/core/blocks/blocks-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,32 @@ describe('Search Block Tests', () => {
);
// clear facets
cy.get('.block.search .filter-list-header .ui.button').click();
cy.url().should(
'not.contain',
'%7B%22i%22%3A%22portal_type%22%2C%22o%22%3A%22paqo.list.contains%22%2C%22v%22%3A%5B%22Event%22%5D%7D',
);

// navigate to the searched url
cy.navigate(
'/my-search-page?query=%5B%7B%22i%22%3A%22portal_type%22%2C%22o%22%3A%22paqo.list.contains%22%2C%22v%22%3A%5B%22Event%22%5D%7D%5D',
);
cy.reload();
cy.wait(500);
cy.get('.search-details').should('contain', 'Search results: 1');

//navigate to home
cy.navigate('/');
cy.wait(500);

// navigate to the searched url
cy.navigate(
// '/my-search-page?query=%5B%7B%22i%22%3A%22portal_type%22%2C%22o%22%3A%22paqo.list.contains%22%2C%22v%22%3A%5B%22Event%22%5D%7D%5D',
'/my-search-page?query=%5B%7B%22i%22%3A%22portal_type%22%2C%22o%22%3A%22paqo.list.contains%22%2C%22v%22%3A%5B%22Event%22%5D%7D%5D',
);
cy.get('.search-details').should('contain', 'Search results: 1');

cy.reload();
cy.get('.search-details').should('contain', 'Search results: 1');
});

it('Search block - test date range facet', () => {
Expand Down Expand Up @@ -173,11 +199,7 @@ describe('Search Block Tests', () => {
);
});

// Sept-2023 - @sneridagh:
// Skipped for now, it behaves quite weird and different than the "live" one
// Still due to be investigated, I could not pinpoint why
// See: https://github.com/plone/volto/issues/5219
it.skip('Search block - test live searchbox', () => {
it('Search block - test live searchbox', () => {
cy.visit('/');
cy.get('#toolbar-add > .icon').click();
cy.get('#toolbar-add-document').click();
Expand Down
1 change: 1 addition & 0 deletions news/5298 bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix the search block for search via url - @ionlizarazu
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
}
],
"license": "MIT",
"version": "17.1.1",
"version": "17.2.0",
"repository": {
"type": "git",
"url": "git@github.com:plone/volto.git"
Expand Down
2 changes: 1 addition & 1 deletion packages/volto-slate/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@plone/volto-slate",
"version": "17.1.1",
"version": "17.2.0",
"description": "Slate.js integration with Volto",
"main": "src/index.js",
"author": "European Environment Agency: IDM2 A-Team",
Expand Down
60 changes: 47 additions & 13 deletions src/components/manage/Blocks/Search/hocs/withSearch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ const PAQO = 'plone.app.querystring.operation';
* @function getInitialState
*
*/
function getInitialState(data, facets, urlSearchText, id) {
function getInitialState(
data,
facets,
urlSearchText,
id,
sortOnParam,
sortOrderParam,
) {
const { types: facetWidgetTypes } =
config.blocks.blocksConfig.search.extensions.facetWidgets;
const facetSettings = data?.facets || [];
Expand Down Expand Up @@ -62,8 +69,8 @@ function getInitialState(data, facets, urlSearchText, id) {
]
: []),
],
sort_on: data.query?.sort_on,
sort_order: data.query?.sort_order,
sort_on: sortOnParam || data.query?.sort_on,
sort_order: sortOrderParam || data.query?.sort_order,
b_size: data.query?.b_size,
limit: data.query?.limit,
block: id,
Expand Down Expand Up @@ -257,7 +264,28 @@ const withSearch = (options) => (WrappedComponent) => {
const multiFacets = data.facets
?.filter((facet) => facet?.multiple)
.map((facet) => facet?.field?.value);
const [facets, setFacets] = React.useState({});
const [facets, setFacets] = React.useState(
Object.assign(
{},
...urlQuery.map(({ i, v }) => ({ [i]: v })), // TODO: the 'o' should be kept. This would be a major refactoring of the facets

// support for simple filters like ?Subject=something
// TODO: since the move to hash params this is no longer working.
// We'd have to treat the location.search and manage it just like the
// hash, to support it. We can read it, but we'd have to reset it as
// well, so at that point what's the difference to the hash?
...configuredFacets.map((f) =>
locationSearchData[f]
? {
[f]:
multiFacets.indexOf(f) > -1
? [locationSearchData[f]]
: locationSearchData[f],
}
: {},
),
),
);
const previousUrlQuery = usePrevious(urlQuery);

React.useEffect(() => {
Expand Down Expand Up @@ -296,11 +324,16 @@ const withSearch = (options) => (WrappedComponent) => {
const [sortOn, setSortOn] = React.useState(data?.query?.sort_on);
const [sortOrder, setSortOrder] = React.useState(data?.query?.sort_order);

const [searchData, setSearchData] = React.useState({});
const [searchData, setSearchData] = React.useState(
getInitialState(data, facets, urlSearchText, id),
);

const deepFacets = JSON.stringify(facets);
React.useEffect(() => {
setSearchData(getInitialState(data, facets, urlSearchText, id));
}, [facets, data, urlSearchText, id]);
setSearchData(
getInitialState(data, facets, urlSearchText, id, sortOn, sortOrder),
);
}, [deepFacets, facets, data, urlSearchText, id, sortOn, sortOrder]);

const timeoutRef = React.useRef();
const facetSettings = data?.facets;
Expand All @@ -316,7 +349,7 @@ const withSearch = (options) => (WrappedComponent) => {
if (timeoutRef.current) clearTimeout(timeoutRef.current);
timeoutRef.current = setTimeout(
() => {
const searchData = normalizeState({
const newSearchData = normalizeState({
id,
query: data.query || {},
facets: toSearchFacets || facets,
Expand All @@ -328,8 +361,8 @@ const withSearch = (options) => (WrappedComponent) => {
if (toSearchFacets) setFacets(toSearchFacets);
if (toSortOn) setSortOn(toSortOn);
if (toSortOrder) setSortOrder(toSortOrder);
setSearchData(searchData);
setLocationSearchData(getSearchFields(searchData));
setSearchData(newSearchData);
setLocationSearchData(getSearchFields(newSearchData));
},
toSearchFacets ? inputDelay / 3 : inputDelay,
);
Expand All @@ -349,13 +382,14 @@ const withSearch = (options) => (WrappedComponent) => {
);

const removeSearchQuery = () => {
searchData.query = searchData.query.reduce(
let newSearchData = { ...searchData };
newSearchData.query = searchData.query.reduce(
// Remove SearchableText from query
(acc, kvp) => (kvp.i === 'SearchableText' ? acc : [...acc, kvp]),
[],
);
setSearchData(searchData);
setLocationSearchData(getSearchFields(searchData));
setSearchData(newSearchData);
setLocationSearchData(getSearchFields(newSearchData));
};

const querystringResults = useSelector(
Expand Down
8 changes: 6 additions & 2 deletions src/components/manage/Widgets/QueryWidget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ export class QuerystringWidgetComponent extends Component {
label: field[1].title,
value: field[0],
isDisabled: (value || []).some(
(v) => v['i'] === field[0],
(v) =>
v['i'] !== 'path' && v['i'] === field[0],
),
}),
),
Expand Down Expand Up @@ -444,8 +445,11 @@ export class QuerystringWidgetComponent extends Component {
(field) => ({
label: field[1].title,
value: field[0],
// disable selecting indexes that are already used,
// except for path, which has explicit support
// in the backend for multipath queries
isDisabled: (value || []).some(
(v) => v['i'] === field[0],
(v) => v['i'] !== 'path' && v['i'] === field[0],
),
}),
),
Expand Down

0 comments on commit 6f9ec22

Please sign in to comment.