diff --git a/CHANGELOG.md b/CHANGELOG.md index 048987aa719..35714ff4b3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ### Features +1. [17095](https://github.com/influxdata/influxdb/pull/17095): Extend pkger dashboards with table view support + ### Bug Fixes 1. [17039](https://github.com/influxdata/influxdb/pull/17039): Fixed issue where tasks are exported for notification rules diff --git a/pkger/clone_resource.go b/pkger/clone_resource.go index 655d13e29d1..781675e12ee 100644 --- a/pkger/clone_resource.go +++ b/pkger/clone_resource.go @@ -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, "", "") @@ -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, @@ -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{ diff --git a/pkger/service_test.go b/pkger/service_test.go index f4c33949cf6..f33cac0f581 100644 --- a/pkger/service_test.go +++ b/pkger/service_test.go @@ -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 {