Skip to content

Commit

Permalink
add float to zero check
Browse files Browse the repository at this point in the history
  • Loading branch information
emicklei committed Jun 21, 2024
1 parent 9d1dac7 commit 99e54ff
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
23 changes: 12 additions & 11 deletions explorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
)

type objectAccess struct {
isRoot bool // set to true if is was one of the values at start
object any
path []string
label string
typeName string
hideNils bool
isRoot bool // set to true if is was one of the values at start
object any
path []string
label string
typeName string
hideZeros bool
}

func (o objectAccess) Value() any {
Expand Down Expand Up @@ -65,11 +65,12 @@ func newExplorerOnAll(labelValuePairs ...any) *explorer {
continue
}
s.objectAtPut(i, 0, objectAccess{
isRoot: true,
object: value,
path: []string{""},
label: label,
typeName: fmt.Sprintf("%T", value),
isRoot: true,
object: value,
path: []string{""},
label: label,
hideZeros: true,
typeName: fmt.Sprintf("%T", value),
})
}
return s
Expand Down
8 changes: 8 additions & 0 deletions field.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,11 @@ func stringToReflectMapKey(hash string, m reflect.Value) reflect.Value {
// not found is actually a bug
return reflect.ValueOf(nil)
}

func isZeroPrintstring(s string) bool {
switch s {
case `""`, "0", "false", "nil", "0.000000", "0.000":
return true
}
return false
}
2 changes: 1 addition & 1 deletion index_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (b *indexDataBuilder) build(row, column int, access objectAccess, value any
for i, each := range fields {
entries[i] = fieldEntry{
fieldAccess: each,
hideZero: access.hideNils,
hideZero: access.hideZeros,
}
}
b.data.Rows[row].Cells[column] = fieldList{
Expand Down
14 changes: 7 additions & 7 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ func (s *service) init() {
return printString(f.value())
},
"includeField": func(f fieldEntry, s string) bool {
switch s {
case `""`, "0", "false", "nil":
return f.hideZero
if isZeroPrintstring(s) {
return !f.hideZero
}
return true
},
Expand Down Expand Up @@ -160,7 +159,7 @@ func (s *service) serveInstructions(w http.ResponseWriter, r *http.Request) {
return
case "toggleZeros":
s.explorer.updateObjectAt(cmd.Row, cmd.Column, func(access objectAccess) objectAccess {
access.hideNils = !access.hideNils
access.hideZeros = !access.hideZeros
return access
})
return
Expand All @@ -172,9 +171,10 @@ func (s *service) serveInstructions(w http.ResponseWriter, r *http.Request) {
for _, each := range cmd.Selections {
newPath := append(fromAccess.path, each)
oa := objectAccess{
object: fromAccess.object,
path: newPath,
label: strings.Join(newPath, "."),
object: fromAccess.object,
path: newPath,
label: strings.Join(newPath, "."),
hideZeros: true,
}
v := oa.Value()
if !canExplore(v) {
Expand Down

0 comments on commit 99e54ff

Please sign in to comment.