From 1e33a59363872b42e37675160aa9d02d1a893776 Mon Sep 17 00:00:00 2001 From: Julia Rechkunova Date: Tue, 16 Jan 2024 16:32:35 +0100 Subject: [PATCH 1/7] [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 "" From 46b424bd293de5bc2b1061f6606a73eab17cbd24 Mon Sep 17 00:00:00 2001 From: Julia Rechkunova Date: Tue, 16 Jan 2024 17:17:46 +0100 Subject: [PATCH 2/7] [Discover] Try to reference Lens --- src/plugins/saved_search_so/kibana.jsonc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/saved_search_so/kibana.jsonc b/src/plugins/saved_search_so/kibana.jsonc index 98b443602ff20..1cc48ca56073d 100644 --- a/src/plugins/saved_search_so/kibana.jsonc +++ b/src/plugins/saved_search_so/kibana.jsonc @@ -8,7 +8,7 @@ "server": true, "browser": false, "requiredPlugins": ["data"], - "optionalPlugins": [], + "optionalPlugins": ["lens"], "requiredBundles": [], "extraPublicDirs": ["common"] } From fbf691094361aaa9b51eba48625dbce5e01b00a8 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 16 Jan 2024 19:21:26 +0000 Subject: [PATCH 3/7] [CI] Auto-commit changed files from 'node scripts/lint_ts_projects --fix' --- src/plugins/saved_search/tsconfig.json | 2 -- src/plugins/saved_search_so/tsconfig.json | 4 ++++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/plugins/saved_search/tsconfig.json b/src/plugins/saved_search/tsconfig.json index b1aa1679469ee..33b000e5f6ece 100644 --- a/src/plugins/saved_search/tsconfig.json +++ b/src/plugins/saved_search/tsconfig.json @@ -12,13 +12,11 @@ "kbn_references": [ "@kbn/core", "@kbn/data-plugin", - "@kbn/kibana-utils-plugin", "@kbn/spaces-plugin", "@kbn/saved-objects-tagging-oss-plugin", "@kbn/i18n", "@kbn/config-schema", "@kbn/core-saved-objects-server", - "@kbn/core-saved-objects-utils-server", "@kbn/object-versioning", "@kbn/content-management-utils", "@kbn/content-management-plugin", diff --git a/src/plugins/saved_search_so/tsconfig.json b/src/plugins/saved_search_so/tsconfig.json index e2025b326c197..f4080e5a29d73 100644 --- a/src/plugins/saved_search_so/tsconfig.json +++ b/src/plugins/saved_search_so/tsconfig.json @@ -12,6 +12,10 @@ "kbn_references": [ "@kbn/core", "@kbn/data-plugin", + "@kbn/config-schema", + "@kbn/core-saved-objects-server", + "@kbn/kibana-utils-plugin", + "@kbn/core-saved-objects-utils-server", ], "exclude": [ "target/**/*", From 6450c58982d0dca9c7b521c2a68cb5faada11fd9 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 16 Jan 2024 19:43:58 +0000 Subject: [PATCH 4/7] [CI] Auto-commit changed files from 'node scripts/generate codeowners' --- .github/CODEOWNERS | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index d737589ccd9ef..868186dfecef0 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -651,6 +651,7 @@ packages/kbn-saved-objects-settings @elastic/appex-sharedux src/plugins/saved_objects_tagging_oss @elastic/appex-sharedux x-pack/plugins/saved_objects_tagging @elastic/appex-sharedux src/plugins/saved_search @elastic/kibana-data-discovery +src/plugins/saved_search_so @elastic/kibana-data-discovery examples/screenshot_mode_example @elastic/appex-sharedux src/plugins/screenshot_mode @elastic/appex-sharedux x-pack/examples/screenshotting_example @elastic/appex-sharedux From ef7a1ea542f5c9d5162c6e1e9b73838251c8b7f2 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 30 Jan 2024 10:09:50 +0000 Subject: [PATCH 5/7] [CI] Auto-commit changed files from 'node scripts/build_plugin_list_docs' --- docs/developer/plugin-list.asciidoc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/developer/plugin-list.asciidoc b/docs/developer/plugin-list.asciidoc index fe9a0d40f5d23..84cf4e7f04ba1 100644 --- a/docs/developer/plugin-list.asciidoc +++ b/docs/developer/plugin-list.asciidoc @@ -303,6 +303,10 @@ oss plugins. |Contains the saved search saved object definition and helpers. +|{kib-repo}blob/{branch}/src/plugins/saved_search_so/README.md[savedSearchSo] +|Contains the saved search saved object definition. + + |{kib-repo}blob/{branch}/src/plugins/screenshot_mode/README.md[screenshotMode] |The service exposed by this plugin informs consumers whether they should optimize for non-interactivity. In this way plugins can avoid loading unnecessary code, data or other services. From 4bd7a3d74388df391ca68cb76b4b95fbdbe17aae Mon Sep 17 00:00:00 2001 From: Julia Rechkunova Date: Thu, 8 Feb 2024 14:00:13 +0100 Subject: [PATCH 6/7] [Discover] Rearrange consts --- src/plugins/saved_search/common/constants.ts | 3 --- .../common/content_management/v1/cm_services.ts | 5 ++++- src/plugins/saved_search/common/index.ts | 17 ++++++----------- src/plugins/saved_search_so/common/constants.ts | 2 -- 4 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/plugins/saved_search/common/constants.ts b/src/plugins/saved_search/common/constants.ts index a980bd40e3e26..57e3cfff51ebb 100644 --- a/src/plugins/saved_search/common/constants.ts +++ b/src/plugins/saved_search/common/constants.ts @@ -10,7 +10,4 @@ export const SavedSearchType = 'search'; export const LATEST_VERSION = 1; -export const MIN_SAVED_SEARCH_SAMPLE_SIZE = 1; -export const MAX_SAVED_SEARCH_SAMPLE_SIZE = 10000; - export type SavedSearchContentType = typeof SavedSearchType; diff --git a/src/plugins/saved_search/common/content_management/v1/cm_services.ts b/src/plugins/saved_search/common/content_management/v1/cm_services.ts index 0cbbe69c4bfeb..641b203f0676d 100644 --- a/src/plugins/saved_search/common/content_management/v1/cm_services.ts +++ b/src/plugins/saved_search/common/content_management/v1/cm_services.ts @@ -15,7 +15,10 @@ import { updateOptionsSchema, createResultSchema, } from '@kbn/content-management-utils'; -import { MIN_SAVED_SEARCH_SAMPLE_SIZE, MAX_SAVED_SEARCH_SAMPLE_SIZE } from '../../constants'; +import { + MIN_SAVED_SEARCH_SAMPLE_SIZE, + MAX_SAVED_SEARCH_SAMPLE_SIZE, +} from '@kbn/saved-search-so-plugin/common'; const sortSchema = schema.arrayOf(schema.string(), { maxSize: 2 }); diff --git a/src/plugins/saved_search/common/index.ts b/src/plugins/saved_search/common/index.ts index 0ac92232fb3b8..47ed071e7b085 100644 --- a/src/plugins/saved_search/common/index.ts +++ b/src/plugins/saved_search/common/index.ts @@ -6,6 +6,11 @@ * Side Public License, v 1. */ +export { + VIEW_MODE, + MIN_SAVED_SEARCH_SAMPLE_SIZE, + MAX_SAVED_SEARCH_SAMPLE_SIZE, +} from '@kbn/saved-search-so-plugin/common'; export { getSavedSearchUrl, getSavedSearchFullPathUrl } from './saved_searches_url'; export { fromSavedSearchAttributes } from './saved_searches_utils'; @@ -16,15 +21,5 @@ export type { SavedSearchAttributes, } from './types'; -export enum VIEW_MODE { - DOCUMENT_LEVEL = 'documents', - AGGREGATED_LEVEL = 'aggregated', -} - -export { - SavedSearchType, - LATEST_VERSION, - MIN_SAVED_SEARCH_SAMPLE_SIZE, - MAX_SAVED_SEARCH_SAMPLE_SIZE, -} from './constants'; +export { SavedSearchType, LATEST_VERSION } from './constants'; export { getKibanaContextFn } from './expressions/kibana_context'; diff --git a/src/plugins/saved_search_so/common/constants.ts b/src/plugins/saved_search_so/common/constants.ts index 7a943f9838fa1..aa7387516bb6b 100644 --- a/src/plugins/saved_search_so/common/constants.ts +++ b/src/plugins/saved_search_so/common/constants.ts @@ -6,8 +6,6 @@ * 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; From f7ec1544f40a0e6b4024c9736977618d5e0bb194 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Thu, 8 Feb 2024 13:11:19 +0000 Subject: [PATCH 7/7] [CI] Auto-commit changed files from 'node scripts/lint_ts_projects --fix' --- src/plugins/saved_search/tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/src/plugins/saved_search/tsconfig.json b/src/plugins/saved_search/tsconfig.json index 05e37ffa997ce..8c17ee85b081e 100644 --- a/src/plugins/saved_search/tsconfig.json +++ b/src/plugins/saved_search/tsconfig.json @@ -31,6 +31,7 @@ "@kbn/core-plugins-server", "@kbn/utility-types", "@kbn/saved-objects-finder-plugin", + "@kbn/saved-search-so-plugin", ], "exclude": [ "target/**/*",