Skip to content

Commit

Permalink
Recently accessed items filter prop
Browse files Browse the repository at this point in the history
  • Loading branch information
tsullivan committed May 1, 2023
1 parent b43f859 commit 85a3e03
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,20 @@ import { NavigationProps, NavigationServices } from '../../../types';
import { getI18nStrings } from '../../i18n_strings';
import { navigationStyles as styles } from '../../styles';

interface Props {
recentlyAccessed$: Observable<RecentItem[]>;
}
type Props = Pick<NavigationProps, 'recentlyAccessedFilter'>;
type Services = Pick<NavigationServices, 'recentlyAccessed$'>;

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<EuiSideNavItemType<unknown>> = [
{
name: '', // no list header title
Expand Down
4 changes: 4 additions & 0 deletions packages/shared-ux/chrome/navigation/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 &
Expand Down
8 changes: 8 additions & 0 deletions x-pack/plugins/serverless_search/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -52,6 +53,7 @@ const navItems: NavItemProps[] = [
],
},
];

export class ServerlessSearchPlugin
implements Plugin<ServerlessSearchPluginSetup, ServerlessSearchPluginStart>
{
Expand All @@ -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(
<NavigationKibanaProvider core={core}>
<Navigation
Expand All @@ -81,6 +88,7 @@ export class ServerlessSearchPlugin
platformConfig={{}}
homeHref="/app/enterprise_search/content/setup_guide"
linkToCloud="projects"
recentlyAccessedFilter={recentlyAccessedFilter}
/>
</NavigationKibanaProvider>
);
Expand Down

0 comments on commit 85a3e03

Please sign in to comment.