Skip to content

Commit

Permalink
Filter resource outline
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha committed Dec 15, 2024
1 parent 531c7df commit 3741d47
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 152 deletions.
2 changes: 0 additions & 2 deletions .config/api-rules/violation_exceptions.list
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/shared
API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/shared,UIParameters,InstanceLabelPaths
API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/ui/v1alpha1,ActionTemplate,Icons
API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/ui/v1alpha1,ActionTemplateGroup,Items
API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/ui/v1alpha1,ActionTemplateGroupFilter,Items
API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/ui/v1alpha1,ChartInfo,ValuesFiles
API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/ui/v1alpha1,Dashboard,Panels
API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/ui/v1alpha1,Dashboard,Vars
Expand All @@ -74,7 +73,6 @@ API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/ui/v1a
API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/ui/v1alpha1,ResourceOutlineFilterSpec,Actions
API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/ui/v1alpha1,ResourceOutlineFilterSpec,Pages
API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/ui/v1alpha1,ResourcePageOutlineFilter,Sections
API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/ui/v1alpha1,SectionOutlineFilter,Blocks
API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/ui/v1alpha1,UIParameters,Actions
API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/ui/v1alpha1,UIParameters,InstanceLabelPaths
API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/ui/v1alpha1,VariantRef,Icons
Expand Down
51 changes: 12 additions & 39 deletions apis/ui/v1alpha1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions apis/ui/v1alpha1/resourceoutlinefilter_helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
Copyright AppsCode Inc. and Contributors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

func (a ResourceOutlineFilterSpec) GetPage(name string) ResourcePageOutlineFilter {
for _, page := range a.Pages {
if page.Name == name {
return page
}
}
return ResourcePageOutlineFilter{
Name: name,
Sections: nil,
}
}

func (a ResourceOutlineFilterSpec) GetAction(name string) ActionTemplateGroupFilter {
for _, action := range a.Actions {
if action.Name == name {
return action
}
}
return ActionTemplateGroupFilter{
Name: name,
Items: nil,
}
}

func (a ResourcePageOutlineFilter) GetSection(name string) SectionOutlineFilter {
for _, section := range a.Sections {
if section.Name == name {
return section
}
}
return SectionOutlineFilter{
Name: name,
Blocks: nil,
}
}
17 changes: 6 additions & 11 deletions apis/ui/v1alpha1/resourceoutlinefilter_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,15 @@ type ResourcePageOutlineFilter struct {
}

type ActionTemplateGroupFilter struct {
Name string `json:"name,omitempty"`
Items []ItemFilter `json:"items"`
Name string `json:"name,omitempty"`
Items map[string]bool `json:"items"`
}

type SectionOutlineFilter struct {
Name string `json:"name,omitempty"`
Info bool `json:"info"`
Insight bool `json:"insight"`
Blocks []ItemFilter `json:"blocks,omitempty"`
}

type ItemFilter struct {
Name string `json:"name,omitempty"`
Show bool `json:"show"`
Name string `json:"name,omitempty"`
Info bool `json:"info"`
Insight bool `json:"insight"`
Blocks map[string]bool `json:"blocks,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
28 changes: 8 additions & 20 deletions apis/ui/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 6 additions & 20 deletions crds/meta.k8s.appscode.com_resourceoutlinefilters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,9 @@ spec:
items:
properties:
items:
items:
properties:
name:
type: string
show:
type: boolean
required:
- show
type: object
type: array
additionalProperties:
type: boolean
type: object
name:
type: string
required:
Expand All @@ -63,16 +56,9 @@ spec:
items:
properties:
blocks:
items:
properties:
name:
type: string
show:
type: boolean
required:
- show
type: object
type: array
additionalProperties:
type: boolean
type: object
info:
type: boolean
insight:
Expand Down
26 changes: 6 additions & 20 deletions crds/ui.k8s.appscode.com_resourceoutlinefilters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,9 @@ spec:
items:
properties:
items:
items:
properties:
name:
type: string
show:
type: boolean
required:
- show
type: object
type: array
additionalProperties:
type: boolean
type: object
name:
type: string
required:
Expand All @@ -63,16 +56,9 @@ spec:
items:
properties:
blocks:
items:
properties:
name:
type: string
show:
type: boolean
required:
- show
type: object
type: array
additionalProperties:
type: boolean
type: object
info:
type: boolean
insight:
Expand Down
38 changes: 13 additions & 25 deletions pkg/layouts/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,10 @@ func GetDefaultResourceOutlineFilter(kc client.Client, outline *rsapi.ResourceOu
for _, ag := range ed.Spec.UI.Actions {
ag2 := uiapi.ActionTemplateGroupFilter{
Name: ag.Name,
Items: make([]uiapi.ItemFilter, 0, len(ag.Items)),
Items: make(map[string]bool, len(ag.Items)),
}
for _, a := range ag.Items {
a2 := uiapi.ItemFilter{
Name: a.Name,
Show: true,
}
ag2.Items = append(ag2.Items, a2)
ag2.Items[a.Name] = true
}
result.Spec.Actions = append(result.Spec.Actions, ag2)
}
Expand Down Expand Up @@ -109,13 +105,11 @@ func GetDefaultResourceOutlineFilter(kc client.Client, outline *rsapi.ResourceOu
Insight: sectionOutline.Insight != nil,
}

var tables []uiapi.ItemFilter
tables := map[string]bool{}
for _, block := range sectionOutline.Blocks {
blocks, err := FlattenPageBlockOutlineFilter(kc, src, block, rsapi.List)
if err != nil {
if err := FlattenPageBlockOutlineFilter(kc, src, block, rsapi.List, tables); err != nil {
return nil, err
}
tables = append(tables, blocks...)
}
section.Blocks = tables

Expand All @@ -132,34 +126,28 @@ func FlattenPageBlockOutlineFilter(
src kmapi.ResourceID,
in rsapi.PageBlockOutline,
priority rsapi.Priority,
) ([]uiapi.ItemFilter, error) {
out map[string]bool,
) error {
if in.Kind == rsapi.TableKindSubTable ||
in.Kind == rsapi.TableKindConnection ||
in.Kind == rsapi.TableKindCustom ||
in.Kind == rsapi.TableKindSelf {
return []uiapi.ItemFilter{
{
Name: in.Name,
Show: true,
},
}, nil
out[in.Name] = true
return nil
} else if in.Kind != rsapi.TableKindBlock {
return nil, fmt.Errorf("unknown block kind %+v", in)
return fmt.Errorf("unknown block kind %+v", in)
}

obj, err := blockdefs.LoadByName(in.Name)
if err != nil {
return nil, err
return err
}
var result []uiapi.ItemFilter
for _, block := range obj.Spec.Blocks {
out, err := FlattenPageBlockOutlineFilter(kc, src, block, priority)
if err != nil {
return nil, err
if err := FlattenPageBlockOutlineFilter(kc, src, block, priority, out); err != nil {
return err
}
result = append(result, out...)
}
return result, nil
return nil
}

func GetResourceOutlineFilter(kc client.Client, outline *rsapi.ResourceOutline) (*uiapi.ResourceOutlineFilter, error) {
Expand Down
Loading

0 comments on commit 3741d47

Please sign in to comment.