From 7b193edb98006917214819787cf355cbcdeda2fe Mon Sep 17 00:00:00 2001 From: Lukasz Ostafin Date: Thu, 5 Sep 2024 11:17:52 +0200 Subject: [PATCH] IBX-8132: [UDW] For object relation field user can remove selected item from bookmarks --- .../ibexa_universal_discovery_widget.en.xliff | 14 +++++++-- .../selected-locations/selected.locations.js | 31 ++++++++++++------- .../universal-discovery/components/tab/tab.js | 5 ++- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/bundle/Resources/translations/ibexa_universal_discovery_widget.en.xliff b/src/bundle/Resources/translations/ibexa_universal_discovery_widget.en.xliff index 163fc82bed..4d8fc5641f 100644 --- a/src/bundle/Resources/translations/ibexa_universal_discovery_widget.en.xliff +++ b/src/bundle/Resources/translations/ibexa_universal_discovery_widget.en.xliff @@ -306,6 +306,11 @@ Collapse sidebar key: selected_locations.collapse.sidebar + + Deselect + Deselect + key: selected_locations.deselect + Deselect all Deselect all @@ -316,9 +321,14 @@ Expand sidebar key: selected_locations.expand.sidebar + + %count% selected item + %count% selected item + key: selected_locations.selected_item + - %count% selected item(s) - %count% selected item(s) + %count% selected items + %count% selected items key: selected_locations.selected_items diff --git a/src/bundle/ui-dev/src/modules/universal-discovery/components/selected-locations/selected.locations.js b/src/bundle/ui-dev/src/modules/universal-discovery/components/selected-locations/selected.locations.js index 87fe7a38ca..a25422cff1 100644 --- a/src/bundle/ui-dev/src/modules/universal-discovery/components/selected-locations/selected.locations.js +++ b/src/bundle/ui-dev/src/modules/universal-discovery/components/selected-locations/selected.locations.js @@ -19,6 +19,7 @@ const SelectedLocations = () => { const [selectedLocations, dispatchSelectedLocationsAction] = useContext(SelectedLocationsContext); const allowConfirmation = useContext(AllowConfirmationContext); const [isExpanded, setIsExpanded] = useState(false); + const areMultilocationsSelected = selectedLocations.length > 1; const className = createCssClassNames({ 'c-selected-locations': true, 'c-selected-locations--expanded': isExpanded, @@ -42,11 +43,17 @@ const SelectedLocations = () => { setIsExpanded(!isExpanded); }; const renderSelectionCounter = () => { - const selectedLabel = Translator.trans( - /*@Desc("%count% selected item(s)")*/ 'selected_locations.selected_items', - { count: selectedLocations.length }, - 'ibexa_universal_discovery_widget', - ); + const selectedLabel = areMultilocationsSelected + ? Translator.trans( + /*@Desc("%count% selected items")*/ 'selected_locations.selected_items', + { count: selectedLocations.length }, + 'ibexa_universal_discovery_widget', + ) + : Translator.trans( + /*@Desc("%count% selected item")*/ 'selected_locations.selected_item', + { count: selectedLocations.length }, + 'ibexa_universal_discovery_widget', + ); return
{selectedLabel}
; }; @@ -67,11 +74,9 @@ const SelectedLocations = () => { ); }; const renderActionButtons = () => { - const removeAllLabel = Translator.trans( - /*@Desc("Deselect all")*/ 'selected_locations.deselect_all', - {}, - 'ibexa_universal_discovery_widget', - ); + const removeLabel = areMultilocationsSelected + ? Translator.trans(/*@Desc("Deselect all")*/ 'selected_locations.deselect_all', {}, 'ibexa_universal_discovery_widget') + : Translator.trans(/*@Desc("Deselect")*/ 'selected_locations.deselect', {}, 'ibexa_universal_discovery_widget'); return (
@@ -80,7 +85,7 @@ const SelectedLocations = () => { className="c-selected-locations__clear-selection-button btn ibexa-btn ibexa-btn--small ibexa-btn--secondary" onClick={clearSelection} > - {removeAllLabel} + {removeLabel}
); @@ -107,6 +112,10 @@ const SelectedLocations = () => { }; useEffect(() => { + if (!allowConfirmation) { + return; + } + parseTooltip(refSelectedLocations.current); hideAllTooltips(); diff --git a/src/bundle/ui-dev/src/modules/universal-discovery/components/tab/tab.js b/src/bundle/ui-dev/src/modules/universal-discovery/components/tab/tab.js index 82964f0856..2ac0160ae2 100644 --- a/src/bundle/ui-dev/src/modules/universal-discovery/components/tab/tab.js +++ b/src/bundle/ui-dev/src/modules/universal-discovery/components/tab/tab.js @@ -8,7 +8,7 @@ import SelectedLocations from '../selected-locations/selected.locations'; import ContentCreateWidget from '../content-create-widget/content.create.widget'; import ContentMetaPreview from '../../content.meta.preview.module'; -import { SelectedLocationsContext, DropdownPortalRefContext, MultipleConfigContext } from '../../universal.discovery.module'; +import { SelectedLocationsContext, DropdownPortalRefContext } from '../../universal.discovery.module'; const Tab = ({ children, actionsDisabledMap }) => { const topBarRef = useRef(); @@ -16,8 +16,7 @@ const Tab = ({ children, actionsDisabledMap }) => { const [contentHeight, setContentHeight] = useState('100%'); const [selectedLocations] = useContext(SelectedLocationsContext); const dropdownPortalRef = useContext(DropdownPortalRefContext); - const [multiple] = useContext(MultipleConfigContext); - const selectedLocationsComponent = !!selectedLocations.length && multiple ? : null; + const selectedLocationsComponent = !!selectedLocations.length ? : null; const contentStyles = { height: contentHeight, };