diff --git a/src/Explorer/Tabs/DocumentsTab1.tsx b/src/Explorer/Tabs/DocumentsTab1.tsx index 6d6c6313b..dd52ce418 100644 --- a/src/Explorer/Tabs/DocumentsTab1.tsx +++ b/src/Explorer/Tabs/DocumentsTab1.tsx @@ -1,792 +1,771 @@ -import { extractPartitionKey, ItemDefinition, PartitionKeyDefinition, QueryIterator, Resource } from "@azure/cosmos"; import * as ko from "knockout"; -import Q from "q"; import React from "react"; import "react-splitter-layout/lib/index.css"; -import UploadIcon from "../../../images/Upload_16x16.svg"; -import * as Constants from "../../Common/Constants"; -import { DocumentsGridMetrics, KeyCodes } from "../../Common/Constants"; -import { createDocument } from "../../Common/dataAccess/createDocument"; -import { deleteDocument } from "../../Common/dataAccess/deleteDocument"; -import { queryDocuments } from "../../Common/dataAccess/queryDocuments"; -import { readDocument } from "../../Common/dataAccess/readDocument"; -import { updateDocument } from "../../Common/dataAccess/updateDocument"; -import editable from "../../Common/EditableUtility"; -import { getErrorMessage, getErrorStack } from "../../Common/ErrorHandlingUtils"; -import * as HeadersUtility from "../../Common/HeadersUtility"; -import { Splitter, SplitterBounds, SplitterDirection } from "../../Common/Splitter"; import * as DataModels from "../../Contracts/DataModels"; import * as ViewModels from "../../Contracts/ViewModels"; -import { Action } from "../../Shared/Telemetry/TelemetryConstants"; -import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor"; -import { userContext } from "../../UserContext"; -import { logConsoleError } from "../../Utils/NotificationConsoleUtils"; -import * as QueryUtils from "../../Utils/QueryUtils"; -import { CommandButtonComponentProps } from "../Controls/CommandButton/CommandButtonComponent"; -import Explorer from "../Explorer"; -import { AccessibleVerticalList } from "../Tree/AccessibleVerticalList"; -import DocumentId from "../Tree/DocumentId"; +// import { AccessibleVerticalList } from "../Tree/AccessibleVerticalList"; +// import DocumentId from "../Tree/DocumentId"; import DocumentsTabContent from "./DocumentsTabContent"; // import template from "./DocumentsTab.html"; import TabsBase from "./TabsBase"; export default class DocumentsTab extends TabsBase { // public readonly html = template; - public selectedDocumentId: ko.Observable; - public selectedDocumentContent: ViewModels.Editable; - public initialDocumentContent: ko.Observable; + // public selectedDocumentId: ko.Observable; + // public selectedDocumentContent: ViewModels.Editable; + // public initialDocumentContent: ko.Observable; public documentContentsGridId: string; public documentContentsContainerId: string; - public filterContent: ko.Observable; - public appliedFilter: ko.Observable; - public lastFilterContents: ko.ObservableArray; - public isFilterExpanded: ko.Observable; - public isFilterCreated: ko.Observable; - public applyFilterButton: ViewModels.Button; - public isEditorDirty: ko.Computed; - public editorState: ko.Observable; - public newDocumentButton: ViewModels.Button; - public saveNewDocumentButton: ViewModels.Button; - public saveExisitingDocumentButton: ViewModels.Button; - public discardNewDocumentChangesButton: ViewModels.Button; - public discardExisitingDocumentChangesButton: ViewModels.Button; - public deleteExisitingDocumentButton: ViewModels.Button; + // public filterContent: ko.Observable; + // public appliedFilter: ko.Observable; + // public lastFilterContents: ko.ObservableArray; + // public isFilterExpanded: ko.Observable; + // public isFilterCreated: ko.Observable; + // public applyFilterButton: ViewModels.Button; + // public isEditorDirty: ko.Computed; + // public editorState: ko.Observable; + // public newDocumentButton: ViewModels.Button; + // public saveNewDocumentButton: ViewModels.Button; + // public saveExisitingDocumentButton: ViewModels.Button; + // public discardNewDocumentChangesButton: ViewModels.Button; + // public discardExisitingDocumentChangesButton: ViewModels.Button; + // public deleteExisitingDocumentButton: ViewModels.Button; public displayedError: ko.Observable; - public accessibleDocumentList: AccessibleVerticalList; - public dataContentsGridScrollHeight: ko.Observable; - public isPreferredApiMongoDB: boolean; - public shouldShowEditor: ko.Computed; - public splitter: Splitter; - public showPartitionKey: boolean; - public idHeader: string; + // public accessibleDocumentList: AccessibleVerticalList; + // public dataContentsGridScrollHeight: ko.Observable; + // public isPreferredApiMongoDB: boolean; + // public shouldShowEditor: ko.Computed; + // public splitter: Splitter; + // public showPartitionKey: boolean; + // public idHeader: string; // TODO need to refactor public partitionKey: DataModels.PartitionKey; public partitionKeyPropertyHeader: string; public partitionKeyProperty: string; - public documentIds: ko.ObservableArray; + // public documentIds: ko.ObservableArray; - private _documentsIterator: QueryIterator; - private _resourceTokenPartitionKey: string; + // private _documentsIterator: QueryIterator; + // private _resourceTokenPartitionKey: string; constructor(options: ViewModels.DocumentsTabOptions) { super(options); - this.isPreferredApiMongoDB = userContext.apiType === "Mongo" || options.isPreferredApiMongoDB; + // this.isPreferredApiMongoDB = userContext.apiType === "Mongo" || options.isPreferredApiMongoDB; - this.idHeader = this.isPreferredApiMongoDB ? "_id" : "id"; + // this.idHeader = this.isPreferredApiMongoDB ? "_id" : "id"; this.documentContentsGridId = `documentContentsGrid${this.tabId}`; this.documentContentsContainerId = `documentContentsContainer${this.tabId}`; - this.editorState = ko.observable( - ViewModels.DocumentExplorerState.noDocumentSelected - ); - this.selectedDocumentId = ko.observable(); - this.selectedDocumentContent = editable.observable(""); - this.initialDocumentContent = ko.observable(""); + // this.editorState = ko.observable( + // ViewModels.DocumentExplorerState.noDocumentSelected + // ); + // this.selectedDocumentId = ko.observable(); + // this.selectedDocumentContent = editable.observable(""); + // this.initialDocumentContent = ko.observable(""); this.partitionKey = options.partitionKey || (this.collection && this.collection.partitionKey); - this._resourceTokenPartitionKey = options.resourceTokenPartitionKey; - this.documentIds = options.documentIds; + // this._resourceTokenPartitionKey = options.resourceTokenPartitionKey; + // this.documentIds = options.documentIds; this.partitionKeyPropertyHeader = (this.collection && this.collection.partitionKeyPropertyHeader) || this._getPartitionKeyPropertyHeader(); this.partitionKeyProperty = this.partitionKeyPropertyHeader ? this.partitionKeyPropertyHeader.replace(/[/]+/g, ".").substr(1).replace(/[']+/g, "") - : null; + : undefined; - this.isFilterExpanded = ko.observable(false); - this.isFilterCreated = ko.observable(true); - this.filterContent = ko.observable(""); - this.appliedFilter = ko.observable(""); + // this.isFilterExpanded = ko.observable(false); + // this.isFilterCreated = ko.observable(true); + // this.filterContent = ko.observable(""); + // this.appliedFilter = ko.observable(""); this.displayedError = ko.observable(""); - this.lastFilterContents = ko.observableArray([ - 'WHERE c.id = "foo"', - "ORDER BY c._ts DESC", - 'WHERE c.id = "foo" ORDER BY c._ts DESC', - ]); + // this.lastFilterContents = ko.observableArray([ + // 'WHERE c.id = "foo"', + // "ORDER BY c._ts DESC", + // 'WHERE c.id = "foo" ORDER BY c._ts DESC', + // ]); - this.dataContentsGridScrollHeight = ko.observable(null); + // this.dataContentsGridScrollHeight = ko.observable(null); // initialize splitter only after template has been loaded so dom elements are accessible - super.onTemplateReady((isTemplateReady: boolean) => { - if (isTemplateReady) { - const tabContainer: HTMLElement = document.getElementById("content"); - const splitterBounds: SplitterBounds = { - min: Constants.DocumentsGridMetrics.DocumentEditorMinWidthRatio * tabContainer.clientWidth, - max: Constants.DocumentsGridMetrics.DocumentEditorMaxWidthRatio * tabContainer.clientWidth, - }; - this.splitter = new Splitter({ - splitterId: "h_splitter2", - leftId: this.documentContentsContainerId, - bounds: splitterBounds, - direction: SplitterDirection.Vertical, - }); - } - }); + // super.onTemplateReady((isTemplateReady: boolean) => { + // if (isTemplateReady) { + // const tabContainer: HTMLElement = document.getElementById("content"); + // const splitterBounds: SplitterBounds = { + // min: Constants.DocumentsGridMetrics.DocumentEditorMinWidthRatio * tabContainer.clientWidth, + // max: Constants.DocumentsGridMetrics.DocumentEditorMaxWidthRatio * tabContainer.clientWidth, + // }; + // this.splitter = new Splitter({ + // splitterId: "h_splitter2", + // leftId: this.documentContentsContainerId, + // bounds: splitterBounds, + // direction: SplitterDirection.Vertical, + // }); + // } + // }); - this.accessibleDocumentList = new AccessibleVerticalList(this.documentIds()); - this.accessibleDocumentList.setOnSelect( - (selectedDocument: DocumentId) => selectedDocument && selectedDocument.click() - ); - this.selectedDocumentId.subscribe((newSelectedDocumentId: DocumentId) => - this.accessibleDocumentList.updateCurrentItem(newSelectedDocumentId) - ); - this.documentIds.subscribe((newDocuments: DocumentId[]) => { - this.accessibleDocumentList.updateItemList(newDocuments); - if (newDocuments.length > 0) { - this.dataContentsGridScrollHeight( - newDocuments.length * DocumentsGridMetrics.IndividualRowHeight + DocumentsGridMetrics.BufferHeight + "px" - ); - } else { - this.dataContentsGridScrollHeight( - DocumentsGridMetrics.IndividualRowHeight + DocumentsGridMetrics.BufferHeight + "px" - ); - } - }); + // this.accessibleDocumentList = new AccessibleVerticalList(this.documentIds()); + // this.accessibleDocumentList.setOnSelect( + // (selectedDocument: DocumentId) => selectedDocument && selectedDocument.click() + // ); + // this.selectedDocumentId.subscribe((newSelectedDocumentId: DocumentId) => + // this.accessibleDocumentList.updateCurrentItem(newSelectedDocumentId) + // ); + // this.documentIds.subscribe((newDocuments: DocumentId[]) => { + // this.accessibleDocumentList.updateItemList(newDocuments); + // if (newDocuments.length > 0) { + // this.dataContentsGridScrollHeight( + // newDocuments.length * DocumentsGridMetrics.IndividualRowHeight + DocumentsGridMetrics.BufferHeight + "px" + // ); + // } else { + // this.dataContentsGridScrollHeight( + // DocumentsGridMetrics.IndividualRowHeight + DocumentsGridMetrics.BufferHeight + "px" + // ); + // } + // }); - this.isEditorDirty = ko.computed(() => { - switch (this.editorState()) { - case ViewModels.DocumentExplorerState.noDocumentSelected: - case ViewModels.DocumentExplorerState.exisitingDocumentNoEdits: - return false; + // this.isEditorDirty = ko.computed(() => { + // switch (this.editorState()) { + // case ViewModels.DocumentExplorerState.noDocumentSelected: + // case ViewModels.DocumentExplorerState.exisitingDocumentNoEdits: + // return false; - case ViewModels.DocumentExplorerState.newDocumentValid: - case ViewModels.DocumentExplorerState.newDocumentInvalid: - case ViewModels.DocumentExplorerState.exisitingDocumentDirtyInvalid: - return true; + // case ViewModels.DocumentExplorerState.newDocumentValid: + // case ViewModels.DocumentExplorerState.newDocumentInvalid: + // case ViewModels.DocumentExplorerState.exisitingDocumentDirtyInvalid: + // return true; - case ViewModels.DocumentExplorerState.exisitingDocumentDirtyValid: - return ( - this.selectedDocumentContent.getEditableOriginalValue() !== - this.selectedDocumentContent.getEditableCurrentValue() - ); + // case ViewModels.DocumentExplorerState.exisitingDocumentDirtyValid: + // return ( + // this.selectedDocumentContent.getEditableOriginalValue() !== + // this.selectedDocumentContent.getEditableCurrentValue() + // ); - default: - return false; - } - }); + // default: + // return false; + // } + // }); - this.newDocumentButton = { - enabled: ko.computed(() => { - switch (this.editorState()) { - case ViewModels.DocumentExplorerState.noDocumentSelected: - case ViewModels.DocumentExplorerState.exisitingDocumentNoEdits: - return true; - } + // this.newDocumentButton = { + // enabled: ko.computed(() => { + // switch (this.editorState()) { + // case ViewModels.DocumentExplorerState.noDocumentSelected: + // case ViewModels.DocumentExplorerState.exisitingDocumentNoEdits: + // return true; + // } - return false; - }), + // return false; + // }), - visible: ko.computed(() => { - return true; - }), - }; + // visible: ko.computed(() => { + // return true; + // }), + // }; - this.saveNewDocumentButton = { - enabled: ko.computed(() => { - switch (this.editorState()) { - case ViewModels.DocumentExplorerState.newDocumentValid: - return true; - } + // this.saveNewDocumentButton = { + // enabled: ko.computed(() => { + // switch (this.editorState()) { + // case ViewModels.DocumentExplorerState.newDocumentValid: + // return true; + // } - return false; - }), + // return false; + // }), - visible: ko.computed(() => { - switch (this.editorState()) { - case ViewModels.DocumentExplorerState.newDocumentValid: - case ViewModels.DocumentExplorerState.newDocumentInvalid: - return true; - } + // visible: ko.computed(() => { + // switch (this.editorState()) { + // case ViewModels.DocumentExplorerState.newDocumentValid: + // case ViewModels.DocumentExplorerState.newDocumentInvalid: + // return true; + // } - return false; - }), - }; + // return false; + // }), + // }; - this.discardNewDocumentChangesButton = { - enabled: ko.computed(() => { - switch (this.editorState()) { - case ViewModels.DocumentExplorerState.newDocumentValid: - case ViewModels.DocumentExplorerState.newDocumentInvalid: - return true; - } + // this.discardNewDocumentChangesButton = { + // enabled: ko.computed(() => { + // switch (this.editorState()) { + // case ViewModels.DocumentExplorerState.newDocumentValid: + // case ViewModels.DocumentExplorerState.newDocumentInvalid: + // return true; + // } - return false; - }), + // return false; + // }), - visible: ko.computed(() => { - switch (this.editorState()) { - case ViewModels.DocumentExplorerState.newDocumentValid: - case ViewModels.DocumentExplorerState.newDocumentInvalid: - return true; - } + // visible: ko.computed(() => { + // switch (this.editorState()) { + // case ViewModels.DocumentExplorerState.newDocumentValid: + // case ViewModels.DocumentExplorerState.newDocumentInvalid: + // return true; + // } - return false; - }), - }; + // return false; + // }), + // }; - this.saveExisitingDocumentButton = { - enabled: ko.computed(() => { - switch (this.editorState()) { - case ViewModels.DocumentExplorerState.exisitingDocumentDirtyValid: - return true; - } + // this.saveExisitingDocumentButton = { + // enabled: ko.computed(() => { + // switch (this.editorState()) { + // case ViewModels.DocumentExplorerState.exisitingDocumentDirtyValid: + // return true; + // } - return false; - }), + // return false; + // }), - visible: ko.computed(() => { - switch (this.editorState()) { - case ViewModels.DocumentExplorerState.exisitingDocumentNoEdits: - case ViewModels.DocumentExplorerState.exisitingDocumentDirtyInvalid: - case ViewModels.DocumentExplorerState.exisitingDocumentDirtyValid: - return true; - } + // visible: ko.computed(() => { + // switch (this.editorState()) { + // case ViewModels.DocumentExplorerState.exisitingDocumentNoEdits: + // case ViewModels.DocumentExplorerState.exisitingDocumentDirtyInvalid: + // case ViewModels.DocumentExplorerState.exisitingDocumentDirtyValid: + // return true; + // } - return false; - }), - }; + // return false; + // }), + // }; - this.discardExisitingDocumentChangesButton = { - enabled: ko.computed(() => { - switch (this.editorState()) { - case ViewModels.DocumentExplorerState.exisitingDocumentDirtyInvalid: - case ViewModels.DocumentExplorerState.exisitingDocumentDirtyValid: - return true; - } + // this.discardExisitingDocumentChangesButton = { + // enabled: ko.computed(() => { + // switch (this.editorState()) { + // case ViewModels.DocumentExplorerState.exisitingDocumentDirtyInvalid: + // case ViewModels.DocumentExplorerState.exisitingDocumentDirtyValid: + // return true; + // } - return false; - }), + // return false; + // }), - visible: ko.computed(() => { - switch (this.editorState()) { - case ViewModels.DocumentExplorerState.exisitingDocumentNoEdits: - case ViewModels.DocumentExplorerState.exisitingDocumentDirtyInvalid: - case ViewModels.DocumentExplorerState.exisitingDocumentDirtyValid: - return true; - } + // visible: ko.computed(() => { + // switch (this.editorState()) { + // case ViewModels.DocumentExplorerState.exisitingDocumentNoEdits: + // case ViewModels.DocumentExplorerState.exisitingDocumentDirtyInvalid: + // case ViewModels.DocumentExplorerState.exisitingDocumentDirtyValid: + // return true; + // } - return false; - }), - }; + // return false; + // }), + // }; - this.deleteExisitingDocumentButton = { - enabled: ko.computed(() => { - switch (this.editorState()) { - case ViewModels.DocumentExplorerState.exisitingDocumentNoEdits: - case ViewModels.DocumentExplorerState.exisitingDocumentDirtyInvalid: - case ViewModels.DocumentExplorerState.exisitingDocumentDirtyValid: - return true; - } + // this.deleteExisitingDocumentButton = { + // enabled: ko.computed(() => { + // switch (this.editorState()) { + // case ViewModels.DocumentExplorerState.exisitingDocumentNoEdits: + // case ViewModels.DocumentExplorerState.exisitingDocumentDirtyInvalid: + // case ViewModels.DocumentExplorerState.exisitingDocumentDirtyValid: + // return true; + // } - return false; - }), + // return false; + // }), - visible: ko.computed(() => { - switch (this.editorState()) { - case ViewModels.DocumentExplorerState.exisitingDocumentNoEdits: - case ViewModels.DocumentExplorerState.exisitingDocumentDirtyInvalid: - case ViewModels.DocumentExplorerState.exisitingDocumentDirtyValid: - return true; - } + // visible: ko.computed(() => { + // switch (this.editorState()) { + // case ViewModels.DocumentExplorerState.exisitingDocumentNoEdits: + // case ViewModels.DocumentExplorerState.exisitingDocumentDirtyInvalid: + // case ViewModels.DocumentExplorerState.exisitingDocumentDirtyValid: + // return true; + // } - return false; - }), - }; + // return false; + // }), + // }; - this.applyFilterButton = { - enabled: ko.computed(() => { - return true; - }), + // this.applyFilterButton = { + // enabled: ko.computed(() => { + // return true; + // }), - visible: ko.computed(() => { - return true; - }), - }; - this.buildCommandBarOptions(); - this.shouldShowEditor = ko.computed(() => { - const documentHasContent: boolean = - this.selectedDocumentContent() != null && this.selectedDocumentContent().length > 0; - const isNewDocument: boolean = - this.editorState() === ViewModels.DocumentExplorerState.newDocumentValid || - this.editorState() === ViewModels.DocumentExplorerState.newDocumentInvalid; + // visible: ko.computed(() => { + // return true; + // }), + // }; + // // this.buildCommandBarOptions(); + // this.shouldShowEditor = ko.computed(() => { + // const documentHasContent: boolean = + // this.selectedDocumentContent() != null && this.selectedDocumentContent().length > 0; + // const isNewDocument: boolean = + // this.editorState() === ViewModels.DocumentExplorerState.newDocumentValid || + // this.editorState() === ViewModels.DocumentExplorerState.newDocumentInvalid; - return documentHasContent || isNewDocument; - }); - this.selectedDocumentContent.subscribe((newContent: string) => this._onEditorContentChange(newContent)); + // return documentHasContent || isNewDocument; + // }); + // this.selectedDocumentContent.subscribe((newContent: string) => this._onEditorContentChange(newContent)); - this.showPartitionKey = this._shouldShowPartitionKey(); + // this.showPartitionKey = this._shouldShowPartitionKey(); } - private _shouldShowPartitionKey(): boolean { - if (!this.collection) { - return false; - } + // private _shouldShowPartitionKey(): boolean { + // if (!this.collection) { + // return false; + // } - if (!this.collection.partitionKey) { - return false; - } + // if (!this.collection.partitionKey) { + // return false; + // } - if (this.collection.partitionKey.systemKey && this.isPreferredApiMongoDB) { - return false; - } + // if (this.collection.partitionKey.systemKey && this.isPreferredApiMongoDB) { + // return false; + // } - return true; - } + // return true; + // } - public onShowFilterClick(): Q.Promise { - this.isFilterCreated(true); - this.isFilterExpanded(true); + // public onShowFilterClick(): Q.Promise { + // this.isFilterCreated(true); + // this.isFilterExpanded(true); - $(".filterDocExpanded").addClass("active"); - $("#content").addClass("active"); - $(".querydropdown").focus(); + // $(".filterDocExpanded").addClass("active"); + // $("#content").addClass("active"); + // $(".querydropdown").focus(); - return Q(); - } + // return Q(); + // } - public onHideFilterClick(): Q.Promise { - this.isFilterExpanded(false); + // public onHideFilterClick(): Q.Promise { + // this.isFilterExpanded(false); - $(".filterDocExpanded").removeClass("active"); - $("#content").removeClass("active"); - $(".queryButton").focus(); - return Q(); - } + // $(".filterDocExpanded").removeClass("active"); + // $("#content").removeClass("active"); + // $(".queryButton").focus(); + // return Q(); + // } - public onCloseButtonKeyDown = (source: any, event: KeyboardEvent): boolean => { - if (event.keyCode === KeyCodes.Enter || event.keyCode === KeyCodes.Space) { - this.onHideFilterClick(); - event.stopPropagation(); - return false; - } - return true; - }; + // public onCloseButtonKeyDown = (source: any, event: KeyboardEvent): boolean => { + // if (event.keyCode === KeyCodes.Enter || event.keyCode === KeyCodes.Space) { + // this.onHideFilterClick(); + // event.stopPropagation(); + // return false; + // } + // return true; + // }; - public async refreshDocumentsGrid(): Promise { - // clear documents grid - this.documentIds([]); + // public async refreshDocumentsGrid(): Promise { + // // clear documents grid + // this.documentIds([]); - try { - // reset iterator - this._documentsIterator = this.createIterator(); - // load documents - await this.loadNextPage(); - // collapse filter - this.appliedFilter(this.filterContent()); - this.isFilterExpanded(false); - document.getElementById("errorStatusIcon")?.focus(); - } catch (error) { - window.alert(getErrorMessage(error)); - } - } + // try { + // // reset iterator + // this._documentsIterator = this.createIterator(); + // // load documents + // await this.loadNextPage(); + // // collapse filter + // this.appliedFilter(this.filterContent()); + // this.isFilterExpanded(false); + // document.getElementById("errorStatusIcon")?.focus(); + // } catch (error) { + // window.alert(getErrorMessage(error)); + // } + // } - public onRefreshButtonKeyDown = (source: any, event: KeyboardEvent): boolean => { - if (event.keyCode === KeyCodes.Enter || event.keyCode === KeyCodes.Space) { - this.refreshDocumentsGrid(); - event.stopPropagation(); - return false; - } - return true; - }; + // public onRefreshButtonKeyDown = (source: any, event: KeyboardEvent): boolean => { + // if (event.keyCode === KeyCodes.Enter || event.keyCode === KeyCodes.Space) { + // this.refreshDocumentsGrid(); + // event.stopPropagation(); + // return false; + // } + // return true; + // }; - public onDocumentIdClick(clickedDocumentId: DocumentId): Q.Promise { - if (this.editorState() !== ViewModels.DocumentExplorerState.noDocumentSelected) { - return Q(); - } + // public onDocumentIdClick(clickedDocumentId: DocumentId): Q.Promise { + // if (this.editorState() !== ViewModels.DocumentExplorerState.noDocumentSelected) { + // return Q(); + // } - this.editorState(ViewModels.DocumentExplorerState.exisitingDocumentNoEdits); + // this.editorState(ViewModels.DocumentExplorerState.exisitingDocumentNoEdits); - return Q(); - } + // return Q(); + // } - public onNewDocumentClick = (): Q.Promise => { - if (this.isEditorDirty() && !this._isIgnoreDirtyEditor()) { - return Q(); - } - this.selectedDocumentId(null); + // public onNewDocumentClick = (): Q.Promise => { + // if (this.isEditorDirty() && !this._isIgnoreDirtyEditor()) { + // return Q(); + // } + // this.selectedDocumentId(null); - const defaultDocument: string = this.renderObjectForEditor({ id: "replace_with_new_document_id" }, null, 4); - this.initialDocumentContent(defaultDocument); - this.selectedDocumentContent.setBaseline(defaultDocument); - this.editorState(ViewModels.DocumentExplorerState.newDocumentValid); + // const defaultDocument: string = this.renderObjectForEditor({ id: "replace_with_new_document_id" }, null, 4); + // this.initialDocumentContent(defaultDocument); + // this.selectedDocumentContent.setBaseline(defaultDocument); + // this.editorState(ViewModels.DocumentExplorerState.newDocumentValid); - return Q(); - }; + // return Q(); + // }; - public onSaveNewDocumentClick = (): Promise => { - this.isExecutionError(false); - const startKey: number = TelemetryProcessor.traceStart(Action.CreateDocument, { - dataExplorerArea: Constants.Areas.Tab, - tabTitle: this.tabTitle(), - }); - const document = JSON.parse(this.selectedDocumentContent()); - this.isExecuting(true); - return createDocument(this.collection, document) - .then( - (savedDocument: any) => { - const value: string = this.renderObjectForEditor(savedDocument || {}, null, 4); - this.selectedDocumentContent.setBaseline(value); - this.initialDocumentContent(value); - const partitionKeyValueArray = extractPartitionKey( - savedDocument, - this.partitionKey as PartitionKeyDefinition - ); - const partitionKeyValue = partitionKeyValueArray && partitionKeyValueArray[0]; - const id = new DocumentId(this, savedDocument, partitionKeyValue); - const ids = this.documentIds(); - ids.push(id); + // public onSaveNewDocumentClick = (): Promise => { + // this.isExecutionError(false); + // const startKey: number = TelemetryProcessor.traceStart(Action.CreateDocument, { + // dataExplorerArea: Constants.Areas.Tab, + // tabTitle: this.tabTitle(), + // }); + // const document = JSON.parse(this.selectedDocumentContent()); + // this.isExecuting(true); + // return createDocument(this.collection, document) + // .then( + // (savedDocument: any) => { + // const value: string = this.renderObjectForEditor(savedDocument || {}, null, 4); + // this.selectedDocumentContent.setBaseline(value); + // this.initialDocumentContent(value); + // const partitionKeyValueArray = extractPartitionKey( + // savedDocument, + // this.partitionKey as PartitionKeyDefinition + // ); + // const partitionKeyValue = partitionKeyValueArray && partitionKeyValueArray[0]; + // const id = new DocumentId(this, savedDocument, partitionKeyValue); + // const ids = this.documentIds(); + // ids.push(id); - this.selectedDocumentId(id); - this.documentIds(ids); - this.editorState(ViewModels.DocumentExplorerState.exisitingDocumentNoEdits); - TelemetryProcessor.traceSuccess( - Action.CreateDocument, - { - dataExplorerArea: Constants.Areas.Tab, - tabTitle: this.tabTitle(), - }, - startKey - ); - }, - (error) => { - this.isExecutionError(true); - const errorMessage = getErrorMessage(error); - window.alert(errorMessage); - TelemetryProcessor.traceFailure( - Action.CreateDocument, - { - dataExplorerArea: Constants.Areas.Tab, - tabTitle: this.tabTitle(), - error: errorMessage, - errorStack: getErrorStack(error), - }, - startKey - ); - } - ) - .finally(() => this.isExecuting(false)); - }; + // this.selectedDocumentId(id); + // this.documentIds(ids); + // this.editorState(ViewModels.DocumentExplorerState.exisitingDocumentNoEdits); + // TelemetryProcessor.traceSuccess( + // Action.CreateDocument, + // { + // dataExplorerArea: Constants.Areas.Tab, + // tabTitle: this.tabTitle(), + // }, + // startKey + // ); + // }, + // (error) => { + // this.isExecutionError(true); + // const errorMessage = getErrorMessage(error); + // window.alert(errorMessage); + // TelemetryProcessor.traceFailure( + // Action.CreateDocument, + // { + // dataExplorerArea: Constants.Areas.Tab, + // tabTitle: this.tabTitle(), + // error: errorMessage, + // errorStack: getErrorStack(error), + // }, + // startKey + // ); + // } + // ) + // .finally(() => this.isExecuting(false)); + // }; - public onRevertNewDocumentClick = (): Q.Promise => { - this.initialDocumentContent(""); - this.selectedDocumentContent(""); - this.editorState(ViewModels.DocumentExplorerState.noDocumentSelected); + // public onRevertNewDocumentClick = (): Q.Promise => { + // this.initialDocumentContent(""); + // this.selectedDocumentContent(""); + // this.editorState(ViewModels.DocumentExplorerState.noDocumentSelected); - return Q(); - }; + // return Q(); + // }; - public onSaveExisitingDocumentClick = (): Promise => { - const selectedDocumentId = this.selectedDocumentId(); - const documentContent = JSON.parse(this.selectedDocumentContent()); + // public onSaveExisitingDocumentClick = (): Promise => { + // const selectedDocumentId = this.selectedDocumentId(); + // const documentContent = JSON.parse(this.selectedDocumentContent()); - const partitionKeyValueArray = extractPartitionKey(documentContent, this.partitionKey as PartitionKeyDefinition); - const partitionKeyValue = partitionKeyValueArray && partitionKeyValueArray[0]; + // const partitionKeyValueArray = extractPartitionKey(documentContent, this.partitionKey as PartitionKeyDefinition); + // const partitionKeyValue = partitionKeyValueArray && partitionKeyValueArray[0]; - selectedDocumentId.partitionKeyValue = partitionKeyValue; + // selectedDocumentId.partitionKeyValue = partitionKeyValue; - this.isExecutionError(false); - const startKey: number = TelemetryProcessor.traceStart(Action.UpdateDocument, { - dataExplorerArea: Constants.Areas.Tab, - tabTitle: this.tabTitle(), - }); - this.isExecuting(true); - return updateDocument(this.collection, selectedDocumentId, documentContent) - .then( - (updatedDocument: any) => { - const value: string = this.renderObjectForEditor(updatedDocument || {}, null, 4); - this.selectedDocumentContent.setBaseline(value); - this.initialDocumentContent(value); - this.documentIds().forEach((documentId: DocumentId) => { - if (documentId.rid === updatedDocument._rid) { - documentId.id(updatedDocument.id); - } - }); - this.editorState(ViewModels.DocumentExplorerState.exisitingDocumentNoEdits); - TelemetryProcessor.traceSuccess( - Action.UpdateDocument, - { - dataExplorerArea: Constants.Areas.Tab, - tabTitle: this.tabTitle(), - }, - startKey - ); - }, - (error) => { - this.isExecutionError(true); - const errorMessage = getErrorMessage(error); - window.alert(errorMessage); - TelemetryProcessor.traceFailure( - Action.UpdateDocument, - { - dataExplorerArea: Constants.Areas.Tab, - tabTitle: this.tabTitle(), - error: errorMessage, - errorStack: getErrorStack(error), - }, - startKey - ); - } - ) - .finally(() => this.isExecuting(false)); - }; + // this.isExecutionError(false); + // const startKey: number = TelemetryProcessor.traceStart(Action.UpdateDocument, { + // dataExplorerArea: Constants.Areas.Tab, + // tabTitle: this.tabTitle(), + // }); + // this.isExecuting(true); + // return updateDocument(this.collection, selectedDocumentId, documentContent) + // .then( + // (updatedDocument: any) => { + // const value: string = this.renderObjectForEditor(updatedDocument || {}, null, 4); + // this.selectedDocumentContent.setBaseline(value); + // this.initialDocumentContent(value); + // this.documentIds().forEach((documentId: DocumentId) => { + // if (documentId.rid === updatedDocument._rid) { + // documentId.id(updatedDocument.id); + // } + // }); + // this.editorState(ViewModels.DocumentExplorerState.exisitingDocumentNoEdits); + // TelemetryProcessor.traceSuccess( + // Action.UpdateDocument, + // { + // dataExplorerArea: Constants.Areas.Tab, + // tabTitle: this.tabTitle(), + // }, + // startKey + // ); + // }, + // (error) => { + // this.isExecutionError(true); + // const errorMessage = getErrorMessage(error); + // window.alert(errorMessage); + // TelemetryProcessor.traceFailure( + // Action.UpdateDocument, + // { + // dataExplorerArea: Constants.Areas.Tab, + // tabTitle: this.tabTitle(), + // error: errorMessage, + // errorStack: getErrorStack(error), + // }, + // startKey + // ); + // } + // ) + // .finally(() => this.isExecuting(false)); + // }; - public onRevertExisitingDocumentClick = (): Q.Promise => { - this.selectedDocumentContent.setBaseline(this.initialDocumentContent()); - this.initialDocumentContent.valueHasMutated(); - this.editorState(ViewModels.DocumentExplorerState.exisitingDocumentNoEdits); + // public onRevertExisitingDocumentClick = (): Q.Promise => { + // this.selectedDocumentContent.setBaseline(this.initialDocumentContent()); + // this.initialDocumentContent.valueHasMutated(); + // this.editorState(ViewModels.DocumentExplorerState.exisitingDocumentNoEdits); - return Q(); - }; + // return Q(); + // }; - public onDeleteExisitingDocumentClick = async (): Promise => { - const selectedDocumentId = this.selectedDocumentId(); - const msg = !this.isPreferredApiMongoDB - ? "Are you sure you want to delete the selected item ?" - : "Are you sure you want to delete the selected document ?"; + // public onDeleteExisitingDocumentClick = async (): Promise => { + // const selectedDocumentId = this.selectedDocumentId(); + // const msg = !this.isPreferredApiMongoDB + // ? "Are you sure you want to delete the selected item ?" + // : "Are you sure you want to delete the selected document ?"; - if (window.confirm(msg)) { - await this._deleteDocument(selectedDocumentId); - } - }; + // if (window.confirm(msg)) { + // await this._deleteDocument(selectedDocumentId); + // } + // }; - public onValidDocumentEdit(): Q.Promise { - if ( - this.editorState() === ViewModels.DocumentExplorerState.newDocumentInvalid || - this.editorState() === ViewModels.DocumentExplorerState.newDocumentValid - ) { - this.editorState(ViewModels.DocumentExplorerState.newDocumentValid); - return Q(); - } + // public onValidDocumentEdit(): Q.Promise { + // if ( + // this.editorState() === ViewModels.DocumentExplorerState.newDocumentInvalid || + // this.editorState() === ViewModels.DocumentExplorerState.newDocumentValid + // ) { + // this.editorState(ViewModels.DocumentExplorerState.newDocumentValid); + // return Q(); + // } - this.editorState(ViewModels.DocumentExplorerState.exisitingDocumentDirtyValid); - return Q(); - } + // this.editorState(ViewModels.DocumentExplorerState.exisitingDocumentDirtyValid); + // return Q(); + // } - public onInvalidDocumentEdit(): Q.Promise { - if ( - this.editorState() === ViewModels.DocumentExplorerState.newDocumentInvalid || - this.editorState() === ViewModels.DocumentExplorerState.newDocumentValid - ) { - this.editorState(ViewModels.DocumentExplorerState.newDocumentInvalid); - return Q(); - } + // public onInvalidDocumentEdit(): Q.Promise { + // if ( + // this.editorState() === ViewModels.DocumentExplorerState.newDocumentInvalid || + // this.editorState() === ViewModels.DocumentExplorerState.newDocumentValid + // ) { + // this.editorState(ViewModels.DocumentExplorerState.newDocumentInvalid); + // return Q(); + // } - if ( - this.editorState() === ViewModels.DocumentExplorerState.exisitingDocumentNoEdits || - this.editorState() === ViewModels.DocumentExplorerState.exisitingDocumentDirtyValid - ) { - this.editorState(ViewModels.DocumentExplorerState.exisitingDocumentDirtyInvalid); - return Q(); - } + // if ( + // this.editorState() === ViewModels.DocumentExplorerState.exisitingDocumentNoEdits || + // this.editorState() === ViewModels.DocumentExplorerState.exisitingDocumentDirtyValid + // ) { + // this.editorState(ViewModels.DocumentExplorerState.exisitingDocumentDirtyInvalid); + // return Q(); + // } - return Q(); - } + // return Q(); + // } public onTabClick(): void { super.onTabClick(); this.collection && this.collection.selectedSubnodeKind(ViewModels.CollectionTabKind.Documents); } - public async onActivate(): Promise { - super.onActivate(); + // public async onActivate(): Promise { + // super.onActivate(); - if (!this._documentsIterator) { - try { - this._documentsIterator = this.createIterator(); - await this.loadNextPage(); - } catch (error) { - if (this.onLoadStartKey != null && this.onLoadStartKey != undefined) { - TelemetryProcessor.traceFailure( - Action.Tab, - { - databaseName: this.collection.databaseId, - collectionName: this.collection.id(), + // if (!this._documentsIterator) { + // try { + // this._documentsIterator = this.createIterator(); + // await this.loadNextPage(); + // } catch (error) { + // if (this.onLoadStartKey != null && this.onLoadStartKey != undefined) { + // TelemetryProcessor.traceFailure( + // Action.Tab, + // { + // databaseName: this.collection.databaseId, + // collectionName: this.collection.id(), - dataExplorerArea: Constants.Areas.Tab, - tabTitle: this.tabTitle(), - error: getErrorMessage(error), - errorStack: getErrorStack(error), - }, - this.onLoadStartKey - ); - this.onLoadStartKey = null; - } - } - } - } + // dataExplorerArea: Constants.Areas.Tab, + // tabTitle: this.tabTitle(), + // error: getErrorMessage(error), + // errorStack: getErrorStack(error), + // }, + // this.onLoadStartKey + // ); + // this.onLoadStartKey = undefined; + // } + // } + // } + // } - private _isIgnoreDirtyEditor = (): boolean => { - const msg = "Changes will be lost. Do you want to continue?"; - return window.confirm(msg); - }; + // private _isIgnoreDirtyEditor = (): boolean => { + // const msg = "Changes will be lost. Do you want to continue?"; + // return window.confirm(msg); + // }; - protected __deleteDocument(documentId: DocumentId): Promise { - return deleteDocument(this.collection, documentId); - } + // protected __deleteDocument(documentId: DocumentId): Promise { + // return deleteDocument(this.collection, documentId); + // } - private _deleteDocument(selectedDocumentId: DocumentId): Promise { - this.isExecutionError(false); - const startKey: number = TelemetryProcessor.traceStart(Action.DeleteDocument, { - dataExplorerArea: Constants.Areas.Tab, - tabTitle: this.tabTitle(), - }); - this.isExecuting(true); - return this.__deleteDocument(selectedDocumentId) - .then( - () => { - this.documentIds.remove((documentId: DocumentId) => documentId.rid === selectedDocumentId.rid); - this.selectedDocumentContent(""); - this.selectedDocumentId(null); - this.editorState(ViewModels.DocumentExplorerState.noDocumentSelected); - TelemetryProcessor.traceSuccess( - Action.DeleteDocument, - { - dataExplorerArea: Constants.Areas.Tab, - tabTitle: this.tabTitle(), - }, - startKey - ); - }, - (error) => { - this.isExecutionError(true); - console.error(error); - TelemetryProcessor.traceFailure( - Action.DeleteDocument, - { - dataExplorerArea: Constants.Areas.Tab, - tabTitle: this.tabTitle(), - error: getErrorMessage(error), - errorStack: getErrorStack(error), - }, - startKey - ); - } - ) - .finally(() => this.isExecuting(false)); - } + // private _deleteDocument(selectedDocumentId: DocumentId): Promise { + // this.isExecutionError(false); + // const startKey: number = TelemetryProcessor.traceStart(Action.DeleteDocument, { + // dataExplorerArea: Constants.Areas.Tab, + // tabTitle: this.tabTitle(), + // }); + // this.isExecuting(true); + // return this.__deleteDocument(selectedDocumentId) + // .then( + // () => { + // this.documentIds.remove((documentId: DocumentId) => documentId.rid === selectedDocumentId.rid); + // this.selectedDocumentContent(""); + // this.selectedDocumentId(null); + // this.editorState(ViewModels.DocumentExplorerState.noDocumentSelected); + // TelemetryProcessor.traceSuccess( + // Action.DeleteDocument, + // { + // dataExplorerArea: Constants.Areas.Tab, + // tabTitle: this.tabTitle(), + // }, + // startKey + // ); + // }, + // (error) => { + // this.isExecutionError(true); + // console.error(error); + // TelemetryProcessor.traceFailure( + // Action.DeleteDocument, + // { + // dataExplorerArea: Constants.Areas.Tab, + // tabTitle: this.tabTitle(), + // error: getErrorMessage(error), + // errorStack: getErrorStack(error), + // }, + // startKey + // ); + // } + // ) + // .finally(() => this.isExecuting(false)); + // } - public createIterator(): QueryIterator { - const filters = this.lastFilterContents(); - const filter: string = this.filterContent().trim(); - const query: string = this.buildQuery(filter); - const options: any = {}; - options.enableCrossPartitionQuery = HeadersUtility.shouldEnableCrossPartitionKey(); + // public createIterator(): QueryIterator { + // const filters = this.lastFilterContents(); + // const filter: string = this.filterContent().trim(); + // const query: string = this.buildQuery(filter); + // const options: any = {}; + // options.enableCrossPartitionQuery = HeadersUtility.shouldEnableCrossPartitionKey(); - if (this._resourceTokenPartitionKey) { - options.partitionKey = this._resourceTokenPartitionKey; - } + // if (this._resourceTokenPartitionKey) { + // options.partitionKey = this._resourceTokenPartitionKey; + // } - return queryDocuments(this.collection.databaseId, this.collection.id(), query, options); - } + // return queryDocuments(this.collection.databaseId, this.collection.id(), query, options); + // } - public async selectDocument(documentId: DocumentId): Promise { - this.selectedDocumentId(documentId); - const content = await readDocument(this.collection, documentId); - this.initDocumentEditor(documentId, content); - } + // public async selectDocument(documentId: DocumentId): Promise { + // this.selectedDocumentId(documentId); + // const content = await readDocument(this.collection, documentId); + // this.initDocumentEditor(documentId, content); + // } - public loadNextPage(): Q.Promise { - this.isExecuting(true); - this.isExecutionError(false); - return this._loadNextPageInternal() - .then( - (documentsIdsResponse = []) => { - const currentDocuments = this.documentIds(); - const currentDocumentsRids = currentDocuments.map((currentDocument) => currentDocument.rid); - const nextDocumentIds = documentsIdsResponse - // filter documents already loaded in observable - .filter((d: any) => { - return currentDocumentsRids.indexOf(d._rid) < 0; - }) - // map raw response to view model - .map((rawDocument: any) => { - const partitionKeyValue = rawDocument._partitionKeyValue; - return new DocumentId(this, rawDocument, partitionKeyValue); - }); + // public loadNextPage(): Q.Promise { + // this.isExecuting(true); + // this.isExecutionError(false); + // return this._loadNextPageInternal() + // .then( + // (documentsIdsResponse = []) => { + // const currentDocuments = this.documentIds(); + // const currentDocumentsRids = currentDocuments.map((currentDocument) => currentDocument.rid); + // const nextDocumentIds = documentsIdsResponse + // // filter documents already loaded in observable + // .filter((d: any) => { + // return currentDocumentsRids.indexOf(d._rid) < 0; + // }) + // // map raw response to view model + // .map((rawDocument: any) => { + // const partitionKeyValue = rawDocument._partitionKeyValue; + // return new DocumentId(this, rawDocument, partitionKeyValue); + // }); - const merged = currentDocuments.concat(nextDocumentIds); - this.documentIds(merged); - if (this.onLoadStartKey != null && this.onLoadStartKey != undefined) { - TelemetryProcessor.traceSuccess( - Action.Tab, - { - databaseName: this.collection.databaseId, - collectionName: this.collection.id(), + // const merged = currentDocuments.concat(nextDocumentIds); + // this.documentIds(merged); + // if (this.onLoadStartKey != null && this.onLoadStartKey != undefined) { + // TelemetryProcessor.traceSuccess( + // Action.Tab, + // { + // databaseName: this.collection.databaseId, + // collectionName: this.collection.id(), - dataExplorerArea: Constants.Areas.Tab, - tabTitle: this.tabTitle(), - }, - this.onLoadStartKey - ); - this.onLoadStartKey = null; - } - }, - (error) => { - this.isExecutionError(true); - const errorMessage = getErrorMessage(error); - logConsoleError(errorMessage); - if (this.onLoadStartKey != null && this.onLoadStartKey != undefined) { - TelemetryProcessor.traceFailure( - Action.Tab, - { - databaseName: this.collection.databaseId, - collectionName: this.collection.id(), + // dataExplorerArea: Constants.Areas.Tab, + // tabTitle: this.tabTitle(), + // }, + // this.onLoadStartKey + // ); + // this.onLoadStartKey = null; + // } + // }, + // (error) => { + // this.isExecutionError(true); + // const errorMessage = getErrorMessage(error); + // logConsoleError(errorMessage); + // if (this.onLoadStartKey != null && this.onLoadStartKey != undefined) { + // TelemetryProcessor.traceFailure( + // Action.Tab, + // { + // databaseName: this.collection.databaseId, + // collectionName: this.collection.id(), - dataExplorerArea: Constants.Areas.Tab, - tabTitle: this.tabTitle(), - error: errorMessage, - errorStack: getErrorStack(error), - }, - this.onLoadStartKey - ); - this.onLoadStartKey = null; - } - } - ) - .finally(() => this.isExecuting(false)); - } + // dataExplorerArea: Constants.Areas.Tab, + // tabTitle: this.tabTitle(), + // error: errorMessage, + // errorStack: getErrorStack(error), + // }, + // this.onLoadStartKey + // ); + // this.onLoadStartKey = null; + // } + // } + // ) + // .finally(() => this.isExecuting(false)); + // } - public onLoadMoreKeyInput = (source: any, event: KeyboardEvent): void => { - if (event.key === " " || event.key === "Enter") { - const focusElement = document.getElementById(this.documentContentsGridId); - this.loadNextPage(); - focusElement && focusElement.focus(); - event.stopPropagation(); - event.preventDefault(); - } - }; + // public onLoadMoreKeyInput = (source: any, event: KeyboardEvent): void => { + // if (event.key === " " || event.key === "Enter") { + // const focusElement = document.getElementById(this.documentContentsGridId); + // this.loadNextPage(); + // focusElement && focusElement.focus(); + // event.stopPropagation(); + // event.preventDefault(); + // } + // }; - protected _loadNextPageInternal(): Q.Promise { - return Q(this._documentsIterator.fetchNext().then((response) => response.resources)); - } + // protected _loadNextPageInternal(): Q.Promise { + // return Q(this._documentsIterator.fetchNext().then((response) => response.resources)); + // } - protected _onEditorContentChange(newContent: string) { - try { - const parsed: any = JSON.parse(newContent); - this.onValidDocumentEdit(); - } catch (e) { - this.onInvalidDocumentEdit(); - } - } + // protected _onEditorContentChange(newContent: string) { + // try { + // const parsed: any = JSON.parse(newContent); + // this.onValidDocumentEdit(); + // } catch (e) { + // this.onInvalidDocumentEdit(); + // } + // } - public initDocumentEditor(documentId: DocumentId, documentContent: any): Q.Promise { - if (documentId) { - const content: string = this.renderObjectForEditor(documentContent, null, 4); - this.selectedDocumentContent.setBaseline(content); - this.initialDocumentContent(content); - const newState = documentId - ? ViewModels.DocumentExplorerState.exisitingDocumentNoEdits - : ViewModels.DocumentExplorerState.newDocumentValid; - this.editorState(newState); - } + // public initDocumentEditor(documentId: DocumentId, documentContent: any): Q.Promise { + // if (documentId) { + // const content: string = this.renderObjectForEditor(documentContent, null, 4); + // this.selectedDocumentContent.setBaseline(content); + // this.initialDocumentContent(content); + // const newState = documentId + // ? ViewModels.DocumentExplorerState.exisitingDocumentNoEdits + // : ViewModels.DocumentExplorerState.newDocumentValid; + // this.editorState(newState); + // } - return Q(); - } + // return Q(); + // } - public buildQuery(filter: string): string { - return QueryUtils.buildDocumentsQuery(filter, this.partitionKeyProperty, this.partitionKey); - } + // public buildQuery(filter: string): string { + // return QueryUtils.buildDocumentsQuery(filter, this.partitionKeyProperty, this.partitionKey); + // } // protected getTabsButtons(): CommandButtonComponentProps[] { // const buttons: CommandButtonComponentProps[] = []; @@ -876,22 +855,22 @@ export default class DocumentsTab extends TabsBase { // } protected buildCommandBarOptions(): void { - ko.computed(() => - ko.toJSON([ - this.newDocumentButton.visible, - this.newDocumentButton.enabled, - this.saveNewDocumentButton.visible, - this.saveNewDocumentButton.enabled, - this.discardNewDocumentChangesButton.visible, - this.discardNewDocumentChangesButton.enabled, - this.saveExisitingDocumentButton.visible, - this.saveExisitingDocumentButton.enabled, - this.discardExisitingDocumentChangesButton.visible, - this.discardExisitingDocumentChangesButton.enabled, - this.deleteExisitingDocumentButton.visible, - this.deleteExisitingDocumentButton.enabled, - ]) - ).subscribe(() => this.updateNavbarWithTabsButtons()); + // ko.computed(() => + // ko.toJSON([ + // this.newDocumentButton.visible, + // this.newDocumentButton.enabled, + // this.saveNewDocumentButton.visible, + // this.saveNewDocumentButton.enabled, + // this.discardNewDocumentChangesButton.visible, + // this.discardNewDocumentChangesButton.enabled, + // this.saveExisitingDocumentButton.visible, + // this.saveExisitingDocumentButton.enabled, + // this.discardExisitingDocumentChangesButton.visible, + // this.discardExisitingDocumentChangesButton.enabled, + // this.deleteExisitingDocumentButton.visible, + // this.deleteExisitingDocumentButton.enabled, + // ]) + // ).subscribe(() => this.updateNavbarWithTabsButtons()); this.updateNavbarWithTabsButtons(); } @@ -901,25 +880,25 @@ export default class DocumentsTab extends TabsBase { this.partitionKey.paths && this.partitionKey.paths.length > 0 && this.partitionKey.paths[0]) || - null + undefined ); } - public static _createUploadButton(container: Explorer): CommandButtonComponentProps { - const label = "Upload Item"; - return { - iconSrc: UploadIcon, - iconAlt: label, - onCommandClick: () => { - const selectedCollection: ViewModels.Collection = container.findSelectedCollection(); - selectedCollection && container.openUploadItemsPanePane(); - }, - commandButtonLabel: label, - ariaLabel: label, - hasPopup: true, - disabled: container.isDatabaseNodeOrNoneSelected(), - }; - } + // public static _createUploadButton(container: Explorer): CommandButtonComponentProps { + // const label = "Upload Item"; + // return { + // iconSrc: UploadIcon, + // iconAlt: label, + // onCommandClick: () => { + // const selectedCollection: ViewModels.Collection = container.findSelectedCollection(); + // selectedCollection && container.openUploadItemsPanePane(); + // }, + // commandButtonLabel: label, + // ariaLabel: label, + // hasPopup: true, + // disabled: container.isDatabaseNodeOrNoneSelected(), + // }; + // } render(): JSX.Element { return ; diff --git a/src/Explorer/Tabs/DocumentsTabContent.tsx b/src/Explorer/Tabs/DocumentsTabContent.tsx index 567098a86..a30d5999f 100644 --- a/src/Explorer/Tabs/DocumentsTabContent.tsx +++ b/src/Explorer/Tabs/DocumentsTabContent.tsx @@ -12,9 +12,8 @@ import { SelectionMode, Stack, Text, - TextField, + TextField } from "@fluentui/react"; -import {} from "@fluentui/react/lib/Image"; import * as React from "react"; import SplitterLayout from "react-splitter-layout"; import CloseIcon from "../../../images/close-black.svg"; @@ -28,6 +27,7 @@ import { Areas } from "../../Common/Constants"; import { getErrorMessage, getErrorStack } from "../../Common/ErrorHandlingUtils"; import { logError } from "../../Common/Logger"; import { createDocument, deleteDocument, queryDocuments, updateDocument } from "../../Common/MongoProxyClient"; +import * as ViewModels from "../../Contracts/ViewModels"; import { Action } from "../../Shared/Telemetry/TelemetryConstants"; import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor"; import { userContext } from "../../UserContext"; @@ -36,7 +36,7 @@ import { EditorReact } from "../Controls/Editor/EditorReact"; import { useCommandBar } from "../Menus/CommandBar/CommandBarComponentAdapter"; import DocumentId from "../Tree/DocumentId"; import ObjectId from "../Tree/ObjectId"; -import DocumentsTab from "./DocumentsTab"; +import DocumentsTab from "./DocumentsTab1"; import { formatDocumentContent, getPartitionKeyDefinition, hasShardKeySpecified } from "./DocumentTabUtils"; const filterIcon: IIconProps = { iconName: "Filter" }; @@ -54,6 +54,7 @@ export interface IDocumentsTabContentState { documentIds: Array; editorKey: string; selectedDocumentId?: DocumentId; + isEditorContentEdited: boolean; } export interface IDocument { @@ -76,6 +77,8 @@ const imageProps: Partial = { const filterSuggestions = [{ value: `{"id": "foo"}` }, { value: "{ qty: { $gte: 20 } }" }]; const intitalDocumentContent = `{ \n "id": "replace_with_new_document_id" \n }`; +const idHeader = userContext.apiType === "Mongo" ? "_id" : "id"; + export default class DocumentsTabContent extends React.Component { public newDocumentButton: IButton; public saveNewDocumentButton: IButton; @@ -115,7 +118,7 @@ export default class DocumentsTabContent extends React.Component { - const partitionKeyValue = rawDocument._partitionKeyValue; - return new DocumentId(this.props, rawDocument, partitionKeyValue); + const partitionKeyValue = rawDocument.partitionKeyValue; + return new DocumentId(this.props as DocumentsTab, rawDocument, partitionKeyValue); }); - this.setState({ documentIds: nextDocumentIds }); } if (this.props.onLoadStartKey !== undefined) { @@ -219,6 +224,19 @@ export default class DocumentsTabContent extends React.Component { + if (this.state.isEditorContentEdited) { + const isChangesConfirmed = window.confirm("Your unsaved changes will be lost.") + if (isChangesConfirmed) { + this.handleRowContent(row); + this.setState({ isEditorContentEdited: false }); + return; + } + } else { + this.handleRowContent(row); + } + }; + + handleRowContent = (row: DocumentId): void => { const formattedDocumentContent = formatDocumentContent(row); this.newDocumentButton = { visible: false, @@ -255,7 +273,7 @@ export default class DocumentsTabContent extends React.Component { const { partitionKeyProperty, partitionKeyValue, rid, self, stringPartitionKeyValue, ts } = row; @@ -291,7 +309,7 @@ export default class DocumentsTabContent extends React.Component { - const { collection } = this.props; - return deleteDocument(collection.databaseId, collection, this.state.selectedDocumentId); + private async onDeleteExisitingDocumentClick(): Promise { + const msg = userContext.apiType !== "Mongo" + ? "Are you sure you want to delete the selected item ?" + : "Are you sure you want to delete the selected document ?"; + + const { + isExecutionError, + isExecuting, + collection, + } = this.props; + + if (window.confirm(msg)) { + try { + isExecuting(true) + await deleteDocument(collection.databaseId, collection as ViewModels.Collection, this.state.selectedDocumentId); + isExecuting(false) + } catch (error) { + console.error(error); + isExecutionError(true); + isExecuting(false) + } + } } private onRevertExisitingDocumentClick(): void { @@ -510,7 +548,7 @@ export default class DocumentsTabContent extends React.Component { @@ -603,7 +646,10 @@ export default class DocumentsTabContent extends React.Component(['{"id":"foo"}', "{ qty: { $gte: 20 } }"]); - if (this.partitionKeyProperty && ~this.partitionKeyProperty.indexOf(`"`)) { this.partitionKeyProperty = this.partitionKeyProperty.replace(/["]+/g, ""); } @@ -38,279 +17,279 @@ export default class MongoDocumentsTab extends DocumentsTab { this.partitionKeyPropertyHeader = "/" + this.partitionKeyProperty; } - this.isFilterExpanded = ko.observable(true); + // this.isFilterExpanded = ko.observable(true); super.buildCommandBarOptions.bind(this); super.buildCommandBarOptions(); } - public onSaveNewDocumentClick = (): Promise => { - const documentContent = JSON.parse(this.selectedDocumentContent()); - this.displayedError(""); - const startKey: number = TelemetryProcessor.traceStart(Action.CreateDocument, { - dataExplorerArea: Constants.Areas.Tab, - tabTitle: this.tabTitle(), - }); + // public onSaveNewDocumentClick = (): Promise => { + // const documentContent = JSON.parse(this.selectedDocumentContent()); + // this.displayedError(""); + // const startKey: number = TelemetryProcessor.traceStart(Action.CreateDocument, { + // dataExplorerArea: Constants.Areas.Tab, + // tabTitle: this.tabTitle(), + // }); - if ( - this.partitionKeyProperty && - this.partitionKeyProperty !== "_id" && - !this._hasShardKeySpecified(documentContent) - ) { - const message = `The document is lacking the shard property: ${this.partitionKeyProperty}`; - this.displayedError(message); - let that = this; - setTimeout(() => { - that.displayedError(""); - }, Constants.ClientDefaults.errorNotificationTimeoutMs); - this.isExecutionError(true); - TelemetryProcessor.traceFailure( - Action.CreateDocument, - { - dataExplorerArea: Constants.Areas.Tab, - tabTitle: this.tabTitle(), - error: message, - }, - startKey - ); - Logger.logError("Failed to save new document: Document shard key not defined", "MongoDocumentsTab"); - throw new Error("Document without shard key"); - } + // if ( + // this.partitionKeyProperty && + // this.partitionKeyProperty !== "_id" && + // !this._hasShardKeySpecified(documentContent) + // ) { + // const message = `The document is lacking the shard property: ${this.partitionKeyProperty}`; + // this.displayedError(message); + // let that = this; + // setTimeout(() => { + // that.displayedError(""); + // }, Constants.ClientDefaults.errorNotificationTimeoutMs); + // this.isExecutionError(true); + // TelemetryProcessor.traceFailure( + // Action.CreateDocument, + // { + // dataExplorerArea: Constants.Areas.Tab, + // tabTitle: this.tabTitle(), + // error: message, + // }, + // startKey + // ); + // Logger.logError("Failed to save new document: Document shard key not defined", "MongoDocumentsTab"); + // throw new Error("Document without shard key"); + // } - this.isExecutionError(false); - this.isExecuting(true); - return createDocument(this.collection.databaseId, this.collection, this.partitionKeyProperty, documentContent) - .then( - (savedDocument: any) => { - let partitionKeyArray = extractPartitionKey( - savedDocument, - this._getPartitionKeyDefinition() as PartitionKeyDefinition - ); + // this.isExecutionError(false); + // this.isExecuting(true); + // return createDocument(this.collection.databaseId, this.collection, this.partitionKeyProperty, documentContent) + // .then( + // (savedDocument: any) => { + // let partitionKeyArray = extractPartitionKey( + // savedDocument, + // this._getPartitionKeyDefinition() as PartitionKeyDefinition + // ); - let partitionKeyValue = partitionKeyArray && partitionKeyArray[0]; + // let partitionKeyValue = partitionKeyArray && partitionKeyArray[0]; - let id = new ObjectId(this, savedDocument, partitionKeyValue); - let ids = this.documentIds(); - ids.push(id); - delete savedDocument._self; + // let id = new ObjectId(this, savedDocument, partitionKeyValue); + // let ids = this.documentIds(); + // ids.push(id); + // delete savedDocument._self; - let value: string = this.renderObjectForEditor(savedDocument || {}, null, 4); - this.selectedDocumentContent.setBaseline(value); + // let value: string = this.renderObjectForEditor(savedDocument || {}, null, 4); + // this.selectedDocumentContent.setBaseline(value); - this.selectedDocumentId(id); - this.documentIds(ids); - this.editorState(ViewModels.DocumentExplorerState.exisitingDocumentNoEdits); - TelemetryProcessor.traceSuccess( - Action.CreateDocument, - { - dataExplorerArea: Constants.Areas.Tab, - tabTitle: this.tabTitle(), - }, - startKey - ); - }, - (error) => { - this.isExecutionError(true); - const errorMessage = getErrorMessage(error); - window.alert(errorMessage); - TelemetryProcessor.traceFailure( - Action.CreateDocument, - { - dataExplorerArea: Constants.Areas.Tab, - tabTitle: this.tabTitle(), - error: errorMessage, - errorStack: getErrorStack(error), - }, - startKey - ); - } - ) - .finally(() => this.isExecuting(false)); - }; + // this.selectedDocumentId(id); + // this.documentIds(ids); + // this.editorState(ViewModels.DocumentExplorerState.exisitingDocumentNoEdits); + // TelemetryProcessor.traceSuccess( + // Action.CreateDocument, + // { + // dataExplorerArea: Constants.Areas.Tab, + // tabTitle: this.tabTitle(), + // }, + // startKey + // ); + // }, + // (error) => { + // this.isExecutionError(true); + // const errorMessage = getErrorMessage(error); + // window.alert(errorMessage); + // TelemetryProcessor.traceFailure( + // Action.CreateDocument, + // { + // dataExplorerArea: Constants.Areas.Tab, + // tabTitle: this.tabTitle(), + // error: errorMessage, + // errorStack: getErrorStack(error), + // }, + // startKey + // ); + // } + // ) + // .finally(() => this.isExecuting(false)); + // }; - public onSaveExisitingDocumentClick = (): Promise => { - const selectedDocumentId = this.selectedDocumentId(); - const documentContent = this.selectedDocumentContent(); - this.isExecutionError(false); - this.isExecuting(true); - const startKey: number = TelemetryProcessor.traceStart(Action.UpdateDocument, { - dataExplorerArea: Constants.Areas.Tab, - tabTitle: this.tabTitle(), - }); + // public onSaveExisitingDocumentClick = (): Promise => { + // const selectedDocumentId = this.selectedDocumentId(); + // const documentContent = this.selectedDocumentContent(); + // this.isExecutionError(false); + // this.isExecuting(true); + // const startKey: number = TelemetryProcessor.traceStart(Action.UpdateDocument, { + // dataExplorerArea: Constants.Areas.Tab, + // tabTitle: this.tabTitle(), + // }); - return updateDocument(this.collection.databaseId, this.collection, selectedDocumentId, documentContent) - .then( - (updatedDocument: any) => { - let value: string = this.renderObjectForEditor(updatedDocument || {}, null, 4); - this.selectedDocumentContent.setBaseline(value); + // return updateDocument(this.collection.databaseId, this.collection, selectedDocumentId, documentContent) + // .then( + // (updatedDocument: any) => { + // let value: string = this.renderObjectForEditor(updatedDocument || {}, null, 4); + // this.selectedDocumentContent.setBaseline(value); - this.documentIds().forEach((documentId: DocumentId) => { - if (documentId.rid === updatedDocument._rid) { - const partitionKeyArray = extractPartitionKey( - updatedDocument, - this._getPartitionKeyDefinition() as PartitionKeyDefinition - ); + // this.documentIds().forEach((documentId: DocumentId) => { + // if (documentId.rid === updatedDocument._rid) { + // const partitionKeyArray = extractPartitionKey( + // updatedDocument, + // this._getPartitionKeyDefinition() as PartitionKeyDefinition + // ); - let partitionKeyValue = partitionKeyArray && partitionKeyArray[0]; + // let partitionKeyValue = partitionKeyArray && partitionKeyArray[0]; - const id = new ObjectId(this, updatedDocument, partitionKeyValue); - documentId.id(id.id()); - } - }); - this.editorState(ViewModels.DocumentExplorerState.exisitingDocumentNoEdits); - TelemetryProcessor.traceSuccess( - Action.UpdateDocument, - { - dataExplorerArea: Constants.Areas.Tab, - tabTitle: this.tabTitle(), - }, - startKey - ); - }, - (error) => { - this.isExecutionError(true); - const errorMessage = getErrorMessage(error); - window.alert(errorMessage); - TelemetryProcessor.traceFailure( - Action.UpdateDocument, - { - dataExplorerArea: Constants.Areas.Tab, - tabTitle: this.tabTitle(), - error: errorMessage, - errorStack: getErrorStack(error), - }, - startKey - ); - } - ) - .finally(() => this.isExecuting(false)); - }; + // const id = new ObjectId(this, updatedDocument, partitionKeyValue); + // documentId.id(id.id()); + // } + // }); + // this.editorState(ViewModels.DocumentExplorerState.exisitingDocumentNoEdits); + // TelemetryProcessor.traceSuccess( + // Action.UpdateDocument, + // { + // dataExplorerArea: Constants.Areas.Tab, + // tabTitle: this.tabTitle(), + // }, + // startKey + // ); + // }, + // (error) => { + // this.isExecutionError(true); + // const errorMessage = getErrorMessage(error); + // window.alert(errorMessage); + // TelemetryProcessor.traceFailure( + // Action.UpdateDocument, + // { + // dataExplorerArea: Constants.Areas.Tab, + // tabTitle: this.tabTitle(), + // error: errorMessage, + // errorStack: getErrorStack(error), + // }, + // startKey + // ); + // } + // ) + // .finally(() => this.isExecuting(false)); + // }; public buildQuery(filter: string): string { return filter || "{}"; } - public async selectDocument(documentId: DocumentId): Promise { - this.selectedDocumentId(documentId); - const content = await readDocument(this.collection.databaseId, this.collection, documentId); - this.initDocumentEditor(documentId, content); - } + // public async selectDocument(documentId: DocumentId): Promise { + // this.selectedDocumentId(documentId); + // const content = await readDocument(this.collection.databaseId, this.collection, documentId); + // this.initDocumentEditor(documentId, content); + // } - public loadNextPage(): Q.Promise { - this.isExecuting(true); - this.isExecutionError(false); - const filter: string = this.filterContent().trim(); - const query: string = this.buildQuery(filter); + // public loadNextPage(): Q.Promise { + // this.isExecuting(true); + // this.isExecutionError(false); + // const filter: string = this.filterContent().trim(); + // const query: string = this.buildQuery(filter); - return Q(queryDocuments(this.collection.databaseId, this.collection, true, query, this.continuationToken)) - .then( - ({ continuationToken, documents }) => { - this.continuationToken = continuationToken; - let currentDocuments = this.documentIds(); - const currentDocumentsRids = currentDocuments.map((currentDocument) => currentDocument.rid); - const nextDocumentIds = documents - .filter((d: any) => { - return currentDocumentsRids.indexOf(d._rid) < 0; - }) - .map((rawDocument: any) => { - const partitionKeyValue = rawDocument._partitionKeyValue; - return new DocumentId(this, rawDocument, partitionKeyValue); - }); + // return Q(queryDocuments(this.collection.databaseId, this.collection, true, query, this.continuationToken)) + // .then( + // ({ continuationToken, documents }) => { + // this.continuationToken = continuationToken; + // let currentDocuments = this.documentIds(); + // const currentDocumentsRids = currentDocuments.map((currentDocument) => currentDocument.rid); + // const nextDocumentIds = documents + // .filter((d: any) => { + // return currentDocumentsRids.indexOf(d._rid) < 0; + // }) + // .map((rawDocument: any) => { + // const partitionKeyValue = rawDocument._partitionKeyValue; + // return new DocumentId(this, rawDocument, partitionKeyValue); + // }); - const merged = currentDocuments.concat(nextDocumentIds); + // const merged = currentDocuments.concat(nextDocumentIds); - this.documentIds(merged); - currentDocuments = this.documentIds(); - if (this.filterContent().length > 0 && currentDocuments.length > 0) { - currentDocuments[0].click(); - } else { - this.selectedDocumentContent(""); - this.selectedDocumentId(null); - this.editorState(ViewModels.DocumentExplorerState.noDocumentSelected); - } - if (this.onLoadStartKey != null && this.onLoadStartKey != undefined) { - TelemetryProcessor.traceSuccess( - Action.Tab, - { - databaseName: this.collection.databaseId, - collectionName: this.collection.id(), + // this.documentIds(merged); + // currentDocuments = this.documentIds(); + // if (this.filterContent().length > 0 && currentDocuments.length > 0) { + // currentDocuments[0].click(); + // } else { + // this.selectedDocumentContent(""); + // this.selectedDocumentId(null); + // this.editorState(ViewModels.DocumentExplorerState.noDocumentSelected); + // } + // if (this.onLoadStartKey != null && this.onLoadStartKey != undefined) { + // TelemetryProcessor.traceSuccess( + // Action.Tab, + // { + // databaseName: this.collection.databaseId, + // collectionName: this.collection.id(), - dataExplorerArea: Constants.Areas.Tab, - tabTitle: this.tabTitle(), - }, - this.onLoadStartKey - ); - this.onLoadStartKey = null; - } - }, - (error: any) => { - if (this.onLoadStartKey != null && this.onLoadStartKey != undefined) { - TelemetryProcessor.traceFailure( - Action.Tab, - { - databaseName: this.collection.databaseId, - collectionName: this.collection.id(), + // dataExplorerArea: Constants.Areas.Tab, + // tabTitle: this.tabTitle(), + // }, + // this.onLoadStartKey + // ); + // this.onLoadStartKey = null; + // } + // }, + // (error: any) => { + // if (this.onLoadStartKey != null && this.onLoadStartKey != undefined) { + // TelemetryProcessor.traceFailure( + // Action.Tab, + // { + // databaseName: this.collection.databaseId, + // collectionName: this.collection.id(), - dataExplorerArea: Constants.Areas.Tab, - tabTitle: this.tabTitle(), - error: getErrorMessage(error), - errorStack: getErrorStack(error), - }, - this.onLoadStartKey - ); - this.onLoadStartKey = null; - } - } - ) - .finally(() => this.isExecuting(false)); - } + // dataExplorerArea: Constants.Areas.Tab, + // tabTitle: this.tabTitle(), + // error: getErrorMessage(error), + // errorStack: getErrorStack(error), + // }, + // this.onLoadStartKey + // ); + // this.onLoadStartKey = null; + // } + // } + // ) + // .finally(() => this.isExecuting(false)); + // } - protected _onEditorContentChange(newContent: string) { - try { - if ( - this.editorState() === ViewModels.DocumentExplorerState.newDocumentValid || - this.editorState() === ViewModels.DocumentExplorerState.newDocumentInvalid - ) { - let parsed: any = JSON.parse(newContent); - } + // protected _onEditorContentChange(newContent: string) { + // try { + // if ( + // this.editorState() === ViewModels.DocumentExplorerState.newDocumentValid || + // this.editorState() === ViewModels.DocumentExplorerState.newDocumentInvalid + // ) { + // let parsed: any = JSON.parse(newContent); + // } - // Mongo uses BSON format for _id, trying to parse it as JSON blocks normal flow in an edit - this.onValidDocumentEdit(); - } catch (e) { - this.onInvalidDocumentEdit(); - } - } + // // Mongo uses BSON format for _id, trying to parse it as JSON blocks normal flow in an edit + // this.onValidDocumentEdit(); + // } catch (e) { + // this.onInvalidDocumentEdit(); + // } + // } /** Renders a Javascript object to be displayed inside Monaco Editor */ - protected renderObjectForEditor(value: any, replacer: any, space: string | number): string { - return MongoUtility.tojson(value, null, false); - } + // protected renderObjectForEditor(value: any, replacer: any, space: string | number): string { + // return MongoUtility.tojson(value, null, false); + // } - private _hasShardKeySpecified(document: any): boolean { - return Boolean(extractPartitionKey(document, this._getPartitionKeyDefinition() as PartitionKeyDefinition)); - } + // private _hasShardKeySpecified(document: any): boolean { + // return Boolean(extractPartitionKey(document, this._getPartitionKeyDefinition() as PartitionKeyDefinition)); + // } - private _getPartitionKeyDefinition(): DataModels.PartitionKey { - let partitionKey: DataModels.PartitionKey = this.partitionKey; + // private _getPartitionKeyDefinition(): DataModels.PartitionKey { + // let partitionKey: DataModels.PartitionKey = this.partitionKey; - if ( - this.partitionKey && - this.partitionKey.paths && - this.partitionKey.paths.length && - this.partitionKey.paths.length > 0 && - this.partitionKey.paths[0].indexOf("$v") > -1 - ) { - // Convert BsonSchema2 to /path format - partitionKey = { - kind: partitionKey.kind, - paths: ["/" + this.partitionKeyProperty.replace(/\./g, "/")], - version: partitionKey.version, - }; - } + // if ( + // this.partitionKey && + // this.partitionKey.paths && + // this.partitionKey.paths.length && + // this.partitionKey.paths.length > 0 && + // this.partitionKey.paths[0].indexOf("$v") > -1 + // ) { + // // Convert BsonSchema2 to /path format + // partitionKey = { + // kind: partitionKey.kind, + // paths: ["/" + this.partitionKeyProperty.replace(/\./g, "/")], + // version: partitionKey.version, + // }; + // } - return partitionKey; - } + // return partitionKey; + // } - protected __deleteDocument(documentId: DocumentId): Promise { - return deleteDocument(this.collection.databaseId, this.collection, documentId); - } + // protected __deleteDocument(documentId: DocumentId): Promise { + // return deleteDocument(this.collection.databaseId, this.collection, documentId); + // } } diff --git a/src/Explorer/Tree/DocumentId.ts b/src/Explorer/Tree/DocumentId.ts index 6ba31447a..7be53db13 100644 --- a/src/Explorer/Tree/DocumentId.ts +++ b/src/Explorer/Tree/DocumentId.ts @@ -27,12 +27,12 @@ export default class DocumentId { this.isDirty = ko.observable(false); } - public click() { - if (!this.container.isEditorDirty() || window.confirm("Your unsaved changes will be lost.")) { - this.loadDocument(); - } - return; - } + // public click() { + // if (!this.container.isEditorDirty() || window.confirm("Your unsaved changes will be lost.")) { + // this.loadDocument(); + // } + // return; + // } public partitionKeyHeader(): Object { if (!this.partitionKeyProperty) { @@ -65,7 +65,7 @@ export default class DocumentId { return JSON.stringify(partitionKeyValue); } - public async loadDocument(): Promise { - await this.container.selectDocument(this); - } + // public async loadDocument(): Promise { + // await this.container.selectDocument(this); + // } }