Skip to content

Commit

Permalink
fix(web): fix func name regx for creating func (#707)
Browse files Browse the repository at this point in the history
  • Loading branch information
LeezQ authored Jan 31, 2023
1 parent 888ee82 commit 3de3d1a
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 30 deletions.
14 changes: 9 additions & 5 deletions web/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"SystemDependence": "Built-In",
"Value": "Value",
"isSupport": "Whether to support",
"FunctionNameRule": "Function names can only be in letters"
"FunctionNameRule": "Function names can only start with _ or English"
},
"HomePanel": {
"APP": "Android or iOS app",
Expand Down Expand Up @@ -143,7 +143,7 @@
"Policy": "Permissions",
"Private": "Private",
"Readonly": "Readonly",
"Readwrite": "Readwrite",
"ReadWrite": "ReadWrite",
"SearchBucket": "Enter the bucket name to search",
"Size": "Size",
"Storage": "Cloud Storage",
Expand All @@ -158,8 +158,9 @@
"BucketName": "Bucket name",
"CreateBucket": "Create buckets",
"EditBucket": "Edit Bucket",
"DeleteBucket": "Delete Buckets"
"BucketNameRule": "Can only contain English or numbers or -, and cannot end with -"
"DeleteBucket": "Delete Buckets",
"BucketNameRule": "Can only contain lowercase English, numbers, and the beginning and end cannot be numbers or -",
"BucketNamePlaceholder": "bucket-name"
},
"TriggerPanel": {
"AddTrigger": "Add Trigger",
Expand All @@ -179,5 +180,8 @@
"Cron": "expression"
},
"NoData": "Currently no data",
"SaveAndRestart": "save and restart"
"SaveAndRestart": "save and restart",
"DataEntry": {
"CreateError": "field cannot be empty"
}
}
14 changes: 9 additions & 5 deletions web/public/locales/zh-CN/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"DependenceVersion": "依赖版本",
"DependenceTip": "请输入依赖包名",
"Select": "已选择",
"FunctionNameRule": "函数名只能是英文"
"FunctionNameRule": "函数名只能以 _ 或英文开头"
},
"TriggerPanel": {
"Trigger": "触发器",
Expand Down Expand Up @@ -121,7 +121,7 @@
"Policy": "权限",
"Private": "私有",
"Readonly": "公共读",
"Readwrite": "公共读写",
"ReadWrite": "公共读写",
"Upload": "上传",
"Drag": "拖放到此处或者",
"File": "文件",
Expand All @@ -142,7 +142,8 @@
"Used": "已使用",
"Success": "上传成功",
"EmptyText": "暂无Bucket数据",
"BucketNameRule": "只能包含英文或数字或 -,且不能以 - 结尾"
"BucketNameRule": "只能包含小写英文、数字,开头和结尾不能是数字或 -",
"BucketNamePlaceholder": "bucket-name"
},
"Search": "搜索",
"Close": "关闭",
Expand Down Expand Up @@ -178,5 +179,8 @@
"Page": "",
"NoData": "当前无数据",
"Logout": "退出登录",
"SaveAndRestart": "保存并重启"
}
"SaveAndRestart": "保存并重启",
"DataEntry": {
"CreateError": "字段不能为空"
}
}
14 changes: 9 additions & 5 deletions web/public/locales/zh/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"SystemDependence": "内置依赖",
"Value": "",
"isSupport": "是否支持",
"FunctionNameRule": "函数名只能是英文"
"FunctionNameRule": "函数名只能以 _ 或英文开头"
},
"HomePanel": {
"APP": "Android or iOS 应用",
Expand Down Expand Up @@ -143,7 +143,7 @@
"Policy": "权限",
"Private": "私有",
"Readonly": "公共读",
"Readwrite": "公共读写",
"ReadWrite": "公共读写",
"SearchBucket": "输入bucket名进行搜索",
"Size": "大小",
"Storage": "云存储",
Expand All @@ -154,12 +154,13 @@
"Upload": "上传",
"Used": "已使用",
"UploadTip": "请选择文件或者文件夹上传",
"BucketNameRule": "只能包含英文或数字或 -,且不能以 - 结尾",
"BucketNameRule": "只能包含小写英文、数字,开头和结尾不能是数字或 -",
"Bucket": "",
"BucketName": "Bucket名称",
"CreateBucket": "创建Bucket",
"EditBucket": "编辑Bucket",
"DeleteBucket": "删除Bucket"
"DeleteBucket": "删除Bucket",
"BucketNamePlaceholder": "bucket-name"
},
"TriggerPanel": {
"AddTrigger": "新建触发器",
Expand All @@ -179,5 +180,8 @@
"Cron": "表达式"
},
"NoData": "当前无数据",
"SaveAndRestart": "保存并重启"
"SaveAndRestart": "保存并重启",
"DataEntry": {
"CreateError": "字段不能为空"
}
}
2 changes: 1 addition & 1 deletion web/src/pages/app/database/CollectionDataList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function CollectionDataList() {
return (
<>
{store.currentDB === undefined ? (
<Center className="h-full">
<Center className="h-full text-lg">
{t("CollectionPanel.EmptyCollectionText")}
<CreateCollectionModal>
<span className="ml-2 text-blue-500 cursor-pointer">{t("CreateNow")}</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ import {
} from "../../../service";
import useDBMStore from "../../../store";

import useGlobalStore from "@/pages/globalStore";

export default function DataPanel() {
const [currentData, setCurrentData] = useState<any>(undefined);
const globalStore = useGlobalStore();

const [record, setRecord] = useState("");
const [record, setRecord] = useState("{}");
const store = useDBMStore((state) => state);
type QueryData = {
_id: string;
Expand Down Expand Up @@ -57,12 +60,21 @@ export default function DataPanel() {
});

const handleData = async () => {
if (currentData?._id) {
const params = JSON.parse(record);
await updateDataMutation.mutateAsync(params);
} else {
const params = JSON.parse(record);
await addDataMutation.mutateAsync(params);
let params = {};
try {
params = JSON.parse(record);
if (Object.keys(params).length === 0) {
globalStore.showError(t("DataEntry.CreateError"));
return;
}
if (currentData?._id) {
await updateDataMutation.mutateAsync(params);
} else {
await addDataMutation.mutateAsync(params);
}
} catch (error) {
globalStore.showError(error?.toString());
return;
}
};

Expand Down
2 changes: 1 addition & 1 deletion web/src/pages/app/functions/mods/EditorPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function EditorPanel() {
{currentFunction?.name ? (
<FunctionEditor
className="flex-grow"
path={currentFunction?.name || ""}
path={currentFunction?.id || ""}
value={functionCache.getCache(currentFunction!.id)}
onChange={(value) => {
updateFunctionCode(currentFunction, value || "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const CreateModal = (props: { functionItem?: any; children?: React.ReactElement
description: functionItem?.desc || "",
websocket: !!functionItem?.websocket,
methods: functionItem?.methods || ["GET", "POST"],
code: functionItem?.source.code || functionTemplates[0].value,
code: functionItem?.source.code || functionTemplates[0].value.trim(),
tags: [],
};

Expand Down Expand Up @@ -117,7 +117,7 @@ const CreateModal = (props: { functionItem?: any; children?: React.ReactElement
<Input
{...register("name", {
pattern: {
value: /^[A-Za-z][A-Za-z0-9-_]+$/,
value: /^[_A-Za-z][A-Za-z0-9-_]+$/,
message: t("FunctionPanel.FunctionNameRule"),
},
})}
Expand Down
3 changes: 3 additions & 0 deletions web/src/pages/app/functions/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
FunctionControllerRemove,
FunctionControllerUpdate,
} from "@/apis/v1/apps";
import useFunctionCache from "@/hooks/useFunctionCache";
import useGlobalStore from "@/pages/globalStore";

const queryKeys = {
Expand Down Expand Up @@ -70,6 +71,7 @@ export const useUpdateFunctionMutation = () => {
export const useDeleteFunctionMutation = () => {
const globalStore = useGlobalStore();
const store = useFunctionStore();
const functionCache = useFunctionCache();
const queryClient = useQueryClient();
return useMutation(
(values: any) => {
Expand All @@ -82,6 +84,7 @@ export const useDeleteFunctionMutation = () => {
} else {
queryClient.invalidateQueries(queryKeys.useFunctionListQuery);
store.setCurrentFunction({});
functionCache.removeCache(data?.data?.id);
}
},
},
Expand Down
2 changes: 1 addition & 1 deletion web/src/pages/app/storages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function StoragePage() {
<Col>
{currentStorage === undefined ? (
<Panel className="items-center h-full">
<Center className="h-full">
<Center className="h-full text-lg">
{t("StoragePanel.EmptyText")}
<CreateBucketModal>
<span className="ml-2 text-blue-500 cursor-pointer">{t("CreateNow")}</span>
Expand Down
5 changes: 3 additions & 2 deletions web/src/pages/app/storages/mods/CreateBucketModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,11 @@ function CreateBucketModal(props: { storage?: TBucket; children: React.ReactElem
{...register("name", {
required: true,
pattern: {
value: /^[A-Za-z][A-Za-z0-9-]+[A-Za-z]$/,
value: /^[a-z][a-z0-9-]+[a-z]$/,
message: t("StoragePanel.BucketNameRule"),
},
})}
placeholder={String(t("StoragePanel.BucketNamePlaceholder"))}
variant="filled"
disabled={isEdit}
/>
Expand All @@ -121,7 +122,7 @@ function CreateBucketModal(props: { storage?: TBucket; children: React.ReactElem
<Select {...register("policy", { required: true })} variant="filled">
<option value="private">{t("StoragePanel.Private")}</option>
<option value="readonly">{t("StoragePanel.Readonly")}</option>
<option value="readwrite">{t("StoragePanel.Readwrite")}</option>
<option value="readwrite">{t("StoragePanel.ReadWrite")}</option>
</Select>
</FormControl>
</VStack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function DeleteBucketModal(props: { storage: TBucket; onSuccessAction?: () => vo
</p>
<p className="mb-4">
{t("StoragePanel.StorageNameTip")}
<span className=" text-red-500 mr-1 font-bold">{storage.name}</span>
<span className=" text-red-500 mx-1 font-bold">{storage.name}</span>
{t("ToConfirm")}
</p>
<FormControl>
Expand Down

0 comments on commit 3de3d1a

Please sign in to comment.