Skip to content

Commit

Permalink
fix(log): fixed single chunk display
Browse files Browse the repository at this point in the history
  • Loading branch information
YuryShkoda committed Apr 18, 2023
1 parent 75f5a3c commit 8254b78
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
31 changes: 21 additions & 10 deletions web/src/containers/Studio/internal/components/log/logChunk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Highlight from 'react-highlight'
import { ErrorOutline, Warning } from '@mui/icons-material'
import ContentCopyIcon from '@mui/icons-material/ContentCopy'
import ExpandMoreIcon from '@mui/icons-material/ExpandMore'
import CheckIcon from '@mui/icons-material/Check'
import { makeStyles } from '@mui/styles'
import {
defaultChunkSize,
Expand Down Expand Up @@ -44,9 +45,9 @@ interface LogChunkProps {

const LogChunk = (props: LogChunkProps) => {
const { id, text, logLineCount, scrollToLogInstance } = props

const classes = useStyles()
const [expanded, setExpanded] = useState(props.expanded)
const [copied, setCopied] = useState(false)

useEffect(() => {
setExpanded(props.expanded)
Expand Down Expand Up @@ -107,16 +108,26 @@ const LogChunk = (props: LogChunkProps) => {
? (id + 1) * defaultChunkSize
: logLineCount
}`}</span>
<ContentCopyIcon
style={{ fontSize: 20 }}
onClick={(evt: SyntheticEvent) => {
evt.stopPropagation()
{copied ? (
<CheckIcon style={{ fontSize: 20, color: 'green' }} />
) : (
<ContentCopyIcon
style={{ fontSize: 20 }}
onClick={(evt: SyntheticEvent) => {
evt.stopPropagation()

navigator.clipboard.writeText(
clearErrorsAndWarningsHtmlWrapping(text)
)
}}
/>
navigator.clipboard.writeText(
clearErrorsAndWarningsHtmlWrapping(text)
)

setCopied(true)

setTimeout(() => {
setCopied(false)
}, 1000)
}}
/>
)}
{errors && errors.length !== 0 && (
<ErrorOutline color="error" style={{ fontSize: 20 }} />
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ const LogComponent = (props: LogComponentProps) => {
const [logChunksState, setLogChunksState] = useState<boolean[]>(
new Array(logChunks.length).fill(false)
)

const [scrollToLogInstance, setScrollToLogInstance] = useState<LogInstance>()
const [oldestExpandedChunk, setOldestExpandedChunk] = useState<number>(
logChunksState.length - 1
Expand Down
4 changes: 2 additions & 2 deletions web/src/utils/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ export const isTheLastChunk = (
}

export const splitIntoChunks = (log: string, chunkSize = defaultChunkSize) => {
if (!log.length) return []
if (!log) return []

const logLines: string[] = log.split(`\n`)

if (logLines.length <= chunkSize) return log
if (logLines.length <= chunkSize) return [log]

const chunks: string[] = []

Expand Down

0 comments on commit 8254b78

Please sign in to comment.