Skip to content

Commit 7dcc72a

Browse files
authored
feat(web): fix functionPannel & dataPannel (#586)
1 parent 792a0f3 commit 7dcc72a

File tree

7 files changed

+59
-25
lines changed

7 files changed

+59
-25
lines changed

web/src/components/CopyText/index.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ import useGlobalStore from "@/pages/globalStore";
88
export default function CopyText(props: {
99
text: string;
1010
tip?: string;
11+
className?: string;
1112
children?: React.ReactElement;
1213
}) {
1314
const { onCopy, setValue } = useClipboard("");
1415
const { showSuccess } = useGlobalStore();
1516

16-
const { children = <CopyIcon />, text, tip } = props;
17+
const { children = <CopyIcon />, text, tip, className } = props;
1718

1819
useEffect(() => {
1920
setValue(text);
@@ -22,7 +23,7 @@ export default function CopyText(props: {
2223
return (
2324
<Tooltip label={t("ToolTip.Copy")} placement="top">
2425
{React.cloneElement(children, {
25-
className: "ml-2",
26+
className: "ml-2 " + (className || ""),
2627
onClick: () => {
2728
onCopy();
2829
showSuccess(tip || t("ToolTip.Copied"));

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,29 @@ import { Tab, TabList, TabPanel, TabPanels, Tabs } from "@chakra-ui/react";
22

33
import RightPanel from "../../mods/RightPanel";
44

5-
import ColPannel from "./mods/ColPannel";
5+
// import ColPannel from "./mods/ColPannel";
66
import DataPannel from "./mods/DataPannel";
7-
import IndexPannel from "./mods/IndexPannel";
7+
// import IndexPannel from "./mods/IndexPannel";
88

99
export default function CollectionDataList() {
1010
return (
1111
<RightPanel>
1212
<Tabs className="h-full">
1313
<TabList>
1414
<Tab>数据管理</Tab>
15-
<Tab>索引管理</Tab>
16-
<Tab>集合结构</Tab>
15+
{/* <Tab>索引管理</Tab>
16+
<Tab>集合结构</Tab> */}
1717
</TabList>
1818
<TabPanels className="h-full">
1919
<TabPanel className="overflow-hidden relative" style={{ height: "calc(100% - 55px)" }}>
2020
<DataPannel />
2121
</TabPanel>
22-
<TabPanel>
22+
{/* <TabPanel>
2323
<IndexPannel />
2424
</TabPanel>
2525
<TabPanel className="overflow-hidden relative" style={{ height: "calc(100% - 35px)" }}>
2626
<ColPannel />
27-
</TabPanel>
27+
</TabPanel> */}
2828
</TabPanels>
2929
</Tabs>
3030
</RightPanel>

web/src/pages/app/database/CollectionDataList/mods/DataPannel/index.tsx

+11-2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ import Pagination from "@/components/Pagination";
1010
import getPageInfo from "@/utils/getPageInfo";
1111

1212
import { useAddDataMutation, useEntryDataQuery, useUpdateDataMutation } from "../../../service";
13+
import useDBMStore from "../../../store";
1314

1415
import DeleteButton from "./DeleteButton";
1516
export default function DataPannel() {
1617
const [currentData, setCurrentData] = useState<any>(undefined);
1718

1819
const [record, setRecord] = useState("");
19-
20+
const store = useDBMStore((state) => state);
2021
type FormData = {
2122
_id: string;
2223
};
@@ -71,9 +72,16 @@ export default function DataPannel() {
7172
pointerEvents="none"
7273
children={<Search2Icon color="gray.300" />}
7374
/>
74-
<Input borderRadius="4" placeholder="_id" bg="white" {...register("_id")} />
75+
<Input
76+
disabled={store.currentDB === undefined}
77+
borderRadius="4"
78+
placeholder="_id"
79+
bg="white"
80+
{...register("_id")}
81+
/>
7582
</InputGroup>
7683
<Button
84+
disabled={store.currentDB === undefined}
7785
px={9}
7886
type={"submit"}
7987
colorScheme={"green"}
@@ -86,6 +94,7 @@ export default function DataPannel() {
8694
</div>
8795
</form>
8896
<Button
97+
disabled={store.currentDB === undefined}
8998
colorScheme={"primary"}
9099
size="sm"
91100
onClick={() => {

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

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export default function CollectionListPanel() {
2121
onSuccess: (data) => {
2222
if (data.data.length > 0) {
2323
store.setCurrentDB(data.data[0]);
24+
} else {
25+
store.setCurrentDB(undefined);
2426
}
2527
},
2628
});

web/src/pages/app/database/store.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { immer } from "zustand/middleware/immer";
55
import { TDB } from "@/apis/typing";
66

77
type State = {
8-
currentDB?: TDB;
9-
setCurrentDB: (currentDB: TDB) => void;
8+
currentDB?: TDB | undefined;
9+
setCurrentDB: (currentDB: TDB | undefined) => void;
1010
};
1111

1212
const useDBMStore = create<State>()(

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

-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import { Badge, Button, Center, HStack } from "@chakra-ui/react";
66
import { t } from "i18next";
77

8-
import CopyText from "@/components/CopyText";
98
import FunctionEditor from "@/components/Editor/FunctionEditor";
109
import FileTypeIcon, { FileType } from "@/components/FileTypeIcon";
1110
import PanelHeader from "@/components/Panel/Header";
@@ -75,12 +74,6 @@ function FunctionPage() {
7574
</div>
7675

7776
<HStack spacing="4">
78-
{store.getFunctionUrl() !== "" && (
79-
<span>
80-
<span className=" text-slate-500">调用地址:{store.getFunctionUrl()}</span>
81-
<CopyText text={store.getFunctionUrl()} />
82-
</span>
83-
)}
8477
<DeployButton />
8578
<Button
8679
size="sm"

web/src/pages/app/functions/mods/DebugPannel/index.tsx

+35-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
import React, { useState } from "react";
1+
import React, { useEffect, useState } from "react";
22
import SyntaxHighlighter from "react-syntax-highlighter";
33
import {
44
Button,
55
Center,
66
Input,
7+
InputGroup,
8+
InputRightElement,
9+
Select,
710
Spinner,
811
Tab,
912
TabList,
@@ -14,6 +17,7 @@ import {
1417
import axios from "axios";
1518
import { t } from "i18next";
1619

20+
import CopyText from "@/components/CopyText";
1721
import JsonEditor from "@/components/Editor/JsonEditor";
1822
import PanelHeader from "@/components/Panel/Header";
1923
import { Pages } from "@/constants";
@@ -34,6 +38,7 @@ export default function DebugPanel() {
3438

3539
const [runningResData, setRunningResData] = useState();
3640
const [isLoading, setIsLoading] = useState(false);
41+
const [runningMethod, setRunningMethod] = useState<string>("");
3742

3843
const compileMutation = useCompileMutation();
3944

@@ -58,6 +63,11 @@ export default function DebugPanel() {
5863
enabled: globalStore.currentPageId === Pages.function,
5964
},
6065
);
66+
useEffect(() => {
67+
if (currentFunction?.methods) {
68+
setRunningMethod(currentFunction.methods[0]);
69+
}
70+
}, [setRunningMethod, currentFunction]);
6171

6272
const runningCode = async () => {
6373
if (isLoading || !currentFunction?.id) return;
@@ -70,7 +80,7 @@ export default function DebugPanel() {
7080
if (!compileRes.error) {
7181
const res = await axios({
7282
url: getFunctionDebugUrl(),
73-
method: "post",
83+
method: runningMethod,
7484
data: {
7585
func: compileRes.data || "",
7686
param: JSON.parse(params),
@@ -101,10 +111,29 @@ export default function DebugPanel() {
101111
<div className="flex flex-col h-full">
102112
<div className="flex-1 border-r-slate-300 flex flex-col">
103113
<div className="flex py-4 px-2 items-center">
104-
<Button size="sm" className="mr-2">
105-
GET
106-
</Button>
107-
<Input size="sm" readOnly rounded={4} value={getFunctionDebugUrl()} />
114+
<Select
115+
width="150px"
116+
size="sm"
117+
value={runningMethod}
118+
disabled={getFunctionDebugUrl() === ""}
119+
onChange={(e) => {
120+
setRunningMethod(e.target.value);
121+
}}
122+
>
123+
{currentFunction.methods?.map((item: string) => {
124+
return (
125+
<option value={item} key={item}>
126+
{item}
127+
</option>
128+
);
129+
})}
130+
</Select>
131+
<InputGroup className="ml-2">
132+
<Input size="sm" readOnly rounded={4} value={getFunctionDebugUrl()} />
133+
<InputRightElement>
134+
<CopyText text={getFunctionDebugUrl()} className="mb-2" />
135+
</InputRightElement>
136+
</InputGroup>
108137
<Button
109138
style={{ borderRadius: 2 }}
110139
size="sm"

0 commit comments

Comments
 (0)