diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index dcfce13388c7..872b7b34ae77 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -662,6 +662,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 diff --git a/docs/developer/plugin-list.asciidoc b/docs/developer/plugin-list.asciidoc index 3eccd4beaeda..a2f2da5d0db6 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. diff --git a/package.json b/package.json index ccd5182e04a5..d6fa3701ceff 100644 --- a/package.json +++ b/package.json @@ -665,6 +665,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/common/constants.ts b/src/plugins/saved_search/common/constants.ts index a980bd40e3e2..57e3cfff51eb 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 0cbbe69c4bfe..641b203f0676 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 0ac92232fb3b..47ed071e7b08 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/server/plugin.ts b/src/plugins/saved_search/server/plugin.ts index d09775442fd0..3ad969926d90 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/tsconfig.json b/src/plugins/saved_search/tsconfig.json index c4ea0eaf4d5b..8c17ee85b081 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", @@ -33,6 +31,7 @@ "@kbn/core-plugins-server", "@kbn/utility-types", "@kbn/saved-objects-finder-plugin", + "@kbn/saved-search-so-plugin", ], "exclude": [ "target/**/*", diff --git a/src/plugins/saved_search_so/README.md b/src/plugins/saved_search_so/README.md new file mode 100644 index 000000000000..558bd619fd40 --- /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 000000000000..aa7387516bb6 --- /dev/null +++ b/src/plugins/saved_search_so/common/constants.ts @@ -0,0 +1,15 @@ +/* + * 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 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 000000000000..7faa35e48b30 --- /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 000000000000..6b3057569d3e --- /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 000000000000..1cc48ca56073 --- /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": ["lens"], + "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 000000000000..62b857c90cad --- /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 000000000000..51ef3566d853 --- /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 911c9a9f9322..6d327db99445 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 000000000000..f4080e5a29d7 --- /dev/null +++ b/src/plugins/saved_search_so/tsconfig.json @@ -0,0 +1,23 @@ +{ + "extends": "../../../tsconfig.base.json", + "compilerOptions": { + "outDir": "target/types", + }, + "include": [ + "common/**/*", + "public/**/*", + "server/**/*", + "../../../typings/**/*", + ], + "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/**/*", + ] +} diff --git a/tsconfig.base.json b/tsconfig.base.json index bb1f7b787702..2a92d90d8e94 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -1318,6 +1318,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 d75766cfa5b0..c79a82b54eaa 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5700,6 +5700,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 ""