Skip to content

Commit 32799df

Browse files
Merge pull request #718 from contentstack/bugfix/cmg-665
Bugfix/cmg 665
2 parents e008d4e + 371429c commit 32799df

File tree

5 files changed

+124
-61
lines changed

5 files changed

+124
-61
lines changed

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) => {

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
}

ui/src/components/AuditLogs/index.tsx

Lines changed: 25 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import {
1616
import './index.scss';
1717
import { auditLogsConstants } from '../../utilities/constants';
1818
import AuditFilterModal from '../AuditFilterModal';
19+
20+
const renderCell = (value: any) => <div>{value ?? '-'}</div>;
21+
1922
const AuditLogs: React.FC = () => {
2023
const params = useParams<{ projectId?: string }>();
2124
const [loading, setLoading] = useState<boolean>(false);
@@ -66,7 +69,7 @@ const AuditLogs: React.FC = () => {
6669
const predefinedOptions: FileOption[] = [
6770
{ label: 'Content Types', value: 'content-types' },
6871
{ label: 'Global Fields', value: 'global-fields' },
69-
{ label: 'Entries', value: 'Entries_Select_field' }
72+
{ label: 'Entries', value: 'Entries_Select_feild' }
7073
];
7174
setFileOptions(predefinedOptions);
7275
}
@@ -136,7 +139,6 @@ const AuditLogs: React.FC = () => {
136139
};
137140
const handleFileChange = async (selectedOption: FileOption | null) => {
138141
setSelectedFile(selectedOption);
139-
console.info('selectedOption', selectedOption);
140142
setDropDownOptions(selectedOption?.value);
141143
setSearchText('');
142144
setFilterValue([]);
@@ -152,12 +154,10 @@ const AuditLogs: React.FC = () => {
152154
};
153155
const ColumnFilter = () => {
154156
const closeModal = () => {
155-
console.info(isFilterDropdownOpen);
156157
setIsFilterDropdownOpen(false);
157158
};
158159
const openFilterDropdown = () => {
159160
if (!isFilterDropdownOpen) {
160-
console.info('openFilterDropdown');
161161
setIsFilterDropdownOpen(true);
162162
}
163163
setIsFilterDropdownOpen(true);
@@ -249,34 +249,24 @@ const AuditLogs: React.FC = () => {
249249
</div>
250250
);
251251
};
252-
const renderCell = (value: any) => <div>{value ?? '-'}</div>;
253252
const contentTypeHeader = [
254253
{
255254
Header: 'Title',
256255
accessor: (data: TableDataItem) => renderCell(data?.name),
257256
addToColumnSelector: true,
258257
disableSortBy: true,
259-
disableResizing: false,
260-
canDragDrop: true,
261-
width: 150
262258
},
263259
{
264260
Header: 'Field Name',
265261
accessor: (data: TableDataItem) => renderCell(data?.display_name),
266262
addToColumnSelector: true,
267263
disableSortBy: true,
268-
disableResizing: false,
269-
canDragDrop: true,
270-
width: 200
271264
},
272265
{
273266
Header: 'Field Type',
274267
accessor: (data: TableDataItem) => renderCell(data?.data_type),
275268
addToColumnSelector: true,
276269
disableSortBy: true,
277-
disableResizing: false,
278-
canDragDrop: true,
279-
width: 200,
280270
filter: ColumnFilter
281271
},
282272
{
@@ -287,32 +277,22 @@ const AuditLogs: React.FC = () => {
287277
: typeof data?.missingRefs === 'string'
288278
? data?.missingRefs
289279
: '-';
290-
291280
return renderCell(missing);
292281
},
293282
addToColumnSelector: true,
294283
disableSortBy: true,
295-
disableResizing: false,
296-
canDragDrop: true,
297-
width: 200
298284
},
299285
{
300286
Header: 'Tree Structure',
301287
accessor: (data: TableDataItem) => renderCell(data?.treeStr),
302288
addToColumnSelector: true,
303289
disableSortBy: true,
304-
disableResizing: false,
305-
canDragDrop: true,
306-
width: 200
307290
},
308291
{
309292
Header: 'Fix Status',
310293
accessor: (data: TableDataItem) => renderCell(data?.fixStatus),
311294
addToColumnSelector: true,
312295
disableSortBy: true,
313-
disableResizing: false,
314-
canDragDrop: true,
315-
width: 200
316296
}
317297
];
318298
const entryHeader = [
@@ -339,37 +319,42 @@ const AuditLogs: React.FC = () => {
339319
accessor: (data: TableDataItem) => renderCell(data?.display_name),
340320
addToColumnSelector: true,
341321
disableSortBy: true,
342-
disableResizing: false,
343-
canDragDrop: true,
344-
width: 200
345322
},
346323
{
347324
Header: 'Display Type',
348-
accessor: (data: TableDataItem) => renderCell(data?.display_type),
325+
accessor: (data: TableDataItem) => renderCell(data?.display_type || data?.data_type),
349326
addToColumnSelector: true,
350327
disableSortBy: true,
351-
disableResizing: false,
352-
canDragDrop: true,
353-
width: 200,
354328
filter: ColumnFilter
355329
},
356330
{
357-
Header: 'Missing Select Value',
358-
accessor: (data: TableDataItem) => renderCell(data?.missingCTSelectFieldValues),
331+
Header: 'Missing Value',
332+
cssClass: "missing-val",
333+
accessor: (data: TableDataItem) => {
334+
if (data?.missingCTSelectFieldValues) {
335+
return renderCell(data?.missingCTSelectFieldValues);
336+
}
337+
if (typeof data?.missingRefs === 'object' && data?.missingRefs) {
338+
const ctUid = (data?.missingRefs as any)?.[0]?._content_type_uid;
339+
if (Array.isArray(ctUid)) {
340+
return renderCell(ctUid?.length > 0 ? ctUid?.join(', ') : null);
341+
} else if (typeof ctUid === 'string') {
342+
return renderCell(ctUid);
343+
}
344+
}
345+
return renderCell(null);
346+
},
359347
addToColumnSelector: true,
360348
disableSortBy: true,
361-
disableResizing: false,
362-
canDragDrop: true,
363-
width: 200
364349
},
365350
{
366351
Header: 'Tree Structure',
367-
accessor: (data: TableDataItem) => renderCell(data?.treeStr ?? '-'),
352+
width: 300,
353+
accessor: (data: TableDataItem) => renderCell(data?.treeStr),
368354
addToColumnSelector: true,
369355
disableSortBy: true,
370-
disableResizing: false,
371-
canDragDrop: true,
372-
width: 250
356+
default: false,
357+
cssClass: "tree-struct"
373358
}
374359
];
375360

0 commit comments

Comments
 (0)