Skip to content

Commit

Permalink
feat(web): support deleting multiple storage files (#1755)
Browse files Browse the repository at this point in the history
* feat(web): support deleting multiple storage files
  • Loading branch information
0fatal committed Jan 2, 2024
1 parent 94e3e82 commit 4e47d04
Show file tree
Hide file tree
Showing 9 changed files with 365 additions and 113 deletions.
27 changes: 27 additions & 0 deletions web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"react-day-picker": "^8.8.0",
"react-dom": "18.2.0",
"react-hook-form": "^7.43.9",
"react-hotkeys-hook": "^4.4.1",
"react-i18next": "^12.3.1",
"react-icons": "^4.8.0",
"react-image-crop": "^10.1.5",
Expand All @@ -56,6 +57,7 @@
"remark-math": "^5.1.1",
"sass": "^1.62.1",
"simplebar-react": "^3.2.4",
"ts-key-enum": "^2.0.12",
"uuid": "^9.0.0",
"zustand": "^4.3.8"
},
Expand Down
5 changes: 4 additions & 1 deletion web/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,10 @@
"SuccessfullyHosted": "Successfully hosted",
"SuccessfullyHostedTips": "HTTP is active, HTTPS activation may take some time. To check the hosting status, use HTTP for now.",
"BucketTips": "Newly created buckets or buckets after app restart need to wait for 15 ~ 30 s to take effect",
"DomainNotResolved": "Try using ping or nslookup to check if domain name resolution is effective"
"DomainNotResolved": "Try using ping or nslookup to check if domain name resolution is effective",
"DeleteFiles": "Are you sure you want to delete {{num}} directories or files?",
"DeletingFiles": "Deleting {{num}} directories or files...",
"DeleteFilesResult": "Delete directories or files: {{successNum}} success, {{failedNum}} failed."
},
"TriggerPanel": {
"AddTrigger": "Add Trigger",
Expand Down
13 changes: 8 additions & 5 deletions web/public/locales/zh-CN/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@
"ConfirmDeploy": "确认发布",
"CustomDependence": "自定义依赖",
"CustomDependenceTip": "暂无自定义依赖",
"DeleteDependencyConfirm": "确认要删除该依赖吗?删除依赖后会立即重启应用。",
"DeleteDependencyConfirm": "确定要删除该依赖吗?删除依赖后会立即重启应用。",
"Debug": "运行",
"DebugResult": "运行结果",
"DeleteConfirm": "确认要删除函数吗",
"DeleteConfirm": "确定要删除函数吗",
"Dependence": "NPM 依赖",
"DependenceAdd": "添加依赖",
"DependenceEdit": "编辑依赖",
Expand Down Expand Up @@ -237,8 +237,8 @@
"StoragePanel": {
"All": "总容量",
"DeleteConfirm": "当前操作将会永久删除云存储",
"DeleteFileTip": "确认要删除文件吗",
"DeleteFolderTip": "确认要删除整个文件夹吗?请注意当有大量文件存在时会稍许有一点慢哦",
"DeleteFileTip": "确定要删除文件吗",
"DeleteFolderTip": "确定要删除整个文件夹吗?请注意当有大量文件存在时会稍许有一点慢哦",
"Drag": "拖放到此处或者",
"EmptyText": "暂无 Bucket 数据,",
"File": "文件",
Expand Down Expand Up @@ -296,7 +296,10 @@
"SuccessfullyHosted": "托管成功",
"SuccessfullyHostedTips": "HTTP已生效,HTTPS需要一些时间生效。如需查看托管状态,请暂时使用HTTP访问。",
"BucketTips": "新创建的 bucket,或应用重启后的 bucket ,需要等待 15 ~ 30s 才能生效",
"DomainNotResolved": "尝试使用 ping 或 nslookup 来查看域名解析是否生效"
"DomainNotResolved": "尝试使用 ping 或 nslookup 来查看域名解析是否生效",
"DeleteFiles": "确定要删除 {{num}} 个目录及文件吗?",
"DeletingFiles": "正在删除 {{num}} 个目录及文件...",
"DeleteFilesResult": "删除目录及文件:{{successNum}} 成功,{{failedNum}} 失败"
},
"TriggerPanel": {
"AddTrigger": "新建触发器",
Expand Down
13 changes: 8 additions & 5 deletions web/public/locales/zh/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@
"ConfirmDeploy": "确认发布",
"CustomDependence": "自定义依赖",
"CustomDependenceTip": "暂无自定义依赖",
"DeleteDependencyConfirm": "确认要删除该依赖吗?删除依赖后会立即重启应用。",
"DeleteDependencyConfirm": "确定要删除该依赖吗?删除依赖后会立即重启应用。",
"Debug": "运行",
"DebugResult": "运行结果",
"DeleteConfirm": "确认要删除函数吗",
"DeleteConfirm": "确定要删除函数吗",
"Dependence": "NPM 依赖",
"DependenceAdd": "添加依赖",
"DependenceEdit": "编辑依赖",
Expand Down Expand Up @@ -237,8 +237,8 @@
"StoragePanel": {
"All": "总容量",
"DeleteConfirm": "当前操作将会永久删除云存储",
"DeleteFileTip": "确认要删除文件吗",
"DeleteFolderTip": "确认要删除整个文件夹吗?请注意当有大量文件存在时会稍许有一点慢哦",
"DeleteFileTip": "确定要删除文件吗",
"DeleteFolderTip": "确定要删除整个文件夹吗?请注意当有大量文件存在时会稍许有一点慢哦",
"Drag": "拖放到此处或者",
"EmptyText": "暂无 Bucket 数据,",
"File": "文件",
Expand Down Expand Up @@ -296,7 +296,10 @@
"SuccessfullyHosted": "托管成功",
"SuccessfullyHostedTips": "HTTP已生效,HTTPS需要一些时间生效。如需查看托管状态,请暂时使用HTTP访问。",
"BucketTips": "新创建的 bucket,或应用重启后的 bucket ,需要等待 15 ~ 30s 才能生效",
"DomainNotResolved": "尝试使用 ping 或 nslookup 来查看域名解析是否生效"
"DomainNotResolved": "尝试使用 ping 或 nslookup 来查看域名解析是否生效",
"DeleteFiles": "确定要删除 {{num}} 个目录及文件吗?",
"DeletingFiles": "正在删除 {{num}} 个目录及文件...",
"DeleteFilesResult": "删除目录及文件:{{successNum}} 成功,{{failedNum}} 失败"
},
"TriggerPanel": {
"AddTrigger": "新建触发器",
Expand Down
86 changes: 86 additions & 0 deletions web/src/components/ConfirmDialog/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { useCallback, useRef, useState } from "react";
import {
AlertDialog,
AlertDialogBody,
AlertDialogCloseButton,
AlertDialogContent,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogOverlay,
Box,
Button,
} from "@chakra-ui/react";

interface ConfirmDialogProps {
onConfirm: React.MouseEventHandler<HTMLButtonElement>;
headerText: string;
bodyText: string | React.ReactElement | any;
confirmButtonText?: string;
isOpen: boolean;
onClose: () => void;
}

const ConfirmDialog = ({
onConfirm,
headerText,
bodyText,
confirmButtonText,
isOpen,
onClose,
}: ConfirmDialogProps) => {
const cancelRef = useRef(null);

const onSubmit: React.MouseEventHandler<HTMLButtonElement> = (event) => {
onConfirm(event);
onClose();
};

return (
<AlertDialog isOpen={isOpen} leastDestructiveRef={cancelRef} onClose={onClose}>
<AlertDialogOverlay />
<AlertDialogContent>
<AlertDialogHeader fontSize="lg" fontWeight="bold">
{headerText}
</AlertDialogHeader>
<AlertDialogCloseButton />
<AlertDialogBody>
<Box>{bodyText}</Box>
</AlertDialogBody>
<AlertDialogFooter>
<Button onClick={onSubmit}>{confirmButtonText}</Button>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
);
};

export const useConfirmDialog = () => {
const [isOpen, setOpen] = useState(false);
const [data, setData] = useState<Omit<Omit<ConfirmDialogProps, "isOpen">, "onClose"> | null>(
null,
);

const show = useCallback((data: Omit<Omit<ConfirmDialogProps, "isOpen">, "onClose">) => {
setOpen(true);
setData({
...data,
});
}, []);

const onClose = useCallback(() => {
setOpen(false);
}, []);

const Dialog = useCallback(
() => (data ? <ConfirmDialog {...data} isOpen={isOpen} onClose={onClose} /> : <></>),
[data, isOpen, onClose],
);
return {
Dialog,
show,
onClose,
isOpen,
};
};

export default ConfirmDialog;
2 changes: 1 addition & 1 deletion web/src/hooks/useAwsS3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function useAwsS3() {
});

const getList = async (bucketName: string | undefined, { marker, maxKeys, prefix }: any) => {
if (!bucketName || bucketName === "") return [];
if (!bucketName || bucketName === "") return { data: [] };

const res = await s3
.listObjects({
Expand Down

0 comments on commit 4e47d04

Please sign in to comment.