Skip to content

Commit

Permalink
fix: can not delete multiple entities (#749)
Browse files Browse the repository at this point in the history
Signed-off-by: ryjiang <[email protected]>
  • Loading branch information
shanghaikid authored Jan 22, 2025
1 parent b94d7b6 commit d1ff76a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 25 deletions.
1 change: 1 addition & 0 deletions client/src/i18n/cn/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const dialogTrans = {
deleteTipAction: '输入',
deleteTipPurpose: '以确认。',
deleteTitle: `删除 {{type}}`,
deleteEntityTitle: `删除 Entity`,
renameTitle: `重命名 {{type}}`,
releaseTitle: `发布 {{type}}`,
duplicateTitle: `复制 {{type}}`,
Expand Down
1 change: 1 addition & 0 deletions client/src/i18n/en/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}}`,
Expand Down
57 changes: 32 additions & 25 deletions client/src/pages/databases/collections/data/CollectionData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -342,12 +329,32 @@ const CollectionData = (props: CollectionDataProps) => {
params: {
component: (
<DeleteTemplate
label={btnTrans('drop')}
title={dialogTrans('deleteTitle', {
type: collectionTrans('entities'),
})}
label={btnTrans('delete')}
title={dialogTrans('deleteEntityTitle')}
text={collectionTrans('deleteDataWarning')}
handleDelete={handleDelete}
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();
}}
/>
),
},
Expand All @@ -357,7 +364,7 @@ const CollectionData = (props: CollectionDataProps) => {
icon: 'delete',
tooltip: btnTrans('deleteTooltip'),
disabledTooltip: collectionTrans('deleteDisabledTooltip'),
disabled: () => selectedData.length === 0,
disabled: () => !selectedData?.length,
},
];

Expand Down

0 comments on commit d1ff76a

Please sign in to comment.