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

[Backport 2.x] Adapt the newsfeed button to the updated header #7794

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const HeaderUserThemeMenu = () => {
: screenModeOptions[0].value
);

const legacyAppearance = !uiSettings.get('home:useNewHomePage');
const useLegacyAppearance = !uiSettings.get('home:useNewHomePage');

const onButtonClick = () => {
setPopover(!isPopoverOpen);
Expand Down Expand Up @@ -105,7 +105,7 @@ export const HeaderUserThemeMenu = () => {
setPopover(false);
};

const innerButton = legacyAppearance ? (
const innerButton = useLegacyAppearance ? (
<EuiHeaderSectionItemButton
aria-expanded="false"
aria-haspopup="true"
Expand Down Expand Up @@ -193,7 +193,7 @@ export const HeaderUserThemeMenu = () => {
button={button}
isOpen={isPopoverOpen}
closePopover={closePopover}
anchorPosition={legacyAppearance ? 'downLeft' : 'rightDown'}
anchorPosition={useLegacyAppearance ? 'downLeft' : 'rightDown'}
panelPaddingSize="s"
>
<EuiPopoverTitle>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

.osdNewsfeedButtonWrapper {
position: relative;

&--dot {
position: absolute;
right: -1 * $euiSizeXS;
top: -1 * $euiSizeXS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@

import React, { useState, Fragment, useEffect } from 'react';
import * as Rx from 'rxjs';
import { EuiHeaderSectionItemButton, EuiIcon } from '@elastic/eui';
import { EuiButtonIcon, EuiHeaderSectionItemButton, EuiIcon, EuiToolTip } from '@elastic/eui';
import { i18n } from '@osd/i18n';
import { NewsfeedFlyout } from './flyout_list';
import { FetchResult } from '../types';
import { CoreStart } from '../../../../core/public';
import './newsfeed_header_nav_button.scss';

export interface INewsfeedContext {
setFlyoutVisible: React.Dispatch<React.SetStateAction<boolean>>;
Expand All @@ -44,10 +46,11 @@ export const NewsfeedContext = React.createContext({} as INewsfeedContext);
export type NewsfeedApiFetchResult = Rx.Observable<void | FetchResult | null>;

export interface Props {
coreStart: CoreStart;
apiFetchResult: NewsfeedApiFetchResult;
}

export const NewsfeedNavButton = ({ apiFetchResult }: Props) => {
export const NewsfeedNavButton = ({ coreStart, apiFetchResult }: Props) => {
const [showBadge, setShowBadge] = useState<boolean>(false);
const [flyoutVisible, setFlyoutVisible] = useState<boolean>(false);
const [newsFetchResult, setNewsFetchResult] = useState<FetchResult | null | void>(null);
Expand All @@ -69,11 +72,40 @@ export const NewsfeedNavButton = ({ apiFetchResult }: Props) => {
setFlyoutVisible(!flyoutVisible);
}

return (
<NewsfeedContext.Provider value={{ setFlyoutVisible, newsFetchResult }}>
<Fragment>
<EuiHeaderSectionItemButton
data-test-subj="newsfeed"
const useLegacyAppearance = !coreStart.uiSettings.get('home:useNewHomePage');
const innerElement = useLegacyAppearance ? (
<EuiHeaderSectionItemButton
data-test-subj="newsfeed"
aria-controls="keyPadMenu"
aria-expanded={flyoutVisible}
aria-haspopup="true"
aria-label={
showBadge
? i18n.translate('newsfeed.headerButton.unreadAriaLabel', {
defaultMessage: 'Newsfeed menu - unread items available',
})
: i18n.translate('newsfeed.headerButton.readAriaLabel', {
defaultMessage: 'Newsfeed menu - all items read',
})
}
notification={showBadge ? true : null}
onClick={showFlyout}
>
<EuiIcon type="cheer" size="m" />
</EuiHeaderSectionItemButton>
) : (
<EuiToolTip
content={i18n.translate('newsfeed.headerButton.menuButtonTooltip', {
defaultMessage: 'Newsfeed',
})}
delay="long"
position="bottom"
>
<div className="osdNewsfeedButtonWrapper">
<EuiButtonIcon
iconType="cheer"
color="primary"
size="xs"
aria-controls="keyPadMenu"
aria-expanded={flyoutVisible}
aria-haspopup="true"
Expand All @@ -86,11 +118,17 @@ export const NewsfeedNavButton = ({ apiFetchResult }: Props) => {
defaultMessage: 'Newsfeed menu - all items read',
})
}
notification={showBadge ? true : null}
onClick={showFlyout}
>
<EuiIcon type="cheer" size="m" />
</EuiHeaderSectionItemButton>
/>
<EuiIcon className="osdNewsfeedButtonWrapper--dot" color="accent" type="dot" size="s" />
</div>
</EuiToolTip>
);

return (
<NewsfeedContext.Provider value={{ setFlyoutVisible, newsFetchResult }}>
<Fragment>
{innerElement}
{flyoutVisible ? <NewsfeedFlyout /> : null}
</Fragment>
</NewsfeedContext.Provider>
Expand Down
9 changes: 5 additions & 4 deletions src/plugins/newsfeed/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ export class NewsfeedPublicPlugin
}

public start(core: CoreStart) {
const useLegacyAppearance = !core.uiSettings.get('home:useNewHomePage');
const api$ = this.fetchNewsfeed(core, this.config).pipe(share());
core.chrome.navControls.registerRight({
core.chrome.navControls[useLegacyAppearance ? 'registerRight' : 'registerLeftBottom']({
order: 1000,
mount: (target) => this.mount(api$, target),
mount: (target) => this.mount(core, api$, target),
});

return {
Expand Down Expand Up @@ -95,10 +96,10 @@ export class NewsfeedPublicPlugin
);
}

private mount(api$: NewsfeedApiFetchResult, targetDomElement: HTMLElement) {
private mount(coreStart: CoreStart, api$: NewsfeedApiFetchResult, targetDomElement: HTMLElement) {
ReactDOM.render(
<I18nProvider>
<NewsfeedNavButton apiFetchResult={api$} />
<NewsfeedNavButton coreStart={coreStart} apiFetchResult={api$} />
</I18nProvider>,
targetDomElement
);
Expand Down
Loading