Skip to content

Commit

Permalink
feat(log): added time to downloaded log name
Browse files Browse the repository at this point in the history
  • Loading branch information
YuryShkoda committed Apr 27, 2023
1 parent 56a522c commit 3848bb0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const LogChunk = (props: LogChunkProps) => {
)}
<FileDownloadIcon
onClick={(evt: SyntheticEvent) => {
download(evt, rowText, `log.${getLineRange('-')}`)
download(evt, rowText, `.${getLineRange('-')}`)
}}
/>
{errors && errors.length !== 0 && (
Expand Down
20 changes: 14 additions & 6 deletions web/src/utils/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,27 @@ export const splitIntoChunks = (log: string, chunkSize = defaultChunkSize) => {
export const clearErrorsAndWarningsHtmlWrapping = (log: string) =>
log.replace(/^<font[^>]*>/gm, '').replace(/<\/font>/gm, '')

export const download = (
evt: SyntheticEvent,
log: string,
fileName = 'log'
) => {
export const download = (evt: SyntheticEvent, log: string, fileName = '') => {
evt.stopPropagation()

const padWithZero = (num: number) => (num < 9 ? `0${num}` : `${num}`)

const date = new Date()
const datePrefix = [
date.getFullYear(),
padWithZero(date.getMonth() + 1),
padWithZero(date.getDate()),
padWithZero(date.getHours()),
padWithZero(date.getMinutes()),
padWithZero(date.getSeconds())
].join('')

const file = new Blob([log])
const url = URL.createObjectURL(file)

const a = document.createElement('a')
a.href = url
a.download = `${fileName}.log`
a.download = `${datePrefix}${fileName}.log`
document.body.appendChild(a)
a.click()

Expand Down

0 comments on commit 3848bb0

Please sign in to comment.