From 678bb759c12657d602d22771214b2f03de8edeb2 Mon Sep 17 00:00:00 2001 From: Prince0906 Date: Sun, 28 Jul 2024 16:53:19 +0530 Subject: [PATCH] added necessary changes --- .../components/manage/Widgets/ArrayWidget.jsx | 80 +++++++++---------- 1 file changed, 38 insertions(+), 42 deletions(-) diff --git a/packages/volto/src/components/manage/Widgets/ArrayWidget.jsx b/packages/volto/src/components/manage/Widgets/ArrayWidget.jsx index 2b59ff3778..9baaee8a2f 100644 --- a/packages/volto/src/components/manage/Widgets/ArrayWidget.jsx +++ b/packages/volto/src/components/manage/Widgets/ArrayWidget.jsx @@ -148,42 +148,50 @@ const compareOption = (inputValue = '', option, accessors) => { * ``` */ -const ArrayWidget = ({ - id, - title, - description, - required, - error, - value, - onChange, - choices, - items, - vocabBaseUrl, - vocabLoading, - vocabLoaded, - getVocabulary, - disabled, - isDisabled, - focus, - placeholder, - default: defaultValue, - noValueOption, - reactSelectCreateable, - reactSortableHOC, - reactSelect, - lang, - creatable, -}) => { +const ArrayWidget = (props) => { + const { + id, + value, + onChange, + choices, + items, + vocabBaseUrl, + vocabLoading, + vocabLoaded, + getVocabulary, + disabled, + isDisabled, + focus, + placeholder, + default: defaultValue, + noValueOption, + reactSelectCreateable, + reactSortableHOC, + reactSelect, + lang, + creatable, + } = props; + const intl = useIntl(); // Effect to fetch vocabulary if needed + useEffect(() => { + if (!items?.choices?.length && !choices?.length && vocabBaseUrl) { + getVocabulary({ + vocabNameOrURL: vocabBaseUrl, + size: -1, + subrequest: lang, + }); + } + }, [items, choices, vocabBaseUrl, lang, getVocabulary]); + useEffect(() => { if ( !items?.choices?.length && !choices?.length && - vocabBaseUrl && vocabLoading === undefined && - !vocabLoaded + !vocabLoaded && + vocabBaseUrl ) { getVocabulary({ vocabNameOrURL: vocabBaseUrl, @@ -194,9 +202,9 @@ const ArrayWidget = ({ }, [ items, choices, - vocabBaseUrl, vocabLoading, vocabLoaded, + vocabBaseUrl, lang, getVocabulary, ]); @@ -253,13 +261,7 @@ const ArrayWidget = ({ : SortableContainer(CreatableSelect); return ( - +