diff --git a/src/Common/dataAccess/updateDocument.ts b/src/Common/dataAccess/updateDocument.ts index dd97b46de..7985ffa43 100644 --- a/src/Common/dataAccess/updateDocument.ts +++ b/src/Common/dataAccess/updateDocument.ts @@ -1,5 +1,6 @@ import { Item, RequestOptions } from "@azure/cosmos"; import { HttpHeaders } from "Common/Constants"; +import { LocalStorageUtility, StorageKey } from "Shared/StorageUtility"; import { CollectionBase } from "../../Contracts/ViewModels"; import DocumentId from "../../Explorer/Tree/DocumentId"; import { logConsoleInfo, logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; @@ -23,10 +24,17 @@ export const updateDocument = async ( [HttpHeaders.partitionKey]: documentId.partitionKeyValue, } : {}; + + // If user has chosen to ignore partition key on update, pass null instead of actual partition key value + const ignorePartitionKeyOnDocumentUpdateFlag = LocalStorageUtility.getEntryBoolean( + StorageKey.IgnorePartitionKeyOnDocumentUpdate, + ); + const partitionKey = ignorePartitionKeyOnDocumentUpdateFlag ? undefined : getPartitionKeyValue(documentId); + const response = await client() .database(collection.databaseId) .container(collection.id()) - .item(documentId.id(), getPartitionKeyValue(documentId)) + .item(documentId.id(), partitionKey) .replace(newDocument, options); logConsoleInfo(`Successfully updated ${entityName} ${documentId.id()}`); diff --git a/src/Explorer/Panes/SettingsPane/SettingsPane.tsx b/src/Explorer/Panes/SettingsPane/SettingsPane.tsx index c8106eca7..046e827fd 100644 --- a/src/Explorer/Panes/SettingsPane/SettingsPane.tsx +++ b/src/Explorer/Panes/SettingsPane/SettingsPane.tsx @@ -204,6 +204,9 @@ export const SettingsPane: FunctionComponent<{ explorer: Explorer }> = ({ ? (LocalStorageUtility.getEntryString(StorageKey.MongoGuidRepresentation) as Constants.MongoGuidRepresentation) : Constants.MongoGuidRepresentation.CSharpLegacy, ); + const [ignorePartitionKeyOnDocumentUpdate, setIgnorePartitionKeyOnDocumentUpdate] = useState( + LocalStorageUtility.getEntryBoolean(StorageKey.IgnorePartitionKeyOnDocumentUpdate), + ); const styles = useStyles(); @@ -424,6 +427,12 @@ export const SettingsPane: FunctionComponent<{ explorer: Explorer }> = ({ LocalStorageUtility.setEntryString(StorageKey.MongoGuidRepresentation, mongoGuidRepresentation); } + // Advanced settings + LocalStorageUtility.setEntryBoolean( + StorageKey.IgnorePartitionKeyOnDocumentUpdate, + ignorePartitionKeyOnDocumentUpdate, + ); + setIsExecuting(false); logConsoleInfo( `Updated items per page setting to ${LocalStorageUtility.getEntryNumber(StorageKey.ActualItemPerPage)}`, @@ -453,6 +462,10 @@ export const SettingsPane: FunctionComponent<{ explorer: Explorer }> = ({ ); } + logConsoleInfo( + `${ignorePartitionKeyOnDocumentUpdate ? "Enabled" : "Disabled"} ignoring partition key on document update`, + ); + refreshExplorer && (await explorer.refreshExplorer()); closeSidePanel(); }; @@ -593,6 +606,13 @@ export const SettingsPane: FunctionComponent<{ explorer: Explorer }> = ({ setMongoGuidRepresentation(option.key as Constants.MongoGuidRepresentation); }; + const handleOnIgnorePartitionKeyOnDocumentUpdateChange = ( + ev: React.MouseEvent, + checked?: boolean, + ): void => { + setIgnorePartitionKeyOnDocumentUpdate(!!checked); + }; + const choiceButtonStyles = { root: { clear: "both", @@ -1137,6 +1157,23 @@ export const SettingsPane: FunctionComponent<{ explorer: Explorer }> = ({ )} + + +
Advanced Settings
+
+ +
+ +
+
+
)} diff --git a/src/Explorer/Panes/SettingsPane/__snapshots__/SettingsPane.test.tsx.snap b/src/Explorer/Panes/SettingsPane/__snapshots__/SettingsPane.test.tsx.snap index 41759f1c7..e46ba57ea 100644 --- a/src/Explorer/Panes/SettingsPane/__snapshots__/SettingsPane.test.tsx.snap +++ b/src/Explorer/Panes/SettingsPane/__snapshots__/SettingsPane.test.tsx.snap @@ -575,6 +575,37 @@ exports[`Settings Pane should render Default properly 1`] = ` + + +
+ Advanced Settings +
+
+ +
+ +
+
+
+ + +
+ Advanced Settings +
+
+ +
+ +
+
+
{