Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tidy log menu #37

Merged
merged 4 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 12 additions & 22 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ThemeProvider } from "@emotion/react";
import { useEffect, useState, useReducer, useMemo } from "react";
import Log_Menu from "./components/Log_Menu.tsx";
import FilterMenu from "./components/FilterMenu.tsx";
import { theme } from "./theme";
import BoxBasic from "./components/Box";
import {
Expand All @@ -16,14 +16,13 @@ import {
import { payload } from "./schema/payload.ts";

import Table from "@mui/material/Table";
import TextField from "@mui/material/TextField";
import TableBody from "@mui/material/TableBody";
import TableCell from "@mui/material/TableCell";
import TableContainer from "@mui/material/TableContainer";
import TableRow from "@mui/material/TableRow";
import Paper from "@mui/material/Paper";
import { TableHead } from "@mui/material";
import { log_levels } from "./schema/Log_Levels.ts";
import { LogLevel } from "./schema/level.ts";

function App() {
// Initialize information for Queries and Auth
Expand Down Expand Up @@ -136,24 +135,15 @@ function App() {
return (
<ThemeProvider theme={theme}>
<h1>Athena Logpanel </h1>
<Log_Menu
logFilterValue={logFilter}
onLogFilterChange={handleLogFilterChange}
/>
<TextField
id="app-name"
label="Application Name"
variant="outlined"
margin="normal"
onChange={e => handleAppName(e.target.value)}
/>
<TextField
id="beamline"
label="Beamline"
variant="outlined"
margin="normal"
onChange={e => handleBeamline(e.target.value)}
<FilterMenu
level={logFilter}
onLevelChange={handleLogFilterChange}
beamline=""
onBeamlineChange={handleBeamline}
application=""
onApplicationChange={handleAppName}
/>

<BoxBasic>
<TableContainer component={Paper}>
<Table sx={{ minWidth: 650 }} aria-label="simple table">
Expand Down Expand Up @@ -230,14 +220,14 @@ function getMessage(logging: JSON): LogRecord | undefined {
// Type Checking of API Response
if (MessageType(message)) {
app_name.push(message.application_name);
const level_str = log_levels[message.level] || "UNKNOWN";
const level_str = LogLevel[message.level] || "UNKNOWN";
log_level_str.push(level_str);
log_message.push(message.full_message);
log_level.push(message.level);
}
if (isLogMessageCluster(message)) {
app_name.push(message.cluster_name);
const level_str = log_levels[message.level] || "UNKNOWN";
const level_str = LogLevel[message.level] || "UNKNOWN";
log_level_str.push(level_str);
log_message.push(message.message);
log_level.push(message.level);
Expand Down
70 changes: 70 additions & 0 deletions src/components/FilterMenu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import * as React from "react";
import Box from "@mui/material/Box";
import InputLabel from "@mui/material/InputLabel";
import MenuItem from "@mui/material/MenuItem";
import FormControl from "@mui/material/FormControl";
import { allLogLevels } from "../schema/level";
import { Grid, Select, TextField } from "@mui/material";

interface Props {
level: number;
onLevelChange: (level: number) => void;
beamline: string;
onBeamlineChange: (beamline: string) => void;
application: string;
onApplicationChange: (application: string) => void;
}

const FilterMenu: React.FC<Props> = (props: Props) => {
return (
<Box sx={{ padding: "1vw" }}>
<Grid container spacing={2}>
<Grid item xs={1}>
<FormControl fullWidth margin="normal">
<InputLabel id="log-filter-id">Level</InputLabel>
<Select
id="log-filter-label"
value={props.level}
label="Level"
onChange={e =>
props.onLevelChange(e.target.value as unknown as number)
}
>
{allLogLevels().map(([level, num]) => (
<MenuItem key={level} value={num}>
{level}
</MenuItem>
))}
</Select>
</FormControl>
</Grid>
<Grid item xs>
<TextField
id="app-name"
label="Application"
variant="outlined"
margin="normal"
onChange={e => props.onApplicationChange(e.target.value)}
fullWidth
>
{props.application}
</TextField>
</Grid>
<Grid item xs>
<TextField
id="beamline"
label="Beamline"
variant="outlined"
margin="normal"
onChange={e => props.onBeamlineChange(e.target.value)}
fullWidth
>
{props.beamline}
</TextField>
</Grid>
</Grid>
</Box>
);
};

export default FilterMenu;
45 changes: 0 additions & 45 deletions src/components/Log_Menu.tsx

This file was deleted.

10 changes: 0 additions & 10 deletions src/schema/Log_Levels.ts

This file was deleted.

17 changes: 17 additions & 0 deletions src/schema/level.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export enum LogLevel {
callumforrester marked this conversation as resolved.
Show resolved Hide resolved
EMERG = 0,
ALERT = 1,
CRITICAL = 2,
ERROR = 3,
WARN = 4,
NOTICE = 5,
INFO = 6,
DEBUG = 7,
}

export function allLogLevels(): [string, number][] {
// Typescript annoyance, there doesn't seem to be a nice solution
// https://stackoverflow.com/questions/56044872/typescript-enum-object-values-return-value
const entries = Object.entries(LogLevel);
return entries.slice(entries.length / 2) as [string, number][];
}
Loading