From b798f0dce2877c45606ef43721e22dfb577492e1 Mon Sep 17 00:00:00 2001 From: Giulia Ghisini <51911425+giuliaghisini@users.noreply.github.com> Date: Fri, 20 Dec 2024 11:45:28 +0100 Subject: [PATCH] feat: added usePloneRanking option in Search Block (#820) * feat: added usePloneRanking option in Search Block * Update RELEASE.md --------- Co-authored-by: Martina Bustacchini <41484878+deodorhunter@users.noreply.github.com> --- RELEASE.md | 2 +- .../manage/Blocks/Search/SearchBlockView.jsx | 24 +++++++------------ .../components/manage/Blocks/Search/schema.js | 16 +++++++++++++ 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/RELEASE.md b/RELEASE.md index 2ad16f311..f1c36bc22 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -50,7 +50,7 @@ ### Novità -- ... +- Nel blocco 'Cerca' è stata aggiunta l'opzione "Usa l'ordinamento dei risultati di Plone" nella sezione 'Controlli'. ### Fix diff --git a/src/customizations/volto/components/manage/Blocks/Search/SearchBlockView.jsx b/src/customizations/volto/components/manage/Blocks/Search/SearchBlockView.jsx index 3720d2832..7be815006 100644 --- a/src/customizations/volto/components/manage/Blocks/Search/SearchBlockView.jsx +++ b/src/customizations/volto/components/manage/Blocks/Search/SearchBlockView.jsx @@ -4,7 +4,7 @@ existing listing template styles - Inspired from https://github.com/plone/volto/commit/211d9bea13119cc430db9d53a4740a860781ca2e - the way to handle search sort + the way to handle search sort. If searchableText is setted, discard default sorting and uses plone's ranking only if is configured from sidebar. (Changed applyDefaults fn passing usePloneRanking) */ import React from 'react'; @@ -52,7 +52,7 @@ const blockPropsAreChanged = (prevProps, nextProps) => { return isEqual(prev, next); }; -const applyDefaults = (data, root) => { +const applyDefaults = (data, root, usePloneRanking) => { const defaultQuery = [ { i: 'path', @@ -65,19 +65,13 @@ const applyDefaults = (data, root) => { (item) => item['i'] === 'SearchableText', ).length; - const sort_on = - searchBySearchableText === 0 - ? data?.sort_on - ? { sort_on: data.sort_on } - : { sort_on: 'effective' } - : undefined; + let sort_on = { sort_on: data?.sort_on ?? 'effective' }; + let sort_order = { sort_order: data?.sort_order ?? 'descending' }; - const sort_order = - searchBySearchableText === 0 - ? data?.sort_order - ? { sort_order: data.sort_order } - : { sort_order: 'descending' } - : undefined; + if (usePloneRanking && searchBySearchableText > 0) { + sort_on = undefined; + sort_order = undefined; + } const result = { ...data, @@ -115,7 +109,7 @@ const SearchBlockView = (props) => { }, [dataListingBodyVariation, mode]); const root = useSelector((state) => state.breadcrumbs.root); - const listingBodyData = applyDefaults(searchData, root); + const listingBodyData = applyDefaults(searchData, root, data.usePloneRanking); const { variations } = config.blocks.blocksConfig.listing; const listingBodyVariation = variations.find(({ id }) => id === selectedView); if (!Layout) return null; diff --git a/src/customizations/volto/components/manage/Blocks/Search/schema.js b/src/customizations/volto/components/manage/Blocks/Search/schema.js index 7f0d4c2cc..3f076921b 100644 --- a/src/customizations/volto/components/manage/Blocks/Search/schema.js +++ b/src/customizations/volto/components/manage/Blocks/Search/schema.js @@ -153,6 +153,15 @@ const messages = defineMessages({ id: 'Link to', defaultMessage: 'Link to', }, + usePloneRanking: { + id: "Usa l'ordinamento dei risultati di Plone", + defaultMessage: "Usa l'ordinamento dei risultati di Plone", + }, + usePloneRankingDescription: { + id: "Usa l'ordinamento dei risultati di Plone - descrizione", + defaultMessage: + "Se impostato, nel momento in cui un utente effettua una ricerca testuale per parola chiave, non viene usato l'ordinamento di default impostato nella sezione 'Ricerca iniziale', ma l'ordinamento di Plone in base all'ordine di importanza dei risultati da esso stabilito.", + }, }); const enhanceSchema = (originalSchema, formData) => { @@ -285,6 +294,7 @@ const SearchSchema = ({ data = {}, intl }) => { ...(data.showSearchInput ?? true ? ['showSearchButton'] : []), // ...(data.showSearchInput ? ['searchInputPrompt'] : []), // ...(data.showSearchButton ? ['searchButtonLabel'] : []), + 'usePloneRanking', 'showTotalResults', ], }, @@ -316,6 +326,12 @@ const SearchSchema = ({ data = {}, intl }) => { title: intl.formatMessage(messages.showTotalResults), default: true, }, + usePloneRanking: { + type: 'boolean', + title: intl.formatMessage(messages.usePloneRanking), + description: intl.formatMessage(messages.usePloneRankingDescription), + default: false, + }, searchButtonLabel: { title: intl.formatMessage(messages.searchButtonLabel), placeholder: intl.formatMessage(messages.searchButtonPlaceholder),