From 847d5f1b3b18219454979420241f39a608c87e04 Mon Sep 17 00:00:00 2001 From: GyDi Date: Mon, 11 Apr 2022 01:46:33 +0800 Subject: [PATCH] feat: log page supports filter --- src/pages/logs.tsx | 66 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 58 insertions(+), 8 deletions(-) diff --git a/src/pages/logs.tsx b/src/pages/logs.tsx index 020f3ca..936ba19 100644 --- a/src/pages/logs.tsx +++ b/src/pages/logs.tsx @@ -1,5 +1,6 @@ +import { useMemo, useState } from "react"; import { useRecoilState } from "recoil"; -import { Button, Paper } from "@mui/material"; +import { Box, Button, MenuItem, Paper, Select, TextField } from "@mui/material"; import { Virtuoso } from "react-virtuoso"; import { useTranslation } from "react-i18next"; import { atomLogData } from "../services/states"; @@ -10,6 +11,18 @@ const LogPage = () => { const { t } = useTranslation(); const [logData, setLogData] = useRecoilState(atomLogData); + const [logState, setLogState] = useState("all"); + const [filterText, setFilterText] = useState(""); + + const filterLogs = useMemo(() => { + return logData.filter((data) => { + return ( + data.payload.includes(filterText) && + (logState === "all" ? true : data.type.includes(logState)) + ); + }); + }, [logData, logState, filterText]); + return ( { } > - - } - followOutput={"smooth"} - /> + + + + + setFilterText(e.target.value)} + sx={{ input: { py: 0.65, px: 1.25 } }} + /> + + + + } + followOutput={"smooth"} + /> + );