From 7d5eebf228152b91d4f1d3e35610fc5e207c54db Mon Sep 17 00:00:00 2001 From: allence Date: Sat, 4 Mar 2023 09:47:58 +0800 Subject: [PATCH] feat(web): add file upload code template (#844) --- web/public/locales/en/translation.json | 3 +- web/public/locales/zh-CN/translation.json | 11 ++--- web/public/locales/zh/translation.json | 11 ++--- web/src/components/FileUpload/index.tsx | 38 ++++++++--------- web/src/components/Pagination/index.tsx | 2 +- web/src/layouts/Header/UserSetting/index.tsx | 1 + .../mods/DataPanel/index.tsx | 15 +++---- .../app/functions/mods/DeployButton/index.tsx | 5 ++- .../CreateModal/functionTemplates.ts | 41 +++++++++++++++++++ web/src/pages/app/setting/UserInfo/index.tsx | 1 + .../app/storages/mods/FileList/index.tsx | 16 +++----- .../app/storages/mods/UploadButton/index.tsx | 38 ++++------------- 12 files changed, 102 insertions(+), 80 deletions(-) diff --git a/web/public/locales/en/translation.json b/web/public/locales/en/translation.json index 6d60ac083b..cd14e0ebe1 100644 --- a/web/public/locales/en/translation.json +++ b/web/public/locales/en/translation.json @@ -262,5 +262,6 @@ "Back": "Return", "Personal Access Token": "Personal Access Token", "SwitchLanguage": "Switch Language", - "Storage": "Storage" + "Storage": "Storage", + "upload example": "file upload" } diff --git a/web/public/locales/zh-CN/translation.json b/web/public/locales/zh-CN/translation.json index df89b404e8..113fbe12cc 100644 --- a/web/public/locales/zh-CN/translation.json +++ b/web/public/locales/zh-CN/translation.json @@ -161,9 +161,9 @@ "Storage": "存储", "StorageList": "云存储列表", "Policy": "权限", - "Private": "私有", - "Readonly": "公共读", - "ReadWrite": "公共读写", + "Private": "私有 (private)", + "Readonly": "公共读 (readonly)", + "ReadWrite": "公共读写 (readwrite)", "Upload": "上传", "Drag": "拖放到此处或者", "File": "文件", @@ -262,5 +262,6 @@ "Back": "返回", "Personal Access Token": "访问凭证 (PAT)", "SwitchLanguage": "切换语言", - "Storage": "云存储" -} + "Storage": "云存储", + "upload example": "文件上传示例" +} \ No newline at end of file diff --git a/web/public/locales/zh/translation.json b/web/public/locales/zh/translation.json index 9757d78715..c71d7dea6c 100644 --- a/web/public/locales/zh/translation.json +++ b/web/public/locales/zh/translation.json @@ -177,9 +177,9 @@ "FolderName": "文件夹名称", "NameTip": "请输入文件夹名称", "Policy": "权限", - "Private": "私有", - "Readonly": "公共读", - "ReadWrite": "公共读写", + "Private": "私有 (private)", + "Readonly": "公共读 (readonly)", + "ReadWrite": "公共读写 (readwrite)", "SearchBucket": "输入 bucket 名进行搜索", "Size": "大小", "Storage": "存储", @@ -262,5 +262,6 @@ "Back": "返回", "Personal Access Token": "访问凭证 (PAT)", "SwitchLanguage": "切换语言", - "Storage": "云存储" -} + "Storage": "云存储", + "upload example": "文件上传示例" +} \ No newline at end of file diff --git a/web/src/components/FileUpload/index.tsx b/web/src/components/FileUpload/index.tsx index 234e67fa8f..c26db0f2f7 100644 --- a/web/src/components/FileUpload/index.tsx +++ b/web/src/components/FileUpload/index.tsx @@ -1,26 +1,19 @@ -import React, { useEffect } from "react"; +import React from "react"; import { useTranslation } from "react-i18next"; import clsx from "clsx"; import styles from "./index.module.scss"; +type UploadType = "file" | "folder"; + // drag drop file component -function FileUpload(props: { onUpload: (files: any) => void; uploadType: "file" | "folder" }) { - const { onUpload = () => {}, uploadType } = props; +function FileUpload(props: { onUpload: (files: any) => void }) { + const { onUpload = () => {} } = props; // drag state const [dragActive, setDragActive] = React.useState(false); // ref const inputRef = React.useRef(null); const { t } = useTranslation(); - useEffect(() => { - if (uploadType === "folder") { - inputRef.current.setAttribute("webkitdirectory", ""); - inputRef.current.setAttribute("directory", ""); - } else { - inputRef.current.removeAttribute("webkitdirectory"); - inputRef.current.removeAttribute("directory"); - } - }, [uploadType]); // handle drag events const handleDrag = function (e: any) { @@ -53,7 +46,14 @@ function FileUpload(props: { onUpload: (files: any) => void; uploadType: "file" }; // triggers the input when the button is clicked - const onButtonClick = () => { + const onButtonClick = (uploadType: UploadType) => { + if (uploadType === "folder") { + inputRef.current.setAttribute("webkitdirectory", ""); + inputRef.current.setAttribute("directory", ""); + } else { + inputRef.current.removeAttribute("webkitdirectory"); + inputRef.current.removeAttribute("directory"); + } inputRef?.current?.click(); }; @@ -78,12 +78,12 @@ function FileUpload(props: { onUpload: (files: any) => void; uploadType: "file" htmlFor="input-file-upload" >
-

- {uploadType === "file" ? t("StoragePanel.File") : t("StoragePanel.Folder")} - {t("StoragePanel.Drag")} -

- + +
diff --git a/web/src/components/Pagination/index.tsx b/web/src/components/Pagination/index.tsx index 54a228c39b..5035f1c499 100644 --- a/web/src/components/Pagination/index.tsx +++ b/web/src/components/Pagination/index.tsx @@ -33,7 +33,7 @@ export default function Pagination(props: { return ( - + {t("Total")}: {total} diff --git a/web/src/layouts/Header/UserSetting/index.tsx b/web/src/layouts/Header/UserSetting/index.tsx index 249ff84af3..d5c6761dc4 100644 --- a/web/src/layouts/Header/UserSetting/index.tsx +++ b/web/src/layouts/Header/UserSetting/index.tsx @@ -15,6 +15,7 @@ export default function UserSetting(props: { name: string; avatar?: string; widt - +
+ query.refetch()} />