Skip to content

Commit 38cf606

Browse files
bexsoftBenjamin Perezdvaldivia
authored
Added validation to Log Search module (#561)
Added validation to Log Search module so we can hide the log search option when API is not available Co-authored-by: Benjamin Perez <benjamin@bexsoft.net> Co-authored-by: Daniel Valdivia <hola@danielvaldivia.com>
1 parent 5e3f9ac commit 38cf606

File tree

1 file changed

+68
-29
lines changed

1 file changed

+68
-29
lines changed

portal-ui/src/screens/Console/Logs/LogsMain.tsx

Lines changed: 68 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
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";
218
import PageHeader from "../Common/PageHeader/PageHeader";
3-
import { Grid } from "@material-ui/core";
19+
import { Grid, LinearProgress } from "@material-ui/core";
420
import { createStyles, Theme, withStyles } from "@material-ui/core/styles";
521
import Tab from "@material-ui/core/Tab";
622
import Tabs from "@material-ui/core/Tabs";
23+
import { containerForHeader } from "../Common/FormComponents/common/styleLibrary";
724
import ErrorLogs from "./ErrorLogs/ErrorLogs";
825
import LogsSearchMain from "./LogSearch/LogsSearchMain";
9-
import { containerForHeader } from "../Common/FormComponents/common/styleLibrary";
26+
import api from "../../../common/api";
1027

1128
interface ILogsMainProps {
1229
classes: any;
@@ -25,37 +42,59 @@ const styles = (theme: Theme) =>
2542

2643
const LogsMain = ({ classes }: ILogsMainProps) => {
2744
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+
2861
return (
2962
<Fragment>
3063
<PageHeader label="Logs" />
3164
<Grid container>
3265
<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 />
5998
)}
6099
</Grid>
61100
</Grid>

0 commit comments

Comments
 (0)