Skip to content
Merged

Dev #117

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
20 changes: 10 additions & 10 deletions api/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ export const HTTP_TEXTS = {
"Reseting the content mapping is restricted. Please verify the status and review preceding actions.",
CONTENTMAPPER_NOT_FOUND:
"Sorry, the requested content mapper id does not exists.",
ADMIN_LOGIN_ERROR:
"Sorry, You Don't have admin access in any of the Organisation"
ADMIN_LOGIN_ERROR:
"Sorry, You Don't have admin access in any of the Organisation",
};

export const HTTP_RESPONSE_HEADERS = {
Expand Down Expand Up @@ -127,11 +127,11 @@ export const PREDEFINED_STATUS = [
export const PREDEFINED_STEPS = [1, 2, 3, 4, 5];

export const NEW_PROJECT_STATUS = {
0: 0, //DRAFT
1: 1, //READY_TO_TEST
2: 2, //TESTING_IN_PROGRESS
3: 3, //READY_FOR_MIGRATION
4: 4, //MIGRATION_IN_PROGRESS
5: 5, //MIGRATION_SUCCESSFUL
6: 6 //MIGRATION_TERMINATED
};
0: 0, //DRAFT
1: 1, //READY_TO_TEST
2: 2, //TESTING_IN_PROGRESS
3: 3, //READY_FOR_MIGRATION
4: 4, //MIGRATION_IN_PROGRESS
5: 5, //MIGRATION_SUCCESSFUL
6: 6, //MIGRATION_TERMINATED
};
9 changes: 9 additions & 0 deletions api/src/controllers/projects.contentMapper.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ const resetContentType = async (req: Request, res: Response): Promise<void> => {
// res.status(200).json(resp);
// };

const getSingleContentTypes = async (
req: Request,
res: Response
): Promise<void> => {
const resp = await contentMapperService.getSingleContentTypes(req);
res.status(201).json(resp);
};

export const contentMapperController = {
getContentTypes,
getFieldMapping,
Expand All @@ -45,4 +53,5 @@ export const contentMapperController = {
putContentTypeFields,
resetContentType,
// removeMapping,
getSingleContentTypes
};
1 change: 0 additions & 1 deletion api/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const connectToDatabase = async () => {
fs.mkdirSync("./database");
}
logger.info("successfully connecting to Low DB");

} catch (error) {
logger.error("Error while connecting to Low DB:", error);
process.exit(1);
Expand Down
12 changes: 6 additions & 6 deletions api/src/models/FieldMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { JSONFile } from "lowdb/node";
import LowWithLodash from "../utils/lowdb-lodash.utils.js";

interface Advanced {
validationRegex: string,
Mandatory:boolean,
Multiple:boolean,
Unique:boolean,
NonLocalizable:boolean
validationRegex: string;
Mandatory: boolean;
Multiple: boolean;
Unique: boolean;
NonLocalizable: boolean;
}

interface FieldMapper {
Expand All @@ -21,7 +21,7 @@ interface FieldMapper {
isDeleted: boolean;
backupFieldType: string;
refrenceTo: { uid: string; title: string };
advanced:Advanced
advanced: Advanced;
}[];
}

Expand Down
6 changes: 6 additions & 0 deletions api/src/routes/contentMapper.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,11 @@ router.put(
"/resetFields/:orgId/:projectId/:contentTypeId",
asyncRouter(contentMapperController.resetContentType)
);
//get Single contenttype data
router.get(
"/:projectId/:contentTypeUid",
asyncRouter(contentMapperController.getSingleContentTypes)
);


export default router;
47 changes: 44 additions & 3 deletions api/src/services/contentMapper.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
HTTP_TEXTS,
HTTP_CODES,
STEPPER_STEPS,
NEW_PROJECT_STATUS
NEW_PROJECT_STATUS,
} from "../constants/index.js";
import logger from "../utils/logger.js";
import { config } from "../config/index.js";
Expand Down Expand Up @@ -256,8 +256,7 @@ const updateContentType = async (req: Request) => {
NEW_PROJECT_STATUS[4],
].includes(project.status) ||
project.current_step < STEPPER_STEPS.CONTENT_MAPPING
)
{
) {
logger.error(
getLogMessage(
srcFun,
Expand Down Expand Up @@ -635,6 +634,47 @@ const removeMapping = async (projectId: string) => {
);
}
};
const getSingleContentTypes = async (req: Request) => {
const projectId = req?.params?.projectId;
const contentTypeUID = req?.params?.contentTypeUid;
const { token_payload } = req.body;

const authtoken = await getAuthtoken(
token_payload?.region,
token_payload?.user_id
);
await ProjectModelLowdb.read();
const project = ProjectModelLowdb.chain
.get("projects")
.find({ id: projectId })
.value();
const stackId = project?.destination_stack_id;

const [err, res] = await safePromise(
https({
method: "GET",
url: `${config.CS_API[
token_payload?.region as keyof typeof config.CS_API
]!}/content_types/${contentTypeUID}`,
headers: {
api_key: stackId,
authtoken: authtoken,
},
})
);

if (err)
return {
data: err.response.data,
status: err.response.status,
};

return {
title: res?.data?.content_type?.title,
uid: res?.data?.content_type?.uid,
schema: res?.data?.content_type?.schema,
};
};

export const contentMapperService = {
putTestData,
Expand All @@ -645,4 +685,5 @@ export const contentMapperService = {
resetToInitialMapping,
resetAllContentTypesMapping,
removeMapping,
getSingleContentTypes
};
14 changes: 7 additions & 7 deletions api/src/services/org.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,19 +312,19 @@ const getStackLocal = async (token_payload: any, data: any) => {
status: err.response.status,
};
}
let localesArr:any =[]
res?.data?.locales.map((lang:any)=>{
let localesArr: any = [];
res?.data?.locales.map((lang: any) => {
return localesArr.push({
code:lang.code,
name:lang.name
})
})
code: lang.code,
name: lang.name,
});
});

let obj = {
name: stack.name,
api_key: stack.api_key,
master_locale: stack.master_locale,
locales: localesArr
locales: localesArr,
};
stacks.push(obj);
}
Expand Down
10 changes: 5 additions & 5 deletions api/src/services/projects.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
HTTP_TEXTS,
HTTP_CODES,
STEPPER_STEPS,
NEW_PROJECT_STATUS
NEW_PROJECT_STATUS,
} from "../constants/index.js";
import { config } from "../config/index.js";
import { getLogMessage, safePromise } from "../utils/index.js";
Expand Down Expand Up @@ -479,8 +479,8 @@ const updateDestinationStack = async (req: Request) => {
);

if (
project.status === NEW_PROJECT_STATUS[4] ||
project.status === NEW_PROJECT_STATUS[5] ||
project.status === NEW_PROJECT_STATUS[4] ||
project.status === NEW_PROJECT_STATUS[5] ||
project.current_step < STEPPER_STEPS.DESTINATION_STACK
) {
logger.error(
Expand Down Expand Up @@ -531,7 +531,7 @@ const updateDestinationStack = async (req: Request) => {
data.projects[projectIndex].destination_stack_id = stack_api_key;
data.projects[projectIndex].current_step =
STEPPER_STEPS.DESTINATION_STACK;
data.projects[projectIndex].status = NEW_PROJECT_STATUS[0];
data.projects[projectIndex].status = NEW_PROJECT_STATUS[0];
data.projects[projectIndex].updated_at = new Date().toISOString();
});

Expand Down Expand Up @@ -590,7 +590,7 @@ const updateCurrentStep = async (req: Request) => {

switch (project.current_step) {
case STEPPER_STEPS.LEGACY_CMS: {
if (project.status !== NEW_PROJECT_STATUS[0] || !isStepCompleted) {
if (project.status !== NEW_PROJECT_STATUS[0] || !isStepCompleted) {
logger.error(
getLogMessage(
srcFunc,
Expand Down
2 changes: 0 additions & 2 deletions api/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

export const throwError = (message: string, statusCode: number) => {
throw Object.assign(new Error(message), { statusCode });
};
Expand Down Expand Up @@ -26,4 +25,3 @@ export const getLogMessage = (
...(error && { error }),
};
};

12 changes: 7 additions & 5 deletions ui/src/components/ContentMapper/contentMapper.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface ContentstackFields {
export interface FieldTypes {
label: string;
value: any;
id?: string;
}
export interface TableTypes {
sortBy: any;
Expand Down Expand Up @@ -76,16 +77,16 @@ export interface FieldMetadata {
allow_rich_text?: boolean;
markdown?: boolean;
}
export interface ContentTypeField {
export interface ContentTypesSchema {
uid?: string;
display_name?: string;
data_type?: 'text' | 'number' | 'isodate' | 'json' | 'file';
field_metadata?: FieldMetadata;
enum?: any;
}
export interface ContentTypesSchema {
[key: string]: ContentTypeField;
}
// export interface ContentTypesSchema {
// [key: string]: ContentTypeField;
// }

export type ExistingFieldType = {
[key: string]: FieldTypes | undefined;
Expand All @@ -96,7 +97,8 @@ export interface Mapping {
}
export interface ContentTypeList {
title: string;
schema: [];
schema: ContentTypesSchema[];
uid: string;
}

export interface optionsType {
Expand Down
19 changes: 13 additions & 6 deletions ui/src/components/ContentMapper/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
@import '../../scss/variables';

.content-types-list-wrapper {
max-height: calc(100vh - 7.25rem);
max-width: 27%;
overflow: hidden;
width: 100%;
}
.content-types-list-header {
Expand All @@ -17,8 +19,11 @@
}
}
.ct-list {
height: 100%;
list-style-type: none;
margin: 5px 15px 0;
margin: 15px 0;
overflow-y: auto;
overflow-x: hidden;
li {
align-items: center;
border: 1px solid transparent;
Expand All @@ -41,17 +46,15 @@
}
.content-types-fields-wrapper {
border-left: 1px solid $color-brand-secondary-lightest;
display: flex;
flex-direction: column;
max-width: 73%;
width: 100%;
padding: 0px;
}
.cta-wrapper {
border-top: 1px solid $color-base-gray-40;
flex: 1 0 auto;
// bottom: 0;
padding: $space-12 $space-24 $space-12 $space-12;
// position: fixed;
// right: 0;
text-align: right;
width: 100%;
z-index: 1;
Expand All @@ -61,6 +64,7 @@
flex: 1 0 auto;
}
.table-wrapper {
flex: 1;
.Table {
min-height: inherit;
.Table__body__column {
Expand All @@ -83,12 +87,15 @@
justify-content: space-between;
padding: 12px;
}
.action-component-body {
display: flex;
}
.step-container {
display: flex;
flex-direction: column;
margin-top: 0;
margin-left: 0px;
margin-bottom: 20px;
// margin-bottom: 20px;
width: 100%;
}
.saveButton {
Expand Down
Loading