Skip to content

Commit 7c1bb55

Browse files
authored
Merge pull request #418 from contentstack/dev
Dev
2 parents 781cb61 + b3bda76 commit 7c1bb55

File tree

28 files changed

+445
-180
lines changed

28 files changed

+445
-180
lines changed

api/src/controllers/projects.controller.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ const updateMigrationExecution = async (req: Request, res: Response): Promise<vo
171171
res.status(project.status).json(project);
172172
}
173173

174+
const getMigratedStacks = async (req: Request, res: Response): Promise<void> => {
175+
const project = await projectService.getMigratedStacks(req);
176+
res.status(project.status).json(project);
177+
}
178+
174179
export const projectController = {
175180
getAllProjects,
176181
getProject,
@@ -187,4 +192,5 @@ export const projectController = {
187192
revertProject,
188193
updateStackDetails,
189194
updateMigrationExecution,
195+
getMigratedStacks,
190196
};

api/src/routes/projects.routes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,6 @@ router.patch("/:projectId/stack-details", asyncRouter(projectController.updateSt
8080
//update migration execution key
8181
router.put("/:projectId/migration-excution",asyncRouter(projectController.updateMigrationExecution));
8282

83+
router.get("/:projectId/get-migrated-stacks", asyncRouter(projectController.getMigratedStacks))
84+
8385
export default router;

api/src/services/contentMapper.service.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -292,19 +292,12 @@ const getExistingContentTypes = async (req: Request) => {
292292
headers,
293293
})
294294
);
295-
296-
if (err) {
297-
throw new Error(
298-
`Error fetching selected content type: ${
299-
err.response?.data || err.message
300-
}`
301-
);
302-
}
295+
303296

304297
selectedContentType = {
305-
title: res.data.content_type?.title,
306-
uid: res.data.content_type?.uid,
307-
schema: res.data.content_type?.schema,
298+
title: res?.data?.content_type?.title,
299+
uid: res?.data?.content_type?.uid,
300+
schema: res?.data?.content_type?.schema,
308301
};
309302
}
310303
return {
@@ -314,7 +307,7 @@ const getExistingContentTypes = async (req: Request) => {
314307
} catch (error: any) {
315308
return {
316309
data: error.message,
317-
status: 500,
310+
status: error.status || 500,
318311
};
319312
}
320313
};

api/src/services/projects.service.ts

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,51 @@ const updateMigrationExecution = async (req: Request) => {
12121212
};
12131213

12141214

1215+
/**
1216+
* get the destination_stack_id of completed projects.
1217+
*
1218+
* @param req - The request object containing the parameters and body.
1219+
* @returns An object with the status and data of the update operation.
1220+
* @throws ExceptionFunction if an error occurs during the process.
1221+
*/
1222+
const getMigratedStacks = async(req: Request) => {
1223+
1224+
const { token_payload } = req.body;
1225+
const srcFunc = "getMigratedStacks";
1226+
1227+
try {
1228+
await ProjectModelLowdb.read();
1229+
const projects = ProjectModelLowdb.data?.projects || [];
1230+
1231+
// Map through projects to extract `destinationstack` key
1232+
const destinationStacks = projects.filter((project: any) => project?.status === 5 && project.current_step === 5)
1233+
.map((project: any) => project.destination_stack_id);
1234+
1235+
return {
1236+
status: HTTP_CODES.OK,
1237+
destinationStacks
1238+
};
1239+
1240+
} catch (error:any) {
1241+
// Log error message
1242+
logger.error(
1243+
getLogMessage(
1244+
srcFunc,
1245+
"Error occurred while while getting all destinationstack id's of projects",
1246+
token_payload,
1247+
error
1248+
)
1249+
);
1250+
1251+
// Throw a custom exception with the error details
1252+
throw new ExceptionFunction(
1253+
error?.message || HTTP_TEXTS.INTERNAL_ERROR,
1254+
error?.statusCode || error?.status || HTTP_CODES.SERVER_ERROR
1255+
);
1256+
1257+
}
1258+
1259+
}
12151260

12161261
export const projectService = {
12171262
getAllProjects,
@@ -1229,5 +1274,6 @@ export const projectService = {
12291274
revertProject,
12301275
updateStackDetails,
12311276
updateContentMapper,
1232-
updateMigrationExecution
1277+
updateMigrationExecution,
1278+
getMigratedStacks
12331279
};

api/src/utils/content-type-creator.utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ const convertToSchemaFormate = ({ field, advanced = true }: any) => {
192192
"unique": field?.advanced?.unique ?? false,
193193
"non_localizable": field.advanced?.nonLocalizable ?? false
194194
};
195-
data.field_metadata.default_value = field?.advanced?.default_value ?? null;
195+
const default_value = field?.advanced?.options?.length ? (field?.advanced?.options?.find((item: any) => (item?.key === field?.advanced?.default_value) || (item?.key === field?.advanced?.default_value))) : { value: field?.advanced?.default_value };
196+
data.field_metadata.default_value = default_value?.value ?? null;
196197
return data;
197198
}
198199
case 'radio': {

api/src/utils/test-folder-creator.utils.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ const {
1010
ASSETS_SCHEMA_FILE,
1111
CONTENT_TYPES_DIR_NAME,
1212
CONTENT_TYPES_SCHEMA_FILE,
13-
ENTRIES_MASTER_FILE
13+
ENTRIES_MASTER_FILE,
14+
GLOBAL_FIELDS_DIR_NAME,
15+
GLOBAL_FIELDS_FILE_NAME
1416
} = MIGRATION_DATA_CONFIG;
1517

1618

@@ -201,10 +203,41 @@ const sortAssets = async (baseDir: string) => {
201203
await fs.promises.writeFile(path.join(assetsPath, ASSETS_SCHEMA_FILE), JSON?.stringify?.(assetsMeta));
202204
}
203205

206+
const writeGlobalField = async (schema: any, globalSave: string, filePath: string) => {
207+
try {
208+
await fs.promises.access(globalSave);
209+
} catch (err) {
210+
try {
211+
await fs.promises.mkdir(globalSave, { recursive: true });
212+
} catch (mkdirErr) {
213+
console.error("🚀 ~ fs.mkdir ~ err:", mkdirErr);
214+
return;
215+
}
216+
}
217+
try {
218+
await fs.promises.writeFile(filePath, JSON.stringify(schema, null, 2));
219+
} catch (writeErr) {
220+
console.error("🚀 ~ fs.writeFile ~ err:", writeErr);
221+
}
222+
};
223+
224+
const sortGlobalField = async (baseDir: string, finalData: any) => {
225+
const globalSave = path.join(process.cwd(), baseDir, GLOBAL_FIELDS_DIR_NAME);
226+
const globalPath = path.join(globalSave, GLOBAL_FIELDS_FILE_NAME);
227+
const globalData = await JSON.parse(await fs.promises.readFile(globalPath, 'utf8'));
228+
const globalResult = [];
229+
for await (const ct of globalData) {
230+
await lookForReference(ct, finalData);
231+
globalResult?.push(ct);
232+
}
233+
await writeGlobalField(globalResult, globalPath, globalPath);
234+
}
235+
204236
const sortContentType = async (baseDir: string, finalData: any) => {
205237
const contentTypePath: string = path.join(process.cwd(), baseDir, CONTENT_TYPES_DIR_NAME);
206238
const contentSave = path.join(baseDir, CONTENT_TYPES_DIR_NAME);
207239
const ctData = await JSON.parse(await fs.promises.readFile(path.join(contentTypePath, CONTENT_TYPES_SCHEMA_FILE), 'utf8'));
240+
await sortGlobalField(baseDir, finalData);
208241
const contentTypes: any = [];
209242
for await (const ct of finalData) {
210243
const findCtData = ctData?.find((ele: any) => ele?.uid === ct?.contentType);
@@ -218,6 +251,7 @@ const sortContentType = async (baseDir: string, finalData: any) => {
218251
}
219252

220253

254+
221255
export const testFolderCreator = async ({ destinationStackId }: any) => {
222256
const sanitizedStackId = path.basename(destinationStackId);
223257
const baseDir = path.join(MIGRATION_DATA_CONFIG.DATA, sanitizedStackId);

ui/src/components/AdvancePropertise/index.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ import {
1717
// Service
1818
import { getContentTypes } from '../../services/api/migration.service';
1919

20+
// Utilities
21+
import { validateArray } from '../../utilities/functions';
22+
2023
// Interfaces
2124
import { optionsType, SchemaProps } from './advanceProperties.interface';
2225
import { ContentType } from '../ContentMapper/contentMapper.interface';
@@ -330,9 +333,11 @@ const AdvancePropertise = (props: SchemaProps) => {
330333
}, [ctValue]);
331334

332335
// Option for content types
333-
const option = Array.isArray(contentTypes)
334-
? contentTypes.map((option) => ({ label: option?.contentstackTitle, value: option?.contentstackUid }))
335-
: [{ label: contentTypes, value: contentTypes }];
336+
const contentTypesList = contentTypes?.filter((ct: ContentType) => ct?.type === "content_type");
337+
338+
const option = validateArray(contentTypesList)
339+
? contentTypesList?.map((option: ContentType) => ({ label: option?.contentstackTitle, value: option?.contentstackUid }))
340+
: [{ label: contentTypesList, value: contentTypesList }];
336341

337342
return (
338343
<>

ui/src/components/Common/Card/card.interface.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export interface ICardType {
2626
* The file format ID of the card.
2727
*/
2828
fileformat_id?: string;
29+
30+
[key: string]: any;
2931
}
3032

3133
/**

ui/src/components/Common/Card/card.scss

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,17 @@
7676
* @cssproperty box-shadow - The box shadow effect to apply.
7777
* @cssvalue 0 3px $px-5 $px-2 rgb(215 215 215) - The specific box shadow values.
7878
*/
79-
.connector_list:hover {
79+
.connector_list:hover {
8080
box-shadow: 0 3px $px-5 $px-2 rgb(215 215 215);
8181
}
8282

83+
.connector_list.disabled-card {
84+
&:hover {
85+
box-shadow: none;
86+
cursor: not-allowed;
87+
}
88+
}
89+
8390
/**
8491
* Styles for the service icon in the card component.
8592
*
@@ -148,4 +155,8 @@
148155
p {
149156
color: $color-stepper-title;
150157
}
158+
}
159+
.Card__disabled{
160+
cursor: not-allowed;
161+
opacity: .5;
151162
}

ui/src/components/Common/Card/card.tsx

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
1+
// Libraries
12
import { Icon, Paragraph, Radio, Tooltip } from '@contentstack/venus-components';
23
import { MouseEvent, useState } from 'react';
3-
import WordWrapper from '../WordWrapper/WordWrapper';
4-
import { addDomainInPath } from '../../../utilities/functions';
4+
import { useSelector } from 'react-redux';
55

6+
// Redux Store
7+
import { RootState } from '../../../store';
8+
9+
// Interface
10+
import { ICardType } from './card.interface';
11+
12+
// CSS
613
import './card.scss';
714

815
/**
916
* Props for the Card component.
1017
*/
1118
type CardProps = {
12-
data: any;
19+
data: ICardType;
1320
idField?: string;
1421
onCardClick?: (T: any) => unknown;
15-
selectedCard: any;
22+
selectedCard: ICardType;
1623
cardType?: string;
24+
disabled: boolean;
1725
};
1826

1927
/**
@@ -25,35 +33,37 @@ type CardProps = {
2533
* @param cardType - The type of the card.
2634
* @param idField - The field name for the card's ID. Defaults to 'id'.
2735
*/
28-
const Card = ({ data, selectedCard, onCardClick, cardType, idField = 'id' }: CardProps) => {
29-
const imgStyle = {
30-
width: cardType === 'legacyCMS' ? '60px' : '46px',
31-
height: cardType === 'legacyCMS' ? '60px' : '46px'
32-
};
36+
const Card = ({ data, selectedCard, onCardClick, cardType, idField = 'id',disabled }: CardProps) => {
3337
const [isHovered, setIsHovered] = useState(false);
3438

39+
const newMigrationData = useSelector((state:RootState)=>state?.migration?.newMigrationData);
40+
3541
const handleMouseEnter = () => {
36-
if (selectedCard[idField] === data?.[idField]) {
37-
setIsHovered(true);
38-
}
42+
if (!newMigrationData?.legacy_cms?.uploadedFile?.isValidated) {
43+
if (selectedCard[idField] === data?.[idField]) {
44+
setIsHovered(true);
45+
}
46+
}
3947
};
4048

4149
const handleMouseLeave = () => {
4250
setIsHovered(false);
4351
};
4452

4553
const handleClick = (event: MouseEvent<HTMLDivElement>) => {
46-
event.preventDefault(); // Prevent the default action
47-
onCardClick?.(data);
54+
if (!newMigrationData?.legacy_cms?.uploadedFile?.isValidated) {
55+
event.preventDefault(); // Prevent the default action
56+
onCardClick?.(data);
57+
}
4858
};
4959

5060
return (
5161
<div
5262
onMouseEnter={handleMouseEnter}
5363
onMouseLeave={handleMouseLeave}
54-
className={`connector_list ${cardType === 'legacyCMS' ? 'trigger_list' : ''}`}
64+
className={`connector_list ${cardType === 'legacyCMS' ? 'trigger_list' : ''} ${disabled ? 'Card__disabled' : ''} `}
5565
style={{ position: 'relative' }}
56-
onClick={handleClick}
66+
onClick={!disabled ? handleClick : undefined}
5767
>
5868
{data.description && (
5969
<div style={{ position: 'absolute' }}>

0 commit comments

Comments
 (0)