Skip to content

Commit

Permalink
Add necessary serverless and chrome extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
tsullivan committed May 1, 2023
1 parent fb4e6ea commit dd1463a
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export class ChromeService {
const helpSupportUrl$ = new BehaviorSubject<string>(KIBANA_ASK_ELASTIC_LINK);
const isNavDrawerLocked$ = new BehaviorSubject(localStorage.getItem(IS_LOCKED_KEY) === 'true');
const chromeStyle$ = new BehaviorSubject<ChromeStyle>('classic');
const projectNavigation$ = new BehaviorSubject<JSX.Element | undefined>(undefined);

const getKbnVersionClass = () => {
// we assume that the version is valid and has the form 'X.X.X'
Expand Down Expand Up @@ -170,6 +171,10 @@ export class ChromeService {
chromeStyle$.next(style);
};

const setProjectNavigation = (navigation: JSX.Element) => {
projectNavigation$.next(navigation);
};

const isIE = () => {
const ua = window.navigator.userAgent;
const msie = ua.indexOf('MSIE '); // IE 10 or older
Expand Down Expand Up @@ -211,14 +216,21 @@ export class ChromeService {
}

const getHeaderComponent = () => {
const Component = ({ style$ }: { style$: typeof chromeStyle$ }) => {
const Component = ({
style$,
navigation$,
}: {
style$: typeof chromeStyle$;
navigation$: typeof projectNavigation$;
}) => {
if (style$.getValue() === 'project') {
return (
<ProjectHeader
{...{
application,
globalHelpExtensionMenuLinks$,
}}
navigation={navigation$.getValue() ?? null}
actionMenu$={application.currentActionMenu$}
breadcrumbs$={breadcrumbs$.pipe(takeUntil(this.stop$))}
helpExtension$={helpExtension$.pipe(takeUntil(this.stop$))}
Expand Down Expand Up @@ -260,7 +272,7 @@ export class ChromeService {
/>
);
};
return <Component {...{ style$: chromeStyle$ }} />;
return <Component {...{ style$: chromeStyle$, navigation$: projectNavigation$ }} />;
};

return {
Expand Down Expand Up @@ -335,6 +347,7 @@ export class ChromeService {
getBodyClasses$: () => bodyClasses$.pipe(takeUntil(this.stop$)),
setChromeStyle,
getChromeStyle$: () => chromeStyle$.pipe(takeUntil(this.stop$)),
setProjectNavigation,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import React from 'react';
import { Router } from 'react-router-dom';
import { EuiHeader, EuiHeaderLogo, EuiHeaderSection, EuiHeaderSectionItem } from '@elastic/eui';
import { EuiHeader, EuiHeaderSection, EuiHeaderSectionItem } from '@elastic/eui';
import {
ChromeBreadcrumb,
ChromeGlobalHelpExtensionMenuLink,
Expand All @@ -33,29 +33,21 @@ interface Props {
helpSupportUrl$: Observable<string>;
kibanaVersion: string;
application: InternalApplicationStart;
navigation: JSX.Element | null;
navControlsRight$: Observable<ChromeNavControl[]>;
}

export const ProjectHeader = ({
application,
kibanaDocLink,
kibanaVersion,
navigation,
...observables
}: Props) => {
const renderLogo = () => (
<EuiHeaderLogo
iconType="logoElastic"
href="#"
onClick={(e) => e.preventDefault()}
aria-label="Go to home page"
/>
);

return (
<>
<EuiHeader position="fixed">
<EuiHeaderSection grow={false}>
<EuiHeaderSectionItem border="right">{renderLogo()}</EuiHeaderSectionItem>
<EuiHeaderSectionItem>
<HeaderBreadcrumbs breadcrumbs$={observables.breadcrumbs$} />
</EuiHeaderSectionItem>
Expand All @@ -81,9 +73,7 @@ export const ProjectHeader = ({
</EuiHeaderSection>
</EuiHeader>
<Router history={application.history}>
<ProjectNavigation>
<span />
</ProjectNavigation>
<ProjectNavigation>{navigation}</ProjectNavigation>
</Router>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const createStartContractMock = () => {
getBodyClasses$: jest.fn(),
getChromeStyle$: jest.fn(),
setChromeStyle: jest.fn(),
setProjectNavigation: jest.fn(),
};
startContract.navLinks.getAll.mockReturnValue([]);
startContract.getIsVisible$.mockReturnValue(new BehaviorSubject(false));
Expand Down
8 changes: 8 additions & 0 deletions packages/core/chrome/core-chrome-browser/src/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,12 @@ export interface ChromeStart {
* Get an observable of the current style type of the chrome.
*/
getChromeStyle$(): Observable<ChromeStyle>;

/**
* Sets the project navigation to render in the chrome.
* @param projectNavigation The navigation to render in the chrome.
*
* @remarks Has no effect if the chrome style is not `project`.
*/
setProjectNavigation(projectNavigation: JSX.Element): void;
}
5 changes: 4 additions & 1 deletion x-pack/plugins/serverless/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ export class ServerlessPlugin implements Plugin<ServerlessPluginSetup, Serverles

core.chrome.setChromeStyle('project');

return {};
return {
setServerlessNavigation: (navigation: JSX.Element) =>
core.chrome.setProjectNavigation(navigation),
};
}

public stop() {}
Expand Down
5 changes: 3 additions & 2 deletions x-pack/plugins/serverless/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface ServerlessPluginSetup {}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface ServerlessPluginStart {}
export interface ServerlessPluginStart {
setServerlessNavigation: (navigation: JSX.Element) => void;
}

0 comments on commit dd1463a

Please sign in to comment.