-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from catalystneuro/feature/previous-project-logs
feat: add previous project logs button
- Loading branch information
Showing
12 changed files
with
244 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React, { useCallback, useEffect, useRef, useState } from 'react'; | ||
import { TerminalDiv } from './styles'; | ||
import { get } from '../../utils/requests'; | ||
|
||
interface TerminalProps { | ||
logName?: string; | ||
projectPath: string; | ||
} | ||
|
||
const LogComponent: React.FC<TerminalProps> = ({ logName,projectPath }) => { | ||
const logRef = useRef<HTMLUListElement>(null); | ||
const [logs, setLogs] = useState(''); | ||
|
||
const fetchLogs = useCallback(async () => { | ||
try { | ||
let uri = "log" | ||
if (logName && projectPath) uri = `log/${logName}?project=${projectPath}` | ||
const url = encodeURI(uri) | ||
|
||
const logResponse = await get(url, { 'Content-Type': 'text/plain' }) | ||
setLogs(logResponse as string); | ||
} catch { | ||
setLogs(logName ? `No log files found for: ${logName}` : `No log files found.`); | ||
} | ||
},[logName,projectPath]) | ||
|
||
useEffect(() => { | ||
fetchLogs() | ||
}, []); | ||
|
||
useEffect(() => { | ||
logRef.current?.lastElementChild?.scrollIntoView() | ||
}, [logs]); | ||
|
||
|
||
if (!logs) return (<TerminalDiv id={logName ? `terminal-${logName}` : "terminal"}><li><span>Loading {logName} logs file...</span></li></TerminalDiv>) | ||
|
||
return ( | ||
<TerminalDiv ref={logRef} id={logName ? `terminal-${logName}` : "terminal"}> | ||
{logs.split('\n').map((line, index) => ( | ||
<li key={index}> | ||
<span> | ||
{line} | ||
</span> | ||
</li> | ||
))} | ||
</TerminalDiv> | ||
); | ||
}; | ||
|
||
export default LogComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { FC, MouseEventHandler, useCallback, useRef } from "react"; | ||
import LogComponent from "./LogComponent"; | ||
import { BaseModalBackground, TerminalContainer } from "./styles"; | ||
|
||
interface ModalProps { | ||
projectPath: string; | ||
logName: string | string[]; | ||
isOpen: boolean; | ||
onClose: () => void; | ||
} | ||
|
||
const TerminalModal: FC<ModalProps> = ({ isOpen, onClose, logName,projectPath }) => { | ||
|
||
const node = useRef(null) | ||
|
||
const handleBackgroundClick = useCallback<MouseEventHandler<HTMLDivElement>>((e)=>{ | ||
|
||
if (node.current === e.target) { | ||
onClose() | ||
} | ||
},[node]) | ||
|
||
return ( | ||
<> | ||
{isOpen && | ||
<BaseModalBackground onClick={handleBackgroundClick} ref={node}> | ||
{typeof logName === "string" ? <LogComponent logName={logName} projectPath={projectPath} /> : ( | ||
<TerminalContainer > | ||
{logName?.map(l=><LogComponent key={l} logName={l} projectPath={projectPath} />)} | ||
</TerminalContainer> | ||
)} | ||
</BaseModalBackground>} | ||
</> | ||
) | ||
} | ||
|
||
export default TerminalModal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import styled from 'styled-components'; | ||
|
||
export const BaseModalBackground = styled.div` | ||
display: flex; | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
width: 100vw; | ||
height: 100vh; | ||
z-index: 30; | ||
background-color: rgba(0, 0, 0, 0.5); | ||
align-items: center; | ||
justify-content: center; | ||
` | ||
|
||
export const TerminalContainer = styled.div` | ||
border-radius: 20px; | ||
overflow: hidden; | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: space-between; | ||
width: 80%; | ||
height: 80%; | ||
max-width: 80%; | ||
max-height: 80%; | ||
`; | ||
|
||
export const TerminalDiv = styled.ul` | ||
width: 100%; | ||
margin: 0; | ||
scroll-behavior: smooth; | ||
list-style: none; | ||
padding: 10px; | ||
overflow: hidden; | ||
background-color: #181c24; | ||
overflow-y: auto !important; | ||
color: white; | ||
font-family: monospace; | ||
font-size: 12px; | ||
li { | ||
padding: 5px; | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.