forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- create shared helper (WS will presumably also want this) for generating EUI breadcrumb objects with React Router links+click behavior - create React component that calls chrome.setBreadcrumbs on page mount - clean up type definitions - move app-wide props to IAppSearchProps and update most pages/views to simply import it instead of calling their own definitions
- Loading branch information
Showing
11 changed files
with
140 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...s/enterprise_search/public/applications/shared/kibana_breadcrumbs/generate_breadcrumbs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { Breadcrumb as EuiBreadcrumb } from '@elastic/eui'; | ||
import { History } from 'history'; | ||
|
||
import { letBrowserHandleEvent } from '../react_router_helpers'; | ||
|
||
/** | ||
* Generate React-Router-friendly EUI breadcrumb objects | ||
* https://elastic.github.io/eui/#/navigation/breadcrumbs | ||
*/ | ||
|
||
interface IGenerateBreadcrumbProps { | ||
text: string; | ||
path: string; | ||
history: History; | ||
} | ||
|
||
export const generateBreadcrumb = ({ text, path, history }: IGenerateBreadcrumbProps) => ({ | ||
text, | ||
href: history.createHref({ pathname: path }), | ||
onClick: event => { | ||
if (letBrowserHandleEvent(event)) return; | ||
event.preventDefault(); | ||
history.push(path); | ||
}, | ||
}); | ||
|
||
/** | ||
* Product-specific breadcrumb helpers | ||
*/ | ||
|
||
type TBreadcrumbs = EuiBreadcrumb[] | []; | ||
|
||
export const enterpriseSearchBreadcrumbs = (history: History) => ( | ||
breadcrumbs: TBreadcrumbs = [] | ||
) => [ | ||
generateBreadcrumb({ text: 'Enterprise Search', path: '/', history }), | ||
...breadcrumbs.map(({ text, path }) => generateBreadcrumb({ text, path, history })), | ||
]; | ||
|
||
export const appSearchBreadcrumbs = (history: History) => (breadcrumbs: TBreadcrumbs = []) => | ||
enterpriseSearchBreadcrumbs(history)([ | ||
{ text: 'App Search', path: '/app_search' }, | ||
...breadcrumbs, | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...ugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/set_breadcrumbs.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React, { useEffect } from 'react'; | ||
import { useHistory } from 'react-router-dom'; | ||
import { Breadcrumb as EuiBreadcrumb } from '@elastic/eui'; | ||
import { appSearchBreadcrumbs } from './generate_breadcrumbs'; | ||
|
||
/** | ||
* Small on-mount helper for setting Kibana's chrome breadcrumbs on any App Search view | ||
* @see https://github.com/elastic/kibana/blob/master/src/core/public/chrome/chrome_service.tsx | ||
*/ | ||
|
||
export type TSetBreadcrumbs = (breadcrumbs: EuiBreadcrumb[]) => void; | ||
|
||
interface ISetBreadcrumbsProps { | ||
text: string; | ||
setBreadcrumbs(): setBreadcrumbs; | ||
isRoot?: boolean; | ||
} | ||
|
||
export const SetAppSearchBreadcrumbs: React.FC<ISetBreadcrumbsProps> = ({ | ||
text, | ||
setBreadcrumbs, | ||
isRoot, | ||
}) => { | ||
const history = useHistory(); | ||
const crumb = isRoot ? [] : [{ text, path: history.location.pathname }]; | ||
|
||
useEffect(() => { | ||
setBreadcrumbs(appSearchBreadcrumbs(history)(crumb)); | ||
}, []); // eslint-disable-line | ||
|
||
return null; | ||
}; |