From afeaac9c33570b41a44d7db33a1d2aa778705ce2 Mon Sep 17 00:00:00 2001 From: Victor Fernandez de Alba Date: Fri, 23 Jun 2023 11:56:01 +0200 Subject: [PATCH] Backport changes in `withQuerystringResults.jsx` to maintain both in sync (change not backported initially because the PR containing it was "breaking" --- .../Blocks/Listing/withQuerystringResults.jsx | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/components/manage/Blocks/Listing/withQuerystringResults.jsx b/src/components/manage/Blocks/Listing/withQuerystringResults.jsx index c2e0e717ae..b61736c3c9 100644 --- a/src/components/manage/Blocks/Listing/withQuerystringResults.jsx +++ b/src/components/manage/Blocks/Listing/withQuerystringResults.jsx @@ -14,18 +14,23 @@ function getDisplayName(WrappedComponent) { export default function withQuerystringResults(WrappedComponent) { function WithQuerystringResults(props) { - const { data = {}, properties: content, path, variation } = props; + const { + data = {}, + id = data.block, + properties: content, + 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 - const { block } = data; const { b_size = settings.defaultPageSize } = querystring; // batchsize // save the path so it won't trigger dispatch on eager router location change const [initialPath] = React.useState(getBaseUrl(path)); const copyFields = ['limit', 'query', 'sort_on', 'sort_order', 'depth']; - const { currentPage, setCurrentPage } = usePagination(block, 1); + const { currentPage, setCurrentPage } = usePagination(id, 1); const adaptedQuery = Object.assign( variation?.fullobjects ? { fullobjects: 1 } : { metadata_fields: '_all' }, { @@ -47,32 +52,32 @@ export default function withQuerystringResults(WrappedComponent) { const folderItems = content?.is_folderish ? content.items : []; const hasQuery = querystring?.query?.length > 0; - const hasLoaded = hasQuery ? querystringResults?.[block]?.loaded : true; + const hasLoaded = hasQuery ? querystringResults?.[id]?.loaded : true; const listingItems = - querystring?.query?.length > 0 && querystringResults?.[block] - ? querystringResults?.[block]?.items || [] + querystring?.query?.length > 0 && querystringResults?.[id] + ? querystringResults?.[id]?.items || [] : folderItems; const showAsFolderListing = !hasQuery && content?.items_total > b_size; const showAsQueryListing = - hasQuery && querystringResults?.[block]?.total > b_size; + hasQuery && querystringResults?.[id]?.total > b_size; const totalPages = showAsFolderListing ? Math.ceil(content.items_total / b_size) : showAsQueryListing - ? Math.ceil(querystringResults[block].total / b_size) + ? Math.ceil(querystringResults[id].total / b_size) : 0; const prevBatch = showAsFolderListing ? content.batching?.prev : showAsQueryListing - ? querystringResults[block].batching?.prev + ? querystringResults[id].batching?.prev : null; const nextBatch = showAsFolderListing ? content.batching?.next : showAsQueryListing - ? querystringResults[block].batching?.next + ? querystringResults[id].batching?.next : null; const isImageGallery = @@ -82,7 +87,7 @@ export default function withQuerystringResults(WrappedComponent) { useDeepCompareEffect(() => { if (hasQuery) { dispatch( - getQueryStringResults(initialPath, adaptedQuery, block, currentPage), + getQueryStringResults(initialPath, adaptedQuery, id, currentPage), ); } else if (isImageGallery && !hasQuery) { // when used as image gallery, it doesn't need a query to list children @@ -100,7 +105,7 @@ export default function withQuerystringResults(WrappedComponent) { }, ], }, - block, + id, ), ); } else { @@ -109,7 +114,7 @@ export default function withQuerystringResults(WrappedComponent) { adaptedQueryRef.current = adaptedQuery; currentPageRef.current = currentPage; }, [ - block, + id, isImageGallery, adaptedQuery, hasQuery, @@ -122,7 +127,7 @@ export default function withQuerystringResults(WrappedComponent) { setCurrentPage(activePage)} - total={querystringResults?.[block]?.total} + total={querystringResults?.[id]?.total} batch_size={b_size} currentPage={currentPage} totalPages={totalPages}