Skip to content

Commit c68b03b

Browse files
authored
feat(web): generate function code with AI prompt (#978)
* refactor(web): new logo * feat(web): add prompt function code generate
1 parent 251a3c4 commit c68b03b

File tree

16 files changed

+358
-40
lines changed

16 files changed

+358
-40
lines changed

.vscode/settings.json

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
"sealctl",
9393
"sealos",
9494
"signin",
95+
"Signup",
9596
"statefulset",
9697
"storageclass",
9798
"tailwindcss",

web/public/favicon.ico

-116 KB
Binary file not shown.

web/public/locales/en/translation.json

+11-8
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"Copied": "copied",
4444
"Copy": "copy",
4545
"Create": "new application",
46-
"CreateNow": "create now",
46+
"CreateNow": "Create Now",
4747
"Custom": "customize",
4848
"Days": "days",
4949
"Delete": "Delete ",
@@ -88,7 +88,6 @@
8888
"DeploySuccess": "Deploy successfully",
8989
"Description": "Function Description",
9090
"EditFunction": "Edit Function",
91-
"EmptyText": "No function information yet,",
9291
"Function": "Function",
9392
"FunctionList": "Function List",
9493
"FunctionName": "Function Name",
@@ -106,7 +105,9 @@
106105
"EmptyDebugTip": "No results yet",
107106
"EmptyFunctionTip": "You have not created the function",
108107
"UploadButton": "upload",
109-
"LeaveFunctionPage": "About to leave the function edit page"
108+
"LeaveFunctionPage": "About to leave the function edit page",
109+
"PromptDescription": "Use natural language to describe your needs, laf will help you generate code, for example: help me write a hello world, return {hello: 'laf AI'}",
110+
"CreateWithAITip": "Create functions with AI assistance"
110111
},
111112
"HomePanel": {
112113
"APP": "Android or iOS app",
@@ -308,10 +309,10 @@
308309
"PasswordNotMatch": "The two passwords you entered do not match",
309310
"SmsCodeSendSuccess": "Verification code sent successfully",
310311
"ValidationCodePlaceholder": "Please input the verification code",
311-
"SignupSuccess": "Sign up successfully",
312312
"ResetPassword": "Reset Password",
313313
"ResetPasswordSuccess": "Reset password successfully",
314-
"NewPassword": "New Password"
314+
"NewPassword": "New Password",
315+
"SignUpSuccess": "Sign up successfully"
315316
},
316317
"Time": "Time",
317318
"CreateTime": "Created",
@@ -328,6 +329,8 @@
328329
"payment status": "Payment status",
329330
"Monthly": "Monthly",
330331
"CreateFolder": "New Folder",
331-
"Or": "or",
332-
"BeforeunloadTip": "Are you sure you want to leave the current editing page?"
333-
}
332+
"Or": "Or",
333+
"Generating": "Generating",
334+
"Start": "Start",
335+
"TryLafAI": "Try 🎉 Laf AI !"
336+
}

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

+9-6
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@
8888
"DeploySuccess": "发布成功",
8989
"Description": "函数描述",
9090
"EditFunction": "编辑函数",
91-
"EmptyText": "暂无函数信息,",
9291
"Function": "函数",
9392
"FunctionList": "函数列表",
9493
"FunctionName": "函数名",
@@ -106,7 +105,9 @@
106105
"EmptyDebugTip": "暂无运行结果",
107106
"EmptyFunctionTip": "您还没有创建函数",
108107
"UploadButton": "上传",
109-
"LeaveFunctionPage": "即将离开函数编辑页面"
108+
"LeaveFunctionPage": "即将离开函数编辑页面",
109+
"PromptDescription": "使用自然语言描述你的需求, laf 会帮你生成代码, 例如: 写一个 hello world ,返回 {hello: 'laf AI'}",
110+
"CreateWithAITip": "使用 AI 辅助创建函数"
110111
},
111112
"HomePanel": {
112113
"APP": "Android or iOS 应用",
@@ -308,10 +309,10 @@
308309
"PasswordNotMatch": "两次输入的密码不一致",
309310
"SmsCodeSendSuccess": "验证码发送成功",
310311
"ValidationCodePlaceholder": "请输入验证码",
311-
"SignupSuccess": "注册成功",
312312
"ResetPassword": "重置密码",
313313
"ResetPasswordSuccess": "重置密码成功",
314-
"NewPassword": "新密码"
314+
"NewPassword": "新密码",
315+
"SignUpSuccess": "注册成功"
315316
},
316317
"Time": "时间",
317318
"CreateTime": "创建时间",
@@ -329,5 +330,7 @@
329330
"Monthly": "",
330331
"CreateFolder": "新建文件夹",
331332
"Or": "",
332-
"BeforeunloadTip": "确定要离开当前编辑页面吗?"
333-
}
333+
"Generating": "正在生成",
334+
"Start": "开始生成",
335+
"TryLafAI": "试试 🎉 Laf AI !"
336+
}

web/public/locales/zh/translation.json

+9-6
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@
8888
"DeploySuccess": "发布成功",
8989
"Description": "函数描述",
9090
"EditFunction": "编辑函数",
91-
"EmptyText": "暂无函数信息,",
9291
"Function": "函数",
9392
"FunctionList": "函数列表",
9493
"FunctionName": "函数名",
@@ -106,7 +105,9 @@
106105
"EmptyDebugTip": "暂无运行结果",
107106
"EmptyFunctionTip": "您还没有创建函数",
108107
"UploadButton": "上传",
109-
"LeaveFunctionPage": "即将离开函数编辑页面"
108+
"LeaveFunctionPage": "即将离开函数编辑页面",
109+
"PromptDescription": "使用自然语言描述你的需求, laf 会帮你生成代码, 例如: 写一个 hello world ,返回 {hello: 'laf AI'}",
110+
"CreateWithAITip": "使用 AI 辅助创建函数"
110111
},
111112
"HomePanel": {
112113
"APP": "Android or iOS 应用",
@@ -308,10 +309,10 @@
308309
"PasswordNotMatch": "两次输入的密码不一致",
309310
"SmsCodeSendSuccess": "验证码发送成功",
310311
"ValidationCodePlaceholder": "请输入验证码",
311-
"SignupSuccess": "注册成功",
312312
"ResetPassword": "重置密码",
313313
"ResetPasswordSuccess": "重置密码成功",
314-
"NewPassword": "新密码"
314+
"NewPassword": "新密码",
315+
"SignUpSuccess": "注册成功"
315316
},
316317
"Time": "时间",
317318
"CreateTime": "创建时间",
@@ -329,5 +330,7 @@
329330
"Monthly": "",
330331
"CreateFolder": "新建文件夹",
331332
"Or": "",
332-
"BeforeunloadTip": "确定要离开当前编辑页面吗?"
333-
}
333+
"Generating": "正在生成",
334+
"Start": "开始生成",
335+
"TryLafAI": "试试 🎉 Laf AI !"
336+
}

web/public/logo.png

-2.92 KB
Loading

web/public/logo_light.png

2.68 KB
Loading

web/public/logo_text.png

2.9 KB
Loading

web/src/components/Editor/FunctionEditor.tsx

+14-3
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,22 @@ const updateModel = (path: string, value: string, editorRef: any) => {
8888
function FunctionEditor(props: {
8989
value: string;
9090
className?: string;
91-
onChange: (value: string | undefined) => void;
91+
onChange?: (value: string | undefined) => void;
9292
path: string;
9393
height?: string;
9494
colorMode?: string;
95+
readOnly?: boolean;
9596
}) {
96-
const { value, onChange, path, height = "100%", className, colorMode = "light" } = props;
97+
const {
98+
value,
99+
onChange,
100+
path,
101+
height = "100%",
102+
className,
103+
colorMode = "light",
104+
readOnly = false,
105+
} = props;
106+
97107
const editorRef = useRef<monaco.editor.IStandaloneCodeEditor | null>();
98108
const subscriptionRef = useRef<monaco.IDisposable | undefined>(undefined);
99109
const monacoEl = useRef(null);
@@ -104,6 +114,7 @@ function FunctionEditor(props: {
104114
minimap: {
105115
enabled: false,
106116
},
117+
readOnly: readOnly,
107118
language: "typescript",
108119
automaticLayout: true,
109120
scrollbar: {
@@ -124,7 +135,7 @@ function FunctionEditor(props: {
124135
}
125136

126137
return () => {};
127-
}, [colorMode, path, value]);
138+
}, [colorMode, path, readOnly, value]);
128139

129140
useEffect(() => {
130141
if (monacoEl && editorRef.current) {

web/src/layouts/Header/index.tsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import { useTranslation } from "react-i18next";
66
import { FiGithub } from "react-icons/fi";
7+
import { useColorMode } from "@chakra-ui/react";
78

89
import UserSetting from "./UserSetting";
910

@@ -12,11 +13,17 @@ import useGlobalStore from "@/pages/globalStore";
1213
export default function Header(props: { size: "sm" | "lg" }) {
1314
const { userInfo } = useGlobalStore((state) => state);
1415
const { t } = useTranslation();
16+
const { colorMode } = useColorMode();
1517

1618
return (
1719
<div className="flex justify-between px-10 py-4 h-[60px]">
1820
<div className="flex items-center">
19-
<img src="/logo.png" alt="logo" width={30} className="mr-4" />
21+
<img
22+
src={colorMode === "dark" ? "/logo_light.png" : "/logo_text.png"}
23+
alt="logo"
24+
width={80}
25+
className="mr-4"
26+
/>
2027
<a
2128
href="https://github.com/labring/laf"
2229
className="flex items-center ml-2 p-2 py-1 text-base text-gray-700 hover:text-black bg-white rounded-md"

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

+23-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { useTranslation } from "react-i18next";
12
import { HStack, Input, useColorMode } from "@chakra-ui/react";
23
import clsx from "clsx";
3-
import { t } from "i18next";
44

55
import CopyText from "@/components/CopyText";
66
import FunctionEditor from "@/components/Editor/FunctionEditor";
@@ -11,6 +11,7 @@ import { useFunctionListQuery } from "../../service";
1111
import useFunctionStore from "../../store";
1212
import DeployButton from "../DeployButton";
1313
import CreateModal from "../FunctionPanel/CreateModal";
14+
import PromptModal from "../FunctionPanel/CreateModal/PromptModal";
1415

1516
import FunctionDetailPopOver from "./FunctionDetailPopOver";
1617

@@ -20,6 +21,7 @@ function EditorPanel() {
2021
const store = useFunctionStore((store) => store);
2122
const { currentFunction, updateFunctionCode, getFunctionUrl } = store;
2223
const { colorMode } = useColorMode();
24+
const { t } = useTranslation();
2325
const functionCache = useFunctionCache();
2426

2527
const functionListQuery = useFunctionListQuery();
@@ -33,7 +35,7 @@ function EditorPanel() {
3335
"border-lafWhite-400": !darkMode,
3436
})}
3537
>
36-
<HStack maxW={"60%"} spacing={2}>
38+
<HStack maxW={"55%"} spacing={2}>
3739
<CopyText className="font-bold text-xl" text={currentFunction?.name}>
3840
<span>{currentFunction?.name}</span>
3941
</CopyText>
@@ -44,15 +46,15 @@ function EditorPanel() {
4446
<span className="flex-none inline-block w-2 h-2 rounded-full bg-warn-700"></span>
4547
)}
4648
{currentFunction?.desc ? (
47-
<span className="text-slate-400 font-normal whitespace-nowrap overflow-hidden">
49+
<span className="text-slate-400 font-normal whitespace-nowrap overflow-hidden text-ellipsis">
4850
{currentFunction?.desc}
4951
</span>
5052
) : null}
5153
</HStack>
5254

5355
<HStack spacing={1}>
5456
<CopyText text={getFunctionUrl()}>
55-
<Input minW={"260px"} size="sm" readOnly value={getFunctionUrl()} />
57+
<Input w={"240px"} size="sm" readOnly value={getFunctionUrl()} />
5658
</CopyText>
5759

5860
<DeployButton />
@@ -62,14 +64,23 @@ function EditorPanel() {
6264

6365
{!functionListQuery.isFetching && functionListQuery.data?.data?.length === 0 && (
6466
<EmptyBox>
65-
<div>
66-
{t("FunctionPanel.EmptyText")}
67-
<CreateModal key="create_modal_new">
68-
<span className="ml-2 text-primary-600 hover:border-b-2 hover:border-primary-600 cursor-pointer">
69-
{t("CreateNow")}
70-
</span>
71-
</CreateModal>
72-
</div>
67+
<>
68+
<div className="flex justify-center items-center">
69+
<CreateModal key="create_modal_new">
70+
<span className="ml-2 text-primary-600 border-b-2 border-b-transparent hover:border-primary-600 cursor-pointer">
71+
{t("CreateNow")}
72+
</span>
73+
</CreateModal>
74+
75+
<p className="mx-2 mb-[2px]">{t("Or")}</p>
76+
77+
<PromptModal>
78+
<span className="text-primary-600 font-bold border-b-2 border-b-transparent hover:border-primary-600 cursor-pointer">
79+
{t("TryLafAI")}
80+
</span>
81+
</PromptModal>
82+
</div>
83+
</>
7384
</EmptyBox>
7485
)}
7586

0 commit comments

Comments
 (0)