diff --git a/news/3839.breaking b/news/3839.breaking new file mode 100644 index 0000000000..6c960e21f1 --- /dev/null +++ b/news/3839.breaking @@ -0,0 +1 @@ +Use default query in SSR rendering and client fetch of the listing block when we don't have a search criteria. Fix https://github.com/plone/volto/issues/3839 @wesleybl diff --git a/src/components/manage/Blocks/Listing/getAsyncData.js b/src/components/manage/Blocks/Listing/getAsyncData.js index 7d4ffe3662..1f1d67e276 100644 --- a/src/components/manage/Blocks/Listing/getAsyncData.js +++ b/src/components/manage/Blocks/Listing/getAsyncData.js @@ -1,5 +1,6 @@ import { getQueryStringResults } from '@plone/volto/actions'; import { resolveBlockExtensions } from '@plone/volto/helpers'; +import { defaultQuery } from './withQuerystringResults'; export default ({ dispatch, data, path, blocksConfig }) => { const { resolvedExtensions } = resolveBlockExtensions(data, blocksConfig); @@ -9,7 +10,9 @@ export default ({ dispatch, data, path, blocksConfig }) => { getQueryStringResults( path, { - ...data.querystring, + ...(data.querystring + ? data.querystring + : { query: defaultQuery, sort_on: 'getObjPositionInParent' }), ...(resolvedExtensions?.variation?.fullobjects ? { fullobjects: 1 } : { metadata_fields: '_all' }), diff --git a/src/components/manage/Blocks/Listing/withQuerystringResults.jsx b/src/components/manage/Blocks/Listing/withQuerystringResults.jsx index d675fc050a..22bf8be59c 100644 --- a/src/components/manage/Blocks/Listing/withQuerystringResults.jsx +++ b/src/components/manage/Blocks/Listing/withQuerystringResults.jsx @@ -3,18 +3,26 @@ import { useDispatch, useSelector } from 'react-redux'; import hoistNonReactStatics from 'hoist-non-react-statics'; import useDeepCompareEffect from 'use-deep-compare-effect'; -import { getContent, getQueryStringResults } from '@plone/volto/actions'; +import { getQueryStringResults } from '@plone/volto/actions'; import { usePagination, getBaseUrl } from '@plone/volto/helpers'; import config from '@plone/volto/registry'; +export const defaultQuery = [ + { + i: 'path', + o: 'plone.app.querystring.operation.string.relativePath', + v: '::1', + }, +]; + function getDisplayName(WrappedComponent) { return WrappedComponent.displayName || WrappedComponent.name || 'Component'; } export default function withQuerystringResults(WrappedComponent) { function WithQuerystringResults(props) { - const { data = {}, properties: content, path, variation } = props; + const { data = {}, path, variation } = props; const { settings } = config; const querystring = data.querystring || data; // For backwards compat with data saved before Blocks schema. Note, this is also how the Search block passes data to ListingBody @@ -43,33 +51,22 @@ export default function withQuerystringResults(WrappedComponent) { ); const dispatch = useDispatch(); - const folderItems = content?.is_folderish ? content.items : []; const hasQuery = querystring?.query?.length > 0; - const hasLoaded = hasQuery ? !querystringResults?.[block]?.loading : true; + const hasLoaded = !querystringResults?.[block]?.loading; - const listingItems = - querystring?.query?.length > 0 && querystringResults?.[block] - ? querystringResults?.[block]?.items || [] - : folderItems; + const listingItems = querystringResults?.[block]?.items || []; - const showAsFolderListing = !hasQuery && content?.items_total > b_size; - const showAsQueryListing = - hasQuery && querystringResults?.[block]?.total > b_size; + const showAsQueryListing = querystringResults?.[block]?.total > b_size; + const showAsFolderListing = !hasQuery && showAsQueryListing; - const totalPages = showAsFolderListing - ? Math.ceil(content.items_total / b_size) - : showAsQueryListing + const totalPages = showAsQueryListing ? Math.ceil(querystringResults[block].total / b_size) : 0; - const prevBatch = showAsFolderListing - ? content.batching?.prev - : showAsQueryListing + const prevBatch = showAsQueryListing ? querystringResults[block].batching?.prev : null; - const nextBatch = showAsFolderListing - ? content.batching?.next - : showAsQueryListing + const nextBatch = showAsQueryListing ? querystringResults[block].batching?.next : null; @@ -102,7 +99,18 @@ export default function withQuerystringResults(WrappedComponent) { ), ); } else { - dispatch(getContent(initialPath, null, null, currentPage)); + dispatch( + getQueryStringResults( + initialPath, + { + ...adaptedQuery, + sort_on: 'getObjPositionInParent', + query: defaultQuery, + }, + block, + currentPage, + ), + ); } }, [ block,