Skip to content

Commit

Permalink
Search Serverless plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
clintandrewhall committed Apr 21, 2023
1 parent 03e8824 commit 89bd09c
Show file tree
Hide file tree
Showing 25 changed files with 350 additions and 5 deletions.
7 changes: 7 additions & 0 deletions config/serverless.es.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
xpack.apm.enabled: false
xpack.uptime.enabled: false

enterpriseSearch.enabled: true
xpack.serverless.search.enabled: true

uiSettings.overrides.defaultRoute: /app/enterprise_search/content/search_indices
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@
"@kbn/server-route-repository": "link:packages/kbn-server-route-repository",
"@kbn/serverless": "link:x-pack/plugins/serverless",
"@kbn/serverless-observability": "link:x-pack/plugins/serverless_observability",
"@kbn/serverless-search": "link:x-pack/plugins/serverless_search",
"@kbn/serverless-security": "link:x-pack/plugins/serverless_security",
"@kbn/session-notifications-plugin": "link:test/plugin_functional/plugins/session_notifications",
"@kbn/session-view-plugin": "link:x-pack/plugins/session_view",
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ pageLoadAssetSize:
securitySolution: 66738
serverless: 16573
serverlessObservability: 16582
serverlessSearch: 17548
serverlessSecurity: 41807
sessionView: 77750
share: 71239
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,8 @@
"@kbn/serverless/*": ["x-pack/plugins/serverless/*"],
"@kbn/serverless-observability": ["x-pack/plugins/serverless_observability"],
"@kbn/serverless-observability/*": ["x-pack/plugins/serverless_observability/*"],
"@kbn/serverless-search": ["x-pack/plugins/serverless_search"],
"@kbn/serverless-search/*": ["x-pack/plugins/serverless_search/*"],
"@kbn/serverless-security": ["x-pack/plugins/serverless_security"],
"@kbn/serverless-security/*": ["x-pack/plugins/serverless_security/*"],
"@kbn/session-notifications-plugin": ["test/plugin_functional/plugins/session_notifications"],
Expand Down
13 changes: 12 additions & 1 deletion x-pack/plugins/enterprise_search/public/applications/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,17 @@ import { mountLicensingLogic } from './shared/licensing';

export const renderApp = (
App: React.FC<InitialAppData>,
{ params, core, plugins }: { params: AppMountParameters; core: CoreStart; plugins: PluginsStart },
{
params,
core,
plugins,
isSidebarEnabled,
}: {
params: AppMountParameters;
core: CoreStart;
plugins: PluginsStart;
isSidebarEnabled: boolean;
},
{ config, data }: { config: ClientConfigType; data: ClientData }
) => {
const { publicUrl, errorConnectingMessage, ...initialData } = data;
Expand Down Expand Up @@ -68,6 +78,7 @@ export const renderApp = (
charts: plugins.charts,
cloud: plugins.cloud,
uiSettings: core.uiSettings,
isSidebarEnabled,
guidedOnboarding: plugins.guidedOnboarding,
history: params.history,
navigateToUrl: core.application.navigateToUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ interface KibanaLogicProps {
guidedOnboarding: GuidedOnboardingPluginStart;
security: SecurityPluginStart;
uiSettings: IUiSettingsClient;
isSidebarEnabled: boolean;
// Optional plugins
cloud?: CloudSetup;
}

export interface KibanaValues extends Omit<KibanaLogicProps, 'cloud'> {
cloud: Partial<CloudSetup>;
data: DataPublicPluginStart;
Expand All @@ -67,12 +69,13 @@ export const KibanaLogic = kea<MakeLogicType<KibanaValues>>({
reducers: ({ props }) => ({
application: [props.application || {}, {}],
capabilities: [props.capabilities || {}, {}],
config: [props.config || {}, {}],
charts: [props.charts, {}],
cloud: [props.cloud || {}, {}],
config: [props.config || {}, {}],
data: [props.data, {}],
guidedOnboarding: [props.guidedOnboarding, {}],
history: [props.history, {}],
isSidebarEnabled: [props.isSidebarEnabled, {}],
lens: [props.lens, {}],
navigateToUrl: [
(url: string, options?: CreateHrefOptions) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ import { KibanaLogic } from '../kibana';
import { generateNavLink } from './nav_link_helpers';

export const useEnterpriseSearchNav = () => {
const { productAccess, productFeatures } = useValues(KibanaLogic);
const { isSidebarEnabled, productAccess, productFeatures } = useValues(KibanaLogic);

if (!isSidebarEnabled) return undefined;

const navItems: Array<EuiSideNavItemType<unknown>> = [
{
Expand Down Expand Up @@ -174,6 +176,7 @@ export const useEnterpriseSearchNav = () => {

export const useEnterpriseSearchEngineNav = (engineName?: string, isEmptyState?: boolean) => {
const navItems = useEnterpriseSearchNav();
if (!navItems) return undefined;
if (!engineName) return navItems;
const applicationsItem = navItems.find((item) => item.id === 'applications');
if (!applicationsItem || !applicationsItem.items) return navItems;
Expand Down Expand Up @@ -259,6 +262,9 @@ export const useEnterpriseSearchAnalyticsNav = (
}
) => {
const navItems = useEnterpriseSearchNav();

if (!navItems) return undefined;

const applicationsNav = navItems.find((item) => item.id === 'applications');
const analyticsNav = applicationsNav?.items?.find((item) => item.id === 'analyticsCollections');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ export const EnterpriseSearchPageTemplateWrapper: React.FC<PageTemplateProps> =
),
}}
isEmptyState={isEmptyState && !isLoading}
solutionNav={solutionNav ? { icon: 'logoEnterpriseSearch', ...solutionNav } : undefined}
solutionNav={
solutionNav && solutionNav.items
? { icon: 'logoEnterpriseSearch', ...solutionNav }
: undefined
}
>
{setPageChrome}
{readOnlyMode && (
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/enterprise_search/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ import { EnterpriseSearchPlugin } from './plugin';
export const plugin = (initializerContext: PluginInitializerContext) => {
return new EnterpriseSearchPlugin(initializerContext);
};

export type { EnterpriseSearchPublicSetup, EnterpriseSearchPublicStart } from './plugin';
10 changes: 9 additions & 1 deletion x-pack/plugins/enterprise_search/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ export interface ClientData extends InitialAppData {
errorConnectingMessage?: string;
}

export type EnterpriseSearchPublicSetup = ReturnType<EnterpriseSearchPlugin['setup']>;
export type EnterpriseSearchPublicStart = ReturnType<EnterpriseSearchPlugin['start']>;

interface PluginsSetup {
cloud?: CloudSetup;
home?: HomePublicPluginSetup;
Expand All @@ -62,6 +65,7 @@ export class EnterpriseSearchPlugin implements Plugin {
private config: ClientConfigType;
private hasInitialized: boolean = false;
private data: ClientData = {} as ClientData;
private isSidebarEnabled = true;

constructor(initializerContext: PluginInitializerContext) {
this.config = initializerContext.config.get<ClientConfigType>();
Expand Down Expand Up @@ -315,7 +319,11 @@ export class EnterpriseSearchPlugin implements Plugin {
: undefined;
const plugins = { ...pluginsStart, cloud } as PluginsStart;

return { params, core: coreStart, plugins };
coreStart.chrome
.getChromeStyle$()
.subscribe((style) => (this.isSidebarEnabled = style !== 'project'));

return { params, core: coreStart, plugins, isSidebarEnabled: this.isSidebarEnabled };
}

private getPluginData() {
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/serverless_search/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/build
/target
3 changes: 3 additions & 0 deletions x-pack/plugins/serverless_search/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# serverlessSearch

A witty, fitting description to come.
9 changes: 9 additions & 0 deletions x-pack/plugins/serverless_search/common/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export const PLUGIN_ID = 'serverlessSearch';
export const PLUGIN_NAME = 'serverlessSearch';
23 changes: 23 additions & 0 deletions x-pack/plugins/serverless_search/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"type": "plugin",
"id": "@kbn/serverless-search",
"owner": "@elastic/appex-sharedux",
"description": "Serverless customizations for search.",
"plugin": {
"id": "serverlessSearch",
"server": true,
"browser": true,
"configPath": [
"xpack",
"serverless",
"search"
],
"requiredPlugins": [
"serverless",
"enterpriseSearch",
"management"
],
"optionalPlugins": [],
"requiredBundles": []
}
}
11 changes: 11 additions & 0 deletions x-pack/plugins/serverless_search/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "@kbn/serverless-search",
"version": "1.0.0",
"license": "Elastic License 2.0",
"private": true,
"scripts": {
"build": "yarn plugin-helpers build",
"plugin-helpers": "node ../../../scripts/plugin_helpers",
"kbn": "node ../../../scripts/kbn"
}
}
16 changes: 16 additions & 0 deletions x-pack/plugins/serverless_search/public/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { ServerlessSearchPlugin } from './plugin';

// This exports static code and TypeScript types,
// as well as, Kibana Platform `plugin()` initializer.
export function plugin() {
return new ServerlessSearchPlugin();
}

export type { ServerlessSearchPluginSetup, ServerlessSearchPluginStart } from './types';
54 changes: 54 additions & 0 deletions x-pack/plugins/serverless_search/public/layout/nav.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import React from 'react';
import { EuiCollapsibleNavGroup, EuiListGroup } from '@elastic/eui';
import { ApplicationStart, HttpSetup } from '@kbn/core/public';

export interface ServerlessSearchCollapsibleNavigationProps {
http: HttpSetup;
navigateToUrl: ApplicationStart['navigateToUrl'];
}

export const ServerlessSearchCollapsibleNavigation = ({
http,
navigateToUrl,
}: ServerlessSearchCollapsibleNavigationProps) => {
const navigateTo = (url: string) => () => {
navigateToUrl(http.basePath.prepend(url));
};
const navItems = [
{
label: 'Overview',
onClick: navigateTo('/app/enterprise_search/overview'),
},
{
label: 'Indices',
onClick: navigateTo('/app/enterprise_search/content/search_indices'),
},
{
label: 'Engines',
onClick: navigateTo('/app/enterprise_search/content/engines'),
},
{
label: 'API keys',
onClick: navigateTo('/app/management/security/api_keys'),
},
{
label: 'Ingest pipelines',
onClick: navigateTo('/app/management/ingest/ingest_pipelines'),
},
];

return (
<>
<EuiCollapsibleNavGroup title="Search" iconType="logoEnterpriseSearch" isCollapsible={false}>
<EuiListGroup listItems={navItems} />
</EuiCollapsibleNavGroup>
</>
);
};
43 changes: 43 additions & 0 deletions x-pack/plugins/serverless_search/public/plugin.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import React from 'react';
import { CoreSetup, CoreStart, Plugin } from '@kbn/core/public';
import {
ServerlessSearchPluginSetup,
ServerlessSearchPluginSetupDependencies,
ServerlessSearchPluginStart,
ServerlessSearchPluginStartDependencies,
} from './types';

import { ServerlessSearchCollapsibleNavigation } from './layout/nav';

export class ServerlessSearchPlugin
implements Plugin<ServerlessSearchPluginSetup, ServerlessSearchPluginStart>
{
public setup(
_core: CoreSetup,
_setupDeps: ServerlessSearchPluginSetupDependencies
): ServerlessSearchPluginSetup {
return {};
}

public start(
core: CoreStart,
{ serverless }: ServerlessSearchPluginStartDependencies
): ServerlessSearchPluginStart {
serverless.setServerlessNavigation(
<ServerlessSearchCollapsibleNavigation
http={core.http}
navigateToUrl={core.application.navigateToUrl}
/>
);
return {};
}

public stop() {}
}
31 changes: 31 additions & 0 deletions x-pack/plugins/serverless_search/public/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

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

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface ServerlessSearchPluginSetup {}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface ServerlessSearchPluginStart {}

export interface ServerlessSearchPluginSetupDependencies {
enterpriseSearch: EnterpriseSearchPublicSetup;
management: ManagementSetup;
serverless: ServerlessPluginSetup;
}

export interface ServerlessSearchPluginStartDependencies {
enterpriseSearch: EnterpriseSearchPublicStart;
management: ManagementStart;
serverless: ServerlessPluginStart;
}
23 changes: 23 additions & 0 deletions x-pack/plugins/serverless_search/server/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { schema, TypeOf } from '@kbn/config-schema';
import { PluginConfigDescriptor } from '@kbn/core/server';

export * from './types';

const configSchema = schema.object({
enabled: schema.boolean({ defaultValue: false }),
});

type ConfigType = TypeOf<typeof configSchema>;

export const config: PluginConfigDescriptor<ConfigType> = {
schema: configSchema,
};

export type ServerlessSearchConfig = TypeOf<typeof configSchema>;
Loading

0 comments on commit 89bd09c

Please sign in to comment.