Browse Source

Merge pull request #33 from Tumao727/feature/delete-partitions

Delete partitions
nameczz 4 years ago
parent
commit
53028e351f

+ 2 - 2
client/src/http/Partition.ts

@@ -26,8 +26,8 @@ export class PartitionHttp extends BaseModel implements PartitionView {
     return super.findAll({ path, params: { collection_name: collectionName } });
   }
 
-  static createPartition(createParam: PartitionManageParam) {
-    const { collectionName, partitionName, type } = createParam;
+  static managePartition(param: PartitionManageParam) {
+    const { collectionName, partitionName, type } = param;
     const path = this.URL_BASE;
     return super.create({
       path,

+ 3 - 0
client/src/i18n/cn/partition.ts

@@ -12,6 +12,9 @@ const partitionTrans = {
 
   createTitle: 'Create Partition',
   nameWarning: '_default is reserved, cannot be used as name',
+
+  deleteWarning:
+    'You are trying to delete partition. This action cannot be undone.',
 };
 
 export default partitionTrans;

+ 1 - 1
client/src/i18n/cn/success.ts

@@ -2,7 +2,7 @@ const successTrans = {
   connect: 'Connet milvus success',
   create: `{{name}} has been created`,
   load: `{{name}} has been loaded`,
-  delete: `{{name}} has been deleted`,
+  delete: `{{name}} successfully deleted`,
 };
 
 export default successTrans;

+ 2 - 0
client/src/i18n/cn/warning.ts

@@ -5,6 +5,8 @@ const warningTrans = {
   positive: '{{name}} should be positive',
   integer: '{{name}} should be integers',
   range: 'range is {{min}} ~ {{max}}',
+
+  deletePartition: 'default partition cannot be deleted',
 };
 
 export default warningTrans;

+ 3 - 0
client/src/i18n/en/partition.ts

@@ -12,6 +12,9 @@ const partitionTrans = {
 
   createTitle: 'Create Partition',
   nameWarning: '_default is reserved, cannot be used as name',
+
+  deleteWarning:
+    'You are trying to delete partition. This action cannot be undone.',
 };
 
 export default partitionTrans;

+ 1 - 1
client/src/i18n/en/success.ts

@@ -2,7 +2,7 @@ const successTrans = {
   connect: 'Connet milvus success',
   create: `{{name}} has been created`,
   load: `{{name}} has been loaded`,
-  delete: `{{name}} has been deleted`,
+  delete: `{{name}} successfully deleted`,
 };
 
 export default successTrans;

+ 2 - 0
client/src/i18n/en/warning.ts

@@ -5,6 +5,8 @@ const warningTrans = {
   positive: '{{name}} should be positive',
   integer: '{{name}} should be integers',
   range: 'range is {{min}} ~ {{max}}',
+
+  deletePartition: 'default partition cannot be deleted',
 };
 
 export default warningTrans;

+ 44 - 3
client/src/pages/partitions/partitions.tsx

@@ -14,6 +14,7 @@ import Status from '../../components/status/Status';
 import { ManageRequestMethods } from '../../types/Common';
 import { StatusEnum } from '../../components/status/Types';
 import { useDialogHook } from '../../hooks/Dialog';
+import DeleteTemplate from '../../components/customDialog/DeleteDialogTemplate';
 
 const useStyles = makeStyles((theme: Theme) => ({
   wrapper: {
@@ -31,6 +32,9 @@ const Partitions: FC<{
   const classes = useStyles();
   const { t } = useTranslation('partition');
   const { t: successTrans } = useTranslation('success');
+  const { t: warningTrans } = useTranslation('warning');
+  const { t: btnTrans } = useTranslation('btn');
+  const { t: dialogTrans } = useTranslation('dialog');
   const InfoIcon = icons.info;
   const LoadIcon = icons.load;
   const ReleaseIcon = icons.release;
@@ -69,6 +73,21 @@ const Partitions: FC<{
     }
   };
 
+  const handleDelete = async () => {
+    for (const partition of selectedPartitions) {
+      const param: PartitionManageParam = {
+        partitionName: partition._name,
+        collectionName,
+        type: ManageRequestMethods.DELETE,
+      };
+      await PartitionHttp.managePartition(param);
+    }
+
+    openSnackBar(successTrans('delete', { name: t('partition') }));
+    fetchPartitions(collectionName);
+    handleCloseDialog();
+  };
+
   const handleRelease = async (data: PartitionView) => {};
 
   const handleLoad = async (data: PartitionView) => {
@@ -103,9 +122,31 @@ const Partitions: FC<{
     },
     {
       type: 'iconBtn',
-      onClick: () => {},
-      label: t('delete'),
+      onClick: () => {
+        setDialog({
+          open: true,
+          type: 'custom',
+          params: {
+            component: (
+              <DeleteTemplate
+                label={btnTrans('delete')}
+                title={dialogTrans('deleteTitle', { type: t('partition') })}
+                text={t('deleteWarning')}
+                handleDelete={handleDelete}
+              />
+            ),
+          },
+        });
+      },
+      label: '',
       icon: 'delete',
+      // can't delete default partition
+      disabled: () =>
+        selectedPartitions.length === 0 ||
+        selectedPartitions.some(p => p._name === '_default'),
+      tooltip: selectedPartitions.some(p => p._name === '_default')
+        ? warningTrans('deletePartition')
+        : '',
     },
   ];
 
@@ -183,7 +224,7 @@ const Partitions: FC<{
       type: ManageRequestMethods.CREATE,
     };
 
-    await PartitionHttp.createPartition(param);
+    await PartitionHttp.managePartition(param);
 
     openSnackBar(successTrans('create', { name: t('partition') }));
     handleCloseDialog();