Skip to content

Commit d65604f

Browse files
authored
Merge pull request #720 from contentstack/pre-dev
Pre dev
2 parents d70a74b + 32799df commit d65604f

File tree

13 files changed

+212
-90
lines changed

13 files changed

+212
-90
lines changed

.talismanrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,7 @@ fileignoreconfig:
5959
- filename: ui/src/components/ContentMapper/index.tsx
6060
checksum: b5f66e808ecf4461ccb5c4fde937da1e6d9e640a2521d6d85858a22261df6571
6161

62+
- filename: ui/src/components/Common/Card/card.tsx
63+
checksum: 6c6194f6b8f470ad107e59f2c4247647bdaa804e458c06b007cf9e074aabac69
64+
6265

api/src/services/migration.service.ts

Lines changed: 83 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,6 @@ const getAuditData = async (req: Request): Promise<any> => {
654654
const searchText = req?.params?.searchText;
655655
const filter = req?.params?.filter;
656656
const srcFunc = "getAuditData";
657-
658657
if (projectId?.includes('..') || stackId?.includes('..') || moduleName?.includes('..')) {
659658
throw new BadRequestError("Invalid projectId, stackId, or moduleName");
660659
}
@@ -675,38 +674,105 @@ const getAuditData = async (req: Request): Promise<any> => {
675674
}
676675
const filePath = path?.resolve(auditLogPath, `${moduleName}.json`);
677676
let fileData;
678-
if (fs?.existsSync(filePath)) {
679-
const fileContent = await fsPromises?.readFile(filePath, 'utf8');
680-
try {
681-
if (typeof fileContent === 'string') {
682-
fileData = JSON?.parse(fileContent);
677+
if (moduleName === 'Entries_Select_feild') {
678+
const entriesSelectFieldPath = filePath;
679+
const entriesPath = path?.resolve(auditLogPath, `entries.json`);
680+
const entriesSelectFieldExists = fs?.existsSync(entriesSelectFieldPath);
681+
const entriesExists = fs?.existsSync(entriesPath);
682+
let combinedData: any[] = [];
683+
const addToCombined = (parsed: any) => {
684+
if (Array.isArray(parsed)) {
685+
combinedData = combinedData.concat(parsed);
686+
} else if (parsed && typeof parsed === 'object') {
687+
Object.values(parsed).forEach(val => {
688+
if (Array.isArray(val)) {
689+
combinedData = combinedData.concat(val);
690+
} else if (val && typeof val === 'object') {
691+
combinedData.push(val);
692+
}
693+
});
694+
}
695+
};
696+
if (entriesSelectFieldExists) {
697+
const fileContent = await fsPromises?.readFile(entriesSelectFieldPath, 'utf8');
698+
try {
699+
if (typeof fileContent === 'string') {
700+
const parsed = JSON?.parse(fileContent);
701+
addToCombined(parsed);
702+
}
703+
} catch (error) {
704+
logger.error(`Error parsing JSON from file ${entriesSelectFieldPath}:`, error);
705+
throw new BadRequestError('Invalid JSON format in audit file');
706+
}
707+
}
708+
if (entriesExists) {
709+
const fileContent = await fsPromises?.readFile(entriesPath, 'utf8');
710+
try {
711+
if (typeof fileContent === 'string') {
712+
const parsed = JSON?.parse(fileContent);
713+
addToCombined(parsed);
714+
}
715+
} catch (error) {
716+
logger.error(`Error parsing JSON from file ${entriesPath}:`, error);
717+
throw new BadRequestError('Invalid JSON format in audit file');
718+
}
719+
}
720+
fileData = combinedData;
721+
} else {
722+
if (fs?.existsSync(filePath)) {
723+
const fileContent = await fsPromises?.readFile(filePath, 'utf8');
724+
try {
725+
if (typeof fileContent === 'string') {
726+
fileData = JSON?.parse(fileContent);
727+
}
728+
} catch (error) {
729+
logger.error(`Error parsing JSON from file ${filePath}:`, error);
730+
throw new BadRequestError('Invalid JSON format in audit file');
683731
}
684-
} catch (error) {
685-
logger.error(`Error parsing JSON from file ${filePath}:`, error);
686-
throw new BadRequestError('Invalid JSON format in audit file');
687732
}
688733
}
689734

690735
if (!fileData) {
691736
throw new BadRequestError(`No audit data found for module: ${moduleName}`);
692737
}
693738
let transformedData = transformAndFlattenData(fileData);
694-
if (filter != GET_AUDIT_DATA?.FILTERALL) {
695-
const filters = filter?.split("-");
696-
moduleName === 'Entries_Select_feild' ? transformedData = transformedData?.filter((log) => {
697-
return filters?.some((filter) => {
698-
return (
699-
log?.display_type?.toLowerCase()?.includes(filter?.toLowerCase())
739+
if (moduleName === 'Entries_Select_feild') {
740+
if (filter != GET_AUDIT_DATA?.FILTERALL) {
741+
const filters = filter?.split("-");
742+
transformedData = transformedData?.filter((log) => {
743+
return filters?.some((filter) => {
744+
return (
745+
log?.display_type?.toLowerCase()?.includes(filter?.toLowerCase()) ||
746+
log?.data_type?.toLowerCase()?.includes(filter?.toLowerCase())
747+
);
748+
});
749+
});
750+
}
751+
if (searchText && searchText !== null && searchText !== "null") {
752+
transformedData = transformedData?.filter((item) => {
753+
return Object?.values(item)?.some(value =>
754+
value &&
755+
typeof value === 'string' &&
756+
value?.toLowerCase?.()?.includes(searchText?.toLowerCase())
700757
);
701758
});
702-
}) : transformedData = transformedData?.filter((log) => {
759+
}
760+
const finalData = transformedData?.slice?.(startIndex, stopIndex);
761+
return {
762+
data: finalData,
763+
totalCount: transformedData?.length,
764+
status: HTTP_CODES?.OK
765+
};
766+
}
767+
if (filter != GET_AUDIT_DATA?.FILTERALL) {
768+
const filters = filter?.split("-");
769+
transformedData = transformedData?.filter((log) => {
703770
return filters?.some((filter) => {
704771
return (
705772
log?.data_type?.toLowerCase()?.includes(filter?.toLowerCase())
706773
);
707774
});
708775
});
709-
710776
}
711777
if (searchText && searchText !== null && searchText !== "null") {
712778
transformedData = transformedData?.filter((item: any) => {

api/src/utils/entries-field-creator.utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import _ from "lodash";
22
import { JSDOM } from "jsdom";
33
import { htmlToJson } from '@contentstack/json-rte-serializer';
4+
// @ts-ignore
45
import { HTMLToJSON } from 'html-to-json-parser';
56

67
const append = "a";
@@ -75,7 +76,7 @@ export function unflatten(table: Table): any {
7576

7677
const htmlConverter = async ({ content = "" }: any) => {
7778
const dom = `<div>${content}</div>`;
78-
return await HTMLToJSON(dom, true);
79+
return await Promise.resolve(HTMLToJSON(dom, true));
7980
}
8081

8182
const getAssetsUid = ({ url }: any) => {

docker-compose.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ services:
77
ports:
88
- "5001:5001"
99
restart: always
10+
volumes:
11+
- shared_data:/app/extracted_files
1012

1113
upload-api:
1214
container_name: migration-upload-api
@@ -17,6 +19,7 @@ services:
1719
restart: always
1820
volumes:
1921
- ${CMS_DATA_PATH}:${CONTAINER_PATH}
22+
- shared_data:/app/extracted_files
2023

2124
ui:
2225
container_name: migration-ui
@@ -25,3 +28,6 @@ services:
2528
ports:
2629
- "3000:3000"
2730
restart: always
31+
32+
volumes:
33+
shared_data:

setup-docker.sh

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,48 @@ done
2323

2424
read -p "Enter the full path to your $CMS_TYPE data file (e.g., $EXAMPLE_FILE): " CMS_DATA_PATH
2525

26-
if [ ! -f "$CMS_DATA_PATH" ]; then
27-
echo "❌ File does not exist: $CMS_DATA_PATH"
26+
# Remove surrounding quotes if they exist
27+
CMS_DATA_PATH="${CMS_DATA_PATH%\"}"
28+
CMS_DATA_PATH="${CMS_DATA_PATH#\"}"
29+
30+
# Store original Windows path for Docker volume mounting
31+
ORIGINAL_PATH="$CMS_DATA_PATH"
32+
33+
# Convert Windows path to Unix format for Git Bash file operations ONLY
34+
UNIX_PATH="$CMS_DATA_PATH"
35+
if [[ "$CMS_DATA_PATH" =~ ^[A-Za-z]:\\ ]]; then
36+
# Replace backslashes with forward slashes
37+
UNIX_PATH=$(echo "$CMS_DATA_PATH" | sed 's/\\/\//g')
38+
# Convert C: to /c/ format for Git Bash
39+
UNIX_PATH=$(echo "$UNIX_PATH" | sed 's/^\([A-Za-z]\):/\/\L\1/')
40+
fi
41+
42+
# Check if file exists using the converted path
43+
if [ ! -f "$UNIX_PATH" ]; then
44+
echo "❌ File does not exist: $UNIX_PATH"
2845
exit 1
2946
fi
3047

31-
FILENAME=$(basename "$CMS_DATA_PATH")
48+
FILENAME=$(basename "$UNIX_PATH")
3249
CONTAINER_PATH="/data/$FILENAME"
3350

3451
export CMS_TYPE
35-
export CMS_DATA_PATH
52+
export CMS_DATA_PATH="$ORIGINAL_PATH"
3653
export CONTAINER_PATH
3754

3855
ENV_PATH="./upload-api/.env"
3956

4057
set_env_var() {
4158
VAR_NAME="$1"
4259
VAR_VALUE="$2"
60+
61+
# Create directory if it doesn't exist
62+
mkdir -p "$(dirname "$ENV_PATH")"
63+
4364
if grep -q "^${VAR_NAME}=" "$ENV_PATH" 2>/dev/null; then
44-
# Update existing variable (cross-platform)
45-
sed -i.bak "s|^${VAR_NAME}=.*|${VAR_NAME}=${VAR_VALUE}|" "$ENV_PATH"
65+
# Update existing variable - escape special characters for sed
66+
ESCAPED_VALUE=$(printf '%s\n' "$VAR_VALUE" | sed 's/[[\.*^$()+?{|]/\\&/g')
67+
sed -i.bak "s|^${VAR_NAME}=.*|${VAR_NAME}=${ESCAPED_VALUE}|" "$ENV_PATH"
4668
rm -f "$ENV_PATH.bak"
4769
else
4870
# Append new variable
@@ -51,9 +73,24 @@ set_env_var() {
5173
}
5274

5375
set_env_var "CMS_TYPE" "$CMS_TYPE"
54-
set_env_var "CMS_DATA_PATH" "$CMS_DATA_PATH"
76+
# Use original Windows path for Docker volume mounting
77+
set_env_var "CMS_DATA_PATH" "$ORIGINAL_PATH"
5578
set_env_var "CONTAINER_PATH" "$CONTAINER_PATH"
5679
set_env_var "NODE_BACKEND_API" "http://migration-api:5001"
5780

81+
# Check if docker-compose.yml exists before running
82+
if [ ! -f "docker-compose.yml" ]; then
83+
echo "❌ docker-compose.yml not found in current directory"
84+
echo "Current directory: $(pwd)"
85+
echo "Available files:"
86+
ls -la
87+
exit 1
88+
fi
89+
90+
echo "✅ Starting Docker Compose with the following configuration:"
91+
echo "CMS_TYPE: $CMS_TYPE"
92+
echo "CMS_DATA_PATH (for Docker): $ORIGINAL_PATH"
93+
echo "CMS_DATA_PATH (for file check): $UNIX_PATH"
94+
echo "CONTAINER_PATH: $CONTAINER_PATH"
5895

59-
docker compose up --build
96+
MSYS_NO_PATHCONV=1 docker compose up --build

ui/src/components/AuditFilterModal/index.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,17 @@ const AuditFilterModal = ({
2929
{ label: 'global_field', value: 'global_field' },
3030
{ label: 'reference', value: 'reference' },
3131
{ label: 'group', value: 'group' },
32+
{ label: 'json', value: 'json' }
3233
];
3334
}
3435

35-
if (selectedFileType?.includes?.('Entries')) {
36-
return [{ label: 'dropdown', value: 'dropdown' }];
37-
}
3836

39-
return [];
37+
38+
return [{ label: 'dropdown', value: 'dropdown' },
39+
{ label: "radio", value: "radio" },
40+
{ label: "reference", value: "reference" },
41+
{ label: "checkbox", value: 'checkbox' }
42+
];
4043
};
4144

4245
const filterOptions = getFilterOptions();

ui/src/components/AuditLogs/auditLogs.interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export interface TableDataItem {
3232
missingCTSelectFieldValues?: string;
3333
parentKey?: string;
3434
ct_uid?: string;
35+
_content_type_uid?: string;
3536

3637
}
3738
export type DropdownOption = {

ui/src/components/AuditLogs/index.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,12 @@
5252
.TablePagination {
5353
position: sticky;
5454
bottom: 0;
55+
}
56+
57+
.tree-struct {
58+
width: 300px !important;
59+
}
60+
61+
.missing-val {
62+
width: 270px !important;
5563
}

0 commit comments

Comments
 (0)