Skip to content

Commit bea1f1f

Browse files
Merge pull request #847 from contentstack/dev
Pre-Stage pr
2 parents b336562 + ac18582 commit bea1f1f

File tree

13 files changed

+100
-73
lines changed

13 files changed

+100
-73
lines changed

api/src/services/contentMapper.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ const resetToInitialMapping = async (req: Request) => {
751751
const fieldMappingData = contentTypeData.fieldMapping.map((itemId: any) => {
752752
const fieldData = FieldMapperModel.chain
753753
.get("field_mapper")
754-
.find({ id: itemId, projectId: projectId })
754+
.find({ id: itemId, projectId: projectId, contentTypeId: contentTypeId})
755755
.value();
756756
return fieldData;
757757
});
@@ -771,7 +771,7 @@ const resetToInitialMapping = async (req: Request) => {
771771
//await FieldMapperModel.read();
772772
(fieldMappingData || []).forEach((field: any) => {
773773
const fieldIndex = FieldMapperModel.data.field_mapper.findIndex(
774-
(f: any) => f?.id === field?.id
774+
(f: any) => f?.id === field?.id && f?.projectId === projectId && f?.contentTypeId === contentTypeId
775775
);
776776
if (fieldIndex > -1) {
777777
FieldMapperModel.update((data: any) => {

api/src/services/sitecore.service.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,31 @@ async function writeFiles(
105105
console.error('Error writing files:', error);
106106
}
107107
}
108+
const uidCorrector = ({ uid } :{uid : string}) => {
109+
if (!uid || typeof uid !== 'string') {
110+
return '';
111+
}
112+
113+
let newUid = uid;
114+
115+
// Note: UIDs starting with numbers and restricted keywords are handled externally in Sitecore
116+
// The prefix is applied in contentTypeMaker function when needed
108117

109-
const uidCorrector = ({ uid }: any) => {
110-
if (startsWithNumber(uid)) {
111-
return `${append}_${_.replace(
112-
uid,
113-
new RegExp('[ -]', 'g'),
114-
'_'
115-
)?.toLowerCase()}`;
118+
// Clean up the UID
119+
newUid = newUid
120+
.replace(/[ -]/g, '_') // Replace spaces and hyphens with underscores
121+
.replace(/[^a-zA-Z0-9_]+/g, '_') // Replace non-alphanumeric characters (except underscore)
122+
.replace(/([A-Z])/g, (match) => `_${match.toLowerCase()}`) // Handle camelCase
123+
.toLowerCase() // Convert to lowercase
124+
.replace(/_+/g, '_') // Replace multiple underscores with single
125+
.replace(/^_|_$/g, ''); // Remove leading/trailing underscores
126+
127+
// Ensure UID doesn't start with underscore (Contentstack requirement)
128+
if (newUid.startsWith('_')) {
129+
newUid = newUid.substring(1);
116130
}
117-
return _.replace(uid, new RegExp('[ -]', 'g'), '_')?.toLowerCase();
131+
132+
return newUid;
118133
};
119134

120135
const createAssets = async ({

api/src/utils/content-type-creator.utils.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,32 @@ function startsWithNumber(str: string) {
7474
return /^\d/.test(str);
7575
}
7676

77-
const uidCorrector = ({ uid }: any) => {
78-
if (startsWithNumber(uid)) {
79-
return `a_${_.replace(uid, new RegExp("[ -]", "g"), '_')?.toLowerCase()}`
77+
const uidCorrector = ({ uid } : {uid : string}) => {
78+
if (!uid || typeof uid !== 'string') {
79+
return '';
8080
}
81-
return _.replace(uid, new RegExp("[ -]", "g"), '_')?.toLowerCase()
82-
}
81+
82+
let newUid = uid;
83+
84+
// Note: UIDs starting with numbers and restricted keywords are handled externally in Sitecore
85+
// The prefix is applied in contentTypeMaker function when needed
86+
87+
// Clean up the UID
88+
newUid = newUid
89+
.replace(/[ -]/g, '_') // Replace spaces and hyphens with underscores
90+
.replace(/[^a-zA-Z0-9_]+/g, '_') // Replace non-alphanumeric characters (except underscore)
91+
.replace(/([A-Z])/g, (match) => `_${match.toLowerCase()}`) // Handle camelCase
92+
.toLowerCase() // Convert to lowercase
93+
.replace(/_+/g, '_') // Replace multiple underscores with single
94+
.replace(/^_|_$/g, ''); // Remove leading/trailing underscores
95+
96+
// Ensure UID doesn't start with underscore (Contentstack requirement)
97+
if (newUid.startsWith('_')) {
98+
newUid = newUid.substring(1);
99+
}
100+
101+
return newUid;
102+
};
83103

84104

85105
function buildFieldSchema(item: any, marketPlacePath: string, parentUid = ''): any {
@@ -577,8 +597,8 @@ const convertToSchemaFormate = ({ field, advanced = false, marketPlacePath, keyM
577597
"field_metadata": {
578598
description: "",
579599
"default_value": {
580-
"title": "",
581-
"url": '',
600+
"title": field?.advanced?.title ?? '',
601+
"url": field?.advanced?.url ?? '',
582602
}
583603
},
584604
"format": field?.advanced?.validationRegex ?? '',

ui/src/cmsData/legacyCms.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@
338338
"uid": "cs6c761d71844ac800"
339339
},
340340
"title": "Add Source Affix",
341-
"description": "Add a 2–5 character affix for the source name. Use only letters, no numbers or special characters",
341+
"description": "Add a 2–5 letter-only affix for the source name. The affix will function as a prefix if the content type UID matches with <a href=\"https://www.contentstack.com/docs/developers/create-content-types/restricted-keywords-for-uids\" target=\"_blank\">restricted UIDs</a>. The affix will function as a suffix for field UIDs. If left blank, \"cs\" will be used by default. Avoid numbers, special characters, and restricted keywords",
342342
"step_lock_text": "Editing this step is currently disabled. To make changes in Draft mode, please deactivate the migration",
343343
"lock": false,
344344
"active": false,

ui/src/components/ContentMapper/index.scss

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,8 @@
151151
}
152152
.Table {
153153
border-left: 0 none;
154-
// min-height: inherit;
154+
min-height: 26.25rem;
155155
.Table__body__row {
156-
// height: auto!important;
157-
// min-height: 80px;
158156
.Table-select-body {
159157
>.checkbox-wrapper {
160158
align-items: flex-start;

ui/src/components/ContentMapper/index.tsx

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -760,15 +760,16 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
760760
}
761761

762762
setItemStatusMap(itemStatusMap);
763+
setLoading(true);
763764

764765
const { data } = await getFieldMapping(contentTypeId || '', 0, 1000, searchText || '', projectId);
765766

766-
767767
for (let index = 0; index <= 1000; index++) {
768768
itemStatusMap[index] = 'loaded';
769769
}
770770

771771
setItemStatusMap({ ...itemStatusMap });
772+
setLoading(false);
772773

773774
const validTableData = data?.fieldMapping?.filter((field: FieldMapType) => field?.otherCmsType !== undefined);
774775

@@ -777,7 +778,6 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
777778
setSelectedEntries(validTableData ?? []);
778779
setTotalCounts(validTableData?.length);
779780
setInitialRowSelectedData(validTableData?.filter((item: FieldMapType) => !item?.isDeleted))
780-
setIsLoading(false);
781781
generateSourceGroupSchema(validTableData);
782782
} catch (error) {
783783
console.error('fetchData -> error', error);
@@ -811,15 +811,15 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
811811
}
812812

813813
setItemStatusMap({ ...updateditemStatusMapCopy });
814+
setLoading(false);
814815

815816
const validTableData = data?.fieldMapping?.filter((field: FieldMapType) => field?.otherCmsType !== undefined);
816817

817818
// eslint-disable-next-line no-unsafe-optional-chaining
818-
setTableData([...tableData, ...validTableData ?? tableData]);
819-
setTotalCounts([...tableData, ...validTableData ?? tableData]?.length);
820-
setIsLoading(false);
819+
setTableData(validTableData ?? []);
820+
setSelectedEntries(validTableData ?? []);
821+
setTotalCounts(validTableData?.length);
821822
setIsAllCheck(true);
822-
823823
} catch (error) {
824824
console.error('loadMoreItems -> error', error);
825825
}
@@ -2645,20 +2645,6 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
26452645
initialRowSelectedData={initialRowSelectedData}
26462646
initialSelectedRowIds={rowIds}
26472647
itemSize={80}
2648-
v2Features={{
2649-
isNewEmptyState: true
2650-
}}
2651-
customEmptyState={
2652-
<EmptyState
2653-
forPage="list"
2654-
heading={<div className="empty_search_heading">No Fields available</div>}
2655-
moduleIcon="NoSearchResult"
2656-
description="Try changing the search query to find what you are looking for."
2657-
version="v2"
2658-
testId="no-results-found-page"
2659-
className="custom-empty-state"
2660-
/>
2661-
}
26622648
withExportCta={{
26632649
component: (
26642650
<div className='d-flex align-items-center'>

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

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const LoadPreFix = (props: LoadSelectCmsProps) => {
2929

3030
const dispatch = useDispatch();
3131

32-
const [prefix, setPrefix] = useState<string>(newMigrationData?.legacy_cms?.affix || '');
32+
const [prefix, setPrefix] = useState<string>(newMigrationData?.legacy_cms?.affix || 'cs');
3333

3434
const [isError, setIsError] = useState<boolean>(false);
3535
const [errorMessage, setErrorMessage] = useState<string>('');
@@ -76,7 +76,6 @@ const LoadPreFix = (props: LoadSelectCmsProps) => {
7676
isRestictedKeywordCheckboxChecked: isCheckedBoxChecked
7777
}
7878
};
79-
8079
dispatch(updateNewMigrationData(newMigrationDataObj));
8180
} else {
8281
setPrefix(value);
@@ -93,28 +92,37 @@ const LoadPreFix = (props: LoadSelectCmsProps) => {
9392
};
9493

9594
dispatch(updateNewMigrationData(newMigrationDataObj));
96-
9795
setIsError(false);
9896

9997
//call for Step Change
10098
props?.handleStepChange(props?.currentStep);
10199
return;
102100
}
103101
} else {
104-
setIsError(true);
105-
setErrorMessage('Please enter Affix');
102+
setIsError(false);
103+
setErrorMessage('');
104+
setIsRestrictedKey(false);
105+
setPrefix('');
106+
}
107+
});
108+
109+
const handleOnBlur = (value: string) => {
110+
if (isEmptyString(value?.trim())) {
111+
setIsError(false);
112+
setErrorMessage('');
113+
setIsRestrictedKey(false);
114+
setPrefix('cs');
106115
const newMigrationDataObj: INewMigration = {
107116
...newMigrationData,
108117
legacy_cms: {
109118
...newMigrationData?.legacy_cms,
110-
affix: value,
119+
affix: 'cs',
111120
isRestictedKeywordCheckboxChecked: isCheckedBoxChecked
112121
}
113122
};
114-
115123
dispatch(updateNewMigrationData(newMigrationDataObj));
116124
}
117-
});
125+
};
118126

119127
/**** ALL USEEffects HERE ****/
120128

@@ -136,6 +144,9 @@ const LoadPreFix = (props: LoadSelectCmsProps) => {
136144
aria-label="affix"
137145
disabled={newMigrationData?.legacy_cms?.uploadedFile?.isValidated}
138146
isReadOnly={newMigrationData?.legacy_cms?.uploadedFile?.isValidated}
147+
onBlur={(e: React.FocusEvent<HTMLInputElement>) => {
148+
handleOnBlur(e.target.value);
149+
}}
139150
/>
140151
{isError && <p className="errorMessage">{errorMessage}</p>}
141152
</div>

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ const LoadUploadFile = (props: LoadUploadFileProps) => {
154154
setIsDisabled(true);
155155

156156
if (
157-
!isEmptyString(newMigrationData?.legacy_cms?.affix) &&
158157
!isEmptyString(newMigrationData?.legacy_cms?.selectedCms?.cms_id) &&
159158
!isEmptyString(newMigrationData?.legacy_cms?.selectedFileFormat?.fileformat_id)
160159
) {
@@ -358,24 +357,23 @@ const LoadUploadFile = (props: LoadUploadFileProps) => {
358357
setShowMessage(true);
359358
setValidationMessage('File validated successfully.');
360359
setIsDisabled(true);
361-
!isEmptyString(newMigrationData?.legacy_cms?.affix) ||
360+
if (
362361
!isEmptyString(newMigrationData?.legacy_cms?.selectedCms?.cms_id) ||
363-
(!isEmptyString(newMigrationData?.legacy_cms?.selectedFileFormat?.fileformat_id) &&
364-
props.handleStepChange(props?.currentStep, true));
362+
!isEmptyString(newMigrationData?.legacy_cms?.selectedFileFormat?.fileformat_id)
363+
) {
364+
props.handleStepChange(props?.currentStep, true);
365+
}
365366
}
366367
if (newMigrationData?.legacy_cms?.uploadedFile?.reValidate) {
367368
setValidationMessage('');
368369
}
369-
if(!isEmptyString(newMigrationData?.legacy_cms?.affix) && !newMigrationData?.legacy_cms?.uploadedFile?.isValidated && !newMigrationData?.legacy_cms?.uploadedFile?.reValidate){
370+
if(!newMigrationData?.legacy_cms?.uploadedFile?.isValidated && !newMigrationData?.legacy_cms?.uploadedFile?.reValidate){
370371
setIsDisabled(false);
371372
}
372373
setReValidate(newMigrationData?.legacy_cms?.uploadedFile?.reValidate || false);
373-
374-
// else{
375-
// setIsValidated(false);
376-
// }
377374
}, [isValidated, newMigrationData]);
378375

376+
379377
useEffect(() => {
380378
if (newMigrationData?.legacy_cms?.selectedFileFormat?.fileformat_id) {
381379
setFileFormat(newMigrationData?.legacy_cms?.selectedFileFormat?.fileformat_id);
@@ -448,7 +446,7 @@ const LoadUploadFile = (props: LoadUploadFileProps) => {
448446
isLoading={isLoading}
449447
loadingColor="#6c5ce7"
450448
version="v2"
451-
disabled={!(reValidate || (!isDisabled && !isEmptyString(newMigrationData?.legacy_cms?.affix)))}
449+
disabled={!(reValidate || (!isDisabled))}
452450
>
453451
Validate File
454452
</Button>

ui/src/components/LegacyCms/index.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ const LegacyCMSComponent = forwardRef(({ legacyCMSData, isCompleted, handleOnAll
142142
}
143143

144144
//Make Step 2 complete
145-
if (!isEmptyString(selectedCmsData?.cms_id) && (!isEmptyString(legacyCMSData?.affix) || !isEmptyString(newMigrationData?.legacy_cms?.affix))) {
145+
if (!isEmptyString(selectedCmsData?.cms_id) && (!isEmptyString(legacyCMSData?.affix) )) {
146146
setInternalActiveStepIndex(1);
147147
}
148148

@@ -197,22 +197,20 @@ const LegacyCMSComponent = forwardRef(({ legacyCMSData, isCompleted, handleOnAll
197197

198198
//Make Step 2 complete
199199
if (
200-
!isEmptyString(newMigrationData?.legacy_cms?.selectedCms?.cms_id) &&
201-
!isEmptyString(newMigrationData?.legacy_cms?.affix)
200+
!isEmptyString(newMigrationData?.legacy_cms?.selectedCms?.cms_id)
202201
) {
203202
setInternalActiveStepIndex(1);
204203
}
205204

206-
if(!isEmptyString(newMigrationData?.legacy_cms?.selectedCms?.cms_id) && !isEmptyString(newMigrationData?.legacy_cms?.affix) && newMigrationData?.legacy_cms?.uploadedFile?.isValidated){
205+
if(!isEmptyString(newMigrationData?.legacy_cms?.selectedCms?.cms_id) && newMigrationData?.legacy_cms?.uploadedFile?.isValidated){
207206
setInternalActiveStepIndex(3);
208207
}
209208
setisProjectMapped(newMigrationData?.isprojectMapped)
210209

211210
},[newMigrationData]);
212211

213212
useEffect(()=>{
214-
if(! isEmptyString(newMigrationData?.legacy_cms?.affix)
215-
&& !isEmptyString(newMigrationData?.legacy_cms?.selectedFileFormat?.title) &&
213+
if( !isEmptyString(newMigrationData?.legacy_cms?.selectedFileFormat?.title) &&
216214
! isEmptyString(newMigrationData?.legacy_cms?.selectedCms?.title) &&
217215
newMigrationData?.legacy_cms?.uploadedFile?.isValidated){
218216
setIsAllStepsCompleted(true);

ui/src/components/Stepper/HorizontalStepper/HorizontalStepper.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,6 @@ const HorizontalStepper = forwardRef(
159159
shouldCloseOnOverlayClick: false
160160
}
161161
});
162-
} else if (
163-
-1 < newMigrationData?.legacy_cms?.currentStep &&
164-
newMigrationData?.legacy_cms?.currentStep < 2
165-
) {
166-
showNotification(newMigrationData?.legacy_cms?.currentStep + 1);
167162
} else if (
168163
newMigrationData?.destination_stack?.selectedStack === undefined ||
169164
newMigrationData?.destination_stack?.selectedStack === null ||

0 commit comments

Comments
 (0)