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 ui/src/components/Common/SaveChangesModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const SaveChangesModal = (props: Props) => {
className="text-capitalize"
/>
<ModalBody className="">
You have unsaved changes on content type <strong>{props?.otherCmsTitle || ''}</strong>. Save your changes if you don&apos;t want to lose them.
You have unsaved changes on content type <strong>{props?.otherCmsTitle ?? ''}</strong>. Save your changes if you don&apos;t want to lose them.
</ModalBody>
<ModalFooter>
<ButtonGroup>
Expand Down
85 changes: 46 additions & 39 deletions ui/src/components/ContentMapper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -790,8 +790,7 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re
if (field?.ContentstackFieldType === 'group') {
groupId = field?.uid;
data?.push({ ...field, child: [] });
} else {
if (field?.uid?.startsWith(groupId + '.')) {
} else if (field?.uid?.startsWith(groupId + '.')) {
const obj = data[data?.length - 1];
if (Object.hasOwn(obj, 'child')) {
obj?.child?.push(field);
Expand All @@ -801,7 +800,6 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re
} else {
data.push({ ...field, child: [] });
}
}
});
setNestedList(data);
}
Expand All @@ -821,7 +819,7 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re
data?.uid !== 'title') &&
(value?.uid !== 'url' &&
data?.uid !== 'url') &&
!fieldTypes.has(value?.data_type || '') &&
!fieldTypes.has(value?.data_type ?? '') &&
!value?.field_metadata?.multiline &&
!value?.enum &&
!value?.field_metadata?.allow_rich_text &&
Expand Down Expand Up @@ -1085,36 +1083,43 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re
option = [{ label: OptionsForEachRow, value: OptionsForEachRow }];
}

const OptionValue: FieldTypes =
OptionsForRow.length === 1 && (existingField[data?.uid] || updatedExstingField[data?.uid] ) &&
(OptionsForRow[0]?.value?.uid === 'url' || OptionsForRow[0]?.value?.uid === 'title' || OptionsForRow[0]?.value?.data_type === 'group' || OptionsForRow[0]?.value?.data_type === 'reference')
? {
label: OptionsForRow[0]?.value?.display_name,
value: OptionsForRow[0]?.value,
isDisabled: true
}
: (OptionsForRow.length === 0 || (OptionsForRow.length > 0 && OptionsForRow.every((item)=>item.isDisabled)
&& (!existingField[data?.uid] || ! updatedExstingField[data?.uid] ) ))
? {
label: dummy_obj[data?.ContentstackFieldType]?.label,
value: dummy_obj[data?.ContentstackFieldType]?.label,
isDisabled: data?.ContentstackFieldType === 'text' ||
data?.ContentstackFieldType === 'group' ||
data?.ContentstackFieldType === 'url' ||
data?.otherCmsType === "reference"
}
: {
label: `${selectedOption} matches`,
value: `${selectedOption} matches`,
isDisabled: false
};

const adjustedOptions = (OptionsForRow.length === 0 && !contentTypeSchema) ? option :
(OptionsForRow.length > 0 && OptionsForRow.every((item)=>item.isDisabled) && OptionValue.label === dummy_obj[data?.ContentstackFieldType]?.label) ? []
: OptionsForRow.map((option: OptionsType) => ({
let OptionValue: FieldTypes;
if (OptionsForRow.length === 1 && (existingField[data?.uid] || updatedExstingField[data?.uid] ) &&
(OptionsForRow[0]?.value?.uid === 'url' || OptionsForRow[0]?.value?.uid === 'title' || OptionsForRow[0]?.value?.data_type === 'group' || OptionsForRow[0]?.value?.data_type === 'reference')) {
OptionValue = {
label: OptionsForRow[0]?.value?.display_name,
value: OptionsForRow[0]?.value,
isDisabled: true
}
} else if ((OptionsForRow.length === 0 || (OptionsForRow.length > 0 && OptionsForRow.every((item)=>item.isDisabled) && (!existingField[data?.uid] || ! updatedExstingField[data?.uid] ) ))) {
OptionValue = {
label: dummy_obj[data?.ContentstackFieldType]?.label,
value: dummy_obj[data?.ContentstackFieldType]?.label,
isDisabled: data?.ContentstackFieldType === 'text' ||
data?.ContentstackFieldType === 'group' ||
data?.ContentstackFieldType === 'url' ||
data?.otherCmsType === "reference"
}
} else {
OptionValue = {
label: `${selectedOption} matches`,
value: `${selectedOption} matches`,
isDisabled: false
};
}

let optionResult: OptionsType[];

if (OptionsForRow.length > 0 && OptionsForRow.every((item)=>item.isDisabled) && OptionValue.label === dummy_obj[data?.ContentstackFieldType]?.label) {
optionResult = []
} else {
optionResult = OptionsForRow.map((option: OptionsType) => ({
...option,
isDisabled: selectedOptions.includes(option?.label ?? '')
}));
}

const adjustedOptions = (OptionsForRow.length === 0 && !contentTypeSchema) ? option : optionResult;

return (
<div className="table-row">
Expand Down Expand Up @@ -1153,7 +1158,7 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re

useEffect(() => {
if (isUpdated) {
setTableData(updatedRows as FieldMapType[]);
setTableData(updatedRows);
setExistingField(updatedExstingField);
setSelectedOptions(updatedSelectedOptions);
setSelectedEntries(updatedRows);
Expand Down Expand Up @@ -1284,10 +1289,9 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re
const { status } = await resetToInitialMapping(
orgId,
projectID,
selectedContentType?.id || '',
selectedContentType?.id ?? '',
dataCs
);
//setOtherContentType();
setExistingField({});
setContentTypeSchema([]);
setContentTypeMapped({});
Expand Down Expand Up @@ -1316,14 +1320,17 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re
type: 'error'
});
} else {
const { data } = await fetchExistingContentType(projectId, otherContentType?.id || '');
const { data } = await fetchExistingContentType(projectId, otherContentType?.id ?? '');

const index = contentTypesList.findIndex(ct => ct?.uid === data?.uid);
if(index != -1){
contentTypesList[index] = data;

const contentTypesArr: ContentTypeList[] = contentTypesList;

if(index != -1) {
contentTypesArr[index] = data;
}

setContentTypesList(contentTypesList)
setContentTypesList(contentTypesArr);
setContentTypeSchema(data?.schema)
}
}
Expand Down Expand Up @@ -1590,7 +1597,7 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re
rowSelectCheckboxProp={{ key: '_canSelect', value: true }}
name={{
singular: '',
plural: `${totalCounts === 0 ? `Count` : ''}`
plural: `${totalCounts === 0 ? 'Count' : ''}`
}}
/>
<div className='text-end my-3 mx-3 px-1'>
Expand Down
10 changes: 4 additions & 6 deletions ui/src/components/SchemaModal/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
display: flex;
justify-content: flex-start;
padding: 0;
text-align: left;
&:hover {
.title {
.field-title {
color: $color-brand-primary-base;
}
.icons {
Expand Down Expand Up @@ -63,7 +64,7 @@
}
}
}
& > .title {
& > .field-title {
color: $color-brand-primary-base;
font-weight: $font-weight-semi-bold;
}
Expand All @@ -75,12 +76,9 @@
font-weight: $font-weight-regular;
line-height: $line-height-reset !important;
opacity: 1;
overflow: hidden;
padding: 0.625rem 0;
text-overflow: ellipsis;
text-transform: capitalize;
transition: opacity 0.5s linear, width 300ms linear;
white-space: nowrap;
width: 12.5rem;
}
.icons {
Expand All @@ -103,7 +101,7 @@
}
}
& > ul {
padding-left: 0.125rem;
padding-left: 1.125rem;
& > li {
& > ul {
padding-left: 1.5625rem;
Expand Down
41 changes: 16 additions & 25 deletions ui/src/components/SchemaModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ const getTopLevelIcons = (field: FieldMapType) => {
experience_container: 'PersonalizationLogoGreySmall'
};

if (field?.ContentstackFieldType === 'Single Line Textbox') {
if (field?.ContentstackFieldType === 'Single Line Textbox' || field?.ContentstackFieldType === 'single_line_text') {
return icons['title'];
}

if (field?.ContentstackFieldType === 'URL' || field?.ContentstackFieldType === 'single_line_text') {
if (field?.ContentstackFieldType === 'URL' || field?.ContentstackFieldType === 'url') {
return icons['text'];
}

Expand All @@ -54,11 +54,11 @@ const getTopLevelIcons = (field: FieldMapType) => {
return icons['isodate'];
}

if (field?.ContentstackFieldType === 'Multi Line Textbox') {
if (field?.ContentstackFieldType === 'Multi Line Textbox' || field?.ContentstackFieldType === 'multi_line_text') {
return icons['multitext'];
}

if (field?.ContentstackFieldType === 'HTML Rich text Editor') {
if (field?.ContentstackFieldType === 'HTML Rich text Editor' || field?.ContentstackFieldType === 'html') {
return icons['rte'];
}

Expand All @@ -77,7 +77,7 @@ const getTopLevelIcons = (field: FieldMapType) => {
return icons['boolean'];
}

if (field?.ContentstackFieldType === 'Reference') {
if (field?.ContentstackFieldType === 'Reference' || field?.ContentstackFieldType === 'refernce') {
return icons['reference'];
}

Expand All @@ -98,24 +98,22 @@ const TreeView = ({ schema = [] }: schemaType) => {
if (field?.ContentstackFieldType === 'group') {
groupId = field?.uid;
data?.push({ ...field, child: [] });
} else {
if (field?.uid?.startsWith(groupId + '.')) {
} else if (field?.uid?.startsWith(groupId + '.')) {
const obj = data[data?.length - 1];
if (Object.prototype.hasOwnProperty.call(obj, 'child')) {
if (Object.hasOwn(obj, 'child')) {
obj?.child?.push(field);
} else {
obj.child = [field];
}
} else {
data.push({ ...field, child: [] });
}
}
});
setNestedList(data);
}, [schema]);

// Check if schema is nested
const hasNestedValue = (field: FieldMapType) => field && field?.child && field?.child?.length > 0;
const hasNestedValue = (field: FieldMapType) => field?.child && field?.child?.length > 0;

// Remove Group name from its child
const getChildFieldName = (text?: string, groupName?: string) => {
Expand Down Expand Up @@ -147,22 +145,22 @@ const TreeView = ({ schema = [] }: schemaType) => {

const generateNestedOutline = (item: FieldMapType, index: number) => {
return (
<ul className={item && item?.child && item?.child?.length > 0 ? '' : 'close'}>
<ul className={item?.child && item?.child?.length > 0 ? '' : 'close'}>
{item?.child?.map((field: FieldMapType, nestedIndex: number) => {
let fieldname = '';
if (field?.uid) {
fieldname = field?.uid?.replace(/\.+/g, '_');
}
return (
<li key={`${field?.otherCmsField}${field?.ContentstackFieldType}`}>
<div
<button
data-outlinename={fieldname}
onClick={(e: React.MouseEvent<HTMLElement>) => {
e.preventDefault();
e.stopPropagation();
handleClick(e);
}}
className={`iconsholder`}
className={`iconsholder list-button`}
>
<span className="icons">
{hasNestedValue(field) && (
Expand All @@ -173,7 +171,7 @@ const TreeView = ({ schema = [] }: schemaType) => {
<span className="field-title">
{getChildFieldName(field?.otherCmsField, item?.otherCmsField)}
</span>
</div>
</button>

{hasNestedValue(field) && generateNestedOutline(field, nestedIndex)}
</li>
Expand All @@ -200,28 +198,21 @@ const TreeView = ({ schema = [] }: schemaType) => {
key={`${item?.otherCmsField}${item?.ContentstackFieldType}`}
className={`${hasNested ? 'nested-child' : ''}`}
>
<div
<button
data-outlinename={outlineName}
className={`iconsholder`}
className={`iconsholder list-button`}
onClick={(e: React.MouseEvent<HTMLElement>) => {
e.preventDefault();
e.stopPropagation();
handleClick(e);
}}
>
<span
className={`icons ${hasNested ? 'nested' : ''}`}
onMouseOver={() => {
document
?.querySelector('.PageLayout__leftSidebar')
?.classList.add('hovered');
}}
>
<span className={`icons ${hasNested ? 'nested' : ''}`}>
{hasNested && <Icon className={'chevron'} icon="ChevronExtraSmall" />}
<Icon className={'fieldicon'} icon={getTopLevelIcons(item) as string} />
</span>
<span className={`field-title`}>{item?.otherCmsField}</span>
</div>
</button>
{hasNested && generateNestedOutline(item, index)}
</li>
);
Expand Down
Loading