Skip to content

Commit

Permalink
Fall back to sorting alphabetically when position number conflicts in…
Browse files Browse the repository at this point in the history
… nav segment
  • Loading branch information
florkbr authored and Hyperkid123 committed Dec 3, 2024
1 parent 06340d1 commit e7bafcf
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
4 changes: 3 additions & 1 deletion controllers/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -1012,8 +1012,10 @@ func setupBundlesData(feList *crd.FrontendList, feEnvironment crd.FrontendEnviro

for _, bundle := range *feEnvironment.Spec.Bundles {
delete(skippedNavItemsMap, bundle.ID)
// TODO sort alphabetically if position collision
sort.Slice(bundleNavSegmentMap[bundle.ID], func(i, j int) bool {
if (bundleNavSegmentMap[bundle.ID])[i].Position == (bundleNavSegmentMap[bundle.ID])[j].Position {
return (bundleNavSegmentMap[bundle.ID])[i].SegmentID[0] < (bundleNavSegmentMap[bundle.ID])[j].SegmentID[0]
}
return (bundleNavSegmentMap[bundle.ID])[i].Position < (bundleNavSegmentMap[bundle.ID])[j].Position
})
navItems := []crd.ChromeNavItem{}
Expand Down
31 changes: 26 additions & 5 deletions tests/e2e/generate-bundles/01-create-resources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ spec:
modules: []
moduleID: landing-page
navigationSegments:
- segmentId: inventory-partial-2
- segmentId: inventory-last-segment
bundleId: rhel
position: 200
position: 200 # should be last based on position values
navItems:
- id: landing2
title: Landing section
title: Landing section last
href: /apps/landing
- id: bar2
title: Some new link
Expand All @@ -51,12 +51,12 @@ spec:
- id: baz2
title: Some new link
href: /baz
- segmentId: inventory-partial
- segmentId: c-inventory-segment
bundleId: rhel
position: 100
navItems:
- id: landing
title: Landing section
title: Landing section c
href: /apps/landing
- id: bar
title: Some new link
Expand All @@ -68,6 +68,27 @@ spec:
- id: baz
title: Some new link
href: /baz
- segmentId: a-inventory-segment
bundleId: rhel
position: 100 # collision with above segment - should sort by segmentId alphabetically
navItems:
- id: landing
title: Landing section A
href: /apps/landing
- segmentId: b-inventory-segment
bundleId: rhel
position: 100 # collision with above segment - should sort by segmentId alphabetically
navItems:
- id: landing
title: Landing section B
href: /apps/landing
- segmentId: d-inventory-segment
bundleId: rhel
position: 100 # collision with above segment - should sort by segmentId alphabetically
navItems:
- id: landing
title: Landing section D
href: /apps/landing
- segmentId: skipped-partial
bundleId: skipped
position: 100
Expand Down
7 changes: 4 additions & 3 deletions tests/e2e/generate-bundles/02-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ data:
{"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","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","id":"landing2"},{"expandable":true,"title":"Some
new link","id":"bar2","routes":[{"href":"/nested/bar","title":"Foo","id":"foo"}]},{"href":"/baz","title":"Some
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":[]}]

0 comments on commit e7bafcf

Please sign in to comment.