Skip to content

Commit d43ac45

Browse files
authored
Extract DashboardConfig struct (#3117)
## Changes Extract DashboardConfig out of Dashboard resource. ## Why It's going to be used in direct backend to store state.
1 parent 8b6919f commit d43ac45

File tree

8 files changed

+57
-36
lines changed

8 files changed

+57
-36
lines changed

bundle/config/mutator/initialize_urls_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,10 @@ func TestInitializeURLs(t *testing.T) {
8888
Dashboards: map[string]*resources.Dashboard{
8989
"dashboard1": {
9090
ID: "01ef8d56871e1d50ae30ce7375e42478",
91-
Dashboard: dashboards.Dashboard{
92-
DisplayName: "My special dashboard",
91+
DashboardConfig: resources.DashboardConfig{
92+
Dashboard: dashboards.Dashboard{
93+
DisplayName: "My special dashboard",
94+
},
9395
},
9496
},
9597
},

bundle/config/mutator/resourcemutator/apply_target_mode_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,10 @@ func mockBundle(mode config.Mode) *bundle.Bundle {
140140
},
141141
Dashboards: map[string]*resources.Dashboard{
142142
"dashboard1": {
143-
Dashboard: dashboards.Dashboard{
144-
DisplayName: "dashboard1",
143+
DashboardConfig: resources.DashboardConfig{
144+
Dashboard: dashboards.Dashboard{
145+
DisplayName: "dashboard1",
146+
},
145147
},
146148
},
147149
},

bundle/config/mutator/translate_paths_dashboards_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ func TestTranslatePathsDashboards_FilePathRelativeSubDirectory(t *testing.T) {
2929
Resources: config.Resources{
3030
Dashboards: map[string]*resources.Dashboard{
3131
"dashboard": {
32-
Dashboard: dashboards.Dashboard{
33-
DisplayName: "My Dashboard",
32+
DashboardConfig: resources.DashboardConfig{
33+
Dashboard: dashboards.Dashboard{
34+
DisplayName: "My Dashboard",
35+
},
3436
},
3537
FilePath: "../src/my_dashboard.lvdash.json",
3638
},

bundle/config/resources/dashboard.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,7 @@ type DashboardPermission struct {
2323
GroupName string `json:"group_name,omitempty"`
2424
}
2525

26-
type Dashboard struct {
27-
ID string `json:"id,omitempty" bundle:"readonly"`
28-
Permissions []DashboardPermission `json:"permissions,omitempty"`
29-
ModifiedStatus ModifiedStatus `json:"modified_status,omitempty" bundle:"internal"`
30-
URL string `json:"url,omitempty" bundle:"internal"`
31-
26+
type DashboardConfig struct {
3227
dashboards.Dashboard
3328

3429
// =========================
@@ -47,10 +42,20 @@ type Dashboard struct {
4742
//
4843
// Defaults to false if not set.
4944
EmbedCredentials bool `json:"embed_credentials,omitempty"`
45+
}
46+
47+
type Dashboard struct {
48+
ID string `json:"id,omitempty" bundle:"readonly"`
49+
Permissions []DashboardPermission `json:"permissions,omitempty"`
50+
ModifiedStatus ModifiedStatus `json:"modified_status,omitempty" bundle:"internal"`
51+
URL string `json:"url,omitempty" bundle:"internal"`
52+
53+
DashboardConfig
5054

5155
// FilePath points to the local `.lvdash.json` file containing the dashboard definition.
5256
// This is inlined into serialized_dashboard during deployment. The file_path is kept around
5357
// as metadata which is needed for `databricks bundle generate dashboard --resource <dashboard_key>` to work.
58+
// This is not part of DashboardConfig because we don't need to store this in the resource state.
5459
FilePath string `json:"file_path,omitempty"`
5560
}
5661

bundle/config/resources_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"github.com/databricks/databricks-sdk-go/experimental/mocks"
1616
"github.com/databricks/databricks-sdk-go/service/apps"
1717
"github.com/databricks/databricks-sdk-go/service/catalog"
18-
"github.com/databricks/databricks-sdk-go/service/dashboards"
1918
"github.com/databricks/databricks-sdk-go/service/jobs"
2019
"github.com/databricks/databricks-sdk-go/service/ml"
2120
"github.com/databricks/databricks-sdk-go/service/pipelines"
@@ -146,9 +145,7 @@ func TestResourcesBindSupport(t *testing.T) {
146145
"my_cluster": {},
147146
},
148147
Dashboards: map[string]*resources.Dashboard{
149-
"my_dashboard": {
150-
Dashboard: dashboards.Dashboard{},
151-
},
148+
"my_dashboard": {},
152149
},
153150
Volumes: map[string]*resources.Volume{
154151
"my_volume": {

bundle/deploy/terraform/check_dashboards_modified_remotely_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ func mockDashboardBundle(t *testing.T) *bundle.Bundle {
2828
Resources: config.Resources{
2929
Dashboards: map[string]*resources.Dashboard{
3030
"dash1": {
31-
Dashboard: dashboards.Dashboard{
32-
DisplayName: "My Special Dashboard",
31+
DashboardConfig: resources.DashboardConfig{
32+
Dashboard: dashboards.Dashboard{
33+
DisplayName: "My Special Dashboard",
34+
},
3335
},
3436
},
3537
},

bundle/deploy/terraform/convert_test.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -830,8 +830,10 @@ func TestTerraformToBundleEmptyRemoteResources(t *testing.T) {
830830
},
831831
Dashboards: map[string]*resources.Dashboard{
832832
"test_dashboard": {
833-
Dashboard: dashboards.Dashboard{
834-
DisplayName: "test_dashboard",
833+
DashboardConfig: resources.DashboardConfig{
834+
Dashboard: dashboards.Dashboard{
835+
DisplayName: "test_dashboard",
836+
},
835837
},
836838
},
837839
},
@@ -1019,13 +1021,17 @@ func TestTerraformToBundleModifiedResources(t *testing.T) {
10191021
},
10201022
Dashboards: map[string]*resources.Dashboard{
10211023
"test_dashboard": {
1022-
Dashboard: dashboards.Dashboard{
1023-
DisplayName: "test_dashboard",
1024+
DashboardConfig: resources.DashboardConfig{
1025+
Dashboard: dashboards.Dashboard{
1026+
DisplayName: "test_dashboard",
1027+
},
10241028
},
10251029
},
10261030
"test_dashboard_new": {
1027-
Dashboard: dashboards.Dashboard{
1028-
DisplayName: "test_dashboard_new",
1031+
DashboardConfig: resources.DashboardConfig{
1032+
Dashboard: dashboards.Dashboard{
1033+
DisplayName: "test_dashboard_new",
1034+
},
10291035
},
10301036
},
10311037
},

bundle/deploy/terraform/tfdyn/convert_dashboard_test.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ import (
1515

1616
func TestConvertDashboard(t *testing.T) {
1717
src := resources.Dashboard{
18-
Dashboard: dashboards.Dashboard{
19-
DisplayName: "my dashboard",
20-
WarehouseId: "f00dcafe",
21-
ParentPath: "/some/path",
18+
DashboardConfig: resources.DashboardConfig{
19+
Dashboard: dashboards.Dashboard{
20+
DisplayName: "my dashboard",
21+
WarehouseId: "f00dcafe",
22+
ParentPath: "/some/path",
23+
},
24+
EmbedCredentials: true,
2225
},
2326

24-
EmbedCredentials: true,
25-
2627
Permissions: []resources.DashboardPermission{
2728
{
2829
Level: "CAN_VIEW",
@@ -61,7 +62,9 @@ func TestConvertDashboard(t *testing.T) {
6162

6263
func TestConvertDashboardSerializedDashboardString(t *testing.T) {
6364
src := resources.Dashboard{
64-
SerializedDashboard: `{ "json": true }`,
65+
DashboardConfig: resources.DashboardConfig{
66+
SerializedDashboard: `{ "json": true }`,
67+
},
6568
}
6669

6770
vin, err := convert.FromTyped(src, dyn.NilValue)
@@ -80,11 +83,13 @@ func TestConvertDashboardSerializedDashboardString(t *testing.T) {
8083

8184
func TestConvertDashboardSerializedDashboardAny(t *testing.T) {
8285
src := resources.Dashboard{
83-
SerializedDashboard: map[string]any{
84-
"pages": []map[string]any{
85-
{
86-
"displayName": "New Page",
87-
"layout": []map[string]any{},
86+
DashboardConfig: resources.DashboardConfig{
87+
SerializedDashboard: map[string]any{
88+
"pages": []map[string]any{
89+
{
90+
"displayName": "New Page",
91+
"layout": []map[string]any{},
92+
},
8893
},
8994
},
9095
},

0 commit comments

Comments
 (0)