Skip to content

Commit

Permalink
Set the Chrome project API as protected for Serverless plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
tsullivan committed May 11, 2023
1 parent a520001 commit 060f94a
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 36 deletions.
30 changes: 29 additions & 1 deletion packages/core/chrome/core-chrome-browser-internal/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
* Side Public License, v 1.
*/

import type {
ChromeProjectNavigation,
ChromeStart,
SideNavComponent,
} from '@kbn/core-chrome-browser';
import type { Observable } from 'rxjs';
import type { ChromeStart } from '@kbn/core-chrome-browser';

/** @internal */
export interface InternalChromeStart extends ChromeStart {
Expand All @@ -23,4 +27,28 @@ export interface InternalChromeStart extends ChromeStart {
* @internal
*/
getBodyClasses$(): Observable<string[]>;

/**
* Used only by the serverless plugin to customize project-style chrome.
* Use {@link ServerlessPluginStart.setSideNavComponent} to set serverless navigation.
*/
project: {
/**
* Sets the project navigation config to be used for rendering project navigation.
* It is used for default project sidenav, project breadcrumbs, tracking active deep link.
* @param projectNavigation The project navigation config
*
* @remarks Has no effect if the chrome style is not `project`.
*/
setNavigation(projectNavigation: ChromeProjectNavigation): void;

/**
* Set custom project sidenav component to be used instead of the default project sidenav.
* @param getter A function returning a CustomNavigationComponent.
* This component will receive Chrome navigation state as props (not yet implemented)
*
* @remarks Has no effect if the chrome style is not `project`.
*/
setSideNavComponent(component: SideNavComponent | null): void;
};
}
23 changes: 0 additions & 23 deletions packages/core/chrome/core-chrome-browser/src/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import type { ChromeHelpExtension } from './help_extension';
import type { ChromeBreadcrumb, ChromeBreadcrumbsAppendExtension } from './breadcrumb';
import type { ChromeBadge, ChromeStyle, ChromeUserBanner } from './types';
import type { ChromeGlobalHelpExtensionMenuLink } from './help_extension';
import type { ChromeProjectNavigation, SideNavComponent } from './project_navigation';

/**
* ChromeStart allows plugins to customize the global chrome header UI and
Expand Down Expand Up @@ -162,26 +161,4 @@ export interface ChromeStart {
* Get an observable of the current style type of the chrome.
*/
getChromeStyle$(): Observable<ChromeStyle>;
/**
* Configuration for serverless projects
*/
project: {
/**
* Sets the project navigation config to be used for rendering project navigation.
* It is used for default project sidenav, project breadcrumbs, tracking active deep link.
* @param projectNavigation The project navigation config
*
* @remarks Has no effect if the chrome style is not `project`.
*/
setNavigation(projectNavigation: ChromeProjectNavigation): void;

/**
* Set custom project sidenav component to be used instead of the default project sidenav.
* @param getter A function returning a CustomNavigationComponent.
* This component will receive Chrome navigation state as props (not yet implemented)
*
* @remarks Has no effect if the chrome style is not `project`.
*/
setSideNavComponent(component: SideNavComponent | null): void;
};
}
18 changes: 9 additions & 9 deletions x-pack/plugins/serverless/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,21 @@
* 2.0.
*/

import React from 'react';
import ReactDOM from 'react-dom';

import { KibanaThemeProvider } from '@kbn/kibana-react-plugin/public';
import { InternalChromeStart } from '@kbn/core-chrome-browser-internal';
import { CoreSetup, CoreStart, Plugin, PluginInitializerContext } from '@kbn/core/public';
import { KibanaThemeProvider } from '@kbn/kibana-react-plugin/public';
import { ProjectSwitcher, ProjectSwitcherKibanaProvider } from '@kbn/serverless-project-switcher';
import { ProjectType } from '@kbn/serverless-types';

import React from 'react';
import ReactDOM from 'react-dom';
import { API_SWITCH_PROJECT as projectChangeAPIUrl } from '../common';
import { ServerlessConfig } from './config';
import {
ServerlessPluginSetup,
ServerlessPluginStart,
ServerlessPluginSetupDependencies,
ServerlessPluginStart,
ServerlessPluginStartDependencies,
} from './types';
import { ServerlessConfig } from './config';
import { API_SWITCH_PROJECT as projectChangeAPIUrl } from '../common';

export class ServerlessPlugin
implements
Expand Down Expand Up @@ -64,7 +63,8 @@ export class ServerlessPlugin

return {
setSideNavComponent: (sideNavigationComponent) =>
core.chrome.project.setSideNavComponent(sideNavigationComponent),
// Casting the "chrome.projects" service to an "internal" type: it's intentional to call the service only from here.
(core.chrome as InternalChromeStart).project.setSideNavComponent(sideNavigationComponent),
};
}

Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/serverless/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
"@kbn/serverless-types",
"@kbn/utils",
"@kbn/core-chrome-browser",
"@kbn/core-chrome-browser-internal",
]
}
4 changes: 2 additions & 2 deletions x-pack/plugins/serverless_search/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ export class ServerlessSearchPlugin

public start(
core: CoreStart,
_startDeps: ServerlessSearchPluginStartDependencies
{ serverless }: ServerlessSearchPluginStartDependencies
): ServerlessSearchPluginStart {
core.chrome.project.setSideNavComponent(createComponent(core));
serverless.setSideNavComponent(createComponent(core));
return {};
}

Expand Down
5 changes: 4 additions & 1 deletion x-pack/plugins/serverless_search/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
* 2.0.
*/

import { ManagementSetup, ManagementStart } from '@kbn/management-plugin/public';
import {
EnterpriseSearchPublicSetup,
EnterpriseSearchPublicStart,
} from '@kbn/enterprise-search-plugin/public';
import { ManagementSetup, ManagementStart } from '@kbn/management-plugin/public';
import { ServerlessPluginSetup, ServerlessPluginStart } from '@kbn/serverless/public';

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface ServerlessSearchPluginSetup {}
Expand All @@ -20,9 +21,11 @@ export interface ServerlessSearchPluginStart {}
export interface ServerlessSearchPluginSetupDependencies {
enterpriseSearch: EnterpriseSearchPublicSetup;
management: ManagementSetup;
serverless: ServerlessPluginSetup;
}

export interface ServerlessSearchPluginStartDependencies {
enterpriseSearch: EnterpriseSearchPublicStart;
management: ManagementStart;
serverless: ServerlessPluginStart;
}
1 change: 1 addition & 0 deletions x-pack/plugins/serverless_search/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
"@kbn/i18n",
"@kbn/kibana-react-plugin",
"@kbn/i18n-react",
"@kbn/serverless",
]
}

0 comments on commit 060f94a

Please sign in to comment.