Skip to content

Commit 484c0c4

Browse files
opensearch-trigger-bot[bot]github-actions[bot]opensearch-changeset-bot[bot]
authored
Add navControlsPrimaryHeaderRight slot to header (#9223) (#9250)
* Add navControlNewPrimaryRight slot to header * Changeset file for PR #9223 created/updated * Fix vertical align for header items * Fix test coverage drop * Fix failed UTs * Fix bootstrap failed * Update failed snapshots * Remove left border * Refactor with headerRight * Renaming to primaryHeaderRight * Changeset file for PR #9223 created/updated --------- (cherry picked from commit 8ae1c71) Signed-off-by: Lin Wang <[email protected]> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
1 parent ac21bd7 commit 484c0c4

File tree

9 files changed

+323
-3
lines changed

9 files changed

+323
-3
lines changed

changelogs/fragments/9223.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
feat:
2+
- Add navControlsPrimaryHeaderRight slot to header ([#9223](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9223))

src/core/public/chrome/chrome_service.mock.ts

+2
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,12 @@ const createStartContractMock = () => {
7575
registerCenter: jest.fn(),
7676
registerRight: jest.fn(),
7777
registerLeftBottom: jest.fn(),
78+
registerPrimaryHeaderRight: jest.fn(),
7879
getLeft$: jest.fn(),
7980
getCenter$: jest.fn(),
8081
getRight$: jest.fn(),
8182
getLeftBottom$: jest.fn(),
83+
getPrimaryHeaderRight$: jest.fn(),
8284
},
8385
navGroup: {
8486
getNavGroupsMap$: jest.fn(() => new BehaviorSubject({})),

src/core/public/chrome/chrome_service.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ export class ChromeService {
392392
navControlsExpandedCenter$={navControls.getExpandedCenter$()}
393393
navControlsExpandedRight$={navControls.getExpandedRight$()}
394394
navControlsLeftBottom$={navControls.getLeftBottom$()}
395+
navControlsPrimaryHeaderRight$={navControls.getPrimaryHeaderRight$()}
395396
onIsLockedUpdate={setIsNavDrawerLocked}
396397
isLocked$={getIsNavDrawerLocked$}
397398
branding={injectedMetadata.getBranding()}

src/core/public/chrome/nav_controls/nav_controls_service.test.ts

+24
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,28 @@ describe('RecentlyAccessed#start()', () => {
163163
expect(await navControls.getLeftBottom$().pipe(take(1)).toPromise()).toEqual([nc2, nc1, nc3]);
164164
});
165165
});
166+
167+
describe('new primary header right controls', () => {
168+
it('allows registration', async () => {
169+
const navControls = getStart();
170+
const nc = { mount: jest.fn() };
171+
navControls.registerPrimaryHeaderRight(nc);
172+
expect(await navControls.getPrimaryHeaderRight$().pipe(take(1)).toPromise()).toEqual([nc]);
173+
});
174+
175+
it('sorts controls by order property', async () => {
176+
const navControls = getStart();
177+
const nc1 = { mount: jest.fn(), order: 10 };
178+
const nc2 = { mount: jest.fn(), order: 0 };
179+
const nc3 = { mount: jest.fn(), order: 20 };
180+
navControls.registerPrimaryHeaderRight(nc1);
181+
navControls.registerPrimaryHeaderRight(nc2);
182+
navControls.registerPrimaryHeaderRight(nc3);
183+
expect(await navControls.getPrimaryHeaderRight$().pipe(take(1)).toPromise()).toEqual([
184+
nc2,
185+
nc1,
186+
nc3,
187+
]);
188+
});
189+
});
166190
});

src/core/public/chrome/nav_controls/nav_controls_service.ts

+17
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ export interface ChromeNavControls {
6464
registerCenter(navControl: ChromeNavControl): void;
6565
/** Register a nav control to be presented on the left-bottom side of the left navigation. */
6666
registerLeftBottom(navControl: ChromeNavControl): void;
67+
/** Register a nav control to be presented on the right side of the primary chrome header. */
68+
registerPrimaryHeaderRight(navControl: ChromeNavControl): void;
6769
/** @internal */
6870
getLeft$(): Observable<ChromeNavControl[]>;
6971
/** @internal */
@@ -72,6 +74,8 @@ export interface ChromeNavControls {
7274
getCenter$(): Observable<ChromeNavControl[]>;
7375
/** @internal */
7476
getLeftBottom$(): Observable<ChromeNavControl[]>;
77+
/** @internal */
78+
getPrimaryHeaderRight$(): Observable<ChromeNavControl[]>;
7579
}
7680

7781
/** @internal */
@@ -87,6 +91,9 @@ export class NavControlsService {
8791
new Set()
8892
);
8993
const navControlsLeftBottom$ = new BehaviorSubject<ReadonlySet<ChromeNavControl>>(new Set());
94+
const navControlsPrimaryHeaderRight$ = new BehaviorSubject<ReadonlySet<ChromeNavControl>>(
95+
new Set()
96+
);
9097

9198
return {
9299
// In the future, registration should be moved to the setup phase. This
@@ -115,6 +122,11 @@ export class NavControlsService {
115122
new Set([...navControlsLeftBottom$.value.values(), navControl])
116123
),
117124

125+
registerPrimaryHeaderRight: (navControl: ChromeNavControl) =>
126+
navControlsPrimaryHeaderRight$.next(
127+
new Set([...navControlsPrimaryHeaderRight$.value.values(), navControl])
128+
),
129+
118130
getLeft$: () =>
119131
navControlsLeft$.pipe(
120132
map((controls) => sortBy([...controls.values()], 'order')),
@@ -145,6 +157,11 @@ export class NavControlsService {
145157
map((controls) => sortBy([...controls.values()], 'order')),
146158
takeUntil(this.stop$)
147159
),
160+
getPrimaryHeaderRight$: () =>
161+
navControlsPrimaryHeaderRight$.pipe(
162+
map((controls) => sortBy([...controls.values()], 'order')),
163+
takeUntil(this.stop$)
164+
),
148165
};
149166
}
150167

0 commit comments

Comments
 (0)