-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add log read mod: change key mod: code review mod: add template import mod: code review
- Loading branch information
Showing
20 changed files
with
530 additions
and
60 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
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
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,62 @@ | ||
@import '~@app/common.less'; | ||
.log-modal { | ||
height: 100vh; | ||
.ant-modal { | ||
height: 80%; | ||
.ant-modal-content { | ||
height: 100%; | ||
} | ||
} | ||
.import-modal-title { | ||
display: flex; | ||
align-items: center; | ||
} | ||
.ant-modal-header { | ||
border-bottom: none; | ||
padding-right: 80px; | ||
padding-top: 15px; | ||
.ant-modal-title { | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
} | ||
.ant-modal-close { | ||
top: 5px; | ||
} | ||
} | ||
.ant-modal-body { | ||
display: flex; | ||
height: 91%; | ||
} | ||
.log-container { | ||
width: 100%; | ||
height: 100%; | ||
overflow: auto; | ||
padding: 10px 20px 120px; | ||
font-size: 18px; | ||
text-align: left; | ||
background: #333; | ||
color: #fff; | ||
word-break: break-all; | ||
} | ||
} | ||
.log-tab { | ||
max-height: 65vh; | ||
.ant-tabs-nav { | ||
width: 200px; | ||
.ant-tabs-tab { | ||
background-color: @lightGray; | ||
color: @darkBlue; | ||
} | ||
.ant-tabs-tab-active { | ||
background-color: #0091FF; | ||
color: #fff; | ||
.ant-tabs-tab-btn { | ||
color: #fff; | ||
} | ||
} | ||
} | ||
.ant-tabs-content-holder > .ant-tabs-content { | ||
display: none | ||
} | ||
} |
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,131 @@ | ||
import { Button, Modal, Tabs } from 'antd'; | ||
import _ from 'lodash'; | ||
import React, { useEffect, useRef, useState } from 'react'; | ||
import intl from 'react-intl-universal'; | ||
import Icon from '@app/components/Icon'; | ||
import './index.less'; | ||
import { useStore } from '@app/stores'; | ||
import { ITaskStatus } from '@app/interfaces/import'; | ||
|
||
const { TabPane } = Tabs; | ||
|
||
interface ILogDimension { | ||
space: string; | ||
id: number; | ||
status: ITaskStatus; | ||
} | ||
|
||
interface ILog { | ||
name: string; | ||
path: string; | ||
} | ||
interface IProps { | ||
logDimension: ILogDimension; | ||
visible: boolean; | ||
onCancel: () => void; | ||
} | ||
const LogModal = (props: IProps) => { | ||
const { visible, onCancel, logDimension: { space, id, status } } = props; | ||
const { dataImport: { getLogs, downloadTaskLog, getImportLogDetail, getErrLogDetail } } = useStore(); | ||
const logRef = useRef<HTMLDivElement>(null); | ||
const timer = useRef<any>(null); | ||
const offset = useRef(0); | ||
const _status = useRef(status); | ||
const [logs, setLogs] = useState<ILog[]>([]); | ||
const [currentLog, setCurrentLog] = useState<ILog | null>(null); | ||
const handleTabChange = (key: string) => { | ||
setCurrentLog(logs.filter(item => item.name === key)[0]); | ||
}; | ||
|
||
const getAllLogs = async() => { | ||
const { code, data } = await getLogs(id); | ||
if(code === 0) { | ||
setLogs(data); | ||
setCurrentLog(data[0]); | ||
} | ||
}; | ||
|
||
const handleLogDownload = () => { | ||
if(currentLog) { | ||
downloadTaskLog(currentLog.path); | ||
} | ||
}; | ||
|
||
const readLog = async() => { | ||
const getLogDetail = currentLog!.name === 'import.log' ? getImportLogDetail : getErrLogDetail; | ||
const res = await getLogDetail({ | ||
offset: offset.current, | ||
taskId: id, | ||
path: currentLog!.path | ||
}); | ||
handleLogData(res); | ||
}; | ||
|
||
const handleLogData = (res) => { | ||
const { data } = res; | ||
if(!logRef.current) { | ||
timer.current = setTimeout(readLog, 2000); | ||
return; | ||
} | ||
if (data) { | ||
logRef.current.innerHTML += data.join('<br/>') + '<br/>'; | ||
logRef.current.scrollTop = logRef.current.scrollHeight; | ||
offset.current += data.length; | ||
timer.current = setTimeout(readLog, 2000); | ||
} else if (_status.current === ITaskStatus.StatusProcessing) { | ||
timer.current = setTimeout(readLog, 2000); | ||
} else { | ||
offset.current = 0; | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
getAllLogs(); | ||
return () => { | ||
clearTimeout(timer.current); | ||
}; | ||
}, []); | ||
|
||
useEffect(() => { | ||
_status.current = status; | ||
}, [status]); | ||
useEffect(() => { | ||
clearTimeout(timer.current); | ||
if(logRef.current) { | ||
logRef.current.innerHTML = ''; | ||
} | ||
offset.current = 0; | ||
if(currentLog) { | ||
readLog(); | ||
} | ||
}, [currentLog]); | ||
return ( | ||
<Modal | ||
title={<> | ||
<div className="import-modal-title"> | ||
<span>{`${space} ${intl.get('import.task')} - ${intl.get('common.log')}`}</span> | ||
{status === ITaskStatus.StatusProcessing && <Button type="text" loading={true} />} | ||
</div> | ||
<Button className="studio-add-btn primary-btn" onClick={handleLogDownload}> | ||
<Icon type="icon-studio-btn-download" /> | ||
{intl.get('import.downloadLog')} | ||
</Button> | ||
</>} | ||
width="80%" | ||
visible={visible} | ||
onCancel={onCancel} | ||
wrapClassName="log-modal" | ||
destroyOnClose={true} | ||
footer={false} | ||
> | ||
<Tabs className="log-tab" tabBarGutter={0} tabPosition="left" onChange={handleTabChange}> | ||
{logs.map(log => ( | ||
<TabPane tab={`${log.name}`} key={log.name} /> | ||
))} | ||
</Tabs> | ||
<div className="log-container" ref={logRef}/> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default LogModal; |
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 |
---|---|---|
|
@@ -38,6 +38,9 @@ | |
& > span { | ||
margin-right: 6px | ||
} | ||
.red { | ||
color: @red | ||
} | ||
} | ||
.err-info { | ||
color: @red | ||
|
Oops, something went wrong.