fix:日志组件在没配置 source 的时候不发起请求 (#1548)

This commit is contained in:
吴多益 2021-02-05 11:24:20 +08:00 committed by GitHub
parent d7fae41a81
commit 939c85f61c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 3 deletions

View File

@ -100,6 +100,7 @@ register('en-US', {
'Image.sizeNotEqual': 'The image you selected does not meet the size requirements {{info}}',
'Image.width': 'width: {{width}}px',
'Image.zoomIn': 'Zoom In',
'Log.mustHaveSource': 'Must have source in config',
'link': 'Link',
'loading': 'Loading',
'LocationPicker.placeholder': 'Pick location',

View File

@ -101,6 +101,7 @@ register('zh-CN', {
'Image.sizeNotEqual': '请上传{{info}}的图片',
'Image.width': '宽度 {{width}}px',
'Image.zoomIn': '查看大图',
'Log.mustHaveSource': '需要配置 Source',
'link': '链接',
'loading': '加载中',
'LocationPicker.placeholder': '请选择位置',

View File

@ -93,7 +93,9 @@ export class Log extends React.Component<LogProps, LogState> {
this.pauseOrResumeScrolling
);
}
this.loadLogs();
if (this.props.source) {
this.loadLogs();
}
}
componentDidUpdate() {
@ -160,14 +162,20 @@ export class Log extends React.Component<LogProps, LogState> {
render() {
const {
source,
className,
classnames: cx,
render,
placeholder,
height,
translate: __
} = this.props;
let loading = __(placeholder);
if (!source) {
loading = __('Log.mustHaveSource');
}
const lines = this.state.logs.map((line, index) => {
return (
<div className={cx('Log-line')} key={index}>
@ -182,7 +190,7 @@ export class Log extends React.Component<LogProps, LogState> {
className={cx('Log', className)}
style={{height: height}}
>
{lines.length ? lines : __(placeholder)}
{lines.length ? lines : loading}
<div className={cx('Log-line')} key="last">
<code>{this.state.lastLine}</code>
</div>