Skip to content
Merged

Dev #231

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
2e63843
refactor:resolved eslint any warnings
AishDani Jul 31, 2024
9ac0dd8
refactor:removed console
AishDani Jul 31, 2024
52b2e7c
Merge pull request #225 from contentstack/bugfix/legacy-cms
RohitKini Jul 31, 2024
419bd9e
Added clearable option feature in the field dropdown for Existing stack
sayalijoshi27 Jul 31, 2024
7f3747c
Merge pull request #226 from contentstack/bugfix/content-mapper
RohitKini Jul 31, 2024
e38f5fe
[CMG-253] revised
sayalijoshi27 Aug 1, 2024
7ded172
Merge pull request #227 from contentstack/bugfix/content-mapper
RohitKini Aug 1, 2024
14084f9
refactor:When multiple groups are present and you select group 1 then…
AishDani Aug 5, 2024
8df5fa4
refactore:removed api call to send new created stack details to backend
AishDani Aug 5, 2024
177834c
Merge pull request #228 from contentstack/bugfix/legacy-cms
RohitKini Aug 5, 2024
c0f9228
SNYK errors resolved
sayalijoshi27 Aug 6, 2024
a569671
[CMG-281] - Content Mapper | When an existing stack is chosen or a ne…
sayalijoshi27 Aug 6, 2024
be71509
[CMG-282] - Content Mapper | LHS | On hover of Content type and Globa…
sayalijoshi27 Aug 6, 2024
6f900ef
refactor:content mapper bugs
AishDani Aug 6, 2024
b82bfa5
[CMG-283], [CMG-284]
sayalijoshi27 Aug 6, 2024
73a58c6
Merge pull request #229 from contentstack/bugfix/content-mapper
RohitKini Aug 6, 2024
1261c5b
refactor:resolved search issue of fields:[CMG-285]
AishDani Aug 6, 2024
9f56149
Merge branch 'dev' of github.com:contentstack/migration-v2-node-serve…
AishDani Aug 6, 2024
8a71453
refactor:resolved When search for Content type/Global fields, it does…
AishDani Aug 6, 2024
a8cd690
Merge pull request #230 from contentstack/bugfix/legacy-cms
RohitKini Aug 6, 2024
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
72 changes: 45 additions & 27 deletions api/src/services/contentMapper.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,12 @@ const getExistingContentTypes = async (req: Request) => {
* @throws ExceptionFunction if an error occurs while updating the content type.
*/
const updateContentType = async (req: Request) => {
const srcFun = "udateContentType";
const srcFun = "updateContentType";
const { orgId, projectId, contentTypeId } = req.params;
const { contentTypeData, token_payload } = req.body;
const fieldMapping = contentTypeData?.fieldMapping;

// const updatedContentType: any = {};

// Read project data
await ProjectModelLowdb.read();
const projectIndex = (await getProjectUtil(
projectId,
Expand All @@ -307,6 +306,7 @@ const updateContentType = async (req: Request) => {
)) as number;
const project = ProjectModelLowdb.data.projects[projectIndex];

// Check project status
if (
[NEW_PROJECT_STATUS[5], NEW_PROJECT_STATUS[4]].includes(project.status) ||
project.current_step < STEPPER_STEPS.CONTENT_MAPPING
Expand All @@ -318,24 +318,35 @@ const updateContentType = async (req: Request) => {
token_payload
)
);
throw new BadRequestError(HTTP_TEXTS.CANNOT_UPDATE_CONTENT_MAPPING);
return {
status: 400,
message: HTTP_TEXTS.CANNOT_UPDATE_CONTENT_MAPPING
};
}

// Validate contentTypeData
if (isEmpty(contentTypeData)) {
logger.error(
getLogMessage(
srcFun,
`${HTTP_TEXTS.INVALID_CONTENT_TYPE} Id: ${contentTypeId}`
)
);
throw new BadRequestError(HTTP_TEXTS.INVALID_CONTENT_TYPE);
return {
status: 400,
message: HTTP_TEXTS.INVALID_CONTENT_TYPE
};
}

try {
await ContentTypesMapperModelLowdb.read();
const updateIndex = ContentTypesMapperModelLowdb.chain
.get("ContentTypesMappers")
.findIndex({ id: contentTypeId, projectId: projectId })
.value();

if (fieldMapping) {
fieldMapping.forEach(async (field: any) => {
for (const field of fieldMapping) {
if (
!field.ContentstackFieldType ||
field.ContentstackFieldType === "" ||
Expand All @@ -351,25 +362,24 @@ const updateContentType = async (req: Request) => {
)}`
)
);
await ContentTypesMapperModelLowdb.read();
ContentTypesMapperModelLowdb.update((data: any) => {
data.ContentTypesMappers[updateIndex].status =
CONTENT_TYPE_STATUS[3];
await ContentTypesMapperModelLowdb.update((data: any) => {
data.ContentTypesMappers[updateIndex].status = CONTENT_TYPE_STATUS[3];
});
throw new BadRequestError(
`${VALIDATION_ERRORS.STRING_REQUIRED.replace(
return {
status: 400,
message: `${VALIDATION_ERRORS.STRING_REQUIRED.replace(
"$",
"ContentstackFieldType or contentstackFieldUid"
)}`
);
};
}
});
}
}

const updateIndex = ContentTypesMapperModelLowdb.chain
.get("ContentTypesMappers")
.findIndex({ id: contentTypeId, projectId: projectId })
.value();
// const updateIndex = ContentTypesMapperModelLowdb.chain
// .get("ContentTypesMappers")
// .findIndex({ id: contentTypeId, projectId: projectId })
// .value();
ContentTypesMapperModelLowdb.update((data: any) => {
if (updateIndex >= 0) {
data.ContentTypesMappers[updateIndex].otherCmsTitle =
Expand All @@ -394,12 +404,15 @@ const updateContentType = async (req: Request) => {
`${HTTP_TEXTS.CONTENT_TYPE_NOT_FOUND} Id: ${contentTypeId}`
)
);
throw new BadRequestError(HTTP_TEXTS.CONTENT_TYPE_NOT_FOUND);
return {
status: 404,
message: HTTP_TEXTS.CONTENT_TYPE_NOT_FOUND
};
}

if (!isEmpty(fieldMapping)) {
await FieldMapperModel.read();
(fieldMapping || []).forEach((field: any) => {
fieldMapping.forEach((field: any) => {
const fieldIndex = FieldMapperModel.data.field_mapper.findIndex(
(f: any) => f?.id === field?.id
);
Expand All @@ -411,18 +424,22 @@ const updateContentType = async (req: Request) => {
}
});
}
await ContentTypesMapperModelLowdb.read();
await ContentTypesMapperModelLowdb.update((data: any) => {
data.ContentTypesMappers[updateIndex].status = CONTENT_TYPE_STATUS[2];
});
// fetch updated data to return in response

// Fetch and return updated content type
await ContentTypesMapperModelLowdb.read();
const updatedContentType = ContentTypesMapperModelLowdb.chain
.get("ContentTypesMappers")
.find({ id: contentTypeId, projectId: projectId })
.value();

return { updatedContentType };
return {
status: 200,
data: { updatedContentType }
};

} catch (error: any) {
logger.error(
getLogMessage(
Expand All @@ -431,12 +448,13 @@ const updateContentType = async (req: Request) => {
error
)
);
throw new ExceptionFunction(
error?.message || HTTP_TEXTS.INTERNAL_ERROR,
error?.status || HTTP_CODES.SERVER_ERROR
);
return {
status: error?.status || 500,
message: error?.message || HTTP_TEXTS.INTERNAL_ERROR
};
}
};

/**
* Resets the field mapping and content mapping for a specific content type in a project.
*
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/Card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const CardList = ({ project }: ProjectType) => {
<div className="flex-v-center">
<Icon version="v2" icon="Clock" height="18" width="18" size='small' fill='none' stroke='#6E6B86' />
<span className="ProjectCard__modified-date">
{getDays(project?.updated_at)}
{project?.updated_at && getDays(project?.updated_at)}
</span>
</div>
</Tooltip>
Expand Down
6 changes: 3 additions & 3 deletions ui/src/components/Common/SaveChangesModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import {

interface Props {
closeModal: () => void;
isopen: any;
isopen: (flag: boolean) => void;
otherCmsTitle?: string;
saveContentType: () => void;
saveContentType?: () => void;
openContentType?: () => void;
changeStep?: () => void;
dropdownStateChange: () => void;
Expand Down Expand Up @@ -48,7 +48,7 @@ const SaveChangesModal = (props: Props) => {
</Button>
<Button version={"v2"} onClick={() => {
props?.dropdownStateChange();
props.saveContentType();
props?.saveContentType?.();
props.closeModal();
props.openContentType?.();
props?.changeStep?.();
Expand Down
5 changes: 5 additions & 0 deletions ui/src/components/ContentMapper/contentMapper.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,9 @@ export interface ContentTypeMap {
[key: string]: string;
}

export interface ContentTypeSaveHandles {
handleSaveContentType: () => void;
}
export type MouseOrKeyboardEvent = React.MouseEvent<HTMLElement, MouseEvent> | React.KeyboardEvent<HTMLButtonElement>;


76 changes: 41 additions & 35 deletions ui/src/components/ContentMapper/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -63,43 +63,47 @@
list-style-type: none;
padding: 15px 0 15px 0;
li {
align-items: center;
cursor: pointer;
display: flex;
font-size: $size-font-xl;
justify-content: space-between;
line-height: normal;
min-height: 42px;
padding: $px-8 $px-10 $px-8 $px-12;
&:hover, &.active-ct {
background-color: $color-brand-white-base;
.list-button {
align-items: center;
display: flex;
font-size: $size-font-xl;
justify-content: space-between;
line-height: normal;
min-height: 42px;
padding: $px-8 $px-10 $px-8 $px-12;

.cms-title {
align-items: center;
display: flex;
margin-right: $px-12;
max-height: 24px;
white-space: nowrap;
width: 70%;
.tippy-wrapper {
display: flex;
}
span {
color: $color-brand-primary-base;
color: $color-font-base;
margin-left: $px-10;
overflow: hidden;
text-overflow: ellipsis;
}
}
.ct-options {
justify-content: flex-end;
}
}
.cms-title {
align-items: center;
display: flex;
margin-right: $px-12;
max-height: 24px;
white-space: nowrap;
width: 80%;
.tippy-wrapper {
display: flex;
&:hover, &.active-ct {
button {
background-color: $color-brand-white-base;
}
span {
color: $color-font-base;
margin-left: $px-10;
overflow: hidden;
text-overflow: ellipsis;
.cms-title {
span {
color: $color-brand-primary-base;
}
}
}
.ct-options {
justify-content: flex-end;
}
}
}
}
.mapped-icon {
circle {
Expand Down Expand Up @@ -243,12 +247,14 @@ div .table-row {
top: $px-50;
z-index: 1;
li {
align-items: center;
cursor: pointer;
display: flex;
font-size: $size-font-medium;
justify-content: space-between;
padding: $px-8 $px-12;
button {
align-items: center;
display: flex;
justify-content: space-between;
font-size: $size-font-medium;
padding: $px-8 $px-12;
}

&:hover {
background-color: $color-base-white-10;
color: $color-brand-primary-base;
Expand Down
Loading