Skip to content

Commit

Permalink
feat: add home icon in left bottom
Browse files Browse the repository at this point in the history
Signed-off-by: SuZhou-Joe <[email protected]>
  • Loading branch information
SuZhou-Joe committed Aug 22, 2024
1 parent 3a41f7b commit f1f06ee
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ export function CollapsibleNavGroupEnabled({
<div
className={classNames({
'bottom-container': true,
'eui-xScroll': true,
'bottom-container-collapsed': !isNavOpen,
'bottom-container-expanded': isNavOpen,
})}
Expand Down
19 changes: 19 additions & 0 deletions src/plugins/home/public/application/components/home_icon.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import { fireEvent, render } from '@testing-library/react';
import { HomeIcon } from './home_icon';
import { coreMock } from '../../../../../core/public/mocks';

describe('<HomeIcon />', () => {
it('should call chrome.navGroup.setCurrentNavGroup and application.navigateToApp methods from core service when click', () => {
const coreStartMock = coreMock.createStart();
const { container } = render(<HomeIcon core={coreStartMock} appId="foo" />);
const component = container.children[0];
fireEvent.click(component);
expect(coreStartMock.application.navigateToApp).toBeCalledWith('foo');
});
});
20 changes: 20 additions & 0 deletions src/plugins/home/public/application/components/home_icon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import { EuiButtonIcon } from '@elastic/eui';
import { CoreStart } from 'opensearch-dashboards/public';

export function HomeIcon({ core, appId }: { core: CoreStart; appId: string }) {
return (
<EuiButtonIcon
aria-label="go-to-home"
iconType="home"
onClick={() => {
core.application.navigateToApp(appId);
}}
/>
);
}
15 changes: 15 additions & 0 deletions src/plugins/home/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
} from 'opensearch-dashboards/public';
import { i18n } from '@osd/i18n';
import { first } from 'rxjs/operators';
import React from 'react';

import { Branding } from 'src/core/types';
import {
Expand Down Expand Up @@ -70,6 +71,8 @@ import {
ContentManagementPluginStart,
} from '../../content_management/public';
import { initHome, setupHome } from './application/home_render';
import { toMountPoint } from '../../opensearch_dashboards_react/public';
import { HomeIcon } from './application/components/home_icon';

export interface HomePluginStartDependencies {
data: DataPublicPluginStart;
Expand Down Expand Up @@ -255,6 +258,18 @@ export class HomePublicPlugin
});
}

if (core.chrome.navGroup.getNavGroupEnabled()) {
core.chrome.navControls.registerLeftBottom({
order: 0,
mount: toMountPoint(
React.createElement(HomeIcon, {
core,
appId: PLUGIN_ID,
})
),
});
}

return {
featureCatalogue: this.featuresCatalogueRegistry,
getSavedHomepageLoader: () => this.sectionTypeService.getSavedHomepageLoader(),
Expand Down

0 comments on commit f1f06ee

Please sign in to comment.