Add Arc MIAA delete action back (#11901)

* Add Arc MIAA delete action back

* fix
This commit is contained in:
Charles Gagnon
2020-08-21 14:10:29 -07:00
committed by GitHub
parent b4d61a067e
commit a6efd56844
14 changed files with 259 additions and 253 deletions

View File

@@ -51,7 +51,7 @@ export class AzureArcTreeDataProvider implements vscode.TreeDataProvider<TreeNod
}
public async addOrUpdateController(model: ControllerModel, password: string, refreshTree = true): Promise<void> {
const controllerNode = this._controllerNodes.find(node => model.equals(node.model));
const controllerNode = this.getControllerNode(model);
if (controllerNode) {
controllerNode.model.info = model.info;
} else {
@@ -64,6 +64,10 @@ export class AzureArcTreeDataProvider implements vscode.TreeDataProvider<TreeNod
await this.saveControllers();
}
public getControllerNode(model: ControllerModel): ControllerTreeNode | undefined {
return this._controllerNodes.find(node => model.equals(node.model));
}
public async removeController(controllerNode: ControllerTreeNode): Promise<void> {
this._controllerNodes = this._controllerNodes.filter(node => node !== controllerNode);
this._onDidChangeTreeData.fire(undefined);
@@ -115,17 +119,16 @@ export class AzureArcTreeDataProvider implements vscode.TreeDataProvider<TreeNod
* Opens the dashboard for the specified resource
* @param controllerModel The model for the controller containing the resource we want to open the dashboard for
* @param resourceType The resourceType for the resource
* @param namespace The namespace of the resource
* @param name The name of the resource
*/
public async openResourceDashboard(controllerModel: ControllerModel, resourceType: string, namespace: string, name: string): Promise<void> {
public async openResourceDashboard(controllerModel: ControllerModel, resourceType: string, name: string): Promise<void> {
const controllerNode = this._controllerNodes.find(n => n.model === controllerModel);
if (controllerNode) {
const resourceNode = controllerNode.getResourceNode(resourceType, namespace, name);
const resourceNode = controllerNode.getResourceNode(resourceType, name);
if (resourceNode) {
} else {
console.log(`Couldn't find resource node for ${namespace}.${name} (${resourceType})`);
console.log(`Couldn't find resource node for ${name} (${resourceType})`);
}
await resourceNode?.openDashboard();
} else {

View File

@@ -13,7 +13,6 @@ import { ControllerDashboard } from '../dashboards/controller/controllerDashboar
import { PostgresModel } from '../../models/postgresModel';
import { parseInstanceName, UserCancelledError } from '../../common/utils';
import { MiaaModel } from '../../models/miaaModel';
import { Deferred } from '../../common/promise';
import { RefreshTreeNode } from './refreshTreeNode';
import { ResourceTreeNode } from './resourceTreeNode';
import { AzureArcTreeDataProvider } from './azureArcTreeDataProvider';
@@ -25,24 +24,20 @@ import * as loc from '../../localizedConstants';
export class ControllerTreeNode extends TreeNode {
private _children: ResourceTreeNode[] = [];
private _childrenRefreshPromise = new Deferred();
constructor(public model: ControllerModel, private _context: vscode.ExtensionContext, private _treeDataProvider: AzureArcTreeDataProvider) {
super(model.label, vscode.TreeItemCollapsibleState.Collapsed, ResourceType.dataControllers);
model.onRegistrationsUpdated(registrations => this.refreshChildren(registrations));
}
public async getChildren(): Promise<TreeNode[]> {
// First reset our deferred promise so we're sure we'll get the refreshed children
this._childrenRefreshPromise = new Deferred();
try {
await this.model.refresh(false);
await this._childrenRefreshPromise.promise;
this.updateChildren(this.model.registrations);
} catch (err) {
vscode.window.showErrorMessage(loc.errorConnectingToController(err));
try {
await this.model.refresh(false, true);
await this._childrenRefreshPromise.promise;
this.updateChildren(this.model.registrations);
} catch (err) {
if (!(err instanceof UserCancelledError)) {
vscode.window.showErrorMessage(loc.errorConnectingToController(err));
@@ -65,17 +60,15 @@ export class ControllerTreeNode extends TreeNode {
/**
* Finds and returns the ResourceTreeNode specified if it exists, otherwise undefined
* @param resourceType The resourceType of the node
* @param namespace The namespace of the node
* @param name The name of the node
*/
public getResourceNode(resourceType: string, namespace: string, name: string): ResourceTreeNode | undefined {
public getResourceNode(resourceType: string, name: string): ResourceTreeNode | undefined {
return this._children.find(c =>
c.model?.info.resourceType === resourceType &&
c.model?.info.namespace === namespace &&
c.model.info.name === name);
}
private refreshChildren(registrations: Registration[]): void {
private updateChildren(registrations: Registration[]): void {
const newChildren: ResourceTreeNode[] = [];
registrations.forEach(registration => {
if (!registration.instanceName) {
@@ -105,7 +98,7 @@ export class ControllerTreeNode extends TreeNode {
node = new PostgresTreeNode(postgresModel, this.model, this._context);
break;
case ResourceType.sqlManagedInstances:
const miaaModel = new MiaaModel(resourceInfo, registration, this._treeDataProvider);
const miaaModel = new MiaaModel(this.model, resourceInfo, registration, this._treeDataProvider);
node = new MiaaTreeNode(miaaModel, this.model);
break;
}
@@ -119,6 +112,5 @@ export class ControllerTreeNode extends TreeNode {
// Update our model info too
this.model.info.resources = <ResourceInfo[]>this._children.map(c => c.model?.info).filter(c => c);
this._treeDataProvider.saveControllers();
this._childrenRefreshPromise.resolve();
}
}