Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dev env refs to generated frontend config files. #241

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
55 changes: 50 additions & 5 deletions controllers/frontend_controller_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ var _ = ginkgo.Describe("Search index", func() {
testCase := SearchIndexCase{
Env: FrontendEnvName,
Namespace: FrontendNamespace,
ExpectedResult: "[{\"id\":\"test-search-index-test-search-index-env-test\",\"href\":\"/test/href\",\"title\":\"Test\",\"description\":\"Test description\"},{\"id\":\"test-search-index-test-search-index-env-test2\",\"href\":\"/test2/href\",\"title\":\"Test2\",\"description\":\"Test2 description\"}]",
ExpectedResult: fmt.Sprintf("[{\"id\":\"test-search-index-test-search-index-env-test\",\"href\":\"/test/href\",\"title\":\"Test\",\"description\":\"Test description\",\"frontendRef\":\"%s\"},{\"id\":\"test-search-index-test-search-index-env-test2\",\"href\":\"/test2/href\",\"title\":\"Test2\",\"description\":\"Test2 description\",\"frontendRef\":\"%s\"}]", FrontendName, FrontendName),
SearchFrontendEntries: []SearchFrontendEntry{{
Name: FrontendName,
SearchEntries: []*crd.SearchEntry{{
Expand Down Expand Up @@ -1066,7 +1066,7 @@ var _ = ginkgo.Describe("Search index", func() {
testCase := SearchIndexCase{
Env: FrontendEnvName2,
Namespace: FrontendNamespace,
ExpectedResult: "[{\"id\":\"test-search-index2-test-search-index-env2-test-search-index2\",\"href\":\"/test/href\",\"title\":\"Test\",\"description\":\"Test description\"},{\"id\":\"test-search-index3-test-search-index-env2-test-search-index3\",\"href\":\"/test/href\",\"title\":\"Test\",\"description\":\"Test description\"}]",
ExpectedResult: fmt.Sprintf("[{\"id\":\"test-search-index2-test-search-index-env2-test-search-index2\",\"href\":\"/test/href\",\"title\":\"Test\",\"description\":\"Test description\",\"frontendRef\":\"%s\"},{\"id\":\"test-search-index3-test-search-index-env2-test-search-index3\",\"href\":\"/test/href\",\"title\":\"Test\",\"description\":\"Test description\",\"frontendRef\":\"%s\"}]", FrontendName2, FrontendName3),
SearchFrontendEntries: []SearchFrontendEntry{{
Name: FrontendName2,
SearchEntries: []*crd.SearchEntry{{
Expand Down Expand Up @@ -1225,7 +1225,25 @@ var _ = ginkgo.Describe("Widget registry", func() {

ginkgo.It("Should create widget registry", func() {
ginkgo.By("collection entries from Frontend resources", func() {
expectedResult := []crd.WidgetEntry{*Widget1, *Widget2, *Widget3}
expectedResult := []crd.WidgetEntry{{
FrontendRef: FrontendName,
Scope: Widget1.Scope,
Module: Widget1.Module,
Config: Widget1.Config,
Defaults: WidgetDefaults,
}, {
FrontendRef: FrontendName,
Scope: Widget2.Scope,
Module: Widget2.Module,
Config: Widget2.Config,
Defaults: WidgetDefaults,
}, {
FrontendRef: FrontendName2,
Scope: Widget3.Scope,
Module: Widget3.Module,
Config: Widget3.Config,
Defaults: WidgetDefaults,
}}
widgetCases := []WidgetCase{{
WidgetsFrontend: []WidgetFrontendTestEntry{{
Widgets: []*crd.WidgetEntry{Widget1, Widget2},
Expand Down Expand Up @@ -1368,11 +1386,38 @@ var _ = ginkgo.Describe("Service tiles", func() {
Groups: []crd.FrontendServiceCategoryGroupGenerated{{
ID: ServiceSectionGroupID1,
Title: "Service Section Group 1",
Tiles: &[]crd.ServiceTile{*ServiceTile1, *ServiceTile2},
Tiles: &[]crd.ServiceTile{{
Section: ServiceTile1.Section,
Group: ServiceTile1.Group,
ID: ServiceTile1.ID,
Href: ServiceTile1.Href,
Title: ServiceTile1.Title,
Description: ServiceTile1.Description,
Icon: ServiceTile1.Icon,
FrontendRef: FrontendName,
}, {
Section: ServiceTile2.Section,
Group: ServiceTile2.Group,
ID: ServiceTile2.ID,
Href: ServiceTile2.Href,
Title: ServiceTile2.Title,
Description: ServiceTile2.Description,
Icon: ServiceTile2.Icon,
FrontendRef: FrontendName,
}},
}, {
ID: ServiceSectionGroupID2,
Title: "Service Section Group 2",
Tiles: &[]crd.ServiceTile{*ServiceTile3},
Tiles: &[]crd.ServiceTile{{
Section: ServiceTile3.Section,
Group: ServiceTile3.Group,
ID: ServiceTile3.ID,
Href: ServiceTile3.Href,
Title: ServiceTile3.Title,
Description: ServiceTile3.Description,
Icon: ServiceTile3.Icon,
FrontendRef: FrontendName,
}},
}},
},
}
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 {
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
Loading
Loading