mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-23 19:01:28 +00:00
Compare commits
8 Commits
migration/
...
migrate/Qu
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e20931fbfe | ||
|
|
1f12940d48 | ||
|
|
44315867ce | ||
|
|
1f979a5fb7 | ||
|
|
474ec70923 | ||
|
|
1277940fe9 | ||
|
|
2b8327d222 | ||
|
|
1b74f619ab |
@@ -3068,78 +3068,6 @@ settings-pane {
|
|||||||
display: none;
|
display: none;
|
||||||
height: 0px;
|
height: 0px;
|
||||||
}
|
}
|
||||||
.react-editor {
|
|
||||||
height: 400px;
|
|
||||||
}
|
|
||||||
.documentTabSearchBar{
|
|
||||||
width: 80%;
|
|
||||||
margin: 15px;
|
|
||||||
}
|
|
||||||
.documentSqlTabSearchBar{
|
|
||||||
width: 68%;
|
|
||||||
margin: 15px;
|
|
||||||
}
|
|
||||||
.documentTabFiltetButton{
|
|
||||||
margin-top: 15px;
|
|
||||||
}
|
|
||||||
.filterSuggestions {
|
|
||||||
z-index: 1;
|
|
||||||
position: absolute;
|
|
||||||
top: 133px;
|
|
||||||
padding: 10px;
|
|
||||||
margin-left: 10px;
|
|
||||||
background: white;
|
|
||||||
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
|
|
||||||
transition: 0.3s;
|
|
||||||
width: 20%;
|
|
||||||
height: auto;
|
|
||||||
}
|
|
||||||
.sqlFilterSuggestions {
|
|
||||||
margin-left: 10%;
|
|
||||||
}
|
|
||||||
.documentTabSuggestions {
|
|
||||||
padding: 5px;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
.documentTabNoFilterView {
|
|
||||||
margin: 15px;
|
|
||||||
}
|
|
||||||
.noFilterText {
|
|
||||||
margin-right: 10px;
|
|
||||||
}
|
|
||||||
.documentTabWatermark{
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
flex-direction: column;
|
|
||||||
margin-top: 10%;
|
|
||||||
margin-right: 12%;
|
|
||||||
}
|
|
||||||
.documentCreateText {
|
|
||||||
margin-top: 10px;
|
|
||||||
}
|
|
||||||
.documentLoadMore {
|
|
||||||
color: #0078D4;
|
|
||||||
font-size: 12px;
|
|
||||||
cursor: pointer;
|
|
||||||
margin-top: 10px;
|
|
||||||
}
|
|
||||||
.leftSplitter {
|
|
||||||
align-items: center;
|
|
||||||
text-align: center;
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
.documentIdItem{
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
.splitterWrapper .splitter-layout .layout-pane.layout-pane-primary{
|
|
||||||
max-height: 60%;
|
|
||||||
}
|
|
||||||
.queryText {
|
|
||||||
padding: 20px;
|
|
||||||
padding-left: 10px;
|
|
||||||
padding-right: 0px;
|
|
||||||
}
|
|
||||||
.spinner {
|
.spinner {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
|||||||
@@ -208,4 +208,4 @@
|
|||||||
}
|
}
|
||||||
.trigger-form {
|
.trigger-form {
|
||||||
padding: 10px 30px 10px 30px;
|
padding: 10px 30px 10px 30px;
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
import { CollectionBase } from "../../Contracts/ViewModels";
|
import { CollectionBase } from "../../Contracts/ViewModels";
|
||||||
import DocumentId from "../../Explorer/Tree/DocumentId";
|
|
||||||
import { logConsoleInfo, logConsoleProgress } from "../../Utils/NotificationConsoleUtils";
|
|
||||||
import { client } from "../CosmosClient";
|
import { client } from "../CosmosClient";
|
||||||
import { getEntityName } from "../DocumentUtility";
|
import { getEntityName } from "../DocumentUtility";
|
||||||
import { handleError } from "../ErrorHandlingUtils";
|
import { handleError } from "../ErrorHandlingUtils";
|
||||||
|
import { logConsoleInfo, logConsoleProgress } from "../../Utils/NotificationConsoleUtils";
|
||||||
|
import DocumentId from "../../Explorer/Tree/DocumentId";
|
||||||
|
|
||||||
export const deleteDocument = async (collection: CollectionBase, documentId: DocumentId): Promise<void> => {
|
export const deleteDocument = async (collection: CollectionBase, documentId: DocumentId): Promise<void> => {
|
||||||
const entityName: string = getEntityName();
|
const entityName: string = getEntityName();
|
||||||
|
|||||||
@@ -88,9 +88,6 @@ export interface SubscriptionPolicies {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface Resource {
|
export interface Resource {
|
||||||
_partitionKeyValue?: string;
|
|
||||||
_partitionKey?: string;
|
|
||||||
_attachments?: string;
|
|
||||||
_rid: string;
|
_rid: string;
|
||||||
_self: string;
|
_self: string;
|
||||||
_etag: string;
|
_etag: string;
|
||||||
|
|||||||
@@ -33,20 +33,16 @@ export class EditorReact extends React.Component<EditorReactProps, EditorReactSt
|
|||||||
this.createEditor(this.configureEditor.bind(this));
|
this.createEditor(this.configureEditor.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
public shouldComponentUpdate(): boolean {
|
public componentDidUpdate(previous: EditorReactProps) {
|
||||||
return true;
|
if (this.props.content !== previous.content) {
|
||||||
|
this.editor.setValue(this.props.content);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public componentWillUnmount(): void {
|
public componentWillUnmount(): void {
|
||||||
this.selectionListener && this.selectionListener.dispose();
|
this.selectionListener && this.selectionListener.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
public componentDidUpdate(prevProps: EditorReactProps): void {
|
|
||||||
if (this.props.content !== prevProps.content) {
|
|
||||||
this.editor.setValue(this.props.content);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public render(): JSX.Element {
|
public render(): JSX.Element {
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ import { SnapshotRequest } from "./NotebookComponent/types";
|
|||||||
import { NotebookContainerClient } from "./NotebookContainerClient";
|
import { NotebookContainerClient } from "./NotebookContainerClient";
|
||||||
import { NotebookContentClient } from "./NotebookContentClient";
|
import { NotebookContentClient } from "./NotebookContentClient";
|
||||||
import { SchemaAnalyzerNotebook } from "./SchemaAnalyzer/SchemaAnalyzerUtils";
|
import { SchemaAnalyzerNotebook } from "./SchemaAnalyzer/SchemaAnalyzerUtils";
|
||||||
import { useNotebook } from "./useNotebook";
|
|
||||||
|
|
||||||
type NotebookPaneContent = string | ImmutableNotebook;
|
type NotebookPaneContent = string | ImmutableNotebook;
|
||||||
|
|
||||||
@@ -111,7 +110,6 @@ export default class NotebookManager {
|
|||||||
this.junoClient.subscribeToPinnedRepos((pinnedRepos) => {
|
this.junoClient.subscribeToPinnedRepos((pinnedRepos) => {
|
||||||
this.params.resourceTree.initializeGitHubRepos(pinnedRepos);
|
this.params.resourceTree.initializeGitHubRepos(pinnedRepos);
|
||||||
this.params.resourceTree.triggerRender();
|
this.params.resourceTree.triggerRender();
|
||||||
useNotebook.getState().initializeGitHubRepos(pinnedRepos);
|
|
||||||
});
|
});
|
||||||
this.refreshPinnedRepos();
|
this.refreshPinnedRepos();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,10 @@ import { getErrorMessage } from "../../Common/ErrorHandlingUtils";
|
|||||||
import * as Logger from "../../Common/Logger";
|
import * as Logger from "../../Common/Logger";
|
||||||
import { configContext } from "../../ConfigContext";
|
import { configContext } from "../../ConfigContext";
|
||||||
import * as DataModels from "../../Contracts/DataModels";
|
import * as DataModels from "../../Contracts/DataModels";
|
||||||
import { IPinnedRepo } from "../../Juno/JunoClient";
|
|
||||||
import { Action, ActionModifiers } from "../../Shared/Telemetry/TelemetryConstants";
|
import { Action, ActionModifiers } from "../../Shared/Telemetry/TelemetryConstants";
|
||||||
import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor";
|
import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor";
|
||||||
import { userContext } from "../../UserContext";
|
import { userContext } from "../../UserContext";
|
||||||
import { getAuthorizationHeader } from "../../Utils/AuthorizationUtils";
|
import { getAuthorizationHeader } from "../../Utils/AuthorizationUtils";
|
||||||
import * as GitHubUtils from "../../Utils/GitHubUtils";
|
|
||||||
import { NotebookContentItem, NotebookContentItemType } from "./NotebookContentItem";
|
import { NotebookContentItem, NotebookContentItemType } from "./NotebookContentItem";
|
||||||
import NotebookManager from "./NotebookManager";
|
import NotebookManager from "./NotebookManager";
|
||||||
|
|
||||||
@@ -41,7 +39,6 @@ interface NotebookState {
|
|||||||
updateNotebookItem: (item: NotebookContentItem) => void;
|
updateNotebookItem: (item: NotebookContentItem) => void;
|
||||||
deleteNotebookItem: (item: NotebookContentItem) => void;
|
deleteNotebookItem: (item: NotebookContentItem) => void;
|
||||||
initializeNotebooksTree: (notebookManager: NotebookManager) => Promise<void>;
|
initializeNotebooksTree: (notebookManager: NotebookManager) => Promise<void>;
|
||||||
initializeGitHubRepos: (pinnedRepos: IPinnedRepo[]) => void;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useNotebook: UseStore<NotebookState> = create((set, get) => ({
|
export const useNotebook: UseStore<NotebookState> = create((set, get) => ({
|
||||||
@@ -205,31 +202,4 @@ export const useNotebook: UseStore<NotebookState> = create((set, get) => ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
initializeGitHubRepos: (pinnedRepos: IPinnedRepo[]): void => {
|
|
||||||
const gitHubNotebooksContentRoot = cloneDeep(get().gitHubNotebooksContentRoot);
|
|
||||||
if (gitHubNotebooksContentRoot) {
|
|
||||||
gitHubNotebooksContentRoot.children = [];
|
|
||||||
pinnedRepos?.forEach((pinnedRepo) => {
|
|
||||||
const repoFullName = GitHubUtils.toRepoFullName(pinnedRepo.owner, pinnedRepo.name);
|
|
||||||
const repoTreeItem: NotebookContentItem = {
|
|
||||||
name: repoFullName,
|
|
||||||
path: "PsuedoDir",
|
|
||||||
type: NotebookContentItemType.Directory,
|
|
||||||
children: [],
|
|
||||||
};
|
|
||||||
|
|
||||||
pinnedRepo.branches.forEach((branch) => {
|
|
||||||
repoTreeItem.children.push({
|
|
||||||
name: branch.name,
|
|
||||||
path: GitHubUtils.toContentUri(pinnedRepo.owner, pinnedRepo.name, branch.name, ""),
|
|
||||||
type: NotebookContentItemType.Directory,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
gitHubNotebooksContentRoot.children.push(repoTreeItem);
|
|
||||||
});
|
|
||||||
|
|
||||||
set({ gitHubNotebooksContentRoot });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import * as Entities from "../../Tables/Entities";
|
|||||||
import { CassandraAPIDataClient, CassandraTableKey, TableDataClient } from "../../Tables/TableDataClient";
|
import { CassandraAPIDataClient, CassandraTableKey, TableDataClient } from "../../Tables/TableDataClient";
|
||||||
import * as TableEntityProcessor from "../../Tables/TableEntityProcessor";
|
import * as TableEntityProcessor from "../../Tables/TableEntityProcessor";
|
||||||
import * as Utilities from "../../Tables/Utilities";
|
import * as Utilities from "../../Tables/Utilities";
|
||||||
import QueryTablesTab from "../../Tabs/QueryTablesTab";
|
import { NewQueryTablesTab } from "../../Tabs/QueryTablesTab/NewQueryTablesTab";
|
||||||
import { RightPaneForm, RightPaneFormProps } from "../RightPaneForm/RightPaneForm";
|
import { RightPaneForm, RightPaneFormProps } from "../RightPaneForm/RightPaneForm";
|
||||||
import {
|
import {
|
||||||
attributeNameLabel,
|
attributeNameLabel,
|
||||||
@@ -36,7 +36,7 @@ import {
|
|||||||
|
|
||||||
interface AddTableEntityPanelProps {
|
interface AddTableEntityPanelProps {
|
||||||
tableDataClient: TableDataClient;
|
tableDataClient: TableDataClient;
|
||||||
queryTablesTab: QueryTablesTab;
|
queryTablesTab: NewQueryTablesTab;
|
||||||
tableEntityListViewModel: TableEntityListViewModel;
|
tableEntityListViewModel: TableEntityListViewModel;
|
||||||
cassandraApiClient: CassandraAPIDataClient;
|
cassandraApiClient: CassandraAPIDataClient;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import TableEntityListViewModel from "../../Tables/DataTable/TableEntityListView
|
|||||||
import * as Entities from "../../Tables/Entities";
|
import * as Entities from "../../Tables/Entities";
|
||||||
import { CassandraAPIDataClient, TableDataClient } from "../../Tables/TableDataClient";
|
import { CassandraAPIDataClient, TableDataClient } from "../../Tables/TableDataClient";
|
||||||
import * as TableEntityProcessor from "../../Tables/TableEntityProcessor";
|
import * as TableEntityProcessor from "../../Tables/TableEntityProcessor";
|
||||||
import QueryTablesTab from "../../Tabs/QueryTablesTab";
|
import { NewQueryTablesTab } from "../../Tabs/QueryTablesTab/NewQueryTablesTab";
|
||||||
import { RightPaneForm, RightPaneFormProps } from "../RightPaneForm/RightPaneForm";
|
import { RightPaneForm, RightPaneFormProps } from "../RightPaneForm/RightPaneForm";
|
||||||
import {
|
import {
|
||||||
attributeNameLabel,
|
attributeNameLabel,
|
||||||
@@ -34,7 +34,7 @@ import {
|
|||||||
|
|
||||||
interface EditTableEntityPanelProps {
|
interface EditTableEntityPanelProps {
|
||||||
tableDataClient: TableDataClient;
|
tableDataClient: TableDataClient;
|
||||||
queryTablesTab: QueryTablesTab;
|
queryTablesTab: NewQueryTablesTab;
|
||||||
tableEntityListViewModel: TableEntityListViewModel;
|
tableEntityListViewModel: TableEntityListViewModel;
|
||||||
cassandraApiClient: CassandraAPIDataClient;
|
cassandraApiClient: CassandraAPIDataClient;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
|
import { ItemDefinition, QueryIterator, Resource } from "@azure/cosmos";
|
||||||
import * as ko from "knockout";
|
import * as ko from "knockout";
|
||||||
import * as _ from "underscore";
|
import * as _ from "underscore";
|
||||||
|
|
||||||
import { Action } from "../../../Shared/Telemetry/TelemetryConstants";
|
|
||||||
import CacheBase from "./CacheBase";
|
|
||||||
import * as CommonConstants from "../../../Common/Constants";
|
import * as CommonConstants from "../../../Common/Constants";
|
||||||
|
import { Action } from "../../../Shared/Telemetry/TelemetryConstants";
|
||||||
|
import * as TelemetryProcessor from "../../../Shared/Telemetry/TelemetryProcessor";
|
||||||
|
import { NewQueryTablesTab } from "../../Tabs/QueryTablesTab/NewQueryTablesTab";
|
||||||
import * as Constants from "../Constants";
|
import * as Constants from "../Constants";
|
||||||
import * as Entities from "../Entities";
|
import * as Entities from "../Entities";
|
||||||
import QueryTablesTab from "../../Tabs/QueryTablesTab";
|
import CacheBase from "./CacheBase";
|
||||||
import * as TelemetryProcessor from "../../../Shared/Telemetry/TelemetryProcessor";
|
|
||||||
import { QueryIterator, ItemDefinition, Resource } from "@azure/cosmos";
|
|
||||||
|
|
||||||
// This is the format of the data we will have to pass to Datatable render callback,
|
// This is the format of the data we will have to pass to Datatable render callback,
|
||||||
// and property names are defined by Datatable as well.
|
// and property names are defined by Datatable as well.
|
||||||
@@ -49,7 +49,7 @@ abstract class DataTableViewModel {
|
|||||||
|
|
||||||
private dataTableOperationManager: IDataTableOperation;
|
private dataTableOperationManager: IDataTableOperation;
|
||||||
|
|
||||||
public queryTablesTab: QueryTablesTab;
|
public queryTablesTab: NewQueryTablesTab;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.items([]);
|
this.items([]);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { Action } from "../../../Shared/Telemetry/TelemetryConstants";
|
|||||||
import * as TelemetryProcessor from "../../../Shared/Telemetry/TelemetryProcessor";
|
import * as TelemetryProcessor from "../../../Shared/Telemetry/TelemetryProcessor";
|
||||||
import { userContext } from "../../../UserContext";
|
import { userContext } from "../../../UserContext";
|
||||||
import QueryTablesTab from "../../Tabs/QueryTablesTab";
|
import QueryTablesTab from "../../Tabs/QueryTablesTab";
|
||||||
|
import { NewQueryTablesTab } from "../../Tabs/QueryTablesTab/NewQueryTablesTab";
|
||||||
import * as Constants from "../Constants";
|
import * as Constants from "../Constants";
|
||||||
import { getQuotedCqlIdentifier } from "../CqlUtilities";
|
import { getQuotedCqlIdentifier } from "../CqlUtilities";
|
||||||
import * as Entities from "../Entities";
|
import * as Entities from "../Entities";
|
||||||
@@ -112,7 +113,7 @@ export default class TableEntityListViewModel extends DataTableViewModel {
|
|||||||
public queryErrorMessage: ko.Observable<string>;
|
public queryErrorMessage: ko.Observable<string>;
|
||||||
public id: string;
|
public id: string;
|
||||||
|
|
||||||
constructor(tableCommands: TableCommands, queryTablesTab: QueryTablesTab) {
|
constructor(tableCommands: TableCommands, queryTablesTab: NewQueryTablesTab) {
|
||||||
super();
|
super();
|
||||||
this.cache = new TableEntityCache();
|
this.cache = new TableEntityCache();
|
||||||
this.queryErrorMessage = ko.observable<string>();
|
this.queryErrorMessage = ko.observable<string>();
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { KeyCodes } from "../../../Common/Constants";
|
|||||||
import { useSidePanel } from "../../../hooks/useSidePanel";
|
import { useSidePanel } from "../../../hooks/useSidePanel";
|
||||||
import { userContext } from "../../../UserContext";
|
import { userContext } from "../../../UserContext";
|
||||||
import { TableQuerySelectPanel } from "../../Panes/Tables/TableQuerySelectPanel/TableQuerySelectPanel";
|
import { TableQuerySelectPanel } from "../../Panes/Tables/TableQuerySelectPanel/TableQuerySelectPanel";
|
||||||
import QueryTablesTab from "../../Tabs/QueryTablesTab";
|
import { NewQueryTablesTab } from "../../Tabs/QueryTablesTab/NewQueryTablesTab";
|
||||||
import { getQuotedCqlIdentifier } from "../CqlUtilities";
|
import { getQuotedCqlIdentifier } from "../CqlUtilities";
|
||||||
import * as DataTableUtilities from "../DataTable/DataTableUtilities";
|
import * as DataTableUtilities from "../DataTable/DataTableUtilities";
|
||||||
import TableEntityListViewModel from "../DataTable/TableEntityListViewModel";
|
import TableEntityListViewModel from "../DataTable/TableEntityListViewModel";
|
||||||
@@ -39,14 +39,14 @@ export default class QueryViewModel {
|
|||||||
|
|
||||||
public columnOptions: ko.ObservableArray<string>;
|
public columnOptions: ko.ObservableArray<string>;
|
||||||
|
|
||||||
public queryTablesTab: QueryTablesTab;
|
public queryTablesTab: NewQueryTablesTab;
|
||||||
public id: string;
|
public id: string;
|
||||||
private _tableEntityListViewModel: TableEntityListViewModel;
|
private _tableEntityListViewModel: TableEntityListViewModel;
|
||||||
|
|
||||||
constructor(queryTablesTab: QueryTablesTab) {
|
constructor(queryTablesTab: NewQueryTablesTab) {
|
||||||
this.queryTablesTab = queryTablesTab;
|
this.queryTablesTab = queryTablesTab;
|
||||||
this.id = `queryViewModel${this.queryTablesTab.tabId}`;
|
this.id = `queryViewModel${this.queryTablesTab.tabId}`;
|
||||||
this._tableEntityListViewModel = queryTablesTab.tableEntityListViewModel();
|
this._tableEntityListViewModel = queryTablesTab.tableEntityListViewModel;
|
||||||
|
|
||||||
this.queryTextIsReadOnly = ko.computed<boolean>(() => {
|
this.queryTextIsReadOnly = ko.computed<boolean>(() => {
|
||||||
return userContext.apiType !== "Cassandra";
|
return userContext.apiType !== "Cassandra";
|
||||||
|
|||||||
@@ -1,145 +0,0 @@
|
|||||||
import { extractPartitionKey, PartitionKeyDefinition } from "@azure/cosmos";
|
|
||||||
import { IColumn, IImageProps, ImageFit } from "@fluentui/react";
|
|
||||||
import { Resource } from "../../../src/Contracts/DataModels";
|
|
||||||
import * as DataModels from "../../Contracts/DataModels";
|
|
||||||
import DocumentId from "../Tree/DocumentId";
|
|
||||||
|
|
||||||
export interface IDocumentsTabContentState {
|
|
||||||
columns: IColumn[];
|
|
||||||
isModalSelection: boolean;
|
|
||||||
isCompactMode: boolean;
|
|
||||||
announcedMessage?: string;
|
|
||||||
isSuggestionVisible: boolean;
|
|
||||||
filter: string;
|
|
||||||
isFilterOptionVisible: boolean;
|
|
||||||
isEditorVisible: boolean;
|
|
||||||
documentContent: string;
|
|
||||||
selectedSqlDocumentContent: string;
|
|
||||||
documentIds: Array<DocumentId>;
|
|
||||||
documentSqlIds: Array<Resource>;
|
|
||||||
selectedDocumentId?: DocumentId;
|
|
||||||
selectedSqlDocumentId?: DocumentId;
|
|
||||||
isEditorContentEdited: boolean;
|
|
||||||
isAllDocumentsVisible: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IDocument {
|
|
||||||
value: string;
|
|
||||||
id: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IButton {
|
|
||||||
visible: boolean;
|
|
||||||
enabled: boolean;
|
|
||||||
isSelected?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const imageProps: Partial<IImageProps> = {
|
|
||||||
imageFit: ImageFit.centerContain,
|
|
||||||
width: 40,
|
|
||||||
height: 40,
|
|
||||||
style: { marginTop: "15px" },
|
|
||||||
};
|
|
||||||
|
|
||||||
export function hasShardKeySpecified(
|
|
||||||
document: string,
|
|
||||||
partitionKey: DataModels.PartitionKey,
|
|
||||||
partitionKeyProperty: string
|
|
||||||
): boolean {
|
|
||||||
return Boolean(
|
|
||||||
extractPartitionKey(
|
|
||||||
document,
|
|
||||||
getPartitionKeyDefinition(partitionKey, partitionKeyProperty) as PartitionKeyDefinition
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getPartitionKeyDefinition(
|
|
||||||
partitionKey: DataModels.PartitionKey,
|
|
||||||
partitionKeyProperty: string
|
|
||||||
): DataModels.PartitionKey {
|
|
||||||
if (partitionKey?.paths?.[0]?.indexOf("$v") > -1) {
|
|
||||||
// Convert BsonSchema2 to /path format
|
|
||||||
partitionKey = {
|
|
||||||
kind: partitionKey.kind,
|
|
||||||
paths: ["/" + partitionKeyProperty.replace(/\./g, "/")],
|
|
||||||
version: partitionKey.version,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return partitionKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function formatDocumentContent(row: DocumentId): string {
|
|
||||||
const { partitionKeyProperty, partitionKeyValue, id } = row;
|
|
||||||
const documentContent = JSON.stringify({
|
|
||||||
_id: id(),
|
|
||||||
[partitionKeyProperty]: partitionKeyValue || "",
|
|
||||||
});
|
|
||||||
const formattedDocumentContent = documentContent.replace(/,/g, ",\n").replace("{", "{\n").replace("}", "\n}");
|
|
||||||
return formattedDocumentContent;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function formatSqlDocumentContent(row: Resource): string {
|
|
||||||
const { id, _rid, _self, _ts, _etag, _partitionKey, _attachments } = row;
|
|
||||||
const documentContent = JSON.stringify({
|
|
||||||
id: id || "",
|
|
||||||
_rid: _rid || "",
|
|
||||||
_self: _self || "",
|
|
||||||
_ts: _ts || "",
|
|
||||||
_etag: _etag || "",
|
|
||||||
_attachments: _attachments || "",
|
|
||||||
_partitionKey: _partitionKey || "",
|
|
||||||
});
|
|
||||||
const formattedDocumentContent = documentContent.replace(/,/g, ",\n").replace("{", "{\n").replace("}", "\n}");
|
|
||||||
return formattedDocumentContent;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getFilterPlaceholder(isPreferredApiMongoDB: boolean): string {
|
|
||||||
const filterPlaceholder = isPreferredApiMongoDB
|
|
||||||
? "Type a query predicate (e.g., {´a´:´foo´}), or choose one from the drop down list, or leave empty to query all documents."
|
|
||||||
: "Type a query predicate (e.g., WHERE c.id=´1´), or choose one from the drop down list, or leave empty to query all documents.";
|
|
||||||
return filterPlaceholder;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getFilterSuggestions(isPreferredApiMongoDB: boolean): { value: string }[] {
|
|
||||||
const filterSuggestions = isPreferredApiMongoDB
|
|
||||||
? [{ value: `{"_id": "foo"}` }, { value: "{ qty: { $gte: 20 } }" }]
|
|
||||||
: [
|
|
||||||
{ value: 'WHERE c.id = "foo"' },
|
|
||||||
{ value: "ORDER BY c._ts DESC" },
|
|
||||||
{ value: 'WHERE c.id = "foo" ORDER BY c._ts DESC' },
|
|
||||||
];
|
|
||||||
return filterSuggestions;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getDocumentItems(
|
|
||||||
isPreferredApiMongoDB: boolean,
|
|
||||||
documentIds: Array<DocumentId>,
|
|
||||||
documentSqlIds: Array<Resource>,
|
|
||||||
isAllDocumentsVisible: boolean
|
|
||||||
): Array<DocumentId> | Array<Resource> {
|
|
||||||
if (isPreferredApiMongoDB) {
|
|
||||||
return isAllDocumentsVisible ? documentIds : documentIds.slice(0, 5);
|
|
||||||
}
|
|
||||||
return isAllDocumentsVisible ? documentSqlIds : documentSqlIds.slice(0, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
export const assignTabButtonVisibility = (
|
|
||||||
visible: boolean,
|
|
||||||
enabled: boolean
|
|
||||||
): { visible: boolean; enabled: boolean } => {
|
|
||||||
return {
|
|
||||||
visible,
|
|
||||||
enabled,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getfilterText = (isPreferredApiMongoDB: boolean, filter: string): string => {
|
|
||||||
if (isPreferredApiMongoDB) {
|
|
||||||
if (filter) {
|
|
||||||
return `Filter : ${filter}`;
|
|
||||||
}
|
|
||||||
return "No filter applied";
|
|
||||||
}
|
|
||||||
return `Select * from C ${filter}`;
|
|
||||||
};
|
|
||||||
221
src/Explorer/Tabs/DocumentsTab.html
Normal file
221
src/Explorer/Tabs/DocumentsTab.html
Normal file
@@ -0,0 +1,221 @@
|
|||||||
|
<div
|
||||||
|
class="tab-pane active tabdocuments flexContainer"
|
||||||
|
data-bind="
|
||||||
|
setTemplateReady: true,
|
||||||
|
attr:{
|
||||||
|
id: tabId
|
||||||
|
},
|
||||||
|
visible: isActive"
|
||||||
|
role="tabpanel"
|
||||||
|
>
|
||||||
|
<!-- ko if: false -->
|
||||||
|
<!-- Messagebox Ok Cancel- Start -->
|
||||||
|
<div class="messagebox-background">
|
||||||
|
<div class="messagebox">
|
||||||
|
<h2 class="messagebox-title">Title</h2>
|
||||||
|
<div class="messagebox-text" tabindex="0">Text</div>
|
||||||
|
<div class="messagebox-buttons">
|
||||||
|
<div class="messagebox-buttons-container">
|
||||||
|
<button value="ok" class="messagebox-button-primary">Ok</button>
|
||||||
|
<button value="cancel" class="messagebox-button-default">Cancel</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- Messagebox OK Cancel - End -->
|
||||||
|
<!-- /ko -->
|
||||||
|
|
||||||
|
<!-- Filter - Start -->
|
||||||
|
<div class="filterdivs" data-bind="visible: isFilterCreated">
|
||||||
|
<!-- Read-only Filter - Start -->
|
||||||
|
<div class="filterDocCollapsed" data-bind="visible: !isFilterExpanded() && !isPreferredApiMongoDB">
|
||||||
|
<span class="selectQuery">SELECT * FROM c</span>
|
||||||
|
<span class="appliedQuery" data-bind="text: appliedFilter"></span>
|
||||||
|
<button class="filterbtnstyle queryButton" data-bind="click: onShowFilterClick">Edit Filter</button>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="filterDocCollapsed"
|
||||||
|
data-bind="
|
||||||
|
visible: !isFilterExpanded() && isPreferredApiMongoDB"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
class="selectQuery"
|
||||||
|
data-bind="
|
||||||
|
visible: appliedFilter().length > 0"
|
||||||
|
>Filter :
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
class="noFilterApplied"
|
||||||
|
data-bind="
|
||||||
|
visible: !appliedFilter().length > 0"
|
||||||
|
>No filter applied</span
|
||||||
|
>
|
||||||
|
<span class="appliedQuery" data-bind="text: appliedFilter"></span>
|
||||||
|
<button
|
||||||
|
class="filterbtnstyle queryButton"
|
||||||
|
data-bind="
|
||||||
|
click: onShowFilterClick"
|
||||||
|
>
|
||||||
|
Edit Filter
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<!-- Read-only Filter - End -->
|
||||||
|
|
||||||
|
<!-- Editable Filter - start -->
|
||||||
|
<div
|
||||||
|
class="filterDocExpanded"
|
||||||
|
data-bind="
|
||||||
|
visible: isFilterExpanded"
|
||||||
|
>
|
||||||
|
<div>
|
||||||
|
<div class="editFilterContainer">
|
||||||
|
<span class="filterspan" data-bind="visible: !isPreferredApiMongoDB"> SELECT * FROM c </span>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
list="filtersList"
|
||||||
|
class="querydropdown"
|
||||||
|
title="Type a query predicate or choose one from the list."
|
||||||
|
data-bind="
|
||||||
|
attr:{
|
||||||
|
placeholder:isPreferredApiMongoDB?'Type a query predicate (e.g., {´a´:´foo´}), or choose one from the drop down list, or leave empty to query all documents.':'Type a query predicate (e.g., WHERE c.id=´1´), or choose one from the drop down list, or leave empty to query all documents.'
|
||||||
|
},
|
||||||
|
css: { placeholderVisible: filterContent().length === 0 },
|
||||||
|
textInput: filterContent"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<datalist
|
||||||
|
id="filtersList"
|
||||||
|
data-bind="
|
||||||
|
foreach: lastFilterContents"
|
||||||
|
>
|
||||||
|
<option
|
||||||
|
data-bind="
|
||||||
|
value: $data"
|
||||||
|
></option>
|
||||||
|
</datalist>
|
||||||
|
|
||||||
|
<span class="filterbuttonpad">
|
||||||
|
<button
|
||||||
|
class="filterbtnstyle queryButton"
|
||||||
|
data-bind="
|
||||||
|
click: refreshDocumentsGrid,
|
||||||
|
enable: applyFilterButton.enabled"
|
||||||
|
aria-label="Apply filter"
|
||||||
|
tabindex="0"
|
||||||
|
>
|
||||||
|
Apply Filter
|
||||||
|
</button>
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
class="filterclose"
|
||||||
|
role="button"
|
||||||
|
aria-label="close filter"
|
||||||
|
tabindex="0"
|
||||||
|
data-bind="
|
||||||
|
click: onHideFilterClick, event: { keydown: onCloseButtonKeyDown }"
|
||||||
|
>
|
||||||
|
<img src="/close-black.svg" style="height: 14px; width: 14px" alt="Hide filter" />
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- Editable Filter - End -->
|
||||||
|
</div>
|
||||||
|
<!-- Filter - End -->
|
||||||
|
|
||||||
|
<!-- Ids and Editor - Start -->
|
||||||
|
<div class="documentsTabGridAndEditor">
|
||||||
|
<div class="documentsContainerWithSplitter" , data-bind="attr: { id: documentContentsContainerId }">
|
||||||
|
<div class="flexContainer">
|
||||||
|
<!-- Document Ids - Start -->
|
||||||
|
<div
|
||||||
|
class="documentsGridHeaderContainer tabdocuments scrollable"
|
||||||
|
data-bind="
|
||||||
|
attr: {
|
||||||
|
id: documentContentsGridId,
|
||||||
|
tabindex: documentIds().length <= 0 ? -1 : 0
|
||||||
|
},
|
||||||
|
style: { height: dataContentsGridScrollHeight },
|
||||||
|
event: { keydown: accessibleDocumentList.onKeyDown }"
|
||||||
|
>
|
||||||
|
<table id="tabsTable" class="table table-hover can-select dataTable">
|
||||||
|
<thead id="theadcontent">
|
||||||
|
<tr>
|
||||||
|
<th class="documentsGridHeader" data-bind="text: idHeader" tabindex="0"></th>
|
||||||
|
<!-- ko if: showPartitionKey -->
|
||||||
|
<th
|
||||||
|
class="documentsGridHeader documentsGridPartition evenlySpacedHeader"
|
||||||
|
data-bind="
|
||||||
|
attr: {
|
||||||
|
title: partitionKeyPropertyHeader
|
||||||
|
},
|
||||||
|
text: partitionKeyPropertyHeader"
|
||||||
|
tabindex="0"
|
||||||
|
></th>
|
||||||
|
<!-- /ko -->
|
||||||
|
<th
|
||||||
|
class="refreshColHeader"
|
||||||
|
role="button"
|
||||||
|
aria-label="Refresh documents"
|
||||||
|
data-bind="event: { keydown: onRefreshButtonKeyDown }"
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
class="refreshcol"
|
||||||
|
src="/refresh-cosmos.svg"
|
||||||
|
data-bind="click: refreshDocumentsGrid"
|
||||||
|
alt="Refresh documents"
|
||||||
|
tabindex="0"
|
||||||
|
/>
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="tbodycontent">
|
||||||
|
<!-- ko foreach: documentIds -->
|
||||||
|
<tr
|
||||||
|
class="pointer accessibleListElement"
|
||||||
|
data-bind="
|
||||||
|
click: $data.click,
|
||||||
|
css: {
|
||||||
|
gridRowSelected: $parent.selectedDocumentId && $parent.selectedDocumentId() && $parent.selectedDocumentId().rid === $data.rid,
|
||||||
|
gridRowHighlighted: $parent.accessibleDocumentList.currentItem() && $parent.accessibleDocumentList.currentItem().rid === $data.rid
|
||||||
|
}"
|
||||||
|
tabindex="0"
|
||||||
|
>
|
||||||
|
<td class="tabdocumentsGridElement"><a data-bind="text: $data.id, attr: { title: $data.id }"></a></td>
|
||||||
|
<!-- ko if: $data.partitionKeyProperty -->
|
||||||
|
<td class="tabdocumentsGridElement" colspan="2">
|
||||||
|
<a
|
||||||
|
data-bind="text: $data.stringPartitionKeyValue, attr: { title: $data.stringPartitionKeyValue }"
|
||||||
|
></a>
|
||||||
|
</td>
|
||||||
|
<!-- /ko -->
|
||||||
|
</tr>
|
||||||
|
<!-- /ko -->
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<div class="loadMore">
|
||||||
|
<a role="button" data-bind="click: loadNextPage, event: { keypress: onLoadMoreKeyInput }" tabindex="0"
|
||||||
|
>Load more</a
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
<!-- Document Ids - End -->
|
||||||
|
<!-- Splitter -->
|
||||||
|
</div>
|
||||||
|
<div class="splitter ui-resizable-handle ui-resizable-e colResizePointer" id="h_splitter2"></div>
|
||||||
|
</div>
|
||||||
|
<div class="documentWaterMark" data-bind="visible: !shouldShowEditor()">
|
||||||
|
<p><img src="/DocumentWaterMark.svg" alt="Document WaterMark" /></p>
|
||||||
|
<p class="documentWaterMarkText">Create new or work with existing document(s).</p>
|
||||||
|
</div>
|
||||||
|
<!-- Editor - Start -->
|
||||||
|
<json-editor
|
||||||
|
class="editorDivContent"
|
||||||
|
data-bind="visible: shouldShowEditor, css: { mongoDocumentEditor: isPreferredApiMongoDB }"
|
||||||
|
params="{content: initialDocumentContent, isReadOnly: false,lineNumbers: 'on',ariaLabel: 'Document editor',
|
||||||
|
updatedContent: selectedDocumentContent}"
|
||||||
|
></json-editor>
|
||||||
|
<!-- Editor - End -->
|
||||||
|
</div>
|
||||||
|
<!-- Ids and Editor - End -->
|
||||||
|
</div>
|
||||||
152
src/Explorer/Tabs/DocumentsTab.test.ts
Normal file
152
src/Explorer/Tabs/DocumentsTab.test.ts
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
import * as ko from "knockout";
|
||||||
|
import { DatabaseAccount } from "../../Contracts/DataModels";
|
||||||
|
import * as ViewModels from "../../Contracts/ViewModels";
|
||||||
|
import { updateUserContext } from "../../UserContext";
|
||||||
|
import Explorer from "../Explorer";
|
||||||
|
import DocumentId from "../Tree/DocumentId";
|
||||||
|
import DocumentsTab from "./DocumentsTab";
|
||||||
|
|
||||||
|
describe("Documents tab", () => {
|
||||||
|
describe("buildQuery", () => {
|
||||||
|
it("should generate the right select query for SQL API", () => {
|
||||||
|
const documentsTab = new DocumentsTab({
|
||||||
|
partitionKey: null,
|
||||||
|
documentIds: ko.observableArray<DocumentId>(),
|
||||||
|
tabKind: ViewModels.CollectionTabKind.Documents,
|
||||||
|
title: "",
|
||||||
|
tabPath: "",
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(documentsTab.buildQuery("")).toContain("select");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("showPartitionKey", () => {
|
||||||
|
const explorer = new Explorer();
|
||||||
|
const mongoExplorer = new Explorer();
|
||||||
|
updateUserContext({
|
||||||
|
databaseAccount: {
|
||||||
|
properties: {
|
||||||
|
capabilities: [{ name: "EnableGremlin" }],
|
||||||
|
},
|
||||||
|
} as DatabaseAccount,
|
||||||
|
});
|
||||||
|
|
||||||
|
const collectionWithoutPartitionKey = <ViewModels.Collection>(<unknown>{
|
||||||
|
id: ko.observable<string>("foo"),
|
||||||
|
database: {
|
||||||
|
id: ko.observable<string>("foo"),
|
||||||
|
},
|
||||||
|
container: explorer,
|
||||||
|
});
|
||||||
|
|
||||||
|
const collectionWithSystemPartitionKey = <ViewModels.Collection>(<unknown>{
|
||||||
|
id: ko.observable<string>("foo"),
|
||||||
|
database: {
|
||||||
|
id: ko.observable<string>("foo"),
|
||||||
|
},
|
||||||
|
partitionKey: {
|
||||||
|
paths: ["/foo"],
|
||||||
|
kind: "Hash",
|
||||||
|
version: 2,
|
||||||
|
systemKey: true,
|
||||||
|
},
|
||||||
|
container: explorer,
|
||||||
|
});
|
||||||
|
|
||||||
|
const collectionWithNonSystemPartitionKey = <ViewModels.Collection>(<unknown>{
|
||||||
|
id: ko.observable<string>("foo"),
|
||||||
|
database: {
|
||||||
|
id: ko.observable<string>("foo"),
|
||||||
|
},
|
||||||
|
partitionKey: {
|
||||||
|
paths: ["/foo"],
|
||||||
|
kind: "Hash",
|
||||||
|
version: 2,
|
||||||
|
systemKey: false,
|
||||||
|
},
|
||||||
|
container: explorer,
|
||||||
|
});
|
||||||
|
|
||||||
|
const mongoCollectionWithSystemPartitionKey = <ViewModels.Collection>(<unknown>{
|
||||||
|
id: ko.observable<string>("foo"),
|
||||||
|
database: {
|
||||||
|
id: ko.observable<string>("foo"),
|
||||||
|
},
|
||||||
|
partitionKey: {
|
||||||
|
paths: ["/foo"],
|
||||||
|
kind: "Hash",
|
||||||
|
version: 2,
|
||||||
|
systemKey: true,
|
||||||
|
},
|
||||||
|
container: mongoExplorer,
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should be false for null or undefined collection", () => {
|
||||||
|
const documentsTab = new DocumentsTab({
|
||||||
|
partitionKey: null,
|
||||||
|
documentIds: ko.observableArray<DocumentId>(),
|
||||||
|
tabKind: ViewModels.CollectionTabKind.Documents,
|
||||||
|
title: "",
|
||||||
|
tabPath: "",
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(documentsTab.showPartitionKey).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should be false for null or undefined partitionKey", () => {
|
||||||
|
const documentsTab = new DocumentsTab({
|
||||||
|
collection: collectionWithoutPartitionKey,
|
||||||
|
partitionKey: null,
|
||||||
|
documentIds: ko.observableArray<DocumentId>(),
|
||||||
|
tabKind: ViewModels.CollectionTabKind.Documents,
|
||||||
|
title: "",
|
||||||
|
tabPath: "",
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(documentsTab.showPartitionKey).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should be true for non-Mongo accounts with system partitionKey", () => {
|
||||||
|
const documentsTab = new DocumentsTab({
|
||||||
|
collection: collectionWithSystemPartitionKey,
|
||||||
|
partitionKey: null,
|
||||||
|
documentIds: ko.observableArray<DocumentId>(),
|
||||||
|
tabKind: ViewModels.CollectionTabKind.Documents,
|
||||||
|
title: "",
|
||||||
|
tabPath: "",
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(documentsTab.showPartitionKey).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should be false for Mongo accounts with system partitionKey", () => {
|
||||||
|
updateUserContext({
|
||||||
|
apiType: "Mongo",
|
||||||
|
});
|
||||||
|
const documentsTab = new DocumentsTab({
|
||||||
|
collection: mongoCollectionWithSystemPartitionKey,
|
||||||
|
partitionKey: null,
|
||||||
|
documentIds: ko.observableArray<DocumentId>(),
|
||||||
|
tabKind: ViewModels.CollectionTabKind.Documents,
|
||||||
|
title: "",
|
||||||
|
tabPath: "",
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(documentsTab.showPartitionKey).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should be true for non-system partitionKey", () => {
|
||||||
|
const documentsTab = new DocumentsTab({
|
||||||
|
collection: collectionWithNonSystemPartitionKey,
|
||||||
|
partitionKey: null,
|
||||||
|
documentIds: ko.observableArray<DocumentId>(),
|
||||||
|
tabKind: ViewModels.CollectionTabKind.Documents,
|
||||||
|
title: "",
|
||||||
|
tabPath: "",
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(documentsTab.showPartitionKey).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
924
src/Explorer/Tabs/DocumentsTab.ts
Normal file
924
src/Explorer/Tabs/DocumentsTab.ts
Normal file
@@ -0,0 +1,924 @@
|
|||||||
|
import { extractPartitionKey, ItemDefinition, PartitionKeyDefinition, QueryIterator, Resource } from "@azure/cosmos";
|
||||||
|
import * as ko from "knockout";
|
||||||
|
import Q from "q";
|
||||||
|
import DeleteDocumentIcon from "../../../images/DeleteDocument.svg";
|
||||||
|
import DiscardIcon from "../../../images/discard.svg";
|
||||||
|
import NewDocumentIcon from "../../../images/NewDocument.svg";
|
||||||
|
import SaveIcon from "../../../images/save-cosmos.svg";
|
||||||
|
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 { useSelectedNode } from "../useSelectedNode";
|
||||||
|
import template from "./DocumentsTab.html";
|
||||||
|
import TabsBase from "./TabsBase";
|
||||||
|
|
||||||
|
export default class DocumentsTab extends TabsBase {
|
||||||
|
public readonly html = template;
|
||||||
|
public selectedDocumentId: ko.Observable<DocumentId>;
|
||||||
|
public selectedDocumentContent: ViewModels.Editable<string>;
|
||||||
|
public initialDocumentContent: ko.Observable<string>;
|
||||||
|
public documentContentsGridId: string;
|
||||||
|
public documentContentsContainerId: string;
|
||||||
|
public filterContent: ko.Observable<string>;
|
||||||
|
public appliedFilter: ko.Observable<string>;
|
||||||
|
public lastFilterContents: ko.ObservableArray<string>;
|
||||||
|
public isFilterExpanded: ko.Observable<boolean>;
|
||||||
|
public isFilterCreated: ko.Observable<boolean>;
|
||||||
|
public applyFilterButton: ViewModels.Button;
|
||||||
|
public isEditorDirty: ko.Computed<boolean>;
|
||||||
|
public editorState: ko.Observable<ViewModels.DocumentExplorerState>;
|
||||||
|
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<string>;
|
||||||
|
public accessibleDocumentList: AccessibleVerticalList;
|
||||||
|
public dataContentsGridScrollHeight: ko.Observable<string>;
|
||||||
|
public isPreferredApiMongoDB: boolean;
|
||||||
|
public shouldShowEditor: ko.Computed<boolean>;
|
||||||
|
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<DocumentId>;
|
||||||
|
|
||||||
|
private _documentsIterator: QueryIterator<ItemDefinition & Resource>;
|
||||||
|
private _resourceTokenPartitionKey: string;
|
||||||
|
|
||||||
|
constructor(options: ViewModels.DocumentsTabOptions) {
|
||||||
|
super(options);
|
||||||
|
this.isPreferredApiMongoDB = userContext.apiType === "Mongo" || options.isPreferredApiMongoDB;
|
||||||
|
|
||||||
|
this.idHeader = this.isPreferredApiMongoDB ? "_id" : "id";
|
||||||
|
|
||||||
|
this.documentContentsGridId = `documentContentsGrid${this.tabId}`;
|
||||||
|
this.documentContentsContainerId = `documentContentsContainer${this.tabId}`;
|
||||||
|
this.editorState = ko.observable<ViewModels.DocumentExplorerState>(
|
||||||
|
ViewModels.DocumentExplorerState.noDocumentSelected
|
||||||
|
);
|
||||||
|
this.selectedDocumentId = ko.observable<DocumentId>();
|
||||||
|
this.selectedDocumentContent = editable.observable<string>("");
|
||||||
|
this.initialDocumentContent = ko.observable<string>("");
|
||||||
|
this.partitionKey = options.partitionKey || (this.collection && this.collection.partitionKey);
|
||||||
|
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;
|
||||||
|
|
||||||
|
this.isFilterExpanded = ko.observable<boolean>(false);
|
||||||
|
this.isFilterCreated = ko.observable<boolean>(true);
|
||||||
|
this.filterContent = ko.observable<string>("");
|
||||||
|
this.appliedFilter = ko.observable<string>("");
|
||||||
|
this.displayedError = ko.observable<string>("");
|
||||||
|
this.lastFilterContents = ko.observableArray<string>([
|
||||||
|
'WHERE c.id = "foo"',
|
||||||
|
"ORDER BY c._ts DESC",
|
||||||
|
'WHERE c.id = "foo" ORDER BY c._ts DESC',
|
||||||
|
]);
|
||||||
|
|
||||||
|
this.dataContentsGridScrollHeight = ko.observable<string>(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,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
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<boolean>(() => {
|
||||||
|
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.exisitingDocumentDirtyValid:
|
||||||
|
return (
|
||||||
|
this.selectedDocumentContent.getEditableOriginalValue() !==
|
||||||
|
this.selectedDocumentContent.getEditableCurrentValue()
|
||||||
|
);
|
||||||
|
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.newDocumentButton = {
|
||||||
|
enabled: ko.computed<boolean>(() => {
|
||||||
|
switch (this.editorState()) {
|
||||||
|
case ViewModels.DocumentExplorerState.noDocumentSelected:
|
||||||
|
case ViewModels.DocumentExplorerState.exisitingDocumentNoEdits:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}),
|
||||||
|
|
||||||
|
visible: ko.computed<boolean>(() => {
|
||||||
|
return true;
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
|
||||||
|
this.saveNewDocumentButton = {
|
||||||
|
enabled: ko.computed<boolean>(() => {
|
||||||
|
switch (this.editorState()) {
|
||||||
|
case ViewModels.DocumentExplorerState.newDocumentValid:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}),
|
||||||
|
|
||||||
|
visible: ko.computed<boolean>(() => {
|
||||||
|
switch (this.editorState()) {
|
||||||
|
case ViewModels.DocumentExplorerState.newDocumentValid:
|
||||||
|
case ViewModels.DocumentExplorerState.newDocumentInvalid:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
|
||||||
|
this.discardNewDocumentChangesButton = {
|
||||||
|
enabled: ko.computed<boolean>(() => {
|
||||||
|
switch (this.editorState()) {
|
||||||
|
case ViewModels.DocumentExplorerState.newDocumentValid:
|
||||||
|
case ViewModels.DocumentExplorerState.newDocumentInvalid:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}),
|
||||||
|
|
||||||
|
visible: ko.computed<boolean>(() => {
|
||||||
|
switch (this.editorState()) {
|
||||||
|
case ViewModels.DocumentExplorerState.newDocumentValid:
|
||||||
|
case ViewModels.DocumentExplorerState.newDocumentInvalid:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
|
||||||
|
this.saveExisitingDocumentButton = {
|
||||||
|
enabled: ko.computed<boolean>(() => {
|
||||||
|
switch (this.editorState()) {
|
||||||
|
case ViewModels.DocumentExplorerState.exisitingDocumentDirtyValid:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}),
|
||||||
|
|
||||||
|
visible: ko.computed<boolean>(() => {
|
||||||
|
switch (this.editorState()) {
|
||||||
|
case ViewModels.DocumentExplorerState.exisitingDocumentNoEdits:
|
||||||
|
case ViewModels.DocumentExplorerState.exisitingDocumentDirtyInvalid:
|
||||||
|
case ViewModels.DocumentExplorerState.exisitingDocumentDirtyValid:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
|
||||||
|
this.discardExisitingDocumentChangesButton = {
|
||||||
|
enabled: ko.computed<boolean>(() => {
|
||||||
|
switch (this.editorState()) {
|
||||||
|
case ViewModels.DocumentExplorerState.exisitingDocumentDirtyInvalid:
|
||||||
|
case ViewModels.DocumentExplorerState.exisitingDocumentDirtyValid:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}),
|
||||||
|
|
||||||
|
visible: ko.computed<boolean>(() => {
|
||||||
|
switch (this.editorState()) {
|
||||||
|
case ViewModels.DocumentExplorerState.exisitingDocumentNoEdits:
|
||||||
|
case ViewModels.DocumentExplorerState.exisitingDocumentDirtyInvalid:
|
||||||
|
case ViewModels.DocumentExplorerState.exisitingDocumentDirtyValid:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
|
||||||
|
this.deleteExisitingDocumentButton = {
|
||||||
|
enabled: ko.computed<boolean>(() => {
|
||||||
|
switch (this.editorState()) {
|
||||||
|
case ViewModels.DocumentExplorerState.exisitingDocumentNoEdits:
|
||||||
|
case ViewModels.DocumentExplorerState.exisitingDocumentDirtyInvalid:
|
||||||
|
case ViewModels.DocumentExplorerState.exisitingDocumentDirtyValid:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}),
|
||||||
|
|
||||||
|
visible: ko.computed<boolean>(() => {
|
||||||
|
switch (this.editorState()) {
|
||||||
|
case ViewModels.DocumentExplorerState.exisitingDocumentNoEdits:
|
||||||
|
case ViewModels.DocumentExplorerState.exisitingDocumentDirtyInvalid:
|
||||||
|
case ViewModels.DocumentExplorerState.exisitingDocumentDirtyValid:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
|
||||||
|
this.applyFilterButton = {
|
||||||
|
enabled: ko.computed<boolean>(() => {
|
||||||
|
return true;
|
||||||
|
}),
|
||||||
|
|
||||||
|
visible: ko.computed<boolean>(() => {
|
||||||
|
return true;
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
this.buildCommandBarOptions();
|
||||||
|
this.shouldShowEditor = ko.computed<boolean>(() => {
|
||||||
|
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));
|
||||||
|
|
||||||
|
this.showPartitionKey = this._shouldShowPartitionKey();
|
||||||
|
}
|
||||||
|
|
||||||
|
private _shouldShowPartitionKey(): boolean {
|
||||||
|
if (!this.collection) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.collection.partitionKey) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.collection.partitionKey.systemKey && this.isPreferredApiMongoDB) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public onShowFilterClick(): Q.Promise<any> {
|
||||||
|
this.isFilterCreated(true);
|
||||||
|
this.isFilterExpanded(true);
|
||||||
|
|
||||||
|
$(".filterDocExpanded").addClass("active");
|
||||||
|
$("#content").addClass("active");
|
||||||
|
$(".querydropdown").focus();
|
||||||
|
|
||||||
|
return Q();
|
||||||
|
}
|
||||||
|
|
||||||
|
public onHideFilterClick(): Q.Promise<any> {
|
||||||
|
this.isFilterExpanded(false);
|
||||||
|
|
||||||
|
$(".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 async refreshDocumentsGrid(): Promise<void> {
|
||||||
|
// 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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<any> {
|
||||||
|
if (this.editorState() !== ViewModels.DocumentExplorerState.noDocumentSelected) {
|
||||||
|
return Q();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.editorState(ViewModels.DocumentExplorerState.exisitingDocumentNoEdits);
|
||||||
|
|
||||||
|
return Q();
|
||||||
|
}
|
||||||
|
|
||||||
|
public onNewDocumentClick = (): Q.Promise<any> => {
|
||||||
|
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);
|
||||||
|
|
||||||
|
return Q();
|
||||||
|
};
|
||||||
|
|
||||||
|
public onSaveNewDocumentClick = (): Promise<any> => {
|
||||||
|
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];
|
||||||
|
let id = new DocumentId(this, savedDocument, partitionKeyValue);
|
||||||
|
let 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));
|
||||||
|
};
|
||||||
|
|
||||||
|
public onRevertNewDocumentClick = (): Q.Promise<any> => {
|
||||||
|
this.initialDocumentContent("");
|
||||||
|
this.selectedDocumentContent("");
|
||||||
|
this.editorState(ViewModels.DocumentExplorerState.noDocumentSelected);
|
||||||
|
|
||||||
|
return Q();
|
||||||
|
};
|
||||||
|
|
||||||
|
public onSaveExisitingDocumentClick = (): Promise<any> => {
|
||||||
|
const selectedDocumentId = this.selectedDocumentId();
|
||||||
|
const documentContent = JSON.parse(this.selectedDocumentContent());
|
||||||
|
|
||||||
|
const partitionKeyValueArray = extractPartitionKey(documentContent, this.partitionKey as PartitionKeyDefinition);
|
||||||
|
const partitionKeyValue = partitionKeyValueArray && partitionKeyValueArray[0];
|
||||||
|
|
||||||
|
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));
|
||||||
|
};
|
||||||
|
|
||||||
|
public onRevertExisitingDocumentClick = (): Q.Promise<any> => {
|
||||||
|
this.selectedDocumentContent.setBaseline(this.initialDocumentContent());
|
||||||
|
this.initialDocumentContent.valueHasMutated();
|
||||||
|
this.editorState(ViewModels.DocumentExplorerState.exisitingDocumentNoEdits);
|
||||||
|
|
||||||
|
return Q();
|
||||||
|
};
|
||||||
|
|
||||||
|
public onDeleteExisitingDocumentClick = async (): Promise<void> => {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public onValidDocumentEdit(): Q.Promise<any> {
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
public onInvalidDocumentEdit(): Q.Promise<any> {
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Q();
|
||||||
|
}
|
||||||
|
|
||||||
|
public onTabClick(): void {
|
||||||
|
super.onTabClick();
|
||||||
|
this.collection && this.collection.selectedSubnodeKind(ViewModels.CollectionTabKind.Documents);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async onActivate(): Promise<void> {
|
||||||
|
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(),
|
||||||
|
|
||||||
|
dataExplorerArea: Constants.Areas.Tab,
|
||||||
|
tabTitle: this.tabTitle(),
|
||||||
|
error: getErrorMessage(error),
|
||||||
|
errorStack: getErrorStack(error),
|
||||||
|
},
|
||||||
|
this.onLoadStartKey
|
||||||
|
);
|
||||||
|
this.onLoadStartKey = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private _isIgnoreDirtyEditor = (): boolean => {
|
||||||
|
var msg: string = "Changes will be lost. Do you want to continue?";
|
||||||
|
return window.confirm(msg);
|
||||||
|
};
|
||||||
|
|
||||||
|
protected __deleteDocument(documentId: DocumentId): Promise<void> {
|
||||||
|
return deleteDocument(this.collection, documentId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private _deleteDocument(selectedDocumentId: DocumentId): Promise<void> {
|
||||||
|
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<ItemDefinition & Resource> {
|
||||||
|
let filters = this.lastFilterContents();
|
||||||
|
const filter: string = this.filterContent().trim();
|
||||||
|
const query: string = this.buildQuery(filter);
|
||||||
|
let options: any = {};
|
||||||
|
options.enableCrossPartitionQuery = HeadersUtility.shouldEnableCrossPartitionKey();
|
||||||
|
|
||||||
|
if (this._resourceTokenPartitionKey) {
|
||||||
|
options.partitionKey = this._resourceTokenPartitionKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
return queryDocuments(this.collection.databaseId, this.collection.id(), query, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async selectDocument(documentId: DocumentId): Promise<void> {
|
||||||
|
this.selectedDocumentId(documentId);
|
||||||
|
const content = await readDocument(this.collection, documentId);
|
||||||
|
this.initDocumentEditor(documentId, content);
|
||||||
|
}
|
||||||
|
|
||||||
|
public loadNextPage(): Q.Promise<any> {
|
||||||
|
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(),
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
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<DataModels.DocumentId[]> {
|
||||||
|
return Q(this._documentsIterator.fetchNext().then((response) => response.resources));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected _onEditorContentChange(newContent: string) {
|
||||||
|
try {
|
||||||
|
let parsed: any = JSON.parse(newContent);
|
||||||
|
this.onValidDocumentEdit();
|
||||||
|
} catch (e) {
|
||||||
|
this.onInvalidDocumentEdit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public initDocumentEditor(documentId: DocumentId, documentContent: any): Q.Promise<any> {
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
public buildQuery(filter: string): string {
|
||||||
|
return QueryUtils.buildDocumentsQuery(filter, this.partitionKeyProperty, this.partitionKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected getTabsButtons(): CommandButtonComponentProps[] {
|
||||||
|
const buttons: CommandButtonComponentProps[] = [];
|
||||||
|
const label = !this.isPreferredApiMongoDB ? "New Item" : "New Document";
|
||||||
|
if (this.newDocumentButton.visible()) {
|
||||||
|
buttons.push({
|
||||||
|
iconSrc: NewDocumentIcon,
|
||||||
|
iconAlt: label,
|
||||||
|
onCommandClick: this.onNewDocumentClick,
|
||||||
|
commandButtonLabel: label,
|
||||||
|
ariaLabel: label,
|
||||||
|
hasPopup: false,
|
||||||
|
disabled: !this.newDocumentButton.enabled(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.saveNewDocumentButton.visible()) {
|
||||||
|
const label = "Save";
|
||||||
|
buttons.push({
|
||||||
|
iconSrc: SaveIcon,
|
||||||
|
iconAlt: label,
|
||||||
|
onCommandClick: this.onSaveNewDocumentClick,
|
||||||
|
commandButtonLabel: label,
|
||||||
|
ariaLabel: label,
|
||||||
|
hasPopup: false,
|
||||||
|
disabled: !this.saveNewDocumentButton.enabled(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.discardNewDocumentChangesButton.visible()) {
|
||||||
|
const label = "Discard";
|
||||||
|
buttons.push({
|
||||||
|
iconSrc: DiscardIcon,
|
||||||
|
iconAlt: label,
|
||||||
|
onCommandClick: this.onRevertNewDocumentClick,
|
||||||
|
commandButtonLabel: label,
|
||||||
|
ariaLabel: label,
|
||||||
|
hasPopup: false,
|
||||||
|
disabled: !this.discardNewDocumentChangesButton.enabled(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.saveExisitingDocumentButton.visible()) {
|
||||||
|
const label = "Update";
|
||||||
|
buttons.push({
|
||||||
|
iconSrc: SaveIcon,
|
||||||
|
iconAlt: label,
|
||||||
|
onCommandClick: this.onSaveExisitingDocumentClick,
|
||||||
|
commandButtonLabel: label,
|
||||||
|
ariaLabel: label,
|
||||||
|
hasPopup: false,
|
||||||
|
disabled: !this.saveExisitingDocumentButton.enabled(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.discardExisitingDocumentChangesButton.visible()) {
|
||||||
|
const label = "Discard";
|
||||||
|
buttons.push({
|
||||||
|
iconSrc: DiscardIcon,
|
||||||
|
iconAlt: label,
|
||||||
|
onCommandClick: this.onRevertExisitingDocumentClick,
|
||||||
|
commandButtonLabel: label,
|
||||||
|
ariaLabel: label,
|
||||||
|
hasPopup: false,
|
||||||
|
disabled: !this.discardExisitingDocumentChangesButton.enabled(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.deleteExisitingDocumentButton.visible()) {
|
||||||
|
const label = "Delete";
|
||||||
|
buttons.push({
|
||||||
|
iconSrc: DeleteDocumentIcon,
|
||||||
|
iconAlt: label,
|
||||||
|
onCommandClick: this.onDeleteExisitingDocumentClick,
|
||||||
|
commandButtonLabel: label,
|
||||||
|
ariaLabel: label,
|
||||||
|
hasPopup: false,
|
||||||
|
disabled: !this.deleteExisitingDocumentButton.enabled(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.isPreferredApiMongoDB) {
|
||||||
|
buttons.push(DocumentsTab._createUploadButton(this.collection.container));
|
||||||
|
}
|
||||||
|
|
||||||
|
return buttons;
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
this.updateNavbarWithTabsButtons();
|
||||||
|
}
|
||||||
|
|
||||||
|
private _getPartitionKeyPropertyHeader(): string {
|
||||||
|
return (
|
||||||
|
(this.partitionKey &&
|
||||||
|
this.partitionKey.paths &&
|
||||||
|
this.partitionKey.paths.length > 0 &&
|
||||||
|
this.partitionKey.paths[0]) ||
|
||||||
|
null
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static _createUploadButton(container: Explorer): CommandButtonComponentProps {
|
||||||
|
const label = "Upload Item";
|
||||||
|
return {
|
||||||
|
iconSrc: UploadIcon,
|
||||||
|
iconAlt: label,
|
||||||
|
onCommandClick: () => {
|
||||||
|
const selectedCollection: ViewModels.Collection = useSelectedNode.getState().findSelectedCollection();
|
||||||
|
selectedCollection && container.openUploadItemsPanePane();
|
||||||
|
},
|
||||||
|
commandButtonLabel: label,
|
||||||
|
ariaLabel: label,
|
||||||
|
hasPopup: true,
|
||||||
|
disabled: useSelectedNode.getState().isDatabaseNodeOrNoneSelected(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
import * as ko from "knockout";
|
|
||||||
import React from "react";
|
|
||||||
import "react-splitter-layout/lib/index.css";
|
|
||||||
import * as DataModels from "../../Contracts/DataModels";
|
|
||||||
import * as ViewModels from "../../Contracts/ViewModels";
|
|
||||||
import DocumentsTabContent from "./DocumentsTabContent";
|
|
||||||
import TabsBase from "./TabsBase";
|
|
||||||
|
|
||||||
export default class DocumentsTab extends TabsBase {
|
|
||||||
public documentContentsGridId: string;
|
|
||||||
public documentContentsContainerId: string;
|
|
||||||
public displayedError: ko.Observable<string>;
|
|
||||||
public partitionKey: DataModels.PartitionKey;
|
|
||||||
public partitionKeyPropertyHeader: string;
|
|
||||||
public partitionKeyProperty: string;
|
|
||||||
public _resourceTokenPartitionKey: string;
|
|
||||||
|
|
||||||
constructor(options: ViewModels.DocumentsTabOptions) {
|
|
||||||
super(options);
|
|
||||||
this.documentContentsGridId = `documentContentsGrid${this.tabId}`;
|
|
||||||
this.documentContentsContainerId = `documentContentsContainer${this.tabId}`;
|
|
||||||
this.partitionKey = options.partitionKey || (this.collection && this.collection.partitionKey);
|
|
||||||
this._resourceTokenPartitionKey = options.resourceTokenPartitionKey;
|
|
||||||
|
|
||||||
this.partitionKeyPropertyHeader =
|
|
||||||
(this.collection && this.collection.partitionKeyPropertyHeader) || this._getPartitionKeyPropertyHeader();
|
|
||||||
this.partitionKeyProperty = this.partitionKeyPropertyHeader
|
|
||||||
? this.partitionKeyPropertyHeader.replace(/[/]+/g, ".").substr(1).replace(/[']+/g, "")
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
this.displayedError = ko.observable<string>("");
|
|
||||||
}
|
|
||||||
|
|
||||||
public onTabClick(): void {
|
|
||||||
super.onTabClick();
|
|
||||||
this.collection && this.collection.selectedSubnodeKind(ViewModels.CollectionTabKind.Documents);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected buildCommandBarOptions(): void {
|
|
||||||
this.updateNavbarWithTabsButtons();
|
|
||||||
}
|
|
||||||
|
|
||||||
private _getPartitionKeyPropertyHeader(): string {
|
|
||||||
return this.partitionKey?.paths?.[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
render(): JSX.Element {
|
|
||||||
return <DocumentsTabContent {...this} />;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,793 +0,0 @@
|
|||||||
import { extractPartitionKey, PartitionKeyDefinition } from "@azure/cosmos";
|
|
||||||
import {
|
|
||||||
DetailsList,
|
|
||||||
DetailsListLayoutMode,
|
|
||||||
IColumn,
|
|
||||||
IIconProps,
|
|
||||||
Image,
|
|
||||||
List,
|
|
||||||
PrimaryButton,
|
|
||||||
SelectionMode,
|
|
||||||
Stack,
|
|
||||||
Text,
|
|
||||||
TextField,
|
|
||||||
} from "@fluentui/react";
|
|
||||||
import * as React from "react";
|
|
||||||
import SplitterLayout from "react-splitter-layout";
|
|
||||||
import CloseIcon from "../../../images/close-black.svg";
|
|
||||||
import DeleteDocumentIcon from "../../../images/DeleteDocument.svg";
|
|
||||||
import DiscardIcon from "../../../images/discard.svg";
|
|
||||||
import DocumentWaterMark from "../../../images/DocumentWaterMark.svg";
|
|
||||||
import NewDocumentIcon from "../../../images/NewDocument.svg";
|
|
||||||
import SaveIcon from "../../../images/save-cosmos.svg";
|
|
||||||
import UploadIcon from "../../../images/Upload_16x16.svg";
|
|
||||||
import { Resource } from "../../../src/Contracts/DataModels";
|
|
||||||
import * as NotificationConsoleUtils from "../../../src/Utils/NotificationConsoleUtils";
|
|
||||||
import { Areas } from "../../Common/Constants";
|
|
||||||
import { createDocument as createSqlDocuments } from "../../Common/dataAccess/createDocument";
|
|
||||||
import { deleteDocument as deleteSqlDocument } from "../../Common/dataAccess/deleteDocument";
|
|
||||||
import { queryDocuments as querySqlDocuments } from "../../Common/dataAccess/queryDocuments";
|
|
||||||
import { readDocument } from "../../Common/dataAccess/readDocument";
|
|
||||||
import { updateDocument as updateSqlDocuments } from "../../Common/dataAccess/updateDocument";
|
|
||||||
import { getEntityName } from "../../Common/DocumentUtility";
|
|
||||||
import { getErrorMessage, getErrorStack } from "../../Common/ErrorHandlingUtils";
|
|
||||||
import * as HeadersUtility from "../../Common/HeadersUtility";
|
|
||||||
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";
|
|
||||||
import * as QueryUtils from "../../Utils/QueryUtils";
|
|
||||||
import { CommandButtonComponentProps } from "../Controls/CommandButton/CommandButtonComponent";
|
|
||||||
import { EditorReact } from "../Controls/Editor/EditorReact";
|
|
||||||
import { useCommandBar } from "../Menus/CommandBar/CommandBarComponentAdapter";
|
|
||||||
import DocumentId from "../Tree/DocumentId";
|
|
||||||
import ObjectId from "../Tree/ObjectId";
|
|
||||||
import { useSelectedNode } from "../useSelectedNode";
|
|
||||||
import DocumentsTab from "./DocumentsTab";
|
|
||||||
import {
|
|
||||||
assignTabButtonVisibility,
|
|
||||||
formatDocumentContent,
|
|
||||||
formatSqlDocumentContent,
|
|
||||||
getDocumentItems,
|
|
||||||
getFilterPlaceholder,
|
|
||||||
getFilterSuggestions,
|
|
||||||
getfilterText,
|
|
||||||
getPartitionKeyDefinition,
|
|
||||||
hasShardKeySpecified,
|
|
||||||
IDocumentsTabContentState,
|
|
||||||
imageProps,
|
|
||||||
} from "./DocumentTabUtils";
|
|
||||||
|
|
||||||
const filterIcon: IIconProps = { iconName: "Filter" };
|
|
||||||
let newDocumentButton = assignTabButtonVisibility(true, true);
|
|
||||||
let saveNewDocumentButton = assignTabButtonVisibility(false, true);
|
|
||||||
let discardNewDocumentChangesButton = assignTabButtonVisibility(false, false);
|
|
||||||
let saveExisitingDocumentButton = assignTabButtonVisibility(false, false);
|
|
||||||
let discardExisitingDocumentChangesButton = assignTabButtonVisibility(false, false);
|
|
||||||
let deleteExisitingDocumentButton = assignTabButtonVisibility(false, false);
|
|
||||||
|
|
||||||
export default class DocumentsTabContent extends React.Component<DocumentsTab, IDocumentsTabContentState> {
|
|
||||||
public initialDocumentContent: string;
|
|
||||||
|
|
||||||
constructor(props: DocumentsTab) {
|
|
||||||
super(props);
|
|
||||||
const isPreferredApiMongoDB = userContext.apiType === "Mongo";
|
|
||||||
|
|
||||||
const columns: IColumn[] = [
|
|
||||||
{
|
|
||||||
key: "_id",
|
|
||||||
name: isPreferredApiMongoDB ? "_id" : "id",
|
|
||||||
minWidth: 50,
|
|
||||||
maxWidth: 100,
|
|
||||||
isResizable: true,
|
|
||||||
isCollapsible: true,
|
|
||||||
data: "string",
|
|
||||||
onRender: (item: DocumentId) => {
|
|
||||||
return (
|
|
||||||
<div onClick={() => this.handleRow(item)} className="documentIdItem">
|
|
||||||
{isPreferredApiMongoDB ? item.id() : item.id}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
isPadded: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: "column2",
|
|
||||||
name: props.partitionKeyPropertyHeader,
|
|
||||||
minWidth: 50,
|
|
||||||
maxWidth: 100,
|
|
||||||
isResizable: true,
|
|
||||||
isCollapsible: true,
|
|
||||||
data: "number",
|
|
||||||
onRender: (item: DocumentId) => {
|
|
||||||
return (
|
|
||||||
<div onClick={() => this.handleRow(item)} className="documentIdItem">
|
|
||||||
{isPreferredApiMongoDB ? item.partitionKeyValue : item._partitionKeyValue}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
this.initialDocumentContent = `{ \n ${
|
|
||||||
isPreferredApiMongoDB ? '"_id"' : '"id"'
|
|
||||||
}: "replace_with_new_document_id" \n }`;
|
|
||||||
|
|
||||||
this.state = {
|
|
||||||
columns: columns,
|
|
||||||
isModalSelection: false,
|
|
||||||
isCompactMode: false,
|
|
||||||
announcedMessage: undefined,
|
|
||||||
isSuggestionVisible: false,
|
|
||||||
filter: "",
|
|
||||||
isFilterOptionVisible: true,
|
|
||||||
isEditorVisible: false,
|
|
||||||
documentContent: this.initialDocumentContent,
|
|
||||||
documentIds: [],
|
|
||||||
documentSqlIds: [],
|
|
||||||
isEditorContentEdited: false,
|
|
||||||
isAllDocumentsVisible: false,
|
|
||||||
selectedSqlDocumentContent: this.initialDocumentContent,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
componentDidMount(): void {
|
|
||||||
this.props.isExecuting(true);
|
|
||||||
this.updateTabButton();
|
|
||||||
if (userContext.apiType === "Mongo") {
|
|
||||||
this.queryDocumentsData();
|
|
||||||
} else {
|
|
||||||
this.querySqlDocumentsData();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public buildQuery(filter: string): string {
|
|
||||||
return QueryUtils.buildDocumentsQuery(filter, this.props.partitionKeyProperty, this.props.partitionKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
private querySqlDocumentsData = async (): Promise<void> => {
|
|
||||||
this.props.isExecuting(true);
|
|
||||||
this.props.isExecutionError(false);
|
|
||||||
const { filter } = this.state;
|
|
||||||
const query: string = this.buildQuery(filter);
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
const options: any = {};
|
|
||||||
options.enableCrossPartitionQuery = HeadersUtility.shouldEnableCrossPartitionKey();
|
|
||||||
if (this.props._resourceTokenPartitionKey) {
|
|
||||||
options.partitionKey = this.props._resourceTokenPartitionKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const sqlQuery = querySqlDocuments(this.props.collection.databaseId, this.props.collection.id(), query, options);
|
|
||||||
const querySqlDocumentsData = await sqlQuery.fetchNext();
|
|
||||||
this.setState({ documentSqlIds: querySqlDocumentsData.resources?.length ? querySqlDocumentsData.resources : [] });
|
|
||||||
} catch (error) {
|
|
||||||
this.props.isExecutionError(true);
|
|
||||||
const errorMessage = getErrorMessage(error);
|
|
||||||
NotificationConsoleUtils.logConsoleError(errorMessage);
|
|
||||||
} finally {
|
|
||||||
this.props.isExecuting(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private queryDocumentsData = async (): Promise<void> => {
|
|
||||||
this.props.isExecuting(true);
|
|
||||||
this.props.isExecutionError(false);
|
|
||||||
try {
|
|
||||||
const { filter } = this.state;
|
|
||||||
const query: string = filter || "{}";
|
|
||||||
const queryDocumentsData = await queryDocuments(
|
|
||||||
this.props.collection.databaseId,
|
|
||||||
this.props.collection as ViewModels.Collection,
|
|
||||||
true,
|
|
||||||
query,
|
|
||||||
undefined
|
|
||||||
);
|
|
||||||
if (queryDocumentsData) {
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
const nextDocumentIds = queryDocumentsData.documents.map((rawDocument: any) => {
|
|
||||||
const partitionKeyValue = rawDocument._partitionKeyValue;
|
|
||||||
return new DocumentId(this.props as DocumentsTab, rawDocument, partitionKeyValue);
|
|
||||||
});
|
|
||||||
this.setState({ documentIds: nextDocumentIds });
|
|
||||||
}
|
|
||||||
if (this.props.onLoadStartKey !== undefined) {
|
|
||||||
TelemetryProcessor.traceSuccess(
|
|
||||||
Action.Tab,
|
|
||||||
{
|
|
||||||
databaseName: this.props.collection.databaseId,
|
|
||||||
collectionName: this.props.collection.id(),
|
|
||||||
dataExplorerArea: Areas.Tab,
|
|
||||||
tabTitle: this.props.tabTitle(),
|
|
||||||
},
|
|
||||||
this.props.onLoadStartKey
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
if (this.props.onLoadStartKey !== undefined) {
|
|
||||||
TelemetryProcessor.traceFailure(
|
|
||||||
Action.Tab,
|
|
||||||
{
|
|
||||||
databaseName: this.props.collection.databaseId,
|
|
||||||
collectionName: this.props.collection.id(),
|
|
||||||
dataExplorerArea: Areas.Tab,
|
|
||||||
tabTitle: this.props.tabTitle(),
|
|
||||||
error: getErrorMessage(error),
|
|
||||||
errorStack: getErrorStack(error),
|
|
||||||
},
|
|
||||||
this.props.onLoadStartKey
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
this.props.isExecuting(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private handleRow = (row: DocumentId | Resource): void => {
|
|
||||||
if (this.state.isEditorContentEdited) {
|
|
||||||
this.props.collection.container.showOkCancelModalDialog(
|
|
||||||
"Are you sure you want to continue?",
|
|
||||||
"Your unsaved changes will be lost.",
|
|
||||||
"Okay",
|
|
||||||
() => {
|
|
||||||
this.handleRowContent(row);
|
|
||||||
this.setState({ isEditorContentEdited: false });
|
|
||||||
return;
|
|
||||||
},
|
|
||||||
"Cancel",
|
|
||||||
undefined
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
this.handleRowContent(row);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private handleRowContent = (row: DocumentId | Resource): void => {
|
|
||||||
userContext.apiType === "Mongo"
|
|
||||||
? this.updateContent(row as DocumentId, formatDocumentContent(row as DocumentId))
|
|
||||||
: this.updateSqlContent(row as Resource);
|
|
||||||
this.setDefaultUpdateTabButtonVisibility();
|
|
||||||
};
|
|
||||||
|
|
||||||
private updateContent = (row: DocumentId, formattedDocumentContent: string): void => {
|
|
||||||
this.setState(
|
|
||||||
{
|
|
||||||
documentContent: formattedDocumentContent,
|
|
||||||
isEditorVisible: true,
|
|
||||||
selectedDocumentId: row,
|
|
||||||
},
|
|
||||||
() => {
|
|
||||||
this.updateTabButton();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
private updateSqlContent = async (row: Resource): Promise<void> => {
|
|
||||||
const selectedDocumentId: DocumentId = new DocumentId(this.props as DocumentsTab, row, row._partitionKeyValue);
|
|
||||||
|
|
||||||
const content = await readDocument(this.props.collection, selectedDocumentId);
|
|
||||||
const formattedDocumentContent = formatSqlDocumentContent((content as unknown) as Resource);
|
|
||||||
this.setState(
|
|
||||||
{
|
|
||||||
documentContent: formattedDocumentContent,
|
|
||||||
isEditorVisible: true,
|
|
||||||
selectedSqlDocumentContent: formattedDocumentContent,
|
|
||||||
selectedSqlDocumentId: selectedDocumentId,
|
|
||||||
},
|
|
||||||
() => {
|
|
||||||
this.updateTabButton();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
private handleFilter = (): void => {
|
|
||||||
userContext.apiType === "Mongo" ? this.queryDocumentsData() : this.querySqlDocumentsData();
|
|
||||||
this.setState({
|
|
||||||
isSuggestionVisible: false,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
async updateSqlDocument(): Promise<void> {
|
|
||||||
const { isExecutionError, isExecuting, collection } = this.props;
|
|
||||||
const { documentContent, selectedSqlDocumentId } = this.state;
|
|
||||||
isExecutionError(false);
|
|
||||||
const startKey: number = this.getStartKey(Action.UpdateDocument);
|
|
||||||
try {
|
|
||||||
isExecuting(true);
|
|
||||||
const updateSqlDocumentRes = await updateSqlDocuments(
|
|
||||||
collection as ViewModels.Collection,
|
|
||||||
selectedSqlDocumentId,
|
|
||||||
JSON.parse(documentContent)
|
|
||||||
);
|
|
||||||
if (updateSqlDocumentRes) {
|
|
||||||
this.setTraceSuccess(Action.UpdateDocument, startKey);
|
|
||||||
this.querySqlDocumentsData();
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
NotificationConsoleUtils.logConsoleError(getErrorMessage(error));
|
|
||||||
this.setTraceFail(Action.UpdateDocument, startKey, error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async updateMongoDocument(): Promise<void> {
|
|
||||||
const { selectedDocumentId, documentContent, documentIds } = this.state;
|
|
||||||
const { isExecutionError, isExecuting, collection, partitionKey, partitionKeyProperty } = this.props;
|
|
||||||
isExecutionError(false);
|
|
||||||
isExecuting(true);
|
|
||||||
const startKey: number = this.getStartKey(Action.UpdateDocument);
|
|
||||||
try {
|
|
||||||
const updatedDocument = await updateDocument(
|
|
||||||
collection.databaseId,
|
|
||||||
collection as ViewModels.Collection,
|
|
||||||
selectedDocumentId,
|
|
||||||
documentContent
|
|
||||||
);
|
|
||||||
|
|
||||||
documentIds.forEach((documentId: DocumentId) => {
|
|
||||||
if (documentId.rid === updatedDocument._rid) {
|
|
||||||
const partitionKeyArray = extractPartitionKey(
|
|
||||||
updatedDocument,
|
|
||||||
getPartitionKeyDefinition(partitionKey, partitionKeyProperty) as PartitionKeyDefinition
|
|
||||||
);
|
|
||||||
const partitionKeyValue = partitionKeyArray && partitionKeyArray[0];
|
|
||||||
const id = new ObjectId(this.props as DocumentsTab, updatedDocument, partitionKeyValue);
|
|
||||||
documentId.id(id.id());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.setTraceSuccess(Action.UpdateDocument, startKey);
|
|
||||||
this.setState({ isEditorContentEdited: false });
|
|
||||||
} catch (error) {
|
|
||||||
NotificationConsoleUtils.logConsoleError(getErrorMessage(error));
|
|
||||||
this.setTraceFail(Action.UpdateDocument, startKey, error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected getTabsButtons(): CommandButtonComponentProps[] {
|
|
||||||
const buttons: CommandButtonComponentProps[] = [];
|
|
||||||
const label = `New ${getEntityName()}`;
|
|
||||||
if (newDocumentButton.visible) {
|
|
||||||
buttons.push({
|
|
||||||
iconSrc: NewDocumentIcon,
|
|
||||||
iconAlt: label,
|
|
||||||
onCommandClick: this.onNewDocumentClick,
|
|
||||||
commandButtonLabel: label,
|
|
||||||
ariaLabel: label,
|
|
||||||
hasPopup: false,
|
|
||||||
disabled: !newDocumentButton.enabled,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (saveNewDocumentButton.visible) {
|
|
||||||
const label = "Save";
|
|
||||||
buttons.push({
|
|
||||||
iconSrc: SaveIcon,
|
|
||||||
iconAlt: label,
|
|
||||||
onCommandClick: this.onSaveNewDocumentClick,
|
|
||||||
commandButtonLabel: label,
|
|
||||||
ariaLabel: label,
|
|
||||||
hasPopup: false,
|
|
||||||
disabled: !saveNewDocumentButton.enabled,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (discardNewDocumentChangesButton.visible) {
|
|
||||||
const label = "Discard";
|
|
||||||
buttons.push({
|
|
||||||
iconSrc: DiscardIcon,
|
|
||||||
iconAlt: label,
|
|
||||||
onCommandClick: this.onRevertNewDocumentClick,
|
|
||||||
commandButtonLabel: label,
|
|
||||||
ariaLabel: label,
|
|
||||||
hasPopup: false,
|
|
||||||
disabled: !discardNewDocumentChangesButton.enabled,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (saveExisitingDocumentButton.visible) {
|
|
||||||
const label = "Update";
|
|
||||||
buttons.push({
|
|
||||||
...this,
|
|
||||||
updateMongoDocument: this.updateMongoDocument,
|
|
||||||
updateSqlDocument: this.updateSqlDocument,
|
|
||||||
setState: this.setState,
|
|
||||||
iconSrc: SaveIcon,
|
|
||||||
iconAlt: label,
|
|
||||||
onCommandClick: this.onSaveExisitingDocumentClick,
|
|
||||||
commandButtonLabel: label,
|
|
||||||
ariaLabel: label,
|
|
||||||
hasPopup: false,
|
|
||||||
disabled: !saveExisitingDocumentButton.enabled,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (discardExisitingDocumentChangesButton.visible) {
|
|
||||||
const label = "Discard";
|
|
||||||
buttons.push({
|
|
||||||
...this,
|
|
||||||
setState: this.setState,
|
|
||||||
iconSrc: DiscardIcon,
|
|
||||||
iconAlt: label,
|
|
||||||
onCommandClick: this.onRevertExisitingDocumentClick,
|
|
||||||
commandButtonLabel: label,
|
|
||||||
ariaLabel: label,
|
|
||||||
hasPopup: false,
|
|
||||||
disabled: !discardExisitingDocumentChangesButton.enabled,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (deleteExisitingDocumentButton.visible) {
|
|
||||||
const label = "Delete";
|
|
||||||
buttons.push({
|
|
||||||
...this,
|
|
||||||
setState: this.setState,
|
|
||||||
iconSrc: DeleteDocumentIcon,
|
|
||||||
iconAlt: label,
|
|
||||||
onCommandClick: this.onDeleteExisitingDocumentClick,
|
|
||||||
commandButtonLabel: label,
|
|
||||||
ariaLabel: label,
|
|
||||||
hasPopup: false,
|
|
||||||
disabled: !deleteExisitingDocumentButton.enabled,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (userContext.apiType !== "Mongo") {
|
|
||||||
const { collection } = this.props;
|
|
||||||
const label = "Upload Item";
|
|
||||||
buttons.push({
|
|
||||||
iconSrc: UploadIcon,
|
|
||||||
iconAlt: label,
|
|
||||||
onCommandClick: () => {
|
|
||||||
const selectedCollection: ViewModels.Collection = useSelectedNode.getState().findSelectedCollection();
|
|
||||||
selectedCollection && collection.container.openUploadItemsPanePane();
|
|
||||||
},
|
|
||||||
commandButtonLabel: label,
|
|
||||||
ariaLabel: label,
|
|
||||||
hasPopup: true,
|
|
||||||
disabled: useSelectedNode.getState().isDatabaseNodeOrNoneSelected(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return buttons;
|
|
||||||
}
|
|
||||||
|
|
||||||
private onSaveExisitingDocumentClick(): void {
|
|
||||||
userContext.apiType === "Mongo" ? this.updateMongoDocument() : this.updateSqlDocument();
|
|
||||||
}
|
|
||||||
|
|
||||||
private async onDeleteExisitingDocumentClick(): Promise<void> {
|
|
||||||
const confirmationMessage = `Are you sure you want to delete the selected ${getEntityName()} ?`;
|
|
||||||
const { isExecuting, collection } = this.props;
|
|
||||||
const startKey: number = this.getStartKey(Action.DeleteDocument);
|
|
||||||
this.props.collection.container.showOkCancelModalDialog(
|
|
||||||
confirmationMessage,
|
|
||||||
`This ${getEntityName()} will be deleted immediately. You can't undo this action`,
|
|
||||||
"Delete",
|
|
||||||
async () => {
|
|
||||||
try {
|
|
||||||
isExecuting(true);
|
|
||||||
if (userContext.apiType === "Mongo") {
|
|
||||||
await deleteDocument(
|
|
||||||
collection.databaseId,
|
|
||||||
collection as ViewModels.Collection,
|
|
||||||
this.state.selectedDocumentId
|
|
||||||
);
|
|
||||||
this.queryDocumentsData();
|
|
||||||
} else {
|
|
||||||
const { selectedSqlDocumentId } = this.state;
|
|
||||||
await deleteSqlDocument(collection as ViewModels.Collection, selectedSqlDocumentId);
|
|
||||||
this.querySqlDocumentsData();
|
|
||||||
}
|
|
||||||
this.setTraceSuccess(Action.DeleteDocument, startKey);
|
|
||||||
this.setState({ isEditorVisible: false });
|
|
||||||
} catch (error) {
|
|
||||||
this.setTraceFail(Action.DeleteDocument, startKey, error);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"Cancel",
|
|
||||||
undefined
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private onRevertExisitingDocumentClick(): void {
|
|
||||||
const { selectedDocumentId, selectedSqlDocumentContent } = this.state;
|
|
||||||
const documentContent =
|
|
||||||
userContext.apiType === "Mongo" ? formatDocumentContent(selectedDocumentId) : selectedSqlDocumentContent;
|
|
||||||
this.setState({
|
|
||||||
documentContent: documentContent,
|
|
||||||
});
|
|
||||||
discardExisitingDocumentChangesButton = assignTabButtonVisibility(true, false);
|
|
||||||
saveExisitingDocumentButton = assignTabButtonVisibility(true, false);
|
|
||||||
this.updateTabButton();
|
|
||||||
}
|
|
||||||
|
|
||||||
private onNewDocumentClick = () => {
|
|
||||||
newDocumentButton = assignTabButtonVisibility(true, false);
|
|
||||||
saveNewDocumentButton = assignTabButtonVisibility(true, true);
|
|
||||||
discardNewDocumentChangesButton = assignTabButtonVisibility(true, true);
|
|
||||||
saveExisitingDocumentButton = assignTabButtonVisibility(false, false);
|
|
||||||
discardExisitingDocumentChangesButton = assignTabButtonVisibility(false, false);
|
|
||||||
deleteExisitingDocumentButton = assignTabButtonVisibility(false, false);
|
|
||||||
|
|
||||||
this.updateTabButton();
|
|
||||||
this.setState({
|
|
||||||
documentContent: this.initialDocumentContent,
|
|
||||||
isEditorVisible: true,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
private onSaveNewDocumentClick = () => {
|
|
||||||
if (userContext.apiType === "Mongo") {
|
|
||||||
this.onSaveNewMongoDocumentClick();
|
|
||||||
} else {
|
|
||||||
this.onSaveSqlNewMongoDocumentClick();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public onSaveSqlNewMongoDocumentClick = async (): Promise<void> => {
|
|
||||||
const { isExecutionError, isExecuting, collection } = this.props;
|
|
||||||
isExecutionError(false);
|
|
||||||
const startKey: number = this.getStartKey(Action.CreateDocument);
|
|
||||||
const document = JSON.parse(this.state.documentContent);
|
|
||||||
isExecuting(true);
|
|
||||||
try {
|
|
||||||
const savedDocument = await createSqlDocuments(collection, document);
|
|
||||||
if (savedDocument) {
|
|
||||||
const formattedDocumentContent = formatSqlDocumentContent((savedDocument as unknown) as Resource);
|
|
||||||
this.setState({ documentContent: formattedDocumentContent });
|
|
||||||
this.setDefaultUpdateTabButtonVisibility();
|
|
||||||
this.setTraceSuccess(Action.CreateDocument, startKey);
|
|
||||||
}
|
|
||||||
this.querySqlDocumentsData();
|
|
||||||
} catch (error) {
|
|
||||||
NotificationConsoleUtils.logConsoleError(getErrorMessage(error));
|
|
||||||
this.setTraceFail(Action.CreateDocument, startKey, error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private setDefaultUpdateTabButtonVisibility = (): void => {
|
|
||||||
newDocumentButton = assignTabButtonVisibility(true, true);
|
|
||||||
saveNewDocumentButton = assignTabButtonVisibility(false, false);
|
|
||||||
discardNewDocumentChangesButton = assignTabButtonVisibility(false, false);
|
|
||||||
saveExisitingDocumentButton = assignTabButtonVisibility(true, false);
|
|
||||||
discardExisitingDocumentChangesButton = assignTabButtonVisibility(true, false);
|
|
||||||
deleteExisitingDocumentButton = assignTabButtonVisibility(true, true);
|
|
||||||
this.updateTabButton();
|
|
||||||
};
|
|
||||||
|
|
||||||
public onSaveNewMongoDocumentClick = async (): Promise<void> => {
|
|
||||||
const parsedDocumentContent = JSON.parse(this.state.documentContent);
|
|
||||||
const {
|
|
||||||
partitionKey,
|
|
||||||
partitionKeyProperty,
|
|
||||||
displayedError,
|
|
||||||
isExecutionError,
|
|
||||||
isExecuting,
|
|
||||||
collection,
|
|
||||||
} = this.props;
|
|
||||||
displayedError("");
|
|
||||||
const startKey: number = this.getStartKey(Action.CreateDocument);
|
|
||||||
if (
|
|
||||||
partitionKeyProperty &&
|
|
||||||
partitionKeyProperty !== "_id" &&
|
|
||||||
!hasShardKeySpecified(parsedDocumentContent, partitionKey, partitionKeyProperty)
|
|
||||||
) {
|
|
||||||
const message = `The document is lacking the shard property: ${partitionKeyProperty}`;
|
|
||||||
displayedError(message);
|
|
||||||
this.setTraceFail(Action.CreateDocument, startKey, message);
|
|
||||||
logError("Failed to save new document: Document shard key not defined", "MongoDocumentsTab");
|
|
||||||
throw new Error("Document without shard key");
|
|
||||||
}
|
|
||||||
isExecutionError(false);
|
|
||||||
isExecuting(true);
|
|
||||||
try {
|
|
||||||
const savedDocument = await createDocument(
|
|
||||||
collection.databaseId,
|
|
||||||
collection as ViewModels.Collection,
|
|
||||||
partitionKeyProperty,
|
|
||||||
parsedDocumentContent
|
|
||||||
);
|
|
||||||
if (savedDocument) {
|
|
||||||
this.handleLoadMoreDocument();
|
|
||||||
this.setDefaultUpdateTabButtonVisibility();
|
|
||||||
this.setTraceSuccess(Action.CreateDocument, startKey);
|
|
||||||
}
|
|
||||||
this.setState({ isEditorContentEdited: false });
|
|
||||||
this.queryDocumentsData();
|
|
||||||
} catch (error) {
|
|
||||||
window.alert(getErrorMessage(error));
|
|
||||||
this.setTraceFail(Action.CreateDocument, startKey, error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private getStartKey = (action: number): number => {
|
|
||||||
const startKey: number = TelemetryProcessor.traceStart(action, {
|
|
||||||
dataExplorerArea: Areas.Tab,
|
|
||||||
tabTitle: this.props.tabTitle(),
|
|
||||||
});
|
|
||||||
return startKey;
|
|
||||||
};
|
|
||||||
|
|
||||||
private setTraceSuccess = (action: number, startKey: number): void => {
|
|
||||||
const { isExecuting, tabTitle } = this.props;
|
|
||||||
TelemetryProcessor.traceSuccess(
|
|
||||||
action,
|
|
||||||
{
|
|
||||||
dataExplorerArea: Areas.Tab,
|
|
||||||
tabTitle: tabTitle(),
|
|
||||||
},
|
|
||||||
startKey
|
|
||||||
);
|
|
||||||
isExecuting(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
private setTraceFail = (action: number, startKey: number, error: Error | string): void => {
|
|
||||||
const { isExecuting, tabTitle, isExecutionError } = this.props;
|
|
||||||
TelemetryProcessor.traceFailure(
|
|
||||||
action,
|
|
||||||
{
|
|
||||||
dataExplorerArea: Areas.Tab,
|
|
||||||
tabTitle: tabTitle(),
|
|
||||||
error: getErrorMessage(error),
|
|
||||||
errorStack: getErrorStack(error),
|
|
||||||
},
|
|
||||||
startKey
|
|
||||||
);
|
|
||||||
isExecuting(false);
|
|
||||||
isExecutionError(true);
|
|
||||||
};
|
|
||||||
|
|
||||||
private onRevertNewDocumentClick = () => {
|
|
||||||
newDocumentButton = assignTabButtonVisibility(true, true);
|
|
||||||
saveNewDocumentButton = assignTabButtonVisibility(true, false);
|
|
||||||
discardNewDocumentChangesButton = assignTabButtonVisibility(true, false);
|
|
||||||
|
|
||||||
this.updateTabButton();
|
|
||||||
this.setState({
|
|
||||||
isEditorVisible: false,
|
|
||||||
isEditorContentEdited: false,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
private onRenderCell = (item: { value: string }): JSX.Element => {
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
className="documentTabSuggestions"
|
|
||||||
onClick={() =>
|
|
||||||
this.setState({
|
|
||||||
filter: item.value,
|
|
||||||
isSuggestionVisible: false,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<Text>{item.value}</Text>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
private handleLoadMoreDocument = (): void => {
|
|
||||||
userContext.apiType === "Mongo" ? this.queryDocumentsData() : this.querySqlDocumentsData();
|
|
||||||
this.setState({
|
|
||||||
isSuggestionVisible: false,
|
|
||||||
isAllDocumentsVisible: true,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
private updateTabButton = (): void => {
|
|
||||||
useCommandBar.getState().setContextButtons(this.getTabsButtons());
|
|
||||||
};
|
|
||||||
|
|
||||||
private getKey(item: DocumentId): string {
|
|
||||||
return item.rid;
|
|
||||||
}
|
|
||||||
|
|
||||||
private handleDocumentContentChange = (newContent: string): void => {
|
|
||||||
if (saveExisitingDocumentButton.visible && newContent !== this.state.documentContent) {
|
|
||||||
saveExisitingDocumentButton = assignTabButtonVisibility(true, true);
|
|
||||||
discardExisitingDocumentChangesButton = assignTabButtonVisibility(true, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setState(
|
|
||||||
{
|
|
||||||
documentContent: newContent,
|
|
||||||
isEditorContentEdited: true,
|
|
||||||
},
|
|
||||||
() => {
|
|
||||||
this.updateTabButton();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
public render(): JSX.Element {
|
|
||||||
const {
|
|
||||||
columns,
|
|
||||||
isCompactMode,
|
|
||||||
isSuggestionVisible,
|
|
||||||
filter,
|
|
||||||
isFilterOptionVisible,
|
|
||||||
isEditorVisible,
|
|
||||||
documentContent,
|
|
||||||
documentIds,
|
|
||||||
documentSqlIds,
|
|
||||||
isAllDocumentsVisible,
|
|
||||||
} = this.state;
|
|
||||||
const isPreferredApiMongoDB = userContext.apiType === "Mongo";
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
{isFilterOptionVisible && (
|
|
||||||
<>
|
|
||||||
<div>
|
|
||||||
<Stack horizontal verticalFill wrap>
|
|
||||||
{!isPreferredApiMongoDB && <Text className="queryText">SELECT * FROM c</Text>}
|
|
||||||
<TextField
|
|
||||||
iconProps={filterIcon}
|
|
||||||
placeholder={getFilterPlaceholder(isPreferredApiMongoDB)}
|
|
||||||
className={isPreferredApiMongoDB ? "documentTabSearchBar" : "documentSqlTabSearchBar"}
|
|
||||||
onFocus={() => this.setState({ isSuggestionVisible: true })}
|
|
||||||
onChange={(_event, newInput?: string) => {
|
|
||||||
this.setState({ filter: newInput });
|
|
||||||
}}
|
|
||||||
value={filter}
|
|
||||||
/>
|
|
||||||
<PrimaryButton text="Apply Filter" onClick={this.handleFilter} className="documentTabFiltetButton" />
|
|
||||||
<Image
|
|
||||||
src={CloseIcon}
|
|
||||||
alt="Close icon"
|
|
||||||
{...imageProps}
|
|
||||||
onClick={() => this.setState({ isFilterOptionVisible: false })}
|
|
||||||
/>
|
|
||||||
</Stack>
|
|
||||||
</div>
|
|
||||||
{isSuggestionVisible && (
|
|
||||||
<div className={isPreferredApiMongoDB ? "filterSuggestions" : "filterSuggestions sqlFilterSuggestions"}>
|
|
||||||
<List items={getFilterSuggestions(isPreferredApiMongoDB)} onRenderCell={this.onRenderCell} />
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
{!isFilterOptionVisible && (
|
|
||||||
<Stack horizontal verticalFill wrap className="documentTabNoFilterView">
|
|
||||||
<Text className="noFilterText">{getfilterText(isPreferredApiMongoDB, filter)}</Text>
|
|
||||||
<PrimaryButton text="Edit Filter" onClick={() => this.setState({ isFilterOptionVisible: true })} />
|
|
||||||
</Stack>
|
|
||||||
)}
|
|
||||||
<div className="splitterWrapper" onClick={() => this.setState({ isSuggestionVisible: false })}>
|
|
||||||
<SplitterLayout primaryIndex={0} secondaryInitialSize={1000}>
|
|
||||||
<div className="leftSplitter">
|
|
||||||
<DetailsList
|
|
||||||
items={getDocumentItems(isPreferredApiMongoDB, documentIds, documentSqlIds, isAllDocumentsVisible)}
|
|
||||||
compact={isCompactMode}
|
|
||||||
columns={columns}
|
|
||||||
selectionMode={SelectionMode.none}
|
|
||||||
getKey={this.getKey}
|
|
||||||
setKey="none"
|
|
||||||
layoutMode={DetailsListLayoutMode.justified}
|
|
||||||
isHeaderVisible={true}
|
|
||||||
/>
|
|
||||||
<Text onClick={this.handleLoadMoreDocument} className="documentLoadMore" block={true}>
|
|
||||||
Load More
|
|
||||||
</Text>
|
|
||||||
</div>
|
|
||||||
{isEditorVisible ? (
|
|
||||||
<div className="react-editor">
|
|
||||||
<EditorReact
|
|
||||||
language={"json"}
|
|
||||||
content={documentContent}
|
|
||||||
isReadOnly={false}
|
|
||||||
ariaLabel={"Document json"}
|
|
||||||
onContentChanged={this.handleDocumentContentChange}
|
|
||||||
lineNumbers="on"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<div className="documentTabWatermark">
|
|
||||||
<Image src={DocumentWaterMark} alt="Document watermark" />
|
|
||||||
<Text className="documentCreateText">Create new or work with existing document(s).</Text>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</SplitterLayout>
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,90 +0,0 @@
|
|||||||
import * as ko from "knockout";
|
|
||||||
import { PartitionKey, Resource } from "../../../src/Contracts/DataModels";
|
|
||||||
import DocumentId from "../Tree/DocumentId";
|
|
||||||
import * as DocumentTabUtils from "./DocumentTabUtils";
|
|
||||||
|
|
||||||
describe("DocumentTabUtils", () => {
|
|
||||||
describe("getfilterText()", () => {
|
|
||||||
it("Should return filter if isPreferredApiMongoDB is true and filter is applied ", () => {
|
|
||||||
const filteredText: string = DocumentTabUtils.getfilterText(true, `{"_id": "foo"}`);
|
|
||||||
expect(filteredText).toBe(`Filter : {"_id": "foo"}`);
|
|
||||||
});
|
|
||||||
it("Should return `No filter applied` if isPreferredApiMongoDB is true and filter is not applied ", () => {
|
|
||||||
const filteredText: string = DocumentTabUtils.getfilterText(true, "");
|
|
||||||
expect(filteredText).toBe("No filter applied");
|
|
||||||
});
|
|
||||||
it("Should return `Select * from C` with filter if isPreferredApiMongoDB is false and filter is applied ", () => {
|
|
||||||
const filteredText: string = DocumentTabUtils.getfilterText(false, `WHERE c.id = "foo"`);
|
|
||||||
expect(filteredText).toBe(`Select * from C WHERE c.id = "foo"`);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("formatDocumentContent()", () => {
|
|
||||||
const fakeDocumentData = {} as DocumentId;
|
|
||||||
fakeDocumentData.partitionKeyProperty = "test";
|
|
||||||
fakeDocumentData.id = ko.observable("id");
|
|
||||||
|
|
||||||
it("should return formatted content with new line each property.", () => {
|
|
||||||
fakeDocumentData.partitionKeyValue = "partitionValue";
|
|
||||||
const formattedContent: string = DocumentTabUtils.formatDocumentContent(fakeDocumentData);
|
|
||||||
expect(formattedContent).toBe(`{\n"_id":"id",\n"test":"partitionValue"\n}`);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should return formatted content with empty partitionKeyValue when partitionKeyValue is undefined.", () => {
|
|
||||||
fakeDocumentData.partitionKeyValue = undefined;
|
|
||||||
const formattedContent: string = DocumentTabUtils.formatDocumentContent(fakeDocumentData);
|
|
||||||
expect(formattedContent).toBe(`{\n"_id":"id",\n"test":""\n}`);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("formatSqlDocumentContent()", () => {
|
|
||||||
const fakeDocumentData = {} as Resource;
|
|
||||||
it("should return formatted content with new line each property.", () => {
|
|
||||||
fakeDocumentData.id = "testId";
|
|
||||||
fakeDocumentData._rid = "testRid";
|
|
||||||
fakeDocumentData._self = "testSelf";
|
|
||||||
fakeDocumentData._ts = "testTs";
|
|
||||||
fakeDocumentData._etag = "testEtag";
|
|
||||||
fakeDocumentData._attachments = "testAttachments";
|
|
||||||
fakeDocumentData._partitionKey = "testPartitionKey";
|
|
||||||
|
|
||||||
const formattedContent: string = DocumentTabUtils.formatSqlDocumentContent(fakeDocumentData);
|
|
||||||
expect(formattedContent).toBe(
|
|
||||||
`{\n"id":"testId",\n"_rid":"testRid",\n"_self":"testSelf",\n"_ts":"testTs",\n"_etag":"testEtag",\n"_attachments":"testAttachments",\n"_partitionKey":"testPartitionKey"\n}`
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should return formatted content with empty value when key value is undefined.", () => {
|
|
||||||
fakeDocumentData.id = undefined;
|
|
||||||
fakeDocumentData._rid = undefined;
|
|
||||||
fakeDocumentData._self = undefined;
|
|
||||||
fakeDocumentData._ts = undefined;
|
|
||||||
fakeDocumentData._etag = undefined;
|
|
||||||
fakeDocumentData._attachments = undefined;
|
|
||||||
fakeDocumentData._partitionKey = undefined;
|
|
||||||
const formattedContent: string = DocumentTabUtils.formatSqlDocumentContent(fakeDocumentData);
|
|
||||||
expect(formattedContent).toBe(
|
|
||||||
`{\n"id":"",\n"_rid":"",\n"_self":"",\n"_ts":"",\n"_etag":"",\n"_attachments":"",\n"_partitionKey":""\n}`
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
describe("getPartitionKeyDefinition()", () => {
|
|
||||||
const partitionKey = {} as PartitionKey;
|
|
||||||
partitionKey.kind = "Hash";
|
|
||||||
partitionKey.version = 1;
|
|
||||||
partitionKey.systemKey = true;
|
|
||||||
const partitionKeyProperty = "testPartitionKey";
|
|
||||||
|
|
||||||
it("should return formatted partitionKey with formatted path.", () => {
|
|
||||||
partitionKey.paths = ["test"];
|
|
||||||
const formattedPartitionKey = DocumentTabUtils.getPartitionKeyDefinition(partitionKey, partitionKeyProperty);
|
|
||||||
expect(formattedPartitionKey).toEqual({ kind: "Hash", version: 1, systemKey: true, paths: ["test"] });
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should return partitionKey with undefined paths if paths is undefined.", () => {
|
|
||||||
partitionKey.paths = undefined;
|
|
||||||
const formattedPartitionKey = DocumentTabUtils.getPartitionKeyDefinition(partitionKey, partitionKeyProperty);
|
|
||||||
expect(formattedPartitionKey).toEqual({ kind: "Hash", version: 1, systemKey: true, paths: undefined });
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,10 +1,33 @@
|
|||||||
|
import { extractPartitionKey, PartitionKeyDefinition } from "@azure/cosmos";
|
||||||
|
import * as ko from "knockout";
|
||||||
|
import Q from "q";
|
||||||
|
import * as Constants from "../../Common/Constants";
|
||||||
|
import { getErrorMessage, getErrorStack } from "../../Common/ErrorHandlingUtils";
|
||||||
|
import * as Logger from "../../Common/Logger";
|
||||||
|
import {
|
||||||
|
createDocument,
|
||||||
|
deleteDocument,
|
||||||
|
queryDocuments,
|
||||||
|
readDocument,
|
||||||
|
updateDocument,
|
||||||
|
} from "../../Common/MongoProxyClient";
|
||||||
|
import MongoUtility from "../../Common/MongoUtility";
|
||||||
|
import * as DataModels from "../../Contracts/DataModels";
|
||||||
import * as ViewModels from "../../Contracts/ViewModels";
|
import * as ViewModels from "../../Contracts/ViewModels";
|
||||||
|
import { Action } from "../../Shared/Telemetry/TelemetryConstants";
|
||||||
|
import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor";
|
||||||
|
import DocumentId from "../Tree/DocumentId";
|
||||||
|
import ObjectId from "../Tree/ObjectId";
|
||||||
import DocumentsTab from "./DocumentsTab";
|
import DocumentsTab from "./DocumentsTab";
|
||||||
|
|
||||||
export default class MongoDocumentsTab extends DocumentsTab {
|
export default class MongoDocumentsTab extends DocumentsTab {
|
||||||
public collection: ViewModels.Collection;
|
public collection: ViewModels.Collection;
|
||||||
|
private continuationToken: string;
|
||||||
|
|
||||||
constructor(options: ViewModels.DocumentsTabOptions) {
|
constructor(options: ViewModels.DocumentsTabOptions) {
|
||||||
super(options);
|
super(options);
|
||||||
|
this.lastFilterContents = ko.observableArray<string>(['{"id":"foo"}', "{ qty: { $gte: 20 } }"]);
|
||||||
|
|
||||||
if (this.partitionKeyProperty && ~this.partitionKeyProperty.indexOf(`"`)) {
|
if (this.partitionKeyProperty && ~this.partitionKeyProperty.indexOf(`"`)) {
|
||||||
this.partitionKeyProperty = this.partitionKeyProperty.replace(/["]+/g, "");
|
this.partitionKeyProperty = this.partitionKeyProperty.replace(/["]+/g, "");
|
||||||
}
|
}
|
||||||
@@ -15,7 +38,279 @@ export default class MongoDocumentsTab extends DocumentsTab {
|
|||||||
this.partitionKeyPropertyHeader = "/" + this.partitionKeyProperty;
|
this.partitionKeyPropertyHeader = "/" + this.partitionKeyProperty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.isFilterExpanded = ko.observable<boolean>(true);
|
||||||
super.buildCommandBarOptions.bind(this);
|
super.buildCommandBarOptions.bind(this);
|
||||||
super.buildCommandBarOptions();
|
super.buildCommandBarOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public onSaveNewDocumentClick = (): Promise<any> => {
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
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 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);
|
||||||
|
|
||||||
|
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<any> => {
|
||||||
|
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);
|
||||||
|
|
||||||
|
this.documentIds().forEach((documentId: DocumentId) => {
|
||||||
|
if (documentId.rid === updatedDocument._rid) {
|
||||||
|
const partitionKeyArray = extractPartitionKey(
|
||||||
|
updatedDocument,
|
||||||
|
this._getPartitionKeyDefinition() as PartitionKeyDefinition
|
||||||
|
);
|
||||||
|
|
||||||
|
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));
|
||||||
|
};
|
||||||
|
|
||||||
|
public buildQuery(filter: string): string {
|
||||||
|
return filter || "{}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public async selectDocument(documentId: DocumentId): Promise<void> {
|
||||||
|
this.selectedDocumentId(documentId);
|
||||||
|
const content = await readDocument(this.collection.databaseId, this.collection, documentId);
|
||||||
|
this.initDocumentEditor(documentId, content);
|
||||||
|
}
|
||||||
|
|
||||||
|
public loadNextPage(): Q.Promise<any> {
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
|
||||||
|
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(),
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Renders a Javascript object to be displayed inside Monaco Editor */
|
||||||
|
public 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 _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,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return partitionKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected __deleteDocument(documentId: DocumentId): Promise<void> {
|
||||||
|
return deleteDocument(this.collection.databaseId, this.collection, documentId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
52
src/Explorer/Tabs/QueryTablesTab/NewQueryTablesTab.tsx
Normal file
52
src/Explorer/Tabs/QueryTablesTab/NewQueryTablesTab.tsx
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
import React from "react";
|
||||||
|
import * as DataModels from "../../../Contracts/DataModels";
|
||||||
|
import type { TabOptions } from "../../../Contracts/ViewModels";
|
||||||
|
import { useTabs } from "../../../hooks/useTabs";
|
||||||
|
import Explorer from "../../Explorer";
|
||||||
|
import TableCommands from "../../Tables/DataTable/TableCommands";
|
||||||
|
import TableEntityListViewModel from "../../Tables/DataTable/TableEntityListViewModel";
|
||||||
|
import TabsBase from "../TabsBase";
|
||||||
|
import {
|
||||||
|
IQueryTablesTabAccessor,
|
||||||
|
IQueryTablesTabComponentProps,
|
||||||
|
QueryTablesTabComponent,
|
||||||
|
} from "./QueryTablesTabComponent";
|
||||||
|
|
||||||
|
export interface IQueryTablesTabProps {
|
||||||
|
container: Explorer;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class NewQueryTablesTab extends TabsBase {
|
||||||
|
public queryText: string;
|
||||||
|
public currentQuery: string;
|
||||||
|
public partitionKey: DataModels.PartitionKey;
|
||||||
|
public iQueryTablesTabComponentProps: IQueryTablesTabComponentProps;
|
||||||
|
public tableEntityListViewModel: TableEntityListViewModel;
|
||||||
|
public tableCommands: TableCommands;
|
||||||
|
public iQueryTablesTabAccessor: IQueryTablesTabAccessor;
|
||||||
|
|
||||||
|
constructor(options: TabOptions, private props: IQueryTablesTabProps) {
|
||||||
|
super(options);
|
||||||
|
this.tableCommands = new TableCommands(props.container);
|
||||||
|
this.tableEntityListViewModel = new TableEntityListViewModel(this.tableCommands, this);
|
||||||
|
this.iQueryTablesTabComponentProps = {
|
||||||
|
collection: this.collection,
|
||||||
|
tabId: this.tabId,
|
||||||
|
tabsBaseInstance: this,
|
||||||
|
queryTablesTab: this,
|
||||||
|
container: this.props.container,
|
||||||
|
onQueryTablesTabAccessor: (instance: IQueryTablesTabAccessor) => {
|
||||||
|
this.iQueryTablesTabAccessor = instance;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public render(): JSX.Element {
|
||||||
|
return <QueryTablesTabComponent {...this.iQueryTablesTabComponentProps} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
public onTabClick(): void {
|
||||||
|
useTabs.getState().activateTab(this);
|
||||||
|
this.iQueryTablesTabAccessor.onTabClickEvent();
|
||||||
|
}
|
||||||
|
}
|
||||||
619
src/Explorer/Tabs/QueryTablesTab/QueryTablesTabComponent.tsx
Normal file
619
src/Explorer/Tabs/QueryTablesTab/QueryTablesTabComponent.tsx
Normal file
@@ -0,0 +1,619 @@
|
|||||||
|
import React from "react";
|
||||||
|
import AddEntityIcon from "../../../../images/AddEntity.svg";
|
||||||
|
import DeleteEntitiesIcon from "../../../../images/DeleteEntities.svg";
|
||||||
|
import EditEntityIcon from "../../../../images/Edit-entity.svg";
|
||||||
|
import ExecuteQueryIcon from "../../../../images/ExecuteQuery.svg";
|
||||||
|
import QueryBuilderIcon from "../../../../images/Query-Builder.svg";
|
||||||
|
import QueryTextIcon from "../../../../images/Query-Text.svg";
|
||||||
|
import * as ViewModels from "../../../Contracts/ViewModels";
|
||||||
|
import { useSidePanel } from "../../../hooks/useSidePanel";
|
||||||
|
import { userContext } from "../../../UserContext";
|
||||||
|
import { CommandButtonComponentProps } from "../../Controls/CommandButton/CommandButtonComponent";
|
||||||
|
import Explorer from "../../Explorer";
|
||||||
|
import { AddTableEntityPanel } from "../../Panes/Tables/AddTableEntityPanel";
|
||||||
|
import { EditTableEntityPanel } from "../../Panes/Tables/EditTableEntityPanel";
|
||||||
|
import TableCommands from "../../Tables/DataTable/TableCommands";
|
||||||
|
import TableEntityListViewModel from "../../Tables/DataTable/TableEntityListViewModel";
|
||||||
|
import QueryViewModel from "../../Tables/QueryBuilder/QueryViewModel";
|
||||||
|
import { CassandraAPIDataClient, TableDataClient } from "../../Tables/TableDataClient";
|
||||||
|
import TabsBase from "../TabsBase";
|
||||||
|
import { NewQueryTablesTab } from "./NewQueryTablesTab";
|
||||||
|
|
||||||
|
export interface IQueryTablesTabAccessor {
|
||||||
|
onTabClickEvent: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Button {
|
||||||
|
visible: boolean;
|
||||||
|
enabled: boolean;
|
||||||
|
isSelected?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IQueryTablesTabComponentStates {
|
||||||
|
queryViewModel: QueryViewModel;
|
||||||
|
queryText: string;
|
||||||
|
selectedQueryText: string;
|
||||||
|
executeQueryButton: Button;
|
||||||
|
queryBuilderButton: Button;
|
||||||
|
queryTextButton: Button;
|
||||||
|
addEntityButton: Button;
|
||||||
|
editEntityButton: Button;
|
||||||
|
deleteEntityButton: Button;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IQueryTablesTabComponentProps {
|
||||||
|
collection: ViewModels.CollectionBase;
|
||||||
|
tabsBaseInstance: TabsBase;
|
||||||
|
tabId: string;
|
||||||
|
queryTablesTab: NewQueryTablesTab;
|
||||||
|
container: Explorer;
|
||||||
|
onQueryTablesTabAccessor: (instance: IQueryTablesTabAccessor) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class QueryTablesTabComponent extends React.Component<
|
||||||
|
IQueryTablesTabComponentProps,
|
||||||
|
IQueryTablesTabComponentStates
|
||||||
|
> {
|
||||||
|
public collection: ViewModels.Collection;
|
||||||
|
public tableEntityListViewModel: TableEntityListViewModel;
|
||||||
|
public tableCommands: TableCommands;
|
||||||
|
public tableDataClient: TableDataClient;
|
||||||
|
public container: Explorer;
|
||||||
|
public queryViewModel: QueryViewModel;
|
||||||
|
|
||||||
|
constructor(props: IQueryTablesTabComponentProps) {
|
||||||
|
super(props);
|
||||||
|
this.container = props.collection && props.collection.container;
|
||||||
|
this.tableCommands = new TableCommands(this.container);
|
||||||
|
this.tableDataClient = this.container.tableDataClient;
|
||||||
|
this.tableEntityListViewModel = new TableEntityListViewModel(this.tableCommands, props.queryTablesTab);
|
||||||
|
this.tableEntityListViewModel.queryTablesTab = props.queryTablesTab;
|
||||||
|
this.queryViewModel = new QueryViewModel(props.queryTablesTab);
|
||||||
|
this.state = {
|
||||||
|
queryViewModel: this.queryViewModel,
|
||||||
|
queryText: "PartitionKey eq 'partitionKey1'",
|
||||||
|
selectedQueryText: "",
|
||||||
|
executeQueryButton: {
|
||||||
|
enabled: true,
|
||||||
|
visible: true,
|
||||||
|
},
|
||||||
|
queryBuilderButton: {
|
||||||
|
enabled: true,
|
||||||
|
visible: true,
|
||||||
|
isSelected: this.queryViewModel ? this.queryViewModel.isHelperActive() : false,
|
||||||
|
},
|
||||||
|
queryTextButton: {
|
||||||
|
enabled: true,
|
||||||
|
visible: true,
|
||||||
|
isSelected: this.queryViewModel ? this.queryViewModel.isEditorActive() : false,
|
||||||
|
},
|
||||||
|
addEntityButton: {
|
||||||
|
enabled: true,
|
||||||
|
visible: true,
|
||||||
|
},
|
||||||
|
editEntityButton: {
|
||||||
|
enabled: this.tableCommands.isEnabled(
|
||||||
|
TableCommands.editEntityCommand,
|
||||||
|
this.tableEntityListViewModel.selected()
|
||||||
|
),
|
||||||
|
visible: true,
|
||||||
|
},
|
||||||
|
deleteEntityButton: {
|
||||||
|
enabled: this.tableCommands.isEnabled(
|
||||||
|
TableCommands.deleteEntitiesCommand,
|
||||||
|
this.tableEntityListViewModel.selected()
|
||||||
|
),
|
||||||
|
visible: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
if (this.tableEntityListViewModel.items().length > 0 && userContext.apiType === "Tables") {
|
||||||
|
const sampleQuerySubscription = this.state.queryViewModel.queryBuilderViewModel().setExample();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public onExecuteQueryClick(): void {
|
||||||
|
this.state.queryViewModel.runQuery();
|
||||||
|
}
|
||||||
|
|
||||||
|
public onQueryBuilderClick(): void {
|
||||||
|
this.state.queryViewModel.selectHelper();
|
||||||
|
}
|
||||||
|
|
||||||
|
public onQueryTextClick(): void {
|
||||||
|
this.state.queryViewModel.selectEditor();
|
||||||
|
}
|
||||||
|
|
||||||
|
public onAddEntityClick(): void {
|
||||||
|
useSidePanel
|
||||||
|
.getState()
|
||||||
|
.openSidePanel(
|
||||||
|
"Add Table Row",
|
||||||
|
<AddTableEntityPanel
|
||||||
|
tableDataClient={this.tableDataClient}
|
||||||
|
queryTablesTab={this.props.queryTablesTab}
|
||||||
|
tableEntityListViewModel={this.tableEntityListViewModel}
|
||||||
|
cassandraApiClient={new CassandraAPIDataClient()}
|
||||||
|
/>,
|
||||||
|
"700px"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public onEditEntityClick(): void {
|
||||||
|
useSidePanel
|
||||||
|
.getState()
|
||||||
|
.openSidePanel(
|
||||||
|
"Edit Table Entity",
|
||||||
|
<EditTableEntityPanel
|
||||||
|
tableDataClient={this.tableDataClient}
|
||||||
|
queryTablesTab={this.props.queryTablesTab}
|
||||||
|
tableEntityListViewModel={this.tableEntityListViewModel}
|
||||||
|
cassandraApiClient={new CassandraAPIDataClient()}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public onDeleteEntityClick(): void {
|
||||||
|
this.tableCommands.deleteEntitiesCommand(this.tableEntityListViewModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public onActivate(): void {
|
||||||
|
const columns =
|
||||||
|
!!this.tableEntityListViewModel &&
|
||||||
|
!!this.tableEntityListViewModel.table &&
|
||||||
|
this.tableEntityListViewModel.table.columns;
|
||||||
|
if (!!columns) {
|
||||||
|
columns.adjust();
|
||||||
|
$(window).resize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public getTabsButtons(): CommandButtonComponentProps[] {
|
||||||
|
const buttons: CommandButtonComponentProps[] = [];
|
||||||
|
if (this.state.queryBuilderButton.visible) {
|
||||||
|
const label = userContext.apiType === "Cassandra" ? "CQL Query Builder" : "Query Builder";
|
||||||
|
buttons.push({
|
||||||
|
iconSrc: QueryBuilderIcon,
|
||||||
|
iconAlt: label,
|
||||||
|
onCommandClick: this.onQueryBuilderClick,
|
||||||
|
commandButtonLabel: label,
|
||||||
|
ariaLabel: label,
|
||||||
|
hasPopup: false,
|
||||||
|
disabled: !this.state.queryBuilderButton.enabled,
|
||||||
|
isSelected: this.state.queryBuilderButton.isSelected,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.state.queryTextButton.visible) {
|
||||||
|
const label = userContext.apiType === "Cassandra" ? "CQL Query Text" : "Query Text";
|
||||||
|
buttons.push({
|
||||||
|
iconSrc: QueryTextIcon,
|
||||||
|
iconAlt: label,
|
||||||
|
onCommandClick: this.onQueryTextClick,
|
||||||
|
commandButtonLabel: label,
|
||||||
|
ariaLabel: label,
|
||||||
|
hasPopup: false,
|
||||||
|
disabled: !this.state.queryTextButton.enabled,
|
||||||
|
isSelected: this.state.queryTextButton.isSelected,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.state.executeQueryButton.visible) {
|
||||||
|
const label = "Run Query";
|
||||||
|
buttons.push({
|
||||||
|
iconSrc: ExecuteQueryIcon,
|
||||||
|
iconAlt: label,
|
||||||
|
onCommandClick: this.onExecuteQueryClick,
|
||||||
|
commandButtonLabel: label,
|
||||||
|
ariaLabel: label,
|
||||||
|
hasPopup: false,
|
||||||
|
disabled: !this.state.executeQueryButton.enabled,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.state.addEntityButton.visible) {
|
||||||
|
const label = userContext.apiType === "Cassandra" ? "Add Row" : "Add Entity";
|
||||||
|
buttons.push({
|
||||||
|
iconSrc: AddEntityIcon,
|
||||||
|
iconAlt: label,
|
||||||
|
onCommandClick: this.onAddEntityClick,
|
||||||
|
commandButtonLabel: label,
|
||||||
|
ariaLabel: label,
|
||||||
|
hasPopup: true,
|
||||||
|
disabled: !this.state.addEntityButton.enabled,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.state.editEntityButton.visible) {
|
||||||
|
const label = userContext.apiType === "Cassandra" ? "Edit Row" : "Edit Entity";
|
||||||
|
buttons.push({
|
||||||
|
iconSrc: EditEntityIcon,
|
||||||
|
iconAlt: label,
|
||||||
|
onCommandClick: this.onEditEntityClick,
|
||||||
|
commandButtonLabel: label,
|
||||||
|
ariaLabel: label,
|
||||||
|
hasPopup: true,
|
||||||
|
disabled: !this.state.editEntityButton.enabled,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.state.deleteEntityButton.visible) {
|
||||||
|
const label = userContext.apiType === "Cassandra" ? "Delete Rows" : "Delete Entities";
|
||||||
|
buttons.push({
|
||||||
|
iconSrc: DeleteEntitiesIcon,
|
||||||
|
iconAlt: label,
|
||||||
|
onCommandClick: this.onDeleteEntityClick,
|
||||||
|
commandButtonLabel: label,
|
||||||
|
ariaLabel: label,
|
||||||
|
hasPopup: true,
|
||||||
|
disabled: !this.state.deleteEntityButton.enabled,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return buttons;
|
||||||
|
}
|
||||||
|
|
||||||
|
public render(): JSX.Element {
|
||||||
|
const { tabId } = this.props;
|
||||||
|
const { queryViewModel, queryText } = this.state;
|
||||||
|
const {
|
||||||
|
isEditorActive,
|
||||||
|
isHelperActive,
|
||||||
|
hasQueryError,
|
||||||
|
queryErrorMessage,
|
||||||
|
queryBuilderViewModel,
|
||||||
|
toggleAdvancedOptions,
|
||||||
|
ontoggleAdvancedOptionsKeyDown,
|
||||||
|
} = queryViewModel;
|
||||||
|
const {
|
||||||
|
canGroupClauses,
|
||||||
|
andLabel,
|
||||||
|
actionLabel,
|
||||||
|
groupClauses,
|
||||||
|
groupSelectedClauses,
|
||||||
|
fieldLabel,
|
||||||
|
dataTypeLabel,
|
||||||
|
operatorLabel,
|
||||||
|
valueLabel,
|
||||||
|
clauseArray,
|
||||||
|
columnOptions,
|
||||||
|
clauseRules,
|
||||||
|
operators,
|
||||||
|
insertNewFilterLine,
|
||||||
|
onAddClauseKeyDown,
|
||||||
|
addClauseIndex,
|
||||||
|
removeThisFilterLine,
|
||||||
|
onDeleteClauseKeyDown,
|
||||||
|
deleteClause,
|
||||||
|
getClauseGroupViewModels,
|
||||||
|
updateColumnOptions,
|
||||||
|
edmTypes,
|
||||||
|
addNewClause,
|
||||||
|
addNewClauseLine,
|
||||||
|
} = queryBuilderViewModel();
|
||||||
|
console.log("queryBuilderViewModel()", queryBuilderViewModel());
|
||||||
|
console.log("clauseArray()", clauseArray());
|
||||||
|
console.log("clauseRules()", clauseRules());
|
||||||
|
console.log("columnOptions()", columnOptions());
|
||||||
|
console.log("operators()", operators());
|
||||||
|
return (
|
||||||
|
<div className="tab-pane tableContainer" id={tabId} role="tabpanel">
|
||||||
|
<div className="query-builder" id={queryViewModel.id}>
|
||||||
|
<div className="error-bar">
|
||||||
|
{hasQueryError && (
|
||||||
|
<div className="error-message" aria-label="Error Message">
|
||||||
|
<span>
|
||||||
|
<img className="entity-error-Img" src="/error_red.svg" />
|
||||||
|
</span>
|
||||||
|
<span className="error-text" role="alert">
|
||||||
|
{queryErrorMessage}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{isEditorActive() && (
|
||||||
|
<div className="query-editor-panel">
|
||||||
|
<div>
|
||||||
|
<textarea
|
||||||
|
className="query-editor-text"
|
||||||
|
data-bind="
|
||||||
|
css: { 'query-editor-text-invalid': hasQueryError },
|
||||||
|
readOnly: true"
|
||||||
|
name="query-editor"
|
||||||
|
rows={5}
|
||||||
|
cols={100}
|
||||||
|
>
|
||||||
|
{queryText}
|
||||||
|
</textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{isHelperActive && (
|
||||||
|
<div style={{ paddingLeft: "13px" }}>
|
||||||
|
<div className="clause-table" data-bind="with: queryBuilderViewModel ">
|
||||||
|
<div className="scroll-box scrollable" id="scroll">
|
||||||
|
<table className="clause-table">
|
||||||
|
<thead>
|
||||||
|
<tr className="clause-table-row">
|
||||||
|
<th className="clause-table-cell header-background action-header">
|
||||||
|
<span>{actionLabel}</span>
|
||||||
|
</th>
|
||||||
|
<th className="clause-table-cell header-background group-control-header">
|
||||||
|
{canGroupClauses && (
|
||||||
|
<button type="button" onClick={groupClauses} title={groupSelectedClauses}>
|
||||||
|
<img className="and-or-svg" src="/And-Or.svg" alt="Group selected clauses" />
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</th>
|
||||||
|
<th className="clause-table-cell header-background"></th>
|
||||||
|
<th className="clause-table-cell header-background and-or-header">
|
||||||
|
<span>{andLabel}</span>
|
||||||
|
</th>
|
||||||
|
<th className="clause-table-cell header-background field-header">
|
||||||
|
<span>{fieldLabel}</span>
|
||||||
|
</th>
|
||||||
|
<th className="clause-table-cell header-background type-header">
|
||||||
|
<span>{dataTypeLabel}</span>
|
||||||
|
</th>
|
||||||
|
<th className="clause-table-cell header-background operator-header">
|
||||||
|
<span>{operatorLabel}</span>
|
||||||
|
</th>
|
||||||
|
<th className="clause-table-cell header-background value-header">
|
||||||
|
<span>{valueLabel}</span>
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{clauseArray().map((data, index) => (
|
||||||
|
<tr className="clause-table-row">
|
||||||
|
<td className="clause-table-cell action-column">
|
||||||
|
<span
|
||||||
|
className="entity-Add-Cancel"
|
||||||
|
role="button"
|
||||||
|
tabIndex={0}
|
||||||
|
onClick={addClauseIndex.bind(data, index)}
|
||||||
|
onKeyDown={onAddClauseKeyDown.bind(data, index)}
|
||||||
|
title={insertNewFilterLine}
|
||||||
|
>
|
||||||
|
<img className="querybuilder-addpropertyImg" src="/Add-property.svg" alt="Add clause" />
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
className="entity-Add-Cancel"
|
||||||
|
role="button"
|
||||||
|
tabIndex={0}
|
||||||
|
data-bind="hasFocus: isDeleteButtonFocused"
|
||||||
|
onClick={deleteClause.bind(data, index)}
|
||||||
|
onKeyDown={onDeleteClauseKeyDown.bind(data, index)}
|
||||||
|
title={removeThisFilterLine}
|
||||||
|
>
|
||||||
|
<img className="querybuilder-cancelImg" src="/Entity_cancel.svg" alt="Delete clause" />
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
{/* <td className="clause-table-cell group-control-column">
|
||||||
|
<input type="checkbox" aria-label="And/Or" checked={checkedForGrouping} />
|
||||||
|
</td> */}
|
||||||
|
{/* <td>
|
||||||
|
<table className="group-indicator-table">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
{getClauseGroupViewModels(data).map((gi, index) => (
|
||||||
|
<td
|
||||||
|
className="group-indicator-column"
|
||||||
|
style={{
|
||||||
|
backgroundColor: gi.backgroundColor,
|
||||||
|
borderTop: gi.showTopBorder.peek() ? "solid thin #CCCCCC" : "none",
|
||||||
|
borderLeft: gi.showLeftBorder.peek() ? "solid thin #CCCCCC" : "none",
|
||||||
|
borderBottom: gi.showBottomBorder.peek()
|
||||||
|
? "solid thin #CCCCCC"
|
||||||
|
: gi.borderBackgroundColor,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{gi.canUngroup && (
|
||||||
|
<button type="button" onClick={} title={ungroupClausesLabel}>
|
||||||
|
<img src="/QueryBuilder/UngroupClause_16x.png" alt="Ungroup clauses" />
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
))}
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
<td className="clause-table-cell and-or-column">
|
||||||
|
{canAnd && (
|
||||||
|
<select
|
||||||
|
className="clause-table-field and-or-column"
|
||||||
|
data-bind=" value: and_or, "
|
||||||
|
autoFocus={isAndOrFocused}
|
||||||
|
aria-label=" and_or "
|
||||||
|
>
|
||||||
|
{clauseRules().map((data, index) => (
|
||||||
|
<option value={data}>{data}</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
<td className="clause-table-cell field-column" onClick={updateColumnOptions}>
|
||||||
|
<select
|
||||||
|
aria-label={field}
|
||||||
|
className="clause-table-field field-column"
|
||||||
|
data-bind=" value: field"
|
||||||
|
>
|
||||||
|
{columnOptions().map((data, index) => (
|
||||||
|
<option value={data}>{data}</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
<td className="clause-table-cell type-column">
|
||||||
|
{isTypeEditable && (
|
||||||
|
<select
|
||||||
|
className="clause-table-field type-column"
|
||||||
|
aria-label={type}
|
||||||
|
value={type}
|
||||||
|
data-bind="css: {'query-builder-isDisabled': !isTypeEditable()}"
|
||||||
|
>
|
||||||
|
{edmTypes.map((data) => (
|
||||||
|
<option>{parent.edmTypes} </option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
<td className="clause-table-cell operator-column">
|
||||||
|
{isOperaterEditable && (
|
||||||
|
<select
|
||||||
|
className="clause-table-field operator-column"
|
||||||
|
aria-label={operator}
|
||||||
|
data-bind="
|
||||||
|
value: operator,
|
||||||
|
css: {'query-builder-isDisabled': !isOperaterEditable()}"
|
||||||
|
>
|
||||||
|
{operators().map((data, index) => (
|
||||||
|
<option key={index}>{data}</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
<td className="clause-table-cell value-column">
|
||||||
|
{isValue && (
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
className="clause-table-field value-column"
|
||||||
|
type="search"
|
||||||
|
data-bind="textInput: value"
|
||||||
|
aria-label={valueLabel}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{isTimestamp && (
|
||||||
|
<select
|
||||||
|
className="clause-table-field time-column"
|
||||||
|
data-bind="options: $parent.timeOptions, value: timeValue"
|
||||||
|
></select>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{isCustomLastTimestamp && (
|
||||||
|
<input
|
||||||
|
className="clause-table-field time-column"
|
||||||
|
value={customTimeValue}
|
||||||
|
onClick={customTimestampDialog}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{isCustomRangeTimestamp && (
|
||||||
|
<input
|
||||||
|
className="clause-table-field time-column"
|
||||||
|
type="datetime-local"
|
||||||
|
step="1"
|
||||||
|
value={customTimeValue}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
*/}
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className="addClause"
|
||||||
|
role="button"
|
||||||
|
onClick={addNewClause}
|
||||||
|
data-bind="event: { keydown: onAddNewClauseKeyDown }"
|
||||||
|
title={addNewClauseLine}
|
||||||
|
tabIndex={0}
|
||||||
|
>
|
||||||
|
<div className="addClause-heading">
|
||||||
|
<span className="clause-table addClause-title">
|
||||||
|
<img
|
||||||
|
className="addclauseProperty-Img"
|
||||||
|
style={{ marginBottom: "5px" }}
|
||||||
|
src="/Add-property.svg"
|
||||||
|
alt="Add new clause"
|
||||||
|
/>
|
||||||
|
<span style={{ marginLeft: "5px" }}>{addNewClauseLine}</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div className="advanced-options-panel">
|
||||||
|
{/* <div className="advanced-heading">
|
||||||
|
<span
|
||||||
|
className="advanced-title"
|
||||||
|
role="button"
|
||||||
|
onClick={toggleAdvancedOptions}
|
||||||
|
onKeyDown={ontoggleAdvancedOptionsKeyDown}
|
||||||
|
aria-expanded={isExpanded() ? "true" : "false"}
|
||||||
|
tabIndex={0}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="themed-images"
|
||||||
|
type="text/html"
|
||||||
|
id="ExpandChevronRight"
|
||||||
|
data-bind="hasFocus: focusExpandIcon"
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
className="imgiconwidth expand-triangle expand-triangle-right"
|
||||||
|
src="/Triangle-right.svg"
|
||||||
|
alt="toggle"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="themed-images" type="text/html" id="ExpandChevronDown">
|
||||||
|
<img className="imgiconwidth expand-triangle" src="/Triangle-down.svg" alt="toggle" />
|
||||||
|
</div>
|
||||||
|
<span>Advanced Options</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
{isExpanded && (
|
||||||
|
<div className="advanced-options">
|
||||||
|
<div className="top">
|
||||||
|
<span>Show top results:</span>
|
||||||
|
<input
|
||||||
|
className="top-input"
|
||||||
|
type="number"
|
||||||
|
autoFocus={focusTopResult}
|
||||||
|
value={topValue}
|
||||||
|
title={topValueLimitMessage}
|
||||||
|
role="textbox"
|
||||||
|
aria-label="Show top results"
|
||||||
|
/>
|
||||||
|
{isExceedingLimit && (
|
||||||
|
<div role="alert" aria-atomic="true" className="inline-div">
|
||||||
|
<img className="advanced-options-icon" src="/QueryBuilder/StatusWarning_16x.png" />
|
||||||
|
<span>{topValueLimitMessage}</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="select">
|
||||||
|
<span> Select fields for query: </span>
|
||||||
|
{isSelected && (
|
||||||
|
<div>
|
||||||
|
<img className="advanced-options-icon" src="/QueryBuilder/QueryInformation_16x.png" />
|
||||||
|
<span className="select-options-text">{selectMessage}</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<a
|
||||||
|
className="select-options-link"
|
||||||
|
onKeyDown={onselectQueryOptionsKeyDown}
|
||||||
|
onClick={selectQueryOptions}
|
||||||
|
tabIndex={0}
|
||||||
|
role="link"
|
||||||
|
>
|
||||||
|
<span>Choose Columns... </span>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)} */}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="tablesQueryTab tableContainer" id={this.tableEntityListViewModel.id}>
|
||||||
|
<table
|
||||||
|
id="storageTable"
|
||||||
|
className="storage azure-table show-gridlines"
|
||||||
|
tabIndex={0}
|
||||||
|
data-bind="tableSource: items, tableSelection: selected"
|
||||||
|
></table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -32,7 +32,7 @@ import MongoDocumentsTab from "../Tabs/MongoDocumentsTab";
|
|||||||
import { NewMongoQueryTab } from "../Tabs/MongoQueryTab/MongoQueryTab";
|
import { NewMongoQueryTab } from "../Tabs/MongoQueryTab/MongoQueryTab";
|
||||||
import { NewMongoShellTab } from "../Tabs/MongoShellTab/MongoShellTab";
|
import { NewMongoShellTab } from "../Tabs/MongoShellTab/MongoShellTab";
|
||||||
import { NewQueryTab } from "../Tabs/QueryTab/QueryTab";
|
import { NewQueryTab } from "../Tabs/QueryTab/QueryTab";
|
||||||
import QueryTablesTab from "../Tabs/QueryTablesTab";
|
import { NewQueryTablesTab } from "../Tabs/QueryTablesTab/NewQueryTablesTab";
|
||||||
import { CollectionSettingsTabV2 } from "../Tabs/SettingsTabV2";
|
import { CollectionSettingsTabV2 } from "../Tabs/SettingsTabV2";
|
||||||
import { useDatabases } from "../useDatabases";
|
import { useDatabases } from "../useDatabases";
|
||||||
import { useSelectedNode } from "../useSelectedNode";
|
import { useSelectedNode } from "../useSelectedNode";
|
||||||
@@ -391,13 +391,13 @@ export default class Collection implements ViewModels.Collection {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const queryTablesTabs: QueryTablesTab[] = useTabs
|
const queryTablesTabs: NewQueryTablesTab[] = useTabs
|
||||||
.getState()
|
.getState()
|
||||||
.getTabs(
|
.getTabs(
|
||||||
ViewModels.CollectionTabKind.QueryTables,
|
ViewModels.CollectionTabKind.QueryTables,
|
||||||
(tab) => tab.collection && tab.collection.databaseId === this.databaseId && tab.collection.id() === this.id()
|
(tab) => tab.collection && tab.collection.databaseId === this.databaseId && tab.collection.id() === this.id()
|
||||||
) as QueryTablesTab[];
|
) as NewQueryTablesTab[];
|
||||||
let queryTablesTab: QueryTablesTab = queryTablesTabs && queryTablesTabs[0];
|
let queryTablesTab: NewQueryTablesTab = queryTablesTabs && queryTablesTabs[0];
|
||||||
|
|
||||||
if (queryTablesTab) {
|
if (queryTablesTab) {
|
||||||
useTabs.getState().activateTab(queryTablesTab);
|
useTabs.getState().activateTab(queryTablesTab);
|
||||||
@@ -415,14 +415,14 @@ export default class Collection implements ViewModels.Collection {
|
|||||||
tabTitle: title,
|
tabTitle: title,
|
||||||
});
|
});
|
||||||
|
|
||||||
queryTablesTab = new QueryTablesTab({
|
queryTablesTab = new NewQueryTablesTab({
|
||||||
tabKind: ViewModels.CollectionTabKind.QueryTables,
|
tabKind: ViewModels.CollectionTabKind.QueryTables,
|
||||||
title: title,
|
title: title,
|
||||||
tabPath: "",
|
tabPath: "",
|
||||||
collection: this,
|
collection: this,
|
||||||
node: this,
|
node: this,
|
||||||
onLoadStartKey: startKey,
|
onLoadStartKey: startKey,
|
||||||
});
|
}, { container: this.container });
|
||||||
|
|
||||||
useTabs.getState().activateNewTab(queryTablesTab);
|
useTabs.getState().activateNewTab(queryTablesTab);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ export default class DocumentId {
|
|||||||
public partitionKeyValue: any;
|
public partitionKeyValue: any;
|
||||||
public stringPartitionKeyValue: string;
|
public stringPartitionKeyValue: string;
|
||||||
public isDirty: ko.Observable<boolean>;
|
public isDirty: ko.Observable<boolean>;
|
||||||
public _partitionKeyValue: string;
|
|
||||||
|
|
||||||
constructor(container: DocumentsTab, data: any, partitionKeyValue: any) {
|
constructor(container: DocumentsTab, data: any, partitionKeyValue: any) {
|
||||||
this.container = container;
|
this.container = container;
|
||||||
@@ -28,6 +27,13 @@ export default class DocumentId {
|
|||||||
this.isDirty = ko.observable(false);
|
this.isDirty = ko.observable(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public click() {
|
||||||
|
if (!this.container.isEditorDirty() || window.confirm("Your unsaved changes will be lost.")) {
|
||||||
|
this.loadDocument();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
public partitionKeyHeader(): Object {
|
public partitionKeyHeader(): Object {
|
||||||
if (!this.partitionKeyProperty) {
|
if (!this.partitionKeyProperty) {
|
||||||
return undefined;
|
return undefined;
|
||||||
@@ -58,4 +64,8 @@ export default class DocumentId {
|
|||||||
|
|
||||||
return JSON.stringify(partitionKeyValue);
|
return JSON.stringify(partitionKeyValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async loadDocument(): Promise<void> {
|
||||||
|
await this.container.selectDocument(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import * as ko from "knockout";
|
import * as ko from "knockout";
|
||||||
import DocumentsTab from "../Tabs/DocumentsTab";
|
|
||||||
import DocumentId from "./DocumentId";
|
import DocumentId from "./DocumentId";
|
||||||
|
import DocumentsTab from "../Tabs/DocumentsTab";
|
||||||
|
|
||||||
export default class ObjectId extends DocumentId {
|
export default class ObjectId extends DocumentId {
|
||||||
constructor(container: DocumentsTab, data: any, partitionKeyValue: any) {
|
constructor(container: DocumentsTab, data: any, partitionKeyValue: any) {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import _ from "underscore";
|
|||||||
import create, { UseStore } from "zustand";
|
import create, { UseStore } from "zustand";
|
||||||
import * as Constants from "../Common/Constants";
|
import * as Constants from "../Common/Constants";
|
||||||
import * as ViewModels from "../Contracts/ViewModels";
|
import * as ViewModels from "../Contracts/ViewModels";
|
||||||
import { userContext } from "../UserContext";
|
|
||||||
import { useSelectedNode } from "./useSelectedNode";
|
import { useSelectedNode } from "./useSelectedNode";
|
||||||
|
|
||||||
interface DatabasesState {
|
interface DatabasesState {
|
||||||
@@ -137,11 +136,6 @@ export const useDatabases: UseStore<DatabasesState> = create((set, get) => ({
|
|||||||
},
|
},
|
||||||
validateCollectionId: async (databaseId: string, collectionId: string): Promise<boolean> => {
|
validateCollectionId: async (databaseId: string, collectionId: string): Promise<boolean> => {
|
||||||
const database = get().databases.find((db) => db.id() === databaseId);
|
const database = get().databases.find((db) => db.id() === databaseId);
|
||||||
// For a new tables account, database is undefined when creating the first table
|
|
||||||
if (!database && userContext.apiType === "Tables") {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
await database.loadCollections();
|
await database.loadCollections();
|
||||||
return !database.collections().some((collection) => collection.id() === collectionId);
|
return !database.collections().some((collection) => collection.id() === collectionId);
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user