More ViewModel cleanup (#116)

This commit is contained in:
Steve Faulkner
2020-07-27 16:05:25 -05:00
committed by GitHub
parent 2e49ed45c3
commit fea321cd68
97 changed files with 492 additions and 1904 deletions

View File

@@ -240,9 +240,7 @@ export default class Collection implements ViewModels.Collection {
this.expandCollection();
}
this.container.onUpdateTabsButtons([]);
this.container.tabsManager.refreshActiveTab(
(tab: ViewModels.Tab) => tab.collection && tab.collection.rid === this.rid
);
this.container.tabsManager.refreshActiveTab(tab => tab.collection && tab.collection.rid === this.rid);
}
public collapseCollection() {
@@ -293,7 +291,7 @@ export default class Collection implements ViewModels.Collection {
const documentsTabs: DocumentsTab[] = this.container.tabsManager.getTabs(
ViewModels.CollectionTabKind.Documents,
(tab: ViewModels.Tab) => tab.collection && tab.collection.rid === this.rid
tab => tab.collection && tab.collection.rid === this.rid
) as DocumentsTab[];
let documentsTab: DocumentsTab = documentsTabs && documentsTabs[0];
@@ -344,7 +342,7 @@ export default class Collection implements ViewModels.Collection {
const conflictsTabs: ConflictsTab[] = this.container.tabsManager.getTabs(
ViewModels.CollectionTabKind.Conflicts,
(tab: ViewModels.Tab) => tab.collection && tab.collection.rid === this.rid
tab => tab.collection && tab.collection.rid === this.rid
) as ConflictsTab[];
let conflictsTab: ConflictsTab = conflictsTabs && conflictsTabs[0];
@@ -401,7 +399,7 @@ export default class Collection implements ViewModels.Collection {
const queryTablesTabs: QueryTablesTab[] = this.container.tabsManager.getTabs(
ViewModels.CollectionTabKind.QueryTables,
(tab: ViewModels.Tab) => tab.collection && tab.collection.rid === this.rid
tab => tab.collection && tab.collection.rid === this.rid
) as QueryTablesTab[];
let queryTablesTab: QueryTablesTab = queryTablesTabs && queryTablesTabs[0];
@@ -455,7 +453,7 @@ export default class Collection implements ViewModels.Collection {
const graphTabs: GraphTab[] = this.container.tabsManager.getTabs(
ViewModels.CollectionTabKind.Graph,
(tab: ViewModels.Tab) => tab.collection && tab.collection.rid === this.rid
tab => tab.collection && tab.collection.rid === this.rid
) as GraphTab[];
let graphTab: GraphTab = graphTabs && graphTabs[0];
@@ -511,7 +509,7 @@ export default class Collection implements ViewModels.Collection {
const mongoDocumentsTabs: MongoDocumentsTab[] = this.container.tabsManager.getTabs(
ViewModels.CollectionTabKind.Documents,
(tab: ViewModels.Tab) => tab.collection && tab.collection.rid === this.rid
tab => tab.collection && tab.collection.rid === this.rid
) as MongoDocumentsTab[];
let mongoDocumentsTab: MongoDocumentsTab = mongoDocumentsTabs && mongoDocumentsTabs[0];
@@ -562,12 +560,9 @@ export default class Collection implements ViewModels.Collection {
const tabTitle = !this.offer() ? "Settings" : "Scale & Settings";
const pendingNotificationsPromise: Q.Promise<DataModels.Notification> = this._getPendingThroughputSplitNotification();
const matchingTabs: ViewModels.Tab[] = this.container.tabsManager.getTabs(
ViewModels.CollectionTabKind.Settings,
(tab: ViewModels.Tab) => {
return tab.collection && tab.collection.rid === this.rid;
}
);
const matchingTabs = this.container.tabsManager.getTabs(ViewModels.CollectionTabKind.Settings, tab => {
return tab.collection && tab.collection.rid === this.rid;
});
let settingsTab: SettingsTab = matchingTabs && (matchingTabs[0] as SettingsTab);
if (!settingsTab) {
@@ -902,9 +897,7 @@ export default class Collection implements ViewModels.Collection {
} else {
this.expandStoredProcedures();
}
this.container.tabsManager.refreshActiveTab(
(tab: ViewModels.Tab) => tab.collection && tab.collection.rid === this.rid
);
this.container.tabsManager.refreshActiveTab(tab => tab.collection && tab.collection.rid === this.rid);
}
public expandStoredProcedures() {
@@ -961,9 +954,7 @@ export default class Collection implements ViewModels.Collection {
} else {
this.expandUserDefinedFunctions();
}
this.container.tabsManager.refreshActiveTab(
(tab: ViewModels.Tab) => tab.collection && tab.collection.rid === this.rid
);
this.container.tabsManager.refreshActiveTab(tab => tab.collection && tab.collection.rid === this.rid);
}
public expandUserDefinedFunctions() {
@@ -1020,9 +1011,7 @@ export default class Collection implements ViewModels.Collection {
} else {
this.expandTriggers();
}
this.container.tabsManager.refreshActiveTab(
(tab: ViewModels.Tab) => tab.collection && tab.collection.rid === this.rid
);
this.container.tabsManager.refreshActiveTab(tab => tab.collection && tab.collection.rid === this.rid);
}
public expandTriggers() {

View File

@@ -8,7 +8,7 @@ import { extractPartitionKey } from "@azure/cosmos";
import ConflictsTab from "../Tabs/ConflictsTab";
import { readDocument } from "../../Common/DocumentClientUtilityBase";
export default class ConflictId implements ViewModels.ConflictId {
export default class ConflictId {
public container: ConflictsTab;
public rid: string;
public self: string;
@@ -115,7 +115,7 @@ export default class ConflictId implements ViewModels.ConflictId {
return JSON.stringify(partitionKeyValue);
}
public buildDocumentIdFromConflict(partitionKeyValue: any): ViewModels.DocumentId {
public buildDocumentIdFromConflict(partitionKeyValue: any): DocumentId {
const conflictDocumentRid = Constants.HashRoutePrefixes.docsWithIds(
this.container.collection.getDatabase().rid,
this.container.collection.rid,

View File

@@ -52,9 +52,9 @@ export default class Database implements ViewModels.Database {
});
const pendingNotificationsPromise: Q.Promise<DataModels.Notification> = this._getPendingThroughputSplitNotification();
const matchingTabs: ViewModels.Tab[] = this.container.tabsManager.getTabs(
const matchingTabs = this.container.tabsManager.getTabs(
ViewModels.CollectionTabKind.DatabaseSettings,
(tab: ViewModels.Tab) => tab.rid === this.rid
tab => tab.rid === this.rid
);
let settingsTab: DatabaseSettingsTab = matchingTabs && (matchingTabs[0] as DatabaseSettingsTab);
if (!settingsTab) {
@@ -223,9 +223,7 @@ export default class Database implements ViewModels.Database {
this.expandDatabase();
}
this.container.onUpdateTabsButtons([]);
this.container.tabsManager.refreshActiveTab(
(tab: ViewModels.Tab) => tab.collection && tab.collection.getDatabase().rid === this.rid
);
this.container.tabsManager.refreshActiveTab(tab => tab.collection && tab.collection.getDatabase().rid === this.rid);
}
public expandDatabase() {

View File

@@ -1,9 +1,9 @@
import * as ko from "knockout";
import * as DataModels from "../../Contracts/DataModels";
import * as ViewModels from "../../Contracts/ViewModels";
import DocumentsTab from "../Tabs/DocumentsTab";
export default class DocumentId implements ViewModels.DocumentId {
public container: ViewModels.DocumentsTab;
export default class DocumentId {
public container: DocumentsTab;
public rid: string;
public self: string;
public ts: string;
@@ -14,7 +14,7 @@ export default class DocumentId implements ViewModels.DocumentId {
public stringPartitionKeyValue: string;
public isDirty: ko.Observable<boolean>;
constructor(container: ViewModels.DocumentsTab, data: any, partitionKeyValue: any) {
constructor(container: DocumentsTab, data: any, partitionKeyValue: any) {
this.container = container;
this.self = data._self;
this.rid = data._rid;

View File

@@ -1,9 +1,9 @@
import * as ko from "knockout";
import * as ViewModels from "../../Contracts/ViewModels";
import DocumentId from "./DocumentId";
import DocumentsTab from "../Tabs/DocumentsTab";
export default class ObjectId extends DocumentId implements ViewModels.DocumentId {
constructor(container: ViewModels.DocumentsTab, data: any, partitionKeyValue: any) {
export default class ObjectId extends DocumentId {
constructor(container: DocumentsTab, data: any, partitionKeyValue: any) {
super(container, data, partitionKeyValue);
if (typeof data._id === "object") {
this.id = ko.observable(data._id[Object.keys(data._id)[0]]);

View File

@@ -9,6 +9,7 @@ import Q from "q";
import QueryTab from "../Tabs/QueryTab";
import TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor";
import Explorer from "../Explorer";
import TabsBase from "../Tabs/TabsBase";
export default class ResourceTokenCollection implements ViewModels.CollectionBase {
public nodeKind: string;
@@ -120,7 +121,7 @@ export default class ResourceTokenCollection implements ViewModels.CollectionBas
const documentsTabs: DocumentsTab[] = this.container.tabsManager.getTabs(
ViewModels.CollectionTabKind.Documents,
(tab: ViewModels.Tab) => tab.collection && tab.collection.rid === this.rid
(tab: TabsBase) => tab.collection && tab.collection.rid === this.rid
) as DocumentsTab[];
let documentsTab: DocumentsTab = documentsTabs && documentsTabs[0];

View File

@@ -30,6 +30,7 @@ import Explorer from "../Explorer";
import UserDefinedFunction from "./UserDefinedFunction";
import StoredProcedure from "./StoredProcedure";
import Trigger from "./Trigger";
import TabsBase from "../Tabs/TabsBase";
export class ResourceTreeAdapter implements ReactAdapter {
private static readonly DataTitle = "DATA";
@@ -50,7 +51,7 @@ export class ResourceTreeAdapter implements ReactAdapter {
this.parameters = ko.observable(Date.now());
this.container.selectedNode.subscribe((newValue: any) => this.triggerRender());
this.container.tabsManager.activeTab.subscribe((newValue: ViewModels.Tab) => this.triggerRender());
this.container.tabsManager.activeTab.subscribe((newValue: TabsBase) => this.triggerRender());
this.container.isNotebookEnabled.subscribe(newValue => this.triggerRender());
this.koSubsDatabaseIdMap = new ArrayHashMap();
@@ -176,7 +177,7 @@ export class ResourceTreeAdapter implements ReactAdapter {
database.selectDatabase();
this.container.onUpdateTabsButtons([]);
this.container.tabsManager.refreshActiveTab(
(tab: ViewModels.Tab) => tab.collection && tab.collection.getDatabase().rid === database.rid
(tab: TabsBase) => tab.collection && tab.collection.getDatabase().rid === database.rid
);
},
onContextMenuOpen: () => this.container.selectedNode(database)
@@ -275,7 +276,7 @@ export class ResourceTreeAdapter implements ReactAdapter {
this.container.selectedNode(collection);
this.container.onUpdateTabsButtons([]);
this.container.tabsManager.refreshActiveTab(
(tab: ViewModels.Tab) => tab.collection && tab.collection.rid === collection.rid
(tab: TabsBase) => tab.collection && tab.collection.rid === collection.rid
);
},
onExpanded: () => {
@@ -303,7 +304,7 @@ export class ResourceTreeAdapter implements ReactAdapter {
onClick: () => {
collection.selectedSubnodeKind(ViewModels.CollectionTabKind.StoredProcedures);
this.container.tabsManager.refreshActiveTab(
(tab: ViewModels.Tab) => tab.collection && tab.collection.rid === collection.rid
(tab: TabsBase) => tab.collection && tab.collection.rid === collection.rid
);
}
};
@@ -322,7 +323,7 @@ export class ResourceTreeAdapter implements ReactAdapter {
onClick: () => {
collection.selectedSubnodeKind(ViewModels.CollectionTabKind.UserDefinedFunctions);
this.container.tabsManager.refreshActiveTab(
(tab: ViewModels.Tab) => tab.collection && tab.collection.rid === collection.rid
(tab: TabsBase) => tab.collection && tab.collection.rid === collection.rid
);
}
};
@@ -340,7 +341,7 @@ export class ResourceTreeAdapter implements ReactAdapter {
onClick: () => {
collection.selectedSubnodeKind(ViewModels.CollectionTabKind.Triggers);
this.container.tabsManager.refreshActiveTab(
(tab: ViewModels.Tab) => tab.collection && tab.collection.rid === collection.rid
(tab: TabsBase) => tab.collection && tab.collection.rid === collection.rid
);
}
};

View File

@@ -16,10 +16,9 @@ export class ResourceTreeAdapterForResourceToken implements ReactAdapter {
public constructor(private container: Explorer) {
this.parameters = ko.observable(Date.now());
this.container.resourceTokenCollection.subscribe((collection: ViewModels.CollectionBase) => this.triggerRender());
this.container.resourceTokenCollection.subscribe(() => this.triggerRender());
this.container.selectedNode.subscribe((newValue: any) => this.triggerRender());
this.container.tabsManager &&
this.container.tabsManager.activeTab.subscribe((newValue: ViewModels.Tab) => this.triggerRender());
this.container.tabsManager && this.container.tabsManager.activeTab.subscribe(() => this.triggerRender());
this.triggerRender();
}
@@ -65,9 +64,7 @@ export class ResourceTreeAdapterForResourceToken implements ReactAdapter {
// Rewritten version of expandCollapseCollection
this.container.selectedNode(collection);
this.container.onUpdateTabsButtons([]);
this.container.tabsManager.refreshActiveTab(
(tab: ViewModels.Tab) => tab.collection && tab.collection.rid === collection.rid
);
this.container.tabsManager.refreshActiveTab(tab => tab.collection && tab.collection.rid === collection.rid);
},
isSelected: () => this.isDataNodeSelected(collection.rid, "Collection", undefined)
};

View File

@@ -8,6 +8,7 @@ import StoredProcedureTab from "../Tabs/StoredProcedureTab";
import TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor";
import Explorer from "../Explorer";
import { deleteStoredProcedure, executeStoredProcedure } from "../../Common/DocumentClientUtilityBase";
import TabsBase from "../Tabs/TabsBase";
const sampleStoredProcedureBody: string = `// SAMPLE STORED PROCEDURE
function sample(prefix) {
@@ -96,7 +97,7 @@ export default class StoredProcedure {
const storedProcedureTabs: StoredProcedureTab[] = this.container.tabsManager.getTabs(
ViewModels.CollectionTabKind.StoredProcedures,
(tab: ViewModels.Tab) => tab.node && tab.node.rid === this.rid
(tab: TabsBase) => tab.node && tab.node.rid === this.rid
) as StoredProcedureTab[];
let storedProcedureTab: StoredProcedureTab = storedProcedureTabs && storedProcedureTabs[0];
@@ -145,9 +146,7 @@ export default class StoredProcedure {
deleteStoredProcedure(this.collection, storedProcedureData).then(
() => {
this.container.tabsManager.removeTabByComparator(
(tab: ViewModels.Tab) => tab.node && tab.node.rid === this.rid
);
this.container.tabsManager.removeTabByComparator((tab: TabsBase) => tab.node && tab.node.rid === this.rid);
this.collection.children.remove(this);
},
reason => {}
@@ -155,11 +154,11 @@ export default class StoredProcedure {
}
public execute(params: string[], partitionKeyValue?: string): void {
const sprocTabs: ViewModels.StoredProcedureTab[] = this.container.tabsManager.getTabs(
const sprocTabs = this.container.tabsManager.getTabs(
ViewModels.CollectionTabKind.StoredProcedures,
(tab: ViewModels.Tab) => tab.node && tab.node.rid === this.rid
) as ViewModels.StoredProcedureTab[];
const sprocTab: ViewModels.StoredProcedureTab = sprocTabs && sprocTabs.length > 0 && sprocTabs[0];
(tab: TabsBase) => tab.node && tab.node.rid === this.rid
) as StoredProcedureTab[];
const sprocTab = sprocTabs && sprocTabs.length > 0 && sprocTabs[0];
sprocTab.isExecuting(true);
this.container &&
executeStoredProcedure(this.collection, this, partitionKeyValue, params)

View File

@@ -72,7 +72,7 @@ export default class Trigger {
const triggerTabs: TriggerTab[] = this.container.tabsManager.getTabs(
ViewModels.CollectionTabKind.Triggers,
(tab: ViewModels.Tab) => tab.node && tab.node.rid === this.rid
tab => tab.node && tab.node.rid === this.rid
) as TriggerTab[];
let triggerTab: TriggerTab = triggerTabs && triggerTabs[0];
@@ -125,9 +125,7 @@ export default class Trigger {
deleteTrigger(this.collection, triggerData).then(
() => {
this.container.tabsManager.removeTabByComparator(
(tab: ViewModels.Tab) => tab.node && tab.node.rid === this.rid
);
this.container.tabsManager.removeTabByComparator(tab => tab.node && tab.node.rid === this.rid);
this.collection.children.remove(this);
},
reason => {}

View File

@@ -57,7 +57,7 @@ export default class UserDefinedFunction {
const userDefinedFunctionTabs: UserDefinedFunctionTab[] = this.container.tabsManager.getTabs(
ViewModels.CollectionTabKind.UserDefinedFunctions,
(tab: ViewModels.Tab) => tab.collection && tab.collection.rid === this.rid
tab => tab.collection && tab.collection.rid === this.rid
) as UserDefinedFunctionTab[];
let userDefinedFunctionTab: UserDefinedFunctionTab = userDefinedFunctionTabs && userDefinedFunctionTabs[0];
@@ -115,9 +115,7 @@ export default class UserDefinedFunction {
};
deleteUserDefinedFunction(this.collection, userDefinedFunctionData).then(
() => {
this.container.tabsManager.removeTabByComparator(
(tab: ViewModels.Tab) => tab.node && tab.node.rid === this.rid
);
this.container.tabsManager.removeTabByComparator(tab => tab.node && tab.node.rid === this.rid);
this.collection.children.remove(this);
},
reason => {}