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
2 changes: 1 addition & 1 deletion api/src/utils/content-type-creator.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ const convertToSchemaFormate = ({ field, advanced = false, marketPlacePath, keyM
return {
"data_type": "global_field",
"display_name": field?.title,
"reference_to": field?.refrenceTo,
"reference_to": field?.refrenceTo ?? [],
"uid": cleanedUid,
"mandatory": field?.advanced?.mandatory ?? false,
"multiple": field?.advanced?.multiple ?? false,
Expand Down
6 changes: 3 additions & 3 deletions ui/src/components/AdvancePropertise/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ const AdvancePropertise = (props: SchemaProps) => {
referenedItems: props?.value?.referenedItems || []
});

const embedObjects = props?.value?.embedObjects?.map((item: string) => ({
const embedObjects = props?.value?.embedObjects?.map?.((item: string) => ({
label: item,
value: item
}));

const referencedItems = props?.data?.refrenceTo?.map((item: string) => ({
const referencedItems = props?.data?.refrenceTo?.map?.((item: string) => ({
label: item,
value: item
}));
Expand Down Expand Up @@ -690,7 +690,7 @@ const AdvancePropertise = (props: SchemaProps) => {
)}
</>
)}
{props?.fieldtype !== 'Global' && props?.fieldtype !== 'Boolean' && (
{props?.fieldtype !== 'Global Field' && props?.fieldtype !== 'Boolean' && (
<div className="ToggleWrap">
<ToggleSwitch
label="Mandatory"
Expand Down
52 changes: 23 additions & 29 deletions ui/src/components/ContentMapper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const Fields: MappingFields = {
options: {
'Single Line Textbox': 'single_line_text',
'Multi Line Textbox': 'multi_line_text',
'HTML Rich text Editor': 'html',
'HTML Rich Text Editor': 'html',
'JSON Rich Text Editor': 'json'
},
type: 'text'
Expand All @@ -88,7 +88,7 @@ const Fields: MappingFields = {
label: 'Multi Line Textbox',
options: {
'Multi Line Textbox': 'multi_line_text',
'HTML Rich text Editor': 'html',
'HTML Rich Text Editor': 'html',
'JSON Rich Text Editor': 'json'
},
type: 'multiline'
Expand All @@ -97,14 +97,14 @@ const Fields: MappingFields = {
label: 'JSON Rich Text Editor',
options: {
'JSON Rich Text Editor': 'json',
'HTML Rich text Editor': 'html'
'HTML Rich Text Editor': 'html'
},
type: 'json',
},
'html': {
label: 'HTML Rich text Editor',
label: 'HTML Rich Text Editor',
options: {
'HTML Rich text Editor': 'html',
'HTML Rich Text Editor': 'html',
'JSON Rich Text Editor': 'json'
},
type: 'allow_rich_text'
Expand All @@ -114,7 +114,7 @@ const Fields: MappingFields = {
label: 'Markdown',
options: {
'Markdown': 'markdown',
'HTML Rich text Editor': 'html',
'HTML Rich Text Editor': 'html',
'JSON Rich Text Editor': 'json'
},
type: 'markdown'
Expand Down Expand Up @@ -195,8 +195,8 @@ const Fields: MappingFields = {
type: ''
},
'global_field': {
label: 'Global',
options: { 'Global': 'global_field' },
label: 'Global Field',
options: { 'Global Field': 'global_field' },
type: ""
},
'group': {
Expand Down Expand Up @@ -310,6 +310,7 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
const navigate = useNavigate();

const filterRef = useRef<HTMLDivElement | null>(null);
const tableWrapperRef = useRef<HTMLDivElement | null>(null);

/********** ALL USEEFFECT HERE *************/
useEffect(() => {
Expand Down Expand Up @@ -345,7 +346,6 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:

useEffect(() => {
const mappedContentType = contentModels && contentModels?.find((item) => item?.uid === newMigrationData?.content_mapping?.content_type_mapping?.[selectedContentType?.contentstackUid || '']);
// if (contentTypeMapped && otherCmsTitle ) {

if (mappedContentType?.uid) {
setOtherContentType({
Expand Down Expand Up @@ -495,7 +495,7 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
return () => {
document.removeEventListener('click', handleClickOutside, true);
};
}, []);
}, []);

/**
* Debounces a function call by delaying its execution until after the specified delay has elapsed since the last invocation.
Expand Down Expand Up @@ -692,22 +692,6 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:

}, [otherContentType]);

// To dispatch the changed dropdown state
// useEffect(() => {
// const newMigrationDataObj: INewMigration = {
// ...newMigrationData,
// content_mapping: {
// ...newMigrationData?.content_mapping,
// isDropDownChanged: isDropDownChanged,
// content_type_mapping: [
// ...newMigrationData?.content_mapping?.content_type_mapping ?? [],
// ]
// }
// };

// dispatch(updateNewMigrationData((newMigrationDataObj)));
// }, [isDropDownChanged]);


useBlockNavigation(isModalOpen);
// Method to fetch content types
Expand Down Expand Up @@ -851,6 +835,16 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
};

const openContentType = (i: number) => {
// Reset scroll position to top immediately when switching content types
if (tableWrapperRef?.current) {
const elements = tableWrapperRef.current?.querySelectorAll('.Table__body');
elements?.forEach(el => {
if (el instanceof HTMLElement) {
el.scrollTop = 0;
}
});
}

setIsAllCheck(true);
setIsFieldDeleted(false);
setActive(i);
Expand Down Expand Up @@ -1632,7 +1626,7 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
'json': 'allow_rich_text',
'Multi-Line Text': 'multiline',
'multiline': 'multiline',
'HTML Rich text Editor': 'allow_rich_text',
'HTML Rich Text Editor': 'allow_rich_text',
'JSON Rich Text Editor': 'json',
'Rich Text': 'allow_rich_text',
'Group': 'Group',
Expand Down Expand Up @@ -1681,7 +1675,7 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:

const array = groupArray?.[0]?.child || []

if (value.data_type === 'group') {
if (value?.data_type === 'group') {
processSchema(value, data, array, groupArray, OptionsForRow, fieldsOfContentstack)
}
else if (!array?.some(item => item?.id === data?.id) && checkConditions(fieldTypeToMatch, value, data)) {
Expand Down Expand Up @@ -2623,7 +2617,7 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:

{/* Content Type Fields */}
<div className="content-types-fields-wrapper">
<div className="table-wrapper">
<div className="table-wrapper" ref={tableWrapperRef}>
<InfiniteScrollTable
loading={loading}
canSearch={true}
Expand Down
12 changes: 1 addition & 11 deletions ui/src/components/LegacyCms/Actions/LoadFileFormat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Icon, TextInput } from '@contentstack/venus-components';
import { useDispatch, useSelector } from 'react-redux';

// Utilities
import { isEmptyString } from '../../../utilities/functions';
import { isEmptyString, getFileExtension } from '../../../utilities/functions';

// Components
import { RootState } from '../../../store';
Expand All @@ -25,16 +25,6 @@ const LoadFileFormat = (_props: LoadFileFormatProps) => {

const [fileIcon, setFileIcon] = useState(newMigrationDataRef?.current?.legacy_cms?.selectedFileFormat?.title);

/**** ALL METHODS HERE ****/

const getFileExtension = (filePath: string): string => {
const normalizedPath = filePath?.replace(/\\/g, "/")?.replace(/\/$/, "");
const match = normalizedPath?.match(/\.([a-zA-Z0-9]+)$/);
const ext = match ? match?.[1]?.toLowerCase() : "";
const validExtensionRegex = /\.(pdf|zip|xml|json)$/i;
return ext && validExtensionRegex?.test(`.${ext}`) ? `${ext}` : '';
};

/**** ALL USEEffects HERE ****/
// Update ref whenever newMigrationData changes
useEffect(() => {
Expand Down
30 changes: 26 additions & 4 deletions ui/src/components/LegacyCms/Actions/LoadSelectCms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { getConfig } from '../../../services/api/upload.service';
import { isEmptyString, validateArray } from '../../../utilities/functions';

// Interface
import { defaultCardType } from '../../../components/Common/Card/card.interface';
import { defaultCardType, ICardType } from '../../../components/Common/Card/card.interface';
import { DEFAULT_CMS_TYPE, ICMSType, INewMigration } from '../../../context/app/app.interface';

// Components
Expand Down Expand Up @@ -102,11 +102,33 @@ const LoadSelectCms = (props: LoadSelectCmsProps) => {
);
setIsLoading(false);

const currentFormat = newMigrationData?.legacy_cms?.selectedFileFormat?.title;
// filteredCmsData?.forEach((data: ICMSType) => {
// // Check if filter returned any results and if the file format is not the same as the current format
// if (data?.allowed_file_formats?.some((format: ICardType) => format?.fileformat_id?.toLowerCase() !== currentFormat?.toLowerCase()) && filteredCmsData?.length > 0) {
// console.info('inside if', data);
// setIsError(true);
// setErrorMessage('Current file format is not supported for this CMS. Please add the correct CMS')
// } else if (data?.allowed_file_formats?.some((format: ICardType) => format?.fileformat_id?.toLowerCase() === currentFormat?.toLowerCase()) && filteredCmsData?.length > 0) {
// setIsError(false);
// }
// });


// Check if filter returned any results
if (filteredCmsData?.length > 0) {
setCmsData(filteredCmsData);
setIsError(false);
filteredCmsData?.forEach((data: ICMSType) => {
// Check if filter returned any results and if the file format is not the same as the current format
if (data?.allowed_file_formats?.some((format: ICardType) => format?.fileformat_id?.toLowerCase() !== currentFormat?.toLowerCase())) {
setIsError(true);
setErrorMessage('Current file format is not supported for this CMS. Please add the correct CMS');
setCmsData(filteredCmsData);
} else if (data?.allowed_file_formats?.some((format: ICardType) => format?.fileformat_id?.toLowerCase() === currentFormat?.toLowerCase())) {
setIsError(false);
setErrorMessage('');
setCmsData(filteredCmsData);
}
});
} else {
// cmstype is not empty but no matches found
setIsError(true);
Expand Down Expand Up @@ -171,7 +193,7 @@ const LoadSelectCms = (props: LoadSelectCmsProps) => {
onCardClick={data?.cms_id !== selectedCard?.cms_id ? handleCardClick : undefined}
selectedCard={selectedCard}
idField="cms_id"
disabled={newMigrationData?.project_current_step > 1}
disabled={newMigrationData?.project_current_step > 1 || isError}
/>
))}
</div>
Expand Down
8 changes: 8 additions & 0 deletions ui/src/utilities/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,11 @@ export const isValidPrefix = (data: string): boolean => {

return regEx.test(data);
};

export const getFileExtension = (filePath: string): string => {
const normalizedPath = filePath?.replace(/\\/g, "/")?.replace(/\/$/, "");
const match = normalizedPath?.match(/\.([a-zA-Z0-9]+)$/);
const ext = match ? match?.[1]?.toLowerCase() : "";
const validExtensionRegex = /\.(pdf|zip|xml|json)$/i;
return ext && validExtensionRegex?.test(`.${ext}`) ? `${ext}` : '';
};