Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions api/src/utils/content-type-creator.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const saveAppMapper = async ({ marketPlacePath, data, fileName }: any) => {
}
}

const convertToSchemaFormate = ({ field, advanced = true, marketPlacePath }: any) => {
const convertToSchemaFormate = ({ field, advanced = true, marketPlacePath, keyMapper }: any) => {
switch (field?.contentstackFieldType) {
case 'single_line_text': {
return {
Expand Down Expand Up @@ -435,7 +435,7 @@ const convertToSchemaFormate = ({ field, advanced = true, marketPlacePath }: any
return {
data_type: "reference",
display_name: field?.title,
reference_to: field?.refrenceTo ?? [],
reference_to: field?.refrenceTo?.map((item:string) => keyMapper?.[item] || item) ?? [],
field_metadata: {
ref_multiple: true,
ref_multiple_content_types: true
Expand Down Expand Up @@ -728,7 +728,7 @@ export const contenTypeMaker = async ({ contentType, destinationStackId, project
uid: extractValue(element?.contentstackFieldUid, item?.contentstackFieldUid, '.'),
title: extractValue(element?.contentstackField, item?.contentstackField, ' >')?.trim(),
}
const schema: any = convertToSchemaFormate({ field, marketPlacePath });
const schema: any = convertToSchemaFormate({ field, marketPlacePath ,keyMapper});
if (typeof schema === 'object' && Array.isArray(group?.schema) && element?.isDeleted === false) {
group.schema.push(schema);
}
Expand All @@ -741,7 +741,8 @@ export const contenTypeMaker = async ({ contentType, destinationStackId, project
title: item?.contentstackField,
uid: item?.contentstackFieldUid
},
marketPlacePath
marketPlacePath,
keyMapper
});
if (dt && item?.isDeleted === false) {
ct?.schema?.push(dt);
Expand Down
37 changes: 26 additions & 11 deletions ui/src/components/ContentMapper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,7 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
const [otherCmsUid, setOtherCmsUid] = useState<string>(contentTypes?.[0]?.otherCmsUid);

const [active, setActive] = useState<number | null>(0);

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

const [rowIds, setRowIds] = useState<Record<string, boolean>>({});
const [selectedEntries, setSelectedEntries] = useState<FieldMapType[]>([]);
const [contentTypeSchema, setContentTypeSchema] = useState<ContentTypesSchema[] | undefined>([]);
Expand Down Expand Up @@ -365,6 +363,7 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:

if (newMigrationData?.content_mapping?.content_type_mapping?.[selectedContentType?.contentstackUid || ''] === otherContentType?.id) {
setIsAllCheck(false);

tableData?.forEach((row) => {
contentTypeSchema?.forEach((schema) => {

Expand Down Expand Up @@ -679,6 +678,7 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
setItemStatusMap({ ...itemStatusMap });

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

setIsAllCheck(true);
setTableData(validTableData ?? []);
setSelectedEntries(validTableData ?? []);
Expand Down Expand Up @@ -726,6 +726,7 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
setTotalCounts([...tableData, ...validTableData ?? tableData]?.length);
setIsLoading(false);
setIsAllCheck(true);

} catch (error) {
console.error('loadMoreItems -> error', error);
}
Expand Down Expand Up @@ -898,6 +899,7 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:

const handleSelectedEntries = (singleSelectedRowIds: string[]) => {
const selectedObj: UidMap = {};

setIsAllCheck(false);
singleSelectedRowIds?.forEach((uid: string) => {
const isId = selectedEntries?.some((item) => item?.id === uid);
Expand Down Expand Up @@ -1023,6 +1025,7 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:

const handleDropDownChange = (value: FieldTypes) => {
(value?.id !== otherContentType?.id) && setsCsCTypeUpdated(true);

setIsAllCheck(false);
setOtherContentType(value);
};
Expand Down Expand Up @@ -1437,7 +1440,7 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
const fieldTypeToMatch = Fields[data?.backupFieldType as keyof Mapping]?.type;
//check if UID of souce field is matching to exsting content type field UID
for (const value of contentTypeSchema) {
if (data?.uid === value?.uid && data?.backupFieldType === value?.data_type) {
if (data?.uid === value?.uid && data?.backupFieldType === value?.data_type && fieldTypeToMatch) {
OptionsForRow.push({ label: value?.display_name, value, isDisabled: false });
break;
}
Expand Down Expand Up @@ -1505,7 +1508,7 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
if (!hasMatchingEntry) {
updatedExstingField = {
...updatedExstingField,
[data?.uid]: { label: newLabel, value: newvalue }
[data?.backupFieldUid]: { label: newLabel, value: newvalue }
};
existingField[data?.backupFieldUid] = { label: newLabel, value: newvalue }
}
Expand Down Expand Up @@ -1579,12 +1582,13 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
...option,
isDisabled: selectedOptions?.includes?.(option?.label ?? '')
}));

return (
<div className="table-row">
<div className="select">
<Select
value={(OptionsForRow?.length === 0 || existingField?.[data?.backupFieldUid]?.label === undefined) ? OptionValue : existingField[data?.backupFieldUid]}
value={(OptionsForRow?.length === 0 || (data?.backupFieldType !== existingField[data?.backupFieldUid]?.value?.data_type || existingField?.[data?.backupFieldUid]?.label === undefined)) ? OptionValue :

existingField[data?.backupFieldUid]}
onChange={(selectedOption: FieldTypes) => {
if (OptionsForRow?.length === 0) {
handleValueChange(selectedOption, data?.uid, data?.backupFieldUid)
Expand All @@ -1595,7 +1599,7 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
placeholder="Select Field"
version={'v2'}
maxWidth="290px"
isClearable={selectedOptions?.includes?.(existingField?.[data?.backupFieldUid]?.label ?? '')}
isClearable={data?.backupFieldType === existingField[data?.backupFieldUid]?.value?.data_type && selectedOptions?.includes?.(existingField?.[data?.backupFieldUid]?.label ?? '')}
options={adjustedOptions}
isDisabled={OptionValue?.isDisabled || newMigrationData?.project_current_step > 4}
menuPlacement="auto"
Expand Down Expand Up @@ -1719,10 +1723,19 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
const savedCT = filteredContentTypes?.map?.(ct =>
ct?.id === data?.data?.updatedContentType?.id ? { ...ct, status: data?.data?.updatedContentType?.status } : ct
);
let filteredCT = savedCT;
if (!isEmptyString(activeFilter)) {
filteredCT = savedCT?.filter((ct) =>
CONTENT_MAPPING_STATUS?.[ct?.status] === activeFilter
);
}
const savedContentTypes = contentTypes?.map?.(ct =>
ct?.id === selectedContentType?.id ? { ...ct, status: data?.data?.status } : ct
);

setFilteredContentTypes(savedCT);
setContentTypes(savedCT);

setFilteredContentTypes(filteredCT);
setContentTypes(savedContentTypes);
setCount(filteredCT?.length);
try {
otherContentType?.id && await updateContentMapper(orgId, projectID, { ...contentTypeMapped, [selectedContentType?.contentstackUid]: otherContentType?.id });
} catch (err) {
Expand Down Expand Up @@ -2181,6 +2194,7 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
(e?.target as HTMLElement)?.closest('li')?.classList?.add('active-filter');

const filteredCT = contentTypes?.filter((ct) => { return CONTENT_MAPPING_STATUS[ct?.status] === value });
console.info('content types --> ',filteredCT)
if (value !== 'All') {
setFilteredContentTypes(filteredCT);
setCount(filteredCT?.length);
Expand Down Expand Up @@ -2450,7 +2464,8 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
...newMigrationData?.legacy_cms,
uploadedFile: {
...newMigrationData?.legacy_cms?.uploadedFile,
reValidate: true
reValidate: true,
buttonClicked: true,
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ const LoadStacks = (props: LoadFileFormatProps) => {
></Icon>
</Tooltip>
</div>

<LanguageMapper
uid={selectedStack?.uid ?? ''}
stack={newMigrationData?.destination_stack?.selectedStack ?? DEFAULT_DROPDOWN} />
Expand Down
4 changes: 4 additions & 0 deletions ui/src/components/LegacyCms/Actions/LoadUploadFile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ interface UploadState {
fileDetails?: FileDetails;
}


const FileComponent = ({ fileDetails }: Props) => {
return (
<div>
Expand Down Expand Up @@ -122,6 +123,7 @@ const LoadUploadFile = (props: LoadUploadFileProps) => {
legacy_cms: {
...newMigrationDataRef?.current?.legacy_cms,
uploadedFile: {
...newMigrationDataRef?.current?.legacy_cms?.uploadedFile,
name: data?.file_details?.localPath || '',
url: data?.file_details?.localPath,
validation: data?.message,
Expand Down Expand Up @@ -186,6 +188,7 @@ const LoadUploadFile = (props: LoadUploadFileProps) => {
}, 1000);

setIsLoading(false);

saveStateToLocalStorage(
{
isLoading,
Expand Down Expand Up @@ -287,6 +290,7 @@ const LoadUploadFile = (props: LoadUploadFileProps) => {

useEffect(() => {
const savedState = getStateFromLocalStorage(projectId);

if (savedState) {
setIsLoading(savedState.isLoading);
setIsConfigLoading(savedState.isConfigLoading);
Expand Down
3 changes: 1 addition & 2 deletions ui/src/components/LogScreen/MigrationLogViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,8 @@ const MigrationLogViewer = ({ serverPath }: LogsType) => {
) : (
<div
style={logStyles[level || ''] || logStyles.info}
className="log-entry logs-bg"
className="log-entry"
>
<div className="log-number">{index}</div>
<div className="log-time">
{timestamp
? new Date(timestamp)?.toTimeString()?.split(' ')[0]
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/LogScreen/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
font-family: 'IBM Plex Mono', monospace;
font-size: $size-font-large;
font-weight: $font-weight-medium;
padding: 30px 20px;
padding: 5px 0;
position: relative;

&.logs-bg {
Expand Down
3 changes: 1 addition & 2 deletions ui/src/components/LogScreen/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,8 @@ const TestMigrationLogViewer = ({ serverPath, sendDataToParent, projectId }: Log
) : (
<div
style={logStyles[level || ''] || logStyles.info}
className="log-entry logs-bg"
className="log-entry"
>
<div className="log-number">{index}</div>
<div className="log-time">
{timestamp
? new Date(timestamp)?.toTimeString()?.split(' ')[0]
Expand Down
13 changes: 7 additions & 6 deletions ui/src/components/MigrationFlowHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,14 @@ const MigrationFlowHeader = ({

const isProjectStatusThreeAndMapperNotGenerated =
params?.stepId === '1' &&
newMigrationData?.legacy_cms?.projectStatus === 3
newMigrationData?.legacy_cms?.projectStatus === 3 &&
newMigrationData?.legacy_cms?.uploadedFile?.buttonClicked

const isStepInvalid =
params?.stepId &&
params?.stepId <= '2' &&
newMigrationData?.project_current_step?.toString() !== params?.stepId;
newMigrationData?.project_current_step?.toString() !== params?.stepId &&
parseInt(params?.stepId) < newMigrationData?.project_current_step;

const isExecutionStarted =
finalExecutionStarted ||
Expand Down Expand Up @@ -126,10 +128,9 @@ const MigrationFlowHeader = ({
disabled={
isProjectStatusThreeAndMapperNotGenerated ?
isFileValidated :
isPreviousStepDisabled ||
isStep4AndNotMigrated ||
isStepInvalid ||
isExecutionStarted ||
isStep4AndNotMigrated ||
isStepInvalid ||
isExecutionStarted ||
destinationStackMigrated
}
>
Expand Down
4 changes: 3 additions & 1 deletion ui/src/context/app/app.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ export interface IFile {
file_details?: FileDetails;
isValidated: boolean;
reValidate: boolean;
cmsType: string
cmsType: string;
buttonClicked:boolean
}

export interface ICMSType extends ICardType {
Expand Down Expand Up @@ -318,6 +319,7 @@ export const DEFAULT_FILE: IFile = {
isValidated: false,
reValidate: false,
cmsType: '',
buttonClicked: false
};

export const DEFAULT_CMS_TYPE: ICMSType = {
Expand Down
1 change: 1 addition & 0 deletions ui/src/hooks/useWarnOnrefresh.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ export function useWarnOnRefresh(isUnsaved : boolean){
window.removeEventListener('beforeunload', handleBeforeUnload);
};
}, [isUnsaved]);

}
9 changes: 8 additions & 1 deletion ui/src/pages/Migration/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ type LocalesType = {
[key: string]: any
}

/**
* Migration component to handle the migration process
* It includes steps like selecting legacy CMS, configuring destination stack,
* mapping content fields, running test migration, and executing final migration.
*/
const Migration = () => {
const params: Params<string> = useParams();
const { projectId = '' } = useParams();
Expand Down Expand Up @@ -247,6 +252,7 @@ const Migration = () => {
// funcrion to form upload object from config response
const getFileInfo = (data: FileDetails) => {
const newMigrationDataObj = {
...newMigrationData?.legacy_cms?.uploadedFile,
name: data?.localPath,
url: data?.localPath,
isValidated: false,
Expand Down Expand Up @@ -353,7 +359,8 @@ const Migration = () => {
isLocalPath: projectData?.legacy_cms?.is_localPath
},
isValidated: projectData?.legacy_cms?.is_fileValid,
reValidate: newMigrationData?.legacy_cms?.uploadedFile?.reValidate
reValidate: newMigrationData?.legacy_cms?.uploadedFile?.reValidate,
buttonClicked: newMigrationData?.legacy_cms?.uploadedFile?.buttonClicked ? true : false,
} : uploadObj,
isFileFormatCheckboxChecked: true,
isRestictedKeywordCheckboxChecked: true,
Expand Down
4 changes: 2 additions & 2 deletions upload-api/migration-contentful/libs/contentTypeMapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const uidCorrector = (uid, affix) => {
newId = uid?.replace?.(uid, `${affix}_${uid}`);
newId = newId?.replace?.(/[^a-zA-Z0-9]+/g, '_');
}
return newId.replace(/([A-Z])/g, (match) => `_${match?.toLowerCase?.()}`);
return newId.replace(/([A-Z])/g, (match) => `${match?.toLowerCase?.()}`);
};

/**
Expand Down Expand Up @@ -319,7 +319,7 @@ const contentTypeMapper = (data, entries) => {
}
});
}
console.info('contentTypeRefs', contentTypeRefs, contentTypeUid);

return contentTypeRefs;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const uidCorrector = (uid, prefix) => {
newId = uid.replace(uid, `${prefix}_${uid}`);
newId = newId.replace(/[^a-zA-Z0-9]+/g, '_');
}
return newId.replace(/([A-Z])/g, (match) => `_${match.toLowerCase()}`);
return newId.replace(/([A-Z])/g, (match) => `${match.toLowerCase()}`);
};

/**
Expand Down