Skip to content

Commit

Permalink
Merge pull request #236 from Hyperkid123/propagate-nav-position
Browse files Browse the repository at this point in the history
Propagate nav position
  • Loading branch information
Hyperkid123 authored Jan 16, 2025
2 parents 3cc293b + 2727e36 commit 7a33af8
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 8 deletions.
12 changes: 7 additions & 5 deletions api/v1alpha1/frontend_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,13 @@ 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"`
BundleSegmentRef string `json:"bundleSegmentRef,omitempty" yaml:"bundleSegmentRef,omitempty"`
FrontendRef string `json:"frontendRef,omitempty" yaml:"frontendRef,omitempty"`
Routes []ChromeNavItem `json:"routes,omitempty" yaml:"routes,omitempty"`
Permissions []Permission `json:"permissions,omitempty" yaml:"permissions,omitempty"`
// Position argument inherited from the segment, needed for smooth transition between old a new system and for proper developer experience
Position *uint `json:"position,omitempty" yaml:"position,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
5 changes: 5 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

10 changes: 10 additions & 0 deletions config/crd/bases/cloud.redhat.com_bundles.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ spec:
- method
type: object
type: array
position:
description: Position argument inherited from the segment, needed
for smooth transition between old a new system and for proper
developer experience
type: integer
product:
type: string
routes:
Expand Down Expand Up @@ -159,6 +164,11 @@ spec:
- method
type: object
type: array
position:
description: Position argument inherited from the segment,
needed for smooth transition between old a new system
and for proper developer experience
type: integer
product:
type: string
routes:
Expand Down
10 changes: 10 additions & 0 deletions config/crd/bases/cloud.redhat.com_frontends.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ spec:
- method
type: object
type: array
position:
description: Position argument inherited from the segment,
needed for smooth transition between old a new system
and for proper developer experience
type: integer
product:
type: string
routes:
Expand Down Expand Up @@ -446,6 +451,11 @@ spec:
- method
type: object
type: array
position:
description: Position argument inherited from the segment,
needed for smooth transition between old a new system
and for proper developer experience
type: integer
product:
type: string
routes:
Expand Down
8 changes: 7 additions & 1 deletion controllers/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,13 @@ func setupBundlesData(feList *crd.FrontendList, feEnvironment crd.FrontendEnviro
})
navItems := []crd.ChromeNavItem{}
for _, navSegment := range bundleNavSegmentMap[bundle.ID] {
navItems = append(navItems, *navSegment.NavItems...)
for _, navItem := range *navSegment.NavItems {
// duplicate position for further consumption on the frontend
// need a new variable for position to avoid pointer reference issues
pos := navSegment.Position
navItem.Position = &pos
navItems = append(navItems, navItem)
}
}
// fill the nav refs before adding the bundle
navItems, err := fillNavRefsTree(navItems, navSegmentsCache, 0)
Expand Down
20 changes: 20 additions & 0 deletions deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ objects:
- method
type: object
type: array
position:
description: Position argument inherited from the segment,
needed for smooth transition between old a new system and
for proper developer experience
type: integer
product:
type: string
routes:
Expand Down Expand Up @@ -178,6 +183,11 @@ objects:
- method
type: object
type: array
position:
description: Position argument inherited from the segment,
needed for smooth transition between old a new system
and for proper developer experience
type: integer
product:
type: string
routes:
Expand Down Expand Up @@ -568,6 +578,11 @@ objects:
- method
type: object
type: array
position:
description: Position argument inherited from the segment,
needed for smooth transition between old a new system
and for proper developer experience
type: integer
product:
type: string
routes:
Expand Down Expand Up @@ -891,6 +906,11 @@ objects:
- method
type: object
type: array
position:
description: Position argument inherited from the segment,
needed for smooth transition between old a new system
and for proper developer experience
type: integer
product:
type: string
routes:
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/generate-bundles/02-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +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","bundleSegmentRef":"a-inventory-segment","frontendRef":"landing-page"},{"href":"/apps/landing","title":"Landing section B","id":"landing","bundleSegmentRef":"b-inventory-segment","frontendRef":"landing-page"},{"href":"/apps/landing","title":"Landing section c","id":"landing","bundleSegmentRef":"c-inventory-segment","frontendRef":"landing-page"},{"expandable":true,"title":"Some new link","id":"bar","routes":[{"href":"/nested/bar","title":"Foo","id":"foo","bundleSegmentRef":"c-inventory-segment","frontendRef":"landing-page"}],"bundleSegmentRef":"c-inventory-segment","frontendRef":"landing-page"},{"href":"/baz","title":"Some new link","id":"baz","bundleSegmentRef":"c-inventory-segment","frontendRef":"landing-page"},{"href":"/apps/landing","title":"Landing section D","id":"landing","bundleSegmentRef":"d-inventory-segment","frontendRef":"landing-page"},{"href":"/apps/landing","title":"Landing section last","id":"landing2","bundleSegmentRef":"inventory-last-segment","frontendRef":"landing-page"},{"expandable":true,"title":"Some new link","id":"bar2","routes":[{"href":"/nested/bar","title":"Foo","id":"foo","bundleSegmentRef":"inventory-last-segment","frontendRef":"landing-page"}],"bundleSegmentRef":"inventory-last-segment","frontendRef":"landing-page"},{"href":"/baz","title":"Some new link","id":"baz2","bundleSegmentRef":"inventory-last-segment","frontendRef":"landing-page"}]},{"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","position":100,"bundleSegmentRef":"a-inventory-segment","frontendRef":"landing-page"},{"href":"/apps/landing","title":"Landing section B","id":"landing","position":100,"bundleSegmentRef":"b-inventory-segment","frontendRef":"landing-page"},{"href":"/apps/landing","title":"Landing section c","id":"landing","position":100,"bundleSegmentRef":"c-inventory-segment","frontendRef":"landing-page"},{"expandable":true,"title":"Some new link","id":"bar","routes":[{"href":"/nested/bar","title":"Foo","id":"foo","bundleSegmentRef":"c-inventory-segment","frontendRef":"landing-page"}],"position":100,"bundleSegmentRef":"c-inventory-segment","frontendRef":"landing-page"},{"href":"/baz","title":"Some new link","id":"baz","position":100,"bundleSegmentRef":"c-inventory-segment","frontendRef":"landing-page"},{"href":"/apps/landing","title":"Landing section D","id":"landing","position":100,"bundleSegmentRef":"d-inventory-segment","frontendRef":"landing-page"},{"href":"/apps/landing","title":"Landing section last","id":"landing2","position":200,"bundleSegmentRef":"inventory-last-segment","frontendRef":"landing-page"},{"expandable":true,"title":"Some new link","id":"bar2","routes":[{"href":"/nested/bar","title":"Foo","id":"foo","bundleSegmentRef":"inventory-last-segment","frontendRef":"landing-page"}],"position":200,"bundleSegmentRef":"inventory-last-segment","frontendRef":"landing-page"},{"href":"/baz","title":"Some new link","id":"baz2","position":200,"bundleSegmentRef":"inventory-last-segment","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","bundleSegmentRef":"segment-one","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":"segment-one","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":"segment-one","frontendRef":"segmented-app-two"},{"href":"/link-four","title":"Link four classic","id":"link-four","bundleSegmentRef":"segment-one","frontendRef":"segmented-app-one"},{"expandable":true,"title":"Expandable","id":"expandable","routes":[{"href":"/nested/one","title":"Nested one","id":"nested-one","bundleSegmentRef":"nested-segment","frontendRef":"segmented-app-one"},{"href":"/nested/two","title":"Nested two","id":"nested-two","segmentRef":{"frontendName":"segmented-app-two","segmentId":"nested-segment-two"},"bundleSegmentRef":"nested-segment","frontendRef":"segmented-app-two"},{"href":"/nested/three","title":"Nested three","id":"nested-three","segmentRef":{"frontendName":"segmented-app-two","segmentId":"nested-segment-two"},"bundleSegmentRef":"nested-segment","frontendRef":"segmented-app-two"},{"href":"/nested/four","title":"Nested four","id":"nested-four","bundleSegmentRef":"nested-segment","frontendRef":"segmented-app-one"}],"bundleSegmentRef":"nested-segment","frontendRef":"segmented-app-one"}]}]
[{"id":"segmented-bundle","title":"Segmented bundle","navItems":[{"href":"/link-one","title":"Link one classic","id":"link-one","position":100,"bundleSegmentRef":"segment-one","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":"segment-one","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":"segment-one","frontendRef":"segmented-app-two"},{"href":"/link-four","title":"Link four classic","id":"link-four","position":100,"bundleSegmentRef":"segment-one","frontendRef":"segmented-app-one"},{"expandable":true,"title":"Expandable","id":"expandable","routes":[{"href":"/nested/one","title":"Nested one","id":"nested-one","bundleSegmentRef":"nested-segment","frontendRef":"segmented-app-one"},{"href":"/nested/two","title":"Nested two","id":"nested-two","segmentRef":{"frontendName":"segmented-app-two","segmentId":"nested-segment-two"},"bundleSegmentRef":"nested-segment","frontendRef":"segmented-app-two"},{"href":"/nested/three","title":"Nested three","id":"nested-three","segmentRef":{"frontendName":"segmented-app-two","segmentId":"nested-segment-two"},"bundleSegmentRef":"nested-segment","frontendRef":"segmented-app-two"},{"href":"/nested/four","title":"Nested four","id":"nested-four","bundleSegmentRef":"nested-segment","frontendRef":"segmented-app-one"}],"position":200,"bundleSegmentRef":"nested-segment","frontendRef":"segmented-app-one"}]}]

0 comments on commit 7a33af8

Please sign in to comment.