/
dashboard_edge.go
125 lines (103 loc) · 3.08 KB
/
dashboard_edge.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package modconfig
import (
"fmt"
"github.com/hashicorp/hcl/v2"
"github.com/turbot/pipe-fittings/hclhelpers"
"github.com/zclconf/go-cty/cty"
)
// DashboardEdge is a struct representing a leaf dashboard node
type DashboardEdge struct {
ResourceWithMetadataImpl
QueryProviderImpl
// required to allow partial decoding
Remain hcl.Body `hcl:",remain" json:"-"`
Category *DashboardCategory `cty:"category" hcl:"category" column:"category,jsonb" json:"category,omitempty"`
Base *DashboardEdge `hcl:"base" json:"-"`
}
func NewDashboardEdge(block *hcl.Block, mod *Mod, shortName string) HclResource {
fullName := fmt.Sprintf("%s.%s.%s", mod.ShortName, block.Type, shortName)
c := &DashboardEdge{
QueryProviderImpl: QueryProviderImpl{
RuntimeDependencyProviderImpl: RuntimeDependencyProviderImpl{
ModTreeItemImpl: ModTreeItemImpl{
HclResourceImpl: HclResourceImpl{ShortName: shortName,
FullName: fullName,
UnqualifiedName: fmt.Sprintf("%s.%s", block.Type, shortName),
DeclRange: hclhelpers.BlockRange(block),
blockType: block.Type,
},
Mod: mod,
},
},
},
}
c.SetAnonymous(block)
return c
}
func (e *DashboardEdge) Equals(other *DashboardEdge) bool {
diff := e.Diff(other)
return !diff.HasChanges()
}
// OnDecoded implements HclResource
func (e *DashboardEdge) OnDecoded(_ *hcl.Block, resourceMapProvider ResourceMapsProvider) hcl.Diagnostics {
e.setBaseProperties()
// when we reference resources (i.e. category),
// not all properties are retrieved as they are no cty serialisable
// repopulate category from resourceMapProvider
if e.Category != nil {
fullCategory, diags := enrichCategory(e.Category, e, resourceMapProvider)
if diags.HasErrors() {
return diags
}
e.Category = fullCategory
}
return nil
}
func (e *DashboardEdge) Diff(other *DashboardEdge) *DashboardTreeItemDiffs {
res := &DashboardTreeItemDiffs{
Item: e,
Name: e.Name(),
}
if (e.Category == nil) != (other.Category == nil) {
res.AddPropertyDiff("Category")
}
if e.Category != nil && !e.Category.Equals(other.Category) {
res.AddPropertyDiff("Category")
}
res.populateChildDiffs(e, other)
res.queryProviderDiff(e, other)
res.dashboardLeafNodeDiff(e, other)
return res
}
// GetWidth implements DashboardLeafNode
func (e *DashboardEdge) GetWidth() int {
return 0
}
// GetDisplay implements DashboardLeafNode
func (e *DashboardEdge) GetDisplay() string {
return ""
}
// GetDocumentation implements DashboardLeafNode
func (e *DashboardEdge) GetDocumentation() string {
return ""
}
// GetType implements DashboardLeafNode
func (e *DashboardEdge) GetType() string {
return ""
}
// CtyValue implements CtyValueProvider
func (e *DashboardEdge) CtyValue() (cty.Value, error) {
return GetCtyValue(e)
}
func (e *DashboardEdge) setBaseProperties() {
if e.Base == nil {
return
}
// copy base into the HclResourceImpl 'base' property so it is accessible to all nested structs
e.base = e.Base
// call into parent nested struct setBaseProperties
e.QueryProviderImpl.setBaseProperties()
if e.Category == nil {
e.Category = e.Base.Category
}
}