Skip to content

Commit 371429c

Browse files
committed
refactor: streamline audit data handling and enhance UI rendering
- Updated `getAuditData` function to use `const` for file path declaration. - Removed unnecessary console logs for improved code cleanliness. - Introduced a `renderCell` function in the `AuditLogs` component to standardize cell rendering and handle null values more gracefully.
1 parent 51cc6ed commit 371429c

File tree

3 files changed

+21
-23
lines changed

3 files changed

+21
-23
lines changed

api/src/services/migration.service.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -672,9 +672,8 @@ const getAuditData = async (req: Request): Promise<any> => {
672672
if (!fs.existsSync(auditLogPath)) {
673673
throw new BadRequestError("Audit log path not found");
674674
}
675-
let filePath = path?.resolve(auditLogPath, `${moduleName}.json`);
675+
const filePath = path?.resolve(auditLogPath, `${moduleName}.json`);
676676
let fileData;
677-
// Special fallback logic for Entries_Select_feild
678677
if (moduleName === 'Entries_Select_feild') {
679678
const entriesSelectFieldPath = filePath;
680679
const entriesPath = path?.resolve(auditLogPath, `entries.json`);
@@ -737,7 +736,6 @@ const getAuditData = async (req: Request): Promise<any> => {
737736
throw new BadRequestError(`No audit data found for module: ${moduleName}`);
738737
}
739738
let transformedData = transformAndFlattenData(fileData);
740-
console.log(transformedData);
741739
if (moduleName === 'Entries_Select_feild') {
742740
if (filter != GET_AUDIT_DATA?.FILTERALL) {
743741
const filters = filter?.split("-");

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

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

3737
}
3838
export type DropdownOption = {

ui/src/components/AuditLogs/index.tsx

Lines changed: 19 additions & 19 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);
@@ -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);
@@ -252,19 +252,19 @@ const AuditLogs: React.FC = () => {
252252
const contentTypeHeader = [
253253
{
254254
Header: 'Title',
255-
accessor: (data: TableDataItem) => <div>{data?.name ?? '-'}</div>,
255+
accessor: (data: TableDataItem) => renderCell(data?.name),
256256
addToColumnSelector: true,
257257
disableSortBy: true,
258258
},
259259
{
260260
Header: 'Field Name',
261-
accessor: (data: TableDataItem) => <div>{data?.display_name ?? '-'}</div>,
261+
accessor: (data: TableDataItem) => renderCell(data?.display_name),
262262
addToColumnSelector: true,
263263
disableSortBy: true,
264264
},
265265
{
266266
Header: 'Field Type',
267-
accessor: (data: TableDataItem) => <div>{data?.data_type ?? '-'}</div>,
267+
accessor: (data: TableDataItem) => renderCell(data?.data_type),
268268
addToColumnSelector: true,
269269
disableSortBy: true,
270270
filter: ColumnFilter
@@ -277,28 +277,28 @@ const AuditLogs: React.FC = () => {
277277
: typeof data?.missingRefs === 'string'
278278
? data?.missingRefs
279279
: '-';
280-
return <div>{missing ?? '-'}</div>;
280+
return renderCell(missing);
281281
},
282282
addToColumnSelector: true,
283283
disableSortBy: true,
284284
},
285285
{
286286
Header: 'Tree Structure',
287-
accessor: (data: TableDataItem) => <div>{data?.treeStr ?? '-'}</div>,
287+
accessor: (data: TableDataItem) => renderCell(data?.treeStr),
288288
addToColumnSelector: true,
289289
disableSortBy: true,
290290
},
291291
{
292292
Header: 'Fix Status',
293-
accessor: (data: TableDataItem) => <div>{data?.fixStatus ?? '-'}</div>,
293+
accessor: (data: TableDataItem) => renderCell(data?.fixStatus),
294294
addToColumnSelector: true,
295295
disableSortBy: true,
296296
}
297297
];
298298
const entryHeader = [
299299
{
300300
Header: 'Entry UID',
301-
accessor: (data: TableDataItem) => <div>{data?.uid ?? '-'}</div>,
301+
accessor: (data: TableDataItem) => renderCell(data?.uid),
302302
addToColumnSelector: true,
303303
disableSortBy: true,
304304
disableResizing: false,
@@ -307,7 +307,7 @@ const AuditLogs: React.FC = () => {
307307
},
308308
{
309309
Header: 'Name',
310-
accessor: (data: TableDataItem) => <div>{data?.name ?? '-'}</div>,
310+
accessor: (data: TableDataItem) => renderCell(data?.name),
311311
addToColumnSelector: true,
312312
disableSortBy: true,
313313
disableResizing: false,
@@ -316,13 +316,13 @@ const AuditLogs: React.FC = () => {
316316
},
317317
{
318318
Header: 'Display Name',
319-
accessor: (data: TableDataItem) => <div>{data?.display_name ?? '-'}</div>,
319+
accessor: (data: TableDataItem) => renderCell(data?.display_name),
320320
addToColumnSelector: true,
321321
disableSortBy: true,
322322
},
323323
{
324324
Header: 'Display Type',
325-
accessor: (data: TableDataItem) => <div>{data?.display_type || data?.data_type || '-'}</div>,
325+
accessor: (data: TableDataItem) => renderCell(data?.display_type || data?.data_type),
326326
addToColumnSelector: true,
327327
disableSortBy: true,
328328
filter: ColumnFilter
@@ -332,25 +332,25 @@ const AuditLogs: React.FC = () => {
332332
cssClass: "missing-val",
333333
accessor: (data: TableDataItem) => {
334334
if (data?.missingCTSelectFieldValues) {
335-
return <div>{data.missingCTSelectFieldValues ?? '-'}</div>;
335+
return renderCell(data?.missingCTSelectFieldValues);
336336
}
337337
if (typeof data?.missingRefs === 'object' && data?.missingRefs) {
338-
const ctUid = (data.missingRefs as any)[0]?._content_type_uid;
338+
const ctUid = (data?.missingRefs as any)?.[0]?._content_type_uid;
339339
if (Array.isArray(ctUid)) {
340-
return <div>{ctUid.length > 0 ? ctUid.join(', ') : '-'}</div>;
340+
return renderCell(ctUid?.length > 0 ? ctUid?.join(', ') : null);
341341
} else if (typeof ctUid === 'string') {
342-
return <div>{ctUid}</div>;
342+
return renderCell(ctUid);
343343
}
344344
}
345-
return <div>-</div>;
345+
return renderCell(null);
346346
},
347347
addToColumnSelector: true,
348348
disableSortBy: true,
349349
},
350350
{
351351
Header: 'Tree Structure',
352352
width: 300,
353-
accessor: (data: TableDataItem) => <div>{data?.treeStr ?? '-'}</div>,
353+
accessor: (data: TableDataItem) => renderCell(data?.treeStr),
354354
addToColumnSelector: true,
355355
disableSortBy: true,
356356
default: false,

0 commit comments

Comments
 (0)