Skip to content

Commit 4464ff3

Browse files
authored
Render actions for resources (#163)
Signed-off-by: Tamal Saha <[email protected]>
1 parent 51af1b6 commit 4464ff3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+3440
-61
lines changed

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ require (
3030
k8s.io/kube-openapi v0.0.0-20220803164354-a70c9af30aea
3131
kmodules.xyz/apiversion v0.2.0
3232
kmodules.xyz/authorizer v0.25.0
33-
kmodules.xyz/client-go v0.25.6
33+
kmodules.xyz/client-go v0.25.10
3434
kmodules.xyz/custom-resources v0.25.0
3535
kmodules.xyz/monitoring-agent-api v0.25.0
36-
kmodules.xyz/resource-metadata v0.14.1-0.20221026061352-d80461714483
36+
kmodules.xyz/resource-metadata v0.14.1-0.20221130133259-37fa284c9e50
3737
kmodules.xyz/resource-metrics v0.25.0
3838
kmodules.xyz/sets v0.24.0
3939
kubepack.dev/lib-helm v0.5.7-0.20221024120504-d029626cf65b

go.sum

+4-4
Original file line numberDiff line numberDiff line change
@@ -1180,17 +1180,17 @@ kmodules.xyz/apiversion v0.2.0 h1:vAQYqZFm4xu4pbB1cAdHbFEPES6EQkcR4wc06xdTOWk=
11801180
kmodules.xyz/apiversion v0.2.0/go.mod h1:oPX8g8LvlPdPX3Yc5YvCzJHQnw3YF/X4/jdW0b1am80=
11811181
kmodules.xyz/authorizer v0.25.0 h1:yRrLtMOdlU1p4mLzaSz5pmSLpBLsVXLQHkUfiME12iQ=
11821182
kmodules.xyz/authorizer v0.25.0/go.mod h1:Jb99YsLRJE4R4d8F5fFtlxEaxk0prdSk2LApZl4JdyI=
1183-
kmodules.xyz/client-go v0.25.6 h1:59mMNoanKrqOFYqDMtqYU5caFxd+7YrfNqpvyKYWqNE=
1184-
kmodules.xyz/client-go v0.25.6/go.mod h1:NgLAVr+IEAFpI9g7FhZF5qG0SG+SBADxknWu5jp0m8M=
1183+
kmodules.xyz/client-go v0.25.10 h1:jp94jSBI43C91Uy6gJx3qatzpm0GuaDdOLconw2IiCo=
1184+
kmodules.xyz/client-go v0.25.10/go.mod h1:6VSRxDP2UqoWUcF0aSpWu3m/56bEUzuuvZUrAxSFBr8=
11851185
kmodules.xyz/crd-schema-fuzz v0.25.0 h1:c5ZxNRqJak1bkGhECmyrKpzKGThFMB4088Kynyvngbc=
11861186
kmodules.xyz/custom-resources v0.25.0 h1:5JQTEuiv6lC/+VVFNKqzfX4YtJCmN5E7mcNtGnHGVQM=
11871187
kmodules.xyz/custom-resources v0.25.0/go.mod h1:ULwzvLmOqZJcPSXKI7iLclYL5eYRlKx8Nbex28Ht19E=
11881188
kmodules.xyz/monitoring-agent-api v0.25.0 h1:RU9RBeCqQdoS381xXy8cM1aqT+7qmtuPI3KxNQoX16Y=
11891189
kmodules.xyz/monitoring-agent-api v0.25.0/go.mod h1:RH5f/W9eCiW+KTblBIh8MZkjCWdtMQ8MuzCBMfgkynM=
11901190
kmodules.xyz/offshoot-api v0.25.0 h1:Svq9da/+sg5afOjpgo9vx2J/Lu90Mo0aFxkdQmgKnGI=
11911191
kmodules.xyz/offshoot-api v0.25.0/go.mod h1:ysEBn7LJuT3+s8ynAQA/OG0BSsJugXa6KGtDLMRjlKo=
1192-
kmodules.xyz/resource-metadata v0.14.1-0.20221026061352-d80461714483 h1:JkZQBePb6MYc8R8pKaqZM8UdEoRdjvXIBehZL4Aw+X4=
1193-
kmodules.xyz/resource-metadata v0.14.1-0.20221026061352-d80461714483/go.mod h1:lQQvuSlkBQ9LICd1m/g9JpIdxCSmI6MUSfjnadtKzwk=
1192+
kmodules.xyz/resource-metadata v0.14.1-0.20221130133259-37fa284c9e50 h1:sN+roX0nB0NoN4rp4I46xDRX+uPkTPH5LD8Uz8iThP8=
1193+
kmodules.xyz/resource-metadata v0.14.1-0.20221130133259-37fa284c9e50/go.mod h1:lQQvuSlkBQ9LICd1m/g9JpIdxCSmI6MUSfjnadtKzwk=
11941194
kmodules.xyz/resource-metrics v0.25.0 h1:wj3npVZZQr+Yysg/XdGn4LdT5kQizWeO0zq7QlSVx50=
11951195
kmodules.xyz/resource-metrics v0.25.0/go.mod h1:4a49npnu73c9LGDWHWQsPWoXWXU9rpCcknoH1+HHesI=
11961196
kmodules.xyz/sets v0.24.0 h1:GbltLEPVnURjcmWyf8eFstgJBpm9o151wsrABkByGrc=

pkg/graph/renderer.go

+42-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ limitations under the License.
1717
package graph
1818

1919
import (
20+
"bytes"
2021
"context"
2122
"fmt"
23+
"strings"
24+
25+
"kubeops.dev/ui-server/pkg/shared"
2226

2327
"github.com/pkg/errors"
2428
openvizcs "go.openviz.dev/apimachinery/client/clientset/versioned"
@@ -71,7 +75,44 @@ func RenderLayout(
7175
var out rsapi.ResourceView
7276
out.Resource = layout.Spec.Resource
7377
out.LayoutName = layout.Name
74-
out.UI = layout.Spec.UI
78+
if layout.Spec.UI != nil {
79+
out.UI = &sharedapi.UIParameters{
80+
Options: layout.Spec.UI.Options,
81+
Editor: layout.Spec.UI.Editor,
82+
InstanceLabelPaths: layout.Spec.UI.InstanceLabelPaths,
83+
}
84+
out.UI.Actions = make([]*sharedapi.ActionGroup, 0, len(layout.Spec.UI.Actions))
85+
for _, g := range layout.Spec.UI.Actions {
86+
g2 := sharedapi.ActionGroup{
87+
ActionInfo: g.ActionInfo,
88+
Items: make([]sharedapi.Action, 0, len(g.Items)),
89+
}
90+
for _, a := range g.Items {
91+
a2 := sharedapi.Action{
92+
ActionInfo: a.ActionInfo,
93+
Icons: a.Icons,
94+
OperationID: a.OperationID,
95+
Flow: a.Flow,
96+
Editor: a.Editor,
97+
}
98+
tpl := strings.TrimSpace(a.DisabledTemplate)
99+
if tpl != "" {
100+
buf := shared.BufferPool.Get().(*bytes.Buffer)
101+
defer shared.BufferPool.Put(buf)
102+
103+
result, err := shared.RenderTemplate(tpl, srcObj.UnstructuredContent(), buf)
104+
if err != nil {
105+
return nil, errors.Wrapf(err, "failed to test disabledTemplate for action %s", a.Name)
106+
}
107+
result = strings.TrimSpace(result)
108+
a2.Disabled = strings.EqualFold(result, "true")
109+
}
110+
111+
g2.Items = append(g2.Items, a2)
112+
}
113+
out.UI.Actions = append(out.UI.Actions, &g2)
114+
}
115+
}
75116

76117
if layout.Spec.Header != nil && okToRender(layout.Spec.Header.Kind, renderBlocks) {
77118
if bv, err := renderPageBlock(kc, oc, srcRID, &srcObj, layout.Spec.Header, convertToTable); err != nil {

0 commit comments

Comments
 (0)