Skip to content

Commit

Permalink
feat(web): fix create & delete collection bug (#659)
Browse files Browse the repository at this point in the history
  • Loading branch information
kongwy229 authored Jan 22, 2023
1 parent d7fde76 commit 9e95bcb
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 27 deletions.
11 changes: 9 additions & 2 deletions web/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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"
}
6 changes: 5 additions & 1 deletion web/public/locales/zh-CN/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@
"UserSetting": "用户设置"
},
"StoragePanel": {
"CreateBucket": "创建Bucket",
"EditBucket": "编辑Bucket",
"DeleteBucket": "删除Bucket",
"BucketName": "Bucket名称",
"Storage": "云存储",
"Policy": "权限",
"Private": "私有",
Expand Down Expand Up @@ -175,4 +179,4 @@
"NoData": "当前无数据",
"Logout": "退出登录",
"SaveAndRestart": "保存并重启"
}
}
13 changes: 10 additions & 3 deletions web/public/locales/zh/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,12 @@
"Upload": "上传",
"Used": "已使用",
"UploadTip": "请选择文件或者文件夹上传",
"BucketNameRule": "只能包含英文或数字或 -,且不能以 - 结尾"
"BucketNameRule": "只能包含英文或数字或 -,且不能以 - 结尾",
"Bucket": "",
"BucketName": "Bucket名称",
"CreateBucket": "创建Bucket",
"EditBucket": "编辑Bucket",
"DeleteBucket": "删除Bucket"
},
"TriggerPanel": {
"AddTrigger": "新建触发器",
Expand All @@ -170,7 +175,9 @@
"Time": "创建/更新时间",
"Trigger": "触发器",
"Type": "类型",
"CronHelp": "更多示例"
"CronHelp": "更多示例",
"Cron": "表达式"
},
"NoData": "当前无数据"
"NoData": "当前无数据",
"SaveAndRestart": "保存并重启"
}
6 changes: 3 additions & 3 deletions web/src/pages/app/database/CollectionListPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
},
});
Expand Down
8 changes: 4 additions & 4 deletions web/src/pages/app/database/PolicyListPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
});

Expand All @@ -45,7 +45,7 @@ export default function PolicyListPanel() {
{policyQuery?.data?.data.map((item: any) => {
return (
<SectionList.Item
isActive={store.currentShow === "Policy" && item?.id === store.currentPolicy.id}
isActive={store.currentShow === "Policy" && item?.id === store.currentPolicy?.id}
key={item?.id}
onClick={() => {
store.setCurrentPolicy(item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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({});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
19 changes: 12 additions & 7 deletions web/src/pages/app/database/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
},
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
},
},
Expand Down Expand Up @@ -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);
}
},
},
Expand Down
6 changes: 4 additions & 2 deletions web/src/pages/app/storages/mods/CreateBucketModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,15 @@ function CreateBucketModal(props: { storage?: TBucket; children: React.ReactElem
<Modal isOpen={isOpen} onClose={onClose} size="lg">
<ModalOverlay />
<ModalContent>
<ModalHeader>{isEdit ? t("Edit") : t("Create")}Bucket</ModalHeader>
<ModalHeader>
{isEdit ? t("StoragePanel.EditBucket") : t("StoragePanel.CreateBucket")}
</ModalHeader>
<ModalCloseButton />

<ModalBody pb={6}>
<VStack spacing={6} align="flex-start">
<FormControl isInvalid={!!errors?.name}>
<FormLabel htmlFor="name">Bucket {t("Name")}</FormLabel>
<FormLabel htmlFor="name"> {t("StoragePanel.BucketName")}</FormLabel>
<Input
{...register("name", {
required: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function DeleteBucketModal(props: { storage: TBucket; onSuccessAction?: () => vo
<Modal isOpen={isOpen} onClose={onClose}>
<ModalOverlay />
<ModalContent>
<ModalHeader>{t("Delete")} storage</ModalHeader>
<ModalHeader>{t("StoragePanel.DeleteBucket")}</ModalHeader>
<ModalCloseButton />
<ModalBody pb={6}>
<p className="mb-2">
Expand Down
2 changes: 2 additions & 0 deletions web/src/pages/app/storages/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
},
},
Expand Down

0 comments on commit 9e95bcb

Please sign in to comment.