Skip to content

Commit 1ec4d0c

Browse files
committed
feat: add function create
1 parent a12540b commit 1ec4d0c

File tree

10 files changed

+138
-70
lines changed

10 files changed

+138
-70
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from "react";
2+
3+
export default function Icon(props: { children: React.ReactNode; onClick: () => void }) {
4+
return (
5+
<span
6+
onClick={props.onClick}
7+
className="hover:bg-slate-200 rounded inline-block text-center"
8+
style={{ width: 20, height: 20, lineHeight: "18px" }}
9+
>
10+
{props.children}
11+
</span>
12+
);
13+
}

packages/next-web/pages/app/[app_id]/functions/index.module.scss

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
display: flex;
44
align-items: center;
55
margin-bottom: 12px;
6+
padding: 0 12px;
67
justify-content: space-between;
78
border-top: 1px solid #eaeaea;
89
border-bottom: 1px solid #eaeaea;

packages/next-web/pages/app/[app_id]/functions/index.tsx

+9-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* cloud functions index page
33
***************************/
44

5-
import React from "react";
5+
import React, { useEffect } from "react";
66
import { AttachmentIcon } from "@chakra-ui/icons";
77
import { Button, HStack } from "@chakra-ui/react";
88
import Editor from "@monaco-editor/react";
@@ -23,7 +23,13 @@ import useFunctionStore from "./store";
2323
import commonStyles from "./index.module.scss";
2424

2525
function FunctionPage() {
26-
const store = useFunctionStore((store) => store);
26+
const { initFunctionPage, currentFunction } = useFunctionStore((store) => store);
27+
28+
useEffect(() => {
29+
initFunctionPage();
30+
31+
return () => {};
32+
}, [initFunctionPage]);
2733

2834
return (
2935
<div className="flex h-screen" style={{ marginLeft: SiderBarWidth }}>
@@ -57,7 +63,7 @@ function FunctionPage() {
5763
</div>
5864
</div>
5965
<div className="flex-1">
60-
<Editor height="100%" defaultLanguage="javascript" defaultValue={funcString} />
66+
<Editor height="100%" defaultLanguage="javascript" value={currentFunction?.code} />
6167
</div>
6268
<div style={{ height: 300 }}>
6369
<DebugPanel />

packages/next-web/pages/app/[app_id]/functions/mods/DebugPannel/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default function DebugPanel() {
1111
</HStack>
1212
</div>
1313
<div className="flex flex-1">
14-
<div style={{ width: 500 }} className="border border-r-indigo-400 ">
14+
<div style={{ width: 500 }} className="border-r border-r-slate-300 ">
1515
<div className="flex p-2">
1616
<Button size="sm" className="mr-2">
1717
GET

packages/next-web/pages/app/[app_id]/functions/mods/DependecePanel/AddDepenceModal/index.module.scss

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import React from "react";
2+
import { AddIcon } from "@chakra-ui/icons";
3+
import {
4+
Button,
5+
Center,
6+
FormControl,
7+
FormLabel,
8+
Input,
9+
Modal,
10+
ModalBody,
11+
ModalCloseButton,
12+
ModalContent,
13+
ModalFooter,
14+
ModalHeader,
15+
ModalOverlay,
16+
useDisclosure,
17+
} from "@chakra-ui/react";
18+
19+
import Icon from "@/components/Icon";
20+
21+
function AddDepenceModal() {
22+
const { isOpen, onOpen, onClose } = useDisclosure();
23+
24+
const initialRef = React.useRef(null);
25+
26+
return (
27+
<>
28+
<Icon onClick={onOpen}>
29+
<AddIcon />
30+
</Icon>
31+
32+
<Modal initialFocusRef={initialRef} isOpen={isOpen} onClose={onClose}>
33+
<ModalOverlay />
34+
<ModalContent>
35+
<ModalHeader>Create your account</ModalHeader>
36+
<ModalCloseButton />
37+
<ModalBody pb={6}>
38+
<FormControl>
39+
<FormLabel>First name</FormLabel>
40+
<Input ref={initialRef} placeholder="First name" />
41+
</FormControl>
42+
43+
<FormControl mt={4}>
44+
<FormLabel>Last name</FormLabel>
45+
<Input placeholder="Last name" />
46+
</FormControl>
47+
</ModalBody>
48+
49+
<ModalFooter>
50+
<Button colorScheme="blue" mr={3}>
51+
Save
52+
</Button>
53+
<Button onClick={onClose}>Cancel</Button>
54+
</ModalFooter>
55+
</ModalContent>
56+
</Modal>
57+
</>
58+
);
59+
}
60+
61+
export default AddDepenceModal;

packages/next-web/pages/app/[app_id]/functions/mods/DependecePanel/index.tsx

+8-6
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,24 @@ import React from "react";
66
import { AttachmentIcon, WarningIcon } from "@chakra-ui/icons";
77
import { HStack, Input } from "@chakra-ui/react";
88

9+
import AddDepenceModal from "./AddDepenceModal";
10+
911
import commonStyles from "../../index.module.scss";
1012
import styles from "./index.module.scss";
1113

1214
export default function DependecyList() {
1315
return (
1416
<div>
1517
<div className={commonStyles.sectionHeader + " flex justify-between"}>
16-
<h4 className="m-2">NPM 依赖</h4>
18+
<h4>NPM 依赖</h4>
19+
<HStack spacing="2">
20+
<AddDepenceModal />
21+
</HStack>
1722
</div>
1823
<div>
19-
<div className="flex items-center m-2 ">
24+
{/* <div className="flex items-center m-2 ">
2025
<Input size="sm" className="mr-2" />
21-
<HStack spacing="2">
22-
<WarningIcon />
23-
</HStack>
24-
</div>
26+
</div> */}
2527

2628
<ul className={styles.functionList + " mb-4"}>
2729
<li>

packages/next-web/pages/app/[app_id]/functions/mods/FunctionPanel/index.tsx

+6-11
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,19 @@ import { useQuery } from "@tanstack/react-query";
1616
import request from "@/utils/request";
1717

1818
import useFunctionStore from "../../store";
19-
import CreateModal from "../CreateModal";
19+
20+
import CreateModal from "./CreateModal";
2021

2122
import commonStyles from "../../index.module.scss";
2223
import styles from "./index.module.scss";
2324

2425
export default function FunctionList() {
2526
const store = useFunctionStore((store) => store);
2627

27-
const { data } = useQuery(["functions"], () => {
28-
return request.get("/api/function_list");
29-
});
30-
31-
console.log(123, data);
32-
3328
return (
3429
<div>
3530
<div className={commonStyles.sectionHeader + " flex justify-between"}>
36-
<h4 className="m-2">函数列表</h4>
31+
<h4>函数列表</h4>
3732
<HStack spacing="2">
3833
<SunIcon />
3934
<CreateModal />
@@ -70,13 +65,13 @@ export default function FunctionList() {
7065

7166
<h5 className="m-2">所有函数</h5>
7267
<ul className={styles.functionList + " mb-4"}>
73-
{(data?.data || []).map((func: any) => {
68+
{(store.allFunctionList || []).map((func: any) => {
7469
return (
7570
<li
76-
className={func.id === store.currentFunction ? styles.active : ""}
71+
className={func._id === store.currentFunction?._id ? styles.active : ""}
7772
key={func._id}
7873
onClick={() => {
79-
store.setCurrentFunction(func._id);
74+
store.setCurrentFunction(func);
8075
}}
8176
>
8277
<div>

packages/next-web/pages/app/[app_id]/functions/store.ts

+39-49
Original file line numberDiff line numberDiff line change
@@ -2,67 +2,57 @@ import create from "zustand";
22
import { devtools } from "zustand/middleware";
33
import { immer } from "zustand/middleware/immer";
44

5+
import request from "@/utils/request";
6+
7+
type TFunction =
8+
| {
9+
_id: string;
10+
name: string;
11+
code: string;
12+
label: string;
13+
hash: string;
14+
tags: string[];
15+
description: string;
16+
enableHTTP: boolean;
17+
status: number;
18+
triggers: any[];
19+
debugParams: string;
20+
version: number;
21+
created_at: Date;
22+
updated_at: Date;
23+
created_by: string;
24+
appid: string;
25+
}
26+
| undefined;
27+
528
type State = {
6-
currentFunction: number;
29+
currentFunction: TFunction;
730
favFunctoinList: any[];
8-
allFunctionList: any[];
31+
allFunctionList?: any[];
32+
initFunctionPage: () => void;
933

10-
setCurrentFunction: (currentFunction: number) => void;
34+
setCurrentFunction: (currentFunction: TFunction) => void;
1135
};
1236

1337
const useFunctionStore = create<State>()(
1438
devtools(
1539
immer((set) => ({
16-
currentFunction: 0,
17-
favFunctoinList: [
18-
{
19-
id: "123",
20-
name: "addToto",
21-
},
22-
{
23-
id: "222",
24-
name: "antDirt",
25-
},
26-
{
27-
id: "333",
28-
name: "getUser",
29-
},
30-
{
31-
id: "444",
32-
name: "getQrCode",
33-
},
34-
{
35-
id: "555",
36-
name: "getUxserInfo",
37-
},
38-
],
40+
currentFunction: undefined,
41+
favFunctoinList: [],
3942

40-
allFunctionList: [
41-
{
42-
id: "123",
43-
name: "addToto",
44-
},
45-
{
46-
id: "222",
47-
name: "antDirt",
48-
},
49-
{
50-
id: "333",
51-
name: "getUser",
52-
},
53-
{
54-
id: "444",
55-
name: "getQrCode",
56-
},
57-
{
58-
id: "555",
59-
name: "getUxserInfo",
60-
},
61-
],
43+
allFunctionList: [],
44+
45+
initFunctionPage: async () => {
46+
const res = await request.get("/api/function_list");
47+
set((state) => {
48+
state.allFunctionList = res.data;
49+
state.currentFunction = res.data[0];
50+
});
51+
},
6252

6353
setCurrentFunction: (currentFunction) =>
6454
set((state) => {
65-
state.currentFunction = currentFunction;
55+
state.currentFunction = JSON.parse(JSON.stringify(currentFunction));
6656
return state;
6757
}),
6858
})),

0 commit comments

Comments
 (0)