From 85a3e035c9aef1df3754b47854b6d26c66a5002d Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Thu, 27 Apr 2023 14:46:57 -0700 Subject: [PATCH] Recently accessed items filter prop --- .../src/ui/components/recently_accessed.tsx | 16 +++++++++++----- .../shared-ux/chrome/navigation/types/index.ts | 4 ++++ .../plugins/serverless_search/public/plugin.tsx | 8 ++++++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/packages/shared-ux/chrome/navigation/src/ui/components/recently_accessed.tsx b/packages/shared-ux/chrome/navigation/src/ui/components/recently_accessed.tsx index c6b6a6ec14738..1af9d2bd3a846 100644 --- a/packages/shared-ux/chrome/navigation/src/ui/components/recently_accessed.tsx +++ b/packages/shared-ux/chrome/navigation/src/ui/components/recently_accessed.tsx @@ -13,14 +13,20 @@ import { NavigationProps, NavigationServices } from '../../../types'; import { getI18nStrings } from '../../i18n_strings'; import { navigationStyles as styles } from '../../styles'; -interface Props { - recentlyAccessed$: Observable; -} +type Props = Pick; +type Services = Pick; -export const RecentlyAccessed = (props: Props) => { +export const RecentlyAccessed = (props: Props & Services) => { const strings = getI18nStrings(); const recentlyAccessed = useObservable(props.recentlyAccessed$, []); - if (recentlyAccessed.length > 0) { + + // consumer may filter objects from recent that are not applicable to the project + let filteredRecent = recentlyAccessed; + if (props.recentlyAccessedFilter) { + filteredRecent = props.recentlyAccessedFilter(recentlyAccessed); + } + + if (filteredRecent.length > 0) { const navItems: Array> = [ { name: '', // no list header title diff --git a/packages/shared-ux/chrome/navigation/types/index.ts b/packages/shared-ux/chrome/navigation/types/index.ts index a42aee4bc3cc3..2de081df42530 100644 --- a/packages/shared-ux/chrome/navigation/types/index.ts +++ b/packages/shared-ux/chrome/navigation/types/index.ts @@ -125,6 +125,10 @@ export interface NavigationProps { * Control of the link that takes the user to their projects or deployments */ linkToCloud?: 'projects' | 'deployments'; + /** + * Filter function to allow consumer to remove items from the recently accessed section + */ + recentlyAccessedFilter?: (items: RecentItem[]) => RecentItem[]; } export type NavigationBucketProps = (SolutionProperties & diff --git a/x-pack/plugins/serverless_search/public/plugin.tsx b/x-pack/plugins/serverless_search/public/plugin.tsx index 6029c0cb160e6..4c415d8412fa9 100644 --- a/x-pack/plugins/serverless_search/public/plugin.tsx +++ b/x-pack/plugins/serverless_search/public/plugin.tsx @@ -9,6 +9,7 @@ import { CoreSetup, CoreStart, Plugin } from '@kbn/core/public'; import { Navigation, NavigationKibanaProvider, + NavigationProps, NavItemProps, } from '@kbn/shared-ux-chrome-navigation'; import React from 'react'; @@ -52,6 +53,7 @@ const navItems: NavItemProps[] = [ ], }, ]; + export class ServerlessSearchPlugin implements Plugin { @@ -66,6 +68,11 @@ export class ServerlessSearchPlugin core: CoreStart, { serverless }: ServerlessSearchPluginStartDependencies ): ServerlessSearchPluginStart { + const recentlyAccessedFilter: NavigationProps['recentlyAccessedFilter'] = (items) => { + // Example: only allow recent dashboards + return items.filter(({ link }) => link.match('/app/dashboards')); + }; + serverless.setServerlessNavigation( );