Skip to content

Commit 3380690

Browse files
authored
fix(web): pagination ts error (#560)
* fix: pagination ts error * fix: ignore files
1 parent 97c4728 commit 3380690

9 files changed

Lines changed: 52 additions & 27 deletions

File tree

web/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# Logs
2-
logs
32
*.log
43
npm-debug.log*
54
yarn-debug.log*

web/public/locales/zh-CN/translation.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
"Message": {
2222
"DeploySuccess": "发布成功"
2323
},
24+
"ToolTip": {
25+
"Copy": "复制",
26+
"Copied": "已复制"
27+
},
2428
"Common": {
2529
"Dialog": {
2630
"Confirm": "确定",

web/src/components/ConfirmButton/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ interface ConfirmButtonProps {
1616
headerText: string;
1717
bodyText: string;
1818

19-
children: React.ReactNode;
19+
children: React.ReactElement;
2020
}
2121

2222
const ConfirmButton = ({ onSuccessAction, headerText, bodyText, children }: ConfirmButtonProps) => {
@@ -30,7 +30,7 @@ const ConfirmButton = ({ onSuccessAction, headerText, bodyText, children }: Conf
3030

3131
return (
3232
<>
33-
{React.cloneElement(children as React.ReactElement, {
33+
{React.cloneElement(children, {
3434
onClick: onOpen,
3535
})}
3636

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,33 @@
11
import React, { useEffect } from "react";
22
import { CopyIcon } from "@chakra-ui/icons";
3-
import { useClipboard } from "@chakra-ui/react";
3+
import { Tooltip, useClipboard } from "@chakra-ui/react";
4+
import { t } from "i18next";
45

56
import useGlobalStore from "@/pages/globalStore";
67

7-
export default function CopyText(props: { text: string; tip?: string }) {
8+
export default function CopyText(props: {
9+
text: string;
10+
tip?: string;
11+
children?: React.ReactElement;
12+
}) {
813
const { onCopy, setValue } = useClipboard("");
914
const { showSuccess } = useGlobalStore();
1015

11-
const text = props.text;
16+
const { children = <CopyIcon />, text, tip } = props;
17+
1218
useEffect(() => {
1319
setValue(text);
1420
}, [setValue, text]);
1521

1622
return (
17-
<CopyIcon
18-
className="ml-1"
19-
fontSize={12}
20-
onClick={() => {
21-
onCopy();
22-
showSuccess(props.tip || "复制成功");
23-
}}
24-
/>
23+
<Tooltip label={t("ToolTip.Copy")} placement="top">
24+
{React.cloneElement(children, {
25+
className: "ml-2",
26+
onClick: () => {
27+
onCopy();
28+
showSuccess(tip || t("ToolTip.Copied"));
29+
},
30+
})}
31+
</Tooltip>
2532
);
2633
}

web/src/components/Pagination/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default function Pagination(props: {
1313
}) {
1414
const { values, onChange } = props;
1515
const { page = 1, total, limit = 10 } = values;
16-
const maxPage = total ? Math.ceil(total / limit) : undefined;
16+
const maxPage = total ? Math.ceil(total / limit) : -1;
1717

1818
return (
1919
<Flex justifyContent="end" m={4} alignItems="center">
@@ -59,7 +59,7 @@ export default function Pagination(props: {
5959
</Text>
6060
/
6161
<Text fontWeight="bold" as="p" width={"40px"} display="inline-block" textAlign={"center"}>
62-
{isNaN(maxPage) ? "" : maxPage}
62+
{maxPage < 0 ? "" : maxPage}
6363
</Text>
6464
</Flex>
6565

web/src/pages/app/database/CollectionListPanel/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export default function CollectionListPanel() {
6666
<span className="ml-2 text-base">{db.name}</span>
6767
</div>
6868
<div className="invisible flex group-hover:visible">
69-
<IconWrap tooltip="复制">
69+
<IconWrap>
7070
<CopyText text={db.name} tip="名称复制成功" />
7171
</IconWrap>
7272
<DeleteCollectionModal database={db} />

web/src/pages/app/logs/index.tsx

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
} from "@chakra-ui/react";
2020
import { useQuery } from "@tanstack/react-query";
2121

22+
import CopyText from "@/components/CopyText";
2223
import Pagination from "@/components/Pagination";
2324
import { formatDate } from "@/utils/format";
2425
import getPageInfo from "@/utils/getPageInfo";
@@ -116,21 +117,32 @@ export default function LogsPage() {
116117
</Tr>
117118
</Thead>
118119

119-
{logListQuery.isFetching ? (
120-
<Center>
121-
<Spinner />
122-
</Center>
123-
) : null}
124-
125120
<Tbody className="relative">
121+
{logListQuery.isFetching ? (
122+
<Tr>
123+
<Td colSpan={5} height="200px" border={"none"}>
124+
<Center>
125+
<Spinner />
126+
</Center>
127+
</Td>
128+
</Tr>
129+
) : null}
126130
{logListQuery.data?.data?.list.map((item: any) => {
127131
return (
128132
<Tr key={item._id} _hover={{ bgColor: "#efefef" }}>
129133
<Td width={"200px"} className=" text-black-600 ">
130134
{formatDate(item.created_at)}
131135
</Td>
132-
<Td width={"360px"}>{item.request_id}</Td>
133-
<Td>{item.func}</Td>
136+
<Td width={"360px"}>
137+
<CopyText text={item.request_id}>
138+
<span>{item.request_id}</span>
139+
</CopyText>
140+
</Td>
141+
<Td>
142+
<CopyText text={item.func}>
143+
<span>{item.func}</span>
144+
</CopyText>
145+
</Td>
134146
<Td isNumeric>
135147
<span className=" text-green-700">{item.time_usage} ms</span>
136148
</Td>

web/src/pages/app/logs/service.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const queryKeys = {
2+
useLogsQuery: ["useLogsQuery"],
3+
};

web/src/pages/home/mods/CreateAppModal/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { APP_STATUS, DEFAULT_REGION } from "@/constants/index";
2626
import { ApplicationControllerCreate, ApplicationControllerUpdate } from "@/apis/v1/applications";
2727
import useGlobalStore from "@/pages/globalStore";
2828

29-
const CreateAppModal = (props: { application?: any; children: React.ReactNode }) => {
29+
const CreateAppModal = (props: { application?: any; children: React.ReactElement }) => {
3030
const { isOpen, onOpen, onClose } = useDisclosure();
3131
const queryClient = useQueryClient();
3232

@@ -87,7 +87,7 @@ const CreateAppModal = (props: { application?: any; children: React.ReactNode })
8787

8888
return (
8989
<>
90-
{React.cloneElement(props.children as React.ReactElement, {
90+
{React.cloneElement(props.children, {
9191
onClick: () => {
9292
reset(defaultValues);
9393
onOpen();

0 commit comments

Comments
 (0)