Skip to content

Commit

Permalink
added necessary changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Prince0906 committed Jul 28, 2024
1 parent d248361 commit 678bb75
Showing 1 changed file with 38 additions and 42 deletions.
80 changes: 38 additions & 42 deletions packages/volto/src/components/manage/Widgets/ArrayWidget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -194,9 +202,9 @@ const ArrayWidget = ({
}, [
items,
choices,
vocabBaseUrl,
vocabLoading,
vocabLoaded,
vocabBaseUrl,
lang,
getVocabulary,
]);
Expand Down Expand Up @@ -253,13 +261,7 @@ const ArrayWidget = ({
: SortableContainer(CreatableSelect);

return (
<FormFieldWrapper
id={id}
title={title}
description={description}
required={required}
error={error}
>
<FormFieldWrapper {...props}>
<SortableSelect
useDragHandle
// react-sortable-hoc props:
Expand Down Expand Up @@ -338,10 +340,6 @@ const ArrayWidget = ({

ArrayWidget.propTypes = {
id: PropTypes.string.isRequired,
title: PropTypes.string.isRequired,
description: PropTypes.string,
required: PropTypes.bool,
error: PropTypes.arrayOf(PropTypes.string),
getVocabulary: PropTypes.func.isRequired,
choices: PropTypes.arrayOf(
PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
Expand All @@ -364,8 +362,6 @@ ArrayWidget.propTypes = {
};

ArrayWidget.defaultProps = {
description: null,
required: false,
items: {
vocabulary: null,
},
Expand Down

0 comments on commit 678bb75

Please sign in to comment.