Replace ErrorView component w/ robust QueryStatusView
This commit is contained in:
1 parent
41ebf9df20
commit
568c59fdff
3 files changed
+107
-17
No files matched your search
@@ -1,14 +1,12 @@
|
||||
import { ThemeProvider, CssBaseline, GlobalStyles } from '@mui/material';
|
||||
import QueryStatusView from './QueryStatusView';
|
||||
import useMediaQuery from '@mui/material/useMediaQuery';
|
||||
import QueryControl from './QueryControl';
|
||||
import DataTable from './DataTable';
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useState, useEffect, useMemo } from 'react';
|
||||
import useWebSocket, { ReadyState } from 'react-use-websocket';
|
||||
import Sidebar from './SideBar';
|
||||
import getTheme from './Theme';
|
||||
import ErrorView from './ErrorView';
|
||||
import Alert from '@mui/material/Alert';
|
||||
import AlertTitle from '@mui/material/AlertTitle';
|
||||
|
||||
import '@fontsource/noto-sans';
|
||||
import './App.css';
|
||||
@@ -60,6 +58,14 @@ const App = () => {
|
||||
const [blueTable, setBlueTable] = useState({columns: null, rows: null });
|
||||
const [queryError, setQueryError] = useState(null);
|
||||
const [queryState, setQueryState] = useState("Unsubscribed");
|
||||
const queryStateDetails = useMemo(() => {
|
||||
if (queryState == "Unsubscribed") {
|
||||
return "Enter query above, then click the play button to subscribe";
|
||||
}
|
||||
if (queryState == "Subscribed") {
|
||||
return null;
|
||||
}
|
||||
}, [queryState]);
|
||||
const [sidebarIsOpen, setSidebarIsOpen] = useState(false);
|
||||
const [cannedQuery, setCannedQuery] = useState(null);
|
||||
|
||||
@@ -163,16 +169,8 @@ const App = () => {
|
||||
unsubscribe={unsubscribe} />
|
||||
</div>
|
||||
<div style={{width: '90%', rightMargin: '100px' }}>
|
||||
{
|
||||
queryError != null
|
||||
? <ErrorView error={queryError} />
|
||||
: (hasData
|
||||
? <DataTable columns={blueTable?.columns} rows={blueTable?.rows ?? []} sx={{ margin: theme.spacing(2) }} />
|
||||
: <Alert severity="info" sx={{margin: theme.spacing(2)}}>
|
||||
<AlertTitle>No data received.</AlertTitle>
|
||||
<p>Enter query, then click Play</p>
|
||||
</Alert>)
|
||||
}
|
||||
<QueryStatusView queryState={queryState} details={queryStateDetails} error={queryError} />
|
||||
<DataTable columns={blueTable?.columns} rows={blueTable?.rows ?? []} sx={{ margin: theme.spacing(2) }} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
import { useState } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { Box, Typography, Collapse } from '@mui/material';
|
||||
import Alert from '@mui/material/Alert';
|
||||
import AlertTitle from '@mui/material/AlertTitle';
|
||||
import { useTheme } from '@mui/material/styles';
|
||||
import { alpha } from '@mui/system';
|
||||
|
||||
const QueryStatusView = ({ queryState, details, error }) => {
|
||||
const theme = useTheme();
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
let header = queryState;
|
||||
let headerContent = null;
|
||||
let detailElements = [];
|
||||
let severity = queryState == "Subscribed" ? "success" : "info";
|
||||
let cursor = details == null ? "default" : "pointer";
|
||||
if (error != null) {
|
||||
severity = "error";
|
||||
cursor = "pointer";
|
||||
header = `Error Code: ${error.code}`;
|
||||
headerContent = error.message;
|
||||
detailElements.push(<Typography variant="body1">{error.data.error_message}</Typography>);
|
||||
detailElements.push(<Typography variant="subtitle1">Stack Trace:</Typography>);
|
||||
detailElements.push(<Typography variant="body2" component="pre" sx={{ whiteSpace: 'pre-wrap' }}>
|
||||
{error.data.stack_trace}
|
||||
</Typography>);
|
||||
} else if (details != null) {
|
||||
detailElements.push(<Typography variant="body1">{details}</Typography>);
|
||||
}
|
||||
return (
|
||||
<Box sx={{ margin: theme.spacing(2,0) }}>
|
||||
<Alert
|
||||
severity={severity}
|
||||
onClick={() => setOpen(!open)} sx={{
|
||||
margin: theme.spacing(2, 0, 0, 0),
|
||||
cursor: cursor,
|
||||
}}>
|
||||
<AlertTitle>{header}</AlertTitle>
|
||||
{headerContent}
|
||||
</Alert>
|
||||
{detailElements.length == 0
|
||||
? null
|
||||
: <Collapse in={open}>
|
||||
<Box
|
||||
sx={{
|
||||
backgroundColor: alpha(theme.palette[severity].light, 0.75),
|
||||
color: theme.palette[severity].contrastText,
|
||||
padding: theme.spacing(2),
|
||||
marginTop: theme.spacing(1),
|
||||
borderRadius: theme.shape.borderRadius,
|
||||
}}
|
||||
>
|
||||
{detailElements}
|
||||
</Box>
|
||||
</Collapse>}
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
QueryStatusView.propTypes = {
|
||||
queryState: PropTypes.string,
|
||||
details: PropTypes.string,
|
||||
error: PropTypes.shape({
|
||||
code: PropTypes.number,
|
||||
message: PropTypes.string,
|
||||
data: PropTypes.object,
|
||||
})
|
||||
};
|
||||
|
||||
export default QueryStatusView;
|
||||
@@ -59,9 +59,6 @@ const getDarkPalette = () => {
|
||||
backgroundColor: '#ffffff00',
|
||||
}
|
||||
},
|
||||
warning: {
|
||||
main: '#c4823f'
|
||||
},
|
||||
queryStopButton: {
|
||||
Subscribed: {
|
||||
color: '#ff4444a0',
|
||||
@@ -72,6 +69,30 @@ const getDarkPalette = () => {
|
||||
backgroundColor: '#ffffff00',
|
||||
}
|
||||
},
|
||||
error: {
|
||||
light: '#e57373',
|
||||
main: '#f44336',
|
||||
dark: '#d32f2f',
|
||||
contrastText: '#fff',
|
||||
},
|
||||
warning: {
|
||||
light: '#ffb74d',
|
||||
main: '#ff9800',
|
||||
dark: '#f57c00',
|
||||
contrastText: '#000',
|
||||
},
|
||||
info: {
|
||||
light: '#64b5f6',
|
||||
main: '#2196f3',
|
||||
dark: '#303030',
|
||||
contrastText: '#fff',
|
||||
},
|
||||
success: {
|
||||
light: '#81c784',
|
||||
main: '#4caf50',
|
||||
dark: '#388e3c',
|
||||
contrastText: '#000',
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user