From ce021cf22d1d3e5c127ca433be89c46a3d2f8e1e Mon Sep 17 00:00:00 2001 From: ryjiang Date: Wed, 22 Jan 2025 14:26:24 +0800 Subject: [PATCH] fix: can not delete multiple entities Signed-off-by: ryjiang --- client/src/i18n/cn/dialog.ts | 1 + client/src/i18n/en/dialog.ts | 1 + .../collections/data/CollectionData.tsx | 57 +++++++++++-------- 3 files changed, 34 insertions(+), 25 deletions(-) diff --git a/client/src/i18n/cn/dialog.ts b/client/src/i18n/cn/dialog.ts index 95b2a04d..89fce0a0 100644 --- a/client/src/i18n/cn/dialog.ts +++ b/client/src/i18n/cn/dialog.ts @@ -5,6 +5,7 @@ const dialogTrans = { deleteTipAction: '输入', deleteTipPurpose: '以确认。', deleteTitle: `删除 {{type}}`, + deleteEntityTitle: `删除 Entity`, renameTitle: `重命名 {{type}}`, releaseTitle: `发布 {{type}}`, duplicateTitle: `复制 {{type}}`, diff --git a/client/src/i18n/en/dialog.ts b/client/src/i18n/en/dialog.ts index 6f2b376c..a8407780 100644 --- a/client/src/i18n/en/dialog.ts +++ b/client/src/i18n/en/dialog.ts @@ -3,6 +3,7 @@ const dialogTrans = { deleteTipAction: 'Type', deleteTipPurpose: 'to confirm.', deleteTitle: `Drop {{type}}`, + deleteEntityTitle: `Delete Entity`, renameTitle: `Rename {{type}}`, releaseTitle: `Release {{type}}`, duplicateTitle: `Duplicate {{type}}`, diff --git a/client/src/pages/databases/collections/data/CollectionData.tsx b/client/src/pages/databases/collections/data/CollectionData.tsx index 4ff4ed3a..5267658b 100644 --- a/client/src/pages/databases/collections/data/CollectionData.tsx +++ b/client/src/pages/databases/collections/data/CollectionData.tsx @@ -107,27 +107,14 @@ const CollectionData = (props: CollectionDataProps) => { setSelectedData(value); }; const onDelete = async () => { - // reset query + // clear selection + setSelectedData([]); + // reset(); reset(); + // update count count(ConsistencyLevelEnum.Strong); - await query(0, ConsistencyLevelEnum.Strong); - }; - const handleDelete = async () => { - // call delete api - await DataService.deleteEntities(collection.collection_name, { - expr: `${collection!.schema.primaryField.name} in [${selectedData - .map(v => - collection!.schema.primaryField.data_type === - DataTypeStringEnum.VarChar - ? `"${v[collection!.schema.primaryField.name]}"` - : v[collection!.schema.primaryField.name] - ) - .join(',')}]`, - }); - handleCloseDialog(); - openSnackBar(successTrans('delete', { name: collectionTrans('entities') })); - setSelectedData([]); - await onDelete(); + // update query + query(0, ConsistencyLevelEnum.Strong); }; // Query hook @@ -342,12 +329,32 @@ const CollectionData = (props: CollectionDataProps) => { params: { component: ( { + // call delete api + await DataService.deleteEntities(collection.collection_name, { + expr: `${ + collection!.schema.primaryField.name + } in [${selectedData + .map(v => + collection!.schema.primaryField.data_type === + DataTypeStringEnum.VarChar + ? `"${v[collection!.schema.primaryField.name]}"` + : v[collection!.schema.primaryField.name] + ) + .join(',')}]`, + }); + handleCloseDialog(); + openSnackBar( + successTrans('delete', { + name: collectionTrans('entities'), + }) + ); + setSelectedData([]); + await onDelete(); + }} /> ), }, @@ -357,7 +364,7 @@ const CollectionData = (props: CollectionDataProps) => { icon: 'delete', tooltip: btnTrans('deleteTooltip'), disabledTooltip: collectionTrans('deleteDisabledTooltip'), - disabled: () => selectedData.length === 0, + disabled: () => !selectedData?.length, }, ];