forked from labring/laf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
167 lines (161 loc) · 6.31 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import { useState } from "react";
import React from "react";
import { AddIcon, DeleteIcon, Search2Icon } from "@chakra-ui/icons";
import {
Button,
Center,
HStack,
Input,
InputGroup,
InputLeftElement,
Modal,
ModalBody,
ModalCloseButton,
ModalContent,
ModalHeader,
ModalOverlay,
Spinner,
Table,
TableContainer,
Tbody,
Td,
Th,
Thead,
Tr,
useDisclosure,
} from "@chakra-ui/react";
import { t } from "i18next";
import ConfirmButton from "@/components/ConfirmButton";
import EmptyBox from "@/components/EmptyBox";
import IconWrap from "@/components/IconWrap";
import { formatDate } from "@/utils/format";
import AddTriggerModal from "./AddTriggerModal";
import { useDeleteTriggerMutation, useTriggerListQuery } from "./service";
export default function TriggerModal(props: { children: React.ReactElement }) {
const [searchKey, setSearchKey] = useState<string>("");
const triggerListQuery = useTriggerListQuery(() => {});
const deleteTriggerMutation = useDeleteTriggerMutation(() => {
triggerListQuery.refetch();
});
const { isOpen, onOpen, onClose } = useDisclosure();
return (
<>
{React.cloneElement(props.children, {
onClick: () => {
onOpen();
triggerListQuery.refetch();
},
})}
<Modal isOpen={isOpen} onClose={onClose} size="4xl">
<ModalOverlay />
<ModalContent>
<ModalHeader>{t("TriggerPanel.Trigger")}</ModalHeader>
<ModalCloseButton />
<ModalBody pb={6}>
<div className="flex">
<AddTriggerModal>
<Button colorScheme="primary" leftIcon={<AddIcon />}>
{t("TriggerPanel.AddTrigger")}
</Button>
</AddTriggerModal>
<InputGroup className="ml-4" width={"35%"}>
<InputLeftElement
height={"8"}
left="2"
pointerEvents="none"
children={<Search2Icon color="gray.300" fontSize={12} />}
/>
<Input
rounded={"full"}
placeholder={t("TriggerPanel.SearchTip").toString()}
size={"sm"}
onChange={(e) => setSearchKey(e.target.value)}
/>
</InputGroup>
</div>
<div className="relative mt-4 h-full rounded-md">
{triggerListQuery.isFetching ? (
<Center className="absolute bottom-0 left-0 right-0 top-0 z-10 bg-white opacity-60">
<Spinner size={"lg"} />
</Center>
) : null}
<div className="mb-4 h-full overflow-y-auto">
{triggerListQuery.data?.data?.length ? (
<TableContainer minH={"400px"}>
<Table variant="simple">
<Thead>
<Tr bgColor={"#fbfbfc"}>
<Th borderTopLeftRadius={"10px"} borderBottomLeftRadius={"10px"}>
{t("TriggerPanel.Name")}
</Th>
<Th>{t("TriggerPanel.Function")}</Th>
<Th>{t("TriggerPanel.Type")}</Th>
<Th>{t("TriggerPanel.Cron")}</Th>
<Th>{t("TriggerPanel.Time")}</Th>
<Th borderTopRightRadius={"10px"} borderBottomRightRadius={"10px"}>
{t("Operation")}
</Th>
</Tr>
</Thead>
<Tbody className="relative font-mono">
{triggerListQuery.data?.data
.filter((item: any) => {
return item.desc.indexOf(searchKey) > -1;
})
.map((item: any) => (
<Tr key={item._id} _hover={{ bgColor: "#FBFBFC" }}>
<Td borderTopLeftRadius={"10px"} borderBottomLeftRadius={"10px"}>
<span>{item.desc}</span>
</Td>
<Td>
<span>{item.target}</span>
</Td>
<Td>
<span>{t("TriggerPanel.SetTimeout")}</span>
</Td>
<Td>
<span>{item.cron}</span>
</Td>
<Td className="text-slate-500" maxWidth="5rem">
{formatDate(item.updatedAt, "YYYY-MM-DD HH:mm")}
</Td>
<Td borderTopRightRadius={"10px"} borderBottomRightRadius={"10px"}>
<HStack spacing={1}>
<ConfirmButton
onSuccessAction={() =>
deleteTriggerMutation.mutate({ id: item._id })
}
headerText={String(t("Delete"))}
bodyText={t("TriggerPanel.DeleteConfirm")}
>
<IconWrap tooltip={String(t("Delete"))}>
<DeleteIcon fontSize={15} />
</IconWrap>
</ConfirmButton>
</HStack>
</Td>
</Tr>
))}
</Tbody>
</Table>
</TableContainer>
) : (
<EmptyBox className="min-h-[400px]">
<div>
<span>{t("TriggerPanel.EmptyTriggerTip")}</span>
<AddTriggerModal>
<span className="ml-2 cursor-pointer text-primary-600 hover:border-b-2 hover:border-primary-600">
{t("CreateNow")}
</span>
</AddTriggerModal>
</div>
</EmptyBox>
)}
</div>
</div>
</ModalBody>
</ModalContent>
</Modal>
</>
);
}