From 25a2b119e0a2e0356f1279c023487389dff5db21 Mon Sep 17 00:00:00 2001 From: Tamal Saha Date: Tue, 24 Dec 2024 23:27:14 -0800 Subject: [PATCH] Add option to hide pages, sections and actions Signed-off-by: Tamal Saha --- apis/ui/v1alpha1/openapi_generated.go | 37 +++++++++++++++---- .../v1alpha1/resourceoutlinefilter_helpers.go | 3 ++ .../v1alpha1/resourceoutlinefilter_types.go | 9 +++-- ...s.appscode.com_resourceoutlinefilters.yaml | 12 +++++- ...s.appscode.com_resourceoutlinefilters.yaml | 12 +++++- .../v1alpha1/resourceoutlinefilters.yaml | 12 +++++- .../v1alpha1/resourceoutlinefilters.yaml | 12 +++++- pkg/layouts/filter.go | 3 ++ pkg/layouts/lib.go | 9 +++++ 9 files changed, 95 insertions(+), 14 deletions(-) diff --git a/apis/ui/v1alpha1/openapi_generated.go b/apis/ui/v1alpha1/openapi_generated.go index 3ea281569..e0b673c0d 100644 --- a/apis/ui/v1alpha1/openapi_generated.go +++ b/apis/ui/v1alpha1/openapi_generated.go @@ -19880,8 +19880,9 @@ func schema_resource_metadata_apis_ui_v1alpha1_ActionTemplateGroupFilter(ref com Properties: map[string]spec.Schema{ "name": { SchemaProps: spec.SchemaProps{ - Type: []string{"string"}, - Format: "", + Default: "", + Type: []string{"string"}, + Format: "", }, }, "items": { @@ -19899,8 +19900,15 @@ func schema_resource_metadata_apis_ui_v1alpha1_ActionTemplateGroupFilter(ref com }, }, }, + "show": { + SchemaProps: spec.SchemaProps{ + Default: false, + Type: []string{"boolean"}, + Format: "", + }, + }, }, - Required: []string{"items"}, + Required: []string{"name", "show"}, }, }, } @@ -21298,8 +21306,15 @@ func schema_resource_metadata_apis_ui_v1alpha1_ResourcePageOutlineFilter(ref com }, }, }, + "show": { + SchemaProps: spec.SchemaProps{ + Default: false, + Type: []string{"boolean"}, + Format: "", + }, + }, }, - Required: []string{"name"}, + Required: []string{"name", "show"}, }, }, Dependencies: []string{ @@ -21315,8 +21330,16 @@ func schema_resource_metadata_apis_ui_v1alpha1_SectionOutlineFilter(ref common.R Properties: map[string]spec.Schema{ "name": { SchemaProps: spec.SchemaProps{ - Type: []string{"string"}, - Format: "", + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + "show": { + SchemaProps: spec.SchemaProps{ + Default: false, + Type: []string{"boolean"}, + Format: "", }, }, "info": { @@ -21349,7 +21372,7 @@ func schema_resource_metadata_apis_ui_v1alpha1_SectionOutlineFilter(ref common.R }, }, }, - Required: []string{"info", "insight"}, + Required: []string{"name", "show", "info", "insight"}, }, }, } diff --git a/apis/ui/v1alpha1/resourceoutlinefilter_helpers.go b/apis/ui/v1alpha1/resourceoutlinefilter_helpers.go index c77419fe9..0643993eb 100644 --- a/apis/ui/v1alpha1/resourceoutlinefilter_helpers.go +++ b/apis/ui/v1alpha1/resourceoutlinefilter_helpers.go @@ -24,6 +24,7 @@ func (a ResourceOutlineFilterSpec) GetPage(name string) ResourcePageOutlineFilte } return ResourcePageOutlineFilter{ Name: name, + Show: false, Sections: nil, } } @@ -36,6 +37,7 @@ func (a ResourceOutlineFilterSpec) GetAction(name string) ActionTemplateGroupFil } return ActionTemplateGroupFilter{ Name: name, + Show: false, Items: nil, } } @@ -48,6 +50,7 @@ func (a ResourcePageOutlineFilter) GetSection(name string) SectionOutlineFilter } return SectionOutlineFilter{ Name: name, + Show: false, Blocks: nil, } } diff --git a/apis/ui/v1alpha1/resourceoutlinefilter_types.go b/apis/ui/v1alpha1/resourceoutlinefilter_types.go index 29066ae58..f94a5ac5a 100644 --- a/apis/ui/v1alpha1/resourceoutlinefilter_types.go +++ b/apis/ui/v1alpha1/resourceoutlinefilter_types.go @@ -54,15 +54,18 @@ type ResourceOutlineFilterSpec struct { type ResourcePageOutlineFilter struct { Name string `json:"name"` Sections []SectionOutlineFilter `json:"sections,omitempty"` + Show bool `json:"show"` } type ActionTemplateGroupFilter struct { - Name string `json:"name,omitempty"` - Items map[string]bool `json:"items"` + Name string `json:"name"` + Items map[string]bool `json:"items,omitempty"` + Show bool `json:"show"` } type SectionOutlineFilter struct { - Name string `json:"name,omitempty"` + Name string `json:"name"` + Show bool `json:"show"` Info bool `json:"info"` Insight bool `json:"insight"` Blocks map[string]bool `json:"blocks,omitempty"` diff --git a/crds/meta.k8s.appscode.com_resourceoutlinefilters.yaml b/crds/meta.k8s.appscode.com_resourceoutlinefilters.yaml index 403cbb0cf..4606a888e 100644 --- a/crds/meta.k8s.appscode.com_resourceoutlinefilters.yaml +++ b/crds/meta.k8s.appscode.com_resourceoutlinefilters.yaml @@ -41,8 +41,11 @@ spec: type: object name: type: string + show: + type: boolean required: - - items + - name + - show type: object type: array header: @@ -65,13 +68,20 @@ spec: type: boolean name: type: string + show: + type: boolean required: - info - insight + - name + - show type: object type: array + show: + type: boolean required: - name + - show type: object type: array resource: diff --git a/crds/ui.k8s.appscode.com_resourceoutlinefilters.yaml b/crds/ui.k8s.appscode.com_resourceoutlinefilters.yaml index 708758f75..978b472a1 100644 --- a/crds/ui.k8s.appscode.com_resourceoutlinefilters.yaml +++ b/crds/ui.k8s.appscode.com_resourceoutlinefilters.yaml @@ -41,8 +41,11 @@ spec: type: object name: type: string + show: + type: boolean required: - - items + - name + - show type: object type: array header: @@ -65,13 +68,20 @@ spec: type: boolean name: type: string + show: + type: boolean required: - info - insight + - name + - show type: object type: array + show: + type: boolean required: - name + - show type: object type: array resource: diff --git a/hub/resourcedescriptors/meta.k8s.appscode.com/v1alpha1/resourceoutlinefilters.yaml b/hub/resourcedescriptors/meta.k8s.appscode.com/v1alpha1/resourceoutlinefilters.yaml index 5366ef9ec..198a3c47c 100644 --- a/hub/resourcedescriptors/meta.k8s.appscode.com/v1alpha1/resourceoutlinefilters.yaml +++ b/hub/resourcedescriptors/meta.k8s.appscode.com/v1alpha1/resourceoutlinefilters.yaml @@ -64,8 +64,11 @@ spec: type: object name: type: string + show: + type: boolean required: - - items + - name + - show type: object type: array header: @@ -88,13 +91,20 @@ spec: type: boolean name: type: string + show: + type: boolean required: - info - insight + - name + - show type: object type: array + show: + type: boolean required: - name + - show type: object type: array resource: diff --git a/hub/resourcedescriptors/ui.k8s.appscode.com/v1alpha1/resourceoutlinefilters.yaml b/hub/resourcedescriptors/ui.k8s.appscode.com/v1alpha1/resourceoutlinefilters.yaml index 43dcef0f5..24bb6dee4 100644 --- a/hub/resourcedescriptors/ui.k8s.appscode.com/v1alpha1/resourceoutlinefilters.yaml +++ b/hub/resourcedescriptors/ui.k8s.appscode.com/v1alpha1/resourceoutlinefilters.yaml @@ -64,8 +64,11 @@ spec: type: object name: type: string + show: + type: boolean required: - - items + - name + - show type: object type: array header: @@ -88,13 +91,20 @@ spec: type: boolean name: type: string + show: + type: boolean required: - info - insight + - name + - show type: object type: array + show: + type: boolean required: - name + - show type: object type: array resource: diff --git a/pkg/layouts/filter.go b/pkg/layouts/filter.go index c05fa4a30..492ee8179 100644 --- a/pkg/layouts/filter.go +++ b/pkg/layouts/filter.go @@ -49,6 +49,7 @@ func GetDefaultResourceOutlineFilter(kc client.Client, outline *rsapi.ResourceOu for _, ag := range ed.Spec.UI.Actions { ag2 := uiapi.ActionTemplateGroupFilter{ Name: ag.Name, + Show: true, Items: make(map[string]bool, len(ag.Items)), } for _, a := range ag.Items { @@ -95,12 +96,14 @@ func GetDefaultResourceOutlineFilter(kc client.Client, outline *rsapi.ResourceOu for _, pageOutline := range pages { page := uiapi.ResourcePageOutlineFilter{ Name: pageOutline.Name, + Show: true, Sections: make([]uiapi.SectionOutlineFilter, 0, len(pageOutline.Sections)), } for _, sectionOutline := range pageOutline.Sections { section := uiapi.SectionOutlineFilter{ Name: sectionOutline.Name, + Show: true, Info: sectionOutline.Info != nil, Insight: sectionOutline.Insight != nil, } diff --git a/pkg/layouts/lib.go b/pkg/layouts/lib.go index b06116db3..751c59767 100644 --- a/pkg/layouts/lib.go +++ b/pkg/layouts/lib.go @@ -201,6 +201,9 @@ func GetResourceLayout(kc client.Client, outline *rsapi.ResourceOutline) (*rsapi result.Spec.UI.Actions = make([]*shared.ActionTemplateGroup, 0, len(ed.Spec.UI.Actions)) for _, ag := range ed.Spec.UI.Actions { agFilter := filter.Spec.GetAction(ag.Name) + if !agFilter.Show { + continue + } ag2 := shared.ActionTemplateGroup{ ActionInfo: ag.ActionInfo, Items: make([]shared.ActionTemplate, 0, len(ag.Items)), @@ -280,6 +283,9 @@ func GetResourceLayout(kc client.Client, outline *rsapi.ResourceOutline) (*rsapi for _, pageOutline := range pages { pageFilter := filter.Spec.GetPage(pageOutline.Name) + if !pageFilter.Show { + continue + } page := rsapi.ResourcePageLayout{ Name: pageOutline.Name, RequiredFeatureSets: pageOutline.RequiredFeatureSets, @@ -287,6 +293,9 @@ func GetResourceLayout(kc client.Client, outline *rsapi.ResourceOutline) (*rsapi } for _, sectionOutline := range pageOutline.Sections { sectionFilter := pageFilter.GetSection(sectionOutline.Name) + if !sectionFilter.Show { + continue + } section := rsapi.SectionLayout{ Name: sectionOutline.Name,