1
- import React , { Fragment , useState } from "react" ;
1
+ // This file is part of MinIO Console Server
2
+ // Copyright (c) 2021 MinIO, Inc.
3
+ //
4
+ // This program is free software: you can redistribute it and/or modify
5
+ // it under the terms of the GNU Affero General Public License as published by
6
+ // the Free Software Foundation, either version 3 of the License, or
7
+ // (at your option) any later version.
8
+ //
9
+ // This program is distributed in the hope that it will be useful,
10
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ // GNU Affero General Public License for more details.
13
+ //
14
+ // You should have received a copy of the GNU Affero General Public License
15
+ // along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ import React , { Fragment , useState , useEffect } from "react" ;
2
18
import PageHeader from "../Common/PageHeader/PageHeader" ;
3
- import { Grid } from "@material-ui/core" ;
19
+ import { Grid , LinearProgress } from "@material-ui/core" ;
4
20
import { createStyles , Theme , withStyles } from "@material-ui/core/styles" ;
5
21
import Tab from "@material-ui/core/Tab" ;
6
22
import Tabs from "@material-ui/core/Tabs" ;
23
+ import { containerForHeader } from "../Common/FormComponents/common/styleLibrary" ;
7
24
import ErrorLogs from "./ErrorLogs/ErrorLogs" ;
8
25
import LogsSearchMain from "./LogSearch/LogsSearchMain" ;
9
- import { containerForHeader } from "../Common/FormComponents /common/styleLibrary " ;
26
+ import api from "../../.. /common/api " ;
10
27
11
28
interface ILogsMainProps {
12
29
classes : any ;
@@ -25,37 +42,59 @@ const styles = (theme: Theme) =>
25
42
26
43
const LogsMain = ( { classes } : ILogsMainProps ) => {
27
44
const [ currentTab , setCurrentTab ] = useState < number > ( 0 ) ;
45
+ const [ loading , setLoading ] = useState < boolean > ( true ) ;
46
+ const [ showLogSearch , setShowLogSearch ] = useState < boolean > ( false ) ;
47
+
48
+ useEffect ( ( ) => {
49
+ api
50
+ . invoke ( "GET" , `/api/v1/logs/search?q=reqinfo&pageSize=10&pageNo=0` )
51
+ . then ( ( ) => {
52
+ setShowLogSearch ( true ) ;
53
+ setLoading ( false ) ;
54
+ } )
55
+ . catch ( ( err : any ) => {
56
+ setLoading ( false ) ;
57
+ console . info ( "Log Search API not available." ) ;
58
+ } ) ;
59
+ } , [ loading ] ) ;
60
+
28
61
return (
29
62
< Fragment >
30
63
< PageHeader label = "Logs" />
31
64
< Grid container >
32
65
< Grid item xs = { 12 } className = { classes . container } >
33
- < Grid item xs = { 12 } className = { classes . headerLabel } >
34
- All Logs
35
- </ Grid >
36
- < Tabs
37
- value = { currentTab }
38
- onChange = { ( e : React . ChangeEvent < { } > , newValue : number ) => {
39
- setCurrentTab ( newValue ) ;
40
- } }
41
- indicatorColor = "primary"
42
- textColor = "primary"
43
- aria-label = "cluster-tabs"
44
- >
45
- < Tab label = "Error Logs" />
46
- < Tab label = "Logs Search" />
47
- </ Tabs >
48
- </ Grid >
49
- < Grid item xs = { 12 } >
50
- { currentTab === 0 && (
51
- < Grid item xs = { 12 } >
52
- < ErrorLogs />
53
- </ Grid >
54
- ) }
55
- { currentTab === 1 && (
56
- < Grid item xs = { 12 } >
57
- < LogsSearchMain />
58
- </ Grid >
66
+ { ! loading ? (
67
+ < Fragment >
68
+ < Grid item xs = { 12 } className = { classes . headerLabel } >
69
+ All Logs
70
+ </ Grid >
71
+ < Tabs
72
+ value = { currentTab }
73
+ onChange = { ( e : React . ChangeEvent < { } > , newValue : number ) => {
74
+ setCurrentTab ( newValue ) ;
75
+ } }
76
+ indicatorColor = "primary"
77
+ textColor = "primary"
78
+ aria-label = "cluster-tabs"
79
+ >
80
+ < Tab label = "Error Logs" />
81
+ { showLogSearch && < Tab label = "Logs Search" /> }
82
+ </ Tabs >
83
+ < Grid item xs = { 12 } >
84
+ { currentTab === 0 && (
85
+ < Grid item xs = { 12 } >
86
+ < ErrorLogs />
87
+ </ Grid >
88
+ ) }
89
+ { currentTab === 1 && showLogSearch && (
90
+ < Grid item xs = { 12 } >
91
+ < LogsSearchMain />
92
+ </ Grid >
93
+ ) }
94
+ </ Grid >
95
+ </ Fragment >
96
+ ) : (
97
+ < LinearProgress />
59
98
) }
60
99
</ Grid >
61
100
</ Grid >
0 commit comments