1
0
mirror of https://github.com/sasjs/server.git synced 2025-12-11 19:44:35 +00:00

fix(log): fixed single chunk display

This commit is contained in:
Yury Shkoda
2023-04-18 15:46:53 +03:00
parent 75f5a3c0b3
commit 8254b78955
3 changed files with 23 additions and 13 deletions

View File

@@ -4,6 +4,7 @@ import Highlight from 'react-highlight'
import { ErrorOutline, Warning } from '@mui/icons-material' import { ErrorOutline, Warning } from '@mui/icons-material'
import ContentCopyIcon from '@mui/icons-material/ContentCopy' import ContentCopyIcon from '@mui/icons-material/ContentCopy'
import ExpandMoreIcon from '@mui/icons-material/ExpandMore' import ExpandMoreIcon from '@mui/icons-material/ExpandMore'
import CheckIcon from '@mui/icons-material/Check'
import { makeStyles } from '@mui/styles' import { makeStyles } from '@mui/styles'
import { import {
defaultChunkSize, defaultChunkSize,
@@ -44,9 +45,9 @@ interface LogChunkProps {
const LogChunk = (props: LogChunkProps) => { const LogChunk = (props: LogChunkProps) => {
const { id, text, logLineCount, scrollToLogInstance } = props const { id, text, logLineCount, scrollToLogInstance } = props
const classes = useStyles() const classes = useStyles()
const [expanded, setExpanded] = useState(props.expanded) const [expanded, setExpanded] = useState(props.expanded)
const [copied, setCopied] = useState(false)
useEffect(() => { useEffect(() => {
setExpanded(props.expanded) setExpanded(props.expanded)
@@ -107,6 +108,9 @@ const LogChunk = (props: LogChunkProps) => {
? (id + 1) * defaultChunkSize ? (id + 1) * defaultChunkSize
: logLineCount : logLineCount
}`}</span> }`}</span>
{copied ? (
<CheckIcon style={{ fontSize: 20, color: 'green' }} />
) : (
<ContentCopyIcon <ContentCopyIcon
style={{ fontSize: 20 }} style={{ fontSize: 20 }}
onClick={(evt: SyntheticEvent) => { onClick={(evt: SyntheticEvent) => {
@@ -115,8 +119,15 @@ const LogChunk = (props: LogChunkProps) => {
navigator.clipboard.writeText( navigator.clipboard.writeText(
clearErrorsAndWarningsHtmlWrapping(text) clearErrorsAndWarningsHtmlWrapping(text)
) )
setCopied(true)
setTimeout(() => {
setCopied(false)
}, 1000)
}} }}
/> />
)}
{errors && errors.length !== 0 && ( {errors && errors.length !== 0 && (
<ErrorOutline color="error" style={{ fontSize: 20 }} /> <ErrorOutline color="error" style={{ fontSize: 20 }} />
)} )}

View File

@@ -47,7 +47,6 @@ const LogComponent = (props: LogComponentProps) => {
const [logChunksState, setLogChunksState] = useState<boolean[]>( const [logChunksState, setLogChunksState] = useState<boolean[]>(
new Array(logChunks.length).fill(false) new Array(logChunks.length).fill(false)
) )
const [scrollToLogInstance, setScrollToLogInstance] = useState<LogInstance>() const [scrollToLogInstance, setScrollToLogInstance] = useState<LogInstance>()
const [oldestExpandedChunk, setOldestExpandedChunk] = useState<number>( const [oldestExpandedChunk, setOldestExpandedChunk] = useState<number>(
logChunksState.length - 1 logChunksState.length - 1

View File

@@ -81,11 +81,11 @@ export const isTheLastChunk = (
} }
export const splitIntoChunks = (log: string, chunkSize = defaultChunkSize) => { export const splitIntoChunks = (log: string, chunkSize = defaultChunkSize) => {
if (!log.length) return [] if (!log) return []
const logLines: string[] = log.split(`\n`) const logLines: string[] = log.split(`\n`)
if (logLines.length <= chunkSize) return log if (logLines.length <= chunkSize) return [log]
const chunks: string[] = [] const chunks: string[] = []