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>
This commit is contained in:
@@ -1,12 +1,29 @@
|
|||||||
import React, { Fragment, useState } from "react";
|
// This file is part of MinIO Console Server
|
||||||
|
// Copyright (c) 2021 MinIO, Inc.
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import React, { Fragment, useState, useEffect } from "react";
|
||||||
import PageHeader from "../Common/PageHeader/PageHeader";
|
import PageHeader from "../Common/PageHeader/PageHeader";
|
||||||
import { Grid } from "@material-ui/core";
|
import { Grid, LinearProgress } from "@material-ui/core";
|
||||||
import { createStyles, Theme, withStyles } from "@material-ui/core/styles";
|
import { createStyles, Theme, withStyles } from "@material-ui/core/styles";
|
||||||
import Tab from "@material-ui/core/Tab";
|
import Tab from "@material-ui/core/Tab";
|
||||||
import Tabs from "@material-ui/core/Tabs";
|
import Tabs from "@material-ui/core/Tabs";
|
||||||
|
import { containerForHeader } from "../Common/FormComponents/common/styleLibrary";
|
||||||
import ErrorLogs from "./ErrorLogs/ErrorLogs";
|
import ErrorLogs from "./ErrorLogs/ErrorLogs";
|
||||||
import LogsSearchMain from "./LogSearch/LogsSearchMain";
|
import LogsSearchMain from "./LogSearch/LogsSearchMain";
|
||||||
import { containerForHeader } from "../Common/FormComponents/common/styleLibrary";
|
import api from "../../../common/api";
|
||||||
|
|
||||||
interface ILogsMainProps {
|
interface ILogsMainProps {
|
||||||
classes: any;
|
classes: any;
|
||||||
@@ -25,37 +42,59 @@ const styles = (theme: Theme) =>
|
|||||||
|
|
||||||
const LogsMain = ({ classes }: ILogsMainProps) => {
|
const LogsMain = ({ classes }: ILogsMainProps) => {
|
||||||
const [currentTab, setCurrentTab] = useState<number>(0);
|
const [currentTab, setCurrentTab] = useState<number>(0);
|
||||||
|
const [loading, setLoading] = useState<boolean>(true);
|
||||||
|
const [showLogSearch, setShowLogSearch] = useState<boolean>(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
api
|
||||||
|
.invoke("GET", `/api/v1/logs/search?q=reqinfo&pageSize=10&pageNo=0`)
|
||||||
|
.then(() => {
|
||||||
|
setShowLogSearch(true);
|
||||||
|
setLoading(false);
|
||||||
|
})
|
||||||
|
.catch((err: any) => {
|
||||||
|
setLoading(false);
|
||||||
|
console.info("Log Search API not available.");
|
||||||
|
});
|
||||||
|
}, [loading]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<PageHeader label="Logs" />
|
<PageHeader label="Logs" />
|
||||||
<Grid container>
|
<Grid container>
|
||||||
<Grid item xs={12} className={classes.container}>
|
<Grid item xs={12} className={classes.container}>
|
||||||
<Grid item xs={12} className={classes.headerLabel}>
|
{!loading ? (
|
||||||
All Logs
|
<Fragment>
|
||||||
</Grid>
|
<Grid item xs={12} className={classes.headerLabel}>
|
||||||
<Tabs
|
All Logs
|
||||||
value={currentTab}
|
</Grid>
|
||||||
onChange={(e: React.ChangeEvent<{}>, newValue: number) => {
|
<Tabs
|
||||||
setCurrentTab(newValue);
|
value={currentTab}
|
||||||
}}
|
onChange={(e: React.ChangeEvent<{}>, newValue: number) => {
|
||||||
indicatorColor="primary"
|
setCurrentTab(newValue);
|
||||||
textColor="primary"
|
}}
|
||||||
aria-label="cluster-tabs"
|
indicatorColor="primary"
|
||||||
>
|
textColor="primary"
|
||||||
<Tab label="Error Logs" />
|
aria-label="cluster-tabs"
|
||||||
<Tab label="Logs Search" />
|
>
|
||||||
</Tabs>
|
<Tab label="Error Logs" />
|
||||||
</Grid>
|
{showLogSearch && <Tab label="Logs Search" />}
|
||||||
<Grid item xs={12}>
|
</Tabs>
|
||||||
{currentTab === 0 && (
|
<Grid item xs={12}>
|
||||||
<Grid item xs={12}>
|
{currentTab === 0 && (
|
||||||
<ErrorLogs />
|
<Grid item xs={12}>
|
||||||
</Grid>
|
<ErrorLogs />
|
||||||
)}
|
</Grid>
|
||||||
{currentTab === 1 && (
|
)}
|
||||||
<Grid item xs={12}>
|
{currentTab === 1 && showLogSearch && (
|
||||||
<LogsSearchMain />
|
<Grid item xs={12}>
|
||||||
</Grid>
|
<LogsSearchMain />
|
||||||
|
</Grid>
|
||||||
|
)}
|
||||||
|
</Grid>
|
||||||
|
</Fragment>
|
||||||
|
) : (
|
||||||
|
<LinearProgress />
|
||||||
)}
|
)}
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
Reference in New Issue
Block a user