Skip to content

Commit 4a4d22c

Browse files
Merge pull request #826 from contentstack/feature/aem-final
[cmg-709], advance properties toggle button fixes
2 parents 0062135 + 77f93ce commit 4a4d22c

File tree

3 files changed

+25
-59
lines changed

3 files changed

+25
-59
lines changed

ui/src/components/AdvancePropertise/index.tsx

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@ const AdvancePropertise = (props: SchemaProps) => {
182182
* @param checkBoxChanged - Indicates if the checkbox was changed.
183183
*/
184184
const handleToggleChange = (field: string, value: boolean, checkBoxChanged: boolean) => {
185+
// If unchecking embedObject toggle, clear the embed objects
186+
if (field === 'embedObject' && !value) {
187+
setCTValue(null);
188+
setEmbedObjectsLabels([]);
189+
}
190+
185191
setToggleStates((prevStates) => ({
186192
...prevStates,
187193
[field]: value
@@ -202,7 +208,7 @@ const AdvancePropertise = (props: SchemaProps) => {
202208
unique: false,
203209
nonLocalizable: currentToggleStates?.nonLocalizable,
204210
embedObject: currentToggleStates?.embedObject,
205-
embedObjects: embedObjectsLabels,
211+
embedObjects: field === 'embedObject' && !value ? [] : embedObjectsLabels,
206212
default_value: currentToggleStates?.default_value,
207213
minChars: currentToggleStates?.minChars,
208214
maxChars: currentToggleStates?.maxChars,
@@ -611,7 +617,7 @@ const AdvancePropertise = (props: SchemaProps) => {
611617
label="Embed Object(s)"
612618
labelColor="primary"
613619
labelPosition="right"
614-
checked={(ctValue?.length ?? 0) > 0 || toggleStates?.embedObject}
620+
checked={toggleStates?.embedObject}
615621
onChange={
616622
handleToggleChange &&
617623
((e: React.MouseEvent<HTMLElement>) =>
@@ -624,7 +630,7 @@ const AdvancePropertise = (props: SchemaProps) => {
624630
/>
625631
</div>
626632

627-
{((ctValue && ctValue?.length > 0) || toggleStates?.embedObject) && (
633+
{toggleStates?.embedObject && (
628634
<Select
629635
value={ctValue}
630636
isMulti={true}
@@ -633,11 +639,22 @@ const AdvancePropertise = (props: SchemaProps) => {
633639
const embedObject = selectedOptions?.map(
634640
(item: optionsType) => item?.value
635641
); // Update the state with the selected options
642+
643+
// If all embed objects are removed, also uncheck the toggle
644+
const shouldToggleOff = !selectedOptions || selectedOptions.length === 0;
645+
if (shouldToggleOff) {
646+
setToggleStates((prevStates) => ({
647+
...prevStates,
648+
embedObject: false
649+
}));
650+
}
651+
636652
props?.updateFieldSettings(
637653
props?.rowId,
638654
{
639655
validationRegex: toggleStates?.validationRegex ?? '',
640-
embedObjects: embedObject
656+
embedObjects: embedObject,
657+
embedObject: !shouldToggleOff
641658
},
642659
true,
643660
props?.data?.contentstackFieldUid

ui/src/components/Common/AddStack/addStack.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,7 @@ const AddStack = (props: any): JSX.Element => {
130130
onSubmit={onSubmit}
131131
keepDirtyOnReinitialize={true}
132132
validate={(values: Stack) => {
133-
const errors: Errors = {
134-
name: '',
135-
locale: '',
136-
description: ''
137-
};
133+
const errors: any = {};
138134
if (!values?.name || values?.name?.trim().length < 1) {
139135
errors.name = 'Stack name required';
140136
}

ui/src/components/LegacyCms/Actions/LoadSelectCms.tsx

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ const LoadSelectCms = (props: LoadSelectCmsProps) => {
3939
const dispatch = useDispatch();
4040

4141
const [cmsData, setCmsData] = useState<ICMSType[]>([]);
42-
const [searchText] = useState<string>('');
43-
//const [cmsFilterStatus, setCmsFilterStatus] = useState<IFilterStatusType>({});
42+
4443
const [cmsType, setCmsType] = useState<ICMSType>(
4544
newMigrationData?.legacy_cms?.selectedCms || defaultCardType
4645
);
@@ -53,7 +52,6 @@ const LoadSelectCms = (props: LoadSelectCmsProps) => {
5352
const [errorMessage, setErrorMessage] = useState<string>('');
5453

5554
/**** ALL METHODS HERE ****/
56-
5755
//Handle Legacy cms selection
5856
const handleCardClick = async (data: ICMSType) => {
5957
setSelectedCard({ ...data });
@@ -75,7 +73,7 @@ const LoadSelectCms = (props: LoadSelectCmsProps) => {
7573
};
7674

7775
// Filter CMS Data
78-
const filterCMSData = async (searchText: string) => {
76+
const filterCMSData = async () => {
7977
try {
8078
const { all_cms = [] } = migrationData?.legacyCMSData || {};
8179
setSelectedCard(cmsType);
@@ -116,29 +114,6 @@ const LoadSelectCms = (props: LoadSelectCmsProps) => {
116114
setCmsData([]);
117115
}
118116
}
119-
const newMigrationDataObj = {
120-
...newMigrationData,
121-
legacy_cms: {
122-
...newMigrationData?.legacy_cms,
123-
selectedFileFormat: filteredCmsData[0].allowed_file_formats[0]
124-
}
125-
};
126-
127-
//dispatch(updateNewMigrationData(newMigrationDataObj));
128-
129-
// setCmsData(filteredCmsData);
130-
131-
//Normal Search
132-
const _filterCmsData = validateArray(all_cms)
133-
? filteredCmsData?.filter(
134-
({ title, cms_id }: ICMSType) =>
135-
//Filtering Criteria base on SearchText
136-
title?.toLowerCase()?.includes(searchText) ||
137-
cms_id?.toLowerCase()?.includes(searchText)
138-
)
139-
: [];
140-
141-
setCmsData(_filterCmsData);
142117

143118
let newSelectedCard: ICMSType | undefined;
144119

@@ -172,31 +147,9 @@ const LoadSelectCms = (props: LoadSelectCmsProps) => {
172147

173148
/**** ALL USEEffects HERE ****/
174149
useEffect(() => {
175-
filterCMSData(searchText);
150+
filterCMSData();
176151
}, []);
177152

178-
179-
// Handle Legacy cms selection for single match
180-
// useEffect(() => {
181-
// const isSingleMatch = cmsData?.length === 1;
182-
// if (isSingleMatch) {
183-
// setSelectedCard({ ...selectedCard });
184-
185-
// const newMigrationDataObj: INewMigration = {
186-
// ...newMigrationData,
187-
// legacy_cms: {
188-
// ...newMigrationDataRef?.current?.legacy_cms,
189-
// selectedCms: { ...selectedCard }
190-
// }
191-
// };
192-
// console.info("neMigObj ---> ", newMigrationDataObj, cmsData)
193-
// dispatch(updateNewMigrationData(newMigrationDataObj));
194-
195-
// // Call for Step Change
196-
// props?.handleStepChange(props?.currentStep);
197-
// }
198-
// }, [cmsData]);
199-
200153
return (
201154
<div>
202155
<div className="col-12">

0 commit comments

Comments
 (0)