Browse Source

add delete collections

nameczz 4 years ago
parent
commit
afeb014414
2 changed files with 13 additions and 2 deletions
  1. 4 0
      client/src/http/Collection.ts
  2. 9 2
      client/src/pages/collections/Collections.tsx

+ 4 - 0
client/src/http/Collection.ts

@@ -35,6 +35,10 @@ export class CollectionHttp extends BaseModel implements CollectionView {
     });
   }
 
+  static deleteCollection(collectionName: string) {
+    return super.delete({ path: `${this.COLLECTIONS_URL}/${collectionName}` });
+  }
+
   get _autoId() {
     return this.autoID;
   }

+ 9 - 2
client/src/pages/collections/Collections.tsx

@@ -120,7 +120,13 @@ const Collections = () => {
   const handleLoad = async (data: CollectionView) => {};
 
   const handleDelete = async () => {
-    console.log('selected', selectedCollections);
+    for (const item of selectedCollections) {
+      await CollectionHttp.deleteCollection(item._name);
+    }
+    openSnackBar('Delete success');
+    fetchData();
+    handleCloseDialog();
+    setSelectedCollections([]);
   };
 
   const handleAction = (data: CollectionView) => {
@@ -200,6 +206,7 @@ const Collections = () => {
       },
       label: t('delete'),
       icon: 'delete',
+      disabled: data => data.length === 0,
     },
   ];
 
@@ -290,7 +297,7 @@ const Collections = () => {
           colDefinitions={colDefinitions}
           rows={collectionList}
           rowCount={total}
-          primaryKey="id"
+          primaryKey="_name"
           openCheckBox={true}
           showHoverStyle={true}
           selected={selectedCollections}