Skip to content

Commit afd2e97

Browse files
committed
[navigation-next] feat: introduce new interface for group(#7060)
Signed-off-by: SuZhou-Joe <suzhou@amazon.com>
1 parent b85e177 commit afd2e97

File tree

21 files changed

+927
-4
lines changed

21 files changed

+927
-4
lines changed

changelogs/fragments/7060.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
feat:
2+
- Introduce new interface for group ([#7060](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7060))

src/core/public/chrome/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- [Nav Links Service](#navlinksservice-)
77
- [Recently Accessed Service](#recentlyaccessedservice-)
88
- [Doc Title Service](#doctitleservice-)
9+
- [Nav Group Service](#chromenavgroupservice-)
910
- [UI](#ui-)
1011

1112
## About :
@@ -112,6 +113,31 @@ Gets an Observable of the array of recently accessed history :-
112113
chrome.docTitle.change('My application title')
113114
chrome.docTitle.change(['My application', 'My section'])
114115
```
116+
### ChromeNavGroupService:
117+
- Interface : ChromeNavGroup
118+
- Signature : ```navGroup: ChromeNavGroupService```
119+
- Methods :
120+
Add nav links to group :-
121+
122+
`addNavLinksToGroup: (group: ChromeNavGroup, navLinks: ChromeRegistrationNavLink[]) => void;`
123+
124+
Gets an Observable of the array of registered groups :-
125+
126+
`getNavGroupsMap$: Observable<Record<string, NavGroupItemInMap>>`
127+
##### Register a new group with a navLink
128+
129+
```ts
130+
coreSetup.chrome.navGroup.addNavLinksToGroup(
131+
{
132+
id: 'my-group',
133+
title: 'A demo group',
134+
description: 'description for demo group'
135+
},
136+
[{
137+
id: 'nav'
138+
}]
139+
)
140+
```
115141
### UI :
116142
###### consists of tsx/scss files && renders UI components from css Library e.g ```<Progress props={props}>```
117143

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ import { getLogosMock } from '../../common/mocks';
3636
const createSetupContractMock = () => {
3737
return {
3838
registerCollapsibleNavHeader: jest.fn(),
39+
navGroup: {
40+
addNavLinksToGroup: jest.fn(),
41+
getNavGroupEnabled: jest.fn(),
42+
},
3943
};
4044
};
4145

@@ -70,6 +74,10 @@ const createStartContractMock = () => {
7074
getCenter$: jest.fn(),
7175
getRight$: jest.fn(),
7276
},
77+
navGroup: {
78+
getNavGroupsMap$: jest.fn(() => new BehaviorSubject({})),
79+
getNavGroupEnabled: jest.fn(),
80+
},
7381
setAppTitle: jest.fn(),
7482
setIsVisible: jest.fn(),
7583
getIsVisible$: jest.fn(),

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ async function start({
9090
}: { options?: any; cspConfigMock?: any; startDeps?: ReturnType<typeof defaultStartDeps> } = {}) {
9191
const service = new ChromeService(options);
9292

93+
service.setup({ uiSettings: startDeps.uiSettings });
94+
9395
if (cspConfigMock) {
9496
startDeps.injectedMetadata.getCspConfig.mockReturnValue(cspConfigMock);
9597
}
@@ -119,8 +121,9 @@ describe('setup', () => {
119121
const customHeaderMock = React.createElement('TestCustomNavHeader');
120122
const renderMock = jest.fn().mockReturnValue(customHeaderMock);
121123
const chrome = new ChromeService({ browserSupportsCsp: true });
124+
const uiSettings = uiSettingsServiceMock.createSetupContract();
122125

123-
const chromeSetup = chrome.setup();
126+
const chromeSetup = chrome.setup({ uiSettings });
124127
chromeSetup.registerCollapsibleNavHeader(renderMock);
125128

126129
const chromeStart = await chrome.start(defaultStartDeps());
@@ -135,8 +138,9 @@ describe('setup', () => {
135138
const customHeaderMock = React.createElement('TestCustomNavHeader');
136139
const renderMock = jest.fn().mockReturnValue(customHeaderMock);
137140
const chrome = new ChromeService({ browserSupportsCsp: true });
141+
const uiSettings = uiSettingsServiceMock.createSetupContract();
138142

139-
const chromeSetup = chrome.setup();
143+
const chromeSetup = chrome.setup({ uiSettings });
140144
// call 1st time
141145
chromeSetup.registerCollapsibleNavHeader(renderMock);
142146
// call 2nd time

src/core/public/chrome/chrome_service.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ import { Branding } from '../';
5252
import { getLogos } from '../../common';
5353
import type { Logos } from '../../common/types';
5454
import { OverlayStart } from '../overlays';
55+
import {
56+
ChromeNavGroupService,
57+
ChromeNavGroupServiceSetupContract,
58+
ChromeNavGroupServiceStartContract,
59+
} from './nav_group';
5560

5661
export { ChromeNavControls, ChromeRecentlyAccessed, ChromeDocTitle };
5762

@@ -90,6 +95,10 @@ interface ConstructorParams {
9095
browserSupportsCsp: boolean;
9196
}
9297

98+
export interface SetupDeps {
99+
uiSettings: IUiSettingsClient;
100+
}
101+
93102
export interface StartDeps {
94103
application: InternalApplicationStart;
95104
docLinks: DocLinksStart;
@@ -111,6 +120,7 @@ export class ChromeService {
111120
private readonly navLinks = new NavLinksService();
112121
private readonly recentlyAccessed = new RecentlyAccessedService();
113122
private readonly docTitle = new DocTitleService();
123+
private readonly navGroup = new ChromeNavGroupService();
114124
private collapsibleNavHeaderRender?: CollapsibleNavHeaderRender;
115125

116126
constructor(private readonly params: ConstructorParams) {}
@@ -147,7 +157,8 @@ export class ChromeService {
147157
);
148158
}
149159

150-
public setup() {
160+
public setup({ uiSettings }: SetupDeps): ChromeSetup {
161+
const navGroup = this.navGroup.setup({ uiSettings });
151162
return {
152163
registerCollapsibleNavHeader: (render: CollapsibleNavHeaderRender) => {
153164
if (this.collapsibleNavHeaderRender) {
@@ -158,6 +169,7 @@ export class ChromeService {
158169
}
159170
this.collapsibleNavHeaderRender = render;
160171
},
172+
navGroup,
161173
};
162174
}
163175

@@ -186,6 +198,7 @@ export class ChromeService {
186198
const navLinks = this.navLinks.start({ application, http });
187199
const recentlyAccessed = await this.recentlyAccessed.start({ http });
188200
const docTitle = this.docTitle.start({ document: window.document });
201+
const navGroup = await this.navGroup.start({ navLinks });
189202

190203
// erase chrome fields from a previous app while switching to a next app
191204
application.currentAppId$.subscribe(() => {
@@ -254,6 +267,7 @@ export class ChromeService {
254267
recentlyAccessed,
255268
docTitle,
256269
logos,
270+
navGroup,
257271

258272
getHeaderComponent: () => (
259273
<Header
@@ -344,6 +358,7 @@ export class ChromeService {
344358

345359
public stop() {
346360
this.navLinks.stop();
361+
this.navGroup.stop();
347362
this.stop$.next();
348363
}
349364
}
@@ -360,6 +375,7 @@ export class ChromeService {
360375
*/
361376
export interface ChromeSetup {
362377
registerCollapsibleNavHeader: (render: CollapsibleNavHeaderRender) => void;
378+
navGroup: ChromeNavGroupServiceSetupContract;
363379
}
364380

365381
/**
@@ -397,6 +413,8 @@ export interface ChromeStart {
397413
recentlyAccessed: ChromeRecentlyAccessed;
398414
/** {@inheritdoc ChromeDocTitle} */
399415
docTitle: ChromeDocTitle;
416+
/** {@inheritdoc NavGroupService} */
417+
navGroup: ChromeNavGroupServiceStartContract;
400418
/** {@inheritdoc Logos} */
401419
readonly logos: Logos;
402420

src/core/public/chrome/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,4 @@ export { ChromeRecentlyAccessed, ChromeRecentlyAccessedHistoryItem } from './rec
5050
export { ChromeNavControl, ChromeNavControls } from './nav_controls';
5151
export { ChromeDocTitle } from './doc_title';
5252
export { RightNavigationOrder } from './constants';
53+
export { ChromeRegistrationNavLink } from './nav_group';
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
export {
7+
ChromeNavGroupService,
8+
ChromeNavGroupServiceSetupContract,
9+
ChromeNavGroupServiceStartContract,
10+
ChromeRegistrationNavLink,
11+
NavGroupItemInMap,
12+
} from './nav_group_service';

0 commit comments

Comments
 (0)