rules.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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, TextField } from "@mui/material";
  6. import { getRules } from "@/services/api";
  7. import { BaseEmpty, BasePage } from "@/components/base";
  8. import RuleItem from "@/components/rule/rule-item";
  9. import { ProviderButton } from "@/components/rule/provider-button";
  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
  19. full
  20. title={t("Rules")}
  21. contentStyle={{ height: "100%" }}
  22. header={
  23. <Box display="flex" alignItems="center" gap={1}>
  24. <ProviderButton />
  25. </Box>
  26. }
  27. >
  28. <Box
  29. sx={{
  30. pt: 1,
  31. mb: 0.5,
  32. mx: "10px",
  33. height: "36px",
  34. display: "flex",
  35. alignItems: "center",
  36. }}
  37. >
  38. <TextField
  39. hiddenLabel
  40. fullWidth
  41. size="small"
  42. autoComplete="off"
  43. variant="outlined"
  44. spellCheck="false"
  45. placeholder={t("Filter conditions")}
  46. value={filterText}
  47. onChange={(e) => setFilterText(e.target.value)}
  48. sx={{ input: { py: 0.65, px: 1.25 } }}
  49. />
  50. </Box>
  51. <Box height="calc(100% - 50px)">
  52. {rules.length > 0 ? (
  53. <Virtuoso
  54. data={rules}
  55. itemContent={(index, item) => (
  56. <RuleItem index={index + 1} value={item} />
  57. )}
  58. followOutput={"smooth"}
  59. />
  60. ) : (
  61. <BaseEmpty text="No Rules" />
  62. )}
  63. </Box>
  64. </BasePage>
  65. );
  66. };
  67. export default RulesPage;