Skip to content

Commit

Permalink
feat(pkger): add support for exporting table view charts
Browse files Browse the repository at this point in the history
closes: #16882
  • Loading branch information
jsteenb2 committed Mar 4, 2020
1 parent 17698db commit 78a50e2
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
47 changes: 47 additions & 0 deletions pkger/clone_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,23 @@ func convertCellView(cell influxdb.Cell) chart {
}
ch.Note = p.Note
ch.NoteOnEmpty = p.ShowNoteWhenEmpty
case influxdb.TableViewProperties:
setCommon(chartKindTable, p.ViewColors, p.DecimalPlaces, p.Queries)
setNoteFixes(p.Note, p.ShowNoteWhenEmpty, "", "")
ch.TimeFormat = p.TimeFormat
ch.TableOptions = tableOptions{
VerticalTimeAxis: p.TableOptions.VerticalTimeAxis,
SortByField: p.TableOptions.SortBy.InternalName,
Wrapping: p.TableOptions.Wrapping,
FixFirstColumn: p.TableOptions.FixFirstColumn,
}
for _, fieldOpt := range p.FieldOptions {
ch.FieldOptions = append(ch.FieldOptions, fieldOption{
FieldName: fieldOpt.InternalName,
DisplayName: fieldOpt.DisplayName,
Visible: fieldOpt.Visible,
})
}
case influxdb.XYViewProperties:
setCommon(chartKindXY, p.ViewColors, influxdb.DecimalPlaces{}, p.Queries)
setNoteFixes(p.Note, p.ShowNoteWhenEmpty, "", "")
Expand Down Expand Up @@ -299,6 +316,35 @@ func convertChartToResource(ch chart) Resource {
r[fieldChartLegend] = ch.Legend
}

if zero := new(tableOptions); ch.TableOptions != *zero {
tRes := make(Resource)
assignNonZeroBools(tRes, map[string]bool{
fieldChartTableOptionVerticalTimeAxis: ch.TableOptions.VerticalTimeAxis,
fieldChartTableOptionFixFirstColumn: ch.TableOptions.VerticalTimeAxis,
})
assignNonZeroStrings(tRes, map[string]string{
fieldChartTableOptionSortBy: ch.TableOptions.SortByField,
fieldChartTableOptionWrapping: ch.TableOptions.Wrapping,
})
r[fieldChartTableOptions] = tRes
}

if len(ch.FieldOptions) > 0 {
fieldOpts := make([]Resource, 0, len(ch.FieldOptions))
for _, fo := range ch.FieldOptions {
fRes := make(Resource)
assignNonZeroBools(fRes, map[string]bool{
fieldChartFieldOptionVisible: fo.Visible,
})
assignNonZeroStrings(fRes, map[string]string{
fieldChartFieldOptionDisplayName: fo.DisplayName,
fieldChartFieldOptionFieldName: fo.FieldName,
})
fieldOpts = append(fieldOpts, fRes)
}
r[fieldChartFieldOptions] = fieldOpts
}

assignNonZeroBools(r, map[string]bool{
fieldChartNoteOnEmpty: ch.NoteOnEmpty,
fieldChartShade: ch.Shade,
Expand All @@ -314,6 +360,7 @@ func convertChartToResource(ch chart) Resource {
fieldChartPosition: ch.Position,
fieldChartTickPrefix: ch.TickPrefix,
fieldChartTickSuffix: ch.TickSuffix,
fieldChartTimeFormat: ch.TimeFormat,
})

assignNonZeroInts(r, map[string]int{
Expand Down
36 changes: 36 additions & 0 deletions pkger/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1822,6 +1822,42 @@ func TestService(t *testing.T) {
},
},
},
{
name: "table",
newName: "new name",
expectedView: influxdb.View{
ViewContents: influxdb.ViewContents{
Name: "view name",
},
Properties: influxdb.TableViewProperties{
Type: influxdb.ViewPropertyTypeTable,
Note: "a note",
ShowNoteWhenEmpty: true,
Queries: []influxdb.DashboardQuery{newQuery()},
ViewColors: []influxdb.ViewColor{{Type: "scale", Hex: "#8F8AF4", Value: 0}, {Type: "scale", Hex: "#8F8AF4", Value: 0}, {Type: "scale", Hex: "#8F8AF4", Value: 0}},
TableOptions: influxdb.TableOptions{
VerticalTimeAxis: true,
SortBy: influxdb.RenamableField{
InternalName: "_time",
},
Wrapping: "truncate",
FixFirstColumn: true,
},
FieldOptions: []influxdb.RenamableField{
{
InternalName: "_time",
DisplayName: "time (ms)",
Visible: true,
},
},
TimeFormat: "YYYY:MM:DD",
DecimalPlaces: influxdb.DecimalPlaces{
IsEnforced: true,
Digits: 1,
},
},
},
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 78a50e2

Please sign in to comment.