initialize new documents with their partition key (#1815)
* initialize new documents with their partition key * refmt
This commit is contained in:
parent
17207624a9
commit
f4bcee5461
|
@ -463,7 +463,22 @@ export default class DocumentsTab extends TabsBase {
|
||||||
|
|
||||||
private initializeNewDocument = (): void => {
|
private initializeNewDocument = (): void => {
|
||||||
this.selectedDocumentId(null);
|
this.selectedDocumentId(null);
|
||||||
const defaultDocument: string = this.renderObjectForEditor({ id: "replace_with_new_document_id" }, null, 4);
|
const newDocument: any = {
|
||||||
|
id: "replace_with_new_document_id",
|
||||||
|
};
|
||||||
|
this.partitionKeyProperties.forEach((partitionKeyProperty) => {
|
||||||
|
let target = newDocument;
|
||||||
|
const keySegments = partitionKeyProperty.split(".");
|
||||||
|
const finalSegment = keySegments.pop();
|
||||||
|
|
||||||
|
// Initialize nested objects as needed
|
||||||
|
keySegments.forEach((segment) => {
|
||||||
|
target = target[segment] = target[segment] || {};
|
||||||
|
});
|
||||||
|
|
||||||
|
target[finalSegment] = "replace_with_new_partition_key_value";
|
||||||
|
});
|
||||||
|
const defaultDocument: string = this.renderObjectForEditor(newDocument, null, 4);
|
||||||
this.initialDocumentContent(defaultDocument);
|
this.initialDocumentContent(defaultDocument);
|
||||||
this.selectedDocumentContent.setBaseline(defaultDocument);
|
this.selectedDocumentContent.setBaseline(defaultDocument);
|
||||||
this.editorState(ViewModels.DocumentExplorerState.newDocumentValid);
|
this.editorState(ViewModels.DocumentExplorerState.newDocumentValid);
|
||||||
|
|
Loading…
Reference in New Issue