Skip to content

Commit

Permalink
fix problem with sort_on default; fix bug with total results
Browse files Browse the repository at this point in the history
  • Loading branch information
luca-bellenghi committed Sep 4, 2024
1 parent 0808929 commit af375cd
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@
- Agid styling
- Add class .block.listing in listing body container div to use
existing listing template styles
- Inspired from
https://github.com/plone/volto/commit/211d9bea13119cc430db9d53a4740a860781ca2e
the way to handle search sort
*/

import React from 'react';

import ListingBody from '@plone/volto/components/manage/Blocks/Listing/ListingBody';
import { withBlockExtensions } from '@plone/volto/helpers';

import config from '@plone/volto/registry';
import cx from 'classnames';
import {
withSearch,
withQueryString,
withSearch,
} from '@plone/volto/components/manage/Blocks/Search/hocs';
import { compose } from 'redux';
import { useSelector } from 'react-redux';
import config from '@plone/volto/registry';
import cx from 'classnames';
import { isEqual, isFunction } from 'lodash';
import { useSelector } from 'react-redux';
import { compose } from 'redux';

const getListingBodyVariation = (data) => {
const { variations } = config.blocks.blocksConfig.listing;
Expand Down Expand Up @@ -57,12 +60,36 @@ const applyDefaults = (data, root) => {
v: root || '/',
},
];
return {

const searchBySearchableText = data.query.filter(
(item) => item['i'] === 'SearchableText',
).length;

const sort_on =
searchBySearchableText === 0
? data?.sort_on
? { sort_on: data.sort_on }
: { sort_on: 'effective' }
: undefined;

const sort_order =
searchBySearchableText === 0
? data?.sort_order
? { sort_order: data.sort_order }
: { sort_order: 'descending' }
: undefined;

const result = {
...data,
sort_on: data?.sort_on || 'effective',
sort_order: data?.sort_order || 'descending',
query: data?.query?.length ? data.query : defaultQuery,
};
if (!sort_on) {
delete result.sort_on;
}
if (!sort_order) {
delete result.sort_order;
}
return result;
};

const SearchBlockView = (props) => {
Expand All @@ -89,7 +116,6 @@ const SearchBlockView = (props) => {

const root = useSelector((state) => state.breadcrumbs.root);
const listingBodyData = applyDefaults(searchData, root);

const { variations } = config.blocks.blocksConfig.listing;
const listingBodyVariation = variations.find(({ id }) => id === selectedView);
if (!Layout) return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
- Agid styling
*/
import React from 'react';
import { defineMessages, useIntl } from 'react-intl';
import { commonSearchBlockMessages } from 'design-comuni-plone-theme/helpers';
import { defineMessages, useIntl } from 'react-intl';

const messages = defineMessages({
searchResults: {
Expand All @@ -26,7 +25,7 @@ const SearchDetails = ({ total, text, as = 'p', data }) => {
searchedtext: text,
})}
</>
)}
)}{' '}
{data.showTotalResults && (
<>
{intl.formatMessage(messages.searchResults)}: <b>{total}</b>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* CUSTOMIZATIONS:
- Read puntual comments in code
*/
import qs from 'query-string';
import React from 'react';
import { useSelector } from 'react-redux';
import qs from 'query-string';
import { useLocation, useHistory } from 'react-router-dom';
import { useHistory, useLocation } from 'react-router-dom';

import { resolveExtension } from '@plone/volto/helpers/Extensions/withBlockExtensions';
import config from '@plone/volto/registry';
Expand Down Expand Up @@ -236,7 +236,7 @@ const withSearch = (options) => (WrappedComponent) => {
const { inputDelay = 1000 } = options || {};

function WithSearch(props) {
const { data, id, editable = false } = props;
const { data, id, editable = false, properties } = props;

const [locationSearchData, setLocationSearchData] = useSearchBlockState(
id,
Expand Down Expand Up @@ -325,8 +325,10 @@ const withSearch = (options) => (WrappedComponent) => {
const querystringResults = useSelector(
(state) => state.querystringsearch.subrequests,
);
const subrequestID = properties?.UID + '-' + id;
const totalItems =
querystringResults[id]?.total || querystringResults[id]?.items?.length;
querystringResults[subrequestID]?.total ||
querystringResults[subrequestID]?.items?.length;

return (
<WrappedComponent
Expand Down

0 comments on commit af375cd

Please sign in to comment.