From ba1f43abfa76fb202e2ff7531a04f32dbc9dd032 Mon Sep 17 00:00:00 2001 From: Martina Bustacchini Date: Thu, 12 Oct 2023 15:02:04 +0200 Subject: [PATCH 1/3] fix: object browser limit is now respected, add logic for deselection and conditional closing of ob in some cases --- .../manage/Sidebar/ObjectBrowserBody.jsx | 37 ++++++++++++++----- .../manage/Widgets/ObjectBrowserWidget.jsx | 12 +++++- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/customizations/volto/components/manage/Sidebar/ObjectBrowserBody.jsx b/src/customizations/volto/components/manage/Sidebar/ObjectBrowserBody.jsx index 0efa97811..2730b2cd7 100644 --- a/src/customizations/volto/components/manage/Sidebar/ObjectBrowserBody.jsx +++ b/src/customizations/volto/components/manage/Sidebar/ObjectBrowserBody.jsx @@ -247,7 +247,6 @@ class ObjectBrowserBody extends Component { onSelectItem = (item) => { const url = item['@id']; const { block, data, mode, dataName, onChangeBlock } = this.props; - const updateState = (mode) => { switch (mode) { case 'image': @@ -312,8 +311,18 @@ 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 + ) + return data.some( + (d) => flattenToAppURL(d['@id']) === flattenToAppURL(item['@id']), + ); + return selectableTypes.length > 0 + ? selectableTypes.indexOf(item['@type']) >= 0 : true; }; @@ -331,16 +340,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(); } diff --git a/src/customizations/volto/components/manage/Widgets/ObjectBrowserWidget.jsx b/src/customizations/volto/components/manage/Widgets/ObjectBrowserWidget.jsx index f66382de7..1fb82c2d8 100644 --- a/src/customizations/volto/components/manage/Widgets/ObjectBrowserWidget.jsx +++ b/src/customizations/volto/components/manage/Widgets/ObjectBrowserWidget.jsx @@ -159,6 +159,7 @@ export class ObjectBrowserWidgetComponent extends Component { }; onChange = (item) => { + console.log(this.props.onChange); let value = this.props.mode === 'multiple' && this.props.value ? [...this.props.value] @@ -321,8 +322,15 @@ export class ObjectBrowserWidgetComponent extends Component { * @returns {string} Markup for the component. */ render() { - const { id, description, fieldSet, value, mode, onChange, isDisabled } = - this.props; + const { + id, + description, + fieldSet, + value, + mode, + onChange, + isDisabled, + } = this.props; let items = compact(!isArray(value) && value ? [value] : value || []); From 60fa06da0f0ba3667b2c70c6287beec059f544c4 Mon Sep 17 00:00:00 2001 From: Martina Bustacchini Date: Thu, 12 Oct 2023 15:05:18 +0200 Subject: [PATCH 2/3] docs: added Release docs and infos --- RELEASE.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/RELEASE.md b/RELEASE.md index ef13fffbd..7e10a2e84 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -30,6 +30,16 @@ - ... --> +## Versione 8.7.8 (xx/xx/2023) + +### Migliorie + +- Migliorato il comportamento alla selezione/deselezione degli elementi multipli nel componente Object Browser + +### Fix + +- Risolto un bug nel componente Object Browser che permetteva di selezionare piú elementi di quelli consentiti + ## Versione 8.7.7 (12/10/2023) ### Migliorie From e25653ea2e5d18e529a721313d51d871f94c9827 Mon Sep 17 00:00:00 2001 From: Martina Bustacchini Date: Thu, 12 Oct 2023 15:08:07 +0200 Subject: [PATCH 3/3] fix: remove stray console.log --- .../volto/components/manage/Widgets/ObjectBrowserWidget.jsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/customizations/volto/components/manage/Widgets/ObjectBrowserWidget.jsx b/src/customizations/volto/components/manage/Widgets/ObjectBrowserWidget.jsx index 1fb82c2d8..65dfc725f 100644 --- a/src/customizations/volto/components/manage/Widgets/ObjectBrowserWidget.jsx +++ b/src/customizations/volto/components/manage/Widgets/ObjectBrowserWidget.jsx @@ -159,7 +159,6 @@ export class ObjectBrowserWidgetComponent extends Component { }; onChange = (item) => { - console.log(this.props.onChange); let value = this.props.mode === 'multiple' && this.props.value ? [...this.props.value]