Skip to content

Commit

Permalink
[navigation-next] feat: introduce new interface for group (opensearch…
Browse files Browse the repository at this point in the history
…-project#7060)

* feat: introduce new interface for use case

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* Changeset file for PR opensearch-project#7060 created/updated

* feat: introduce new interface for use case

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: introduce new interface for use case

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: introduce new interface for use case

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* fix: update test snapshot

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* fix: update based on comment

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* Changeset file for PR opensearch-project#7060 created/updated

* fix: update based on comment

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* fix: update based on comment

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* fix: update based on comment

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: update based on comment

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: update comment

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: add default nav group

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* fix: type error

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* fix: type error

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: expose DEFAULT_NAV_GROUPS in src/core/public

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: export NavGroupItemInMap type

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: update README

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: update README

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: update interface

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* refactor: move navGroup related interface into a service

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: remove useless code

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* [Navigation-Next] Add nav group enabled in chrome service(7072)

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* Remove useless code

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* use homepage flag

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: update README

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: expose sorted navLinks

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* fix: unit test

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* fix: bootstrap error

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* fix: snapshot error

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: update according to comment

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: support parent link

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: update according to comment

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: update according to comment

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

---------

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
Co-authored-by: ZilongX <99905560+ZilongX@users.noreply.github.com>
(cherry picked from commit 5212f09)
  • Loading branch information
SuZhou-Joe committed Jul 1, 2024
1 parent 4f30080 commit 52fed48
Show file tree
Hide file tree
Showing 21 changed files with 928 additions and 5 deletions.
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://github.com/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 @@ import { getLogosMock } from '../../common/mocks';
const createSetupContractMock = () => {
return {
registerCollapsibleNavHeader: jest.fn(),
navGroup: {
addNavLinksToGroup: jest.fn(),
getNavGroupEnabled: jest.fn(),
},
};
};

Expand Down Expand Up @@ -70,6 +74,10 @@ const createStartContractMock = () => {
getCenter$: jest.fn(),
getRight$: jest.fn(),
},
navGroup: {
getNavGroupsMap$: jest.fn(() => new BehaviorSubject({})),
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 @@ -87,6 +87,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 @@ -116,8 +118,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 @@ -132,8 +135,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
22 changes: 20 additions & 2 deletions src/core/public/chrome/chrome_service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,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 @@ -91,7 +96,11 @@ interface ConstructorParams {
browserSupportsCsp: boolean;
}

interface StartDeps {
export interface SetupDeps {
uiSettings: IUiSettingsClient;
}

export interface StartDeps {
application: InternalApplicationStart;
docLinks: DocLinksStart;
http: HttpStart;
Expand All @@ -112,6 +121,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 @@ -148,7 +158,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 @@ -159,6 +170,7 @@ export class ChromeService {
}
this.collapsibleNavHeaderRender = render;
},
navGroup,
};
}

Expand Down Expand Up @@ -187,6 +199,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 @@ -255,6 +268,7 @@ export class ChromeService {
recentlyAccessed,
docTitle,
logos,
navGroup,

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

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

/**
Expand Down Expand Up @@ -398,6 +414,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

0 comments on commit 52fed48

Please sign in to comment.