Skip to content

Commit 68f8c95

Browse files
Merge pull request #691 from contentstack/bugfix/execution-log
Bug Fixes Execution Log
2 parents f553a28 + 3a38240 commit 68f8c95

File tree

16 files changed

+333
-159
lines changed

16 files changed

+333
-159
lines changed

api/src/services/migration.service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -986,13 +986,14 @@ const getLogs = async (req: Request): Promise<any> => {
986986
}
987987
if (fs.existsSync(absolutePath)) {
988988
let index = 0;
989-
const logs = await fs.promises.readFile(absolutePath, "utf8");
989+
const logs = await fs?.promises?.readFile?.(absolutePath, "utf8");
990990
let logEntries = logs
991991
?.split("\n")
992992
?.map((line) => {
993993
try {
994994
const parsedLine = JSON?.parse(line)
995-
parsedLine['id'] = index;
995+
parsedLine && (parsedLine['id'] = index);
996+
996997
++index;
997998
return parsedLine ? parsedLine : null;
998999
} catch (error) {

api/src/services/runCli.service.ts

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ const determineLogLevel = (text: string): string => {
4747
* Strips ANSI color codes from text to create clean logs
4848
*/
4949
const stripAnsiCodes = (text: string): string => {
50+
const ESC = '\u001b';
5051
// This regex removes all ANSI escape sequences (color codes)
51-
return text.replace(/\u001b\[\d+m/g, '');
52+
return text?.replace(new RegExp(`${ESC}\\[[0-9;]*m`, 'g'), '');
5253
};
5354

5455
/**
@@ -206,34 +207,6 @@ export const runCli = async (
206207
// Debug which log path is being used
207208
console.info(`Log path for CLI commands: ${transformePath}`);
208209

209-
// Test writing all log levels directly to the file
210-
try {
211-
const testLogs = [
212-
{
213-
level: 'info',
214-
message: 'TEST INFO LOG',
215-
timestamp: new Date().toISOString(),
216-
},
217-
{
218-
level: 'warn',
219-
message: 'TEST WARNING LOG',
220-
timestamp: new Date().toISOString(),
221-
},
222-
{
223-
level: 'error',
224-
message: 'TEST ERROR LOG',
225-
timestamp: new Date().toISOString(),
226-
},
227-
];
228-
229-
for (const log of testLogs) {
230-
fs.appendFileSync(transformePath, JSON.stringify(log) + '\n');
231-
}
232-
console.info('Test logs written successfully');
233-
} catch (err) {
234-
console.error('Failed to write test logs:', err);
235-
}
236-
237210
// Make sure to set the global.currentLogFile to the project log file
238211
// This is the key part - setting the log file path to the migration service log file
239212
await setLogFilePath(transformePath);
@@ -377,4 +350,4 @@ export const runCli = async (
377350
}
378351
};
379352

380-
export const utilsCli = { runCli };
353+
export const utilsCli = { runCli };

ui/src/components/Common/Modal/FilterModal/FilterModal.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import { Button, Checkbox, Icon, Radio, Search, Tooltip } from '@contentstack/ve
22
import React, { useEffect, useState } from 'react';
33

44
import WordWrapper from '../../WordWrapper/WordWrapper';
5-
import { IFilterStatusType, IFilterType } from './filterModal.interface';
5+
66
import './FilterModal.scss';
7+
import { IFilterStatusType, IFilterType } from './filterModal.interface';
78

89
/**
910
* Props for the FilterModal component.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@import '../../../../scss/variables';
2+
3+
.text {
4+
font-size: $size-font-medium;
5+
line-height: $line-height-reset;
6+
color: #3d3f4c;
7+
text-transform: capitalize;
8+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { ModalBody, ModalHeader } from '@contentstack/venus-components'
2+
import { LogEntry } from '../../../ExecutionLogs/executionlog.interface';
3+
import './LogModal.scss'
4+
5+
interface LogModalProps {
6+
readonly props: {
7+
closeModal: () => void;
8+
};
9+
readonly data: LogEntry;
10+
}
11+
12+
export default function LogModal({ props, data }: LogModalProps) {
13+
return (
14+
<>
15+
<ModalHeader title={data?.level} closeModal={props?.closeModal} closeIconTestId="cs-default-header-close" className='text'/>
16+
17+
<ModalBody className="modalBodyCustomClass">
18+
{data?.methodName && (<><h3>Method Name: {data?.methodName}</h3><br /></>)}
19+
<p className='text'>{data?.message}</p>
20+
</ModalBody>
21+
</>
22+
);
23+
}

ui/src/components/Common/Settings/Settings.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,8 @@
114114
.back-button {
115115
cursor: pointer;
116116
margin-bottom: 20px;
117-
}
117+
}
118+
119+
.PageLayout--primary--v2 .PageLayout__body--left-drawer {
120+
display: none;
121+
}

ui/src/components/Common/Settings/index.tsx

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useEffect, useState } from 'react';
2-
import { useSelector } from 'react-redux';
2+
import { useSelector, useDispatch } from 'react-redux';
33
import { Params, useNavigate, useParams } from 'react-router';
44
import {
55
Icon,
@@ -31,9 +31,8 @@ import DeleteProjectModal from '../DeleteProjectModal';
3131

3232
//stylesheet
3333
import './Settings.scss';
34-
import { useDispatch } from 'react-redux';
3534
import { updateNewMigrationData } from '../../../store/slice/migrationDataSlice';
36-
import { DEFAULT_NEW_MIGRATION } from '../../../context/app/app.interface';
35+
import { DEFAULT_NEW_MIGRATION, INewMigration } from '../../../context/app/app.interface';
3736
import ExecutionLog from '../../../components/ExecutionLogs';
3837
import AuditLogs from '../../AuditLogs';
3938

@@ -45,16 +44,19 @@ const Settings = () => {
4544
const params: Params<string> = useParams();
4645

4746
const [cmsData, setCmsData] = useState<Setting>();
48-
const [active, setActive] = useState<string>();
4947
const [currentHeader, setCurrentHeader] = useState<string>();
5048
const [projectName, setProjectName] = useState('');
51-
const [projectId, setProjectId] = useState('');
49+
5250
const [projectDescription, setProjectDescription] = useState('');
5351

5452
const selectedOrganisation = useSelector(
5553
(state: RootState) => state?.authentication?.selectedOrganisation
5654
);
5755

56+
const newMigrationData = useSelector((state: RootState) => state?.migration?.newMigrationData);
57+
58+
const active_state = newMigrationData?.settings?.active_state;
59+
5860
const currentStep = useSelector(
5961
(state: RootState) => state?.migration?.newMigrationData?.project_current_step
6062
);
@@ -68,7 +70,6 @@ const Settings = () => {
6870
getCMSDataFromFile(CS_ENTRIES.SETTING)
6971
.then((data) => {
7072
setCmsData(data);
71-
setActive(data?.project?.title);
7273
setCurrentHeader(data?.project?.title);
7374
})
7475
.catch((err) => {
@@ -84,7 +85,6 @@ const Settings = () => {
8485
if (status === HTTP_CODES.OK) {
8586
setProjectName(data?.name);
8687
setProjectDescription(data?.description);
87-
setProjectId(params?.projectId ?? '');
8888
}
8989
};
9090

@@ -133,13 +133,11 @@ const Settings = () => {
133133
};
134134

135135
const handleDeleteProject = async (closeModal: () => void): Promise<void> => {
136-
//setIsLoading(true);
137136
const response = await deleteProject(selectedOrganisation?.value, params?.projectId ?? '');
138137

139-
if (response?.status === HTTP_CODES.OK) {
140-
//setIsLoading(false);
138+
if (response?.status === HTTP_CODES?.OK) {
141139
closeModal();
142-
dispatch(updateNewMigrationData(DEFAULT_NEW_MIGRATION));
140+
dispatch(updateNewMigrationData(newMigrationData));
143141
setTimeout(() => {
144142
navigate('/projects');
145143
}, 800);
@@ -158,7 +156,8 @@ const Settings = () => {
158156

159157
const handleBack = () => {
160158
navigate(`/projects/${params?.projectId}/migration/steps/${currentStep}`);
161-
}
159+
dispatch(updateNewMigrationData({...newMigrationData, settings: DEFAULT_NEW_MIGRATION?.settings }));
160+
};
162161

163162
const handleClick = () => {
164163
cbModal({
@@ -207,7 +206,7 @@ const Settings = () => {
207206
const content = {
208207
component: (
209208
<div>
210-
{active === cmsData?.project?.title && (
209+
{active_state === cmsData?.project?.title && (
211210
<div className="content-block">
212211
<div data-test-id="cs-stack-setting-general" className="stack-settings__heading">
213212
{cmsData?.project?.general}
@@ -261,13 +260,8 @@ const Settings = () => {
261260
</div>
262261
</div>
263262
)}
264-
{active === cmsData?.execution_logs?.title && (
265-
<ExecutionLog projectId={projectId} />
266-
)}
267-
{active === cmsData?.audit_logs?.title &&
268-
<AuditLogs />
269-
270-
}
263+
{active_state === cmsData?.execution_logs?.title && <ExecutionLog />}
264+
{active_state === cmsData?.audit_logs?.title && <AuditLogs />}
271265
</div>
272266
)
273267
};
@@ -291,42 +285,60 @@ const Settings = () => {
291285
withTooltip={true}
292286
tooltipContent={'Back'}
293287
tooltipPosition="right"
294-
className='back-button'
288+
className="back-button"
295289
/>
296290
</div>
297291
{cmsData?.title}
298292
</div>
299293

300294
<ListRow
301295
rightArrow={true}
302-
active={active === cmsData?.project?.title}
296+
active={active_state === cmsData?.project?.title}
303297
content={cmsData?.project?.title}
304298
leftIcon={<Icon icon="Stacks" version="v2" />}
305299
onClick={() => {
306-
setActive(cmsData?.project?.title);
307300
setCurrentHeader(cmsData?.project?.title);
301+
const activeTabState: INewMigration = {
302+
...newMigrationData,
303+
settings: {
304+
active_state: cmsData?.project?.title ?? ''
305+
}
306+
};
307+
dispatch(updateNewMigrationData(activeTabState));
308308
}}
309309
version="v2"
310310
/>
311311

312312
<ListRow
313313
rightArrow={true}
314-
active={active === cmsData?.execution_logs?.title}
314+
active={active_state === cmsData?.execution_logs?.title}
315315
content={cmsData?.execution_logs?.title}
316316
leftIcon={<Icon icon="ExecutionLog" version="v2" />}
317317
onClick={() => {
318-
setActive(cmsData?.execution_logs?.title);
319318
setCurrentHeader(cmsData?.execution_logs?.title);
319+
const activeTabState: INewMigration = {
320+
...newMigrationData,
321+
settings: {
322+
active_state: cmsData?.execution_logs?.title ?? ''
323+
}
324+
};
325+
dispatch(updateNewMigrationData(activeTabState));
320326
}}
321327
version="v2"
322328
/>
323329
<ListRow
324330
rightArrow={true}
325-
active={active === cmsData?.audit_logs?.title}
331+
active={active_state === cmsData?.audit_logs?.title}
326332
content={cmsData?.audit_logs?.title}
327333
leftIcon={<Icon icon="Stacks" version="v2" />}
328334
onClick={() => {
329-
setActive(cmsData?.audit_logs?.title);
335+
const activeTabState: INewMigration = {
336+
...newMigrationData,
337+
settings: {
338+
active_state: cmsData?.audit_logs?.title ?? ''
339+
}
340+
};
341+
dispatch(updateNewMigrationData(activeTabState));
330342
setCurrentHeader(cmsData?.audit_logs?.title);
331343
}}
332344
version="v2"
@@ -338,18 +350,18 @@ const Settings = () => {
338350
const header = {
339351
component: (
340352
<div>
341-
{active === cmsData?.project?.title ? (
353+
{active_state === cmsData?.project?.title ? (
342354
<PageHeader
343355
testId="header"
344356
className="action-component-title"
345-
title={{ label: currentHeader }}
357+
title={{ label: active_state }}
346358
actions={pageActions}
347359
/>
348360
) : (
349361
<PageHeader
350362
testId="header"
351363
className="action-component-title"
352-
title={{ label: currentHeader }}
364+
title={{ label: active_state }}
353365
/>
354366
)}
355367
</div>

0 commit comments

Comments
 (0)