Skip to content

Commit

Permalink
Dev/sda/tree api migration (#2533)
Browse files Browse the repository at this point in the history
Syncing with @bk201- work
  • Loading branch information
bk201- authored Jan 15, 2025
1 parent f5a9763 commit ff895fe
Show file tree
Hide file tree
Showing 32 changed files with 675 additions and 668 deletions.
17 changes: 13 additions & 4 deletions extension.bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,28 @@ export { emulatorPassword, isWindows } from './src/constants';
export { ParsedDocDBConnectionString, parseDocDBConnectionString } from './src/docdb/docDBConnectionStrings';
export { getCosmosClient } from './src/docdb/getCosmosClient';
export * from './src/docdb/registerDocDBCommands';
export { activateInternal, cosmosDBCopyConnectionString, createServer, deactivateInternal, deleteAccount } from './src/extension';
export {
activateInternal,
cosmosDBCopyConnectionString,
createServer,
deactivateInternal,
deleteAccount,
} from './src/extension';
export { ext } from './src/extensionVariables';
export * from './src/graph/registerGraphCommands';
export { connectToMongoClient, isCosmosEmulatorConnectionString } from './src/mongo/connectToMongoClient';
export { MongoCommand } from './src/mongo/MongoCommand';
export {
addDatabaseToAccountConnectionString,
encodeMongoConnectionString,
getDatabaseNameFromConnectionString,
} from './src/mongo/mongoConnectionStrings';
export { findCommandAtPosition, getAllCommandsFromText } from './src/mongo/MongoScrapbook';
export { MongoShell } from './src/mongo/MongoShell';
export { connectToMongoClient, isCosmosEmulatorConnectionString } from './src/mongo/connectToMongoClient';
export { addDatabaseToAccountConnectionString, encodeMongoConnectionString, getDatabaseNameFromConnectionString } from './src/mongo/mongoConnectionStrings';
export * from './src/mongo/registerMongoCommands';
export { IDatabaseInfo } from './src/mongo/tree/MongoAccountTreeItem';
export { addDatabaseToConnectionString } from './src/postgres/postgresConnectionStrings';
export { AttachedAccountsTreeItem, MONGO_CONNECTION_EXPECTED } from './src/tree/AttachedAccountsTreeItem';
export { AzureAccountTreeItemWithAttached } from './src/tree/AzureAccountTreeItemWithAttached';
export * from './src/utils/azureClients';
export { getPublicIpv4, isIpInRanges } from './src/utils/getIp';
export { improveError } from './src/utils/improveError';
Expand Down
525 changes: 229 additions & 296 deletions package.json

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion src/commands/deleteDatabaseAccount/deleteCosmosDBAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { type CosmosDBManagementClient } from '@azure/arm-cosmosdb';
import { getResourceGroupFromId } from '@microsoft/vscode-azext-azureutils';
import { AzExtTreeItem, createSubscriptionContext } from '@microsoft/vscode-azext-utils';
import { type AzureSubscription } from '@microsoft/vscode-azureresources-api';
import * as vscode from 'vscode';
import { ext } from '../../extensionVariables';
import { CosmosAccountResourceItemBase } from '../../tree/CosmosAccountResourceItemBase';
Expand All @@ -27,7 +28,13 @@ export async function deleteCosmosDBAccount(
resourceGroup = getResourceGroupFromId(node.fullId);
accountName = getDatabaseAccountNameFromId(node.fullId);
} else if (node instanceof CosmosAccountResourceItemBase) {
const subscriptionContext = createSubscriptionContext(node.account.subscription);
// Not all CosmosAccountResourceItemBase instances have a subscription property (attached account does not),
// so we need to create a subscription context
if (!('subscription' in node.account)) {
throw new Error('Subscription is required to delete an account.');
}

const subscriptionContext = createSubscriptionContext(node.account.subscription as AzureSubscription);
client = await createCosmosDBClient([context, subscriptionContext]);
resourceGroup = getResourceGroupFromId(node.account.id);
accountName = node.account.name;
Expand Down
13 changes: 9 additions & 4 deletions src/commands/deleteDatabaseAccount/deleteDatabaseAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
type IActionContext,
type ISubscriptionContext,
} from '@microsoft/vscode-azext-utils';
import { type MongoClusterResourceItem } from '../../mongoClusters/tree/MongoClusterResourceItem';
import { type AzureSubscription } from '@microsoft/vscode-azureresources-api';
import { MongoClusterResourceItem } from '../../mongoClusters/tree/MongoClusterResourceItem';
import { CosmosAccountResourceItemBase } from '../../tree/CosmosAccountResourceItemBase';
import { createActivityContext } from '../../utils/activityUtils';
import { localize } from '../../utils/localize';
Expand All @@ -26,10 +27,14 @@ export async function deleteDatabaseAccount(
let subscription: ISubscriptionContext;
if (node instanceof AzExtTreeItem) {
subscription = node.subscription;
} else if (node instanceof CosmosAccountResourceItemBase) {
subscription = createSubscriptionContext(node.account.subscription);
} else if (node instanceof CosmosAccountResourceItemBase && 'subscription' in node.account) {
subscription = createSubscriptionContext(node.account.subscription as AzureSubscription);
} else if (node instanceof MongoClusterResourceItem) {
subscription = createSubscriptionContext(node.subscription);
} else {
subscription = createSubscriptionContext((node as MongoClusterResourceItem).subscription);
// Not all CosmosAccountResourceItemBase instances have a subscription property (attached account does not),
// so we need to create a subscription context
throw new Error('Subscription is required to delete an account.');
}

let accountName: string;
Expand Down
17 changes: 2 additions & 15 deletions src/extensionVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import {
type AzExtTreeDataProvider,
type AzExtTreeItem,
type IAzExtLogOutputChannel,
type TreeElementStateManager,
} from '@microsoft/vscode-azext-utils';
import { type IAzExtLogOutputChannel, type TreeElementStateManager } from '@microsoft/vscode-azext-utils';
import { type AzureHostExtensionApi } from '@microsoft/vscode-azext-utils/hostapi';
import { type AzureResourcesExtensionApi } from '@microsoft/vscode-azureresources-api';
import { type ExtensionContext, type SecretStorage, type TreeView } from 'vscode';
import { type ExtensionContext, type SecretStorage } from 'vscode';
import { type DatabasesFileSystem } from './DatabasesFileSystem';
import { type NoSqlCodeLensProvider } from './docdb/NoSqlCodeLensProvider';
import { type MongoDBLanguageClient } from './mongo/languageClient';
Expand All @@ -22,8 +17,6 @@ import { type MongoClustersWorkspaceBranchDataProvider } from './mongoClusters/t
import { type PostgresCodeLensProvider } from './postgres/services/PostgresCodeLensProvider';
import { type PostgresDatabaseTreeItem } from './postgres/tree/PostgresDatabaseTreeItem';
import { type AttachedAccountsTreeItem } from './tree/AttachedAccountsTreeItem';
import { type AzureAccountTreeItemWithAttached } from './tree/AzureAccountTreeItemWithAttached';
import { type SharedWorkspaceResourceProvider } from './tree/workspace/SharedWorkspaceResourceProvider';

/**
* Namespace for common variables used throughout the extension. They must be initialized in the activate() method of extension.ts
Expand All @@ -33,11 +26,8 @@ export namespace ext {
export let connectedPostgresDB: PostgresDatabaseTreeItem | undefined;
export let context: ExtensionContext;
export let outputChannel: IAzExtLogOutputChannel;
export let tree: AzExtTreeDataProvider;
export let treeView: TreeView<AzExtTreeItem>;
export let attachedAccountsNode: AttachedAccountsTreeItem;
export let isBundle: boolean | undefined;
export let azureAccountTreeItem: AzureAccountTreeItemWithAttached;
export let secretStorage: SecretStorage;
export let postgresCodeLensProvider: PostgresCodeLensProvider | undefined;
export const prefix: string = 'azureDatabases';
Expand All @@ -53,9 +43,6 @@ export namespace ext {
// used for the resources tree
export let mongoClustersBranchDataProvider: MongoClustersBranchDataProvider;

// used for the workspace: this is the general provider
export let workspaceDataProvider: SharedWorkspaceResourceProvider;

// used for the workspace: these are the dedicated providers
export let mongoClustersWorkspaceBranchDataProvider: MongoClustersWorkspaceBranchDataProvider;

Expand Down
22 changes: 14 additions & 8 deletions src/mongoClusters/tree/CollectionItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,26 @@ import {
type TreeElementWithId,
} from '@microsoft/vscode-azext-utils';
import { type Document } from 'bson';
import { ThemeIcon, TreeItemCollapsibleState, type TreeItem } from 'vscode';
import { type Experience } from '../../AzureDBExperiences';
import { ThemeIcon, type TreeItem, TreeItemCollapsibleState } from 'vscode';
import { API, type Experience } from '../../AzureDBExperiences';
import { ext } from '../../extensionVariables';
import { type TreeElementWithContextValue } from '../../tree/TreeElementWithContextValue';
import { type TreeElementWithExperience } from '../../tree/TreeElementWithExperience';
import {
MongoClustersClient,
type CollectionItemModel,
type DatabaseItemModel,
type InsertDocumentsResult,
MongoClustersClient,
} from '../MongoClustersClient';
import { IndexesItem } from './IndexesItem';
import { type MongoClusterModel } from './MongoClusterModel';

export class CollectionItem implements TreeElementWithId, TreeElementWithExperience {
id: string;
experience?: Experience;
export class CollectionItem implements TreeElementWithId, TreeElementWithExperience, TreeElementWithContextValue {
public readonly id: string;
public readonly experience?: Experience;
public readonly contextValue: string = 'treeItem.collection';

private readonly experienceContextValue: string = '';

constructor(
readonly mongoCluster: MongoClusterModel,
Expand All @@ -35,12 +39,14 @@ export class CollectionItem implements TreeElementWithId, TreeElementWithExperie
) {
this.id = `${mongoCluster.id}/${databaseInfo.name}/${collectionInfo.name}`;
this.experience = mongoCluster.dbExperience;
this.experienceContextValue = `experience.${this.experience?.api ?? API.Common}`;
this.contextValue = createContextValue([this.contextValue, this.experienceContextValue]);
}

async getChildren(): Promise<TreeElementBase[]> {
return [
createGenericElement({
contextValue: createContextValue(['treeitem.documents', this.mongoCluster.dbExperience?.api ?? '']),
contextValue: createContextValue(['treeItem.documents', this.experienceContextValue]),
id: `${this.id}/documents`,
label: 'Documents',
commandId: 'command.internal.mongoClusters.containerView.open',
Expand Down Expand Up @@ -90,7 +96,7 @@ export class CollectionItem implements TreeElementWithId, TreeElementWithExperie
getTreeItem(): TreeItem {
return {
id: this.id,
contextValue: createContextValue(['treeitem.collection', this.mongoCluster.dbExperience?.api ?? '']),
contextValue: this.contextValue,
label: this.collectionInfo.name,
iconPath: new ThemeIcon('folder-opened'),
collapsibleState: TreeItemCollapsibleState.Collapsed,
Expand Down
23 changes: 13 additions & 10 deletions src/mongoClusters/tree/DatabaseItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,30 @@ import {
} from '@microsoft/vscode-azext-utils';
import * as vscode from 'vscode';
import { ThemeIcon, TreeItemCollapsibleState, type TreeItem } from 'vscode';
import { type Experience } from '../../AzureDBExperiences';
import { API, type Experience } from '../../AzureDBExperiences';
import { ext } from '../../extensionVariables';
import { type TreeElementWithContextValue } from '../../tree/TreeElementWithContextValue';
import { type TreeElementWithExperience } from '../../tree/TreeElementWithExperience';
import { localize } from '../../utils/localize';
import { MongoClustersClient, type DatabaseItemModel } from '../MongoClustersClient';
import { CollectionItem } from './CollectionItem';
import { type MongoClusterModel } from './MongoClusterModel';

export class DatabaseItem implements TreeElementWithId, TreeElementWithExperience {
id: string;
experience?: Experience;
export class DatabaseItem implements TreeElementWithId, TreeElementWithExperience, TreeElementWithContextValue {
public readonly id: string;
public readonly experience?: Experience;
public readonly contextValue: string = 'treeItem.database';

private readonly experienceContextValue: string = '';

constructor(
readonly mongoCluster: MongoClusterModel,
readonly databaseInfo: DatabaseItemModel,
) {
this.id = `${mongoCluster.id}/${databaseInfo.name}`;
this.experience = mongoCluster.dbExperience;
this.experienceContextValue = `experience.${this.experience?.api ?? API.Common}`;
this.contextValue = createContextValue([this.contextValue, this.experienceContextValue]);
}

async getChildren(): Promise<TreeElementBase[]> {
Expand All @@ -40,11 +46,8 @@ export class DatabaseItem implements TreeElementWithId, TreeElementWithExperienc
// no databases in there:
return [
createGenericElement({
contextValue: createContextValue([
'treeitem.no-collections',
this.mongoCluster.dbExperience?.api ?? '',
]),
id: `${this.id}/no-databases`,
contextValue: createContextValue(['treeItem.no-collections', this.experienceContextValue]),
id: `${this.id}/no-collections`,
label: 'Create collection...',
iconPath: new vscode.ThemeIcon('plus'),
commandId: 'command.mongoClusters.createCollection',
Expand Down Expand Up @@ -94,7 +97,7 @@ export class DatabaseItem implements TreeElementWithId, TreeElementWithExperienc
getTreeItem(): TreeItem {
return {
id: this.id,
contextValue: createContextValue(['treeitem.database', this.mongoCluster.dbExperience?.api ?? '']),
contextValue: this.contextValue,
label: this.databaseInfo.name,
iconPath: new ThemeIcon('database'), // TODO: create our own icon here, this one's shape can change
collapsibleState: TreeItemCollapsibleState.Collapsed,
Expand Down
16 changes: 11 additions & 5 deletions src/mongoClusters/tree/IndexItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ import {
type TreeElementWithId,
} from '@microsoft/vscode-azext-utils';
import { ThemeIcon, TreeItemCollapsibleState, type TreeItem } from 'vscode';
import { type Experience } from '../../AzureDBExperiences';
import { API, type Experience } from '../../AzureDBExperiences';
import { type TreeElementWithContextValue } from '../../tree/TreeElementWithContextValue';
import { type TreeElementWithExperience } from '../../tree/TreeElementWithExperience';
import { type CollectionItemModel, type DatabaseItemModel, type IndexItemModel } from '../MongoClustersClient';
import { type MongoClusterModel } from './MongoClusterModel';

export class IndexItem implements TreeElementWithId, TreeElementWithExperience {
id: string;
experience?: Experience;
export class IndexItem implements TreeElementWithId, TreeElementWithExperience, TreeElementWithContextValue {
public readonly id: string;
public readonly experience?: Experience;
public readonly contextValue: string = 'treeItem.index';

private readonly experienceContextValue: string = '';

constructor(
readonly mongoCluster: MongoClusterModel,
Expand All @@ -27,6 +31,8 @@ export class IndexItem implements TreeElementWithId, TreeElementWithExperience {
) {
this.id = `${mongoCluster.id}/${databaseInfo.name}/${collectionInfo.name}/indexes/${indexInfo.name}`;
this.experience = mongoCluster.dbExperience;
this.experienceContextValue = `experience.${this.experience?.api ?? API.Common}`;
this.contextValue = createContextValue([this.contextValue, this.experienceContextValue]);
}

async getChildren(): Promise<TreeElementBase[]> {
Expand All @@ -47,7 +53,7 @@ export class IndexItem implements TreeElementWithId, TreeElementWithExperience {
getTreeItem(): TreeItem {
return {
id: this.id,
contextValue: createContextValue(['treeitem.index', this.mongoCluster.dbExperience?.api ?? '']),
contextValue: this.contextValue,
label: this.indexInfo.name,
iconPath: new ThemeIcon('combine'), // TODO: create our onw icon here, this one's shape can change
collapsibleState: TreeItemCollapsibleState.Collapsed,
Expand Down
16 changes: 11 additions & 5 deletions src/mongoClusters/tree/IndexesItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@

import { createContextValue, type TreeElementBase, type TreeElementWithId } from '@microsoft/vscode-azext-utils';
import { ThemeIcon, TreeItemCollapsibleState, type TreeItem } from 'vscode';
import { type Experience } from '../../AzureDBExperiences';
import { API, type Experience } from '../../AzureDBExperiences';
import { type TreeElementWithContextValue } from '../../tree/TreeElementWithContextValue';
import { type TreeElementWithExperience } from '../../tree/TreeElementWithExperience';
import { MongoClustersClient, type CollectionItemModel, type DatabaseItemModel } from '../MongoClustersClient';
import { IndexItem } from './IndexItem';
import { type MongoClusterModel } from './MongoClusterModel';

export class IndexesItem implements TreeElementWithId, TreeElementWithExperience {
id: string;
experience?: Experience;
export class IndexesItem implements TreeElementWithId, TreeElementWithExperience, TreeElementWithContextValue {
public readonly id: string;
public readonly experience?: Experience;
public readonly contextValue: string = 'treeItem.indexes';

private readonly experienceContextValue: string = '';

constructor(
readonly mongoCluster: MongoClusterModel,
Expand All @@ -22,6 +26,8 @@ export class IndexesItem implements TreeElementWithId, TreeElementWithExperience
) {
this.id = `${mongoCluster.id}/${databaseInfo.name}/${collectionInfo.name}/indexes`;
this.experience = mongoCluster.dbExperience;
this.experienceContextValue = `experience.${this.experience?.api ?? API.Common}`;
this.contextValue = createContextValue([this.contextValue, this.experienceContextValue]);
}

async getChildren(): Promise<TreeElementBase[]> {
Expand All @@ -35,7 +41,7 @@ export class IndexesItem implements TreeElementWithId, TreeElementWithExperience
getTreeItem(): TreeItem {
return {
id: this.id,
contextValue: createContextValue(['treeitem.indexes', this.mongoCluster.dbExperience?.api ?? '']),
contextValue: this.contextValue,
label: 'Indexes',
iconPath: new ThemeIcon('combine'), // TODO: create our onw icon here, this one's shape can change
collapsibleState: TreeItemCollapsibleState.Collapsed,
Expand Down
Loading

0 comments on commit ff895fe

Please sign in to comment.