From b1c1f95e79995acbd04d9dba26796f6817d23418 Mon Sep 17 00:00:00 2001 From: AishDani Date: Fri, 10 Jan 2025 14:48:47 +0530 Subject: [PATCH 1/8] refactor:logic of delete content type from stack and storing in redux --- ui/src/components/ContentMapper/index.tsx | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/ui/src/components/ContentMapper/index.tsx b/ui/src/components/ContentMapper/index.tsx index 15c1fceb..8c1a16dc 100644 --- a/ui/src/components/ContentMapper/index.tsx +++ b/ui/src/components/ContentMapper/index.tsx @@ -1694,7 +1694,7 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R } }; - const handleCTDeleted = async(isContentType:boolean) => { + const handleCTDeleted = async(isContentType:boolean, contentTypes:ContentTypeList[]) => { const updatedContentTypeMapping = Object.fromEntries( Object.entries(newMigrationData?.content_mapping?.content_type_mapping || {}).filter( ([key]) => !selectedContentType?.contentstackUid.includes(key) @@ -1776,6 +1776,7 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R ...newMigrationData, content_mapping:{ ...newMigrationData?.content_mapping, + existingCT: contentTypes, content_type_mapping : updatedContentTypeMapping } @@ -1793,10 +1794,10 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R if (isContentType) { try { const { data , status} = await getExistingContentTypes(projectId, otherContentType?.id ?? ''); - if (status == 201 && data?.contentTypes?.length > 0 && data?.selectedContentType) { + if (status == 201 && data?.contentTypes?.length > 0) { (otherContentType?.id === data?.selectedContentType?.uid) && setsCsCTypeUpdated(false); - (otherContentType?.id && otherContentType?.label !== data?.selectedContentType?.title) + (otherContentType?.id && otherContentType?.label !== data?.selectedContentType?.title && data?.selectedContentType?.title) && setOtherContentType({ label: data?.selectedContentType?.title, value: data?.selectedContentType?.title, @@ -1824,8 +1825,6 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R setContentTypeSchema(data?.selectedContentType?.schema); } } else { - - await handleCTDeleted(isContentType); Notification({ notificationContent: { text: "No content found in the stack" }, notificationProps: { @@ -1835,6 +1834,9 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R type: 'error' }); } + if(otherContentType?.id && data?.contentTypes?.every((item: any) => item?.uid !== otherContentType?.id)){ + await handleCTDeleted(isContentType, data?.contentTypes); + } } catch (error) { console.log(error); return error; @@ -1843,10 +1845,10 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R try { const { data, status } = await getExistingGlobalFields(projectId, otherContentType?.id ?? ''); - if (status == 201 && data?.globalFields?.length > 0 && data?.selectedGlobalField) { + if (status == 201 && data?.globalFields?.length > 0) { (otherContentType?.id === data?.selectedGlobalField?.uid) && setsCsCTypeUpdated(false); - (otherContentType?.id && otherContentType?.label !== data?.selectedGlobalField?.title) + (otherContentType?.id && otherContentType?.label !== data?.selectedGlobalField?.title && data?.selectedGlobalField?.title) && setOtherContentType({ label: data?.selectedGlobalField?.title, value:data?.selectedGlobalField?.title, @@ -1874,8 +1876,6 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R }); } else { - await handleCTDeleted(isContentType); - Notification({ notificationContent: { text: "No Global Fields found in the stack" }, notificationProps: { @@ -1885,6 +1885,9 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R type: 'error' }); } + if(otherContentType?.id && data?.globalFields?.every((item: any) => item?.uid !== otherContentType?.id)){ + await handleCTDeleted(isContentType, data?.globalFields); + } } catch (error) { console.log(error); return error; From a70e19ca491aadda11c68793bb5b0263de0e26f8 Mon Sep 17 00:00:00 2001 From: AishDani Date: Fri, 10 Jan 2025 16:51:09 +0530 Subject: [PATCH 2/8] refactor:[CMG-431],[CMG-435] --- .../DestinationStack/Actions/LoadStacks.tsx | 12 ++++++------ .../components/LegacyCms/Actions/LoadFileFormat.tsx | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ui/src/components/DestinationStack/Actions/LoadStacks.tsx b/ui/src/components/DestinationStack/Actions/LoadStacks.tsx index fd9ef810..e4efff6a 100644 --- a/ui/src/components/DestinationStack/Actions/LoadStacks.tsx +++ b/ui/src/components/DestinationStack/Actions/LoadStacks.tsx @@ -146,7 +146,7 @@ const LoadStacks = (props: LoadFileFormatProps) => { }; - + /**** ALL METHODS HERE ****/ //Handle Legacy cms selection @@ -214,11 +214,11 @@ const LoadStacks = (props: LoadFileFormatProps) => { return stack?.value === newMigrationData?.destination_stack?.selectedStack?.value } ) - : DEFAULT_DROPDOWN; - if (stackData?.data?.stacks?.length === 0 && (!stackData?.data?.stack)) { - setIsError(true); - setErrorMessage("Please create new stack there is no stack available"); - } + : null; + // if (stackData?.data?.stacks?.length === 0 && (!stackData?.data?.stack)) { + // setIsError(true); + // setErrorMessage("Please create new stack there is no stack available"); + // } if(selectedStackData){ setSelectedStack(selectedStackData); diff --git a/ui/src/components/LegacyCms/Actions/LoadFileFormat.tsx b/ui/src/components/LegacyCms/Actions/LoadFileFormat.tsx index af7054b7..fdd9c094 100644 --- a/ui/src/components/LegacyCms/Actions/LoadFileFormat.tsx +++ b/ui/src/components/LegacyCms/Actions/LoadFileFormat.tsx @@ -74,7 +74,7 @@ const LoadFileFormat = (props: LoadFileFormatProps) => { const cmsType = !isEmptyString(newMigrationData?.legacy_cms?.selectedCms?.parent) ? newMigrationData?.legacy_cms?.selectedCms?.parent : data?.cmsType?.toLowerCase(); const filePath = data?.localPath?.toLowerCase(); const fileFormat = getFileExtension(filePath); - if(! isEmptyString(selectedCard?.fileformat_id)){ + if(! isEmptyString(selectedCard?.fileformat_id) && selectedCard?.fileformat_id === fileFormat){ setFileIcon(selectedCard?.title); } else{ From 3dbb68c48f08abf952bffbc73b432cb90fccdc4d Mon Sep 17 00:00:00 2001 From: AishDani Date: Wed, 15 Jan 2025 17:23:01 +0530 Subject: [PATCH 3/8] refactor:changed the logic for emitting logs into baches --- api/src/server.ts | 33 ++++- .../LogScreen/MigrationLogViewer.tsx | 113 ++++++++++++------ ui/src/components/LogScreen/index.tsx | 78 ++++++++---- 3 files changed, 165 insertions(+), 59 deletions(-) diff --git a/api/src/server.ts b/api/src/server.ts index 157dd0e9..86dcab25 100644 --- a/api/src/server.ts +++ b/api/src/server.ts @@ -115,16 +115,41 @@ try { credentials: true, }, }); + let fileOffset = 0; + const CHUNK_SIZE = 1024 * 1024; // Limit batch size to 1MB // Emit initial log file content to connected clients // File watcher for log file changes watcher.on("change", async (path) => { console.info(`File changed: ${path}`); - // Read the updated file content try { - const data = await fs.promises.readFile(path, "utf8") - // Emit the updated log content to connected clients - io.emit("logUpdate", data); + const fileStats = await fs.promises.stat(path); + + // Read the entire file if there is an update (new logs or changes) + const stream = fs.createReadStream(path, { start: fileOffset }); + let fileData = ''; + + stream.on('data', (chunk) => { + fileData += chunk.toString(); // Collect the file data as a string + }); + + stream.on('end', () => { + // Emit the file content in chunks + let index = 0; + while (index < fileData?.length) { + const chunk = fileData?.slice(index, index + CHUNK_SIZE); // Get the next chunk + + io.emit('logUpdate', chunk); + index += CHUNK_SIZE; // Move to the next chunk + } + + // Update the file offset for the next read + fileOffset = fileStats.size; + }); + + stream.on('error', (err) => { + console.error('Error reading log file:', err); + }); } catch (error) { logger.error(`Error emitting log data: ${error}`); } diff --git a/ui/src/components/LogScreen/MigrationLogViewer.tsx b/ui/src/components/LogScreen/MigrationLogViewer.tsx index 89fabf83..3591ba33 100644 --- a/ui/src/components/LogScreen/MigrationLogViewer.tsx +++ b/ui/src/components/LogScreen/MigrationLogViewer.tsx @@ -41,12 +41,19 @@ type LogsType = { handleStepChange: (currentStep: number) => void; } +export interface LogEntry { + level?: string; + message?: string; + timestamp?: string | null; +} + /** * MigrationLogViewer component displays logs received from the server. * @param {string} serverPath - The path of the server to connect to. */ const MigrationLogViewer = ({ serverPath }: LogsType) => { - const [logs, setLogs] = useState([JSON.stringify({ message: "Migration logs will appear here once the process begins.", level: '' })]); + const [logs, setLogs] = useState([ + { message: "Migration logs will appear here once the process begins.", level: '' }]); const [isModalOpen, setIsModalOpen] = useState(false); const [zoomLevel, setZoomLevel] = useState(1); @@ -75,10 +82,47 @@ const MigrationLogViewer = ({ serverPath }: LogsType) => { * @param {string} newLogs - The new logs received from the server. */ socket.on('logUpdate', (newLogs: string) => { - const logArray = newLogs.split('\n'); - setLogs(logArray); - }); - + //const logArray = (newLogs: string) =>{ + //try { + const parsedLogsArray: LogEntry[] = []; + const logArray = newLogs?.split('\n') + //const parsedLogs = JSON?.parse(logArray); + // const plogs = { + // level: parsedLogs.level || 'info', + // message: parsedLogs.message || 'Unknown message', + // timestamp: parsedLogs.timestamp || null, + // }; + logArray?.forEach((logLine) => { + try { + // Attempt to parse each log entry as a JSON object + const parsedLog = JSON?.parse(logLine); + + // Build the log object with default values + const plogs = { + level: parsedLog.level || 'info', + message: parsedLog.message || 'Unknown message', + timestamp: parsedLog.timestamp || null, + }; + parsedLogsArray.push(plogs); + }catch(error){ + console.log("error in parsing logs : ", error); + } + }); + //return plogs; + //const logArray = newLogs.split('\n'); + setLogs((prevLogs) => [...prevLogs, ...parsedLogsArray]); + //} + + //setLogs((prevLogs) => [...prevLogs, plogs]); + //const logArray = newLogs.split('\n'); + //setLogs(logArray); + + // } catch (error) { + // console.error('Failed to parse logUpdate data:', newLogs, error); + + // } + + }) return () => { socket.disconnect(); // Cleanup on component unmount }; @@ -147,8 +191,8 @@ const MigrationLogViewer = ({ serverPath }: LogsType) => { logs?.forEach((log) => { try { - const logObject = JSON.parse(log); - const message = logObject.message; + //const logObject = JSON.parse(log); + const message = log.message; if (message === "Migration Process Completed") { @@ -209,34 +253,35 @@ const MigrationLogViewer = ({ serverPath }: LogsType) => { transformOrigin: "top left", transition: "transform 0.1s ease" }}> - {logs?.map((log, index) => { - const key = `${index}-${new Date().getMilliseconds()}` - try { - const logObject = JSON.parse(log); - const level = logObject.level; - const timestamp = logObject.timestamp; - const message = logObject.message; - - return ( - newMigrationData?.destination_stack?.migratedStacks?.includes(newMigrationData?.destination_stack?.selectedStack?.value) ? -
-
Migration has already done in selected stack. Please create a new project.
-
- : - message === "Migration logs will appear here once the process begins." - ?
-
{message}
-
- :
-
{index}
-
{timestamp ? new Date(timestamp)?.toTimeString()?.split(' ')[0] : new Date()?.toTimeString()?.split(' ')[0]}
-
{message}
+ {logs.map((log, index) => { + try { + //const logObject = JSON.parse(log); + const { level, timestamp, message } = log; + + return ( +
+ {message === "Migration logs will appear here once the process begins." + ?
+
{message}
: +
+
{index}
+
+ {timestamp ? new Date(timestamp)?.toTimeString()?.split(' ')[0] : new Date()?.toTimeString()?.split(' ')[0]} +
+
{message}
+
+ }
- ); - } catch (error) { - console.error('Invalid JSON string', error); - } - })} + ); + } catch (error) { + console.error('Invalid log format', error); + return null; + } + })}
} diff --git a/ui/src/components/LogScreen/index.tsx b/ui/src/components/LogScreen/index.tsx index 1370695a..59dcf9ed 100644 --- a/ui/src/components/LogScreen/index.tsx +++ b/ui/src/components/LogScreen/index.tsx @@ -16,6 +16,7 @@ import './index.scss'; import { MAGNIFY,DEMAGNIFY } from '../../common/assets'; import { saveStateToLocalStorage } from '../../utilities/functions'; +import { LogEntry } from './MigrationLogViewer'; // Define log styles for different levels const logStyles: { [key: string]: React.CSSProperties } = { @@ -39,7 +40,8 @@ type LogsType = { * @param {string} projectId - The project ID for saving state to local storage. */ const TestMigrationLogViewer = ({ serverPath, sendDataToParent,projectId }: LogsType) => { - const [logs, setLogs] = useState([JSON.stringify({ message: "Migration logs will appear here once the process begins.", level: ''})]); + const [logs, setLogs] = useState([ + { message: "Migration logs will appear here once the process begins.", level: ''}]); const newMigrationData = useSelector((state: RootState) => state?.migration?.newMigrationData); @@ -48,17 +50,43 @@ const TestMigrationLogViewer = ({ serverPath, sendDataToParent,projectId }: Logs // Set up WebSocket connection useEffect(() => { - const socket = io(serverPath || ''); // Connect to the server + const socket = io(serverPath || '',{ + reconnection: true, + }); // Connect to the server + + socket.on('disconnect', () => { + console.warn('Disconnected from server. Retrying...'); + setTimeout(() => socket.connect(), 3000); // Retry connection after 3 seconds + }); /** * Event listener for 'logUpdate' event. * @param {string} newLogs - The new logs received from the server. */ socket.on('logUpdate', (newLogs: string) => { - const logArray = newLogs.split('\n'); - setLogs(logArray); - }); - + console.log("logs ::::: ", newLogs); + const parsedLogsArray: LogEntry[] = []; + const logArray = newLogs?.split('\n') + + //const logArray = newLogs?.forEach(()=>{}) split('\n'); + logArray?.forEach((logLine) => { + try { + // Attempt to parse each log entry as a JSON object + const parsedLog = JSON.parse(logLine); + + // Build the log object with default values + const plogs = { + level: parsedLog.level || 'info', + message: parsedLog.message || 'Unknown message', + timestamp: parsedLog.timestamp || null, + }; + parsedLogsArray.push(plogs); + }catch(error){ + console.log("error in parsing logs : ", error); + } + }); + setLogs((prevLogs) => [...prevLogs, ...parsedLogsArray]); + }) return () => { socket.disconnect(); // Cleanup on component unmount }; @@ -129,8 +157,8 @@ const TestMigrationLogViewer = ({ serverPath, sendDataToParent,projectId }: Logs logs?.forEach((log) => { try { - const logObject = JSON.parse(log); - const message = logObject.message; + //const logObject = JSON.parse(log); + const message = log?.message; if (message === "Test Migration Process Completed") { @@ -186,21 +214,29 @@ const TestMigrationLogViewer = ({ serverPath, sendDataToParent,projectId }: Logs {logs?.map((log, index) => { // const key = `${index}-${new Date().getMilliseconds()}` try { - const logObject = JSON.parse(log); - const level = logObject.level; - const timestamp = logObject.timestamp; - const message = logObject.message; + + //logObject = JSON.parse(log); + const { level, timestamp, message } = log; + + //const logObject = JSON.parse(log); + return ( -
+
+ {message === "Migration logs will appear here once the process begins." - ?
-
{message}
-
- :
+ ?
+
{message}
: +
{index}
-
{ timestamp ? new Date(timestamp)?.toTimeString()?.split(' ')[0] : new Date()?.toTimeString()?.split(' ')[0]}
-
{message}
-
+
+ {timestamp ? new Date(timestamp)?.toTimeString()?.split(' ')[0] : new Date()?.toTimeString()?.split(' ')[0]} +
+
{message}
+
}
); @@ -213,7 +249,7 @@ const TestMigrationLogViewer = ({ serverPath, sendDataToParent,projectId }: Logs
{/* Action buttons for scrolling and zooming */} - {!migratedTestStack?.isMigrated && !logs?.some((log) => log === "Migration logs will appear here once the process begins.") && ( + {!migratedTestStack?.isMigrated && !logs?.some((log) => log.message === "Migration logs will appear here once the process begins.") && (
From 22770e091ac84646692bdf2eec9bb87c3f928d0f Mon Sep 17 00:00:00 2001 From: AishDani Date: Thu, 16 Jan 2025 11:48:41 +0530 Subject: [PATCH 4/8] refactor:removedcommented code --- .../LegacyCms/Actions/LoadFileFormat.tsx | 2 +- .../LogScreen/MigrationLogViewer.tsx | 33 ++++--------------- ui/src/components/LogScreen/index.tsx | 19 +++-------- 3 files changed, 12 insertions(+), 42 deletions(-) diff --git a/ui/src/components/LegacyCms/Actions/LoadFileFormat.tsx b/ui/src/components/LegacyCms/Actions/LoadFileFormat.tsx index fdd9c094..d96f647b 100644 --- a/ui/src/components/LegacyCms/Actions/LoadFileFormat.tsx +++ b/ui/src/components/LegacyCms/Actions/LoadFileFormat.tsx @@ -74,7 +74,7 @@ const LoadFileFormat = (props: LoadFileFormatProps) => { const cmsType = !isEmptyString(newMigrationData?.legacy_cms?.selectedCms?.parent) ? newMigrationData?.legacy_cms?.selectedCms?.parent : data?.cmsType?.toLowerCase(); const filePath = data?.localPath?.toLowerCase(); const fileFormat = getFileExtension(filePath); - if(! isEmptyString(selectedCard?.fileformat_id) && selectedCard?.fileformat_id === fileFormat){ + if(! isEmptyString(selectedCard?.fileformat_id) && selectedCard?.fileformat_id !== fileFormat && newMigrationData?.project_current_step > 1){ setFileIcon(selectedCard?.title); } else{ diff --git a/ui/src/components/LogScreen/MigrationLogViewer.tsx b/ui/src/components/LogScreen/MigrationLogViewer.tsx index 3591ba33..d51f7efa 100644 --- a/ui/src/components/LogScreen/MigrationLogViewer.tsx +++ b/ui/src/components/LogScreen/MigrationLogViewer.tsx @@ -52,8 +52,7 @@ export interface LogEntry { * @param {string} serverPath - The path of the server to connect to. */ const MigrationLogViewer = ({ serverPath }: LogsType) => { - const [logs, setLogs] = useState([ - { message: "Migration logs will appear here once the process begins.", level: '' }]); + const [logs, setLogs] = useState([{ message: "Migration logs will appear here once the process begins.", level: '' }]); const [isModalOpen, setIsModalOpen] = useState(false); const [zoomLevel, setZoomLevel] = useState(1); @@ -82,19 +81,12 @@ const MigrationLogViewer = ({ serverPath }: LogsType) => { * @param {string} newLogs - The new logs received from the server. */ socket.on('logUpdate', (newLogs: string) => { - //const logArray = (newLogs: string) =>{ - //try { const parsedLogsArray: LogEntry[] = []; const logArray = newLogs?.split('\n') - //const parsedLogs = JSON?.parse(logArray); - // const plogs = { - // level: parsedLogs.level || 'info', - // message: parsedLogs.message || 'Unknown message', - // timestamp: parsedLogs.timestamp || null, - // }; + logArray?.forEach((logLine) => { try { - // Attempt to parse each log entry as a JSON object + //parse each log entry as a JSON object const parsedLog = JSON?.parse(logLine); // Build the log object with default values @@ -108,21 +100,10 @@ const MigrationLogViewer = ({ serverPath }: LogsType) => { console.log("error in parsing logs : ", error); } }); - //return plogs; - //const logArray = newLogs.split('\n'); - setLogs((prevLogs) => [...prevLogs, ...parsedLogsArray]); - //} - - //setLogs((prevLogs) => [...prevLogs, plogs]); - //const logArray = newLogs.split('\n'); - //setLogs(logArray); - - // } catch (error) { - // console.error('Failed to parse logUpdate data:', newLogs, error); - - // } - - }) + + setLogs((prevLogs) => [...prevLogs, ...parsedLogsArray]); + }); + return () => { socket.disconnect(); // Cleanup on component unmount }; diff --git a/ui/src/components/LogScreen/index.tsx b/ui/src/components/LogScreen/index.tsx index 59dcf9ed..215ec3ca 100644 --- a/ui/src/components/LogScreen/index.tsx +++ b/ui/src/components/LogScreen/index.tsx @@ -40,8 +40,7 @@ type LogsType = { * @param {string} projectId - The project ID for saving state to local storage. */ const TestMigrationLogViewer = ({ serverPath, sendDataToParent,projectId }: LogsType) => { - const [logs, setLogs] = useState([ - { message: "Migration logs will appear here once the process begins.", level: ''}]); + const [logs, setLogs] = useState([{ message: "Migration logs will appear here once the process begins.", level: ''}]); const newMigrationData = useSelector((state: RootState) => state?.migration?.newMigrationData); @@ -64,23 +63,21 @@ const TestMigrationLogViewer = ({ serverPath, sendDataToParent,projectId }: Logs * @param {string} newLogs - The new logs received from the server. */ socket.on('logUpdate', (newLogs: string) => { - console.log("logs ::::: ", newLogs); const parsedLogsArray: LogEntry[] = []; const logArray = newLogs?.split('\n') - //const logArray = newLogs?.forEach(()=>{}) split('\n'); logArray?.forEach((logLine) => { try { - // Attempt to parse each log entry as a JSON object + // parse each log entry as a JSON object const parsedLog = JSON.parse(logLine); - // Build the log object with default values const plogs = { level: parsedLog.level || 'info', message: parsedLog.message || 'Unknown message', timestamp: parsedLog.timestamp || null, }; parsedLogsArray.push(plogs); + }catch(error){ console.log("error in parsing logs : ", error); } @@ -212,21 +209,13 @@ const TestMigrationLogViewer = ({ serverPath, sendDataToParent,projectId }: Logs transition: "transform 0.1s ease" }}> {logs?.map((log, index) => { - // const key = `${index}-${new Date().getMilliseconds()}` try { - - //logObject = JSON.parse(log); const { level, timestamp, message } = log; - - //const logObject = JSON.parse(log); return (
- + > {message === "Migration logs will appear here once the process begins." ?
{message}
: From f4b330b752dfe498e58159adfd6386943bf5c9bd Mon Sep 17 00:00:00 2001 From: AishDani Date: Thu, 16 Jan 2025 12:00:12 +0530 Subject: [PATCH 5/8] refactor:added code which was removed --- .../LogScreen/MigrationLogViewer.tsx | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/ui/src/components/LogScreen/MigrationLogViewer.tsx b/ui/src/components/LogScreen/MigrationLogViewer.tsx index d51f7efa..2b90c7d6 100644 --- a/ui/src/components/LogScreen/MigrationLogViewer.tsx +++ b/ui/src/components/LogScreen/MigrationLogViewer.tsx @@ -240,21 +240,28 @@ const MigrationLogViewer = ({ serverPath }: LogsType) => { const { level, timestamp, message } = log; return ( + newMigrationData?.destination_stack?.migratedStacks?.includes(newMigrationData?.destination_stack?.selectedStack?.value) ? +
+
Migration has already done in selected stack. Please create a new project.
+
+ :
- {message === "Migration logs will appear here once the process begins." - ?
-
{message}
: -
+ {message === "Migration logs will appear here once the process begins." + ?
+
{message}
+
: +
{index}
- {timestamp ? new Date(timestamp)?.toTimeString()?.split(' ')[0] : new Date()?.toTimeString()?.split(' ')[0]} + {timestamp ? new Date(timestamp)?.toTimeString()?.split(' ')[0] : + new Date()?.toTimeString()?.split(' ')[0]}
-
{message}
-
+
{message}
+
}
); From 7c4e2183299c418ed40282a4a22c3a159d5231f0 Mon Sep 17 00:00:00 2001 From: Sayali Joshi Date: Thu, 16 Jan 2025 17:59:38 +0530 Subject: [PATCH 6/8] Resolved Icons issue on Logger panel --- ui/src/components/LogScreen/MigrationLogViewer.tsx | 2 +- ui/src/components/LogScreen/index.tsx | 2 +- ui/src/components/TestMigration/index.tsx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ui/src/components/LogScreen/MigrationLogViewer.tsx b/ui/src/components/LogScreen/MigrationLogViewer.tsx index 2b90c7d6..5cfe82e4 100644 --- a/ui/src/components/LogScreen/MigrationLogViewer.tsx +++ b/ui/src/components/LogScreen/MigrationLogViewer.tsx @@ -273,7 +273,7 @@ const MigrationLogViewer = ({ serverPath }: LogsType) => {
}
- {!newMigrationData?.migration_execution?.migrationCompleted && ( + {!newMigrationData?.migration_execution?.migrationCompleted && !logs?.every((log) => log.message === "Migration logs will appear here once the process begins.") && (
diff --git a/ui/src/components/LogScreen/index.tsx b/ui/src/components/LogScreen/index.tsx index 215ec3ca..8d4171dc 100644 --- a/ui/src/components/LogScreen/index.tsx +++ b/ui/src/components/LogScreen/index.tsx @@ -238,7 +238,7 @@ const TestMigrationLogViewer = ({ serverPath, sendDataToParent,projectId }: Logs
{/* Action buttons for scrolling and zooming */} - {!migratedTestStack?.isMigrated && !logs?.some((log) => log.message === "Migration logs will appear here once the process begins.") && ( + {!migratedTestStack?.isMigrated && !logs?.every((log) => log.message === "Migration logs will appear here once the process begins.") && (
diff --git a/ui/src/components/TestMigration/index.tsx b/ui/src/components/TestMigration/index.tsx index 6b800ccc..80a1ffcd 100644 --- a/ui/src/components/TestMigration/index.tsx +++ b/ui/src/components/TestMigration/index.tsx @@ -75,7 +75,7 @@ const TestMigration = () => { ? !newMigrationData?.testStacks?.some( (stack) => stack?.stackUid === newMigrationData?.test_migration?.stack_api_key && - stack.isMigrated + stack?.isMigrated ) || newMigrationData?.test_migration?.isMigrationStarted : newMigrationData?.migration_execution?.migrationCompleted || newMigrationData?.migration_execution?.migrationStarted || false; From 02bd405680a1c01cc68f8d8cdfe8392c641d4b3d Mon Sep 17 00:00:00 2001 From: AishDani Date: Thu, 16 Jan 2025 22:24:40 +0530 Subject: [PATCH 7/8] refactor:displaying test migration completed message in terminal on UI --- ui/src/components/LogScreen/index.tsx | 50 +++++++++++++++++++++------ 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/ui/src/components/LogScreen/index.tsx b/ui/src/components/LogScreen/index.tsx index 8d4171dc..b3659bf0 100644 --- a/ui/src/components/LogScreen/index.tsx +++ b/ui/src/components/LogScreen/index.tsx @@ -9,7 +9,7 @@ import { RootState } from '../../store'; import { updateNewMigrationData } from '../../store/slice/migrationDataSlice'; // Interface -import { INewMigration } from '../../context/app/app.interface'; +import { INewMigration, TestStacks } from '../../context/app/app.interface'; // CSS import './index.scss'; @@ -44,9 +44,19 @@ const TestMigrationLogViewer = ({ serverPath, sendDataToParent,projectId }: Logs const newMigrationData = useSelector((state: RootState) => state?.migration?.newMigrationData); + const [migratedStack, setmigratedSatck] = useState( + (newMigrationData?.testStacks ?? [])?.find((test) => test?.stackUid === newMigrationData?.test_migration?.stack_api_key)); + const [isLogsLoading, setisLogsLoading] = useState(false) // Redux dispatcher const dispatch = useDispatch(); + + + useEffect(()=>{ + const migratedTestStack = newMigrationData?.testStacks?.find((test) => test?.stackUid === newMigrationData?.test_migration?.stack_api_key); + setmigratedSatck(migratedTestStack); + },[newMigrationData?.test_migration]); + // Set up WebSocket connection useEffect(() => { const socket = io(serverPath || '',{ @@ -63,6 +73,7 @@ const TestMigrationLogViewer = ({ serverPath, sendDataToParent,projectId }: Logs * @param {string} newLogs - The new logs received from the server. */ socket.on('logUpdate', (newLogs: string) => { + setisLogsLoading(true); const parsedLogsArray: LogEntry[] = []; const logArray = newLogs?.split('\n') @@ -145,19 +156,19 @@ const TestMigrationLogViewer = ({ serverPath, sendDataToParent,projectId }: Logs const logsContainerRef = useRef(null); - const migratedTestStack = newMigrationData?.testStacks?.find((test) => test?.stackUid === newMigrationData?.test_migration?.stack_api_key) useEffect(() => { if (logsContainerRef.current) { logsContainerRef.current.scrollTop = logsContainerRef.current.scrollHeight; } - logs?.forEach((log) => { + logs?.forEach((log: LogEntry) => { try { //const logObject = JSON.parse(log); const message = log?.message; if (message === "Test Migration Process Completed") { + setisLogsLoading(false); // Save test migration state to local storage saveStateToLocalStorage(`testmigration_${projectId}`, { @@ -174,11 +185,21 @@ const TestMigrationLogViewer = ({ serverPath, sendDataToParent,projectId }: Logs type: 'success' }); sendDataToParent?.(false); - + const stacks = newMigrationData?.testStacks?.length > 0 ? + newMigrationData?.testStacks?.map((stack)=> + stack?.stackUid === newMigrationData?.test_migration?.stack_api_key + ? { + ...stack, + stackName: newMigrationData?.test_migration?.stack_name, + isMigrated: true + } + : stack + ) : [{stackUid: newMigrationData?.test_migration?.stack_api_key, stackName: newMigrationData?.test_migration?.stack_name, isMigrated: true}] + // Update testStacks data in Redux const newMigrationObj: INewMigration = { ...newMigrationData, - testStacks: [...newMigrationData?.testStacks ?? [], {stackUid: newMigrationData?.test_migration?.stack_api_key, stackName: newMigrationData?.test_migration?.stack_name, isMigrated: true}], + testStacks: stacks, test_migration:{ ...newMigrationData?.test_migration, isMigrationComplete:true, @@ -194,14 +215,22 @@ const TestMigrationLogViewer = ({ serverPath, sendDataToParent,projectId }: Logs }); }, [logs]); + useEffect(()=>{ + if(! isLogsLoading && !migratedStack?.isMigrated){ + setLogs([{ message: "Migration logs will appear here once the process begins.", level: ''}]); + } + + },[isLogsLoading, migratedStack?.isMigrated]); + + return (
{/* Logs container */}
- {migratedTestStack?.isMigrated + {migratedStack?.isMigrated ?
-
Test Migration is completed for stack {migratedTestStack?.stackName}
-
+
Test Migration is completed for stack {migratedStack?.stackName}
+
:
{message === "Migration logs will appear here once the process begins." ?
-
{message}
: +
{message}
+
:
{index}
@@ -238,7 +268,7 @@ const TestMigrationLogViewer = ({ serverPath, sendDataToParent,projectId }: Logs
{/* Action buttons for scrolling and zooming */} - {!migratedTestStack?.isMigrated && !logs?.every((log) => log.message === "Migration logs will appear here once the process begins.") && ( + {!migratedStack?.isMigrated && !logs?.some((log) => log.message === "Migration logs will appear here once the process begins.") && (
From 87c40e472be7066c5cafe97235f5811ef7872c97 Mon Sep 17 00:00:00 2001 From: AishDani Date: Thu, 16 Jan 2025 22:29:59 +0530 Subject: [PATCH 8/8] refactor:reverted code of icon issue --- ui/src/components/LogScreen/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/src/components/LogScreen/index.tsx b/ui/src/components/LogScreen/index.tsx index b3659bf0..800fb527 100644 --- a/ui/src/components/LogScreen/index.tsx +++ b/ui/src/components/LogScreen/index.tsx @@ -268,7 +268,7 @@ const TestMigrationLogViewer = ({ serverPath, sendDataToParent,projectId }: Logs
{/* Action buttons for scrolling and zooming */} - {!migratedStack?.isMigrated && !logs?.some((log) => log.message === "Migration logs will appear here once the process begins.") && ( + {!migratedStack?.isMigrated && !logs?.every((log) => log.message === "Migration logs will appear here once the process begins.") && (