Improve error display in ds webapp
This commit is contained in:
1 parent
08f6560885
commit
579aeeed33
4 files changed
+119
-76
No files matched your search
@@ -1,10 +1,14 @@
|
||||
import { ThemeProvider, CssBaseline, GlobalStyles } from '@mui/material';
|
||||
import useMediaQuery from '@mui/material/useMediaQuery';
|
||||
import QueryControl from './QueryControl';
|
||||
import ReactDataGrid from './ReactDataGrid';
|
||||
import { useState, 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';
|
||||
@@ -111,6 +115,7 @@ const App = () => {
|
||||
};
|
||||
|
||||
const sidebarWidth = sidebarIsOpen ? '250px' : '65px';
|
||||
const hasData = blueTable.columns != null && blueTable.columns.length > 0;
|
||||
return (
|
||||
<ThemeProvider theme={theme}>
|
||||
<CssBaseline />
|
||||
@@ -141,15 +146,26 @@ const App = () => {
|
||||
<div style={{width: '20%' }} />
|
||||
<h1 id={`main-header`}>BTS Cloud Streams</h1>
|
||||
</div>
|
||||
<div style={{width: '100%', display: 'flex', flexDirection: 'row', alignItems: 'flex-start' }}>
|
||||
<QueryControl
|
||||
columns={blueTable.columns}
|
||||
rows={blueTable.rows}
|
||||
isRunning={isRunning}
|
||||
queryInputText={queryInputText}
|
||||
queryError={queryError}
|
||||
subscribe={subscribe}
|
||||
unsubscribe={unsubscribe} />
|
||||
<div style={{width: '100%', display: 'flex', flexDirection: 'column', alignItems: 'flex-start' }}>
|
||||
<div style={{width: '90%', rightMargin: '100px' }}>
|
||||
<QueryControl
|
||||
isRunning={isRunning}
|
||||
queryInputText={queryInputText}
|
||||
subscribe={subscribe}
|
||||
unsubscribe={unsubscribe} />
|
||||
</div>
|
||||
<div style={{width: '90%', rightMargin: '100px' }}>
|
||||
{
|
||||
queryError != null
|
||||
? <ErrorView error={queryError} />
|
||||
: (hasData
|
||||
? <ReactDataGrid columns={blueTable.columns} rows={blueTable.rows ?? []} />
|
||||
: <Alert severity="info" sx={{margin: theme.spacing(2)}}>
|
||||
<AlertTitle>No data received.</AlertTitle>
|
||||
<p>Enter query, then click Play</p>
|
||||
</Alert>)
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
p.error-text {
|
||||
font-weight: bold;
|
||||
color: var(--error-color);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import React from 'react';
|
||||
import { Box, Typography, Collapse } from '@mui/material';
|
||||
import { useTheme } from '@mui/material/styles';
|
||||
import Alert from '@mui/material/Alert';
|
||||
import AlertTitle from '@mui/material/AlertTitle';
|
||||
|
||||
const ErrorView = ({ error }) => {
|
||||
const theme = useTheme();
|
||||
const [open, setOpen] = React.useState(false);
|
||||
|
||||
if (!error) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<Box sx={{ margin: theme.spacing(2) }}>
|
||||
<Alert severity="error" onClick={() => setOpen(!open)} sx={{ cursor: 'pointer' }}>
|
||||
<AlertTitle>Error Code: {error.code}</AlertTitle>
|
||||
{error.message}
|
||||
</Alert>
|
||||
<Collapse in={open}>
|
||||
<Box
|
||||
sx={{
|
||||
backgroundColor: theme.palette.error.light,
|
||||
color: theme.palette.error.contrastText,
|
||||
padding: theme.spacing(2),
|
||||
marginTop: theme.spacing(1),
|
||||
borderRadius: theme.shape.borderRadius,
|
||||
}}
|
||||
>
|
||||
<Typography variant="body1">{error.data.error_message}</Typography>
|
||||
<Typography variant="subtitle1">Stack Trace:</Typography>
|
||||
<Typography variant="body2" component="pre" sx={{ whiteSpace: 'pre-wrap' }}>
|
||||
{error.data.stack_trace}
|
||||
</Typography>
|
||||
</Box>
|
||||
</Collapse>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
export default ErrorView;
|
||||
@@ -2,7 +2,6 @@ import PropTypes from 'prop-types';
|
||||
import DataTable from './DataTable';
|
||||
import { useRef, useEffect } from 'react';
|
||||
import { useGridApiRef } from '@mui/x-data-grid';
|
||||
import ReactDataGrid from './ReactDataGrid';
|
||||
import Box from '@mui/material/Box';
|
||||
import Button from '@mui/material/Button';
|
||||
import Grid from '@mui/material/Grid';
|
||||
@@ -11,10 +10,9 @@ import PlayArrowIcon from '@mui/icons-material/PlayArrow';
|
||||
import StopIcon from '@mui/icons-material/Stop';
|
||||
import TextField from '@mui/material/TextField';
|
||||
import Tooltip from '@mui/material/Tooltip';
|
||||
import { JsonView, allExpanded, darkStyles, defaultStyles } from 'react-json-view-lite';
|
||||
|
||||
const QueryControl = (props) => {
|
||||
const { columns, rows, isRunning, queryInputText, queryError, subscribe, unsubscribe } = props;
|
||||
const { isRunning, queryInputText, subscribe, unsubscribe } = props;
|
||||
// const theme = useTheme();
|
||||
let textInput = useRef();
|
||||
useEffect(() => {
|
||||
@@ -45,71 +43,55 @@ const QueryControl = (props) => {
|
||||
}
|
||||
};
|
||||
|
||||
const prettyError = {
|
||||
code: 0,
|
||||
message: "",
|
||||
};
|
||||
if (queryError != null) {
|
||||
prettyError.code = queryError.code;
|
||||
// prettyError.message = quer
|
||||
}
|
||||
return (
|
||||
<div style={{
|
||||
width: '75%'
|
||||
}}>
|
||||
<Box sx={{ display: "flex", flexFlow: "column" }}>
|
||||
<Paper elevation={3} sx={{ color: 'primary.main' }}>
|
||||
<Box sx={{ p: 2 }}>
|
||||
<TextField
|
||||
fullWidth
|
||||
multiline
|
||||
rows={10}
|
||||
variant="outlined"
|
||||
onKeyDown={onKeyDown}
|
||||
inputRef={textInput}
|
||||
placeholder="Enter Query..."
|
||||
/>
|
||||
</Box>
|
||||
<Box sx={{ p: 2, borderTop: 1 }}>
|
||||
<Grid container spacing={2} justifyContent="flex-start">
|
||||
<Grid item xs>
|
||||
<Tooltip title="Clear Query Text">
|
||||
<Button onClick={onClearClick} sx={{ padding: '11px', color: 'text.dark' }}>
|
||||
Clear
|
||||
</Button>
|
||||
</Tooltip>
|
||||
</Grid>
|
||||
<Grid item>
|
||||
<Tooltip title="Run (Ctrl+Enter)">
|
||||
<Button onClick={onRunClick} sx={{
|
||||
color: `query_start_button.${isRunning ? 'active' : 'inactive'}.color`,
|
||||
bgcolor: `query_start_button.${isRunning ? 'active' : 'inactive'}.background_color`,
|
||||
padding: '11px'
|
||||
}}>
|
||||
<PlayArrowIcon />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
</Grid>
|
||||
<Grid item>
|
||||
<Tooltip title="Stop">
|
||||
<Button onClick={onStopClick} sx={{
|
||||
color: `query_stop_button.${isRunning ? 'inactive' : 'active'}.color`,
|
||||
bgcolor: `query_stop_button.${isRunning ? 'inactive' : 'active'}.background_color`,
|
||||
padding: '11px'
|
||||
}}>
|
||||
<StopIcon />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
</Grid>
|
||||
<Box sx={{ display: "flex", flexFlow: "column" }}>
|
||||
<Paper elevation={3} sx={{ color: 'primary.main' }}>
|
||||
<Box sx={{ p: 2 }}>
|
||||
<TextField
|
||||
fullWidth
|
||||
multiline
|
||||
rows={10}
|
||||
variant="outlined"
|
||||
onKeyDown={onKeyDown}
|
||||
inputRef={textInput}
|
||||
placeholder="Enter Query..."
|
||||
/>
|
||||
</Box>
|
||||
<Box sx={{ p: 2, borderTop: 1 }}>
|
||||
<Grid container spacing={2} justifyContent="flex-start">
|
||||
<Grid item xs>
|
||||
<Tooltip title="Clear Query Text">
|
||||
<Button onClick={onClearClick} sx={{ padding: '11px', color: 'text.dark' }}>
|
||||
Clear
|
||||
</Button>
|
||||
</Tooltip>
|
||||
</Grid>
|
||||
</Box>
|
||||
</Paper>
|
||||
</Box>
|
||||
{
|
||||
queryError != null ? <JsonView style={{expandIcon: "+"}} data={queryError} shouldExpandNode={allExpanded} /> :
|
||||
<ReactDataGrid columns={columns ?? []} rows={rows ?? []} />
|
||||
}
|
||||
</div>
|
||||
<Grid item>
|
||||
<Tooltip title="Run (Ctrl+Enter)">
|
||||
<Button onClick={onRunClick} sx={{
|
||||
color: `query_start_button.${isRunning ? 'active' : 'inactive'}.color`,
|
||||
bgcolor: `query_start_button.${isRunning ? 'active' : 'inactive'}.background_color`,
|
||||
padding: '11px'
|
||||
}}>
|
||||
<PlayArrowIcon />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
</Grid>
|
||||
<Grid item>
|
||||
<Tooltip title="Stop">
|
||||
<Button onClick={onStopClick} sx={{
|
||||
color: `query_stop_button.${isRunning ? 'inactive' : 'active'}.color`,
|
||||
bgcolor: `query_stop_button.${isRunning ? 'inactive' : 'active'}.background_color`,
|
||||
padding: '11px'
|
||||
}}>
|
||||
<StopIcon />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Box>
|
||||
</Paper>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -118,7 +100,6 @@ QueryControl.propTypes = {
|
||||
rows: PropTypes.array,
|
||||
isRunning: PropTypes.bool,
|
||||
queryInputText: PropTypes.string,
|
||||
queryError: PropTypes.object,
|
||||
subscribe: PropTypes.func,
|
||||
unsubscribe: PropTypes.func,
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user