diff --git a/frontend/src/Dashboard.tsx b/frontend/src/Dashboard.tsx index e8a5e693..4e7461a7 100644 --- a/frontend/src/Dashboard.tsx +++ b/frontend/src/Dashboard.tsx @@ -1,4 +1,4 @@ -import React, { useContext } from "react"; +import React, { useContext, useState, useEffect } from "react"; import { styled, createTheme, ThemeProvider } from "@mui/material/styles"; import CssBaseline from "@mui/material/CssBaseline"; import MuiDrawer from "@mui/material/Drawer"; @@ -17,6 +17,7 @@ import ChevronLeftIcon from "@mui/icons-material/ChevronLeft"; import { MainListItems } from "./ListItems"; import { LoginContext } from "./LoginContext"; import SimpleListMenu from "./SimpleListMenu"; +import { useNavigate } from "react-router-dom"; const drawerWidth = 300; @@ -73,6 +74,7 @@ const mdTheme = createTheme(); export interface DashboardProps { children: React.ReactNode; title: string; + refreshAction: () => void; } function Dashboard(props: DashboardProps) { @@ -80,7 +82,76 @@ function Dashboard(props: DashboardProps) { const toggleDrawer = () => { setOpen(!open); }; - const { user } = useContext(LoginContext); + const { user, setUser } = useContext(LoginContext); + const navigation = useNavigate(); + + const [time, setTime] = useState(Date.now()); + const [refreshInterval, setRefreshInterval] = useState(0); + const [refreshString, setRefreshString] = useState("manual"); + + // execute every time the refreshInterval changes to set the interval correctly + // update the time value every x ms, which triggers refresh (see below) + useEffect(() => { + if (refreshInterval === 0) { + console.log("refreshInterval is 0") + return; + } + const interval = setInterval(() => setTime(Date.now()), refreshInterval); + return () => { + console.log("clear refreshInterval") + clearInterval(interval); + }; + }, [refreshInterval]); + + // refresh every time the 'time' value changes + useEffect(() => { + console.log("reload page at", time); + //setChildKey(prev => prev + 1); + props.refreshAction(); + }, [time]); + + const handleUserNameClick = (event: React.MouseEvent, index: number) => { + switch (index) { + case 0: + navigation("/password"); + break; + case 1: + setUser(null); + navigation("/login"); + break; + default: + break; + } + }; + + const refreshStrings = ["manual", "1s", "5s", "10s", "30s"]; + + const handleRefreshClick = (event: React.MouseEvent, index: number) => { + switch (index) { + case 0: // manual + setRefreshInterval(0); + setRefreshString(refreshStrings.at(index)!); + break; + case 1: // 1s + setRefreshInterval(1000); + setRefreshString(refreshStrings.at(index)!); + break; + case 2: // 5s + setRefreshInterval(5000); + setRefreshString(refreshStrings.at(index)!); + break; + case 3: // 10s + setRefreshInterval(10000); + setRefreshString(refreshStrings.at(index)!); + break; + case 4: // 30s + setRefreshInterval(30000); + setRefreshString(refreshStrings.at(index)!); + break; + default: + break; + } + }; return ( @@ -104,10 +175,23 @@ function Dashboard(props: DashboardProps) { > - - {props.title} - - + + + {props.title} + + + + + diff --git a/frontend/src/SimpleListMenu.tsx b/frontend/src/SimpleListMenu.tsx index cba0b2d4..9b65f5fd 100644 --- a/frontend/src/SimpleListMenu.tsx +++ b/frontend/src/SimpleListMenu.tsx @@ -1,54 +1,24 @@ -import React, { useContext } from "react"; -import { useNavigate } from "react-router-dom"; +import React, { useState } from "react"; import List from "@mui/material/List"; import ListItem from "@mui/material/ListItem"; import ListItemText from "@mui/material/ListItemText"; import MenuItem from "@mui/material/MenuItem"; import Menu from "@mui/material/Menu"; -import { LoginContext } from "./LoginContext"; - -const options = ["Change Password", "Logout"]; - export interface SimpleListMenuProps { title: string | undefined; + options: string[]; + handleMenuItemClick: (event: React.MouseEvent, index: number) => void; } export default function SimpleListMenu(props: SimpleListMenuProps) { - const [anchorEl, setAnchorEl] = React.useState(null); - const [selectedIndex, setSelectedIndex] = React.useState(1); + const [anchorEl, setAnchorEl] = useState(null); + const [selectedIndex, setSelectedIndex] = useState(0); const open = Boolean(anchorEl); const handleClickListItem = (event: React.MouseEvent) => { setAnchorEl(event.currentTarget); }; - const navigation = useNavigate(); - const { setUser } = useContext(LoginContext); - - function onChangePassword() { - navigation("/password"); - } - - function onLogout() { - setUser(null); - navigation("/login"); - } - - const handleMenuItemClick = (event: React.MouseEvent, index: number) => { - setSelectedIndex(index); - setAnchorEl(null); - switch (index) { - case 0: - onChangePassword(); - break; - case 1: - onLogout(); - break; - default: - break; - } - }; - const handleClose = () => { setAnchorEl(null); }; @@ -78,11 +48,15 @@ export default function SimpleListMenu(props: SimpleListMenuProps) { role: "listbox", }} > - {options.map((option, index) => ( + {props.options.map((option, index) => ( handleMenuItemClick(event, index)} + onClick={(event) => { + setSelectedIndex(index); + setAnchorEl(null); + props.handleMenuItemClick(event, index); + }} > {option} diff --git a/frontend/src/pages/AnalysisList.tsx b/frontend/src/pages/AnalysisList.tsx index b85d7f80..7a221ca0 100644 --- a/frontend/src/pages/AnalysisList.tsx +++ b/frontend/src/pages/AnalysisList.tsx @@ -21,6 +21,7 @@ export default function AnalysisList() { const [data, setData] = useState([]); const [limit, setLimit] = useState(50); const [page, setPage] = useState(0); + const [refresh, setRefresh] = useState(false); useEffect(() => { axios @@ -29,9 +30,9 @@ export default function AnalysisList() { setData(res.data); }) .catch((e) => { - console.log(e); + console.log(e.message); }); - }, [limit, page]); + }, [refresh, limit, page]); const handlePageChange = ( _event: React.MouseEvent | null, @@ -103,7 +104,7 @@ export default function AnalysisList() { ); return ( - + setRefresh(!refresh)}>
{data == null || data.length === 0 ?
No App Data
: tableView}
diff --git a/frontend/src/pages/ChangePassword.tsx b/frontend/src/pages/ChangePassword.tsx index 3b24d3b8..ce35417f 100644 --- a/frontend/src/pages/ChangePassword.tsx +++ b/frontend/src/pages/ChangePassword.tsx @@ -79,7 +79,7 @@ export default function ChangePassword() { }; return ( - + {}}> diff --git a/frontend/src/pages/Charging/ChargingTable.tsx b/frontend/src/pages/Charging/ChargingTable.tsx index 37aaa36e..91e78542 100644 --- a/frontend/src/pages/Charging/ChargingTable.tsx +++ b/frontend/src/pages/Charging/ChargingTable.tsx @@ -9,7 +9,7 @@ import { Button, Grid } from "@mui/material"; export default function ChargingTable() { const [expand, setExpand] = useState(true); - const [currentTime, setCurrentTime] = useState(new Date()); + const [refresh, setRefresh] = useState(false); const [onlineChargingData, setOnlineChargingData] = useState([]); const [offlineChargingData, setOfflineChargingData] = useState([]); @@ -44,37 +44,23 @@ export default function ChargingTable() { }; const onRefresh = () => { + console.log("refreshing charging data"); fetchChargingData("Online", setOnlineChargingData); fetchChargingData("Offline", setOfflineChargingData); fetchChargingRecord(); - setCurrentTime(new Date()); }; useEffect(() => { onRefresh(); - const id = setInterval(() => { - onRefresh(); - }, 10000); - return () => clearInterval(id); - }, []); + }, [refresh]); const onExpand = () => { setExpand(!expand); }; return ( - + onRefresh()}> - - - -
([]); + const [refresh, setRefresh] = useState(false); const [limit, setLimit] = useState(50); const [page, setPage] = useState(0); @@ -33,9 +34,9 @@ export default function StatusList() { } }) .catch((e) => { - console.log(e); + console.log(e.message); }); - }, [limit, page]); + }, [refresh, limit, page]); const handlePageChange = ( _event: React.MouseEvent | null, @@ -109,7 +110,7 @@ export default function StatusList() { ); return ( - + setRefresh(!refresh)}>
{data == null || data.length === 0 ?
No App Data
: tableView}
diff --git a/frontend/src/pages/StatusRead.tsx b/frontend/src/pages/StatusRead.tsx index b48a513d..96c9ade9 100644 --- a/frontend/src/pages/StatusRead.tsx +++ b/frontend/src/pages/StatusRead.tsx @@ -11,6 +11,7 @@ import { Card, Table, TableBody, TableCell, TableRow } from "@mui/material"; export default function StatusRead() { const location = useLocation(); const ueContext = location.state as UeContext; + const [refresh, setRefresh] = useState(false); const { id } = useParams<{ id: string; @@ -28,10 +29,10 @@ export default function StatusRead() { const pdus: PduSessionInfo[] = res.map((item) => item.data); setData(pdus); }); - }, [id]); + }, [id, refresh]); return ( - + setRefresh(!refresh)}>

AMF Information [SUPI:{ueContext.Supi}]

diff --git a/frontend/src/pages/SubscriberCreate.tsx b/frontend/src/pages/SubscriberCreate.tsx index 61fd298a..6b9a1f76 100644 --- a/frontend/src/pages/SubscriberCreate.tsx +++ b/frontend/src/pages/SubscriberCreate.tsx @@ -302,6 +302,7 @@ export default function SubscriberCreate() { if (!isNewSubscriber) { useEffect(() => { axios.get("/api/subscriber/" + id + "/" + plmn).then((res) => { + console.log('loaded existing subscriber', res.data); setData(res.data); }); }, [id]); @@ -1577,7 +1578,7 @@ export default function SubscriberCreate() { }; return ( - + {}}>
diff --git a/frontend/src/pages/SubscriberList.tsx b/frontend/src/pages/SubscriberList.tsx index df2913cb..e33ab269 100644 --- a/frontend/src/pages/SubscriberList.tsx +++ b/frontend/src/pages/SubscriberList.tsx @@ -25,13 +25,14 @@ export default function SubscriberList() { const [page, setPage] = useState(0); useEffect(() => { + console.log("get subscribers"); axios .get("/api/subscriber") .then((res) => { setData(res.data); }) .catch((e) => { - console.log(e); + console.log(e.message); }); }, [refresh, limit, page]); @@ -94,6 +95,10 @@ export default function SubscriberList() { navigation("/subscriber/" + subscriber.ueId + "/" + subscriber.plmnID); }; + const handleDuplicate = (subscriber: Subscriber) => { + navigation("/subscriber/create/" + subscriber.ueId + "/" + subscriber.plmnID) + }; + const tableView = (
@@ -103,6 +108,7 @@ export default function SubscriberList() { UE IDDeleteView + Duplicate @@ -124,6 +130,11 @@ export default function SubscriberList() { VIEW + + + ))} @@ -138,7 +149,7 @@ export default function SubscriberList() { ); return ( - + setRefresh(!refresh)}>
{data == null || data.length === 0 ? (
diff --git a/frontend/src/pages/SubscriberRead.tsx b/frontend/src/pages/SubscriberRead.tsx index aed58629..abbb580d 100644 --- a/frontend/src/pages/SubscriberRead.tsx +++ b/frontend/src/pages/SubscriberRead.tsx @@ -272,7 +272,7 @@ export default function SubscriberRead() { }; return ( - + {}}>
diff --git a/frontend/src/pages/TenantCreate.tsx b/frontend/src/pages/TenantCreate.tsx index c2818b28..1ab9bdf4 100644 --- a/frontend/src/pages/TenantCreate.tsx +++ b/frontend/src/pages/TenantCreate.tsx @@ -32,7 +32,7 @@ export default function TenantCreate() { }; return ( - + {}}>
diff --git a/frontend/src/pages/TenantList.tsx b/frontend/src/pages/TenantList.tsx index 68f21980..49d568d9 100644 --- a/frontend/src/pages/TenantList.tsx +++ b/frontend/src/pages/TenantList.tsx @@ -31,7 +31,7 @@ export default function TenantList() { setData(res.data); }) .catch((e) => { - console.log(e); + console.log(e.message); }); }, [limit, page, refresh]); @@ -142,7 +142,7 @@ export default function TenantList() { ); return ( - + setRefresh(!refresh)}>
{data == null || data.length === 0 ? (
diff --git a/frontend/src/pages/TenantUpdate.tsx b/frontend/src/pages/TenantUpdate.tsx index 5c0cb349..97c43fc8 100644 --- a/frontend/src/pages/TenantUpdate.tsx +++ b/frontend/src/pages/TenantUpdate.tsx @@ -36,7 +36,7 @@ export default function TenantUpdate() { }; return ( - + {}}>
diff --git a/frontend/src/pages/UserCreate.tsx b/frontend/src/pages/UserCreate.tsx index f07890fe..99ae655c 100644 --- a/frontend/src/pages/UserCreate.tsx +++ b/frontend/src/pages/UserCreate.tsx @@ -87,7 +87,7 @@ export default function UserCreate() { }; return ( - + {}}>
diff --git a/frontend/src/pages/UserList.tsx b/frontend/src/pages/UserList.tsx index a356bfc1..58fb7d6d 100644 --- a/frontend/src/pages/UserList.tsx +++ b/frontend/src/pages/UserList.tsx @@ -35,7 +35,7 @@ export default function UserList() { setData(res.data); }) .catch((e) => { - console.log(e); + console.log(e.message); }); }, [limit, page, refresh]); @@ -144,7 +144,7 @@ export default function UserList() { ); return ( - + {}}>
{data == null || data.length === 0 ? (
diff --git a/frontend/src/pages/UserUpdate.tsx b/frontend/src/pages/UserUpdate.tsx index 5d20afcc..dcbb79ef 100644 --- a/frontend/src/pages/UserUpdate.tsx +++ b/frontend/src/pages/UserUpdate.tsx @@ -89,7 +89,7 @@ export default function UserUpdate() { }; return ( - + {}}>