From 8727c20ea4a2f4633c949245f13b4d493eecfc0e Mon Sep 17 00:00:00 2001 From: Jun Han Date: Fri, 20 Sep 2019 16:02:51 +0800 Subject: [PATCH] Show interface ids instead of interface names (#380) * Show interface ids instead of interface names * Resolve comment --- src/Nodes/InterfaceLabelNode.ts | 9 +++++++-- src/constants.ts | 1 + src/utility.ts | 11 +++++++++++ tsconfig.json | 2 +- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/Nodes/InterfaceLabelNode.ts b/src/Nodes/InterfaceLabelNode.ts index 007a5df..1e57b8a 100644 --- a/src/Nodes/InterfaceLabelNode.ts +++ b/src/Nodes/InterfaceLabelNode.ts @@ -34,10 +34,15 @@ export class InterfaceLabelNode implements INode { "get", ))).data; TelemetryClient.sendEvent(Constants.IoTHubAILoadInterfacesTreeDoneEvent, { Result: "Success" }); - if (!interfaces || !interfaces.interfaces || Object.keys(interfaces.interfaces).length === 0) { + let interfaceIds = []; + const reportedInterfaces = Utility.getReportedInterfacesFromDigitalTwin(interfaces); + if (reportedInterfaces) { + interfaceIds = Object.values(reportedInterfaces); + } + if (interfaceIds.length === 0) { return [new InfoNode("No Interfaces")]; } - return Object.keys(interfaces.interfaces).map((name) => new InterfaceNode(name, context.asAbsolutePath(path.join("resources", `interface.svg`)))); + return interfaceIds.map((name) => new InterfaceNode(name, context.asAbsolutePath(path.join("resources", `interface.svg`)))); } catch (err) { TelemetryClient.sendEvent(Constants.IoTHubAILoadInterfacesTreeDoneEvent, { Result: "Fail", Message: err.message }); if (err.response && err.response.status === 400) { diff --git a/src/constants.ts b/src/constants.ts index 874e921..1614599 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -125,6 +125,7 @@ export class Constants { public static StateKeyIoTHubID = "iothubid"; public static IoTHubAILoadInterfacesTreeStartEvent = "AZ.LoadInterfacesTree.Start"; public static IoTHubAILoadInterfacesTreeDoneEvent = "AZ.LoadInterfacesTree.Done"; + public static modelDiscoveryInterfaceName = "urn_azureiot_ModelDiscovery_DigitalTwin"; public static DeleteLabel = "Delete"; public static DeleteMessage = "Are you sure you want to delete"; public static readonly DISTRIBUTED_TWIN_NAME: string = "azureiot*com^dtracing^1"; diff --git a/src/utility.ts b/src/utility.ts index 801ae33..c17206e 100644 --- a/src/utility.ts +++ b/src/utility.ts @@ -434,6 +434,17 @@ export class Utility { }; } + public static getReportedInterfacesFromDigitalTwin(interfaces) { + return interfaces && + interfaces.interfaces && + interfaces.interfaces[Constants.modelDiscoveryInterfaceName] && + interfaces.interfaces[Constants.modelDiscoveryInterfaceName].properties && + interfaces.interfaces[Constants.modelDiscoveryInterfaceName].properties.modelInformation && + interfaces.interfaces[Constants.modelDiscoveryInterfaceName].properties.modelInformation.reported && + interfaces.interfaces[Constants.modelDiscoveryInterfaceName].properties.modelInformation.reported.value && + interfaces.interfaces[Constants.modelDiscoveryInterfaceName].properties.modelInformation.reported.value.interfaces; + } + private static tryGetStringFromCharCode(source) { if (source instanceof Uint8Array) { try { diff --git a/tsconfig.json b/tsconfig.json index 11282c9..3515cbd 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,7 +4,7 @@ "target": "es6", "outDir": "out", "lib": [ - "es6" + "es2017" ], "sourceMap": true, "rootDir": "."