don't add full type label for sub array

pull/7/head
yann300 8 years ago
parent c62616543d
commit de53c8a0e6
  1. 29
      src/ui/SolidityTypeFormatter.js
  2. 10
      src/ui/TreeView.js

@ -9,31 +9,34 @@ module.exports = {
function formatData (key, data) { function formatData (key, data) {
var style = fontColor(data) var style = fontColor(data)
var type = '' var type = ''
if (!isArray(data.type) && !isStruct(data.type)) {
type = data.type
}
return yo`<label>${key}: <label style=${style}>${data.self}</label><label style='font-style:italic'> ${type}</label></label>` return yo`<label>${key}: <label style=${style}>${data.self}</label><label style='font-style:italic'> ${type}</label></label>`
} }
function extractData (item, key) { function extractData (item, parent, key) {
var ret = {} var ret = {}
if (isArray(item.type)) { if (item.type.lastIndexOf(']') === item.type.length - 1) {
ret.children = item.value || [] ret.children = item.value || []
ret.self = item.type ret.isArray = true
} else if (isStruct(item.type)) { if (!parent.isArray) {
ret.self = item.type
} else {
ret.self = 'Array'
}
} else if (item.type.indexOf('struct') === 0) {
ret.children = item.value || [] ret.children = item.value || []
ret.self = 'Struct' + '{' + Object.keys(ret.children).length + '}' ret.self = 'Struct' + '{' + Object.keys(ret.children).length + '}'
ret.isStruct = true
} else { } else {
ret.children = [] ret.children = []
ret.self = item.value ret.self = item.value
ret.type = item.type
} }
ret.type = item.type
return ret return ret
} }
function fontColor (data) { function fontColor (data) {
var color = '#124B46' var color = '#124B46'
if (isArray(data.type) || isStruct(data.type)) { if (data.isArray || data.isStruct) {
color = '#847979' color = '#847979'
} else if (data.type.indexOf('uint') === 0 || } else if (data.type.indexOf('uint') === 0 ||
data.type.indexOf('int') === 0 || data.type.indexOf('int') === 0 ||
@ -45,11 +48,3 @@ function fontColor (data) {
} }
return 'color:' + color return 'color:' + color
} }
function isArray (type) {
return type.lastIndexOf(']') === type.length - 1
}
function isStruct (type) {
return type.indexOf('struct') === 0 && !isArray(type)
}

@ -35,17 +35,17 @@ class TreeView {
} }
} }
renderObject (item, key, expand) { renderObject (item, parent, key, expand) {
var data = this.extractData(item, key) var data = this.extractData(item, parent, key)
var children = Object.keys(data.children).map((innerkey) => { var children = Object.keys(data.children).map((innerkey) => {
return this.renderObject(data.children[innerkey], innerkey, expand) return this.renderObject(data.children[innerkey], data, innerkey, expand)
}) })
return this.formatDataInternal(key, data, children, expand) return this.formatDataInternal(key, data, children, expand)
} }
renderProperties (json, expand) { renderProperties (json, expand) {
var children = Object.keys(json).map((innerkey) => { var children = Object.keys(json).map((innerkey) => {
return this.renderObject(json[innerkey], innerkey, expand) return this.renderObject(json[innerkey], json, innerkey, expand)
}) })
return yo`<ul style=${this.cssList}>${children}</ul>` return yo`<ul style=${this.cssList}>${children}</ul>`
} }
@ -70,7 +70,7 @@ class TreeView {
return yo`<label>${key}: ${data.self}</label>` return yo`<label>${key}: ${data.self}</label>`
} }
extractDataDefault (item, key) { extractDataDefault (item, parent, key) {
var ret = {} var ret = {}
if (item instanceof Array) { if (item instanceof Array) {
ret.children = item ret.children = item

Loading…
Cancel
Save