Skip to content

Commit e327df3

Browse files
authored
Merge pull request #150 from errsole/feat/auto-refresh-loading-icon
Feat/auto refresh loading icon
2 parents e396d7d + f446392 commit e327df3

File tree

1 file changed

+46
-9
lines changed

1 file changed

+46
-9
lines changed

lib/web/src/components/ConsoleLogs.js

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class ConsoleLogs extends React.Component {
7373
isAutoRefreshing: false,
7474
latestOnTop,
7575
showCancelButton: false,
76+
isAutoRefreshLoading: false,
7677
abortController: new AbortController()
7778
};
7879
}
@@ -122,8 +123,19 @@ class ConsoleLogs extends React.Component {
122123

123124
startAutoRefresh = () => {
124125
this.autoRefreshInterval = setInterval(() => {
125-
this.setState({ isAutoRefreshing: true });
126-
this.getConsoleLogs(null, 'autoRefresh');
126+
this.setState({ isAutoRefreshing: true, isAutoRefreshLoading: true });
127+
128+
const { currentConsoleLogs, latestOnTop } = this.state;
129+
let logId, datetime;
130+
if (currentConsoleLogs.length > 0) {
131+
const topLog = latestOnTop === 'Newest First'
132+
? currentConsoleLogs[0]
133+
: currentConsoleLogs[currentConsoleLogs.length - 1];
134+
135+
logId = topLog?.id;
136+
datetime = topLog?.attributes?.timestamp;
137+
}
138+
this.getConsoleLogs({ logOrder: 'latest', logId, datetime }, 'autoRefresh');
127139
}, 5000);
128140
};
129141

@@ -407,7 +419,9 @@ class ConsoleLogs extends React.Component {
407419
this.setState({
408420
consoleLogLoading: false,
409421
showCancelButton: false,
410-
abortController: null
422+
abortController: null,
423+
isAutoRefreshLoading: false
424+
411425
});
412426
return;
413427
}
@@ -420,7 +434,11 @@ class ConsoleLogs extends React.Component {
420434
// no-search result
421435
if (!filters || Object.keys(filters).length === 0) {
422436
if (logs.length === 0) {
423-
this.notificationMsg('info', 'No logs to load with the applied filters.', '', 3);
437+
if (this.state.autoRefresh && this.state.isAutoRefreshing) {
438+
// skip showing notification during auto-refresh
439+
} else {
440+
this.notificationMsg('info', 'No logs to load with the applied filters.', '', 3);
441+
}
424442
} else {
425443
logs = this.combineLogs(logs, logOrder, latestOnTop);
426444
logs = this.removeDuplicateLogs(logs);
@@ -471,7 +489,8 @@ class ConsoleLogs extends React.Component {
471489
this.setState({
472490
consoleLogLoading: false,
473491
showCancelButton: false,
474-
abortController: null
492+
abortController: null,
493+
isAutoRefreshLoading: false
475494
});
476495
}
477496
);
@@ -884,6 +903,7 @@ class ConsoleLogs extends React.Component {
884903
const errorLogId = this.state.errorLogId || null;
885904
const errorLogHostname = this.state.errorLogHostname || null;
886905
const antIcon = <LoadingOutlined style={{ fontSize: 30 }} spin />;
906+
const antIconSmall = <LoadingOutlined style={{ fontSize: 20 }} spin />;
887907
const searchTerms = this.state.searchTerms || [];
888908
const activeLogMeta = this.state.activeLogMeta || null;
889909
const metaModalStatus = this.state.metaModalStatus || false;
@@ -1103,18 +1123,35 @@ class ConsoleLogs extends React.Component {
11031123
{this.state.latestOnTop === 'Newest First'
11041124
? (
11051125
<>
1106-
<p className='logs_more'>There may be newer logs to load. <a onClick={() => this.loadMoreErrors('latest')}>Load More</a> </p>
1126+
{this.state.isAutoRefreshLoading
1127+
? (
1128+
<p className='logs_more'><Spin indicator={antIconSmall} style={{ marginRight: 8 }} /> Fetching newer logs...</p>
1129+
)
1130+
: (
1131+
<p className='logs_more'>There may be newer logs to load. <a onClick={() => this.loadMoreErrors('latest')}>Load More</a></p>
1132+
)}
1133+
11071134
{renderConsoleLogs()}
1108-
<p className='logs_more'>There may be older logs to load. <a onClick={() => this.loadMoreErrors('old')}>Load More</a> </p>
1135+
1136+
<p className='logs_more'>There may be older logs to load. <a onClick={() => this.loadMoreErrors('old')}>Load More</a></p>
11091137
</>
11101138
)
11111139
: (
11121140
<>
1113-
<p className='logs_more'>There may be older logs to load. <a onClick={() => this.loadMoreErrors('old')}>Load More</a> </p>
1141+
<p className='logs_more'>There may be older logs to load. <a onClick={() => this.loadMoreErrors('old')}>Load More</a></p>
1142+
11141143
{renderConsoleLogs()}
1115-
<p className='logs_more'>There may be newer logs to load. <a onClick={() => this.loadMoreErrors('latest')}>Load More</a> </p>
1144+
1145+
{this.state.isAutoRefreshLoading
1146+
? (
1147+
<p className='logs_more'><Spin indicator={antIconSmall} style={{ marginRight: 8 }} />Fetching newer logs...</p>
1148+
)
1149+
: (
1150+
<p className='logs_more'>There may be newer logs to load. <a onClick={() => this.loadMoreErrors('latest')}>Load More</a></p>
1151+
)}
11161152
</>
11171153
)}
1154+
11181155
</Collapse>}
11191156
{currentConsoleLogs.length === 0 && <div className='ant-empty ant-empty-normal'><div className='ant-empty-image'><svg width='64' height='41' viewBox='0 0 64 41' xmlns='http://www.w3.org/2000/svg'><g transform='translate(0 1)' fill='none' fillRule='evenodd'><ellipse fill='#F5F5F5' cx='32' cy='33' rx='32' ry='7' /><g fillRule='nonzero' stroke='#D9D9D9'><path d='M55 12.76L44.854 1.258C44.367.474 43.656 0 42.907 0H21.093c-.749 0-1.46.474-1.947 1.257L9 12.761V22h46v-9.24z' /><path d='M41.613 15.931c0-1.605.994-2.93 2.227-2.931H55v18.137C55 33.26 53.68 35 52.05 35h-40.1C10.32 35 9 33.259 9 31.137V13h11.16c1.233 0 2.227 1.323 2.227 2.928v.022c0 1.605 1.005 2.901 2.237 2.901h14.752c1.232 0 2.237-1.308 2.237-2.913v-.007z' fill='#FAFAFA' /></g></g></svg></div><p className='ant-empty-description'>No Data</p></div>}
11201157
</div>

0 commit comments

Comments
 (0)