Skip to content

Commit

Permalink
[Discover] Extract saved search SO into a separate plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
jughosta committed Jan 16, 2024
1 parent 692a8ca commit 1e33a59
Show file tree
Hide file tree
Showing 17 changed files with 137 additions and 8 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
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: 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.
17 changes: 17 additions & 0 deletions src/plugins/saved_search_so/common/constants.ts
Original file line number Diff line number Diff line change
@@ -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',
}
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": [],
"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
19 changes: 19 additions & 0 deletions src/plugins/saved_search_so/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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/**/*",
]
}
2 changes: 2 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down

0 comments on commit 1e33a59

Please sign in to comment.