diff --git a/ui/src/components/AdvancePropertise/index.tsx b/ui/src/components/AdvancePropertise/index.tsx index 56b4b4d95..26f28cdd4 100644 --- a/ui/src/components/AdvancePropertise/index.tsx +++ b/ui/src/components/AdvancePropertise/index.tsx @@ -11,7 +11,7 @@ import { Icon, Select, Radio, - Button, + Button } from '@contentstack/venus-components'; // Service @@ -78,13 +78,28 @@ const AdvancePropertise = (props: SchemaProps) => { const [embedObjectsLabels, setEmbedObjectsLabels] = useState( props?.value?.embedObjects ); - const [referencedCT, setReferencedCT] = useState(referencedItems || null); + const [referencedCT, setReferencedCT] = useState( + referencedItems || null + ); const [showOptions, setShowOptions] = useState>({}); const [showIcon, setShowIcon] = useState(); const filterRef = useRef(null); const [options, setOptions] = useState(props?.value?.options || []); const [draggedIndex, setDraggedIndex] = useState(null); + useEffect(() => { + if (props?.data?.refrenceTo && Array.isArray(props?.data?.refrenceTo)) { + const updatedReferencedItems = props?.data?.refrenceTo.map((item: string) => ({ + label: item, + value: item + })); + setReferencedCT(updatedReferencedItems); + setToggleStates((prevStates) => ({ + ...prevStates, + referenedItems: props?.data?.refrenceTo + })); + } + }, [props?.data?.refrenceTo]); useEffect(() => { const defaultIndex = toggleStates?.option?.findIndex( (item: optionsType) => toggleStates?.default_value === item?.key @@ -344,9 +359,9 @@ const AdvancePropertise = (props: SchemaProps) => { const option = validateArray(contentTypesList) ? contentTypesList?.map((option: ContentType) => ({ - label: option?.contentstackTitle, - value: option?.contentstackUid - })) + label: option?.contentstackTitle, + value: option?.contentstackUid + })) : [{ label: contentTypesList, value: contentTypesList }]; return ( @@ -372,8 +387,7 @@ const AdvancePropertise = (props: SchemaProps) => { draggable onDragStart={() => handleDragStart(index)} onDragOver={(e) => handleDragOver(e, index)} - onDrop={() => handleDrop(index)} - > + onDrop={() => handleDrop(index)}>
@@ -387,8 +401,7 @@ const AdvancePropertise = (props: SchemaProps) => { index === showIcon && ( ) - } - > + }> + onClick={() => handleOnClick(index)}> {showOptions[index] && (
@@ -408,8 +420,7 @@ const AdvancePropertise = (props: SchemaProps) => { buttonType="light" icon={'v2-CheckSquareOffset'} size={'small'} - onClick={() => handleDefalutValue(index, option)} - > + onClick={() => handleDefalutValue(index, option)}> Mark as Default ) : ( @@ -418,8 +429,7 @@ const AdvancePropertise = (props: SchemaProps) => { buttonType="light" icon={'v2-CheckSquareOffset'} size={'small'} - onClick={() => handleRemoveDefalutValue(index)} - > + onClick={() => handleRemoveDefalutValue(index)}> Remove as Default )} @@ -433,53 +443,52 @@ const AdvancePropertise = (props: SchemaProps) => { {(props?.fieldtype === 'Single Line Textbox' || props?.fieldtype === 'Multi Line Textbox') && ( - <> - - - Default Value - - - - - ) => - handleOnChange('default_value', e, true)) - } - /> - - - - - Validation (Regex) - - - - - ) => - handleOnChange('validationRegex', e, true)) - } - /> - - - )} + <> + + + Default Value + + + + + ) => + handleOnChange('default_value', e, true)) + } + /> + + + + + Validation (Regex) + + + + + ) => + handleOnChange('validationRegex', e, true)) + } + /> + + + )} {props?.fieldtype === 'Link' && ( <> @@ -491,8 +500,7 @@ const AdvancePropertise = (props: SchemaProps) => { content={ 'Set a default field value for this field. The value will appear by default while creating an entry for this content type.' } - position="right" - > + position="right">
@@ -540,13 +548,11 @@ const AdvancePropertise = (props: SchemaProps) => { handleRadioChange('default_value', true)} - > + onChange={() => handleRadioChange('default_value', true)}> handleRadioChange('default_value', false)} - > + onChange={() => handleRadioChange('default_value', false)}> )} @@ -564,19 +570,25 @@ const AdvancePropertise = (props: SchemaProps) => { setReferencedCT(selectedOptions); const referencedArray = selectedOptions?.map((item: optionsType) => item?.value); + setToggleStates((prevStates) => ({ + ...prevStates, + referenedItems: referencedArray + })); + props?.updateFieldSettings( props?.rowId, { ...props?.value, + mandatory: toggleStates?.mandatory, + nonLocalizable: toggleStates?.nonLocalizable, validationRegex: toggleStates?.validationRegex ?? '', - referenedItems: referencedArray // <-- update only this property! + referenedItems: referencedArray }, true, props?.data?.contentstackFieldUid ); }} - options={ - option} + options={option} placeholder="Add Content Type(s)" version="v2" isSearchable={true} @@ -595,54 +607,56 @@ const AdvancePropertise = (props: SchemaProps) => {
{(props?.fieldtype === 'HTML Rich text Editor' || props?.fieldtype === 'JSON Rich Text Editor') && ( - <> -
- 0 || toggleStates?.embedObject} - onChange={ - handleToggleChange && - ((e: React.MouseEvent) => - handleToggleChange( - 'embedObject', - (e.target as HTMLInputElement)?.checked, - true - )) - } - /> -
+ <> +
+ 0 || toggleStates?.embedObject} + onChange={ + handleToggleChange && + ((e: React.MouseEvent) => + handleToggleChange( + 'embedObject', + (e.target as HTMLInputElement)?.checked, + true + )) + } + /> +
- {((ctValue && ctValue?.length > 0) || toggleStates?.embedObject) && ( - { + setCTValue(selectedOptions); + const embedObject = selectedOptions?.map( + (item: optionsType) => item?.value + ); // Update the state with the selected options + props?.updateFieldSettings( + props?.rowId, + { + validationRegex: toggleStates?.validationRegex ?? '', + embedObjects: embedObject + }, + true, + props?.data?.contentstackFieldUid + ); + }} + options={option} + placeholder="Select Content Types" + version="v2" + isSearchable={true} + isClearable={true} + width="350px" + maxMenuHeight={200} // isSelectAll={true} - /> - )} - - )} + /> + )} + + )} {props?.fieldtype !== 'Global' && props?.fieldtype !== 'Boolean' && (
{ + disabled={props?.isLocalised}> null, diff --git a/upload-api/migration-aem/libs/contentType/components/TeaserComponent.ts b/upload-api/migration-aem/libs/contentType/components/TeaserComponent.ts index 2020b9278..757b5684d 100644 --- a/upload-api/migration-aem/libs/contentType/components/TeaserComponent.ts +++ b/upload-api/migration-aem/libs/contentType/components/TeaserComponent.ts @@ -65,6 +65,7 @@ export class TeaserComponent extends ContentstackComponent { uid: key, displayName: key, description: "", + isNumber: true, defaultValue: "" }).toContentstack(), object: (key, schemaProp) => {