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

[navigation-next] feat: introduce new interface for group #7060

Merged
merged 36 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
90e7d45
feat: introduce new interface for use case
SuZhou-Joe Jun 19, 2024
2fdc8b2
Changeset file for PR #7060 created/updated
opensearch-changeset-bot[bot] Jun 19, 2024
ac685ba
feat: introduce new interface for use case
SuZhou-Joe Jun 19, 2024
9e2fdac
feat: introduce new interface for use case
SuZhou-Joe Jun 19, 2024
385ac49
feat: introduce new interface for use case
SuZhou-Joe Jun 20, 2024
b672b60
fix: update test snapshot
SuZhou-Joe Jun 20, 2024
3584dcd
fix: update based on comment
SuZhou-Joe Jun 20, 2024
f879c83
Changeset file for PR #7060 created/updated
opensearch-changeset-bot[bot] Jun 20, 2024
7306f05
fix: update based on comment
SuZhou-Joe Jun 20, 2024
308d63d
fix: update based on comment
SuZhou-Joe Jun 20, 2024
c23b04d
fix: update based on comment
SuZhou-Joe Jun 20, 2024
e894656
feat: update based on comment
SuZhou-Joe Jun 21, 2024
4dceb95
feat: update comment
SuZhou-Joe Jun 21, 2024
e3ba6cc
feat: add default nav group
SuZhou-Joe Jun 24, 2024
c4d5a01
fix: type error
SuZhou-Joe Jun 24, 2024
5a543d5
fix: type error
SuZhou-Joe Jun 24, 2024
6572595
feat: expose DEFAULT_NAV_GROUPS in src/core/public
SuZhou-Joe Jun 24, 2024
2bb4910
feat: export NavGroupItemInMap type
SuZhou-Joe Jun 25, 2024
b1dde28
feat: update README
SuZhou-Joe Jun 26, 2024
eb430c0
feat: update README
SuZhou-Joe Jun 26, 2024
0f0e4cc
feat: update interface
SuZhou-Joe Jun 26, 2024
7a61f47
refactor: move navGroup related interface into a service
SuZhou-Joe Jun 27, 2024
b3167e3
feat: remove useless code
SuZhou-Joe Jun 27, 2024
2b9605a
[Navigation-Next] Add nav group enabled in chrome service(7072)
SuZhou-Joe Jun 27, 2024
336e5f6
Remove useless code
SuZhou-Joe Jun 27, 2024
409e332
use homepage flag
SuZhou-Joe Jun 27, 2024
d2ecfd9
feat: update README
SuZhou-Joe Jun 27, 2024
7713b22
feat: expose sorted navLinks
SuZhou-Joe Jun 27, 2024
6886aaa
fix: unit test
SuZhou-Joe Jun 28, 2024
26a5ed6
fix: bootstrap error
SuZhou-Joe Jun 28, 2024
f3e1049
fix: snapshot error
SuZhou-Joe Jun 28, 2024
b816574
feat: update according to comment
SuZhou-Joe Jun 28, 2024
7c2a516
feat: support parent link
SuZhou-Joe Jun 28, 2024
244628f
Merge branch 'main' into feature/register-use-case
ZilongX Jul 1, 2024
8374812
feat: update according to comment
SuZhou-Joe Jul 1, 2024
35c1db7
feat: update according to comment
SuZhou-Joe Jul 1, 2024
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
2 changes: 2 additions & 0 deletions changelogs/fragments/7060.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- Introduce new interface for group ([#7060](https:/opensearch-project/OpenSearch-Dashboards/pull/7060))
26 changes: 26 additions & 0 deletions src/core/public/chrome/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- [Nav Links Service](#navlinksservice-)
- [Recently Accessed Service](#recentlyaccessedservice-)
- [Doc Title Service](#doctitleservice-)
- [Nav Group Service](#chromenavgroupservice-)
- [UI](#ui-)

## About :
Expand Down Expand Up @@ -112,6 +113,31 @@ Gets an Observable of the array of recently accessed history :-
chrome.docTitle.change('My application title')
chrome.docTitle.change(['My application', 'My section'])
```
### ChromeNavGroupService:
- Interface : ChromeNavGroup
- Signature : ```navGroup: ChromeNavGroupService```
- Methods :
Add nav links to group :-

`addNavLinksToGroup: (group: ChromeNavGroup, navLinks: ChromeRegistrationNavLink[]) => void;`

Gets an Observable of the array of registered groups :-

`getNavGroupsMap$: Observable<Record<string, NavGroupItemInMap>>`
##### Register a new group with a navLink

```ts
coreSetup.chrome.navGroup.addNavLinksToGroup(
{
id: 'my-group',
title: 'A demo group',
description: 'description for demo group'
},
[{
id: 'nav'
}]
)
```
### UI :
###### consists of tsx/scss files && renders UI components from css Library e.g ```<Progress props={props}>```

Expand Down
8 changes: 8 additions & 0 deletions src/core/public/chrome/chrome_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
const createSetupContractMock = () => {
return {
registerCollapsibleNavHeader: jest.fn(),
navGroup: {
addNavLinksToGroup: jest.fn(),
getNavGroupEnabled: jest.fn(),
},
};
};

Expand Down Expand Up @@ -70,6 +74,10 @@
getCenter$: jest.fn(),
getRight$: jest.fn(),
},
navGroup: {
getNavGroupsMap$: jest.fn(() => new BehaviorSubject({})),

Check warning on line 78 in src/core/public/chrome/chrome_service.mock.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L78 was not covered by tests
getNavGroupEnabled: jest.fn(),
},
setAppTitle: jest.fn(),
setIsVisible: jest.fn(),
getIsVisible$: jest.fn(),
Expand Down
8 changes: 6 additions & 2 deletions src/core/public/chrome/chrome_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ async function start({
}: { options?: any; cspConfigMock?: any; startDeps?: ReturnType<typeof defaultStartDeps> } = {}) {
const service = new ChromeService(options);

service.setup({ uiSettings: startDeps.uiSettings });

if (cspConfigMock) {
startDeps.injectedMetadata.getCspConfig.mockReturnValue(cspConfigMock);
}
Expand Down Expand Up @@ -119,8 +121,9 @@ describe('setup', () => {
const customHeaderMock = React.createElement('TestCustomNavHeader');
const renderMock = jest.fn().mockReturnValue(customHeaderMock);
const chrome = new ChromeService({ browserSupportsCsp: true });
const uiSettings = uiSettingsServiceMock.createSetupContract();

const chromeSetup = chrome.setup();
const chromeSetup = chrome.setup({ uiSettings });
chromeSetup.registerCollapsibleNavHeader(renderMock);

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

const chromeSetup = chrome.setup();
const chromeSetup = chrome.setup({ uiSettings });
// call 1st time
chromeSetup.registerCollapsibleNavHeader(renderMock);
// call 2nd time
Expand Down
20 changes: 19 additions & 1 deletion src/core/public/chrome/chrome_service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ import { Branding } from '../';
import { getLogos } from '../../common';
import type { Logos } from '../../common/types';
import { OverlayStart } from '../overlays';
import {
ChromeNavGroupService,
ChromeNavGroupServiceSetupContract,
ChromeNavGroupServiceStartContract,
} from './nav_group';

export { ChromeNavControls, ChromeRecentlyAccessed, ChromeDocTitle };

Expand Down Expand Up @@ -90,6 +95,10 @@ interface ConstructorParams {
browserSupportsCsp: boolean;
}

export interface SetupDeps {
uiSettings: IUiSettingsClient;
}

export interface StartDeps {
application: InternalApplicationStart;
docLinks: DocLinksStart;
Expand All @@ -111,6 +120,7 @@ export class ChromeService {
private readonly navLinks = new NavLinksService();
private readonly recentlyAccessed = new RecentlyAccessedService();
private readonly docTitle = new DocTitleService();
private readonly navGroup = new ChromeNavGroupService();
private collapsibleNavHeaderRender?: CollapsibleNavHeaderRender;

constructor(private readonly params: ConstructorParams) {}
Expand Down Expand Up @@ -147,7 +157,8 @@ export class ChromeService {
);
}

public setup() {
public setup({ uiSettings }: SetupDeps): ChromeSetup {
const navGroup = this.navGroup.setup({ uiSettings });
return {
registerCollapsibleNavHeader: (render: CollapsibleNavHeaderRender) => {
if (this.collapsibleNavHeaderRender) {
Expand All @@ -158,6 +169,7 @@ export class ChromeService {
}
this.collapsibleNavHeaderRender = render;
},
navGroup,
};
}

Expand Down Expand Up @@ -186,6 +198,7 @@ export class ChromeService {
const navLinks = this.navLinks.start({ application, http });
const recentlyAccessed = await this.recentlyAccessed.start({ http });
const docTitle = this.docTitle.start({ document: window.document });
const navGroup = await this.navGroup.start({ navLinks });

// erase chrome fields from a previous app while switching to a next app
application.currentAppId$.subscribe(() => {
Expand Down Expand Up @@ -254,6 +267,7 @@ export class ChromeService {
recentlyAccessed,
docTitle,
logos,
navGroup,

getHeaderComponent: () => (
<Header
Expand Down Expand Up @@ -344,6 +358,7 @@ export class ChromeService {

public stop() {
this.navLinks.stop();
this.navGroup.stop();
this.stop$.next();
}
}
Expand All @@ -360,6 +375,7 @@ export class ChromeService {
*/
export interface ChromeSetup {
registerCollapsibleNavHeader: (render: CollapsibleNavHeaderRender) => void;
navGroup: ChromeNavGroupServiceSetupContract;
}

/**
Expand Down Expand Up @@ -397,6 +413,8 @@ export interface ChromeStart {
recentlyAccessed: ChromeRecentlyAccessed;
/** {@inheritdoc ChromeDocTitle} */
docTitle: ChromeDocTitle;
/** {@inheritdoc NavGroupService} */
navGroup: ChromeNavGroupServiceStartContract;
/** {@inheritdoc Logos} */
readonly logos: Logos;

Expand Down
1 change: 1 addition & 0 deletions src/core/public/chrome/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ export { ChromeRecentlyAccessed, ChromeRecentlyAccessedHistoryItem } from './rec
export { ChromeNavControl, ChromeNavControls } from './nav_controls';
export { ChromeDocTitle } from './doc_title';
export { RightNavigationOrder } from './constants';
export { ChromeRegistrationNavLink } from './nav_group';
12 changes: 12 additions & 0 deletions src/core/public/chrome/nav_group/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

export {
ChromeNavGroupService,
ChromeNavGroupServiceSetupContract,
ChromeNavGroupServiceStartContract,
ChromeRegistrationNavLink,
NavGroupItemInMap,
} from './nav_group_service';
Loading
Loading