From c40962c773024e707c31e1984bd1cd6759497c87 Mon Sep 17 00:00:00 2001 From: Wagner Trezub <60133113+Wagner3UB@users.noreply.github.com> Date: Tue, 30 Jan 2024 12:17:08 +0100 Subject: [PATCH] bugfix: wrong conditional proprieties on ObjectBrowser (#4190) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Piero Nicolli Co-authored-by: Víctor Fernández de Alba Co-authored-by: Martina Bustacchini Co-authored-by: Martina Bustacchini <41484878+deodorhunter@users.noreply.github.com> Co-authored-by: Steve Piercy Co-authored-by: Piero Nicolli --- packages/volto/news/4190.bugfix | 1 + .../manage/Sidebar/ObjectBrowserBody.jsx | 39 ++++++++++++++----- 2 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 packages/volto/news/4190.bugfix diff --git a/packages/volto/news/4190.bugfix b/packages/volto/news/4190.bugfix new file mode 100644 index 0000000000..102e518bc3 --- /dev/null +++ b/packages/volto/news/4190.bugfix @@ -0,0 +1 @@ +Fixed wrong conditional proprieties on `ObjectBrowser` for multiple selection. @deodorhunter @Wagner3UB diff --git a/packages/volto/src/components/manage/Sidebar/ObjectBrowserBody.jsx b/packages/volto/src/components/manage/Sidebar/ObjectBrowserBody.jsx index 2a88c9f981..c96b7f9d5b 100644 --- a/packages/volto/src/components/manage/Sidebar/ObjectBrowserBody.jsx +++ b/packages/volto/src/components/manage/Sidebar/ObjectBrowserBody.jsx @@ -296,8 +296,21 @@ class ObjectBrowserBody extends Component { }; isSelectable = (item) => { - return this.props.selectableTypes.length > 0 - ? this.props.selectableTypes.indexOf(item['@type']) >= 0 + const { maximumSelectionSize, data, mode, selectableTypes } = this.props; + if ( + maximumSelectionSize && + data && + mode === 'multiple' && + maximumSelectionSize <= data.length + ) + // The item should actually be selectable, but only for removing it from already selected items list. + // handleClickOnItem will handle the deselection logic. + // The item is not selectable if we reached/exceeded maximumSelectionSize and is not already selected. + return data.some( + (d) => flattenToAppURL(d['@id']) === flattenToAppURL(item['@id']), + ); + return selectableTypes.length > 0 + ? selectableTypes.indexOf(item['@type']) >= 0 : true; }; @@ -315,16 +328,24 @@ class ObjectBrowserBody extends Component { !this.props.maximumSelectionSize || this.props.mode === 'multiple' || !this.props.data || - this.props.data.length < this.props.maximumSelectionSize + this.props.data.length <= this.props.maximumSelectionSize ) { + let isDeselecting; + if (this.props.mode === 'multiple' && Array.isArray(this.props.data)) + isDeselecting = this.props.data.some( + (d) => flattenToAppURL(d['@id']) === flattenToAppURL(item['@id']), + ); this.onSelectItem(item); let length = this.props.data ? this.props.data.length : 0; - - let stopSelecting = - this.props.mode !== 'multiple' || - (this.props.maximumSelectionSize > 0 && - length + 1 >= this.props.maximumSelectionSize); - + let stopSelecting = this.props.mode !== 'multiple'; + if (isDeselecting && !stopSelecting) + stopSelecting = + this.props.maximumSelectionSize > 0 && + length - 1 >= this.props.maximumSelectionSize; + else + stopSelecting = + this.props.maximumSelectionSize > 0 && + length + 1 >= this.props.maximumSelectionSize; if (stopSelecting) { this.props.closeObjectBrowser(); }