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>
  • Loading branch information
3 people authored Jul 1, 2024
1 parent b85e177 commit 5212f09
Show file tree
Hide file tree
Showing 21 changed files with 927 additions and 4 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 @@ -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

0 comments on commit 5212f09

Please sign in to comment.