From 9e95bcb401ff6cc3abf8c77f1f516f4a3dc75706 Mon Sep 17 00:00:00 2001 From: kongwy <1419906205@qq.com> Date: Sun, 22 Jan 2023 22:36:33 +0800 Subject: [PATCH] feat(web): fix create & delete collection bug (#659) --- web/public/locales/en/translation.json | 11 +++++++++-- web/public/locales/zh-CN/translation.json | 6 +++++- web/public/locales/zh/translation.json | 13 ++++++++++--- .../database/CollectionListPanel/index.tsx | 6 +++--- .../app/database/PolicyListPanel/index.tsx | 8 ++++---- .../mods/CreateCollectionModal/index.tsx | 5 +++-- .../mods/DeleteCollectionModal/index.tsx | 2 -- web/src/pages/app/database/service.ts | 19 ++++++++++++------- .../storages/mods/CreateBucketModal/index.tsx | 6 ++++-- .../storages/mods/DeleteBucketModal/index.tsx | 2 +- web/src/pages/app/storages/service.ts | 2 ++ 11 files changed, 53 insertions(+), 27 deletions(-) diff --git a/web/public/locales/en/translation.json b/web/public/locales/en/translation.json index f6a9cbf6c7..6b8c80cdae 100644 --- a/web/public/locales/en/translation.json +++ b/web/public/locales/en/translation.json @@ -154,6 +154,11 @@ "Upload": "Upload", "Used": "Used", "UploadTip": "Please select a file or folder to upload", + "Bucket": "bucket", + "BucketName": "Bucket name", + "CreateBucket": "Create buckets", + "EditBucket": "Edit Bucket", + "DeleteBucket": "Delete Buckets" "BucketNameRule": "Can only contain English or numbers or -, and cannot end with -" }, "TriggerPanel": { @@ -170,7 +175,9 @@ "Time": "Creation/update time", "Trigger": "Trigger", "Type": "Type", - "CronHelp": "more examples" + "CronHelp": "more examples", + "Cron": "expression" }, - "NoData": "Currently no data" + "NoData": "Currently no data", + "SaveAndRestart": "save and restart" } diff --git a/web/public/locales/zh-CN/translation.json b/web/public/locales/zh-CN/translation.json index 7ba913f9c6..395642f593 100644 --- a/web/public/locales/zh-CN/translation.json +++ b/web/public/locales/zh-CN/translation.json @@ -113,6 +113,10 @@ "UserSetting": "用户设置" }, "StoragePanel": { + "CreateBucket": "创建Bucket", + "EditBucket": "编辑Bucket", + "DeleteBucket": "删除Bucket", + "BucketName": "Bucket名称", "Storage": "云存储", "Policy": "权限", "Private": "私有", @@ -175,4 +179,4 @@ "NoData": "当前无数据", "Logout": "退出登录", "SaveAndRestart": "保存并重启" -} +} \ No newline at end of file diff --git a/web/public/locales/zh/translation.json b/web/public/locales/zh/translation.json index 49f40d9aa8..06a449e74b 100644 --- a/web/public/locales/zh/translation.json +++ b/web/public/locales/zh/translation.json @@ -154,7 +154,12 @@ "Upload": "上传", "Used": "已使用", "UploadTip": "请选择文件或者文件夹上传", - "BucketNameRule": "只能包含英文或数字或 -,且不能以 - 结尾" + "BucketNameRule": "只能包含英文或数字或 -,且不能以 - 结尾", + "Bucket": "桶", + "BucketName": "Bucket名称", + "CreateBucket": "创建Bucket", + "EditBucket": "编辑Bucket", + "DeleteBucket": "删除Bucket" }, "TriggerPanel": { "AddTrigger": "新建触发器", @@ -170,7 +175,9 @@ "Time": "创建/更新时间", "Trigger": "触发器", "Type": "类型", - "CronHelp": "更多示例" + "CronHelp": "更多示例", + "Cron": "表达式" }, - "NoData": "当前无数据" + "NoData": "当前无数据", + "SaveAndRestart": "保存并重启" } diff --git a/web/src/pages/app/database/CollectionListPanel/index.tsx b/web/src/pages/app/database/CollectionListPanel/index.tsx index 7012002cdd..c39522a388 100644 --- a/web/src/pages/app/database/CollectionListPanel/index.tsx +++ b/web/src/pages/app/database/CollectionListPanel/index.tsx @@ -20,10 +20,10 @@ export default function CollectionListPanel() { const { t } = useTranslation(); const collectionListQuery = useCollectionListQuery({ onSuccess: (data) => { - if (data.data.length > 0) { - store.setCurrentDB(data.data[0]); - } else { + if (data.data.length === 0) { store.setCurrentDB(undefined); + } else if (store.currentDB === undefined) { + store.setCurrentDB(data?.data[0]); } }, }); diff --git a/web/src/pages/app/database/PolicyListPanel/index.tsx b/web/src/pages/app/database/PolicyListPanel/index.tsx index 62a30d3fef..72110ad293 100644 --- a/web/src/pages/app/database/PolicyListPanel/index.tsx +++ b/web/src/pages/app/database/PolicyListPanel/index.tsx @@ -16,10 +16,10 @@ import { useDeletePolicyMutation, usePolicyListQuery } from "../service"; import useDBMStore from "../store"; export default function PolicyListPanel() { const policyQuery = usePolicyListQuery((data) => { - if (data.data.length > 0) { - store.setCurrentPolicy(data.data[0]); - } else { + if (data.data.length === 0) { store.setCurrentPolicy(undefined); + } else if (store.currentPolicy === undefined) { + store.setCurrentPolicy(data?.data[0]); } }); @@ -45,7 +45,7 @@ export default function PolicyListPanel() { {policyQuery?.data?.data.map((item: any) => { return ( { store.setCurrentPolicy(item); diff --git a/web/src/pages/app/database/mods/CreateCollectionModal/index.tsx b/web/src/pages/app/database/mods/CreateCollectionModal/index.tsx index 8ef259b97e..7cded3f948 100644 --- a/web/src/pages/app/database/mods/CreateCollectionModal/index.tsx +++ b/web/src/pages/app/database/mods/CreateCollectionModal/index.tsx @@ -19,11 +19,11 @@ import { } from "@chakra-ui/react"; import { useCreateDBMutation } from "../../service"; - +import useDBMStore from "../../store"; const CreateCollectionModal = (props: { collection?: any; children: React.ReactElement }) => { const { isOpen, onOpen, onClose } = useDisclosure(); const { t } = useTranslation(); - + const store = useDBMStore(); const { collection, children } = props; const isEdit = !!collection; @@ -44,6 +44,7 @@ const CreateCollectionModal = (props: { collection?: any; children: React.ReactE const onSubmit = async (data: any) => { await createDBMutation.mutateAsync({ name: data.name }); + store.setCurrentDB(data); onClose(); reset({}); }; diff --git a/web/src/pages/app/database/mods/DeleteCollectionModal/index.tsx b/web/src/pages/app/database/mods/DeleteCollectionModal/index.tsx index 101f73e33b..2f060d34bc 100644 --- a/web/src/pages/app/database/mods/DeleteCollectionModal/index.tsx +++ b/web/src/pages/app/database/mods/DeleteCollectionModal/index.tsx @@ -17,12 +17,10 @@ import { } from "@chakra-ui/react"; import { useDeleteDBMutation } from "../../service"; - function DeleteCollectionModal(props: { database: any }) { const { database } = props; const { t } = useTranslation(); const { isOpen, onOpen, onClose } = useDisclosure(); - const deleteDBMutation = useDeleteDBMutation({ onSuccess() { onClose(); diff --git a/web/src/pages/app/database/service.ts b/web/src/pages/app/database/service.ts index c2877b1e2a..169faa4575 100644 --- a/web/src/pages/app/database/service.ts +++ b/web/src/pages/app/database/service.ts @@ -81,7 +81,6 @@ export const useCreateDBMutation = (config?: { onSuccess: (data: any) => void }) globalStore.showError(data.error); } else { await queryClient.invalidateQueries(queryKeys.useCollectionListQuery); - config?.onSuccess && config.onSuccess(data); } }, @@ -92,16 +91,18 @@ export const useCreateDBMutation = (config?: { onSuccess: (data: any) => void }) export const useDeleteDBMutation = (config?: { onSuccess: (data: any) => void }) => { const globalStore = useGlobalStore(); const queryClient = useQueryClient(); + const store = useDBMStore(); return useMutation( (values: any) => { return CollectionControllerRemove(values); }, { - onSuccess(data) { + onSuccess: async (data) => { if (data.error) { globalStore.showError(data.error); } else { - queryClient.invalidateQueries(queryKeys.useCollectionListQuery); + store.setCurrentDB(undefined); + await queryClient.invalidateQueries(queryKeys.useCollectionListQuery); globalStore.showSuccess(t("DeleteSuccess")); config && config.onSuccess(data); } @@ -203,16 +204,18 @@ export const usePolicyListQuery = (onSuccess?: (data: any) => void) => { export const useCreatePolicyMutation = () => { const globalStore = useGlobalStore(); const queryClient = useQueryClient(); + const store = useDBMStore(); return useMutation( (values: any) => { return PolicyControllerCreate(values); }, { - onSuccess(data) { + onSuccess: async (data) => { if (data.error) { globalStore.showError(data.error); } else { - queryClient.invalidateQueries(queryKeys.usePolicyListQuery); + await queryClient.invalidateQueries(queryKeys.usePolicyListQuery); + store.setCurrentPolicy(data.data); } }, }, @@ -241,16 +244,18 @@ export const useUpdatePolicyMutation = () => { export const useDeletePolicyMutation = () => { const globalStore = useGlobalStore(); const queryClient = useQueryClient(); + const store = useDBMStore(); return useMutation( (values: any) => { return PolicyControllerRemove({ name: values }); }, { - onSuccess(data) { + onSuccess: async (data) => { if (data.error) { globalStore.showError(data.error); } else { - queryClient.invalidateQueries(queryKeys.usePolicyListQuery); + store.setCurrentPolicy(undefined); + await queryClient.invalidateQueries(queryKeys.usePolicyListQuery); } }, }, diff --git a/web/src/pages/app/storages/mods/CreateBucketModal/index.tsx b/web/src/pages/app/storages/mods/CreateBucketModal/index.tsx index 0214b36e4a..9b8abf91cc 100644 --- a/web/src/pages/app/storages/mods/CreateBucketModal/index.tsx +++ b/web/src/pages/app/storages/mods/CreateBucketModal/index.tsx @@ -93,13 +93,15 @@ function CreateBucketModal(props: { storage?: TBucket; children: React.ReactElem - {isEdit ? t("Edit") : t("Create")}Bucket + + {isEdit ? t("StoragePanel.EditBucket") : t("StoragePanel.CreateBucket")} + - Bucket {t("Name")} + {t("StoragePanel.BucketName")} vo - {t("Delete")} storage + {t("StoragePanel.DeleteBucket")}

diff --git a/web/src/pages/app/storages/service.ts b/web/src/pages/app/storages/service.ts index 67f0cfbd18..b67b273a59 100644 --- a/web/src/pages/app/storages/service.ts +++ b/web/src/pages/app/storages/service.ts @@ -42,6 +42,7 @@ export const useBucketListQuery = (config?: { onSuccess: (data: any) => void }) export const useBucketCreateMutation = (config?: { onSuccess: (data: any) => void }) => { const globalStore = useGlobalStore(); const queryClient = useQueryClient(); + const store = useStorageStore(); return useMutation( (values: any) => { return BucketControllerCreate(values); @@ -52,6 +53,7 @@ export const useBucketCreateMutation = (config?: { onSuccess: (data: any) => voi globalStore.showError(data.error); } else { await queryClient.invalidateQueries(queryKeys.useBucketListQuery); + store.setCurrentStorage(data.data); } }, },