-
Notifications
You must be signed in to change notification settings - Fork 964
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
[Workspace]Dismiss get started for search/essential/analytics overview page #8874
Changes from 3 commits
ddba225
0ecd000
8b27d2d
1b996fa
5069600
d417496
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
feat: | ||
- [Workspace] support dismiss get started for search overview page ([#8874](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8874)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,31 +3,53 @@ | |
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React, { useEffect } from 'react'; | ||
import React, { useEffect, useState } from 'react'; | ||
import { useObservable } from 'react-use'; | ||
import { CoreStart } from 'opensearch-dashboards/public'; | ||
import { EuiBreadcrumb } from '@elastic/eui'; | ||
import { | ||
EuiBreadcrumb, | ||
EuiButtonIcon, | ||
EuiContextMenu, | ||
EuiIcon, | ||
EuiPopover, | ||
EuiToolTip, | ||
} from '@elastic/eui'; | ||
import { I18nProvider } from '@osd/i18n/react'; | ||
import { i18n } from '@osd/i18n'; | ||
import { useOpenSearchDashboards } from '../../../../../opensearch_dashboards_react/public'; | ||
import { | ||
ContentManagementPluginStart, | ||
SEARCH_OVERVIEW_PAGE_ID, | ||
SECTIONS, | ||
} from '../../../../../content_management/public'; | ||
import { SEARCH_USE_CASE_ID } from '../../../../../../core/public'; | ||
import { NavigationPublicPluginStart } from '../../../../../navigation/public'; | ||
import { getStartedSection } from './search_use_case_setup'; | ||
import { SEARCH_WORKSPACE_DISMISS_GET_STARTED } from '../../../../common/constants'; | ||
|
||
interface Props { | ||
contentManagement: ContentManagementPluginStart; | ||
navigation: NavigationPublicPluginStart; | ||
} | ||
|
||
export const SearchUseCaseOverviewApp = ({ contentManagement }: Props) => { | ||
export const SearchUseCaseOverviewApp = ({ contentManagement, navigation }: Props) => { | ||
const { | ||
services: { chrome }, | ||
services: { chrome, application, uiSettings }, | ||
} = useOpenSearchDashboards<CoreStart>(); | ||
const [isPopoverOpen, setIsPopoverOpen] = useState(false); | ||
const [isGetStartedDismissed, setIsGetStartedDismissed] = useState<boolean>( | ||
!!uiSettings.get(SEARCH_WORKSPACE_DISMISS_GET_STARTED) | ||
); | ||
|
||
const togglePopover = () => setIsPopoverOpen(!isPopoverOpen); | ||
const closePopover = () => setIsPopoverOpen(false); | ||
|
||
const currentNavGroup = useObservable(chrome.navGroup.getCurrentNavGroup$()); | ||
const isSearchUseCase = currentNavGroup?.id === SEARCH_USE_CASE_ID; | ||
|
||
const HeaderControl = navigation.ui.HeaderControl; | ||
const page = contentManagement.getPage(SEARCH_OVERVIEW_PAGE_ID); | ||
|
||
useEffect(() => { | ||
const title = i18n.translate('home.searchOverview.title', { defaultMessage: 'Overview' }); | ||
const titleWithUseCase = i18n.translate('home.searchOverview.titleWithUseCase', { | ||
|
@@ -48,8 +70,83 @@ export const SearchUseCaseOverviewApp = ({ contentManagement }: Props) => { | |
chrome.setBreadcrumbs(breadcrumbs); | ||
}, [chrome, isSearchUseCase]); | ||
|
||
const dismissGetStartCards = async (state: boolean) => { | ||
uiSettings.set(SEARCH_WORKSPACE_DISMISS_GET_STARTED, state); | ||
setIsGetStartedDismissed(state); | ||
}; | ||
|
||
useEffect(() => { | ||
if (isGetStartedDismissed) { | ||
page?.removeSection(SECTIONS.GET_STARTED); | ||
} else { | ||
page?.createSection(getStartedSection); | ||
} | ||
}, [isGetStartedDismissed, page]); | ||
|
||
const hide = i18n.translate('home.searchOverview.getStartedCard.setting.hide.label', { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make sense, i will update the name in follow up PR. |
||
defaultMessage: 'Hide Get started with Search', | ||
}); | ||
|
||
const show = i18n.translate('home.searchOverview.getStartedCard.setting.show.label', { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: the same here. |
||
defaultMessage: 'Show Get started with Search', | ||
}); | ||
const contextMenuItems = [ | ||
{ | ||
name: isGetStartedDismissed ? show : hide, | ||
icon: <EuiIcon type={isGetStartedDismissed ? 'eye' : 'eyeClosed'} />, | ||
onClick: async () => { | ||
await dismissGetStartCards(!isGetStartedDismissed); | ||
closePopover(); | ||
}, | ||
}, | ||
]; | ||
|
||
const settingToolTip = i18n.translate('home.searchOverview.getStartedCard.setting.tooltip', { | ||
defaultMessage: 'Page settings', | ||
}); | ||
|
||
const pageHeaderButton = () => { | ||
const popOver = ( | ||
<EuiPopover | ||
button={ | ||
<EuiButtonIcon | ||
iconType="gear" | ||
aria-label={settingToolTip} | ||
color="primary" | ||
onClick={togglePopover} | ||
display="base" | ||
data-test-subj="search-overview-setting-button" | ||
size="s" | ||
/> | ||
} | ||
isOpen={isPopoverOpen} | ||
closePopover={closePopover} | ||
panelPaddingSize="none" | ||
> | ||
<EuiContextMenu | ||
size="s" | ||
initialPanelId={0} | ||
panels={[ | ||
{ | ||
id: 0, | ||
items: contextMenuItems, | ||
}, | ||
]} | ||
/> | ||
</EuiPopover> | ||
); | ||
return isPopoverOpen ? popOver : <EuiToolTip content={settingToolTip}>{popOver}</EuiToolTip>; | ||
}; | ||
|
||
const TopNavControls = [ | ||
{ | ||
renderComponent: pageHeaderButton(), | ||
}, | ||
]; | ||
|
||
return ( | ||
<I18nProvider> | ||
<HeaderControl setMountPoint={application.setAppRightControls} controls={TopNavControls} /> | ||
{contentManagement ? contentManagement.renderPage(SEARCH_OVERVIEW_PAGE_ID) : null} | ||
</I18nProvider> | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I remember uiSettings has a get$ method that can return an observable, maybe we can use that and there is no need to have a state here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the state
isGetStartedDismissed
used for multiple place and we need a variable forThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const isGetStartedDismissed = useObservable<boolean>(!!uiSettings.get$(SEARCH_WORKSPACE_DISMISS_GET_STARTED)
, may work as well andsetIsGetStartedDismissed
seems useless.