mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2024-11-25 15:06:55 +00:00
Remove Explorer.defaultExperience (#680)
Co-authored-by: Steve Faulkner <southpolesteve@gmail.com>
This commit is contained in:
parent
d1d28885d0
commit
fdd12b41c4
@ -65,28 +65,18 @@ export class ClientDefaults {
|
||||
public static readonly arcadiaTokenRefreshIntervalPaddingMs: number = 2000;
|
||||
}
|
||||
|
||||
export class AccountKind {
|
||||
public static DocumentDB: string = "DocumentDB";
|
||||
public static MongoDB: string = "MongoDB";
|
||||
public static Parse: string = "Parse";
|
||||
public static GlobalDocumentDB: string = "GlobalDocumentDB";
|
||||
public static Default: string = AccountKind.DocumentDB;
|
||||
export enum AccountKind {
|
||||
DocumentDB = "DocumentDB",
|
||||
MongoDB = "MongoDB",
|
||||
Parse = "Parse",
|
||||
GlobalDocumentDB = "GlobalDocumentDB",
|
||||
Default = "DocumentDB",
|
||||
}
|
||||
|
||||
export class CorrelationBackend {
|
||||
public static Url: string = "https://aka.ms/cosmosdbanalytics";
|
||||
}
|
||||
|
||||
export class DefaultAccountExperience {
|
||||
public static DocumentDB: string = "DocumentDB";
|
||||
public static Graph: string = "Graph";
|
||||
public static MongoDB: string = "MongoDB";
|
||||
public static ApiForMongoDB: string = "Azure Cosmos DB for MongoDB API";
|
||||
public static Table: string = "Table";
|
||||
public static Cassandra: string = "Cassandra";
|
||||
public static Default: string = DefaultAccountExperience.DocumentDB;
|
||||
}
|
||||
|
||||
export class CapabilityNames {
|
||||
public static EnableTable: string = "EnableTable";
|
||||
public static EnableGremlin: string = "EnableGremlin";
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { ResourceType } from "@azure/cosmos/dist-esm/common/constants";
|
||||
import { configContext, Platform, updateConfigContext, resetConfigContext } from "../ConfigContext";
|
||||
import { Platform, resetConfigContext, updateConfigContext } from "../ConfigContext";
|
||||
import { updateUserContext } from "../UserContext";
|
||||
import { endpoint, getTokenFromAuthService, requestPlugin, tokenProvider } from "./CosmosClient";
|
||||
|
||||
@ -91,7 +91,6 @@ describe("endpoint", () => {
|
||||
location: "foo",
|
||||
type: "foo",
|
||||
kind: "foo",
|
||||
tags: [],
|
||||
properties: {
|
||||
documentEndpoint: "bar",
|
||||
gremlinEndpoint: "foo",
|
||||
|
@ -4,7 +4,6 @@ export interface DatabaseAccount {
|
||||
location: string;
|
||||
type: string;
|
||||
kind: string;
|
||||
tags: any;
|
||||
properties: DatabaseAccountExtendedProperties;
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,6 @@ const createTestDatabaseAccount = (): DataModels.DatabaseAccount => {
|
||||
gremlinEndpoint: null,
|
||||
tableEndpoint: null,
|
||||
},
|
||||
tags: "testTags",
|
||||
type: "testType",
|
||||
};
|
||||
};
|
||||
@ -30,7 +29,6 @@ const createTestMongo32DatabaseAccount = (): DataModels.DatabaseAccount => {
|
||||
gremlinEndpoint: null,
|
||||
tableEndpoint: null,
|
||||
},
|
||||
tags: "testTags",
|
||||
type: "testType",
|
||||
};
|
||||
};
|
||||
@ -48,7 +46,6 @@ const createTestMongo36DatabaseAccount = (): DataModels.DatabaseAccount => {
|
||||
tableEndpoint: null,
|
||||
mongoEndpoint: "https://testMongoEndpoint.azure.com/",
|
||||
},
|
||||
tags: "testTags",
|
||||
type: "testType",
|
||||
};
|
||||
};
|
||||
@ -65,7 +62,6 @@ const createTestCassandraDatabaseAccount = (): DataModels.DatabaseAccount => {
|
||||
gremlinEndpoint: null,
|
||||
tableEndpoint: null,
|
||||
},
|
||||
tags: "testTags",
|
||||
type: "testType",
|
||||
};
|
||||
};
|
||||
|
@ -1,14 +1,14 @@
|
||||
import { shallow } from "enzyme";
|
||||
import ko from "knockout";
|
||||
import React from "react";
|
||||
import { ScaleComponent, ScaleComponentProps } from "./ScaleComponent";
|
||||
import { container, collection } from "../TestUtils";
|
||||
import { ThroughputInputAutoPilotV3Component } from "./ThroughputInputComponents/ThroughputInputAutoPilotV3Component";
|
||||
import Explorer from "../../../Explorer";
|
||||
import * as Constants from "../../../../Common/Constants";
|
||||
import * as DataModels from "../../../../Contracts/DataModels";
|
||||
import { throughputUnit } from "../SettingsRenderUtils";
|
||||
import * as SharedConstants from "../../../../Shared/Constants";
|
||||
import ko from "knockout";
|
||||
import Explorer from "../../../Explorer";
|
||||
import { throughputUnit } from "../SettingsRenderUtils";
|
||||
import { collection, container } from "../TestUtils";
|
||||
import { ScaleComponent, ScaleComponentProps } from "./ScaleComponent";
|
||||
import { ThroughputInputAutoPilotV3Component } from "./ThroughputInputComponents/ThroughputInputAutoPilotV3Component";
|
||||
|
||||
describe("ScaleComponent", () => {
|
||||
const nonNationalCloudContainer = new Explorer();
|
||||
@ -87,7 +87,6 @@ describe("ScaleComponent", () => {
|
||||
location: undefined,
|
||||
type: undefined,
|
||||
kind: "documentdb",
|
||||
tags: undefined,
|
||||
properties: {
|
||||
documentEndpoint: undefined,
|
||||
tableEndpoint: undefined,
|
||||
|
@ -424,7 +424,6 @@ exports[`SettingsComponent renders 1`] = `
|
||||
},
|
||||
"databaseAccount": [Function],
|
||||
"databases": [Function],
|
||||
"defaultExperience": [Function],
|
||||
"deleteCollectionText": [Function],
|
||||
"deleteDatabaseText": [Function],
|
||||
"gitHubClient": GitHubClient {
|
||||
@ -1710,7 +1709,6 @@ exports[`SettingsComponent renders 1`] = `
|
||||
},
|
||||
"databaseAccount": [Function],
|
||||
"databases": [Function],
|
||||
"defaultExperience": [Function],
|
||||
"deleteCollectionText": [Function],
|
||||
"deleteDatabaseText": [Function],
|
||||
"gitHubClient": GitHubClient {
|
||||
@ -3009,7 +3007,6 @@ exports[`SettingsComponent renders 1`] = `
|
||||
},
|
||||
"databaseAccount": [Function],
|
||||
"databases": [Function],
|
||||
"defaultExperience": [Function],
|
||||
"deleteCollectionText": [Function],
|
||||
"deleteDatabaseText": [Function],
|
||||
"gitHubClient": GitHubClient {
|
||||
@ -4295,7 +4292,6 @@ exports[`SettingsComponent renders 1`] = `
|
||||
},
|
||||
"databaseAccount": [Function],
|
||||
"databases": [Function],
|
||||
"defaultExperience": [Function],
|
||||
"deleteCollectionText": [Function],
|
||||
"deleteDatabaseText": [Function],
|
||||
"gitHubClient": GitHubClient {
|
||||
|
@ -79,7 +79,6 @@ describe("ContainerSampleGenerator", () => {
|
||||
location: "foo",
|
||||
type: "foo",
|
||||
kind: "foo",
|
||||
tags: [],
|
||||
properties: {
|
||||
documentEndpoint: "bar",
|
||||
gremlinEndpoint: "foo",
|
||||
|
@ -115,11 +115,6 @@ export default class Explorer {
|
||||
* */
|
||||
public databaseAccount: ko.Observable<DataModels.DatabaseAccount>;
|
||||
public collectionCreationDefaults: ViewModels.CollectionCreationDefaults = SharedConstants.CollectionCreationDefaults;
|
||||
/**
|
||||
* @deprecated
|
||||
* Use userContext.apiType instead
|
||||
* */
|
||||
public defaultExperience: ko.Observable<string>;
|
||||
public isFixedCollectionWithSharedThroughputSupported: ko.Computed<boolean>;
|
||||
/**
|
||||
* @deprecated
|
||||
@ -376,17 +371,6 @@ export default class Explorer {
|
||||
bounds: splitterBounds,
|
||||
direction: SplitterDirection.Vertical,
|
||||
});
|
||||
this.defaultExperience = ko.observable<string>();
|
||||
// this.databaseAccount.subscribe((databaseAccount) => {
|
||||
// const defaultExperience: string = DefaultExperienceUtility.getDefaultExperienceFromDatabaseAccount(
|
||||
// databaseAccount
|
||||
// );
|
||||
// this.defaultExperience(defaultExperience);
|
||||
// // TODO. Remove this entirely
|
||||
// updateUserContext({
|
||||
// apiType: DefaultExperienceUtility.mapDefaultExperienceStringToEnum(defaultExperience),
|
||||
// });
|
||||
// });
|
||||
|
||||
this.isFixedCollectionWithSharedThroughputSupported = ko.computed(() => {
|
||||
if (userContext.features.enableFixedCollectionWithSharedThroughput) {
|
||||
|
@ -20,7 +20,6 @@ describe("Add Collection Pane", () => {
|
||||
enableFreeTier: false,
|
||||
},
|
||||
type: undefined,
|
||||
tags: [],
|
||||
};
|
||||
|
||||
const mockFreeTierDatabaseAccount: DatabaseAccount = {
|
||||
@ -36,7 +35,6 @@ describe("Add Collection Pane", () => {
|
||||
enableFreeTier: true,
|
||||
},
|
||||
type: undefined,
|
||||
tags: [],
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
@ -44,7 +42,13 @@ describe("Add Collection Pane", () => {
|
||||
});
|
||||
|
||||
it("should be true if graph API and partition key is not /id nor /label", () => {
|
||||
explorer.defaultExperience(Constants.DefaultAccountExperience.Graph.toLowerCase());
|
||||
updateUserContext({
|
||||
databaseAccount: {
|
||||
properties: {
|
||||
capabilities: [{ name: "EnableGremlin" }],
|
||||
},
|
||||
} as DatabaseAccount,
|
||||
});
|
||||
const addCollectionPane = explorer.addCollectionPane as AddCollectionPane;
|
||||
addCollectionPane.partitionKey("/blah");
|
||||
expect(addCollectionPane.isValid()).toBe(true);
|
||||
@ -58,7 +62,6 @@ describe("Add Collection Pane", () => {
|
||||
},
|
||||
} as DatabaseAccount,
|
||||
});
|
||||
|
||||
const addCollectionPane = explorer.addCollectionPane as AddCollectionPane;
|
||||
addCollectionPane.partitionKey("/id");
|
||||
expect(addCollectionPane.isValid()).toBe(false);
|
||||
|
@ -21,7 +21,6 @@ describe("Add Database Pane", () => {
|
||||
enableFreeTier: false,
|
||||
},
|
||||
type: undefined,
|
||||
tags: [],
|
||||
};
|
||||
|
||||
const mockFreeTierDatabaseAccount: DatabaseAccount = {
|
||||
@ -37,7 +36,6 @@ describe("Add Database Pane", () => {
|
||||
enableFreeTier: true,
|
||||
},
|
||||
type: undefined,
|
||||
tags: [],
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
|
@ -413,7 +413,6 @@ exports[`GitHub Repos Panel should render Default properly 1`] = `
|
||||
},
|
||||
"databaseAccount": [Function],
|
||||
"databases": [Function],
|
||||
"defaultExperience": [Function],
|
||||
"deleteCollectionText": [Function],
|
||||
"deleteDatabaseText": [Function],
|
||||
"gitHubClient": GitHubClient {
|
||||
|
@ -403,7 +403,6 @@ exports[`StringInput Pane should render Create new directory properly 1`] = `
|
||||
},
|
||||
"databaseAccount": [Function],
|
||||
"databases": [Function],
|
||||
"defaultExperience": [Function],
|
||||
"deleteCollectionText": [Function],
|
||||
"deleteDatabaseText": [Function],
|
||||
"gitHubClient": GitHubClient {
|
||||
|
@ -401,7 +401,6 @@ exports[`Delete Database Confirmation Pane submit() Should call delete database
|
||||
},
|
||||
"databaseAccount": [Function],
|
||||
"databases": [Function],
|
||||
"defaultExperience": [Function],
|
||||
"deleteCollectionText": [Function],
|
||||
"deleteDatabaseText": [Function],
|
||||
"gitHubClient": GitHubClient {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import * as ko from "knockout";
|
||||
import * as Constants from "../../Common/Constants";
|
||||
import { DatabaseAccount } from "../../Contracts/DataModels";
|
||||
import * as ViewModels from "../../Contracts/ViewModels";
|
||||
import { updateUserContext } from "../../UserContext";
|
||||
import { CommandButtonComponentProps } from "../Controls/CommandButton/CommandButtonComponent";
|
||||
@ -27,7 +27,13 @@ describe("Documents tab", () => {
|
||||
describe("showPartitionKey", () => {
|
||||
const explorer = new Explorer();
|
||||
const mongoExplorer = new Explorer();
|
||||
mongoExplorer.defaultExperience(Constants.DefaultAccountExperience.MongoDB);
|
||||
updateUserContext({
|
||||
databaseAccount: {
|
||||
properties: {
|
||||
capabilities: [{ name: "EnableGremlin" }],
|
||||
},
|
||||
} as DatabaseAccount,
|
||||
});
|
||||
|
||||
const collectionWithoutPartitionKey = <ViewModels.Collection>(<unknown>{
|
||||
id: ko.observable<string>("foo"),
|
||||
|
@ -3,6 +3,7 @@ import * as DataModels from "../../Contracts/DataModels";
|
||||
import * as ViewModels from "../../Contracts/ViewModels";
|
||||
import { ActionModifiers } from "../../Shared/Telemetry/TelemetryConstants";
|
||||
import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor";
|
||||
import { userContext } from "../../UserContext";
|
||||
import Explorer from "../Explorer";
|
||||
import { NotebookClientV2 } from "../Notebook/NotebookClientV2";
|
||||
import TabsBase from "./TabsBase";
|
||||
@ -29,7 +30,7 @@ export default class NotebookTabBase extends TabsBase {
|
||||
NotebookTabBase.clientManager = new NotebookClientV2({
|
||||
connectionInfo: this.container.notebookServerInfo(),
|
||||
databaseAccountName: this.container.databaseAccount().name,
|
||||
defaultExperience: this.container.defaultExperience(),
|
||||
defaultExperience: userContext.apiType,
|
||||
contentProvider: this.container.notebookManager?.notebookContentProvider,
|
||||
});
|
||||
}
|
||||
|
@ -23,7 +23,6 @@ describe("Tabs manager tests", () => {
|
||||
location: "",
|
||||
type: "",
|
||||
kind: "",
|
||||
tags: "",
|
||||
properties: undefined,
|
||||
});
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
import * as DataModels from "../../Contracts/DataModels";
|
||||
import * as ko from "knockout";
|
||||
import Database from "./Database";
|
||||
import Explorer from "../Explorer";
|
||||
import { HttpStatusCodes } from "../../Common/Constants";
|
||||
import * as DataModels from "../../Contracts/DataModels";
|
||||
import { JunoClient } from "../../Juno/JunoClient";
|
||||
import { userContext, updateUserContext } from "../../UserContext";
|
||||
import { updateUserContext, userContext } from "../../UserContext";
|
||||
import Explorer from "../Explorer";
|
||||
import Database from "./Database";
|
||||
|
||||
const createMockContainer = (): Explorer => {
|
||||
const mockContainer = new Explorer();
|
||||
@ -19,7 +19,6 @@ updateUserContext({
|
||||
name: "fakeName",
|
||||
location: "fakeLocation",
|
||||
type: "fakeType",
|
||||
tags: undefined,
|
||||
kind: "fakeKind",
|
||||
properties: {
|
||||
documentEndpoint: "fakeEndpoint",
|
||||
|
@ -14,7 +14,6 @@ const sampleDatabaseAccount: DataModels.DatabaseAccount = {
|
||||
location: "location",
|
||||
type: "type",
|
||||
kind: "kind",
|
||||
tags: [],
|
||||
properties: {
|
||||
documentEndpoint: "documentEndpoint",
|
||||
gremlinEndpoint: "gremlinEndpoint",
|
||||
|
@ -13,7 +13,6 @@ const sampleDatabaseAccount: DatabaseAccount = {
|
||||
location: "location",
|
||||
type: "type",
|
||||
kind: "kind",
|
||||
tags: [],
|
||||
properties: {
|
||||
documentEndpoint: "documentEndpoint",
|
||||
gremlinEndpoint: "gremlinEndpoint",
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { AccountKind, DefaultAccountExperience, TagNames } from "../../Common/Constants";
|
||||
import { AccountKind } from "../../Common/Constants";
|
||||
|
||||
export const emulatorAccount = {
|
||||
name: "",
|
||||
@ -6,9 +6,6 @@ export const emulatorAccount = {
|
||||
location: "",
|
||||
type: "",
|
||||
kind: AccountKind.DocumentDB,
|
||||
tags: {
|
||||
[TagNames.defaultExperience]: DefaultAccountExperience.DocumentDB,
|
||||
},
|
||||
properties: {
|
||||
documentEndpoint: "",
|
||||
tableEndpoint: "",
|
||||
|
@ -1,4 +1,3 @@
|
||||
import Q from "q";
|
||||
import * as Constants from "../../Common/Constants";
|
||||
import { configContext } from "../../ConfigContext";
|
||||
import * as DataModels from "../../Contracts/DataModels";
|
||||
@ -21,8 +20,7 @@ export default class AuthHeadersUtil {
|
||||
const databaseAccount = userContext.databaseAccount;
|
||||
const subscriptionId: string = userContext.subscriptionId;
|
||||
const resourceGroup = userContext.resourceGroup;
|
||||
const defaultExperience: string = DefaultExperienceUtility.getDefaultExperienceFromDatabaseAccount(databaseAccount);
|
||||
const apiKind: DataModels.ApiKind = DefaultExperienceUtility.getApiKindFromDefaultExperience(defaultExperience);
|
||||
const apiKind: DataModels.ApiKind = DefaultExperienceUtility.getApiKindFromDefaultExperience(userContext.apiType);
|
||||
const accountEndpoint = (databaseAccount && databaseAccount.properties.documentEndpoint) || "";
|
||||
const sid = subscriptionId || "";
|
||||
const rg = resourceGroup || "";
|
||||
|
@ -1,27 +1,28 @@
|
||||
import { DefaultAccountExperience, CapabilityNames, AccountKind } from "../../Common/Constants";
|
||||
import { AccountKind, CapabilityNames } from "../../Common/Constants";
|
||||
import { AccessInputMetadata, ApiKind } from "../../Contracts/DataModels";
|
||||
import { DefaultExperienceUtility } from "../../Shared/DefaultExperienceUtility";
|
||||
import { userContext } from "../../UserContext";
|
||||
|
||||
export function getDatabaseAccountPropertiesFromMetadata(metadata: AccessInputMetadata): unknown {
|
||||
let properties = { documentEndpoint: metadata.documentEndpoint };
|
||||
const apiExperience: string = DefaultExperienceUtility.getDefaultExperienceFromApiKind(metadata.apiKind);
|
||||
const apiExperience = DefaultExperienceUtility.getDefaultExperienceFromApiKind(metadata.apiKind);
|
||||
|
||||
if (apiExperience === DefaultAccountExperience.Cassandra) {
|
||||
if (apiExperience === "Cassandra") {
|
||||
properties = Object.assign(properties, {
|
||||
cassandraEndpoint: metadata.apiEndpoint,
|
||||
capabilities: [{ name: CapabilityNames.EnableCassandra }],
|
||||
});
|
||||
} else if (apiExperience === DefaultAccountExperience.Table) {
|
||||
} else if (apiExperience === "Tables") {
|
||||
properties = Object.assign(properties, {
|
||||
tableEndpoint: metadata.apiEndpoint,
|
||||
capabilities: [{ name: CapabilityNames.EnableTable }],
|
||||
});
|
||||
} else if (apiExperience === DefaultAccountExperience.Graph) {
|
||||
} else if (apiExperience === "Gremlin") {
|
||||
properties = Object.assign(properties, {
|
||||
gremlinEndpoint: metadata.apiEndpoint,
|
||||
capabilities: [{ name: CapabilityNames.EnableGremlin }],
|
||||
});
|
||||
} else if (apiExperience === DefaultAccountExperience.MongoDB) {
|
||||
} else if (apiExperience === "Mongo") {
|
||||
if (metadata.apiKind === ApiKind.MongoDBCompute) {
|
||||
properties = Object.assign(properties, {
|
||||
mongoEndpoint: metadata.mongoEndpoint,
|
||||
@ -31,12 +32,8 @@ export function getDatabaseAccountPropertiesFromMetadata(metadata: AccessInputMe
|
||||
return properties;
|
||||
}
|
||||
|
||||
export function getDatabaseAccountKindFromExperience(apiExperience: string): string {
|
||||
if (apiExperience === DefaultAccountExperience.MongoDB) {
|
||||
return AccountKind.MongoDB;
|
||||
}
|
||||
|
||||
if (apiExperience === DefaultAccountExperience.ApiForMongoDB) {
|
||||
export function getDatabaseAccountKindFromExperience(apiExperience: typeof userContext.apiType): AccountKind {
|
||||
if (apiExperience === "Mongo") {
|
||||
return AccountKind.MongoDB;
|
||||
}
|
||||
|
||||
|
@ -1,133 +1,67 @@
|
||||
import * as Constants from "../Common/Constants";
|
||||
import * as DataModels from "../Contracts/DataModels";
|
||||
import * as ViewModels from "../Contracts/ViewModels";
|
||||
import { userContext } from "../UserContext";
|
||||
import { DefaultExperienceUtility } from "./DefaultExperienceUtility";
|
||||
|
||||
describe("Default Experience Utility", () => {
|
||||
describe("getDefaultExperienceFromApiKind()", () => {
|
||||
function runScenario(apiKind: number, expectedExperience: string): void {
|
||||
function runScenario(apiKind: number, expectedExperience: typeof userContext.apiType): void {
|
||||
const resolvedExperience = DefaultExperienceUtility.getDefaultExperienceFromApiKind(apiKind);
|
||||
expect(resolvedExperience).toEqual(expectedExperience);
|
||||
}
|
||||
|
||||
describe("On SQL", () => {
|
||||
it("should return SQL", () => runScenario(DataModels.ApiKind.SQL, Constants.DefaultAccountExperience.DocumentDB));
|
||||
it("should return SQL", () => runScenario(DataModels.ApiKind.SQL, "SQL"));
|
||||
});
|
||||
|
||||
describe("On MongoDB", () => {
|
||||
it("should return MongoDB", () =>
|
||||
runScenario(DataModels.ApiKind.MongoDB, Constants.DefaultAccountExperience.MongoDB));
|
||||
it("should return MongoDB", () => runScenario(DataModels.ApiKind.MongoDB, "Mongo"));
|
||||
});
|
||||
|
||||
describe("On Table", () => {
|
||||
it("should return Table", () => runScenario(DataModels.ApiKind.Table, Constants.DefaultAccountExperience.Table));
|
||||
it("should return Table", () => runScenario(DataModels.ApiKind.Table, "Tables"));
|
||||
});
|
||||
|
||||
describe("On Cassandra", () => {
|
||||
it("should return Cassandra", () =>
|
||||
runScenario(DataModels.ApiKind.Cassandra, Constants.DefaultAccountExperience.Cassandra));
|
||||
it("should return Cassandra", () => runScenario(DataModels.ApiKind.Cassandra, "Cassandra"));
|
||||
});
|
||||
|
||||
describe("On Graph", () => {
|
||||
it("should return Graph", () => runScenario(DataModels.ApiKind.Graph, Constants.DefaultAccountExperience.Graph));
|
||||
it("should return Graph", () => runScenario(DataModels.ApiKind.Graph, "Gremlin"));
|
||||
});
|
||||
|
||||
describe("On unknown", () => {
|
||||
it("should return Default", () => runScenario(-1, Constants.DefaultAccountExperience.Default));
|
||||
it("should return Default", () => runScenario(-1, "SQL"));
|
||||
});
|
||||
});
|
||||
|
||||
describe("getApiKindFromDefaultExperience()", () => {
|
||||
function runScenario(defaultExperience: string, expectedApiKind: number): void {
|
||||
function runScenario(defaultExperience: typeof userContext.apiType, expectedApiKind: number): void {
|
||||
const resolvedApiKind = DefaultExperienceUtility.getApiKindFromDefaultExperience(defaultExperience);
|
||||
expect(resolvedApiKind).toEqual(expectedApiKind);
|
||||
}
|
||||
|
||||
describe("On SQL", () => {
|
||||
it("should return SQL", () => runScenario(Constants.DefaultAccountExperience.DocumentDB, DataModels.ApiKind.SQL));
|
||||
it("should return SQL", () => runScenario("SQL", DataModels.ApiKind.SQL));
|
||||
});
|
||||
|
||||
describe("On MongoDB", () => {
|
||||
it("should return MongoDB", () =>
|
||||
runScenario(Constants.DefaultAccountExperience.MongoDB, DataModels.ApiKind.MongoDB));
|
||||
it("should return MongoDB", () => runScenario("Mongo", DataModels.ApiKind.MongoDB));
|
||||
});
|
||||
|
||||
describe("On Table", () => {
|
||||
it("should return Table", () => runScenario(Constants.DefaultAccountExperience.Table, DataModels.ApiKind.Table));
|
||||
it("should return Table", () => runScenario("Tables", DataModels.ApiKind.Table));
|
||||
});
|
||||
|
||||
describe("On Cassandra", () => {
|
||||
it("should return Cassandra", () =>
|
||||
runScenario(Constants.DefaultAccountExperience.Cassandra, DataModels.ApiKind.Cassandra));
|
||||
it("should return Cassandra", () => runScenario("Cassandra", DataModels.ApiKind.Cassandra));
|
||||
});
|
||||
|
||||
describe("On Graph", () => {
|
||||
it("should return Graph", () => runScenario(Constants.DefaultAccountExperience.Graph, DataModels.ApiKind.Graph));
|
||||
it("should return Graph", () => runScenario("Gremlin", DataModels.ApiKind.Graph));
|
||||
});
|
||||
|
||||
describe("On null", () => {
|
||||
it("should return SQL", () => runScenario(null, DataModels.ApiKind.SQL));
|
||||
});
|
||||
});
|
||||
|
||||
describe("getDefaultExperienceFromDatabaseAccount()", () => {
|
||||
function runScenario(databaseAccount: DataModels.DatabaseAccount, expectedDefaultExperience: string): void {
|
||||
const resolvedExperience = DefaultExperienceUtility.getDefaultExperienceFromDatabaseAccount(databaseAccount);
|
||||
expect(resolvedExperience).toEqual(expectedDefaultExperience);
|
||||
}
|
||||
|
||||
const databaseAccountWithWrongTagsAndCapabilities: DataModels.DatabaseAccount = {
|
||||
id: "test",
|
||||
kind: "GlobalDocumentDB",
|
||||
name: "test",
|
||||
location: "somewhere",
|
||||
type: "DocumentDB",
|
||||
tags: {
|
||||
defaultExperience: "Gremlin (graph)",
|
||||
},
|
||||
properties: {
|
||||
documentEndpoint: "",
|
||||
cassandraEndpoint: "",
|
||||
gremlinEndpoint: "",
|
||||
tableEndpoint: "",
|
||||
capabilities: [
|
||||
{
|
||||
name: Constants.CapabilityNames.EnableGremlin,
|
||||
description: "something",
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
const databaseAccountWithApiKind: DataModels.DatabaseAccount = {
|
||||
id: "test",
|
||||
kind: Constants.AccountKind.MongoDB,
|
||||
name: "test",
|
||||
location: "somewhere",
|
||||
type: "DocumentDB",
|
||||
tags: {},
|
||||
properties: {
|
||||
documentEndpoint: "",
|
||||
cassandraEndpoint: "",
|
||||
gremlinEndpoint: "",
|
||||
tableEndpoint: "",
|
||||
capabilities: [
|
||||
{
|
||||
name: Constants.CapabilityNames.EnableGremlin,
|
||||
description: "something",
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
describe("Disregard tags", () => {
|
||||
it("should return Graph", () =>
|
||||
runScenario(databaseAccountWithWrongTagsAndCapabilities, Constants.DefaultAccountExperience.Graph));
|
||||
});
|
||||
|
||||
describe("Respect Kind over capabilities", () => {
|
||||
it("should return MongoDB", () =>
|
||||
runScenario(databaseAccountWithApiKind, Constants.DefaultAccountExperience.MongoDB));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1,132 +1,47 @@
|
||||
import * as _ from "underscore";
|
||||
import * as Constants from "../Common/Constants";
|
||||
import * as DataModels from "../Contracts/DataModels";
|
||||
import { userContext } from "../UserContext";
|
||||
|
||||
export class DefaultExperienceUtility {
|
||||
public static getDefaultExperienceFromDatabaseAccount(databaseAccount: DataModels.DatabaseAccount): string | null {
|
||||
if (!databaseAccount) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const kind: string =
|
||||
databaseAccount && databaseAccount.kind && databaseAccount.kind && databaseAccount.kind.toLowerCase();
|
||||
const capabilities = (databaseAccount.properties && databaseAccount.properties.capabilities) || [];
|
||||
|
||||
return DefaultExperienceUtility._getDefaultExperience(kind, capabilities);
|
||||
}
|
||||
|
||||
public static getApiKindFromDefaultExperience(defaultExperience: string): DataModels.ApiKind {
|
||||
public static getApiKindFromDefaultExperience(defaultExperience: typeof userContext.apiType): DataModels.ApiKind {
|
||||
if (!defaultExperience) {
|
||||
return DataModels.ApiKind.SQL;
|
||||
}
|
||||
|
||||
switch (defaultExperience) {
|
||||
case Constants.DefaultAccountExperience.DocumentDB:
|
||||
case "SQL":
|
||||
return DataModels.ApiKind.SQL;
|
||||
case Constants.DefaultAccountExperience.MongoDB:
|
||||
case Constants.DefaultAccountExperience.ApiForMongoDB:
|
||||
case "Mongo":
|
||||
return DataModels.ApiKind.MongoDB;
|
||||
case Constants.DefaultAccountExperience.Table:
|
||||
case "Tables":
|
||||
return DataModels.ApiKind.Table;
|
||||
case Constants.DefaultAccountExperience.Cassandra:
|
||||
case "Cassandra":
|
||||
return DataModels.ApiKind.Cassandra;
|
||||
case Constants.DefaultAccountExperience.Graph:
|
||||
case "Gremlin":
|
||||
return DataModels.ApiKind.Graph;
|
||||
default:
|
||||
return DataModels.ApiKind.SQL;
|
||||
}
|
||||
}
|
||||
|
||||
public static getDefaultExperienceFromApiKind(apiKind: DataModels.ApiKind): string {
|
||||
public static getDefaultExperienceFromApiKind(apiKind: DataModels.ApiKind): typeof userContext.apiType {
|
||||
if (apiKind == null) {
|
||||
return Constants.DefaultAccountExperience.Default;
|
||||
return "SQL";
|
||||
}
|
||||
|
||||
switch (apiKind) {
|
||||
case DataModels.ApiKind.SQL:
|
||||
return Constants.DefaultAccountExperience.DocumentDB;
|
||||
return "SQL";
|
||||
case DataModels.ApiKind.MongoDB:
|
||||
case DataModels.ApiKind.MongoDBCompute:
|
||||
return Constants.DefaultAccountExperience.MongoDB;
|
||||
return "Mongo";
|
||||
case DataModels.ApiKind.Table:
|
||||
return Constants.DefaultAccountExperience.Table;
|
||||
return "Tables";
|
||||
case DataModels.ApiKind.Cassandra:
|
||||
return Constants.DefaultAccountExperience.Cassandra;
|
||||
return "Cassandra";
|
||||
case DataModels.ApiKind.Graph:
|
||||
return Constants.DefaultAccountExperience.Graph;
|
||||
return "Gremlin";
|
||||
default:
|
||||
return Constants.DefaultAccountExperience.Default;
|
||||
return "SQL";
|
||||
}
|
||||
}
|
||||
|
||||
private static _getDefaultExperience(kind: string, capabilities: DataModels.Capability[]): string {
|
||||
const defaultDefaultExperience: string = Constants.DefaultAccountExperience.DocumentDB;
|
||||
const defaultExperienceFromKind: string = DefaultExperienceUtility._getDefaultExperienceFromAccountKind(kind) || "";
|
||||
const defaultExperienceFromCapabilities: string =
|
||||
DefaultExperienceUtility._getDefaultExperienceFromAccountCapabilities(capabilities) || "";
|
||||
if (!!defaultExperienceFromKind) {
|
||||
return defaultExperienceFromKind;
|
||||
}
|
||||
|
||||
if (!!defaultExperienceFromCapabilities) {
|
||||
return defaultExperienceFromCapabilities;
|
||||
}
|
||||
|
||||
return defaultDefaultExperience;
|
||||
}
|
||||
|
||||
private static _getDefaultExperienceFromAccountKind(kind: string): string | null {
|
||||
if (!kind) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (kind.toLowerCase() === Constants.AccountKind.MongoDB.toLowerCase()) {
|
||||
return Constants.DefaultAccountExperience.MongoDB;
|
||||
}
|
||||
|
||||
if (kind.toLowerCase() === Constants.AccountKind.Parse.toLowerCase()) {
|
||||
return Constants.DefaultAccountExperience.MongoDB;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static _getDefaultExperienceFromAccountCapabilities(capabilities: DataModels.Capability[]): string | null {
|
||||
if (!capabilities) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!Array.isArray(capabilities)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const enableTable = DefaultExperienceUtility._findCapability(capabilities, Constants.CapabilityNames.EnableTable);
|
||||
if (enableTable) {
|
||||
return Constants.DefaultAccountExperience.Table;
|
||||
}
|
||||
|
||||
const enableGremlin = DefaultExperienceUtility._findCapability(
|
||||
capabilities,
|
||||
Constants.CapabilityNames.EnableGremlin
|
||||
);
|
||||
if (enableGremlin) {
|
||||
return Constants.DefaultAccountExperience.Graph;
|
||||
}
|
||||
|
||||
const enableCassandra = DefaultExperienceUtility._findCapability(
|
||||
capabilities,
|
||||
Constants.CapabilityNames.EnableCassandra
|
||||
);
|
||||
if (enableCassandra) {
|
||||
return Constants.DefaultAccountExperience.Cassandra;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static _findCapability(capabilities: DataModels.Capability[], capabilityName: string): DataModels.Capability {
|
||||
return _.find(capabilities, (capability) => {
|
||||
return capability && capability.name && capability.name.toLowerCase() === capabilityName.toLowerCase();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ interface UserContext {
|
||||
readonly hasWriteAccess: boolean;
|
||||
}
|
||||
|
||||
type ApiType = "SQL" | "Mongo" | "Gremlin" | "Tables" | "Cassandra";
|
||||
export type ApiType = "SQL" | "Mongo" | "Gremlin" | "Tables" | "Cassandra";
|
||||
export type PortalEnv = "localhost" | "blackforest" | "fairfax" | "mooncake" | "prod" | "dev";
|
||||
|
||||
const features = extractFeatures();
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { applyExplorerBindings } from "../applyExplorerBindings";
|
||||
import { AuthType } from "../AuthType";
|
||||
import { AccountKind, DefaultAccountExperience } from "../Common/Constants";
|
||||
import { AccountKind } from "../Common/Constants";
|
||||
import { normalizeArmEndpoint } from "../Common/EnvironmentUtility";
|
||||
import { sendMessage, sendReadyMessage } from "../Common/MessageHandler";
|
||||
import { configContext, Platform, updateConfigContext } from "../ConfigContext";
|
||||
@ -141,8 +141,6 @@ function configureHostedWithResourceToken(config: ResourceToken, explorerParams:
|
||||
name: parsedResourceToken.accountEndpoint,
|
||||
kind: AccountKind.GlobalDocumentDB,
|
||||
properties: { documentEndpoint: parsedResourceToken.accountEndpoint },
|
||||
// Resource tokens can only be used with SQL API
|
||||
tags: { defaultExperience: DefaultAccountExperience.DocumentDB },
|
||||
};
|
||||
updateUserContext({
|
||||
databaseAccount,
|
||||
@ -165,9 +163,7 @@ function configureHostedWithEncryptedToken(config: EncryptedToken, explorerParam
|
||||
authType: AuthType.EncryptedToken,
|
||||
accessToken: encodeURIComponent(config.encryptedToken),
|
||||
});
|
||||
const apiExperience: string = DefaultExperienceUtility.getDefaultExperienceFromApiKind(
|
||||
config.encryptedTokenMetadata.apiKind
|
||||
);
|
||||
const apiExperience = DefaultExperienceUtility.getDefaultExperienceFromApiKind(config.encryptedTokenMetadata.apiKind);
|
||||
const explorer = new Explorer(explorerParams);
|
||||
explorer.configure({
|
||||
databaseAccount: {
|
||||
|
Loading…
Reference in New Issue
Block a user