Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Discover] Split saved search plugin v2 #174939

Closed
wants to merge 9 commits into from
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions docs/developer/plugin-list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 0 additions & 3 deletions src/plugins/saved_search/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

Expand Down
17 changes: 6 additions & 11 deletions src/plugins/saved_search/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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';
6 changes: 0 additions & 6 deletions src/plugins/saved_search/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<SavedSearchServerStartDeps>)
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/saved_search/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -33,6 +31,7 @@
"@kbn/core-plugins-server",
"@kbn/utility-types",
"@kbn/saved-objects-finder-plugin",
"@kbn/saved-search-so-plugin",
],
"exclude": [
"target/**/*",
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/saved_search_so/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Saved search SO

Contains the saved search saved object definition.
15 changes: 15 additions & 0 deletions src/plugins/saved_search_so/common/constants.ts
Original file line number Diff line number Diff line change
@@ -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',
}
9 changes: 9 additions & 0 deletions src/plugins/saved_search_so/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 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';
18 changes: 18 additions & 0 deletions src/plugins/saved_search_so/jest.config.js
Original file line number Diff line number Diff line change
@@ -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: ['<rootDir>/src/plugins/saved_search_so'],
coverageDirectory: '<rootDir>/target/kibana-coverage/jest/src/plugins/saved_search_so',
coverageReporters: ['text', 'html'],
collectCoverageFrom: [
'<rootDir>/src/plugins/saved_search_so/{common,public,server}/**/*.{js,ts,tsx}',
],
};
15 changes: 15 additions & 0 deletions src/plugins/saved_search_so/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -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"],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kibana starts without errors. Seems to be this circular dependency is resolved.

"requiredBundles": [],
"extraPublicDirs": ["common"]
}
}
12 changes: 12 additions & 0 deletions src/plugins/saved_search_so/server/index.ts
Original file line number Diff line number Diff line change
@@ -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();
};
37 changes: 37 additions & 0 deletions src/plugins/saved_search_so/server/plugin.ts
Original file line number Diff line number Diff line change
@@ -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<object, object, object> {
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() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 23 additions & 0 deletions src/plugins/saved_search_so/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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/**/*",
]
}
2 changes: 2 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down