Commit 577dfee0 by Torkel Ödegaard

dasboard_history: fixed json diff so only dashbord is compared and not the whole…

dasboard_history: fixed json diff so only dashbord is compared and not the whole dashboard revision object (message and restoreFrom etc was showing up in json diff)
parent 8f6c9c59
......@@ -6,6 +6,7 @@ import (
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/models"
diff "github.com/yudai/gojsondiff"
deltaFormatter "github.com/yudai/gojsondiff/formatter"
......@@ -17,6 +18,8 @@ var (
// ErrNilDiff occurs when two compared interfaces are identical.
ErrNilDiff = errors.New("dashdiff: diff is nil")
diffLogger = log.New("dashdiffs")
)
type DiffType int
......@@ -77,7 +80,10 @@ func CalculateDiff(options *Options) (*Result, error) {
return nil, err
}
left, jsonDiff, err := getDiff(baseVersionQuery.Result, newVersionQuery.Result)
baseData := baseVersionQuery.Result.Data
newData := newVersionQuery.Result.Data
left, jsonDiff, err := getDiff(baseData, newData)
if err != nil {
return nil, err
}
......@@ -115,13 +121,13 @@ func CalculateDiff(options *Options) (*Result, error) {
}
// getDiff computes the diff of two dashboard versions.
func getDiff(originalDash, newDash *models.DashboardVersion) (interface{}, diff.Diff, error) {
leftBytes, err := simplejson.NewFromAny(originalDash).Encode()
func getDiff(baseData, newData *simplejson.Json) (interface{}, diff.Diff, error) {
leftBytes, err := baseData.Encode()
if err != nil {
return nil, nil, err
}
rightBytes, err := simplejson.NewFromAny(newDash).Encode()
rightBytes, err := newData.Encode()
if err != nil {
return nil, nil, err
}
......
......@@ -97,14 +97,17 @@ func (b *BasicDiff) Basic(lines []*JSONLine) []*BasicBlock {
// iterate through each line
for _, line := range lines {
if b.LastIndent == 3 && line.Indent == 2 && line.Change == ChangeNil {
// TODO: this condition needs an explaination? what does it mean?
if b.LastIndent == 2 && line.Indent == 1 && line.Change == ChangeNil {
if b.Block != nil {
blocks = append(blocks, b.Block)
}
}
b.LastIndent = line.Indent
if line.Indent == 2 {
// TODO: why special handling for indent 2?
if line.Indent == 1 {
switch line.Change {
case ChangeNil:
if line.Change == ChangeNil {
......@@ -143,12 +146,14 @@ func (b *BasicDiff) Basic(lines []*JSONLine) []*BasicBlock {
}
}
// TODO: why special handling for indent > 2 ?
// Other Lines
if line.Indent > 2 {
if line.Indent > 1 {
// Ensure single line change
if line.Key != "" && line.Val != nil && !b.writing {
switch line.Change {
case ChangeAdded, ChangeDeleted:
b.Block.Changes = append(b.Block.Changes, &BasicChange{
Key: line.Key,
Change: line.Change,
......
......@@ -11,7 +11,7 @@
</li>
<li class="gf-tabs-item" ng-show="ctrl.mode === 'compare'">
<span class="active gf-tabs-link">
Version {{ctrl.baseInfo.version}} <i class="fa fa-arrows-h"></i> Version {{ctrl.newInfo.version}}
Version Comparison
</span>
</li>
</ul>
......@@ -123,7 +123,7 @@
Version {{ctrl.newInfo.version}}
<cite class="muted" ng-if="ctrl.isNewLatest">(Latest)</cite>
</h4>
<section ng-if="ctrl.diff === 'basic'">
<section>
<p class="small muted">
<strong>Version {{ctrl.newInfo.version}}</strong> updated by
<span>{{ctrl.newInfo.createdBy}} </span>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment