-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
List PnP Interfaces in tree view (#354)
* Interfaces list * Add BI and icon * Add refresh button * Wrap REST Api
- Loading branch information
1 parent
08cc565
commit f4b03c0
Showing
8 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
import { TreeItem } from "vscode"; | ||
|
||
export class InterfaceItem extends TreeItem { | ||
constructor(name: string, public readonly iconPath: string) { | ||
super(name); | ||
this.contextValue = "interface"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
import axios from "axios"; | ||
import * as path from "path"; | ||
import * as vscode from "vscode"; | ||
import { Constants } from "../constants"; | ||
import { TelemetryClient } from "../telemetryClient"; | ||
import { Utility } from "../utility"; | ||
import { DeviceNode } from "./DeviceNode"; | ||
import { InfoNode } from "./InfoNode"; | ||
import { INode } from "./INode"; | ||
import { InterfaceNode } from "./InterfaceNode"; | ||
|
||
export class InterfaceLabelNode implements INode { | ||
constructor(public deviceNode: DeviceNode) { | ||
} | ||
|
||
public getTreeItem(): vscode.TreeItem { | ||
return { | ||
label: "Interfaces", | ||
collapsibleState: vscode.TreeItemCollapsibleState.Collapsed, | ||
contextValue: "interfaces-label", | ||
}; | ||
} | ||
|
||
public async getChildren(context: vscode.ExtensionContext, iotHubConnectionString: string): Promise<INode[]> { | ||
TelemetryClient.sendEvent(Constants.IoTHubAILoadInterfacesTreeStartEvent); | ||
|
||
try { | ||
const interfaces = (await axios.request(Utility.generateIoTHubAxiosRequestConfig( | ||
iotHubConnectionString, | ||
`/digitalTwins/${this.deviceNode.deviceId}/interfaces?api-version=${Constants.IoTHubApiVersion}`, | ||
"get", | ||
))).data; | ||
TelemetryClient.sendEvent(Constants.IoTHubAILoadInterfacesTreeDoneEvent, { Result: "Success" }); | ||
if (!interfaces || !interfaces.interfaces || Object.keys(interfaces.interfaces).length === 0) { | ||
return [new InfoNode("No Interfaces")]; | ||
} | ||
return Object.keys(interfaces.interfaces).map((name) => new InterfaceNode(name, context.asAbsolutePath(path.join("resources", `interface.svg`)))); | ||
} catch (err) { | ||
TelemetryClient.sendEvent(Constants.IoTHubAILoadInterfacesTreeDoneEvent, { Result: "Fail", Message: err.message }); | ||
return Utility.getErrorMessageTreeItems("interfaces", err.message); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
import * as vscode from "vscode"; | ||
import { InterfaceItem } from "../Model/InterfaceItem"; | ||
import { INode } from "./INode"; | ||
|
||
export class InterfaceNode implements INode { | ||
constructor(private name: string, private iconPath: string) { | ||
} | ||
|
||
public getTreeItem(): vscode.TreeItem { | ||
return new InterfaceItem(this.name, this.iconPath); | ||
} | ||
|
||
public getChildren(): INode[] { | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters