From 1e33a59363872b42e37675160aa9d02d1a893776 Mon Sep 17 00:00:00 2001 From: Julia Rechkunova Date: Tue, 16 Jan 2024 16:32:35 +0100 Subject: [PATCH] [Discover] Extract saved search SO into a separate plugin --- package.json | 1 + src/plugins/saved_search/server/plugin.ts | 6 --- src/plugins/saved_search_so/README.md | 3 ++ .../saved_search_so/common/constants.ts | 17 +++++++++ src/plugins/saved_search_so/common/index.ts | 9 +++++ src/plugins/saved_search_so/jest.config.js | 18 +++++++++ src/plugins/saved_search_so/kibana.jsonc | 15 ++++++++ src/plugins/saved_search_so/server/index.ts | 12 ++++++ src/plugins/saved_search_so/server/plugin.ts | 37 +++++++++++++++++++ .../server/saved_objects/index.ts | 0 .../server/saved_objects/schema.ts | 0 .../server/saved_objects/search.ts | 0 .../saved_objects/search_migrations.test.ts | 0 .../server/saved_objects/search_migrations.ts | 2 - src/plugins/saved_search_so/tsconfig.json | 19 ++++++++++ tsconfig.base.json | 2 + yarn.lock | 4 ++ 17 files changed, 137 insertions(+), 8 deletions(-) create mode 100644 src/plugins/saved_search_so/README.md create mode 100644 src/plugins/saved_search_so/common/constants.ts create mode 100644 src/plugins/saved_search_so/common/index.ts create mode 100644 src/plugins/saved_search_so/jest.config.js create mode 100644 src/plugins/saved_search_so/kibana.jsonc create mode 100644 src/plugins/saved_search_so/server/index.ts create mode 100644 src/plugins/saved_search_so/server/plugin.ts rename src/plugins/{saved_search => saved_search_so}/server/saved_objects/index.ts (100%) rename src/plugins/{saved_search => saved_search_so}/server/saved_objects/schema.ts (100%) rename src/plugins/{saved_search => saved_search_so}/server/saved_objects/search.ts (100%) rename src/plugins/{saved_search => saved_search_so}/server/saved_objects/search_migrations.test.ts (100%) rename src/plugins/{saved_search => saved_search_so}/server/saved_objects/search_migrations.ts (98%) create mode 100644 src/plugins/saved_search_so/tsconfig.json diff --git a/package.json b/package.json index 8755f072d7b57..7140fe6dfebb9 100644 --- a/package.json +++ b/package.json @@ -651,6 +651,7 @@ "@kbn/saved-objects-tagging-oss-plugin": "link:src/plugins/saved_objects_tagging_oss", "@kbn/saved-objects-tagging-plugin": "link:x-pack/plugins/saved_objects_tagging", "@kbn/saved-search-plugin": "link:src/plugins/saved_search", + "@kbn/saved-search-so-plugin": "link:src/plugins/saved_search_so", "@kbn/screenshot-mode-example-plugin": "link:examples/screenshot_mode_example", "@kbn/screenshot-mode-plugin": "link:src/plugins/screenshot_mode", "@kbn/screenshotting-example-plugin": "link:x-pack/examples/screenshotting_example", diff --git a/src/plugins/saved_search/server/plugin.ts b/src/plugins/saved_search/server/plugin.ts index d09775442fd08..3ad969926d90b 100644 --- a/src/plugins/saved_search/server/plugin.ts +++ b/src/plugins/saved_search/server/plugin.ts @@ -14,7 +14,6 @@ import type { } from '@kbn/data-plugin/server'; import type { ContentManagementServerSetup } from '@kbn/content-management-plugin/server'; import { ExpressionsServerSetup } from '@kbn/expressions-plugin/server'; -import { getSavedSearchObjectType } from './saved_objects'; import { SavedSearchType, LATEST_VERSION } from '../common'; import { SavedSearchStorage } from './content_management'; import { kibanaContext } from '../common/expressions'; @@ -54,11 +53,6 @@ export class SavedSearchServerPlugin }, }); - const searchSource = data.search.searchSource; - - const getSearchSourceMigrations = searchSource.getAllMigrations.bind(searchSource); - core.savedObjects.registerType(getSavedSearchObjectType(getSearchSourceMigrations)); - expressions.registerType(kibanaContext); expressions.registerFunction( getKibanaContext(core.getStartServices as StartServicesAccessor) diff --git a/src/plugins/saved_search_so/README.md b/src/plugins/saved_search_so/README.md new file mode 100644 index 0000000000000..558bd619fd40c --- /dev/null +++ b/src/plugins/saved_search_so/README.md @@ -0,0 +1,3 @@ +# Saved search SO + +Contains the saved search saved object definition. diff --git a/src/plugins/saved_search_so/common/constants.ts b/src/plugins/saved_search_so/common/constants.ts new file mode 100644 index 0000000000000..7a943f9838fa1 --- /dev/null +++ b/src/plugins/saved_search_so/common/constants.ts @@ -0,0 +1,17 @@ +/* + * 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 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +// TODO: extract into a package? + +export const MIN_SAVED_SEARCH_SAMPLE_SIZE = 1; +export const MAX_SAVED_SEARCH_SAMPLE_SIZE = 10000; + +export enum VIEW_MODE { + DOCUMENT_LEVEL = 'documents', + AGGREGATED_LEVEL = 'aggregated', +} diff --git a/src/plugins/saved_search_so/common/index.ts b/src/plugins/saved_search_so/common/index.ts new file mode 100644 index 0000000000000..7faa35e48b305 --- /dev/null +++ b/src/plugins/saved_search_so/common/index.ts @@ -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 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +export { MIN_SAVED_SEARCH_SAMPLE_SIZE, MAX_SAVED_SEARCH_SAMPLE_SIZE, VIEW_MODE } from './constants'; diff --git a/src/plugins/saved_search_so/jest.config.js b/src/plugins/saved_search_so/jest.config.js new file mode 100644 index 0000000000000..6b3057569d3eb --- /dev/null +++ b/src/plugins/saved_search_so/jest.config.js @@ -0,0 +1,18 @@ +/* + * 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 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +module.exports = { + preset: '@kbn/test', + rootDir: '../../..', + roots: ['/src/plugins/saved_search_so'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/saved_search_so', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/src/plugins/saved_search_so/{common,public,server}/**/*.{js,ts,tsx}', + ], +}; diff --git a/src/plugins/saved_search_so/kibana.jsonc b/src/plugins/saved_search_so/kibana.jsonc new file mode 100644 index 0000000000000..98b443602ff20 --- /dev/null +++ b/src/plugins/saved_search_so/kibana.jsonc @@ -0,0 +1,15 @@ +{ + "type": "plugin", + "id": "@kbn/saved-search-so-plugin", + "owner": "@elastic/kibana-data-discovery", + "description": "This plugin contains 'search' SO definition", + "plugin": { + "id": "savedSearchSo", + "server": true, + "browser": false, + "requiredPlugins": ["data"], + "optionalPlugins": [], + "requiredBundles": [], + "extraPublicDirs": ["common"] + } +} diff --git a/src/plugins/saved_search_so/server/index.ts b/src/plugins/saved_search_so/server/index.ts new file mode 100644 index 0000000000000..62b857c90cad1 --- /dev/null +++ b/src/plugins/saved_search_so/server/index.ts @@ -0,0 +1,12 @@ +/* + * 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 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +export const plugin = async () => { + const { SavedSearchSOServerPlugin } = await import('./plugin'); + return new SavedSearchSOServerPlugin(); +}; diff --git a/src/plugins/saved_search_so/server/plugin.ts b/src/plugins/saved_search_so/server/plugin.ts new file mode 100644 index 0000000000000..51ef3566d8530 --- /dev/null +++ b/src/plugins/saved_search_so/server/plugin.ts @@ -0,0 +1,37 @@ +/* + * 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 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { CoreSetup, Plugin } from '@kbn/core/server'; +import type { PluginSetup as DataPluginSetup } from '@kbn/data-plugin/server'; +import { getSavedSearchObjectType } from './saved_objects'; + +/** + * Saved search SO plugin server Setup contract + */ +export interface SavedSearchSOPublicSetupDependencies { + data: DataPluginSetup; +} + +export class SavedSearchSOServerPlugin implements Plugin { + constructor() {} + + public setup(core: CoreSetup, { data }: SavedSearchSOPublicSetupDependencies) { + const searchSource = data.search.searchSource; + + const getSearchSourceMigrations = searchSource.getAllMigrations.bind(searchSource); + core.savedObjects.registerType(getSavedSearchObjectType(getSearchSourceMigrations)); + + return {}; + } + + public start() { + return {}; + } + + public stop() {} +} diff --git a/src/plugins/saved_search/server/saved_objects/index.ts b/src/plugins/saved_search_so/server/saved_objects/index.ts similarity index 100% rename from src/plugins/saved_search/server/saved_objects/index.ts rename to src/plugins/saved_search_so/server/saved_objects/index.ts diff --git a/src/plugins/saved_search/server/saved_objects/schema.ts b/src/plugins/saved_search_so/server/saved_objects/schema.ts similarity index 100% rename from src/plugins/saved_search/server/saved_objects/schema.ts rename to src/plugins/saved_search_so/server/saved_objects/schema.ts diff --git a/src/plugins/saved_search/server/saved_objects/search.ts b/src/plugins/saved_search_so/server/saved_objects/search.ts similarity index 100% rename from src/plugins/saved_search/server/saved_objects/search.ts rename to src/plugins/saved_search_so/server/saved_objects/search.ts diff --git a/src/plugins/saved_search/server/saved_objects/search_migrations.test.ts b/src/plugins/saved_search_so/server/saved_objects/search_migrations.test.ts similarity index 100% rename from src/plugins/saved_search/server/saved_objects/search_migrations.test.ts rename to src/plugins/saved_search_so/server/saved_objects/search_migrations.test.ts diff --git a/src/plugins/saved_search/server/saved_objects/search_migrations.ts b/src/plugins/saved_search_so/server/saved_objects/search_migrations.ts similarity index 98% rename from src/plugins/saved_search/server/saved_objects/search_migrations.ts rename to src/plugins/saved_search_so/server/saved_objects/search_migrations.ts index 911c9a9f93225..6d327db994451 100644 --- a/src/plugins/saved_search/server/saved_objects/search_migrations.ts +++ b/src/plugins/saved_search_so/server/saved_objects/search_migrations.ts @@ -6,8 +6,6 @@ * Side Public License, v 1. */ -// TODO: This needs to be removed and properly typed -/* eslint-disable @typescript-eslint/no-explicit-any */ import { flow, get, mapValues } from 'lodash'; import type { SavedObjectAttributes, diff --git a/src/plugins/saved_search_so/tsconfig.json b/src/plugins/saved_search_so/tsconfig.json new file mode 100644 index 0000000000000..e2025b326c197 --- /dev/null +++ b/src/plugins/saved_search_so/tsconfig.json @@ -0,0 +1,19 @@ +{ + "extends": "../../../tsconfig.base.json", + "compilerOptions": { + "outDir": "target/types", + }, + "include": [ + "common/**/*", + "public/**/*", + "server/**/*", + "../../../typings/**/*", + ], + "kbn_references": [ + "@kbn/core", + "@kbn/data-plugin", + ], + "exclude": [ + "target/**/*", + ] +} diff --git a/tsconfig.base.json b/tsconfig.base.json index a4f658e7acb62..6bee6bc4ee253 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -1296,6 +1296,8 @@ "@kbn/saved-objects-tagging-plugin/*": ["x-pack/plugins/saved_objects_tagging/*"], "@kbn/saved-search-plugin": ["src/plugins/saved_search"], "@kbn/saved-search-plugin/*": ["src/plugins/saved_search/*"], + "@kbn/saved-search-so-plugin": ["src/plugins/saved_search_so"], + "@kbn/saved-search-so-plugin/*": ["src/plugins/saved_search_so/*"], "@kbn/screenshot-mode-example-plugin": ["examples/screenshot_mode_example"], "@kbn/screenshot-mode-example-plugin/*": ["examples/screenshot_mode_example/*"], "@kbn/screenshot-mode-plugin": ["src/plugins/screenshot_mode"], diff --git a/yarn.lock b/yarn.lock index 45dce47febdcf..c1993817d46c8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5652,6 +5652,10 @@ version "0.0.0" uid "" +"@kbn/saved-search-so-plugin@link:src/plugins/saved_search_so": + version "0.0.0" + uid "" + "@kbn/screenshot-mode-example-plugin@link:examples/screenshot_mode_example": version "0.0.0" uid ""