Skip to content

Commit

Permalink
Display error to user
Browse files Browse the repository at this point in the history
  • Loading branch information
callumforrester committed Jun 18, 2024
1 parent ddcd089 commit 57a89a9
Showing 1 changed file with 88 additions and 51 deletions.
139 changes: 88 additions & 51 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import { buildSearchQuery, graylogSearch } from "./utils/api/search.ts";
function App() {
// Init states
const [logTable, setLogTable] = useState<LogTableRow[]>([]);
const [logDisplayError, setLogDisplayError] = useState<string | undefined>(
undefined,
);
const [logFilter, setLogfilter] = useState(7);
const [applicationFilter, setApplicationFilter] = useState("*");
const [beamlineFilter, setBeamlineFilter] = useState("*");
Expand All @@ -43,7 +46,12 @@ function App() {
const table = buildTable(searchResults);
setLogTable(table);
} catch (error) {
console.error("Error:", error);
console.error(error);
if (error instanceof Error) {
setLogDisplayError(error.toString());
} else {
setLogDisplayError("Unknown error: see console");
}
}
})();
}, [logFilter, applicationFilter, beamlineFilter]);
Expand Down Expand Up @@ -104,56 +112,85 @@ function App() {
/>

<BoxBasic>
<TableContainer component={Paper}>
<Table sx={{ minWidth: 650 }} aria-label="simple table">
<TableHead>
<TableRow>
<TableCell>
<b>Timestamp</b>
</TableCell>
<TableCell>
<b>Level</b>
</TableCell>
<TableCell>
<b>Host</b>
</TableCell>
<TableCell>
<b>Application</b>
</TableCell>
<TableCell>
<b>Message</b>
</TableCell>
</TableRow>
</TableHead>
<TableBody>
{logTable.map(row => {
return (
<TableRow
key={row.id}
sx={{
backgroundColor: colors[row.level] || colors.default,
}}
>
<TableCell>
<pre>{row.timestamp}</pre>
</TableCell>
<TableCell>
<pre>{row.level}</pre>
</TableCell>
<TableCell>
<pre>{row.host}</pre>
</TableCell>
<TableCell>
<pre>{row.application}</pre>
</TableCell>
<TableCell>{row.text}</TableCell>
{/* sx={{ '&:last-child td, &:last-child th': { border: 0 } }} */}
</TableRow>
);
})}
</TableBody>
</Table>
</TableContainer>
{(() => {
if (logDisplayError === undefined) {
const rows = logTable.map(row => (

Check failure on line 117 in src/App.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

'rows' is assigned a value but never used

Check failure on line 117 in src/App.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

'rows' is declared but its value is never read.

Check failure on line 117 in src/App.tsx

View workflow job for this annotation

GitHub Actions / build (20.x)

'rows' is declared but its value is never read.

Check failure on line 117 in src/App.tsx

View workflow job for this annotation

GitHub Actions / build (20.x)

'rows' is assigned a value but never used
<TableBody>
<TableRow
key={row.id}
sx={{
backgroundColor: colors[row.level] || colors.default,
}}
>
<TableCell>
<pre>{row.timestamp}</pre>
</TableCell>
<TableCell>
<pre>{row.level}</pre>
</TableCell>
<TableCell>
<pre>{row.host}</pre>
</TableCell>
<TableCell>
<pre>{row.application}</pre>
</TableCell>
<TableCell>{row.text}</TableCell>
</TableRow>
</TableBody>
));
return (
<TableContainer component={Paper}>
<Table sx={{ minWidth: 650 }} aria-label="simple table">
<TableHead>
<TableRow>
<TableCell>
<b>Timestamp</b>
</TableCell>
<TableCell>
<b>Level</b>
</TableCell>
<TableCell>
<b>Host</b>
</TableCell>
<TableCell>
<b>Application</b>
</TableCell>
<TableCell>
<b>Message</b>
</TableCell>
</TableRow>
</TableHead>
<TableBody>
{logTable.map(row => (
<TableRow
key={row.id}
sx={{
backgroundColor: colors[row.level] || colors.default,
}}
>
<TableCell>
<pre>{row.timestamp}</pre>
</TableCell>
<TableCell>
<pre>{row.level}</pre>
</TableCell>
<TableCell>
<pre>{row.host}</pre>
</TableCell>
<TableCell>
<pre>{row.application}</pre>
</TableCell>
<TableCell>{row.text}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
);
} else {
return <p>{logDisplayError}</p>;
}
})()}
</BoxBasic>
</ThemeProvider>
);
Expand Down

0 comments on commit 57a89a9

Please sign in to comment.