diff --git a/packages/node_modules/@node-red/nodes/core/common/20-inject.html b/packages/node_modules/@node-red/nodes/core/common/20-inject.html index 206b1e36a..3dca922ac 100644 --- a/packages/node_modules/@node-red/nodes/core/common/20-inject.html +++ b/packages/node_modules/@node-red/nodes/core/common/20-inject.html @@ -168,21 +168,38 @@ inputs:0, outputs:1, outputLabels: function(index) { - var lab = this.payloadType; - if (lab === "json") { - try { - lab = typeof JSON.parse(this.payload); - if (lab === "object") { - if (Array.isArray(JSON.parse(this.payload))) { lab = "Array"; } - } - } catch(e) { - return this._("inject.label.invalid"); } - } - var name = "inject.label."+lab; - var label = this._(name); - if (name !== label) { - return label; + var lab = ''; + + // if only payload and topic - display payload type + // if only one property - show it's type + // if more than one property (other than payload and topic) - show "x properties" where x is the number of properties. + + // this.props will not be an array for legacy inject nodes until they are re-deployed + if (Array.isArray(this.props)) { + var propertyCount = this.props.length; + var payloadProperty = this.props.find(p => p.p === 'payload'); + var topicProperty = this.props.find(p => p.p === 'topic' && p.vt === 'str'); + + if (payloadProperty && topicProperty) { + lab = payloadProperty.vt; + } else if (propertyCount > 1){ + lab = propertyCount + ' properties'; + } else if(propertyCount === 1){ + lab = this.props[0].vt; + } + + // Friendly names + switch(lab){ + case 'date': lab = 'timestamp'; break; + case 'str': lab = 'string'; break; + case 'num': lab = 'number'; break; + case 'bin': lab = 'buffer'; break; + case '': lab = 'nothing'; break; + } + }else{ + lab = 'legacy payload'; } + return lab; }, label: function() {