Skip to content

Commit

Permalink
Add dev env refs to generated frontend config files.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyperkid123 committed Dec 16, 2024
1 parent da51728 commit 428164b
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 21 deletions.
19 changes: 12 additions & 7 deletions api/v1alpha1/frontend_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type SearchEntry struct {
Description string `json:"description" yaml:"description"`
AltTitle []string `json:"alt_title,omitempty" yaml:"alt_title,omitempty"`
IsExternal bool `json:"isExternal,omitempty" yaml:"isExternal,omitempty"`
FrontendRef string `json:"frontendRef,omitempty" yaml:"frontendRef,omitempty"`
}

type ServiceTile struct {
Expand All @@ -57,6 +58,7 @@ type ServiceTile struct {
Description string `json:"description" yaml:"description"`
Icon string `json:"icon" yaml:"icon"`
IsExternal bool `json:"isExternal,omitempty" yaml:"isExternal,omitempty"`
FrontendRef string `json:"frontendRef,omitempty" yaml:"frontendRef,omitempty"`
}

type WidgetHeaderLink struct {
Expand Down Expand Up @@ -86,10 +88,11 @@ type WidgetDefaults struct {
}

type WidgetEntry struct {
Scope string `json:"scope" yaml:"scope"`
Module string `json:"module" yaml:"module"`
Config WidgetConfig `json:"config" yaml:"config"`
Defaults WidgetDefaults `json:"defaults" yaml:"defaults"`
Scope string `json:"scope" yaml:"scope"`
Module string `json:"module" yaml:"module"`
Config WidgetConfig `json:"config" yaml:"config"`
Defaults WidgetDefaults `json:"defaults" yaml:"defaults"`
FrontendRef string `json:"frontendRef,omitempty" yaml:"frontendRef,omitempty"`
}

type BundleSegment struct {
Expand Down Expand Up @@ -231,9 +234,11 @@ type ChromeNavItem struct {
NavItems []ChromeNavItem `json:"navItems,omitempty" yaml:"navItems,omitempty"`
// +kubebuilder:pruning:PreserveUnknownFields
// +kubebuilder:validation:Schemaless
Routes []ChromeNavItem `json:"routes,omitempty" yaml:"routes,omitempty"`
Permissions []Permission `json:"permissions,omitempty" yaml:"permissions,omitempty"`
SegmentRef *SegmentRef `json:"segmentRef,omitempty" yaml:"segmentRef,omitempty"`
Routes []ChromeNavItem `json:"routes,omitempty" yaml:"routes,omitempty"`
Permissions []Permission `json:"permissions,omitempty" yaml:"permissions,omitempty"`
SegmentRef *SegmentRef `json:"segmentRef,omitempty" yaml:"segmentRef,omitempty"`
BundleSegmentRef string `json:"bundleSegmentRef,omitempty" yaml:"bundleSegmentRef,omitempty"`
FrontendRef string `json:"frontendRef,omitempty" yaml:"frontendRef,omitempty"`
}

func (navItem ChromeNavItem) HasSegmentRef() bool {
Expand Down
8 changes: 8 additions & 0 deletions config/crd/bases/cloud.redhat.com_bundles.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ spec:
properties:
appId:
type: string
bundleSegmentRef:
type: string
expandable:
type: boolean
frontendRef:
type: string
groupId:
type: string
href:
Expand Down Expand Up @@ -114,8 +118,12 @@ spec:
properties:
appId:
type: string
bundleSegmentRef:
type: string
expandable:
type: boolean
frontendRef:
type: string
groupId:
type: string
href:
Expand Down
14 changes: 14 additions & 0 deletions config/crd/bases/cloud.redhat.com_frontends.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,12 @@ spec:
properties:
appId:
type: string
bundleSegmentRef:
type: string
expandable:
type: boolean
frontendRef:
type: string
groupId:
type: string
href:
Expand Down Expand Up @@ -401,8 +405,12 @@ spec:
properties:
appId:
type: string
bundleSegmentRef:
type: string
expandable:
type: boolean
frontendRef:
type: string
groupId:
type: string
href:
Expand Down Expand Up @@ -476,6 +484,8 @@ spec:
type: array
description:
type: string
frontendRef:
type: string
href:
type: string
id:
Expand Down Expand Up @@ -504,6 +514,8 @@ spec:
properties:
description:
type: string
frontendRef:
type: string
group:
type: string
href:
Expand Down Expand Up @@ -641,6 +653,8 @@ spec:
- sm
- xl
type: object
frontendRef:
type: string
module:
type: string
scope:
Expand Down
45 changes: 42 additions & 3 deletions controllers/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,7 @@ func adjustSearchEntry(searchEntry *crd.SearchEntry, frontend crd.Frontend) crd.
Href: searchEntry.Href,
AltTitle: altTitleCopy,
IsExternal: searchEntry.IsExternal,
FrontendRef: frontend.Name,
}
return newSearchEntry
}
Expand All @@ -926,6 +927,7 @@ func setupWidgetRegistry(feList *crd.FrontendList) []crd.WidgetEntry {
for _, frontend := range feList.Items {
if frontend.Spec.FeoConfigEnabled {
for _, widget := range frontend.Spec.WidgetRegistry {
widget.FrontendRef = frontend.Name
widgetRegistry = append(widgetRegistry, *widget)
}
}
Expand Down Expand Up @@ -977,6 +979,7 @@ func setupServiceTilesData(feList *crd.FrontendList, feEnvironment crd.FrontendE
groupKey := getServiceTilePath(tile.Section, tile.Group)
if groupTiles, ok := tileGroupAccessMap[groupKey]; ok {
// assign the tile to the service category and group
tile.FrontendRef = frontend.Name
*groupTiles = append(*groupTiles, *tile)
} else {
// ignore the tile if destination does not exist
Expand Down Expand Up @@ -1010,7 +1013,8 @@ func fillNavRefsTree(navItems []crd.ChromeNavItem, navSegmentsCache map[string]m
var err error
for index := 0; index < len(parsedNavItems); index++ {
navItem := parsedNavItems[index]
if navItem.HasSegmentRef() {
// if navItem is a segment ref, replace it with the actual segment
if navItem.HasSegmentRef() && navItem.Href == "" && navItem.Title == "" {
segmentRef := navItem.SegmentRef
segmentRefCacheEntry, ok := navSegmentsCache[segmentRef.FrontendName][segmentRef.SegmentID]
if !ok {
Expand All @@ -1024,13 +1028,26 @@ func fillNavRefsTree(navItems []crd.ChromeNavItem, navSegmentsCache map[string]m
if err != nil {
return parsedNavItems, err
}
// add attributes required for the frontend local dev environment

// don't forget to mark the segment as filled and fill it
navSegmentsCache[segmentRef.FrontendName][segmentRef.SegmentID].IsFilled = true
navSegmentsCache[segmentRef.FrontendName][segmentRef.SegmentID].NavItems = segmentRefItems
}

// copy segmentRefItems and add segment ref for Frontend local dev environment
frontendSegmentRefItems := []crd.ChromeNavItem{}
for _, item := range segmentRefItems {
newItem := item.DeepCopy()
newItem.BundleSegmentRef = navItem.BundleSegmentRef
newItem.FrontendRef = segmentRef.FrontendName
newItem.SegmentRef = segmentRef
frontendSegmentRefItems = append(frontendSegmentRefItems, *newItem)
}

// delete the original ref and replace it with the filled segments
parsedNavItems = append(parsedNavItems[:index], parsedNavItems[index+1:]...)
parsedNavItems = slices.Insert(parsedNavItems, index, segmentRefItems...)
parsedNavItems = slices.Insert(parsedNavItems, index, frontendSegmentRefItems...)
}

// Make sure nested nav items have their refs filled as well
Expand Down Expand Up @@ -1058,7 +1075,7 @@ func fillNavRefsTree(navItems []crd.ChromeNavItem, navSegmentsCache map[string]m
func filterUnknownNavRefs(navItems []crd.ChromeNavItem) []crd.ChromeNavItem {
res := []crd.ChromeNavItem{}
for _, navItem := range navItems {
if navItem.HasSegmentRef() {
if navItem.HasSegmentRef() && navItem.Href == "" && navItem.Title == "" {
// skip if segment is a ref
continue
}
Expand All @@ -1076,6 +1093,26 @@ func filterUnknownNavRefs(navItems []crd.ChromeNavItem) []crd.ChromeNavItem {
return res
}

func addRefsToNavItems(navItems []crd.ChromeNavItem, bundleID string, frontendId string) []crd.ChromeNavItem {

Check failure on line 1096 in controllers/reconcile.go

View workflow job for this annotation

GitHub Actions / Lint

var-naming: func parameter frontendId should be frontendID (revive)
res := []crd.ChromeNavItem{}
for _, navItem := range navItems {
newNavItem := navItem
newNavItem.BundleSegmentRef = bundleID
newNavItem.FrontendRef = frontendId

if newNavItem.IsExpandable() {
newNavItem.Routes = addRefsToNavItems(newNavItem.Routes, bundleID, frontendId)
}

if newNavItem.IsGroup() {
newNavItem.NavItems = addRefsToNavItems(newNavItem.NavItems, bundleID, frontendId)
}

res = append(res, newNavItem)
}
return res
}

func setupBundlesData(feList *crd.FrontendList, feEnvironment crd.FrontendEnvironment) ([]crd.FrontendBundlesGenerated, []string, error) {
bundles := []crd.FrontendBundlesGenerated{}
if feEnvironment.Spec.Bundles == nil {
Expand Down Expand Up @@ -1105,6 +1142,8 @@ func setupBundlesData(feList *crd.FrontendList, feEnvironment crd.FrontendEnviro
for _, frontend := range feList.Items {
if frontend.Spec.FeoConfigEnabled && frontend.Spec.BundleSegments != nil {
for _, bundleNavSegment := range frontend.Spec.BundleSegments {
navItemsWithRefs := addRefsToNavItems(*bundleNavSegment.NavItems, bundleNavSegment.BundleID, frontend.Name)
bundleNavSegment.NavItems = &navItemsWithRefs
bundleNavSegmentMap[bundleNavSegment.BundleID] = append(bundleNavSegmentMap[bundleNavSegment.BundleID], *bundleNavSegment)
skippedNavItemsMap[bundleNavSegment.BundleID] = append(skippedNavItemsMap[bundleNavSegment.BundleID], getNavItemPath(frontend.Name, bundleNavSegment.BundleID, bundleNavSegment.SegmentID))
}
Expand Down
22 changes: 22 additions & 0 deletions deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,12 @@ objects:
properties:
appId:
type: string
bundleSegmentRef:
type: string
expandable:
type: boolean
frontendRef:
type: string
groupId:
type: string
href:
Expand Down Expand Up @@ -133,8 +137,12 @@ objects:
properties:
appId:
type: string
bundleSegmentRef:
type: string
expandable:
type: boolean
frontendRef:
type: string
groupId:
type: string
href:
Expand Down Expand Up @@ -519,8 +527,12 @@ objects:
properties:
appId:
type: string
bundleSegmentRef:
type: string
expandable:
type: boolean
frontendRef:
type: string
groupId:
type: string
href:
Expand Down Expand Up @@ -838,8 +850,12 @@ objects:
properties:
appId:
type: string
bundleSegmentRef:
type: string
expandable:
type: boolean
frontendRef:
type: string
groupId:
type: string
href:
Expand Down Expand Up @@ -913,6 +929,8 @@ objects:
type: array
description:
type: string
frontendRef:
type: string
href:
type: string
id:
Expand Down Expand Up @@ -941,6 +959,8 @@ objects:
properties:
description:
type: string
frontendRef:
type: string
group:
type: string
href:
Expand Down Expand Up @@ -1078,6 +1098,8 @@ objects:
- sm
- xl
type: object
frontendRef:
type: string
module:
type: string
scope:
Expand Down
2 changes: 1 addition & 1 deletion kuttl-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ startControlPlane: true
crdDir: config/crd/test-resources/
testDirs:
- tests/e2e/
timeout: 320
timeout: 15
parallel: 1
commands:
- command: make install
Expand Down
7 changes: 1 addition & 6 deletions tests/e2e/generate-bundles/02-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,4 @@ data:
fed-modules.json: >-
{"landing-page":{"manifestLocation":"/apps/landing-page/fed-mods.json","moduleID":"landing-page","fullProfile":false}}
bundles.json: >-
[{"id":"rhel","title":"Red Hat Enterprise Linux","navItems":[{"href":"/apps/landing","title":"Landing
section A","id":"landing"},{"href":"/apps/landing","title":"Landing section B","id":"landing"},{"href":"/apps/landing","title":"Landing
section c","id":"landing"},{"expandable":true,"title":"Some new link","id":"bar","routes":[{"href":"/nested/bar","title":"Foo","id":"foo"}]},{"href":"/baz","title":"Some
new link","id":"baz"},{"href":"/apps/landing","title":"Landing section D","id":"landing"},{"href":"/apps/landing","title":"Landing
section last","id":"landing2"},{"expandable":true,"title":"Some new link","id":"bar2","routes":[{"href":"/nested/bar","title":"Foo","id":"foo"}]},{"href":"/baz","title":"Some
new link","id":"baz2"}]},{"id":"ansible","title":"Ansible","navItems":[]},{"id":"settings","title":"Settings","navItems":[]}]
[{"id":"rhel","title":"Red Hat Enterprise Linux","navItems":[{"href":"/apps/landing","title":"Landing section A","id":"landing","bundleSegmentRef":"rhel","frontendRef":"landing-page"},{"href":"/apps/landing","title":"Landing section B","id":"landing","bundleSegmentRef":"rhel","frontendRef":"landing-page"},{"href":"/apps/landing","title":"Landing section c","id":"landing","bundleSegmentRef":"rhel","frontendRef":"landing-page"},{"expandable":true,"title":"Some new link","id":"bar","routes":[{"href":"/nested/bar","title":"Foo","id":"foo","bundleSegmentRef":"rhel","frontendRef":"landing-page"}],"bundleSegmentRef":"rhel","frontendRef":"landing-page"},{"href":"/baz","title":"Some new link","id":"baz","bundleSegmentRef":"rhel","frontendRef":"landing-page"},{"href":"/apps/landing","title":"Landing section D","id":"landing","bundleSegmentRef":"rhel","frontendRef":"landing-page"},{"href":"/apps/landing","title":"Landing section last","id":"landing2","bundleSegmentRef":"rhel","frontendRef":"landing-page"},{"expandable":true,"title":"Some new link","id":"bar2","routes":[{"href":"/nested/bar","title":"Foo","id":"foo","bundleSegmentRef":"rhel","frontendRef":"landing-page"}],"bundleSegmentRef":"rhel","frontendRef":"landing-page"},{"href":"/baz","title":"Some new link","id":"baz2","bundleSegmentRef":"rhel","frontendRef":"landing-page"}]},{"id":"ansible","title":"Ansible","navItems":[]},{"id":"settings","title":"Settings","navItems":[]}]
2 changes: 1 addition & 1 deletion tests/e2e/generate-nav-with-segments/02-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ data:
fed-modules.json: >-
{"segmentedAppOne":{"manifestLocation":"/apps/chrome/js/fed-mods.json","fullProfile":false},"segmentedAppTwo":{"manifestLocation":"/apps/chrome/js/fed-mods.json","fullProfile":false}}
bundles.json: >-
[{"id":"segmented-bundle","title":"Segmented bundle","navItems":[{"href":"/link-one","title":"Link one classic","id":"link-one"},{"href":"/link-two","title":"Link two injected","id":"link-two"},{"href":"/link-three","title":"Link three injected","id":"link-three"},{"href":"/link-four","title":"Link four classic","id":"link-four"},{"expandable":true,"title":"Expandable","id":"expandable","routes":[{"href":"/nested/one","title":"Nested one","id":"nested-one"},{"href":"/nested/two","title":"Nested two","id":"nested-two"},{"href":"/nested/three","title":"Nested three","id":"nested-three"},{"href":"/nested/four","title":"Nested four","id":"nested-four"}]}]}]
[{"id":"segmented-bundle","title":"Segmented bundle","navItems":[{"href":"/link-one","title":"Link one classic","id":"link-one","bundleSegmentRef":"segmented-bundle","frontendRef":"segmented-app-one"},{"href":"/link-two","title":"Link two injected","id":"link-two","segmentRef":{"frontendName":"segmented-app-two","segmentId":"segment-two-item-one"},"bundleSegmentRef":"segmented-bundle","frontendRef":"segmented-app-two"},{"href":"/link-three","title":"Link three injected","id":"link-three","segmentRef":{"frontendName":"segmented-app-two","segmentId":"segment-two-item-one"},"bundleSegmentRef":"segmented-bundle","frontendRef":"segmented-app-two"},{"href":"/link-four","title":"Link four classic","id":"link-four","bundleSegmentRef":"segmented-bundle","frontendRef":"segmented-app-one"},{"expandable":true,"title":"Expandable","id":"expandable","routes":[{"href":"/nested/one","title":"Nested one","id":"nested-one","bundleSegmentRef":"segmented-bundle","frontendRef":"segmented-app-one"},{"href":"/nested/two","title":"Nested two","id":"nested-two","segmentRef":{"frontendName":"segmented-app-two","segmentId":"nested-segment-two"},"bundleSegmentRef":"segmented-bundle","frontendRef":"segmented-app-two"},{"href":"/nested/three","title":"Nested three","id":"nested-three","segmentRef":{"frontendName":"segmented-app-two","segmentId":"nested-segment-two"},"bundleSegmentRef":"segmented-bundle","frontendRef":"segmented-app-two"},{"href":"/nested/four","title":"Nested four","id":"nested-four","bundleSegmentRef":"segmented-bundle","frontendRef":"segmented-app-one"}],"bundleSegmentRef":"segmented-bundle","frontendRef":"segmented-app-one"}]}]
2 changes: 1 addition & 1 deletion tests/e2e/generate-search-index/02-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ data:
fed-modules.json: >-
{"search":{"manifestLocation":"/apps/search/fed-mods.json","moduleID":"search","fullProfile":false}}
search-index.json: >-
[{"id":"search-test-search-index-environment-landing","href":"/","title":"Landing","description":"Landing page description","alt_title":["HCC Home page","Home"]},{"id":"search-test-search-index-environment-landing-widgets","href":"/widgets","title":"Widget fantastic","description":"Widget"}]
[{"id":"search-test-search-index-environment-landing","href":"/","title":"Landing","description":"Landing page description","alt_title":["HCC Home page","Home"],"frontendRef":"search"},{"id":"search-test-search-index-environment-landing-widgets","href":"/widgets","title":"Widget fantastic","description":"Widget","frontendRef":"search"}]
Loading

0 comments on commit 428164b

Please sign in to comment.