1515// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
1717import React , { Fragment , useState , useEffect } from "react" ;
18+ import { connect } from "react-redux" ;
1819import PageHeader from "../Common/PageHeader/PageHeader" ;
1920import { Grid , LinearProgress } from "@material-ui/core" ;
2021import { createStyles , Theme , withStyles } from "@material-ui/core/styles" ;
@@ -24,9 +25,11 @@ import { containerForHeader } from "../Common/FormComponents/common/styleLibrary
2425import ErrorLogs from "./ErrorLogs/ErrorLogs" ;
2526import LogsSearchMain from "./LogSearch/LogsSearchMain" ;
2627import api from "../../../common/api" ;
28+ import { AppState } from "../../../store" ;
2729
2830interface ILogsMainProps {
2931 classes : any ;
32+ features : string [ ] | null ;
3033}
3134
3235const styles = ( theme : Theme ) =>
@@ -40,68 +43,58 @@ const styles = (theme: Theme) =>
4043 ...containerForHeader ( theme . spacing ( 4 ) ) ,
4144 } ) ;
4245
43- const LogsMain = ( { classes } : ILogsMainProps ) => {
46+ const LogsMain = ( { classes, features } : ILogsMainProps ) => {
4447 const [ currentTab , setCurrentTab ] = useState < number > ( 0 ) ;
45- const [ loading , setLoading ] = useState < boolean > ( true ) ;
46- const [ showLogSearch , setShowLogSearch ] = useState < boolean > ( false ) ;
4748
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 ] ) ;
49+ const logSearchEnabled = features && features . includes ( "log-search" ) ;
6050
6151 return (
6252 < Fragment >
6353 < PageHeader label = "Logs" />
6454 < Grid container >
6555 < Grid item xs = { 12 } className = { classes . container } >
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- variant = "scrollable"
80- scrollButtons = "auto"
81- >
82- < Tab label = "Error Logs" />
83- { showLogSearch && < Tab label = "Logs Search" /> }
84- </ Tabs >
85- < Grid item xs = { 12 } >
86- { currentTab === 0 && (
87- < Grid item xs = { 12 } >
88- < ErrorLogs />
89- </ Grid >
90- ) }
91- { currentTab === 1 && showLogSearch && (
92- < Grid item xs = { 12 } >
93- < LogsSearchMain />
94- </ Grid >
95- ) }
96- </ Grid >
97- </ Fragment >
98- ) : (
99- < LinearProgress />
100- ) }
56+ < Fragment >
57+ < Grid item xs = { 12 } className = { classes . headerLabel } >
58+ All Logs
59+ </ Grid >
60+ < Tabs
61+ value = { currentTab }
62+ onChange = { ( e : React . ChangeEvent < { } > , newValue : number ) => {
63+ setCurrentTab ( newValue ) ;
64+ } }
65+ indicatorColor = "primary"
66+ textColor = "primary"
67+ aria-label = "cluster-tabs"
68+ variant = "scrollable"
69+ scrollButtons = "auto"
70+ >
71+ < Tab label = "Error Logs" />
72+ { logSearchEnabled && < Tab label = "Logs Search" /> }
73+ </ Tabs >
74+ < Grid item xs = { 12 } >
75+ { currentTab === 0 && (
76+ < Grid item xs = { 12 } >
77+ < ErrorLogs />
78+ </ Grid >
79+ ) }
80+ { currentTab === 1 &&
81+ logSearchEnabled && (
82+ < Grid item xs = { 12 } >
83+ < LogsSearchMain />
84+ </ Grid >
85+ ) }
86+ </ Grid >
87+ </ Fragment >
10188 </ Grid >
10289 </ Grid >
10390 </ Fragment >
10491 ) ;
10592} ;
10693
107- export default withStyles ( styles ) ( LogsMain ) ;
94+ const mapState = ( state : AppState ) => ( {
95+ features : state . console . session . features ,
96+ } ) ;
97+
98+ const connector = connect ( mapState , null ) ;
99+
100+ export default withStyles ( styles ) ( connector ( LogsMain ) ) ;
0 commit comments