Disable bulkdelete for users point to old mongo proxy (#1964)
* Disable bulk delete if old mongo proxy * Bug fix * Fix unit tests * Fix formatting
This commit is contained in:
parent
cfc8196c4b
commit
2c2f0c8d7b
|
@ -942,24 +942,34 @@ export const DocumentsTabComponent: React.FunctionComponent<IDocumentsTabCompone
|
||||||
const _deleteNoSqlDocuments = async (
|
const _deleteNoSqlDocuments = async (
|
||||||
collection: CollectionBase,
|
collection: CollectionBase,
|
||||||
toDeleteDocumentIds: DocumentId[],
|
toDeleteDocumentIds: DocumentId[],
|
||||||
): Promise<DocumentId[]> => {
|
): Promise<DocumentId[]> =>
|
||||||
return partitionKey.systemKey
|
partitionKey.systemKey
|
||||||
? deleteNoSqlDocument(collection, toDeleteDocumentIds[0]).then(() => [toDeleteDocumentIds[0]])
|
? deleteNoSqlDocument(collection, toDeleteDocumentIds[0]).then(() => [toDeleteDocumentIds[0]])
|
||||||
: deleteNoSqlDocuments(collection, toDeleteDocumentIds);
|
: deleteNoSqlDocuments(collection, toDeleteDocumentIds);
|
||||||
};
|
|
||||||
|
|
||||||
const deletePromise = !isPreferredApiMongoDB
|
// TODO: Once new mongo proxy is available for all users, remove the call for MongoProxyClient.deleteDocument().
|
||||||
? _deleteNoSqlDocuments(_collection, toDeleteDocumentIds)
|
// MongoProxyClient.deleteDocuments() should be called for all users.
|
||||||
: MongoProxyClient.deleteDocuments(
|
const _deleteMongoDocuments = async (
|
||||||
_collection.databaseId,
|
databaseId: string,
|
||||||
_collection as ViewModels.Collection,
|
collection: ViewModels.Collection,
|
||||||
toDeleteDocumentIds,
|
documentIds: DocumentId[],
|
||||||
).then(({ deletedCount, isAcknowledged }) => {
|
) =>
|
||||||
|
isMongoBulkDeleteDisabled
|
||||||
|
? MongoProxyClient.deleteDocument(databaseId, collection, documentIds[0]).then(() => [toDeleteDocumentIds[0]])
|
||||||
|
: MongoProxyClient.deleteDocuments(databaseId, collection, documentIds).then(
|
||||||
|
({ deletedCount, isAcknowledged }) => {
|
||||||
if (deletedCount === toDeleteDocumentIds.length && isAcknowledged) {
|
if (deletedCount === toDeleteDocumentIds.length && isAcknowledged) {
|
||||||
return toDeleteDocumentIds;
|
return toDeleteDocumentIds;
|
||||||
}
|
}
|
||||||
throw new Error(`Delete failed with deletedCount: ${deletedCount} and isAcknowledged: ${isAcknowledged}`);
|
throw new Error(
|
||||||
});
|
`Delete failed with deletedCount: ${deletedCount} and isAcknowledged: ${isAcknowledged}`,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const deletePromise = !isPreferredApiMongoDB
|
||||||
|
? _deleteNoSqlDocuments(_collection, toDeleteDocumentIds)
|
||||||
|
: _deleteMongoDocuments(_collection.databaseId, _collection as ViewModels.Collection, toDeleteDocumentIds);
|
||||||
|
|
||||||
return deletePromise
|
return deletePromise
|
||||||
.then(
|
.then(
|
||||||
|
@ -1754,6 +1764,13 @@ export const DocumentsTabComponent: React.FunctionComponent<IDocumentsTabCompone
|
||||||
[createIterator, filterContent],
|
[createIterator, filterContent],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// TODO: remove isMongoBulkDeleteDisabled when new mongo proxy is enabled for all users
|
||||||
|
// TODO: remove partitionKey.systemKey when JS SDK bug is fixed
|
||||||
|
const isMongoBulkDeleteDisabled = !MongoProxyClient.useMongoProxyEndpoint("bulkdelete");
|
||||||
|
const isBulkDeleteDisabled =
|
||||||
|
(partitionKey.systemKey && !isPreferredApiMongoDB) || (isPreferredApiMongoDB && isMongoBulkDeleteDisabled);
|
||||||
|
// -------------------------------------------------------
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CosmosFluentProvider className={styles.container}>
|
<CosmosFluentProvider className={styles.container}>
|
||||||
<div className="tab-pane active" role="tabpanel" style={{ display: "flex" }}>
|
<div className="tab-pane active" role="tabpanel" style={{ display: "flex" }}>
|
||||||
|
@ -1878,7 +1895,7 @@ export const DocumentsTabComponent: React.FunctionComponent<IDocumentsTabCompone
|
||||||
size={tableContainerSizePx}
|
size={tableContainerSizePx}
|
||||||
columnHeaders={columnHeaders}
|
columnHeaders={columnHeaders}
|
||||||
isSelectionDisabled={
|
isSelectionDisabled={
|
||||||
(partitionKey.systemKey && !isPreferredApiMongoDB) ||
|
isBulkDeleteDisabled ||
|
||||||
(configContext.platform === Platform.Fabric && userContext.fabricContext?.isReadOnly)
|
(configContext.platform === Platform.Fabric && userContext.fabricContext?.isReadOnly)
|
||||||
}
|
}
|
||||||
collection={_collection}
|
collection={_collection}
|
||||||
|
|
|
@ -50,6 +50,7 @@ jest.mock("Common/MongoProxyClient", () => ({
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
deleteDocuments: jest.fn(() => Promise.resolve()),
|
deleteDocuments: jest.fn(() => Promise.resolve()),
|
||||||
|
useMongoProxyEndpoint: jest.fn(() => true),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
jest.mock("Explorer/Controls/Editor/EditorReact", () => ({
|
jest.mock("Explorer/Controls/Editor/EditorReact", () => ({
|
||||||
|
|
Loading…
Reference in New Issue