Skip to content

Commit 117b935

Browse files
Merge pull request #729 from contentstack/revert-724-bugfix/cmg-616
Revert "refactor:added alert box for refresh and refactored the issue of cont…"
2 parents 34cfd0c + 7be86bd commit 117b935

File tree

8 files changed

+26
-88
lines changed

8 files changed

+26
-88
lines changed

ui/src/components/ContentMapper/contentMapper.interface.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,5 +206,4 @@ export interface ModifiedField {
206206
backupFieldType: string;
207207
parentId: string;
208208
uid: string;
209-
_canSelect?: boolean;
210209
}

ui/src/components/ContentMapper/index.tsx

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
272272

273273
const [searchContentType, setSearchContentType] = useState('');
274274

275-
const [rowIds, setRowIds] = useState<Record<string, boolean>>({});
275+
const [rowIds, setRowIds] = useState({});
276276
const [selectedEntries, setSelectedEntries] = useState<FieldMapType[]>([]);
277277
const [contentTypeSchema, setContentTypeSchema] = useState<ContentTypesSchema[] | undefined>([]);
278278
const [showFilter, setShowFilter] = useState<boolean>(false);
@@ -292,7 +292,7 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
292292
const [isCsCTypeUpdated, setsCsCTypeUpdated] = useState<boolean>(false);
293293
const [isLoadingSaveButton, setisLoadingSaveButton] = useState<boolean>(false);
294294
const [activeFilter, setActiveFilter] = useState<string>('');
295-
const [isAllCheck, setIsAllCheck] = useState<boolean>(false);
295+
296296

297297
/** ALL HOOKS Here */
298298
const { projectId = '' } = useParams();
@@ -361,7 +361,6 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
361361

362362

363363
if (newMigrationData?.content_mapping?.content_type_mapping?.[selectedContentType?.contentstackUid || ''] === otherContentType?.id) {
364-
setIsAllCheck(false);
365364
tableData?.forEach((row) => {
366365
contentTypeSchema?.forEach((schema) => {
367366

@@ -433,16 +432,14 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
433432
}, [tableData, otherContentType]);
434433

435434
useEffect(() => {
436-
if (isUpdated) {
437-
setIsAllCheck(false);
435+
if (isUpdated) {
438436
setTableData(updatedRows);
439437
setExistingField(updatedExstingField);
440438
setSelectedOptions(updatedSelectedOptions);
441439
setSelectedEntries(updatedRows);
442440
setIsUpdated(false);
443441
}
444442
else{
445-
setIsAllCheck(false);
446443
setExistingField({});
447444
setSelectedOptions([]);
448445

@@ -452,15 +449,15 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
452449
// To make all the fields checked
453450
useEffect(() => {
454451
const selectedId = tableData?.reduce<UidMap>((acc, item) => {
455-
if(!item?.isDeleted && isAllCheck) {
452+
if(!item?.isDeleted) {
456453
acc[item?.id] = true;
457454

458455
}
459456
return acc;
460457
}, {});
461458

462-
isAllCheck && setRowIds(selectedId);
463-
}, [tableData, isAllCheck]);
459+
setRowIds(selectedId);
460+
}, [tableData]);
464461

465462
// To fetch existing content types or global fields as per the type
466463
useEffect(() => {
@@ -545,7 +542,6 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
545542
},[contentTypeSchema]);
546543
useEffect(() => {
547544
if (existingField && isCsCTypeUpdated) {
548-
setIsAllCheck(false);
549545
const matchedKeys = new Set<string>();
550546

551547
contentTypeSchema?.forEach((item) => {
@@ -676,7 +672,7 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
676672
setItemStatusMap({ ...itemStatusMap });
677673

678674
const validTableData = data?.fieldMapping?.filter((field: FieldMapType) => field?.otherCmsType !== undefined);
679-
setIsAllCheck(true);
675+
680676
setTableData(validTableData ?? []);
681677
setSelectedEntries(validTableData ?? []);
682678
setTotalCounts(validTableData?.length);
@@ -721,8 +717,7 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
721717
// eslint-disable-next-line no-unsafe-optional-chaining
722718
setTableData([...tableData, ...validTableData ?? tableData]);
723719
setTotalCounts([...tableData, ...validTableData ?? tableData]?.length);
724-
setIsLoading(false);
725-
setIsAllCheck(true);
720+
setIsLoading(false)
726721
} catch (error) {
727722
console.error('loadMoreItems -> error', error);
728723
}
@@ -754,7 +749,6 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
754749
};
755750

756751
const openContentType = (i: number) => {
757-
setIsAllCheck(true);
758752
setIsFieldDeleted(false);
759753
setActive(i);
760754
const otherTitle = filteredContentTypes?.[i]?.contentstackUid;
@@ -827,26 +821,24 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
827821

828822
// add row ids with their data to rowHistoryObj
829823
useEffect(() => {
830-
setIsAllCheck(false);
831824
Object.keys(rowHistoryObj)?.forEach(key => delete rowHistoryObj[key]);
832825
tableData?.forEach(item => {
833826
rowHistoryObj[item?.id] = [{checked: true, at: Date.now(), ...modifiedObj(item)}]
834827
});
835828
}, [tableData]);
836829

837-
const getParentId = (uid: string) => {
838-
return tableData?.find((i) => i?.uid?.toLowerCase() === uid?.toLowerCase() && i?.backupFieldType?.toLowerCase() === 'group')?.id ?? ''
830+
const getParentId = (uid: string) => {
831+
return tableData?.find(i => i?.uid?.toLowerCase() === uid?.toLowerCase())?.id ?? ''
839832
}
840833

841834
const modifiedObj = (obj: FieldMapType) => {
842-
const {backupFieldType, uid, id, _canSelect} = obj ?? {}
835+
const {backupFieldType, uid, id} = obj ?? {}
843836
const excludeArr = ["group"]
844837
return {
845838
id,
846839
backupFieldType,
847840
uid,
848-
parentId : excludeArr?.includes?.(backupFieldType?.toLowerCase()) ? '' : getParentId(uid?.split('.')[0]?.toLowerCase()),
849-
_canSelect,
841+
parentId : excludeArr?.includes?.(backupFieldType?.toLowerCase()) ? '' : getParentId(uid?.split('.')[0]?.toLowerCase())
850842
}
851843
}
852844

@@ -894,7 +886,7 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
894886

895887
const handleSelectedEntries = (singleSelectedRowIds: string[]) => {
896888
const selectedObj: UidMap = {};
897-
setIsAllCheck(false);
889+
898890
singleSelectedRowIds?.forEach((uid: string) => {
899891
const isId = selectedEntries?.some((item) => item?.id === uid);
900892
if (isId) {
@@ -948,7 +940,7 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
948940
})
949941
}
950942
}
951-
} else if(latestRow?.parentId && latestRow?._canSelect === true){
943+
} else if(latestRow?.parentId && !["title", "url"]?.includes?.(latestRow?.uid?.toLowerCase())){
952944
// Extract the group UID if item is child of any group
953945
const uidBeforeDot = latestRow?.uid?.split?.('.')?.[0]?.toLowerCase();
954946
const groupItem = tableData?.find((entry) => entry?.uid?.toLowerCase() === uidBeforeDot);
@@ -980,7 +972,7 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
980972
}
981973
}
982974

983-
const updatedTableData = selectedEntries?.map?.((tableItem) => {
975+
const updatedTableData = tableData?.map?.((tableItem) => {
984976
// Mark the item as deleted if not found in selectedData
985977
return {
986978
...tableItem,
@@ -996,7 +988,6 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
996988
const handleValueChange = (value: FieldTypes, rowIndex: string, rowContentstackFieldUid: string) => {
997989
setIsDropDownChanged(true);
998990
setFieldValue(value);
999-
setIsAllCheck(false);
1000991
const updatedRows: FieldMapType[] = selectedEntries?.map?.((row) => {
1001992
if (row?.uid === rowIndex && row?.contentstackFieldUid === rowContentstackFieldUid) {
1002993
return { ...row, contentstackFieldType: value?.value };
@@ -1019,7 +1010,7 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
10191010

10201011
const handleDropDownChange = (value: FieldTypes) => {
10211012
(value?.id !== otherContentType?.id) && setsCsCTypeUpdated(true);
1022-
setIsAllCheck(false);
1013+
10231014
setOtherContentType(value);
10241015
};
10251016

@@ -1512,7 +1503,6 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
15121503
if (!updatedSelectedOptions?.includes?.(newValue)) {
15131504
updatedSelectedOptions.push(newValue);
15141505
}
1515-
setIsAllCheck(false);
15161506
setIsUpdated(true);
15171507
}
15181508

@@ -1630,7 +1620,6 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
16301620

16311621
const handleSaveContentType = async () => {
16321622
setisLoadingSaveButton(true);
1633-
setIsAllCheck(false);
16341623
const orgId = selectedOrganisation?.uid;
16351624
const projectID = projectId;
16361625
if (

ui/src/components/DestinationStack/Actions/LoadLanguageMapper.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ const LanguageMapper = ({stack, uid} :{ stack : IDropDown, uid : string}) => {
480480
const [cmsLocaleOptions, setcmsLocaleOptions] = useState<{ label: string; value: string }[]>([]);
481481
const [sourceLocales, setsourceLocales] = useState<{ label: string; value: string }[]>([]);
482482
const [isLoading, setisLoading] = useState<boolean>(false);
483-
const [currentStack, setCurrentStack] = useState<IDropDown>(stack);
483+
const [currentStack, setCurrentStack] = useState<IDropDown>();
484484
const [previousStack, setPreviousStack] = useState<IDropDown>();
485485
const [isStackChanged, setisStackChanged] = useState<boolean>(false);
486486
const [stackValue, setStackValue] = useState<string>(stack?.value)

ui/src/components/DestinationStack/Actions/LoadStacks.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ const LoadStacks = (props: LoadFileFormatProps) => {
8686
const [placeholder] = useState<string>('Select a stack');
8787
const [localePlaceholder, setlocalePlaceholder ] = useState<string>('Master Locale will be set after stack selection');
8888
const newMigrationDataRef = useRef(newMigrationData);
89-
const [isStackLoading, setIsStackLoading] = useState<boolean>(true);
9089

9190
useEffect(() => {
9291
newMigrationDataRef.current = newMigrationData;
@@ -112,7 +111,6 @@ const LoadStacks = (props: LoadFileFormatProps) => {
112111
const handleOnSave = async (data: Stack) => {
113112
try {
114113
// Post data to backend
115-
setIsStackLoading(true);
116114
const resp = await createStacksInOrg(selectedOrganisation?.value, {
117115
...data,
118116
master_locale: data?.locale
@@ -155,7 +153,6 @@ const LoadStacks = (props: LoadFileFormatProps) => {
155153
};
156154

157155
dispatch(updateNewMigrationData(newMigrationDataObj));
158-
setIsStackLoading(false);
159156
// call for Step Change
160157
props.handleStepChange(props?.currentStep, true);
161158

@@ -360,7 +357,7 @@ const LoadStacks = (props: LoadFileFormatProps) => {
360357
</div>
361358
</div>
362359

363-
{newMigrationData?.destination_stack?.selectedStack?.value && (!isEmptyString(newMigrationData?.destination_stack?.selectedStack?.value) || !isStackLoading) &&(
360+
{newMigrationData?.destination_stack?.selectedStack?.value && (
364361
<div className="language-mapper">
365362
<div className="info-lang">
366363
<div className="stackTitle language-title">Language Mapping</div>
@@ -378,7 +375,7 @@ const LoadStacks = (props: LoadFileFormatProps) => {
378375
</div>
379376
<LanguageMapper
380377
uid={selectedStack?.uid ?? ''}
381-
stack={newMigrationData?.destination_stack?.selectedStack ?? DEFAULT_DROPDOWN} />
378+
stack={selectedStack ?? DEFAULT_DROPDOWN} />
382379
</div>
383380
)}
384381
</div>

ui/src/components/DestinationStack/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ const DestinationStackComponent = ({
101101
},[newMigrationData?.isprojectMapped]);
102102

103103
useEffect(()=>{
104-
if(!isEmptyString(newMigrationData?.destination_stack?.selectedStack?.value )
104+
if(! isEmptyString(newMigrationData?.destination_stack?.selectedStack?.value )
105105
){
106106
handleAllStepsComplete(true);
107107
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ interface UploadState {
2626
fileFormat?: string;
2727
isConfigLoading: boolean;
2828
isLoading: boolean;
29-
isValidated?: boolean;
29+
isValidated: boolean;
3030
isDisabled?: boolean;
3131
processing: string;
3232
progressPercentage: number;
@@ -190,7 +190,7 @@ const LoadUploadFile = (props: LoadUploadFileProps) => {
190190
{
191191
isLoading,
192192
isConfigLoading,
193-
//isValidated,
193+
isValidated,
194194
validationMessgae,
195195
isDisabled,
196196
cmsType,
@@ -290,7 +290,7 @@ const LoadUploadFile = (props: LoadUploadFileProps) => {
290290
if (savedState) {
291291
setIsLoading(savedState.isLoading);
292292
setIsConfigLoading(savedState.isConfigLoading);
293-
//setIsValidated(savedState?.isValidated);
293+
setIsValidated(savedState?.isValidated);
294294
setValidationMessage(savedState?.validationMessage);
295295
//setIsDisabled(savedState?.isDisabled);
296296
setCmsType(savedState.cmsType);
@@ -315,7 +315,7 @@ const LoadUploadFile = (props: LoadUploadFileProps) => {
315315
{
316316
isLoading,
317317
isConfigLoading,
318-
//isValidated,
318+
isValidated,
319319
validationMessgae,
320320
//isDisabled,
321321
cmsType,
@@ -331,7 +331,7 @@ const LoadUploadFile = (props: LoadUploadFileProps) => {
331331
}, [
332332
isLoading,
333333
isConfigLoading,
334-
//isValidated,
334+
isValidated,
335335
validationMessgae,
336336
//isDisabled,
337337
cmsType,

ui/src/hooks/useWarnOnrefresh.tsx

Lines changed: 0 additions & 18 deletions
This file was deleted.

ui/src/pages/Migration/index.tsx

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { cbModal, Notification } from '@contentstack/venus-components';
77
// Redux files
88
import { RootState } from '../../store';
99
import { updateMigrationData, updateNewMigrationData } from '../../store/slice/migrationDataSlice';
10-
import { useWarnOnRefresh } from '../../hooks/useWarnOnrefresh';
1110

1211
// Services
1312
import {
@@ -101,38 +100,10 @@ const Migration = () => {
101100
const saveRef = useRef<ContentTypeSaveHandles>(null);
102101
const newMigrationDataRef = useRef(newMigrationData);
103102

104-
const [isSaved, setIsSaved] = useState<boolean>(false);
105-
106103
useEffect(() => {
107104
fetchData();
108105
}, [params?.stepId, params?.projectId, selectedOrganisation?.value]);
109106

110-
useWarnOnRefresh(isSaved);
111-
112-
useEffect(()=>{
113-
const hasNonEmptyMapping =
114-
newMigrationData?.destination_stack?.localeMapping &&
115-
Object.entries(newMigrationData?.destination_stack?.localeMapping || {})?.every(
116-
([label, value]: [string, string]) =>
117-
Boolean(label?.trim()) &&
118-
value !== '' &&
119-
value !== null &&
120-
value !== undefined
121-
);
122-
if(legacyCMSRef?.current && !isCompleted && newMigrationData?.project_current_step === 1){
123-
setIsSaved(true);
124-
}
125-
else if ((isCompleted && !isEmptyString(newMigrationData?.destination_stack?.selectedStack?.value) && newMigrationData?.project_current_step === 2)){
126-
setIsSaved(true);
127-
}
128-
else if(newMigrationData?.content_mapping?.isDropDownChanged){
129-
setIsSaved(true);
130-
}
131-
else{
132-
setIsSaved(false);
133-
}
134-
},[isCompleted, newMigrationData])
135-
136107
/**
137108
* Dispatches the isprojectMapped key to redux
138109
*/
@@ -249,7 +220,7 @@ const Migration = () => {
249220
const newMigrationDataObj = {
250221
name: data?.localPath,
251222
url: data?.localPath,
252-
isValidated: false,
223+
isValidated: data?.localPath !== newMigrationData?.legacy_cms?.uploadedFile?.file_details?.localPath ? false : newMigrationData?.legacy_cms?.uploadedFile?.isValidated,
253224
file_details: {
254225
isLocalPath: data?.isLocalPath,
255226
cmsType: data?.cmsType,

0 commit comments

Comments
 (0)