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.
[k7/Infra UI] Integrate with K7 Breadcrumbs (elastic#25938)
This changes the header to be conditionally rendered based on the k7design UI setting. If the setting is false, the header is rendered as before. If it is true, the header is hidden and the breadcrumbs are set via the Kibana breadcrumbs api.
- Loading branch information
1 parent
138cbc3
commit 35e8c81
Showing
8 changed files
with
213 additions
and
82 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 was deleted.
Oops, something went wrong.
35 changes: 35 additions & 0 deletions
35
x-pack/plugins/infra/public/components/header/external_header.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,35 @@ | ||
/* | ||
* 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 isEqual from 'lodash/fp/isEqual'; | ||
import React from 'react'; | ||
|
||
import { Breadcrumb } from 'ui/chrome/api/breadcrumbs'; | ||
|
||
interface ExternalHeaderProps { | ||
breadcrumbs?: Breadcrumb[]; | ||
setBreadcrumbs: (breadcrumbs: Breadcrumb[]) => void; | ||
} | ||
|
||
export class ExternalHeader extends React.Component<ExternalHeaderProps> { | ||
public componentDidMount() { | ||
this.setBreadcrumbs(); | ||
} | ||
|
||
public componentDidUpdate(prevProps: ExternalHeaderProps) { | ||
if (!isEqual(this.props.breadcrumbs, prevProps.breadcrumbs)) { | ||
this.setBreadcrumbs(); | ||
} | ||
} | ||
|
||
public render() { | ||
return null; | ||
} | ||
|
||
private setBreadcrumbs = () => { | ||
this.props.setBreadcrumbs(this.props.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* 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 from 'react'; | ||
|
||
import { InjectedIntl, injectI18n } from '@kbn/i18n/react'; | ||
import { Breadcrumb } from 'ui/chrome/api/breadcrumbs'; | ||
import { WithKibanaChrome } from '../../containers/with_kibana_chrome'; | ||
import { ExternalHeader } from './external_header'; | ||
import { LegacyHeader } from './legacy_header'; | ||
|
||
interface HeaderProps { | ||
breadcrumbs?: Breadcrumb[]; | ||
appendSections?: React.ReactNode; | ||
intl: InjectedIntl; | ||
} | ||
|
||
export const Header = injectI18n(({ appendSections, breadcrumbs = [], intl }: HeaderProps) => { | ||
const prefixedBreadcrumbs = [ | ||
{ | ||
href: '#/', | ||
text: intl.formatMessage({ | ||
id: 'xpack.infra.header.infrastructureTitle', | ||
defaultMessage: 'Infrastructure', | ||
}), | ||
}, | ||
...(breadcrumbs || []), | ||
]; | ||
|
||
return ( | ||
<WithKibanaChrome> | ||
{({ setBreadcrumbs, uiSettings: { k7Design } }) => | ||
k7Design ? ( | ||
<ExternalHeader breadcrumbs={prefixedBreadcrumbs} setBreadcrumbs={setBreadcrumbs} /> | ||
) : ( | ||
<LegacyHeader appendSections={appendSections} breadcrumbs={prefixedBreadcrumbs} /> | ||
) | ||
} | ||
</WithKibanaChrome> | ||
); | ||
}); |
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,7 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export { Header } from './header'; |
32 changes: 32 additions & 0 deletions
32
x-pack/plugins/infra/public/components/header/legacy_header.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,32 @@ | ||
/* | ||
* 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 { EuiHeader, EuiHeaderBreadcrumbs, EuiHeaderSection } from '@elastic/eui'; | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
|
||
import { Breadcrumb } from 'ui/chrome/api/breadcrumbs'; | ||
|
||
interface LegacyHeaderProps { | ||
breadcrumbs?: Breadcrumb[]; | ||
appendSections?: React.ReactNode; | ||
} | ||
|
||
export const LegacyHeader: React.SFC<LegacyHeaderProps> = ({ | ||
appendSections, | ||
breadcrumbs = [], | ||
}) => ( | ||
<HeaderWrapper> | ||
<EuiHeaderSection> | ||
<EuiHeaderBreadcrumbs breadcrumbs={breadcrumbs} /> | ||
</EuiHeaderSection> | ||
{appendSections} | ||
</HeaderWrapper> | ||
); | ||
|
||
const HeaderWrapper = styled(EuiHeader)` | ||
height: 29px; | ||
`; |
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