rules.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import useSWR from "swr";
  2. import { useState, useMemo } from "react";
  3. import { useTranslation } from "react-i18next";
  4. import { Virtuoso } from "react-virtuoso";
  5. import { Box, Button, MenuItem, Paper, Select, TextField } from "@mui/material";
  6. import { getRules } from "@/services/api";
  7. import BasePage from "@/components/base/base-page";
  8. import BaseEmpty from "@/components/base/base-empty";
  9. import RuleItem from "@/components/rule/rule-item";
  10. const RulesPage = () => {
  11. const { t } = useTranslation();
  12. const { data = [] } = useSWR("getRules", getRules);
  13. const [filterText, setFilterText] = useState("");
  14. const rules = useMemo(() => {
  15. return data.filter((each) => each.payload.includes(filterText));
  16. }, [data, filterText]);
  17. return (
  18. <BasePage title={t("Rules")} contentStyle={{ height: "100%" }}>
  19. <Paper sx={{ boxSizing: "border-box", boxShadow: 2, height: "100%" }}>
  20. <Box
  21. sx={{
  22. pt: 1,
  23. mb: 0.5,
  24. mx: "12px",
  25. height: "36px",
  26. display: "flex",
  27. alignItems: "center",
  28. }}
  29. >
  30. <TextField
  31. hiddenLabel
  32. fullWidth
  33. size="small"
  34. autoComplete="off"
  35. variant="outlined"
  36. spellCheck="false"
  37. placeholder={t("Filter conditions")}
  38. value={filterText}
  39. onChange={(e) => setFilterText(e.target.value)}
  40. sx={{ input: { py: 0.65, px: 1.25 } }}
  41. />
  42. </Box>
  43. <Box height="calc(100% - 50px)">
  44. {rules.length > 0 ? (
  45. <Virtuoso
  46. data={rules}
  47. itemContent={(index, item) => (
  48. <RuleItem index={index + 1} value={item} />
  49. )}
  50. followOutput={"smooth"}
  51. />
  52. ) : (
  53. <BaseEmpty text="No Rules" />
  54. )}
  55. </Box>
  56. </Paper>
  57. </BasePage>
  58. );
  59. };
  60. export default RulesPage;