From fc999e5158ebe737c48b0e074a33a0fca6500d6d Mon Sep 17 00:00:00 2001 From: Gidi Meir Morris Date: Fri, 20 Dec 2019 16:33:10 +0000 Subject: [PATCH 01/14] [Alerting] disables a flaky test in alerting (#53696) * disabled flaky test * use skip instead of comment --- .../security_and_spaces/tests/alerting/alerts.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/alerts.ts b/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/alerts.ts index b168cffe281a0..69bc547e3bfc1 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/alerts.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/alerts.ts @@ -601,7 +601,16 @@ export default function alertTests({ getService }: FtrProviderContext) { } }); - it(`shouldn't schedule actions when alert is muted`, async () => { + /** + * Skipping due to an issue we've discovered in the `muteAll` api + * which corrupts the apiKey and causes this test to exhibit flaky behaviour. + * Failed CIs for example: + * 1. https://github.com/elastic/kibana/issues/53690 + * 2. https://github.com/elastic/kibana/issues/53683 + * + * This will be fixed and reverted in PR: https://github.com/elastic/kibana/pull/53333 + */ + it.skip(`shouldn't schedule actions when alert is muted`, async () => { const testStart = new Date(); const reference = alertUtils.generateReference(); const response = await alertUtils.createAlwaysFiringAction({ From ec4fca66dd81391427babc795c59d8bda03ae69f Mon Sep 17 00:00:00 2001 From: Benjamin Trent Date: Fri, 20 Dec 2019 12:14:46 -0500 Subject: [PATCH 02/14] Add ml inference processor and APIs to console (#53618) Adds new Machine Learning Inference processor to Kibana Console. Also adds new Inference APIs generated from ES specs. --- .../generated/ml.delete_trained_model.json | 11 +++++++ .../spec/generated/ml.get_trained_models.json | 19 ++++++++++++ .../ml.get_trained_models_stats.json | 17 ++++++++++ .../console_extensions/spec/ingest/index.js | 31 ++++++++++++++++++- 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 x-pack/legacy/plugins/console_extensions/spec/generated/ml.delete_trained_model.json create mode 100644 x-pack/legacy/plugins/console_extensions/spec/generated/ml.get_trained_models.json create mode 100644 x-pack/legacy/plugins/console_extensions/spec/generated/ml.get_trained_models_stats.json diff --git a/x-pack/legacy/plugins/console_extensions/spec/generated/ml.delete_trained_model.json b/x-pack/legacy/plugins/console_extensions/spec/generated/ml.delete_trained_model.json new file mode 100644 index 0000000000000..343fa904c4216 --- /dev/null +++ b/x-pack/legacy/plugins/console_extensions/spec/generated/ml.delete_trained_model.json @@ -0,0 +1,11 @@ +{ + "ml.delete_trained_model": { + "methods": [ + "DELETE" + ], + "patterns": [ + "_ml/inference/{model_id}" + ], + "documentation": "https://www.elastic.co/guide/en/elasticsearch/reference/current/delete-inference.html" + } +} diff --git a/x-pack/legacy/plugins/console_extensions/spec/generated/ml.get_trained_models.json b/x-pack/legacy/plugins/console_extensions/spec/generated/ml.get_trained_models.json new file mode 100644 index 0000000000000..cdeaca9654b77 --- /dev/null +++ b/x-pack/legacy/plugins/console_extensions/spec/generated/ml.get_trained_models.json @@ -0,0 +1,19 @@ +{ + "ml.get_trained_models": { + "url_params": { + "allow_no_match": "__flag__", + "include_model_definition": "__flag__", + "decompress_definition": "__flag__", + "from": 0, + "size": 0 + }, + "methods": [ + "GET" + ], + "patterns": [ + "_ml/inference/{model_id}", + "_ml/inference" + ], + "documentation": "https://www.elastic.co/guide/en/elasticsearch/reference/current/get-inference.html" + } +} diff --git a/x-pack/legacy/plugins/console_extensions/spec/generated/ml.get_trained_models_stats.json b/x-pack/legacy/plugins/console_extensions/spec/generated/ml.get_trained_models_stats.json new file mode 100644 index 0000000000000..ab05e203b3980 --- /dev/null +++ b/x-pack/legacy/plugins/console_extensions/spec/generated/ml.get_trained_models_stats.json @@ -0,0 +1,17 @@ +{ + "ml.get_trained_models_stats": { + "url_params": { + "allow_no_match": "__flag__", + "from": 0, + "size": 0 + }, + "methods": [ + "GET" + ], + "patterns": [ + "_ml/inference/{model_id}/_stats", + "_ml/inference/_stats" + ], + "documentation": "https://www.elastic.co/guide/en/elasticsearch/reference/current/get-inference-stats.html" + } +} diff --git a/x-pack/legacy/plugins/console_extensions/spec/ingest/index.js b/x-pack/legacy/plugins/console_extensions/spec/ingest/index.js index f5ca413e5e2e1..def311a6baf59 100644 --- a/x-pack/legacy/plugins/console_extensions/spec/ingest/index.js +++ b/x-pack/legacy/plugins/console_extensions/spec/ingest/index.js @@ -37,4 +37,33 @@ const enrichProcessorDefinition = { }, }; -export const processors = [enrichProcessorDefinition]; +// Based on https://www.elastic.co/guide/en/elasticsearch/reference/master/inference-processor.html +const inferenceProcessorDefinition = { + inference: { + __template: { + model_id: '', + inference_config: {}, + field_mappings: {}, + }, + target_field: '', + model_id: '', + field_mappings: { + __template: {}, + }, + inference_config: { + regression: { + __template: {}, + results_field: '', + }, + classification: { + __template: {}, + results_field: '', + num_top_classes: 2, + top_classes_results_field: '', + }, + }, + ...commonPipelineParams, + }, +}; + +export const processors = [enrichProcessorDefinition, inferenceProcessorDefinition]; From e5822771e30b4329ec64ddbb062ff05baae03c44 Mon Sep 17 00:00:00 2001 From: Aleh Zasypkin Date: Fri, 20 Dec 2019 18:42:42 +0100 Subject: [PATCH 03/14] Use `savedObjects` provided by the platform instead of legacy shim. (#53679) --- x-pack/legacy/plugins/security/index.js | 1 - .../server/audit/audit_logger.test.ts | 4 +- .../security/server/audit/audit_logger.ts | 6 +- x-pack/plugins/security/server/plugin.ts | 21 +++---- .../security/server/saved_objects/index.ts | 57 +++++++------------ 5 files changed, 34 insertions(+), 55 deletions(-) diff --git a/x-pack/legacy/plugins/security/index.js b/x-pack/legacy/plugins/security/index.js index e505a8fb55d90..6ee8b5f8b2b10 100644 --- a/x-pack/legacy/plugins/security/index.js +++ b/x-pack/legacy/plugins/security/index.js @@ -130,7 +130,6 @@ export const security = kibana => const config = server.config(); const xpackInfo = server.plugins.xpack_main.info; securityPlugin.__legacyCompat.registerLegacyAPI({ - savedObjects: server.savedObjects, auditLogger: new AuditLogger(server, 'security', config, xpackInfo), isSystemAPIRequest: server.plugins.kibana.systemApi.isSystemApiRequest.bind( server.plugins.kibana.systemApi diff --git a/x-pack/plugins/security/server/audit/audit_logger.test.ts b/x-pack/plugins/security/server/audit/audit_logger.test.ts index 2ae8b6762c5d4..01cde02b7dfdd 100644 --- a/x-pack/plugins/security/server/audit/audit_logger.test.ts +++ b/x-pack/plugins/security/server/audit/audit_logger.test.ts @@ -14,7 +14,7 @@ const createMockAuditLogger = () => { describe(`#savedObjectsAuthorizationFailure`, () => { test('logs via auditLogger', () => { const auditLogger = createMockAuditLogger(); - const securityAuditLogger = new SecurityAuditLogger(auditLogger); + const securityAuditLogger = new SecurityAuditLogger(() => auditLogger); const username = 'foo-user'; const action = 'foo-action'; const types = ['foo-type-1', 'foo-type-2']; @@ -43,7 +43,7 @@ describe(`#savedObjectsAuthorizationFailure`, () => { describe(`#savedObjectsAuthorizationSuccess`, () => { test('logs via auditLogger when xpack.security.audit.enabled is true', () => { const auditLogger = createMockAuditLogger(); - const securityAuditLogger = new SecurityAuditLogger(auditLogger); + const securityAuditLogger = new SecurityAuditLogger(() => auditLogger); const username = 'foo-user'; const action = 'foo-action'; const types = ['foo-type-1', 'foo-type-2']; diff --git a/x-pack/plugins/security/server/audit/audit_logger.ts b/x-pack/plugins/security/server/audit/audit_logger.ts index 4c2c57d0e029e..df8df35f97b49 100644 --- a/x-pack/plugins/security/server/audit/audit_logger.ts +++ b/x-pack/plugins/security/server/audit/audit_logger.ts @@ -7,7 +7,7 @@ import { LegacyAPI } from '../plugin'; export class SecurityAuditLogger { - constructor(private readonly auditLogger: LegacyAPI['auditLogger']) {} + constructor(private readonly getAuditLogger: () => LegacyAPI['auditLogger']) {} savedObjectsAuthorizationFailure( username: string, @@ -16,7 +16,7 @@ export class SecurityAuditLogger { missing: string[], args?: Record ) { - this.auditLogger.log( + this.getAuditLogger().log( 'saved_objects_authorization_failure', `${username} unauthorized to ${action} ${types.join(',')}, missing ${missing.join(',')}`, { @@ -35,7 +35,7 @@ export class SecurityAuditLogger { types: string[], args?: Record ) { - this.auditLogger.log( + this.getAuditLogger().log( 'saved_objects_authorization_success', `${username} authorized to ${action} ${types.join(',')}`, { diff --git a/x-pack/plugins/security/server/plugin.ts b/x-pack/plugins/security/server/plugin.ts index 14dd1e6ac00d3..cdd2a024310bb 100644 --- a/x-pack/plugins/security/server/plugin.ts +++ b/x-pack/plugins/security/server/plugin.ts @@ -13,8 +13,6 @@ import { Logger, PluginInitializerContext, RecursiveReadonly, - SavedObjectsLegacyService, - LegacyRequest, } from '../../../../src/core/server'; import { deepFreeze } from '../../../../src/core/utils'; import { SpacesPluginSetup } from '../../spaces/server'; @@ -43,7 +41,6 @@ export type FeaturesService = Pick; */ export interface LegacyAPI { isSystemAPIRequest: (request: KibanaRequest) => boolean; - savedObjects: SavedObjectsLegacyService; auditLogger: { log: (eventType: string, message: string, data?: Record) => void; }; @@ -153,6 +150,12 @@ export class Plugin { featuresService: features, }); + setupSavedObjects({ + auditLogger: new SecurityAuditLogger(() => this.getLegacyAPI().auditLogger), + authz, + savedObjects: core.savedObjects, + }); + core.capabilities.registerSwitcher(authz.disableUnauthorizedCapabilities); defineRoutes({ @@ -166,7 +169,6 @@ export class Plugin { csp: core.http.csp, }); - const adminClient = await core.elasticsearch.adminClient$.pipe(first()).toPromise(); return deepFreeze({ authc, @@ -185,16 +187,7 @@ export class Plugin { }, __legacyCompat: { - registerLegacyAPI: (legacyAPI: LegacyAPI) => { - this.legacyAPI = legacyAPI; - - setupSavedObjects({ - auditLogger: new SecurityAuditLogger(legacyAPI.auditLogger), - adminClusterClient: adminClient, - authz, - legacyAPI, - }); - }, + registerLegacyAPI: (legacyAPI: LegacyAPI) => (this.legacyAPI = legacyAPI), registerPrivilegesWithCluster: async () => await authz.registerPrivilegesWithCluster(), diff --git a/x-pack/plugins/security/server/saved_objects/index.ts b/x-pack/plugins/security/server/saved_objects/index.ts index 2bd7440d3ee70..556dc4fda85cf 100644 --- a/x-pack/plugins/security/server/saved_objects/index.ts +++ b/x-pack/plugins/security/server/saved_objects/index.ts @@ -4,60 +4,47 @@ * you may not use this file except in compliance with the Elastic License. */ -import { IClusterClient, KibanaRequest, LegacyRequest } from '../../../../../src/core/server'; +import { + CoreSetup, + KibanaRequest, + LegacyRequest, + SavedObjectsClient, +} from '../../../../../src/core/server'; import { SecureSavedObjectsClientWrapper } from './secure_saved_objects_client_wrapper'; -import { LegacyAPI } from '../plugin'; import { Authorization } from '../authorization'; import { SecurityAuditLogger } from '../audit'; interface SetupSavedObjectsParams { - adminClusterClient: IClusterClient; auditLogger: SecurityAuditLogger; authz: Pick; - legacyAPI: Pick; + savedObjects: CoreSetup['savedObjects']; } -export function setupSavedObjects({ - adminClusterClient, - auditLogger, - authz, - legacyAPI: { savedObjects }, -}: SetupSavedObjectsParams) { +export function setupSavedObjects({ auditLogger, authz, savedObjects }: SetupSavedObjectsParams) { const getKibanaRequest = (request: KibanaRequest | LegacyRequest) => request instanceof KibanaRequest ? request : KibanaRequest.from(request); - savedObjects.setScopedSavedObjectsClientFactory(({ request }) => { - const kibanaRequest = getKibanaRequest(request); - if (authz.mode.useRbacForRequest(kibanaRequest)) { - const internalRepository = savedObjects.getSavedObjectsRepository( - adminClusterClient.callAsInternalUser - ); - return new savedObjects.SavedObjectsClient(internalRepository); - } - const callAsCurrentUserRepository = savedObjects.getSavedObjectsRepository( - adminClusterClient.asScoped(kibanaRequest).callAsCurrentUser + savedObjects.setClientFactory(({ request }) => { + const kibanaRequest = getKibanaRequest(request); + return new SavedObjectsClient( + authz.mode.useRbacForRequest(kibanaRequest) + ? savedObjects.createInternalRepository() + : savedObjects.createScopedRepository(kibanaRequest) ); - return new savedObjects.SavedObjectsClient(callAsCurrentUserRepository); }); - savedObjects.addScopedSavedObjectsClientWrapperFactory( - Number.MAX_SAFE_INTEGER - 1, - 'security', - ({ client, request }) => { - const kibanaRequest = getKibanaRequest(request); - if (authz.mode.useRbacForRequest(kibanaRequest)) { - return new SecureSavedObjectsClientWrapper({ + savedObjects.addClientWrapper(Number.MAX_SAFE_INTEGER - 1, 'security', ({ client, request }) => { + const kibanaRequest = getKibanaRequest(request); + return authz.mode.useRbacForRequest(kibanaRequest) + ? new SecureSavedObjectsClientWrapper({ actions: authz.actions, auditLogger, baseClient: client, checkSavedObjectsPrivilegesAsCurrentUser: authz.checkSavedObjectsPrivilegesWithRequest( kibanaRequest ), - errors: savedObjects.SavedObjectsClient.errors, - }); - } - - return client; - } - ); + errors: SavedObjectsClient.errors, + }) + : client; + }); } From 3bdbcd0d1a1a2a44bef3e006c6b596a282ea11c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Fern=C3=A1ndez=20Haro?= Date: Fri, 20 Dec 2019 17:53:08 +0000 Subject: [PATCH 04/14] [NP] Allow custom validations in HTTP Routes apart from @kbn/config-schema (#51919) * [NP] Allow custom validations in HTTP Routes apart from @kbn/config-schema * API docs * Allow validate function in the route handler (run-code validation) * Prefix RouteXXX + Params and Body Validation Aliases * Fix test broken by lodash * Update API docs * Add default types for simpler manual declaration * Add run-time validation of the RouteValidateSpec * Expose RouteValidationError instead of SchemaTypeError * RouteValidator as a class to match config-schema interface * Test for not-inline handler (need to check IRouter for #47047) * Add preValidation of the input for a safer custom validation * Better types for RouteHandlers * [NP] Move route validation to RouteValidator wrapper * Use the class only internally but maintain the same API * Fix types * Ensure RouteValidator instance in KibanaRequest.from * Fix validator.tests (Buffer.from instead of new Buffer) * Default precheck should allow null values * Also allow undefined in preChecks * MR feedback fixes * Provide RouteValidationResolver to the validation function * Add functional tests * Fix new functional tests * Fix validator additional test * Fix test with new resolver * Remove unused import * Rename ValidationResolver to ValidationResultFactory and change the interface to look more like the KibanaResponseFactory Co-authored-by: Elastic Machine --- ...lugin-server.irouter.handlelegacyerrors.md | 2 +- .../server/kibana-plugin-server.irouter.md | 2 +- .../core/server/kibana-plugin-server.md | 8 +- .../kibana-plugin-server.requesthandler.md | 2 +- .../kibana-plugin-server.routeconfig.md | 4 +- ...bana-plugin-server.routeconfig.validate.md | 2 +- .../kibana-plugin-server.routeregistrar.md | 2 +- .../kibana-plugin-server.routeschemas.body.md | 11 - .../kibana-plugin-server.routeschemas.md | 22 -- ...ibana-plugin-server.routeschemas.params.md | 11 - ...kibana-plugin-server.routeschemas.query.md | 11 - ...rver.routevalidationerror._constructor_.md | 21 ++ ...bana-plugin-server.routevalidationerror.md | 20 ++ ...a-plugin-server.routevalidationfunction.md | 42 +++ ...routevalidationresultfactory.badrequest.md | 13 + ...gin-server.routevalidationresultfactory.md | 23 ++ ...-server.routevalidationresultfactory.ok.md | 13 + ...ibana-plugin-server.routevalidationspec.md | 15 + ...plugin-server.routevalidatorconfig.body.md | 13 + ...bana-plugin-server.routevalidatorconfig.md | 22 ++ ...ugin-server.routevalidatorconfig.params.md | 13 + ...lugin-server.routevalidatorconfig.query.md | 13 + ...-plugin-server.routevalidatorfullconfig.md | 13 + ...ana-plugin-server.routevalidatoroptions.md | 20 ++ ...gin-server.routevalidatoroptions.unsafe.md | 17 ++ packages/kbn-config-schema/src/index.ts | 1 + src/core/server/http/http_server.mocks.ts | 2 +- src/core/server/http/http_server.test.ts | 233 ++++++++++++++- src/core/server/http/index.ts | 8 +- .../http/integration_tests/router.test.ts | 110 +++++++ src/core/server/http/router/error_wrapper.ts | 5 +- src/core/server/http/router/index.ts | 11 +- src/core/server/http/router/request.test.ts | 53 ++++ src/core/server/http/router/request.ts | 58 ++-- src/core/server/http/router/route.ts | 27 +- src/core/server/http/router/router.test.ts | 10 +- src/core/server/http/router/router.ts | 92 ++---- .../server/http/router/validator/index.ts | 29 ++ .../http/router/validator/validator.test.ts | 135 +++++++++ .../server/http/router/validator/validator.ts | 280 ++++++++++++++++++ .../http/router/validator/validator_error.ts | 34 +++ src/core/server/index.ts | 8 +- src/core/server/server.api.md | 63 +++- .../tutorials/lib/tutorials_registry_types.ts | 14 +- .../plugins/core_plugin_b/server/plugin.ts | 20 ++ .../core_plugins/server_plugins.ts | 24 ++ .../apm/server/routes/create_api/index.ts | 2 +- .../lib/adapters/framework/adapter_types.ts | 8 +- .../framework/kibana_framework_adapter.ts | 9 +- .../server/routes/catch_error_handler.ts | 7 +- .../register_privileges_with_cluster.test.ts | 2 +- .../server/routes/authentication/saml.ts | 4 +- .../routes/authorization/roles/delete.ts | 4 +- .../server/routes/authorization/roles/get.ts | 4 +- .../server/routes/licensed_route_handler.ts | 11 +- .../routes/api/external/copy_to_space.test.ts | 27 +- .../server/routes/api/external/delete.test.ts | 11 +- .../server/routes/api/external/post.test.ts | 9 +- .../server/routes/api/external/put.test.ts | 9 +- .../routes/lib/licensed_route_handler.ts | 11 +- 60 files changed, 1369 insertions(+), 301 deletions(-) delete mode 100644 docs/development/core/server/kibana-plugin-server.routeschemas.body.md delete mode 100644 docs/development/core/server/kibana-plugin-server.routeschemas.md delete mode 100644 docs/development/core/server/kibana-plugin-server.routeschemas.params.md delete mode 100644 docs/development/core/server/kibana-plugin-server.routeschemas.query.md create mode 100644 docs/development/core/server/kibana-plugin-server.routevalidationerror._constructor_.md create mode 100644 docs/development/core/server/kibana-plugin-server.routevalidationerror.md create mode 100644 docs/development/core/server/kibana-plugin-server.routevalidationfunction.md create mode 100644 docs/development/core/server/kibana-plugin-server.routevalidationresultfactory.badrequest.md create mode 100644 docs/development/core/server/kibana-plugin-server.routevalidationresultfactory.md create mode 100644 docs/development/core/server/kibana-plugin-server.routevalidationresultfactory.ok.md create mode 100644 docs/development/core/server/kibana-plugin-server.routevalidationspec.md create mode 100644 docs/development/core/server/kibana-plugin-server.routevalidatorconfig.body.md create mode 100644 docs/development/core/server/kibana-plugin-server.routevalidatorconfig.md create mode 100644 docs/development/core/server/kibana-plugin-server.routevalidatorconfig.params.md create mode 100644 docs/development/core/server/kibana-plugin-server.routevalidatorconfig.query.md create mode 100644 docs/development/core/server/kibana-plugin-server.routevalidatorfullconfig.md create mode 100644 docs/development/core/server/kibana-plugin-server.routevalidatoroptions.md create mode 100644 docs/development/core/server/kibana-plugin-server.routevalidatoroptions.unsafe.md create mode 100644 src/core/server/http/router/validator/index.ts create mode 100644 src/core/server/http/router/validator/validator.test.ts create mode 100644 src/core/server/http/router/validator/validator.ts create mode 100644 src/core/server/http/router/validator/validator_error.ts diff --git a/docs/development/core/server/kibana-plugin-server.irouter.handlelegacyerrors.md b/docs/development/core/server/kibana-plugin-server.irouter.handlelegacyerrors.md index 2367420068064..ff71f13466cf8 100644 --- a/docs/development/core/server/kibana-plugin-server.irouter.handlelegacyerrors.md +++ b/docs/development/core/server/kibana-plugin-server.irouter.handlelegacyerrors.md @@ -9,5 +9,5 @@ Wrap a router handler to catch and converts legacy boom errors to proper custom Signature: ```typescript -handleLegacyErrors:

(handler: RequestHandler) => RequestHandler; +handleLegacyErrors: (handler: RequestHandler) => RequestHandler; ``` diff --git a/docs/development/core/server/kibana-plugin-server.irouter.md b/docs/development/core/server/kibana-plugin-server.irouter.md index 73e96191e02e7..a6536d2ed6763 100644 --- a/docs/development/core/server/kibana-plugin-server.irouter.md +++ b/docs/development/core/server/kibana-plugin-server.irouter.md @@ -18,7 +18,7 @@ export interface IRouter | --- | --- | --- | | [delete](./kibana-plugin-server.irouter.delete.md) | RouteRegistrar<'delete'> | Register a route handler for DELETE request. | | [get](./kibana-plugin-server.irouter.get.md) | RouteRegistrar<'get'> | Register a route handler for GET request. | -| [handleLegacyErrors](./kibana-plugin-server.irouter.handlelegacyerrors.md) | <P extends ObjectType, Q extends ObjectType, B extends ObjectType>(handler: RequestHandler<P, Q, B>) => RequestHandler<P, Q, B> | Wrap a router handler to catch and converts legacy boom errors to proper custom errors. | +| [handleLegacyErrors](./kibana-plugin-server.irouter.handlelegacyerrors.md) | <P, Q, B>(handler: RequestHandler<P, Q, B>) => RequestHandler<P, Q, B> | Wrap a router handler to catch and converts legacy boom errors to proper custom errors. | | [patch](./kibana-plugin-server.irouter.patch.md) | RouteRegistrar<'patch'> | Register a route handler for PATCH request. | | [post](./kibana-plugin-server.irouter.post.md) | RouteRegistrar<'post'> | Register a route handler for POST request. | | [put](./kibana-plugin-server.irouter.put.md) | RouteRegistrar<'put'> | Register a route handler for PUT request. | diff --git a/docs/development/core/server/kibana-plugin-server.md b/docs/development/core/server/kibana-plugin-server.md index a39c27a758f9d..9c8aafb158bfd 100644 --- a/docs/development/core/server/kibana-plugin-server.md +++ b/docs/development/core/server/kibana-plugin-server.md @@ -21,6 +21,7 @@ The plugin integrates with the core system via lifecycle events: `setup` | [CspConfig](./kibana-plugin-server.cspconfig.md) | CSP configuration for use in Kibana. | | [ElasticsearchErrorHelpers](./kibana-plugin-server.elasticsearcherrorhelpers.md) | Helpers for working with errors returned from the Elasticsearch service.Since the internal data of errors are subject to change, consumers of the Elasticsearch service should always use these helpers to classify errors instead of checking error internals such as body.error.header[WWW-Authenticate] | | [KibanaRequest](./kibana-plugin-server.kibanarequest.md) | Kibana specific abstraction for an incoming request. | +| [RouteValidationError](./kibana-plugin-server.routevalidationerror.md) | Error to return when the validation is not successful. | | [SavedObjectsClient](./kibana-plugin-server.savedobjectsclient.md) | | | [SavedObjectsErrorHelpers](./kibana-plugin-server.savedobjectserrorhelpers.md) | | | [SavedObjectsRepository](./kibana-plugin-server.savedobjectsrepository.md) | | @@ -94,7 +95,9 @@ The plugin integrates with the core system via lifecycle events: `setup` | [RouteConfig](./kibana-plugin-server.routeconfig.md) | Route specific configuration. | | [RouteConfigOptions](./kibana-plugin-server.routeconfigoptions.md) | Additional route options. | | [RouteConfigOptionsBody](./kibana-plugin-server.routeconfigoptionsbody.md) | Additional body options for a route | -| [RouteSchemas](./kibana-plugin-server.routeschemas.md) | RouteSchemas contains the schemas for validating the different parts of a request. | +| [RouteValidationResultFactory](./kibana-plugin-server.routevalidationresultfactory.md) | Validation result factory to be used in the custom validation function to return the valid data or validation errorsSee [RouteValidationFunction](./kibana-plugin-server.routevalidationfunction.md). | +| [RouteValidatorConfig](./kibana-plugin-server.routevalidatorconfig.md) | The configuration object to the RouteValidator class. Set params, query and/or body to specify the validation logic to follow for that property. | +| [RouteValidatorOptions](./kibana-plugin-server.routevalidatoroptions.md) | Additional options for the RouteValidator class to modify its default behaviour. | | [SavedObject](./kibana-plugin-server.savedobject.md) | | | [SavedObjectAttributes](./kibana-plugin-server.savedobjectattributes.md) | The data for a Saved Object is stored as an object in the attributes property. | | [SavedObjectReference](./kibana-plugin-server.savedobjectreference.md) | A reference to another saved object. | @@ -200,6 +203,9 @@ The plugin integrates with the core system via lifecycle events: `setup` | [RouteContentType](./kibana-plugin-server.routecontenttype.md) | The set of supported parseable Content-Types | | [RouteMethod](./kibana-plugin-server.routemethod.md) | The set of common HTTP methods supported by Kibana routing. | | [RouteRegistrar](./kibana-plugin-server.routeregistrar.md) | Route handler common definition | +| [RouteValidationFunction](./kibana-plugin-server.routevalidationfunction.md) | The custom validation function if @kbn/config-schema is not a valid solution for your specific plugin requirements. | +| [RouteValidationSpec](./kibana-plugin-server.routevalidationspec.md) | Allowed property validation options: either @kbn/config-schema validations or custom validation functionsSee [RouteValidationFunction](./kibana-plugin-server.routevalidationfunction.md) for custom validation. | +| [RouteValidatorFullConfig](./kibana-plugin-server.routevalidatorfullconfig.md) | Route validations config and options merged into one object | | [SavedObjectAttribute](./kibana-plugin-server.savedobjectattribute.md) | Type definition for a Saved Object attribute value | | [SavedObjectAttributeSingle](./kibana-plugin-server.savedobjectattributesingle.md) | Don't use this type, it's simply a helper type for [SavedObjectAttribute](./kibana-plugin-server.savedobjectattribute.md) | | [SavedObjectsClientContract](./kibana-plugin-server.savedobjectsclientcontract.md) | Saved Objects is Kibana's data persisentence mechanism allowing plugins to use Elasticsearch for storing plugin state.\#\# SavedObjectsClient errorsSince the SavedObjectsClient has its hands in everything we are a little paranoid about the way we present errors back to to application code. Ideally, all errors will be either:1. Caused by bad implementation (ie. undefined is not a function) and as such unpredictable 2. An error that has been classified and decorated appropriately by the decorators in [SavedObjectsErrorHelpers](./kibana-plugin-server.savedobjectserrorhelpers.md)Type 1 errors are inevitable, but since all expected/handle-able errors should be Type 2 the isXYZError() helpers exposed at SavedObjectsErrorHelpers should be used to understand and manage error responses from the SavedObjectsClient.Type 2 errors are decorated versions of the source error, so if the elasticsearch client threw an error it will be decorated based on its type. That means that rather than looking for error.body.error.type or doing substring checks on error.body.error.reason, just use the helpers to understand the meaning of the error:\`\`\`js if (SavedObjectsErrorHelpers.isNotFoundError(error)) { // handle 404 }if (SavedObjectsErrorHelpers.isNotAuthorizedError(error)) { // 401 handling should be automatic, but in case you wanted to know }// always rethrow the error unless you handle it throw error; \`\`\`\#\#\# 404s from missing indexFrom the perspective of application code and APIs the SavedObjectsClient is a black box that persists objects. One of the internal details that users have no control over is that we use an elasticsearch index for persistance and that index might be missing.At the time of writing we are in the process of transitioning away from the operating assumption that the SavedObjects index is always available. Part of this transition is handling errors resulting from an index missing. These used to trigger a 500 error in most cases, and in others cause 404s with different error messages.From my (Spencer) perspective, a 404 from the SavedObjectsApi is a 404; The object the request/call was targeting could not be found. This is why \#14141 takes special care to ensure that 404 errors are generic and don't distinguish between index missing or document missing.\#\#\# 503s from missing indexUnlike all other methods, create requests are supposed to succeed even when the Kibana index does not exist because it will be automatically created by elasticsearch. When that is not the case it is because Elasticsearch's action.auto_create_index setting prevents it from being created automatically so we throw a special 503 with the intention of informing the user that their Elasticsearch settings need to be updated.See [SavedObjectsClient](./kibana-plugin-server.savedobjectsclient.md) See [SavedObjectsErrorHelpers](./kibana-plugin-server.savedobjectserrorhelpers.md) | diff --git a/docs/development/core/server/kibana-plugin-server.requesthandler.md b/docs/development/core/server/kibana-plugin-server.requesthandler.md index 79abfd4293e9f..9fc183ffc334b 100644 --- a/docs/development/core/server/kibana-plugin-server.requesthandler.md +++ b/docs/development/core/server/kibana-plugin-server.requesthandler.md @@ -9,7 +9,7 @@ A function executed when route path matched requested resource path. Request han Signature: ```typescript -export declare type RequestHandler

| Type, Method extends RouteMethod = any> = (context: RequestHandlerContext, request: KibanaRequest, TypeOf, TypeOf, Method>, response: KibanaResponseFactory) => IKibanaResponse | Promise>; +export declare type RequestHandler

= (context: RequestHandlerContext, request: KibanaRequest, response: KibanaResponseFactory) => IKibanaResponse | Promise>; ``` ## Example diff --git a/docs/development/core/server/kibana-plugin-server.routeconfig.md b/docs/development/core/server/kibana-plugin-server.routeconfig.md index 1970b23c7ec09..4beb12f0d056e 100644 --- a/docs/development/core/server/kibana-plugin-server.routeconfig.md +++ b/docs/development/core/server/kibana-plugin-server.routeconfig.md @@ -9,7 +9,7 @@ Route specific configuration. Signature: ```typescript -export interface RouteConfig

| Type, Method extends RouteMethod> +export interface RouteConfig ``` ## Properties @@ -18,5 +18,5 @@ export interface RouteConfig

RouteConfigOptions<Method> | Additional route options [RouteConfigOptions](./kibana-plugin-server.routeconfigoptions.md). | | [path](./kibana-plugin-server.routeconfig.path.md) | string | The endpoint \_within\_ the router path to register the route. | -| [validate](./kibana-plugin-server.routeconfig.validate.md) | RouteSchemas<P, Q, B> | false | A schema created with @kbn/config-schema that every request will be validated against. | +| [validate](./kibana-plugin-server.routeconfig.validate.md) | RouteValidatorFullConfig<P, Q, B> | false | A schema created with @kbn/config-schema that every request will be validated against. | diff --git a/docs/development/core/server/kibana-plugin-server.routeconfig.validate.md b/docs/development/core/server/kibana-plugin-server.routeconfig.validate.md index e1ec743ae71cc..23a72fc3c68b3 100644 --- a/docs/development/core/server/kibana-plugin-server.routeconfig.validate.md +++ b/docs/development/core/server/kibana-plugin-server.routeconfig.validate.md @@ -9,7 +9,7 @@ A schema created with `@kbn/config-schema` that every request will be validated Signature: ```typescript -validate: RouteSchemas | false; +validate: RouteValidatorFullConfig | false; ``` ## Remarks diff --git a/docs/development/core/server/kibana-plugin-server.routeregistrar.md b/docs/development/core/server/kibana-plugin-server.routeregistrar.md index 0f5f49636fdd5..901d260fee21d 100644 --- a/docs/development/core/server/kibana-plugin-server.routeregistrar.md +++ b/docs/development/core/server/kibana-plugin-server.routeregistrar.md @@ -9,5 +9,5 @@ Route handler common definition Signature: ```typescript -export declare type RouteRegistrar =

| Type>(route: RouteConfig, handler: RequestHandler) => void; +export declare type RouteRegistrar = (route: RouteConfig, handler: RequestHandler) => void; ``` diff --git a/docs/development/core/server/kibana-plugin-server.routeschemas.body.md b/docs/development/core/server/kibana-plugin-server.routeschemas.body.md deleted file mode 100644 index 78a9d25c25d9d..0000000000000 --- a/docs/development/core/server/kibana-plugin-server.routeschemas.body.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [RouteSchemas](./kibana-plugin-server.routeschemas.md) > [body](./kibana-plugin-server.routeschemas.body.md) - -## RouteSchemas.body property - -Signature: - -```typescript -body?: B; -``` diff --git a/docs/development/core/server/kibana-plugin-server.routeschemas.md b/docs/development/core/server/kibana-plugin-server.routeschemas.md deleted file mode 100644 index 77b980551a8ff..0000000000000 --- a/docs/development/core/server/kibana-plugin-server.routeschemas.md +++ /dev/null @@ -1,22 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [RouteSchemas](./kibana-plugin-server.routeschemas.md) - -## RouteSchemas interface - -RouteSchemas contains the schemas for validating the different parts of a request. - -Signature: - -```typescript -export interface RouteSchemas

| Type> -``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [body](./kibana-plugin-server.routeschemas.body.md) | B | | -| [params](./kibana-plugin-server.routeschemas.params.md) | P | | -| [query](./kibana-plugin-server.routeschemas.query.md) | Q | | - diff --git a/docs/development/core/server/kibana-plugin-server.routeschemas.params.md b/docs/development/core/server/kibana-plugin-server.routeschemas.params.md deleted file mode 100644 index 3dbf9fed94dc0..0000000000000 --- a/docs/development/core/server/kibana-plugin-server.routeschemas.params.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [RouteSchemas](./kibana-plugin-server.routeschemas.md) > [params](./kibana-plugin-server.routeschemas.params.md) - -## RouteSchemas.params property - -Signature: - -```typescript -params?: P; -``` diff --git a/docs/development/core/server/kibana-plugin-server.routeschemas.query.md b/docs/development/core/server/kibana-plugin-server.routeschemas.query.md deleted file mode 100644 index 5be5830cb4bc8..0000000000000 --- a/docs/development/core/server/kibana-plugin-server.routeschemas.query.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [RouteSchemas](./kibana-plugin-server.routeschemas.md) > [query](./kibana-plugin-server.routeschemas.query.md) - -## RouteSchemas.query property - -Signature: - -```typescript -query?: Q; -``` diff --git a/docs/development/core/server/kibana-plugin-server.routevalidationerror._constructor_.md b/docs/development/core/server/kibana-plugin-server.routevalidationerror._constructor_.md new file mode 100644 index 0000000000000..551e13faaf154 --- /dev/null +++ b/docs/development/core/server/kibana-plugin-server.routevalidationerror._constructor_.md @@ -0,0 +1,21 @@ + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [RouteValidationError](./kibana-plugin-server.routevalidationerror.md) > [(constructor)](./kibana-plugin-server.routevalidationerror._constructor_.md) + +## RouteValidationError.(constructor) + +Constructs a new instance of the `RouteValidationError` class + +Signature: + +```typescript +constructor(error: Error | string, path?: string[]); +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| error | Error | string | | +| path | string[] | | + diff --git a/docs/development/core/server/kibana-plugin-server.routevalidationerror.md b/docs/development/core/server/kibana-plugin-server.routevalidationerror.md new file mode 100644 index 0000000000000..71bd72dca2eab --- /dev/null +++ b/docs/development/core/server/kibana-plugin-server.routevalidationerror.md @@ -0,0 +1,20 @@ + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [RouteValidationError](./kibana-plugin-server.routevalidationerror.md) + +## RouteValidationError class + +Error to return when the validation is not successful. + +Signature: + +```typescript +export declare class RouteValidationError extends SchemaTypeError +``` + +## Constructors + +| Constructor | Modifiers | Description | +| --- | --- | --- | +| [(constructor)(error, path)](./kibana-plugin-server.routevalidationerror._constructor_.md) | | Constructs a new instance of the RouteValidationError class | + diff --git a/docs/development/core/server/kibana-plugin-server.routevalidationfunction.md b/docs/development/core/server/kibana-plugin-server.routevalidationfunction.md new file mode 100644 index 0000000000000..34fa096aaae78 --- /dev/null +++ b/docs/development/core/server/kibana-plugin-server.routevalidationfunction.md @@ -0,0 +1,42 @@ + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [RouteValidationFunction](./kibana-plugin-server.routevalidationfunction.md) + +## RouteValidationFunction type + +The custom validation function if @kbn/config-schema is not a valid solution for your specific plugin requirements. + +Signature: + +```typescript +export declare type RouteValidationFunction = (data: any, validationResult: RouteValidationResultFactory) => { + value: T; + error?: never; +} | { + value?: never; + error: RouteValidationError; +}; +``` + +## Example + +The validation should look something like: + +```typescript +interface MyExpectedBody { + bar: string; + baz: number; +} + +const myBodyValidation: RouteValidationFunction = (data, validationResult) => { + const { ok, badRequest } = validationResult; + const { bar, baz } = data || {}; + if (typeof bar === 'string' && typeof baz === 'number') { + return ok({ bar, baz }); + } else { + return badRequest('Wrong payload', ['body']); + } +} + +``` + diff --git a/docs/development/core/server/kibana-plugin-server.routevalidationresultfactory.badrequest.md b/docs/development/core/server/kibana-plugin-server.routevalidationresultfactory.badrequest.md new file mode 100644 index 0000000000000..36ea6103fb352 --- /dev/null +++ b/docs/development/core/server/kibana-plugin-server.routevalidationresultfactory.badrequest.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [RouteValidationResultFactory](./kibana-plugin-server.routevalidationresultfactory.md) > [badRequest](./kibana-plugin-server.routevalidationresultfactory.badrequest.md) + +## RouteValidationResultFactory.badRequest property + +Signature: + +```typescript +badRequest: (error: Error | string, path?: string[]) => { + error: RouteValidationError; + }; +``` diff --git a/docs/development/core/server/kibana-plugin-server.routevalidationresultfactory.md b/docs/development/core/server/kibana-plugin-server.routevalidationresultfactory.md new file mode 100644 index 0000000000000..5f44b490e9a17 --- /dev/null +++ b/docs/development/core/server/kibana-plugin-server.routevalidationresultfactory.md @@ -0,0 +1,23 @@ + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [RouteValidationResultFactory](./kibana-plugin-server.routevalidationresultfactory.md) + +## RouteValidationResultFactory interface + +Validation result factory to be used in the custom validation function to return the valid data or validation errors + +See [RouteValidationFunction](./kibana-plugin-server.routevalidationfunction.md). + +Signature: + +```typescript +export interface RouteValidationResultFactory +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [badRequest](./kibana-plugin-server.routevalidationresultfactory.badrequest.md) | (error: Error | string, path?: string[]) => {
error: RouteValidationError;
} | | +| [ok](./kibana-plugin-server.routevalidationresultfactory.ok.md) | <T>(value: T) => {
value: T;
} | | + diff --git a/docs/development/core/server/kibana-plugin-server.routevalidationresultfactory.ok.md b/docs/development/core/server/kibana-plugin-server.routevalidationresultfactory.ok.md new file mode 100644 index 0000000000000..eca6a31bd547f --- /dev/null +++ b/docs/development/core/server/kibana-plugin-server.routevalidationresultfactory.ok.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [RouteValidationResultFactory](./kibana-plugin-server.routevalidationresultfactory.md) > [ok](./kibana-plugin-server.routevalidationresultfactory.ok.md) + +## RouteValidationResultFactory.ok property + +Signature: + +```typescript +ok: (value: T) => { + value: T; + }; +``` diff --git a/docs/development/core/server/kibana-plugin-server.routevalidationspec.md b/docs/development/core/server/kibana-plugin-server.routevalidationspec.md new file mode 100644 index 0000000000000..f5fc06544043f --- /dev/null +++ b/docs/development/core/server/kibana-plugin-server.routevalidationspec.md @@ -0,0 +1,15 @@ + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [RouteValidationSpec](./kibana-plugin-server.routevalidationspec.md) + +## RouteValidationSpec type + +Allowed property validation options: either @kbn/config-schema validations or custom validation functions + +See [RouteValidationFunction](./kibana-plugin-server.routevalidationfunction.md) for custom validation. + +Signature: + +```typescript +export declare type RouteValidationSpec = ObjectType | Type | RouteValidationFunction; +``` diff --git a/docs/development/core/server/kibana-plugin-server.routevalidatorconfig.body.md b/docs/development/core/server/kibana-plugin-server.routevalidatorconfig.body.md new file mode 100644 index 0000000000000..8b5d2c0413087 --- /dev/null +++ b/docs/development/core/server/kibana-plugin-server.routevalidatorconfig.body.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [RouteValidatorConfig](./kibana-plugin-server.routevalidatorconfig.md) > [body](./kibana-plugin-server.routevalidatorconfig.body.md) + +## RouteValidatorConfig.body property + +Validation logic for the body payload + +Signature: + +```typescript +body?: RouteValidationSpec; +``` diff --git a/docs/development/core/server/kibana-plugin-server.routevalidatorconfig.md b/docs/development/core/server/kibana-plugin-server.routevalidatorconfig.md new file mode 100644 index 0000000000000..4637da7741d80 --- /dev/null +++ b/docs/development/core/server/kibana-plugin-server.routevalidatorconfig.md @@ -0,0 +1,22 @@ + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [RouteValidatorConfig](./kibana-plugin-server.routevalidatorconfig.md) + +## RouteValidatorConfig interface + +The configuration object to the RouteValidator class. Set `params`, `query` and/or `body` to specify the validation logic to follow for that property. + +Signature: + +```typescript +export interface RouteValidatorConfig +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [body](./kibana-plugin-server.routevalidatorconfig.body.md) | RouteValidationSpec<B> | Validation logic for the body payload | +| [params](./kibana-plugin-server.routevalidatorconfig.params.md) | RouteValidationSpec<P> | Validation logic for the URL params | +| [query](./kibana-plugin-server.routevalidatorconfig.query.md) | RouteValidationSpec<Q> | Validation logic for the Query params | + diff --git a/docs/development/core/server/kibana-plugin-server.routevalidatorconfig.params.md b/docs/development/core/server/kibana-plugin-server.routevalidatorconfig.params.md new file mode 100644 index 0000000000000..11de25ff3b19f --- /dev/null +++ b/docs/development/core/server/kibana-plugin-server.routevalidatorconfig.params.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [RouteValidatorConfig](./kibana-plugin-server.routevalidatorconfig.md) > [params](./kibana-plugin-server.routevalidatorconfig.params.md) + +## RouteValidatorConfig.params property + +Validation logic for the URL params + +Signature: + +```typescript +params?: RouteValidationSpec

; +``` diff --git a/docs/development/core/server/kibana-plugin-server.routevalidatorconfig.query.md b/docs/development/core/server/kibana-plugin-server.routevalidatorconfig.query.md new file mode 100644 index 0000000000000..510325c2dfff7 --- /dev/null +++ b/docs/development/core/server/kibana-plugin-server.routevalidatorconfig.query.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [RouteValidatorConfig](./kibana-plugin-server.routevalidatorconfig.md) > [query](./kibana-plugin-server.routevalidatorconfig.query.md) + +## RouteValidatorConfig.query property + +Validation logic for the Query params + +Signature: + +```typescript +query?: RouteValidationSpec; +``` diff --git a/docs/development/core/server/kibana-plugin-server.routevalidatorfullconfig.md b/docs/development/core/server/kibana-plugin-server.routevalidatorfullconfig.md new file mode 100644 index 0000000000000..0f3785b954a3a --- /dev/null +++ b/docs/development/core/server/kibana-plugin-server.routevalidatorfullconfig.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [RouteValidatorFullConfig](./kibana-plugin-server.routevalidatorfullconfig.md) + +## RouteValidatorFullConfig type + +Route validations config and options merged into one object + +Signature: + +```typescript +export declare type RouteValidatorFullConfig = RouteValidatorConfig & RouteValidatorOptions; +``` diff --git a/docs/development/core/server/kibana-plugin-server.routevalidatoroptions.md b/docs/development/core/server/kibana-plugin-server.routevalidatoroptions.md new file mode 100644 index 0000000000000..00b029d9928e3 --- /dev/null +++ b/docs/development/core/server/kibana-plugin-server.routevalidatoroptions.md @@ -0,0 +1,20 @@ + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [RouteValidatorOptions](./kibana-plugin-server.routevalidatoroptions.md) + +## RouteValidatorOptions interface + +Additional options for the RouteValidator class to modify its default behaviour. + +Signature: + +```typescript +export interface RouteValidatorOptions +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [unsafe](./kibana-plugin-server.routevalidatoroptions.unsafe.md) | {
params?: boolean;
query?: boolean;
body?: boolean;
} | Set the unsafe config to avoid running some additional internal \*safe\* validations on top of your custom validation | + diff --git a/docs/development/core/server/kibana-plugin-server.routevalidatoroptions.unsafe.md b/docs/development/core/server/kibana-plugin-server.routevalidatoroptions.unsafe.md new file mode 100644 index 0000000000000..0406a372c4e9d --- /dev/null +++ b/docs/development/core/server/kibana-plugin-server.routevalidatoroptions.unsafe.md @@ -0,0 +1,17 @@ + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [RouteValidatorOptions](./kibana-plugin-server.routevalidatoroptions.md) > [unsafe](./kibana-plugin-server.routevalidatoroptions.unsafe.md) + +## RouteValidatorOptions.unsafe property + +Set the `unsafe` config to avoid running some additional internal \*safe\* validations on top of your custom validation + +Signature: + +```typescript +unsafe?: { + params?: boolean; + query?: boolean; + body?: boolean; + }; +``` diff --git a/packages/kbn-config-schema/src/index.ts b/packages/kbn-config-schema/src/index.ts index 56b3096433c24..fc3e3c541846a 100644 --- a/packages/kbn-config-schema/src/index.ts +++ b/packages/kbn-config-schema/src/index.ts @@ -59,6 +59,7 @@ import { export { ObjectType, TypeOf, Type }; export { ByteSizeValue } from './byte_size_value'; +export { SchemaTypeError, ValidationError } from './errors'; function any(options?: TypeOptions) { return new AnyType(options); diff --git a/src/core/server/http/http_server.mocks.ts b/src/core/server/http/http_server.mocks.ts index 8469a1d23a44b..ba742292e9e83 100644 --- a/src/core/server/http/http_server.mocks.ts +++ b/src/core/server/http/http_server.mocks.ts @@ -77,7 +77,7 @@ function createKibanaRequestMock({ body: schema.object({}, { allowUnknowns: true }), query: schema.object({}, { allowUnknowns: true }), } - ) as KibanaRequest, Readonly<{}>, Readonly<{}>>; + ); } type DeepPartial = T extends any[] diff --git a/src/core/server/http/http_server.test.ts b/src/core/server/http/http_server.test.ts index 27d9f530050be..df357aeaf2731 100644 --- a/src/core/server/http/http_server.test.ts +++ b/src/core/server/http/http_server.test.ts @@ -27,10 +27,18 @@ import supertest from 'supertest'; import { ByteSizeValue, schema } from '@kbn/config-schema'; import { HttpConfig } from './http_config'; -import { Router } from './router'; +import { + Router, + KibanaRequest, + KibanaResponseFactory, + RequestHandler, + RouteValidationResultFactory, + RouteValidationFunction, +} from './router'; import { loggingServiceMock } from '../logging/logging_service.mock'; import { HttpServer } from './http_server'; import { Readable } from 'stream'; +import { RequestHandlerContext } from 'kibana/server'; const cookieOptions = { name: 'sid', @@ -288,6 +296,229 @@ test('valid body', async () => { }); }); +test('valid body with validate function', async () => { + const router = new Router('/foo', logger, enhanceWithContext); + + router.post( + { + path: '/', + validate: { + body: ({ bar, baz } = {}, { ok, badRequest }) => { + if (typeof bar === 'string' && typeof baz === 'number') { + return ok({ bar, baz }); + } else { + return badRequest('Wrong payload', ['body']); + } + }, + }, + }, + (context, req, res) => { + return res.ok({ body: req.body }); + } + ); + + const { registerRouter, server: innerServer } = await server.setup(config); + registerRouter(router); + + await server.start(); + + await supertest(innerServer.listener) + .post('/foo/') + .send({ + bar: 'test', + baz: 123, + }) + .expect(200) + .then(res => { + expect(res.body).toEqual({ bar: 'test', baz: 123 }); + }); +}); + +test('not inline validation - specifying params', async () => { + const router = new Router('/foo', logger, enhanceWithContext); + + const bodyValidation = ( + { bar, baz }: any = {}, + { ok, badRequest }: RouteValidationResultFactory + ) => { + if (typeof bar === 'string' && typeof baz === 'number') { + return ok({ bar, baz }); + } else { + return badRequest('Wrong payload', ['body']); + } + }; + + router.post( + { + path: '/', + validate: { + body: bodyValidation, + }, + }, + (context, req, res) => { + return res.ok({ body: req.body }); + } + ); + + const { registerRouter, server: innerServer } = await server.setup(config); + registerRouter(router); + + await server.start(); + + await supertest(innerServer.listener) + .post('/foo/') + .send({ + bar: 'test', + baz: 123, + }) + .expect(200) + .then(res => { + expect(res.body).toEqual({ bar: 'test', baz: 123 }); + }); +}); + +test('not inline validation - specifying validation handler', async () => { + const router = new Router('/foo', logger, enhanceWithContext); + + const bodyValidation: RouteValidationFunction<{ bar: string; baz: number }> = ( + { bar, baz } = {}, + { ok, badRequest } + ) => { + if (typeof bar === 'string' && typeof baz === 'number') { + return ok({ bar, baz }); + } else { + return badRequest('Wrong payload', ['body']); + } + }; + + router.post( + { + path: '/', + validate: { + body: bodyValidation, + }, + }, + (context, req, res) => { + return res.ok({ body: req.body }); + } + ); + + const { registerRouter, server: innerServer } = await server.setup(config); + registerRouter(router); + + await server.start(); + + await supertest(innerServer.listener) + .post('/foo/') + .send({ + bar: 'test', + baz: 123, + }) + .expect(200) + .then(res => { + expect(res.body).toEqual({ bar: 'test', baz: 123 }); + }); +}); + +// https://github.com/elastic/kibana/issues/47047 +test('not inline handler - KibanaRequest', async () => { + const router = new Router('/foo', logger, enhanceWithContext); + + const handler = ( + context: RequestHandlerContext, + req: KibanaRequest, + res: KibanaResponseFactory + ) => { + const body = { + bar: req.body.bar.toUpperCase(), + baz: req.body.baz.toString(), + }; + + return res.ok({ body }); + }; + + router.post( + { + path: '/', + validate: { + body: ({ bar, baz } = {}, { ok, badRequest }) => { + if (typeof bar === 'string' && typeof baz === 'number') { + return ok({ bar, baz }); + } else { + return badRequest('Wrong payload', ['body']); + } + }, + }, + }, + handler + ); + + const { registerRouter, server: innerServer } = await server.setup(config); + registerRouter(router); + + await server.start(); + + await supertest(innerServer.listener) + .post('/foo/') + .send({ + bar: 'test', + baz: 123, + }) + .expect(200) + .then(res => { + expect(res.body).toEqual({ bar: 'TEST', baz: '123' }); + }); +}); + +test('not inline handler - RequestHandler', async () => { + const router = new Router('/foo', logger, enhanceWithContext); + + const handler: RequestHandler = ( + context, + req, + res + ) => { + const body = { + bar: req.body.bar.toUpperCase(), + baz: req.body.baz.toString(), + }; + + return res.ok({ body }); + }; + + router.post( + { + path: '/', + validate: { + body: ({ bar, baz } = {}, { ok, badRequest }) => { + if (typeof bar === 'string' && typeof baz === 'number') { + return ok({ bar, baz }); + } else { + return badRequest('Wrong payload', ['body']); + } + }, + }, + }, + handler + ); + + const { registerRouter, server: innerServer } = await server.setup(config); + registerRouter(router); + + await server.start(); + + await supertest(innerServer.listener) + .post('/foo/') + .send({ + bar: 'test', + baz: 123, + }) + .expect(200) + .then(res => { + expect(res.body).toEqual({ bar: 'TEST', baz: '123' }); + }); +}); + test('invalid body', async () => { const router = new Router('/foo', logger, enhanceWithContext); diff --git a/src/core/server/http/index.ts b/src/core/server/http/index.ts index 21de3945f1044..55ba813484268 100644 --- a/src/core/server/http/index.ts +++ b/src/core/server/http/index.ts @@ -47,10 +47,16 @@ export { RouteMethod, RouteRegistrar, RouteConfigOptions, - RouteSchemas, RouteConfigOptionsBody, RouteContentType, validBodyOutput, + RouteValidatorConfig, + RouteValidationSpec, + RouteValidationFunction, + RouteValidatorOptions, + RouteValidationError, + RouteValidatorFullConfig, + RouteValidationResultFactory, } from './router'; export { BasePathProxyServer } from './base_path_proxy_server'; export { OnPreAuthHandler, OnPreAuthToolkit } from './lifecycle/on_pre_auth'; diff --git a/src/core/server/http/integration_tests/router.test.ts b/src/core/server/http/integration_tests/router.test.ts index 6117190c57ba8..c3b9b20d84865 100644 --- a/src/core/server/http/integration_tests/router.test.ts +++ b/src/core/server/http/integration_tests/router.test.ts @@ -642,6 +642,116 @@ describe('Response factory', () => { }); }); + it('validate function in body', async () => { + const { server: innerServer, createRouter } = await server.setup(setupDeps); + const router = createRouter('/foo'); + + router.post( + { + path: '/', + validate: { + body: ({ bar, baz } = {}, { ok, badRequest }) => { + if (typeof bar === 'string' && typeof baz === 'number') { + return ok({ bar, baz }); + } else { + return badRequest('Wrong payload', ['body']); + } + }, + }, + }, + (context, req, res) => { + return res.ok({ body: req.body }); + } + ); + + await server.start(); + + await supertest(innerServer.listener) + .post('/foo/') + .send({ + bar: 'test', + baz: 123, + }) + .expect(200) + .then(res => { + expect(res.body).toEqual({ bar: 'test', baz: 123 }); + }); + + await supertest(innerServer.listener) + .post('/foo/') + .send({ + bar: 'test', + baz: '123', + }) + .expect(400) + .then(res => { + expect(res.body).toEqual({ + error: 'Bad Request', + message: '[request body.body]: Wrong payload', + statusCode: 400, + }); + }); + }); + + it('@kbn/config-schema validation in body', async () => { + const { server: innerServer, createRouter } = await server.setup(setupDeps); + const router = createRouter('/foo'); + + router.post( + { + path: '/', + validate: { + body: schema.object({ + bar: schema.string(), + baz: schema.number(), + }), + }, + }, + (context, req, res) => { + return res.ok({ body: req.body }); + } + ); + + await server.start(); + + await supertest(innerServer.listener) + .post('/foo/') + .send({ + bar: 'test', + baz: 123, + }) + .expect(200) + .then(res => { + expect(res.body).toEqual({ bar: 'test', baz: 123 }); + }); + + await supertest(innerServer.listener) + .post('/foo/') + .send({ + bar: 'test', + baz: '123', // Automatic casting happens + }) + .expect(200) + .then(res => { + expect(res.body).toEqual({ bar: 'test', baz: 123 }); + }); + + await supertest(innerServer.listener) + .post('/foo/') + .send({ + bar: 'test', + baz: 'test', // Can't cast it into number + }) + .expect(400) + .then(res => { + expect(res.body).toEqual({ + error: 'Bad Request', + message: '[request body.baz]: expected value of type [number] but got [string]', + statusCode: 400, + }); + }); + }); + it('401 Unauthorized', async () => { const { server: innerServer, createRouter } = await server.setup(setupDeps); const router = createRouter('/'); diff --git a/src/core/server/http/router/error_wrapper.ts b/src/core/server/http/router/error_wrapper.ts index c4b4d3840d1b9..8f895753c38c3 100644 --- a/src/core/server/http/router/error_wrapper.ts +++ b/src/core/server/http/router/error_wrapper.ts @@ -18,19 +18,18 @@ */ import Boom from 'boom'; -import { ObjectType, TypeOf } from '@kbn/config-schema'; import { KibanaRequest } from './request'; import { KibanaResponseFactory } from './response'; import { RequestHandler } from './router'; import { RequestHandlerContext } from '../../../server'; import { RouteMethod } from './route'; -export const wrapErrors =

( +export const wrapErrors = ( handler: RequestHandler ): RequestHandler => { return async ( context: RequestHandlerContext, - request: KibanaRequest, TypeOf, TypeOf, RouteMethod>, + request: KibanaRequest, response: KibanaResponseFactory ) => { try { diff --git a/src/core/server/http/router/index.ts b/src/core/server/http/router/index.ts index 35bfb3ba9c33a..084d30d694474 100644 --- a/src/core/server/http/router/index.ts +++ b/src/core/server/http/router/index.ts @@ -31,7 +31,6 @@ export { RouteMethod, RouteConfig, RouteConfigOptions, - RouteSchemas, RouteContentType, RouteConfigOptionsBody, validBodyOutput, @@ -55,3 +54,13 @@ export { } from './response'; export { IKibanaSocket } from './socket'; + +export { + RouteValidatorConfig, + RouteValidationSpec, + RouteValidationFunction, + RouteValidatorOptions, + RouteValidationError, + RouteValidatorFullConfig, + RouteValidationResultFactory, +} from './validator'; diff --git a/src/core/server/http/router/request.test.ts b/src/core/server/http/router/request.test.ts index ebb7ffa7a6fc9..51162a2c258e9 100644 --- a/src/core/server/http/router/request.test.ts +++ b/src/core/server/http/router/request.test.ts @@ -18,6 +18,7 @@ */ import { KibanaRequest } from './request'; import { httpServerMock } from '../http_server.mocks'; +import { schema } from '@kbn/config-schema'; describe('KibanaRequest', () => { describe('get all headers', () => { @@ -64,4 +65,56 @@ describe('KibanaRequest', () => { }); }); }); + + describe('RouteSchema type inferring', () => { + it('should work with config-schema', () => { + const body = Buffer.from('body!'); + const request = { + ...httpServerMock.createRawRequest({ + params: { id: 'params' }, + query: { search: 'query' }, + }), + payload: body, // Set outside because the mock is using `merge` by lodash and breaks the Buffer into arrays + } as any; + const kibanaRequest = KibanaRequest.from(request, { + params: schema.object({ id: schema.string() }), + query: schema.object({ search: schema.string() }), + body: schema.buffer(), + }); + expect(kibanaRequest.params).toStrictEqual({ id: 'params' }); + expect(kibanaRequest.params.id.toUpperCase()).toEqual('PARAMS'); // infers it's a string + expect(kibanaRequest.query).toStrictEqual({ search: 'query' }); + expect(kibanaRequest.query.search.toUpperCase()).toEqual('QUERY'); // infers it's a string + expect(kibanaRequest.body).toEqual(body); + expect(kibanaRequest.body.byteLength).toBeGreaterThan(0); // infers it's a buffer + }); + + it('should work with ValidationFunction', () => { + const body = Buffer.from('body!'); + const request = { + ...httpServerMock.createRawRequest({ + params: { id: 'params' }, + query: { search: 'query' }, + }), + payload: body, // Set outside because the mock is using `merge` by lodash and breaks the Buffer into arrays + } as any; + const kibanaRequest = KibanaRequest.from(request, { + params: schema.object({ id: schema.string() }), + query: schema.object({ search: schema.string() }), + body: (data, { ok, badRequest }) => { + if (Buffer.isBuffer(data)) { + return ok(data); + } else { + return badRequest('It should be a Buffer', []); + } + }, + }); + expect(kibanaRequest.params).toStrictEqual({ id: 'params' }); + expect(kibanaRequest.params.id.toUpperCase()).toEqual('PARAMS'); // infers it's a string + expect(kibanaRequest.query).toStrictEqual({ search: 'query' }); + expect(kibanaRequest.query.search.toUpperCase()).toEqual('QUERY'); // infers it's a string + expect(kibanaRequest.body).toEqual(body); + expect(kibanaRequest.body.byteLength).toBeGreaterThan(0); // infers it's a buffer + }); + }); }); diff --git a/src/core/server/http/router/request.ts b/src/core/server/http/router/request.ts index b132899910569..47b001700b015 100644 --- a/src/core/server/http/router/request.ts +++ b/src/core/server/http/router/request.ts @@ -20,13 +20,11 @@ import { Url } from 'url'; import { Request } from 'hapi'; -import { ObjectType, Type, TypeOf } from '@kbn/config-schema'; - -import { Stream } from 'stream'; import { deepFreeze, RecursiveReadonly } from '../../../utils'; import { Headers } from './headers'; -import { RouteMethod, RouteSchemas, RouteConfigOptions, validBodyOutput } from './route'; +import { RouteMethod, RouteConfigOptions, validBodyOutput } from './route'; import { KibanaSocket, IKibanaSocket } from './socket'; +import { RouteValidator, RouteValidatorFullConfig } from './validator'; const requestSymbol = Symbol('request'); @@ -70,12 +68,13 @@ export class KibanaRequest< * instance of a KibanaRequest. * @internal */ - public static from< - P extends ObjectType, - Q extends ObjectType, - B extends ObjectType | Type | Type - >(req: Request, routeSchemas?: RouteSchemas, withoutSecretHeaders: boolean = true) { - const requestParts = KibanaRequest.validate(req, routeSchemas); + public static from( + req: Request, + routeSchemas: RouteValidator | RouteValidatorFullConfig = {}, + withoutSecretHeaders: boolean = true + ) { + const routeValidator = RouteValidator.from(routeSchemas); + const requestParts = KibanaRequest.validate(req, routeValidator); return new KibanaRequest( req, requestParts.params, @@ -91,40 +90,17 @@ export class KibanaRequest< * received in the route handler. * @internal */ - private static validate< - P extends ObjectType, - Q extends ObjectType, - B extends ObjectType | Type | Type - >( + private static validate( req: Request, - routeSchemas: RouteSchemas | undefined + routeValidator: RouteValidator ): { - params: TypeOf

; - query: TypeOf; - body: TypeOf; + params: P; + query: Q; + body: B; } { - if (routeSchemas === undefined) { - return { - body: {}, - params: {}, - query: {}, - }; - } - - const params = - routeSchemas.params === undefined - ? {} - : routeSchemas.params.validate(req.params, {}, 'request params'); - - const query = - routeSchemas.query === undefined - ? {} - : routeSchemas.query.validate(req.query, {}, 'request query'); - - const body = - routeSchemas.body === undefined - ? {} - : routeSchemas.body.validate(req.payload, {}, 'request body'); + const params = routeValidator.getParams(req.params, 'request params'); + const query = routeValidator.getQuery(req.query, 'request query'); + const body = routeValidator.getBody(req.payload, 'request body'); return { query, params, body }; } diff --git a/src/core/server/http/router/route.ts b/src/core/server/http/router/route.ts index 129cf4c922ffd..4439a80b1eac7 100644 --- a/src/core/server/http/router/route.ts +++ b/src/core/server/http/router/route.ts @@ -17,8 +17,7 @@ * under the License. */ -import { ObjectType, Type } from '@kbn/config-schema'; -import { Stream } from 'stream'; +import { RouteValidatorFullConfig } from './validator'; /** * The set of common HTTP methods supported by Kibana routing. @@ -124,12 +123,7 @@ export interface RouteConfigOptions { * Route specific configuration. * @public */ -export interface RouteConfig< - P extends ObjectType, - Q extends ObjectType, - B extends ObjectType | Type | Type, - Method extends RouteMethod -> { +export interface RouteConfig { /** * The endpoint _within_ the router path to register the route. * @@ -201,25 +195,10 @@ export interface RouteConfig< * }); * ``` */ - validate: RouteSchemas | false; + validate: RouteValidatorFullConfig | false; /** * Additional route options {@link RouteConfigOptions}. */ options?: RouteConfigOptions; } - -/** - * RouteSchemas contains the schemas for validating the different parts of a - * request. - * @public - */ -export interface RouteSchemas< - P extends ObjectType, - Q extends ObjectType, - B extends ObjectType | Type | Type -> { - params?: P; - query?: Q; - body?: B; -} diff --git a/src/core/server/http/router/router.test.ts b/src/core/server/http/router/router.test.ts index f5469a95b5106..a936da6a40a9f 100644 --- a/src/core/server/http/router/router.test.ts +++ b/src/core/server/http/router/router.test.ts @@ -20,6 +20,7 @@ import { Router } from './router'; import { loggingServiceMock } from '../../logging/logging_service.mock'; import { schema } from '@kbn/config-schema'; + const logger = loggingServiceMock.create().get(); const enhanceWithContext = (fn: (...args: any[]) => any) => fn.bind(null, {}); @@ -38,12 +39,15 @@ describe('Router', () => { const router = new Router('', logger, enhanceWithContext); expect(() => router.get( - // we use 'any' because validate requires @kbn/config-schema usage - { path: '/', validate: { params: { validate: () => 'error' } } } as any, + // we use 'any' because validate requires valid Type or function usage + { + path: '/', + validate: { params: { validate: () => 'error' } } as any, + }, (context, req, res) => res.ok({}) ) ).toThrowErrorMatchingInlineSnapshot( - `"Expected a valid schema declared with '@kbn/config-schema' package at key: [params]."` + `"Expected a valid validation logic declared with '@kbn/config-schema' package or a RouteValidationFunction at key: [params]."` ); }); diff --git a/src/core/server/http/router/router.ts b/src/core/server/http/router/router.ts index 5c52e71cd54bb..bb56ee3727d1a 100644 --- a/src/core/server/http/router/router.ts +++ b/src/core/server/http/router/router.ts @@ -17,24 +17,18 @@ * under the License. */ -import { ObjectType, TypeOf, Type } from '@kbn/config-schema'; import { Request, ResponseObject, ResponseToolkit } from 'hapi'; import Boom from 'boom'; -import { Stream } from 'stream'; +import { Type } from '@kbn/config-schema'; import { Logger } from '../../logging'; import { KibanaRequest } from './request'; import { KibanaResponseFactory, kibanaResponseFactory, IKibanaResponse } from './response'; -import { - RouteConfig, - RouteConfigOptions, - RouteMethod, - RouteSchemas, - validBodyOutput, -} from './route'; +import { RouteConfig, RouteConfigOptions, RouteMethod, validBodyOutput } from './route'; import { HapiResponseAdapter } from './response_adapter'; import { RequestHandlerContext } from '../../../server'; import { wrapErrors } from './error_wrapper'; +import { RouteValidator } from './validator'; interface RouterRoute { method: RouteMethod; @@ -48,11 +42,7 @@ interface RouterRoute { * * @public */ -export type RouteRegistrar = < - P extends ObjectType, - Q extends ObjectType, - B extends ObjectType | Type | Type ->( +export type RouteRegistrar = ( route: RouteConfig, handler: RequestHandler ) => void; @@ -108,9 +98,7 @@ export interface IRouter { * Wrap a router handler to catch and converts legacy boom errors to proper custom errors. * @param handler {@link RequestHandler} - a route handler to wrap */ - handleLegacyErrors:

( - handler: RequestHandler - ) => RequestHandler; + handleLegacyErrors: (handler: RequestHandler) => RequestHandler; /** * Returns all routes registered with this router. @@ -120,12 +108,9 @@ export interface IRouter { getRoutes: () => RouterRoute[]; } -export type ContextEnhancer< - P extends ObjectType, - Q extends ObjectType, - B extends ObjectType, - Method extends RouteMethod -> = (handler: RequestHandler) => RequestHandlerEnhanced; +export type ContextEnhancer = ( + handler: RequestHandler +) => RequestHandlerEnhanced; function getRouteFullPath(routerPath: string, routePath: string) { // If router's path ends with slash and route's path starts with slash, @@ -140,11 +125,10 @@ function getRouteFullPath(routerPath: string, routePath: string) { * @returns Route schemas if `validate` is specified on the route, otherwise * undefined. */ -function routeSchemasFromRouteConfig< - P extends ObjectType, - Q extends ObjectType, - B extends ObjectType | Type | Type ->(route: RouteConfig, routeMethod: RouteMethod) { +function routeSchemasFromRouteConfig( + route: RouteConfig, + routeMethod: RouteMethod +) { // The type doesn't allow `validate` to be undefined, but it can still // happen when it's used from JavaScript. if (route.validate === undefined) { @@ -155,15 +139,17 @@ function routeSchemasFromRouteConfig< if (route.validate !== false) { Object.entries(route.validate).forEach(([key, schema]) => { - if (!(schema instanceof Type)) { + if (!(schema instanceof Type || typeof schema === 'function')) { throw new Error( - `Expected a valid schema declared with '@kbn/config-schema' package at key: [${key}].` + `Expected a valid validation logic declared with '@kbn/config-schema' package or a RouteValidationFunction at key: [${key}].` ); } }); } - return route.validate ? route.validate : undefined; + if (route.validate) { + return RouteValidator.from(route.validate); + } } /** @@ -174,12 +160,7 @@ function routeSchemasFromRouteConfig< */ function validOptions( method: RouteMethod, - routeConfig: RouteConfig< - ObjectType, - ObjectType, - ObjectType | Type | Type, - typeof method - > + routeConfig: RouteConfig ) { const shouldNotHavePayload = ['head', 'get'].includes(method); const { options = {}, validate } = routeConfig; @@ -225,11 +206,7 @@ export class Router implements IRouter { private readonly log: Logger, private readonly enhanceWithContext: ContextEnhancer ) { - const buildMethod = (method: Method) => < - P extends ObjectType, - Q extends ObjectType, - B extends ObjectType | Type | Type - >( + const buildMethod = (method: Method) => ( route: RouteConfig, handler: RequestHandler ) => { @@ -260,17 +237,11 @@ export class Router implements IRouter { return [...this.routes]; } - public handleLegacyErrors

( - handler: RequestHandler - ): RequestHandler { + public handleLegacyErrors(handler: RequestHandler): RequestHandler { return wrapErrors(handler); } - private async handle< - P extends ObjectType, - Q extends ObjectType, - B extends ObjectType | Type | Type - >({ + private async handle({ routeSchemas, request, responseToolkit, @@ -279,9 +250,9 @@ export class Router implements IRouter { request: Request; responseToolkit: ResponseToolkit; handler: RequestHandlerEnhanced; - routeSchemas?: RouteSchemas; + routeSchemas?: RouteValidator; }) { - let kibanaRequest: KibanaRequest, TypeOf, TypeOf, typeof request.method>; + let kibanaRequest: KibanaRequest; const hapiResponseAdapter = new HapiResponseAdapter(responseToolkit); try { kibanaRequest = KibanaRequest.from(request, routeSchemas); @@ -303,12 +274,9 @@ type WithoutHeadArgument = T extends (first: any, ...rest: infer Params) => i ? (...rest: Params) => Return : never; -type RequestHandlerEnhanced< - P extends ObjectType, - Q extends ObjectType, - B extends ObjectType | Type | Type, - Method extends RouteMethod -> = WithoutHeadArgument>; +type RequestHandlerEnhanced = WithoutHeadArgument< + RequestHandler +>; /** * A function executed when route path matched requested resource path. @@ -345,12 +313,12 @@ type RequestHandlerEnhanced< * @public */ export type RequestHandler< - P extends ObjectType, - Q extends ObjectType, - B extends ObjectType | Type | Type, + P = unknown, + Q = unknown, + B = unknown, Method extends RouteMethod = any > = ( context: RequestHandlerContext, - request: KibanaRequest, TypeOf, TypeOf, Method>, + request: KibanaRequest, response: KibanaResponseFactory ) => IKibanaResponse | Promise>; diff --git a/src/core/server/http/router/validator/index.ts b/src/core/server/http/router/validator/index.ts new file mode 100644 index 0000000000000..edb116c40144a --- /dev/null +++ b/src/core/server/http/router/validator/index.ts @@ -0,0 +1,29 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export { + RouteValidator, + RouteValidatorConfig, + RouteValidationSpec, + RouteValidationFunction, + RouteValidatorOptions, + RouteValidatorFullConfig, + RouteValidationResultFactory, +} from './validator'; +export { RouteValidationError } from './validator_error'; diff --git a/src/core/server/http/router/validator/validator.test.ts b/src/core/server/http/router/validator/validator.test.ts new file mode 100644 index 0000000000000..729eb1b60c10a --- /dev/null +++ b/src/core/server/http/router/validator/validator.test.ts @@ -0,0 +1,135 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { RouteValidationError, RouteValidator } from './'; +import { schema, Type } from '@kbn/config-schema'; + +describe('Router validator', () => { + it('should validate and infer the type from a function', () => { + const validator = RouteValidator.from({ + params: ({ foo }, validationResult) => { + if (typeof foo === 'string') { + return validationResult.ok({ foo }); + } + return validationResult.badRequest('Not a string', ['foo']); + }, + }); + expect(validator.getParams({ foo: 'bar' })).toStrictEqual({ foo: 'bar' }); + expect(validator.getParams({ foo: 'bar' }).foo.toUpperCase()).toBe('BAR'); // It knows it's a string! :) + expect(() => validator.getParams({ foo: 1 })).toThrowError('[foo]: Not a string'); + expect(() => validator.getParams({})).toThrowError('[foo]: Not a string'); + + expect(() => validator.getParams(undefined)).toThrowError( + "Cannot destructure property `foo` of 'undefined' or 'null'." + ); + expect(() => validator.getParams({}, 'myField')).toThrowError('[myField.foo]: Not a string'); + + expect(validator.getBody(undefined)).toStrictEqual({}); + expect(validator.getQuery(undefined)).toStrictEqual({}); + }); + + it('should validate and infer the type from a function that does not use the resolver', () => { + const validator = RouteValidator.from({ + params: data => { + if (typeof data.foo === 'string') { + return { value: { foo: data.foo as string } }; + } + return { error: new RouteValidationError('Not a string', ['foo']) }; + }, + }); + expect(validator.getParams({ foo: 'bar' })).toStrictEqual({ foo: 'bar' }); + expect(validator.getParams({ foo: 'bar' }).foo.toUpperCase()).toBe('BAR'); // It knows it's a string! :) + expect(() => validator.getParams({ foo: 1 })).toThrowError('[foo]: Not a string'); + expect(() => validator.getParams({})).toThrowError('[foo]: Not a string'); + + expect(() => validator.getParams(undefined)).toThrowError( + `Cannot read property 'foo' of undefined` + ); + expect(() => validator.getParams({}, 'myField')).toThrowError('[myField.foo]: Not a string'); + + expect(validator.getBody(undefined)).toStrictEqual({}); + expect(validator.getQuery(undefined)).toStrictEqual({}); + }); + + it('should validate and infer the type from a config-schema ObjectType', () => { + const schemaValidation = RouteValidator.from({ + params: schema.object({ + foo: schema.string(), + }), + }); + + expect(schemaValidation.getParams({ foo: 'bar' })).toStrictEqual({ foo: 'bar' }); + expect(schemaValidation.getParams({ foo: 'bar' }).foo.toUpperCase()).toBe('BAR'); // It knows it's a string! :) + expect(() => schemaValidation.getParams({ foo: 1 })).toThrowError( + '[foo]: expected value of type [string] but got [number]' + ); + expect(() => schemaValidation.getParams({})).toThrowError( + '[foo]: expected value of type [string] but got [undefined]' + ); + expect(() => schemaValidation.getParams(undefined)).toThrowError( + '[foo]: expected value of type [string] but got [undefined]' + ); + expect(() => schemaValidation.getParams({}, 'myField')).toThrowError( + '[myField.foo]: expected value of type [string] but got [undefined]' + ); + }); + + it('should validate and infer the type from a config-schema non-ObjectType', () => { + const schemaValidation = RouteValidator.from({ params: schema.buffer() }); + + const foo = Buffer.from('hi!'); + expect(schemaValidation.getParams(foo)).toStrictEqual(foo); + expect(schemaValidation.getParams(foo).byteLength).toBeGreaterThan(0); // It knows it's a buffer! :) + expect(() => schemaValidation.getParams({ foo: 1 })).toThrowError( + 'expected value of type [Buffer] but got [Object]' + ); + expect(() => schemaValidation.getParams({})).toThrowError( + 'expected value of type [Buffer] but got [Object]' + ); + expect(() => schemaValidation.getParams(undefined)).toThrowError( + `expected value of type [Buffer] but got [undefined]` + ); + expect(() => schemaValidation.getParams({}, 'myField')).toThrowError( + '[myField]: expected value of type [Buffer] but got [Object]' + ); + }); + + it('should catch the errors thrown by the validate function', () => { + const validator = RouteValidator.from({ + params: data => { + throw new Error('Something went terribly wrong'); + }, + }); + + expect(() => validator.getParams({ foo: 1 })).toThrowError('Something went terribly wrong'); + expect(() => validator.getParams({}, 'myField')).toThrowError( + '[myField]: Something went terribly wrong' + ); + }); + + it('should not accept invalid validation options', () => { + const wrongValidateSpec = RouteValidator.from({ + params: { validate: (data: T): T => data } as Type, + }); + + expect(() => wrongValidateSpec.getParams({ foo: 1 })).toThrowError( + 'The validation rule provided in the handler is not valid' + ); + }); +}); diff --git a/src/core/server/http/router/validator/validator.ts b/src/core/server/http/router/validator/validator.ts new file mode 100644 index 0000000000000..65c0a934e6ef0 --- /dev/null +++ b/src/core/server/http/router/validator/validator.ts @@ -0,0 +1,280 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { ValidationError, Type, schema, ObjectType } from '@kbn/config-schema'; +import { Stream } from 'stream'; +import { RouteValidationError } from './validator_error'; + +/** + * Validation result factory to be used in the custom validation function to return the valid data or validation errors + * + * See {@link RouteValidationFunction}. + * + * @public + */ +export interface RouteValidationResultFactory { + ok: (value: T) => { value: T }; + badRequest: (error: Error | string, path?: string[]) => { error: RouteValidationError }; +} + +/** + * The custom validation function if @kbn/config-schema is not a valid solution for your specific plugin requirements. + * + * @example + * + * The validation should look something like: + * ```typescript + * interface MyExpectedBody { + * bar: string; + * baz: number; + * } + * + * const myBodyValidation: RouteValidationFunction = (data, validationResult) => { + * const { ok, badRequest } = validationResult; + * const { bar, baz } = data || {}; + * if (typeof bar === 'string' && typeof baz === 'number') { + * return ok({ bar, baz }); + * } else { + * return badRequest('Wrong payload', ['body']); + * } + * } + * ``` + * + * @public + */ +export type RouteValidationFunction = ( + data: any, + validationResult: RouteValidationResultFactory +) => + | { + value: T; + error?: never; + } + | { + value?: never; + error: RouteValidationError; + }; + +/** + * Allowed property validation options: either @kbn/config-schema validations or custom validation functions + * + * See {@link RouteValidationFunction} for custom validation. + * + * @public + */ +export type RouteValidationSpec = ObjectType | Type | RouteValidationFunction; + +// Ugly as hell but we need this conditional typing to have proper type inference +type RouteValidationResultType | undefined> = NonNullable< + T extends RouteValidationFunction + ? ReturnType['value'] + : T extends Type + ? ReturnType + : undefined +>; + +/** + * The configuration object to the RouteValidator class. + * Set `params`, `query` and/or `body` to specify the validation logic to follow for that property. + * + * @public + */ +export interface RouteValidatorConfig { + /** + * Validation logic for the URL params + * @public + */ + params?: RouteValidationSpec

; + /** + * Validation logic for the Query params + * @public + */ + query?: RouteValidationSpec; + /** + * Validation logic for the body payload + * @public + */ + body?: RouteValidationSpec; +} + +/** + * Additional options for the RouteValidator class to modify its default behaviour. + * + * @public + */ +export interface RouteValidatorOptions { + /** + * Set the `unsafe` config to avoid running some additional internal *safe* validations on top of your custom validation + * @public + */ + unsafe?: { + params?: boolean; + query?: boolean; + body?: boolean; + }; +} + +/** + * Route validations config and options merged into one object + * @public + */ +export type RouteValidatorFullConfig = RouteValidatorConfig & + RouteValidatorOptions; + +/** + * Route validator class to define the validation logic for each new route. + * + * @internal + */ +export class RouteValidator

{ + public static from

( + opts: RouteValidator | RouteValidatorFullConfig + ) { + if (opts instanceof RouteValidator) { + return opts; + } + const { params, query, body, ...options } = opts; + return new RouteValidator({ params, query, body }, options); + } + + private static ResultFactory: RouteValidationResultFactory = { + ok: (value: T) => ({ value }), + badRequest: (error: Error | string, path?: string[]) => ({ + error: new RouteValidationError(error, path), + }), + }; + + private constructor( + private readonly config: RouteValidatorConfig, + private readonly options: RouteValidatorOptions = {} + ) {} + + /** + * Get validated URL params + * @internal + */ + public getParams(data: unknown, namespace?: string): Readonly

{ + return this.validate(this.config.params, this.options.unsafe?.params, data, namespace); + } + + /** + * Get validated query params + * @internal + */ + public getQuery(data: unknown, namespace?: string): Readonly { + return this.validate(this.config.query, this.options.unsafe?.query, data, namespace); + } + + /** + * Get validated body + * @internal + */ + public getBody(data: unknown, namespace?: string): Readonly { + return this.validate(this.config.body, this.options.unsafe?.body, data, namespace); + } + + /** + * Has body validation + * @internal + */ + public hasBody(): boolean { + return typeof this.config.body !== 'undefined'; + } + + private validate( + validationRule?: RouteValidationSpec, + unsafe?: boolean, + data?: unknown, + namespace?: string + ): RouteValidationResultType { + if (typeof validationRule === 'undefined') { + return {}; + } + let precheckedData = this.preValidateSchema(data).validate(data, {}, namespace); + + if (unsafe !== true) { + precheckedData = this.safetyPrechecks(precheckedData, namespace); + } + + const customCheckedData = this.customValidation(validationRule, precheckedData, namespace); + + if (unsafe === true) { + return customCheckedData; + } + + return this.safetyPostchecks(customCheckedData, namespace); + } + + private safetyPrechecks(data: T, namespace?: string): T { + // We can add any pre-validation safety logic in here + return data; + } + + private safetyPostchecks(data: T, namespace?: string): T { + // We can add any post-validation safety logic in here + return data; + } + + private customValidation( + validationRule: RouteValidationSpec, + data?: unknown, + namespace?: string + ): RouteValidationResultType { + if (validationRule instanceof Type) { + return validationRule.validate(data, {}, namespace); + } else if (typeof validationRule === 'function') { + return this.validateFunction(validationRule, data, namespace); + } else { + throw new ValidationError( + new RouteValidationError(`The validation rule provided in the handler is not valid`), + namespace + ); + } + } + + private validateFunction( + validateFn: RouteValidationFunction, + data: unknown, + namespace?: string + ): T { + let result: ReturnType; + try { + result = validateFn(data, RouteValidator.ResultFactory); + } catch (err) { + result = { error: new RouteValidationError(err) }; + } + + if (result.error) { + throw new ValidationError(result.error, namespace); + } + return result.value; + } + + private preValidateSchema(data: any) { + if (Buffer.isBuffer(data)) { + // if options.body.parse !== true + return schema.buffer(); + } else if (data instanceof Stream) { + // if options.body.output === 'stream' + return schema.stream(); + } else { + return schema.maybe(schema.nullable(schema.object({}, { allowUnknowns: true }))); + } + } +} diff --git a/src/core/server/http/router/validator/validator_error.ts b/src/core/server/http/router/validator/validator_error.ts new file mode 100644 index 0000000000000..d306db4ad1cf4 --- /dev/null +++ b/src/core/server/http/router/validator/validator_error.ts @@ -0,0 +1,34 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { SchemaTypeError } from '@kbn/config-schema'; + +/** + * Error to return when the validation is not successful. + * @public + */ +export class RouteValidationError extends SchemaTypeError { + constructor(error: Error | string, path: string[] = []) { + super(error, path); + + // Set the prototype explicitly, see: + // https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work + Object.setPrototypeOf(this, RouteValidationError.prototype); + } +} diff --git a/src/core/server/index.ts b/src/core/server/index.ts index 060265120b865..878f854f2a517 100644 --- a/src/core/server/index.ts +++ b/src/core/server/index.ts @@ -134,10 +134,16 @@ export { RouteRegistrar, RouteMethod, RouteConfigOptions, - RouteSchemas, RouteConfigOptionsBody, RouteContentType, validBodyOutput, + RouteValidatorConfig, + RouteValidationSpec, + RouteValidationFunction, + RouteValidatorOptions, + RouteValidatorFullConfig, + RouteValidationResultFactory, + RouteValidationError, SessionStorage, SessionStorageCookieOptions, SessionCookieValidationResult, diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md index 85c0af8131ccb..dc4518ef41253 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -115,6 +115,7 @@ import { RenderSearchTemplateParams } from 'elasticsearch'; import { Request } from 'hapi'; import { ResponseObject } from 'hapi'; import { ResponseToolkit } from 'hapi'; +import { SchemaTypeError } from '@kbn/config-schema'; import { ScrollParams } from 'elasticsearch'; import { SearchParams } from 'elasticsearch'; import { SearchResponse } from 'elasticsearch'; @@ -805,7 +806,7 @@ export interface IRouter { // // @internal getRoutes: () => RouterRoute[]; - handleLegacyErrors:

(handler: RequestHandler) => RequestHandler; + handleLegacyErrors: (handler: RequestHandler) => RequestHandler; patch: RouteRegistrar<'patch'>; post: RouteRegistrar<'post'>; put: RouteRegistrar<'put'>; @@ -841,8 +842,10 @@ export class KibanaRequest | Type>(req: Request, routeSchemas?: RouteSchemas, withoutSecretHeaders?: boolean): KibanaRequest; + static from(req: Request, routeSchemas?: RouteValidator | RouteValidatorFullConfig, withoutSecretHeaders?: boolean): KibanaRequest; readonly headers: Headers; // (undocumented) readonly params: Params; @@ -1159,7 +1162,7 @@ export type RedirectResponseOptions = HttpResponseOptions & { }; // @public -export type RequestHandler

| Type, Method extends RouteMethod = any> = (context: RequestHandlerContext, request: KibanaRequest, TypeOf, TypeOf, Method>, response: KibanaResponseFactory) => IKibanaResponse | Promise>; +export type RequestHandler

= (context: RequestHandlerContext, request: KibanaRequest, response: KibanaResponseFactory) => IKibanaResponse | Promise>; // @public export interface RequestHandlerContext { @@ -1201,10 +1204,10 @@ export type ResponseHeaders = { }; // @public -export interface RouteConfig

| Type, Method extends RouteMethod> { +export interface RouteConfig { options?: RouteConfigOptions; path: string; - validate: RouteSchemas | false; + validate: RouteValidatorFullConfig | false; } // @public @@ -1229,16 +1232,54 @@ export type RouteContentType = 'application/json' | 'application/*+json' | 'appl export type RouteMethod = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options'; // @public -export type RouteRegistrar =

| Type>(route: RouteConfig, handler: RequestHandler) => void; +export type RouteRegistrar = (route: RouteConfig, handler: RequestHandler) => void; // @public -export interface RouteSchemas

| Type> { - // (undocumented) - body?: B; +export class RouteValidationError extends SchemaTypeError { + constructor(error: Error | string, path?: string[]); +} + +// @public +export type RouteValidationFunction = (data: any, validationResult: RouteValidationResultFactory) => { + value: T; + error?: never; +} | { + value?: never; + error: RouteValidationError; +}; + +// @public +export interface RouteValidationResultFactory { // (undocumented) - params?: P; + badRequest: (error: Error | string, path?: string[]) => { + error: RouteValidationError; + }; // (undocumented) - query?: Q; + ok: (value: T) => { + value: T; + }; +} + +// @public +export type RouteValidationSpec = ObjectType | Type | RouteValidationFunction; + +// @public +export interface RouteValidatorConfig { + body?: RouteValidationSpec; + params?: RouteValidationSpec

; + query?: RouteValidationSpec; +} + +// @public +export type RouteValidatorFullConfig = RouteValidatorConfig & RouteValidatorOptions; + +// @public +export interface RouteValidatorOptions { + unsafe?: { + params?: boolean; + query?: boolean; + body?: boolean; + }; } // @public (undocumented) diff --git a/src/plugins/home/server/services/tutorials/lib/tutorials_registry_types.ts b/src/plugins/home/server/services/tutorials/lib/tutorials_registry_types.ts index d081639e5c7e2..951ce935760a1 100644 --- a/src/plugins/home/server/services/tutorials/lib/tutorials_registry_types.ts +++ b/src/plugins/home/server/services/tutorials/lib/tutorials_registry_types.ts @@ -94,17 +94,5 @@ export interface TutorialSchema { savedObjectsInstallMsg: string; } export type TutorialProvider = (context: { [key: string]: unknown }) => TutorialSchema; -export type TutorialContextFactory = ( - req: KibanaRequest< - Readonly<{ - [x: string]: any; - }>, - Readonly<{ - [x: string]: any; - }>, - Readonly<{ - [x: string]: any; - }> - > -) => { [key: string]: unknown }; +export type TutorialContextFactory = (req: KibanaRequest) => { [key: string]: unknown }; export type ScopedTutorialContextFactory = (...args: any[]) => any; diff --git a/test/plugin_functional/plugins/core_plugin_b/server/plugin.ts b/test/plugin_functional/plugins/core_plugin_b/server/plugin.ts index 771e50b22f66b..91a4fe89c1c57 100644 --- a/test/plugin_functional/plugins/core_plugin_b/server/plugin.ts +++ b/test/plugin_functional/plugins/core_plugin_b/server/plugin.ts @@ -18,6 +18,7 @@ */ import { Plugin, CoreSetup } from 'kibana/server'; +import { schema } from '@kbn/config-schema'; import { PluginARequestContext } from '../../core_plugin_a/server'; declare module 'kibana/server' { @@ -34,6 +35,25 @@ export class CorePluginBPlugin implements Plugin { const response = await context.pluginA.ping(); return res.ok({ body: `Pong via plugin A: ${response}` }); }); + + router.post( + { + path: '/core_plugin_b', + validate: { + query: schema.object({ id: schema.string() }), + body: ({ bar, baz } = {}, { ok, badRequest }) => { + if (typeof bar === 'string' && bar === baz) { + return ok({ bar, baz }); + } else { + return badRequest(`bar: ${bar} !== baz: ${baz} or they are not string`); + } + }, + }, + }, + async (context, req, res) => { + return res.ok({ body: `ID: ${req.query.id} - ${req.body.bar.toUpperCase()}` }); + } + ); } public start() {} diff --git a/test/plugin_functional/test_suites/core_plugins/server_plugins.ts b/test/plugin_functional/test_suites/core_plugins/server_plugins.ts index 3881af5642996..d437912c1b69a 100644 --- a/test/plugin_functional/test_suites/core_plugins/server_plugins.ts +++ b/test/plugin_functional/test_suites/core_plugins/server_plugins.ts @@ -29,5 +29,29 @@ export default function({ getService }: PluginFunctionalProviderContext) { .expect(200) .expect('Pong via plugin A: true'); }); + + it('extend request handler context with validation', async () => { + await supertest + .post('/core_plugin_b') + .set('kbn-xsrf', 'anything') + .query({ id: 'TEST' }) + .send({ bar: 'hi!', baz: 'hi!' }) + .expect(200) + .expect('ID: TEST - HI!'); + }); + + it('extend request handler context with validation (400)', async () => { + await supertest + .post('/core_plugin_b') + .set('kbn-xsrf', 'anything') + .query({ id: 'TEST' }) + .send({ bar: 'hi!', baz: 1234 }) + .expect(400) + .expect({ + error: 'Bad Request', + message: '[request body]: bar: hi! !== baz: 1234 or they are not string', + statusCode: 400, + }); + }); }); } diff --git a/x-pack/legacy/plugins/apm/server/routes/create_api/index.ts b/x-pack/legacy/plugins/apm/server/routes/create_api/index.ts index 3e97d851acd29..c1a9838e90406 100644 --- a/x-pack/legacy/plugins/apm/server/routes/create_api/index.ts +++ b/x-pack/legacy/plugins/apm/server/routes/create_api/index.ts @@ -82,7 +82,7 @@ export function createApi() { // if any validation is defined. Not having validation currently // means we don't get the payload. See // https://github.com/elastic/kibana/issues/50179 - body: schema.nullable(anyObject) as typeof anyObject, + body: schema.nullable(anyObject), params: anyObject, query: anyObject } diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/framework/adapter_types.ts b/x-pack/legacy/plugins/infra/server/lib/adapters/framework/adapter_types.ts index 5b4ada31a6b0c..71f6a4db8c30d 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/framework/adapter_types.ts +++ b/x-pack/legacy/plugins/infra/server/lib/adapters/framework/adapter_types.ts @@ -6,7 +6,6 @@ import { SearchResponse, GenericParams } from 'elasticsearch'; import { Lifecycle } from 'hapi'; -import { ObjectType } from '@kbn/config-schema'; import { UsageCollectionSetup } from 'src/plugins/usage_collection/server'; import { RouteMethod, RouteConfig } from '../../../../../../../../src/core/server'; import { PluginSetupContract as FeaturesPluginSetup } from '../../../../../../../plugins/features/server'; @@ -166,11 +165,6 @@ export interface InfraTSVBSeries { export type InfraTSVBDataPoint = [number, number]; -export type InfraRouteConfig< - params extends ObjectType, - query extends ObjectType, - body extends ObjectType, - method extends RouteMethod -> = { +export type InfraRouteConfig = { method: RouteMethod; } & RouteConfig; diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/framework/kibana_framework_adapter.ts b/x-pack/legacy/plugins/infra/server/lib/adapters/framework/kibana_framework_adapter.ts index d7dd4ed1c82a4..4409667d8390a 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/framework/kibana_framework_adapter.ts +++ b/x-pack/legacy/plugins/infra/server/lib/adapters/framework/kibana_framework_adapter.ts @@ -10,7 +10,7 @@ import { GenericParams } from 'elasticsearch'; import { GraphQLSchema } from 'graphql'; import { Legacy } from 'kibana'; import { runHttpQuery } from 'apollo-server-core'; -import { schema, TypeOf, ObjectType } from '@kbn/config-schema'; +import { schema, TypeOf } from '@kbn/config-schema'; import { InfraRouteConfig, InfraTSVBResponse, @@ -43,12 +43,7 @@ export class KibanaFramework { this.plugins = plugins; } - public registerRoute< - params extends ObjectType = any, - query extends ObjectType = any, - body extends ObjectType = any, - method extends RouteMethod = any - >( + public registerRoute( config: InfraRouteConfig, handler: RequestHandler ) { diff --git a/x-pack/plugins/canvas/server/routes/catch_error_handler.ts b/x-pack/plugins/canvas/server/routes/catch_error_handler.ts index fb7f4d6ee2600..4717d8762ffe2 100644 --- a/x-pack/plugins/canvas/server/routes/catch_error_handler.ts +++ b/x-pack/plugins/canvas/server/routes/catch_error_handler.ts @@ -4,14 +4,9 @@ * you may not use this file except in compliance with the Elastic License. */ -import { ObjectType } from '@kbn/config-schema'; import { RequestHandler } from 'src/core/server'; -export const catchErrorHandler: < - P extends ObjectType, - Q extends ObjectType, - B extends ObjectType ->( +export const catchErrorHandler: ( fn: RequestHandler ) => RequestHandler = fn => { return async (context, request, response) => { diff --git a/x-pack/plugins/security/server/authorization/register_privileges_with_cluster.test.ts b/x-pack/plugins/security/server/authorization/register_privileges_with_cluster.test.ts index c18c071ca7675..dc406c17925dd 100644 --- a/x-pack/plugins/security/server/authorization/register_privileges_with_cluster.test.ts +++ b/x-pack/plugins/security/server/authorization/register_privileges_with_cluster.test.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { IClusterClient, Logger } from '../../../../../src/core/server'; +import { IClusterClient, Logger } from 'kibana/server'; import { RawKibanaPrivileges } from '../../common/model'; import { registerPrivilegesWithCluster } from './register_privileges_with_cluster'; diff --git a/x-pack/plugins/security/server/routes/authentication/saml.ts b/x-pack/plugins/security/server/routes/authentication/saml.ts index 06acf5283fe97..465ea61e12a4e 100644 --- a/x-pack/plugins/security/server/routes/authentication/saml.ts +++ b/x-pack/plugins/security/server/routes/authentication/saml.ts @@ -60,7 +60,9 @@ export function defineSAMLRoutes({ router, logger, authc, csp, basePath }: Route router.get( { path: '/api/security/saml/start', - validate: { query: schema.object({ redirectURLFragment: schema.string() }) }, + validate: { + query: schema.object({ redirectURLFragment: schema.string() }), + }, options: { authRequired: false }, }, async (context, request, response) => { diff --git a/x-pack/plugins/security/server/routes/authorization/roles/delete.ts b/x-pack/plugins/security/server/routes/authorization/roles/delete.ts index de966d6f2a758..eb56143288747 100644 --- a/x-pack/plugins/security/server/routes/authorization/roles/delete.ts +++ b/x-pack/plugins/security/server/routes/authorization/roles/delete.ts @@ -13,7 +13,9 @@ export function defineDeleteRolesRoutes({ router, clusterClient }: RouteDefiniti router.delete( { path: '/api/security/role/{name}', - validate: { params: schema.object({ name: schema.string({ minLength: 1 }) }) }, + validate: { + params: schema.object({ name: schema.string({ minLength: 1 }) }), + }, }, createLicensedRouteHandler(async (context, request, response) => { try { diff --git a/x-pack/plugins/security/server/routes/authorization/roles/get.ts b/x-pack/plugins/security/server/routes/authorization/roles/get.ts index 8c158bee1a15e..bf1140e2e6fd1 100644 --- a/x-pack/plugins/security/server/routes/authorization/roles/get.ts +++ b/x-pack/plugins/security/server/routes/authorization/roles/get.ts @@ -14,7 +14,9 @@ export function defineGetRolesRoutes({ router, authz, clusterClient }: RouteDefi router.get( { path: '/api/security/role/{name}', - validate: { params: schema.object({ name: schema.string({ minLength: 1 }) }) }, + validate: { + params: schema.object({ name: schema.string({ minLength: 1 }) }), + }, }, createLicensedRouteHandler(async (context, request, response) => { try { diff --git a/x-pack/plugins/security/server/routes/licensed_route_handler.ts b/x-pack/plugins/security/server/routes/licensed_route_handler.ts index 1194e3d0a83cc..bc5a6a1139215 100644 --- a/x-pack/plugins/security/server/routes/licensed_route_handler.ts +++ b/x-pack/plugins/security/server/routes/licensed_route_handler.ts @@ -4,17 +4,10 @@ * you may not use this file except in compliance with the Elastic License. */ -import { RequestHandler } from 'src/core/server'; -import { ObjectType } from '@kbn/config-schema'; +import { RequestHandler } from 'kibana/server'; import { LICENSE_CHECK_STATE } from '../../../licensing/server'; -export const createLicensedRouteHandler = < - P extends ObjectType, - Q extends ObjectType, - B extends ObjectType ->( - handler: RequestHandler -) => { +export const createLicensedRouteHandler = (handler: RequestHandler) => { const licensedRouteHandler: RequestHandler = (context, request, responseToolkit) => { const { license } = context.licensing; const licenseCheck = license.check('security', 'basic'); diff --git a/x-pack/plugins/spaces/server/routes/api/external/copy_to_space.test.ts b/x-pack/plugins/spaces/server/routes/api/external/copy_to_space.test.ts index 4f78828b14dc2..4d8d08a487e9a 100644 --- a/x-pack/plugins/spaces/server/routes/api/external/copy_to_space.test.ts +++ b/x-pack/plugins/spaces/server/routes/api/external/copy_to_space.test.ts @@ -11,7 +11,7 @@ import { mockRouteContext, mockRouteContextWithInvalidLicense, } from '../__fixtures__'; -import { CoreSetup, IRouter, kibanaResponseFactory } from 'src/core/server'; +import { CoreSetup, IRouter, kibanaResponseFactory, RouteValidatorConfig } from 'src/core/server'; import { loggingServiceMock, elasticsearchServiceMock, @@ -22,10 +22,9 @@ import { SpacesService } from '../../../spaces_service'; import { SpacesAuditLogger } from '../../../lib/audit_logger'; import { SpacesClient } from '../../../lib/spaces_client'; import { initCopyToSpacesApi } from './copy_to_space'; -import { ObjectType } from '@kbn/config-schema'; -import { RouteSchemas } from 'src/core/server/http/router/route'; import { spacesConfig } from '../../../lib/__fixtures__'; import { securityMock } from '../../../../../security/server/mocks'; +import { ObjectType } from '@kbn/config-schema'; describe('copy to space', () => { const spacesSavedObjects = createSpaces(); @@ -78,19 +77,11 @@ describe('copy to space', () => { return { copyToSpace: { - routeValidation: ctsRouteDefinition.validate as RouteSchemas< - ObjectType, - ObjectType, - ObjectType - >, + routeValidation: ctsRouteDefinition.validate as RouteValidatorConfig<{}, {}, {}>, routeHandler: ctsRouteHandler, }, resolveConflicts: { - routeValidation: resolveRouteDefinition.validate as RouteSchemas< - ObjectType, - ObjectType, - ObjectType - >, + routeValidation: resolveRouteDefinition.validate as RouteValidatorConfig<{}, {}, {}>, routeHandler: resolveRouteHandler, }, savedObjectsRepositoryMock, @@ -150,7 +141,7 @@ describe('copy to space', () => { const { copyToSpace } = await setup(); expect(() => - copyToSpace.routeValidation.body!.validate(payload) + (copyToSpace.routeValidation.body as ObjectType).validate(payload) ).toThrowErrorMatchingInlineSnapshot(`"[spaces]: duplicate space ids are not allowed"`); }); @@ -163,7 +154,7 @@ describe('copy to space', () => { const { copyToSpace } = await setup(); expect(() => - copyToSpace.routeValidation.body!.validate(payload) + (copyToSpace.routeValidation.body as ObjectType).validate(payload) ).toThrowErrorMatchingInlineSnapshot( `"[spaces.1]: lower case, a-z, 0-9, \\"_\\", and \\"-\\" are allowed"` ); @@ -181,7 +172,7 @@ describe('copy to space', () => { const { copyToSpace } = await setup(); expect(() => - copyToSpace.routeValidation.body!.validate(payload) + (copyToSpace.routeValidation.body as ObjectType).validate(payload) ).toThrowErrorMatchingInlineSnapshot(`"[objects]: duplicate objects are not allowed"`); }); @@ -322,7 +313,7 @@ describe('copy to space', () => { const { resolveConflicts } = await setup(); expect(() => - resolveConflicts.routeValidation.body!.validate(payload) + (resolveConflicts.routeValidation.body as ObjectType).validate(payload) ).toThrowErrorMatchingInlineSnapshot(`"[objects]: duplicate objects are not allowed"`); }); @@ -343,7 +334,7 @@ describe('copy to space', () => { const { resolveConflicts } = await setup(); expect(() => - resolveConflicts.routeValidation.body!.validate(payload) + (resolveConflicts.routeValidation.body as ObjectType).validate(payload) ).toThrowErrorMatchingInlineSnapshot( `"[retries.key(\\"invalid-space-id!@#$%^&*()\\")]: Invalid space id: invalid-space-id!@#$%^&*()"` ); diff --git a/x-pack/plugins/spaces/server/routes/api/external/delete.test.ts b/x-pack/plugins/spaces/server/routes/api/external/delete.test.ts index 86da3023c515e..28d5708a3873c 100644 --- a/x-pack/plugins/spaces/server/routes/api/external/delete.test.ts +++ b/x-pack/plugins/spaces/server/routes/api/external/delete.test.ts @@ -12,7 +12,7 @@ import { mockRouteContext, mockRouteContextWithInvalidLicense, } from '../__fixtures__'; -import { CoreSetup, IRouter, kibanaResponseFactory } from 'src/core/server'; +import { CoreSetup, IRouter, kibanaResponseFactory, RouteValidatorConfig } from 'src/core/server'; import { loggingServiceMock, elasticsearchServiceMock, @@ -23,10 +23,9 @@ import { SpacesService } from '../../../spaces_service'; import { SpacesAuditLogger } from '../../../lib/audit_logger'; import { SpacesClient } from '../../../lib/spaces_client'; import { initDeleteSpacesApi } from './delete'; -import { RouteSchemas } from 'src/core/server/http/router/route'; -import { ObjectType } from '@kbn/config-schema'; import { spacesConfig } from '../../../lib/__fixtures__'; import { securityMock } from '../../../../../security/server/mocks'; +import { ObjectType } from '@kbn/config-schema'; describe('Spaces Public API', () => { const spacesSavedObjects = createSpaces(); @@ -75,14 +74,16 @@ describe('Spaces Public API', () => { const [routeDefinition, routeHandler] = router.delete.mock.calls[0]; return { - routeValidation: routeDefinition.validate as RouteSchemas, + routeValidation: routeDefinition.validate as RouteValidatorConfig<{}, {}, {}>, routeHandler, }; }; it('requires a space id as part of the path', async () => { const { routeValidation } = await setup(); - expect(() => routeValidation.params!.validate({})).toThrowErrorMatchingInlineSnapshot( + expect(() => + (routeValidation.params as ObjectType).validate({}) + ).toThrowErrorMatchingInlineSnapshot( `"[id]: expected value of type [string] but got [undefined]"` ); }); diff --git a/x-pack/plugins/spaces/server/routes/api/external/post.test.ts b/x-pack/plugins/spaces/server/routes/api/external/post.test.ts index 398b2e37191b6..d82ccaa8ff380 100644 --- a/x-pack/plugins/spaces/server/routes/api/external/post.test.ts +++ b/x-pack/plugins/spaces/server/routes/api/external/post.test.ts @@ -11,7 +11,7 @@ import { mockRouteContext, mockRouteContextWithInvalidLicense, } from '../__fixtures__'; -import { CoreSetup, kibanaResponseFactory, IRouter } from 'src/core/server'; +import { CoreSetup, kibanaResponseFactory, IRouter, RouteValidatorConfig } from 'src/core/server'; import { loggingServiceMock, elasticsearchServiceMock, @@ -22,10 +22,9 @@ import { SpacesService } from '../../../spaces_service'; import { SpacesAuditLogger } from '../../../lib/audit_logger'; import { SpacesClient } from '../../../lib/spaces_client'; import { initPostSpacesApi } from './post'; -import { RouteSchemas } from 'src/core/server/http/router/route'; -import { ObjectType } from '@kbn/config-schema'; import { spacesConfig } from '../../../lib/__fixtures__'; import { securityMock } from '../../../../../security/server/mocks'; +import { ObjectType } from '@kbn/config-schema'; describe('Spaces Public API', () => { const spacesSavedObjects = createSpaces(); @@ -74,7 +73,7 @@ describe('Spaces Public API', () => { const [routeDefinition, routeHandler] = router.post.mock.calls[0]; return { - routeValidation: routeDefinition.validate as RouteSchemas, + routeValidation: routeDefinition.validate as RouteValidatorConfig<{}, {}, {}>, routeHandler, savedObjectsRepositoryMock, }; @@ -159,7 +158,7 @@ describe('Spaces Public API', () => { const { routeValidation, routeHandler, savedObjectsRepositoryMock } = await setup(); const request = httpServerMock.createKibanaRequest({ - body: routeValidation.body!.validate(payload), + body: (routeValidation.body as ObjectType).validate(payload), method: 'post', }); diff --git a/x-pack/plugins/spaces/server/routes/api/external/put.test.ts b/x-pack/plugins/spaces/server/routes/api/external/put.test.ts index 5c213b7f73f62..15837110f4d92 100644 --- a/x-pack/plugins/spaces/server/routes/api/external/put.test.ts +++ b/x-pack/plugins/spaces/server/routes/api/external/put.test.ts @@ -12,7 +12,7 @@ import { mockRouteContext, mockRouteContextWithInvalidLicense, } from '../__fixtures__'; -import { CoreSetup, IRouter, kibanaResponseFactory } from 'src/core/server'; +import { CoreSetup, IRouter, kibanaResponseFactory, RouteValidatorConfig } from 'src/core/server'; import { loggingServiceMock, elasticsearchServiceMock, @@ -23,10 +23,9 @@ import { SpacesService } from '../../../spaces_service'; import { SpacesAuditLogger } from '../../../lib/audit_logger'; import { SpacesClient } from '../../../lib/spaces_client'; import { initPutSpacesApi } from './put'; -import { RouteSchemas } from 'src/core/server/http/router/route'; -import { ObjectType } from '@kbn/config-schema'; import { spacesConfig } from '../../../lib/__fixtures__'; import { securityMock } from '../../../../../security/server/mocks'; +import { ObjectType } from '@kbn/config-schema'; describe('PUT /api/spaces/space', () => { const spacesSavedObjects = createSpaces(); @@ -75,7 +74,7 @@ describe('PUT /api/spaces/space', () => { const [routeDefinition, routeHandler] = router.put.mock.calls[0]; return { - routeValidation: routeDefinition.validate as RouteSchemas, + routeValidation: routeDefinition.validate as RouteValidatorConfig<{}, {}, {}>, routeHandler, savedObjectsRepositoryMock, }; @@ -156,7 +155,7 @@ describe('PUT /api/spaces/space', () => { params: { id: payload.id, }, - body: routeValidation.body!.validate(payload), + body: (routeValidation.body as ObjectType).validate(payload), method: 'post', }); diff --git a/x-pack/plugins/spaces/server/routes/lib/licensed_route_handler.ts b/x-pack/plugins/spaces/server/routes/lib/licensed_route_handler.ts index 3838b1d134ea2..13bed5ce58e2b 100644 --- a/x-pack/plugins/spaces/server/routes/lib/licensed_route_handler.ts +++ b/x-pack/plugins/spaces/server/routes/lib/licensed_route_handler.ts @@ -4,17 +4,10 @@ * you may not use this file except in compliance with the Elastic License. */ -import { RequestHandler } from 'src/core/server'; -import { ObjectType } from '@kbn/config-schema'; +import { RequestHandler } from 'kibana/server'; import { LICENSE_CHECK_STATE } from '../../../../licensing/server'; -export const createLicensedRouteHandler = < - P extends ObjectType, - Q extends ObjectType, - B extends ObjectType ->( - handler: RequestHandler -) => { +export const createLicensedRouteHandler = (handler: RequestHandler) => { const licensedRouteHandler: RequestHandler = (context, request, responseToolkit) => { const { license } = context.licensing; const licenseCheck = license.check('spaces', 'basic'); From 06d26f6b68aaf9d5958db49d52f75f38044b525c Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Fri, 20 Dec 2019 19:01:56 +0100 Subject: [PATCH 05/14] Enforce shimmed plugin boundaries (#52633) --- .github/CODEOWNERS | 10 +++ .../core_plugins/kibana/public/.eslintrc | 3 - .../core_plugins/kibana/public/.eslintrc.js | 72 +++++++++++++++++++ .../__tests__/dashboard_empty_screen.test.tsx | 5 +- .../__tests__/get_saved_dashboard_mock.ts | 2 +- .../kibana/public/dashboard/index.ts | 2 + .../kibana/public/dashboard/legacy_imports.ts | 4 +- .../migrations/migrate_to_730_panels.test.ts | 2 +- .../migrations/migrate_to_730_panels.ts | 2 +- .../public/dashboard/migrations/types.ts | 2 +- .../dashboard/{ => np_ready}/application.ts | 14 ++-- .../{ => np_ready}/dashboard_app.html | 0 .../{ => np_ready}/dashboard_app.tsx | 8 +-- .../dashboard_app_controller.tsx | 14 ++-- .../{ => np_ready}/dashboard_constants.ts | 0 .../{ => np_ready}/dashboard_empty_screen.tsx | 0 .../dashboard_empty_screen_constants.tsx | 0 .../{ => np_ready}/dashboard_state.test.ts | 4 +- .../{ => np_ready}/dashboard_state_manager.ts | 8 +-- .../{ => np_ready}/dashboard_strings.ts | 2 +- .../{ => np_ready}/global_state_sync.ts | 4 +- .../help_menu/help_menu_util.ts} | 9 ++- .../dashboard/{ => np_ready}/legacy_app.js | 21 ++++-- ...embeddable_saved_object_converters.test.ts | 0 .../lib/embeddable_saved_object_converters.ts | 0 .../{ => np_ready}/lib/filter_utils.ts | 2 +- .../lib/get_app_state_defaults.ts | 4 +- .../dashboard/{ => np_ready}/lib/index.ts | 0 .../lib/migrate_app_state.test.ts | 0 .../{ => np_ready}/lib/migrate_app_state.ts | 4 +- .../{ => np_ready}/lib/save_dashboard.ts | 2 +- .../lib/update_saved_dashboard.ts | 4 +- .../dashboard_listing.test.js.snap | 0 .../listing/dashboard_listing.js | 7 +- .../listing/dashboard_listing.test.js | 17 ++--- .../listing/dashboard_listing_ng_wrapper.html | 1 + .../{ => np_ready}/np_core.test.mocks.ts | 0 .../__snapshots__/clone_modal.test.js.snap | 0 .../__snapshots__/save_modal.test.js.snap | 0 .../top_nav/clone_modal.test.js | 0 .../{ => np_ready}/top_nav/clone_modal.tsx | 0 .../top_nav/get_top_nav_config.ts | 2 +- .../{ => np_ready}/top_nav/options.tsx | 0 .../{ => np_ready}/top_nav/save_modal.test.js | 2 +- .../{ => np_ready}/top_nav/save_modal.tsx | 2 +- .../top_nav/show_clone_modal.tsx | 0 .../top_nav/show_options_popover.tsx | 0 .../{ => np_ready}/top_nav/top_nav_ids.ts | 0 .../public/dashboard/{ => np_ready}/types.ts | 6 +- .../kibana/public/dashboard/plugin.ts | 6 +- .../saved_dashboard/saved_dashboard.ts | 2 +- .../__tests__/directives/field_calculator.js | 2 +- .../doc_table}/doc_table.js | 0 .../doc_table}/lib/get_sort.js | 2 +- .../doc_table}/lib/rows_headers.js | 0 .../query_parameters}/_utils.js | 0 .../query_parameters}/action_add_filter.js | 4 +- .../action_set_predecessor_count.js | 2 +- .../action_set_query_parameters.js | 2 +- .../action_set_successor_count.js | 2 +- .../kibana/public/discover/_index.scss | 26 +------ .../discover/angular/doc_table/_index.scss | 2 - .../angular/doc_table/components/_index.scss | 2 - .../components/table_row/_index.scss | 3 - .../discover/{helpers => }/build_services.ts | 13 ++-- .../components/field_chooser/_index.scss | 1 - .../public/discover/get_inner_angular.ts | 24 +++---- .../kibana/public/discover/kibana_services.ts | 14 +++- .../discover/{ => np_ready}/_discover.scss | 0 .../discover/{ => np_ready}/_hacks.scss | 0 .../public/discover/np_ready/_index.scss | 15 ++++ .../discover/{ => np_ready}/_mixins.scss | 0 .../discover/np_ready/angular/_index.scss | 3 + .../{ => np_ready}/angular/context.html | 0 .../{ => np_ready}/angular/context.js | 4 +- .../{ => np_ready}/angular/context/NOTES.md | 0 .../angular/context/_index.scss | 0 .../angular/context/api/__tests__/_stubs.js | 2 +- .../angular/context/api/__tests__/anchor.js | 0 .../context/api/__tests__/predecessors.js | 0 .../context/api/__tests__/successors.js | 0 .../angular/context/api/anchor.js | 0 .../angular/context/api/context.ts | 4 +- .../utils/__tests__/date_conversion.test.ts | 0 .../api/utils/__tests__/sorting.test.ts | 0 .../context/api/utils/date_conversion.ts | 0 .../api/utils/fetch_hits_in_interval.ts | 2 +- .../context/api/utils/generate_intervals.ts | 2 +- .../api/utils/get_es_query_search_after.ts | 0 .../context/api/utils/get_es_query_sort.ts | 2 +- .../angular/context/api/utils/sorting.ts | 2 +- .../components/action_bar/_action_bar.scss | 0 .../context/components/action_bar/_index.scss | 0 .../components/action_bar/action_bar.test.tsx | 0 .../components/action_bar/action_bar.tsx | 0 .../action_bar/action_bar_directive.ts | 2 +- .../action_bar/action_bar_warning.tsx | 0 .../context/components/action_bar/index.ts | 0 .../angular/context/query/actions.js | 4 +- .../angular/context/query/constants.js | 0 .../angular/context/query/index.js | 0 .../angular/context/query/state.js | 0 .../context/query_parameters/actions.js | 4 +- .../context/query_parameters/constants.ts | 0 .../angular/context/query_parameters/index.js | 0 .../angular/context/query_parameters/state.ts | 0 .../{ => np_ready}/angular/context_app.html | 0 .../{ => np_ready}/angular/context_app.js | 5 +- .../__snapshots__/no_results.test.js.snap | 0 .../angular/directives/_histogram.scss | 0 .../angular/directives/_index.scss | 0 .../angular/directives/_no_results.scss | 0 .../angular/directives/histogram.tsx | 2 +- .../angular/directives/index.js | 3 +- .../angular/directives/no_results.js | 2 +- .../angular/directives/no_results.test.js | 2 +- .../angular/directives/uninitialized.tsx | 0 .../directives/unsupported_index_pattern.js | 0 .../{ => np_ready}/angular/discover.html | 0 .../{ => np_ready}/angular/discover.js | 9 +-- .../discover/{ => np_ready}/angular/doc.html | 0 .../discover/{ => np_ready}/angular/doc.ts | 2 +- .../angular/doc_table/_doc_table.scss | 0 .../np_ready/angular/doc_table/_index.scss | 2 + .../angular/doc_table/actions/columns.ts | 0 .../angular/doc_table/components/_index.scss | 2 + .../doc_table/components/_table_header.scss | 0 .../tool_bar_pager_buttons.test.tsx.snap | 0 .../tool_bar_pager_text.test.tsx.snap | 0 .../doc_table/components/pager/index.ts | 2 +- .../pager/tool_bar_pager_buttons.test.tsx | 0 .../pager/tool_bar_pager_buttons.tsx | 0 .../pager/tool_bar_pager_text.test.tsx | 0 .../components/pager/tool_bar_pager_text.tsx | 0 .../doc_table/components/table_header.ts | 2 +- .../__snapshots__/table_header.test.tsx.snap | 0 .../components/table_header/helpers.tsx | 4 +- .../table_header/table_header.test.tsx | 2 +- .../components/table_header/table_header.tsx | 2 +- .../table_header/table_header_column.tsx | 0 .../angular/doc_table/components/table_row.ts | 6 +- .../doc_table/components/table_row/_cell.scss | 0 .../components/table_row/_details.scss | 0 .../components/table_row/_index.scss | 3 + .../doc_table/components/table_row/_open.scss | 0 .../doc_table/components/table_row/cell.html | 0 .../components/table_row/details.html | 0 .../doc_table/components/table_row/open.html | 0 .../table_row/truncate_by_height.html | 0 .../angular/doc_table/doc_table.html | 0 .../angular/doc_table/doc_table.ts | 2 +- .../angular/doc_table/doc_table_strings.js | 0 .../{ => np_ready}/angular/doc_table/index.ts | 0 .../angular/doc_table/infinite_scroll.ts | 0 .../angular/doc_table/lib/get_sort.d.ts | 2 +- .../angular/doc_table/lib/get_sort.js | 0 .../lib/get_sort_for_search_source.ts | 2 +- .../angular/doc_table/lib/pager/index.js | 0 .../angular/doc_table/lib/pager/pager.js | 0 .../doc_table/lib/pager/pager_factory.ts | 0 .../{ => np_ready}/angular/doc_viewer.ts | 0 .../angular/get_painless_error.ts | 0 .../discover/{ => np_ready}/angular/index.ts | 0 .../discover/{ => np_ready}/application.ts | 0 .../discover/np_ready/components/_index.scss | 3 + .../components/doc/doc.test.tsx | 2 +- .../{ => np_ready}/components/doc/doc.tsx | 2 +- .../components/doc/use_es_doc_search.test.tsx | 0 .../components/doc/use_es_doc_search.ts | 2 +- .../__snapshots__/doc_viewer.test.tsx.snap | 0 .../doc_viewer_render_tab.test.tsx.snap | 0 .../components/doc_viewer/_doc_viewer.scss | 0 .../components/doc_viewer/_index.scss | 0 .../components/doc_viewer/doc_viewer.test.tsx | 33 ++++++--- .../components/doc_viewer/doc_viewer.tsx | 3 +- .../doc_viewer/doc_viewer_render_error.tsx | 3 +- .../doc_viewer/doc_viewer_render_tab.test.tsx | 2 +- .../doc_viewer/doc_viewer_render_tab.tsx | 2 +- .../components/doc_viewer/doc_viewer_tab.tsx | 2 +- .../components/fetch_error/_fetch_error.scss | 0 .../components/fetch_error/_index.scss | 0 .../components/fetch_error/fetch_error.tsx | 2 +- .../components/fetch_error/index.js | 0 .../discover_index_pattern.test.tsx.snap | 0 .../field_chooser/_field_chooser.scss | 0 .../components/field_chooser/_index.scss | 1 + .../field_chooser/change_indexpattern.tsx | 0 .../field_chooser/discover_field.html | 0 .../field_chooser/discover_field.js | 4 +- .../discover_field_search.test.tsx | 0 .../field_chooser/discover_field_search.tsx | 0 .../discover_field_search_directive.ts | 2 +- .../discover_index_pattern.test.tsx | 0 .../field_chooser/discover_index_pattern.tsx | 0 .../discover_index_pattern_directive.ts | 2 +- .../field_chooser/field_chooser.html | 0 .../components/field_chooser/field_chooser.js | 2 +- .../lib/detail_views/string.html | 0 .../field_chooser/lib/field_calculator.js | 0 .../field_chooser/string_progress_bar.tsx | 2 +- .../components/field_chooser/types.ts | 0 .../components/help_menu/help_menu_util.js | 2 +- .../open_search_panel.test.js.snap | 0 .../components/top_nav/open_search_panel.js | 4 +- .../top_nav/open_search_panel.test.js | 2 +- .../top_nav/show_open_search_panel.js | 3 +- .../embeddable/_embeddables.scss | 0 .../{ => np_ready}/embeddable/_index.scss | 0 .../{ => np_ready}/embeddable/constants.ts | 0 .../{ => np_ready}/embeddable/index.ts | 0 .../embeddable/search_embeddable.ts | 8 +-- .../embeddable/search_embeddable_factory.ts | 7 +- .../embeddable/search_template.html | 0 .../{ => np_ready}/embeddable/types.ts | 7 +- .../{ => np_ready}/helpers/breadcrumbs.ts | 0 .../helpers/get_index_pattern_id.ts | 2 +- .../{helpers => np_ready}/register_feature.ts | 32 ++++----- .../public/discover/{ => np_ready}/types.d.ts | 2 +- .../kibana/public/discover/plugin.ts | 12 ++-- .../kibana/public/home/_index.scss | 2 +- .../application.tsx} | 2 +- .../__snapshots__/add_data.test.js.snap | 0 .../__snapshots__/home.test.js.snap | 0 .../recently_accessed.test.js.snap | 0 .../sample_data_view_data_button.test.js.snap | 0 .../__snapshots__/synopsis.test.js.snap | 0 .../__snapshots__/welcome.test.tsx.snap | 0 .../{ => np_ready}/components/_add_data.scss | 0 .../home/{ => np_ready}/components/_home.scss | 0 .../{ => np_ready}/components/_index.scss | 12 ++-- .../components/_sample_data_set_cards.scss | 0 .../{ => np_ready}/components/_synopsis.scss | 0 .../{ => np_ready}/components/_welcome.scss | 0 .../{ => np_ready}/components/add_data.js | 2 +- .../components/add_data.test.js | 4 +- .../components/feature_directory.js | 2 +- .../home/{ => np_ready}/components/home.js | 4 +- .../{ => np_ready}/components/home.test.js | 5 +- .../components/home.test.mocks.ts | 2 +- .../{ => np_ready}/components/home_app.js | 4 +- .../components/recently_accessed.js | 0 .../components/recently_accessed.test.js | 0 .../components/sample_data/index.tsx | 0 .../components/sample_data_set_card.js | 0 .../components/sample_data_set_cards.js | 2 +- .../sample_data_view_data_button.js | 2 +- .../sample_data_view_data_button.test.js | 2 +- .../{ => np_ready}/components/synopsis.js | 0 .../components/synopsis.test.js | 0 .../__snapshots__/content.test.js.snap | 0 .../__snapshots__/footer.test.js.snap | 0 .../instruction_set.test.js.snap | 0 .../__snapshots__/introduction.test.js.snap | 0 .../saved_objects_installer.test.js.snap | 0 .../__snapshots__/tutorial.test.js.snap | 0 .../components/tutorial/_tutorial.scss | 0 .../components/tutorial/content.js | 2 +- .../components/tutorial/content.test.js | 2 +- .../components/tutorial/footer.js | 0 .../components/tutorial/footer.test.js | 0 .../components/tutorial/instruction.js | 0 .../components/tutorial/instruction_set.js | 2 +- .../tutorial/instruction_set.test.js | 2 +- .../components/tutorial/introduction.js | 0 .../components/tutorial/introduction.test.js | 2 +- .../components/tutorial/number_parameter.js | 0 .../components/tutorial/parameter_form.js | 0 .../tutorial/replace_template_strings.js | 2 +- .../tutorial/saved_objects_installer.js | 0 .../tutorial/saved_objects_installer.test.js | 0 .../tutorial/status_check_states.js | 0 .../components/tutorial/string_parameter.js | 0 .../components/tutorial/tutorial.js | 2 +- .../components/tutorial/tutorial.test.js | 4 +- .../components/tutorial_directory.js | 2 +- .../components/welcome.test.tsx | 2 +- .../{ => np_ready}/components/welcome.tsx | 2 +- .../home/{ => np_ready}/load_tutorials.js | 2 +- .../home/{ => np_ready}/sample_data_client.js | 2 +- .../core_plugins/kibana/public/home/plugin.ts | 2 +- .../core_plugins/kibana/public/index.scss | 3 +- .../kibana/public/visualize/_index.scss | 13 +--- .../public/visualize/editor/_index.scss | 1 - .../public/visualize/embeddable/_index.scss | 2 - .../kibana/public/visualize/index.ts | 3 + .../public/visualize/kibana_services.ts | 4 +- .../kibana/public/visualize/legacy_imports.ts | 5 +- .../public/visualize/listing/_index.scss | 1 - .../public/visualize/np_ready/_index.scss | 10 +++ .../visualize/{ => np_ready}/application.ts | 6 +- .../visualize/{ => np_ready}/breadcrumbs.ts | 0 .../{ => np_ready}/editor/_editor.scss | 0 .../visualize/np_ready/editor/_index.scss | 1 + .../{ => np_ready}/editor/editor.html | 0 .../visualize/{ => np_ready}/editor/editor.js | 14 ++-- .../{ => np_ready}/editor/lib/index.js | 0 .../editor/lib/migrate_app_state.js | 0 .../{ => np_ready}/editor/visualization.js | 0 .../editor/visualization_editor.js | 0 .../{ => np_ready}/global_state_sync.ts | 4 +- .../help_menu/help_menu_util.js | 0 .../visualize/{ => np_ready}/legacy_app.js | 2 +- .../visualize/np_ready/listing/_index.scss | 1 + .../{ => np_ready}/listing/_listing.scss | 0 .../listing/visualize_listing.html | 1 + .../listing/visualize_listing.js | 7 +- .../listing/visualize_listing_table.js | 4 +- .../visualize/{ => np_ready}/types.d.ts | 2 +- .../visualize/{ => np_ready}/visualize_app.ts | 2 +- .../{ => np_ready}/visualize_constants.ts | 0 .../__snapshots__/new_vis_modal.test.tsx.snap | 0 .../{ => np_ready}/wizard/_dialog.scss | 0 .../visualize/np_ready/wizard/_index.scss | 1 + .../visualize/{ => np_ready}/wizard/index.ts | 0 .../wizard/new_vis_modal.test.tsx | 7 +- .../{ => np_ready}/wizard/new_vis_modal.tsx | 24 +++++-- .../wizard/search_selection/index.ts | 0 .../search_selection/search_selection.tsx | 4 +- .../{ => np_ready}/wizard/show_new_vis.tsx | 7 +- .../wizard/type_selection/index.ts | 0 .../type_selection/new_vis_help.test.tsx | 0 .../wizard/type_selection/new_vis_help.tsx | 0 .../wizard/type_selection/type_selection.tsx | 8 +-- .../wizard/type_selection/vis_help_text.tsx | 0 .../wizard/type_selection/vis_type_icon.tsx | 0 .../kibana/public/visualize/plugin.ts | 25 +++++-- .../saved_visualizations/_saved_vis.ts | 2 +- .../saved_visualization_references.test.ts | 2 +- .../saved_visualization_references.ts | 2 +- .../saved_visualizations.ts | 2 +- .../public/visualize/wizard/_index.scss | 1 - .../_embeddables.scss | 0 .../public/visualize_embeddable/_index.scss | 2 + .../_visualize_lab_disabled.scss | 0 .../constants.ts | 0 .../disabled_lab_embeddable.tsx | 2 +- .../disabled_lab_visualization.tsx | 0 .../get_index_pattern.ts | 2 +- .../index.ts | 0 .../visualize_embeddable.ts | 8 +-- .../visualize_embeddable_factory.tsx | 15 ++-- src/legacy/core_plugins/timelion/index.ts | 2 +- .../core_plugins/timelion/public/app.js | 1 + .../ui/public/registry/doc_views_helpers.tsx | 2 +- .../styles/_legacy/components/_table.scss | 2 +- .../saved_objects/saved_object_save_modal.tsx | 2 +- .../dashboard/create_and_add_embeddables.js | 2 +- .../apps/dashboard/panel_controls.js | 2 +- .../functional/page_objects/dashboard_page.js | 2 +- .../functional/page_objects/visualize_page.js | 2 +- .../expression_types/embeddable_types.ts | 4 +- .../functions/common/saved_search.ts | 2 +- .../functions/common/saved_visualization.ts | 2 +- .../dashboard_mode/public/dashboard_viewer.js | 6 +- .../panel_actions/get_csv_panel_action.tsx | 4 +- .../public/app/lib/kibana/kibana_context.tsx | 2 +- .../legacy/plugins/transform/public/plugin.ts | 2 +- .../legacy/plugins/transform/public/shim.ts | 2 +- .../feature_controls/dashboard_security.ts | 2 +- .../feature_controls/dashboard_spaces.ts | 2 +- .../feature_controls/visualize_spaces.ts | 2 +- 361 files changed, 538 insertions(+), 384 deletions(-) delete mode 100644 src/legacy/core_plugins/kibana/public/.eslintrc create mode 100644 src/legacy/core_plugins/kibana/public/.eslintrc.js rename src/legacy/core_plugins/kibana/public/dashboard/{ => np_ready}/application.ts (95%) rename src/legacy/core_plugins/kibana/public/dashboard/{ => np_ready}/dashboard_app.html (100%) rename src/legacy/core_plugins/kibana/public/dashboard/{ => np_ready}/dashboard_app.tsx (94%) rename src/legacy/core_plugins/kibana/public/dashboard/{ => np_ready}/dashboard_app_controller.tsx (98%) rename src/legacy/core_plugins/kibana/public/dashboard/{ => np_ready}/dashboard_constants.ts (100%) rename src/legacy/core_plugins/kibana/public/dashboard/{ => np_ready}/dashboard_empty_screen.tsx (100%) rename src/legacy/core_plugins/kibana/public/dashboard/{ => np_ready}/dashboard_empty_screen_constants.tsx (100%) rename src/legacy/core_plugins/kibana/public/dashboard/{ => np_ready}/dashboard_state.test.ts (96%) rename src/legacy/core_plugins/kibana/public/dashboard/{ => np_ready}/dashboard_state_manager.ts (98%) rename src/legacy/core_plugins/kibana/public/dashboard/{ => np_ready}/dashboard_strings.ts (96%) rename src/legacy/core_plugins/kibana/public/dashboard/{ => np_ready}/global_state_sync.ts (97%) rename src/legacy/core_plugins/kibana/public/dashboard/{help_menu/help_menu_util.js => np_ready/help_menu/help_menu_util.ts} (80%) rename src/legacy/core_plugins/kibana/public/dashboard/{ => np_ready}/legacy_app.js (92%) rename src/legacy/core_plugins/kibana/public/dashboard/{ => np_ready}/lib/embeddable_saved_object_converters.test.ts (100%) rename src/legacy/core_plugins/kibana/public/dashboard/{ => np_ready}/lib/embeddable_saved_object_converters.ts (100%) rename src/legacy/core_plugins/kibana/public/dashboard/{ => np_ready}/lib/filter_utils.ts (97%) rename src/legacy/core_plugins/kibana/public/dashboard/{ => np_ready}/lib/get_app_state_defaults.ts (90%) rename src/legacy/core_plugins/kibana/public/dashboard/{ => np_ready}/lib/index.ts (100%) rename src/legacy/core_plugins/kibana/public/dashboard/{ => np_ready}/lib/migrate_app_state.test.ts (100%) rename src/legacy/core_plugins/kibana/public/dashboard/{ => np_ready}/lib/migrate_app_state.ts (96%) rename src/legacy/core_plugins/kibana/public/dashboard/{ => np_ready}/lib/save_dashboard.ts (97%) rename src/legacy/core_plugins/kibana/public/dashboard/{ => np_ready}/lib/update_saved_dashboard.ts (93%) rename src/legacy/core_plugins/kibana/public/dashboard/{ => np_ready}/listing/__snapshots__/dashboard_listing.test.js.snap (100%) rename src/legacy/core_plugins/kibana/public/dashboard/{ => np_ready}/listing/dashboard_listing.js (96%) rename src/legacy/core_plugins/kibana/public/dashboard/{ => np_ready}/listing/dashboard_listing.test.js (90%) rename src/legacy/core_plugins/kibana/public/dashboard/{ => np_ready}/listing/dashboard_listing_ng_wrapper.html (94%) rename src/legacy/core_plugins/kibana/public/dashboard/{ => np_ready}/np_core.test.mocks.ts (100%) rename src/legacy/core_plugins/kibana/public/dashboard/{ => np_ready}/top_nav/__snapshots__/clone_modal.test.js.snap (100%) rename src/legacy/core_plugins/kibana/public/dashboard/{ => np_ready}/top_nav/__snapshots__/save_modal.test.js.snap (100%) rename src/legacy/core_plugins/kibana/public/dashboard/{ => np_ready}/top_nav/clone_modal.test.js (100%) rename src/legacy/core_plugins/kibana/public/dashboard/{ => np_ready}/top_nav/clone_modal.tsx (100%) rename src/legacy/core_plugins/kibana/public/dashboard/{ => np_ready}/top_nav/get_top_nav_config.ts (98%) rename src/legacy/core_plugins/kibana/public/dashboard/{ => np_ready}/top_nav/options.tsx (100%) rename src/legacy/core_plugins/kibana/public/dashboard/{ => np_ready}/top_nav/save_modal.test.js (96%) rename src/legacy/core_plugins/kibana/public/dashboard/{ => np_ready}/top_nav/save_modal.tsx (98%) rename src/legacy/core_plugins/kibana/public/dashboard/{ => np_ready}/top_nav/show_clone_modal.tsx (100%) rename src/legacy/core_plugins/kibana/public/dashboard/{ => np_ready}/top_nav/show_options_popover.tsx (100%) rename src/legacy/core_plugins/kibana/public/dashboard/{ => np_ready}/top_nav/top_nav_ids.ts (100%) rename src/legacy/core_plugins/kibana/public/dashboard/{ => np_ready}/types.ts (96%) rename src/legacy/core_plugins/kibana/public/discover/{angular/doc_table/__tests__ => __tests__/doc_table}/doc_table.js (100%) rename src/legacy/core_plugins/kibana/public/discover/{angular/doc_table/__tests__ => __tests__/doc_table}/lib/get_sort.js (98%) rename src/legacy/core_plugins/kibana/public/discover/{angular/doc_table/__tests__ => __tests__/doc_table}/lib/rows_headers.js (100%) rename src/legacy/core_plugins/kibana/public/discover/{angular/context/query_parameters/__tests__ => __tests__/query_parameters}/_utils.js (100%) rename src/legacy/core_plugins/kibana/public/discover/{angular/context/query_parameters/__tests__ => __tests__/query_parameters}/action_add_filter.js (93%) rename src/legacy/core_plugins/kibana/public/discover/{angular/context/query_parameters/__tests__ => __tests__/query_parameters}/action_set_predecessor_count.js (95%) rename src/legacy/core_plugins/kibana/public/discover/{angular/context/query_parameters/__tests__ => __tests__/query_parameters}/action_set_query_parameters.js (96%) rename src/legacy/core_plugins/kibana/public/discover/{angular/context/query_parameters/__tests__ => __tests__/query_parameters}/action_set_successor_count.js (95%) delete mode 100644 src/legacy/core_plugins/kibana/public/discover/angular/doc_table/_index.scss delete mode 100644 src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/_index.scss delete mode 100644 src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/table_row/_index.scss rename src/legacy/core_plugins/kibana/public/discover/{helpers => }/build_services.ts (88%) delete mode 100644 src/legacy/core_plugins/kibana/public/discover/components/field_chooser/_index.scss rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/_discover.scss (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/_hacks.scss (100%) create mode 100644 src/legacy/core_plugins/kibana/public/discover/np_ready/_index.scss rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/_mixins.scss (100%) create mode 100644 src/legacy/core_plugins/kibana/public/discover/np_ready/angular/_index.scss rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/context.html (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/context.js (97%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/context/NOTES.md (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/context/_index.scss (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/context/api/__tests__/_stubs.js (98%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/context/api/__tests__/anchor.js (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/context/api/__tests__/predecessors.js (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/context/api/__tests__/successors.js (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/context/api/anchor.js (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/context/api/context.ts (97%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/context/api/utils/__tests__/date_conversion.test.ts (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/context/api/utils/__tests__/sorting.test.ts (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/context/api/utils/date_conversion.ts (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/context/api/utils/fetch_hits_in_interval.ts (97%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/context/api/utils/generate_intervals.ts (96%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/context/api/utils/get_es_query_search_after.ts (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/context/api/utils/get_es_query_sort.ts (97%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/context/api/utils/sorting.ts (96%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/context/components/action_bar/_action_bar.scss (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/context/components/action_bar/_index.scss (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/context/components/action_bar/action_bar.test.tsx (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/context/components/action_bar/action_bar.tsx (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/context/components/action_bar/action_bar_directive.ts (97%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/context/components/action_bar/action_bar_warning.tsx (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/context/components/action_bar/index.ts (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/context/query/actions.js (97%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/context/query/constants.js (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/context/query/index.js (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/context/query/state.js (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/context/query_parameters/actions.js (94%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/context/query_parameters/constants.ts (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/context/query_parameters/index.js (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/context/query_parameters/state.ts (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/context_app.html (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/context_app.js (97%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/directives/__snapshots__/no_results.test.js.snap (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/directives/_histogram.scss (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/directives/_index.scss (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/directives/_no_results.scss (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/directives/histogram.tsx (99%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/directives/index.js (91%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/directives/no_results.js (99%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/directives/no_results.test.js (98%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/directives/uninitialized.tsx (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/directives/unsupported_index_pattern.js (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/discover.html (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/discover.js (99%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/doc.html (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/doc.ts (98%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/doc_table/_doc_table.scss (100%) create mode 100644 src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/_index.scss rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/doc_table/actions/columns.ts (100%) create mode 100644 src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/_index.scss rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/doc_table/components/_table_header.scss (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/doc_table/components/pager/__snapshots__/tool_bar_pager_buttons.test.tsx.snap (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/doc_table/components/pager/__snapshots__/tool_bar_pager_text.test.tsx.snap (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/doc_table/components/pager/index.ts (94%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/doc_table/components/pager/tool_bar_pager_buttons.test.tsx (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/doc_table/components/pager/tool_bar_pager_buttons.tsx (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/doc_table/components/pager/tool_bar_pager_text.test.tsx (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/doc_table/components/pager/tool_bar_pager_text.tsx (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/doc_table/components/table_header.ts (96%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/doc_table/components/table_header/__snapshots__/table_header.test.tsx.snap (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/doc_table/components/table_header/helpers.tsx (94%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/doc_table/components/table_header/table_header.test.tsx (98%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/doc_table/components/table_header/table_header.tsx (96%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/doc_table/components/table_header/table_header_column.tsx (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/doc_table/components/table_row.ts (97%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/doc_table/components/table_row/_cell.scss (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/doc_table/components/table_row/_details.scss (100%) create mode 100644 src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/table_row/_index.scss rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/doc_table/components/table_row/_open.scss (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/doc_table/components/table_row/cell.html (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/doc_table/components/table_row/details.html (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/doc_table/components/table_row/open.html (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/doc_table/components/table_row/truncate_by_height.html (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/doc_table/doc_table.html (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/doc_table/doc_table.ts (97%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/doc_table/doc_table_strings.js (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/doc_table/index.ts (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/doc_table/infinite_scroll.ts (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/doc_table/lib/get_sort.d.ts (92%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/doc_table/lib/get_sort.js (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/doc_table/lib/get_sort_for_search_source.ts (96%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/doc_table/lib/pager/index.js (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/doc_table/lib/pager/pager.js (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/doc_table/lib/pager/pager_factory.ts (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/doc_viewer.ts (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/get_painless_error.ts (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/angular/index.ts (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/application.ts (100%) create mode 100644 src/legacy/core_plugins/kibana/public/discover/np_ready/components/_index.scss rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/components/doc/doc.test.tsx (98%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/components/doc/doc.tsx (98%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/components/doc/use_es_doc_search.test.tsx (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/components/doc/use_es_doc_search.ts (97%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/components/doc_viewer/__snapshots__/doc_viewer.test.tsx.snap (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/components/doc_viewer/__snapshots__/doc_viewer_render_tab.test.tsx.snap (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/components/doc_viewer/_doc_viewer.scss (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/components/doc_viewer/_index.scss (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/components/doc_viewer/doc_viewer.test.tsx (79%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/components/doc_viewer/doc_viewer.tsx (93%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/components/doc_viewer/doc_viewer_render_error.tsx (94%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/components/doc_viewer/doc_viewer_render_tab.test.tsx (95%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/components/doc_viewer/doc_viewer_render_tab.tsx (94%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/components/doc_viewer/doc_viewer_tab.tsx (97%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/components/fetch_error/_fetch_error.scss (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/components/fetch_error/_index.scss (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/components/fetch_error/fetch_error.tsx (99%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/components/fetch_error/index.js (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/components/field_chooser/__snapshots__/discover_index_pattern.test.tsx.snap (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/components/field_chooser/_field_chooser.scss (100%) create mode 100644 src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/_index.scss rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/components/field_chooser/change_indexpattern.tsx (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/components/field_chooser/discover_field.html (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/components/field_chooser/discover_field.js (97%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/components/field_chooser/discover_field_search.test.tsx (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/components/field_chooser/discover_field_search.tsx (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/components/field_chooser/discover_field_search_directive.ts (94%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/components/field_chooser/discover_index_pattern.test.tsx (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/components/field_chooser/discover_index_pattern.tsx (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/components/field_chooser/discover_index_pattern_directive.ts (95%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/components/field_chooser/field_chooser.html (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/components/field_chooser/field_chooser.js (99%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/components/field_chooser/lib/detail_views/string.html (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/components/field_chooser/lib/field_calculator.js (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/components/field_chooser/string_progress_bar.tsx (96%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/components/field_chooser/types.ts (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/components/help_menu/help_menu_util.js (95%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/components/top_nav/__snapshots__/open_search_panel.test.js.snap (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/components/top_nav/open_search_panel.js (95%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/components/top_nav/open_search_panel.test.js (96%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/components/top_nav/show_open_search_panel.js (93%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/embeddable/_embeddables.scss (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/embeddable/_index.scss (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/embeddable/constants.ts (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/embeddable/index.ts (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/embeddable/search_embeddable.ts (98%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/embeddable/search_embeddable_factory.ts (94%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/embeddable/search_template.html (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/embeddable/types.ts (92%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/helpers/breadcrumbs.ts (100%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/helpers/get_index_pattern_id.ts (95%) rename src/legacy/core_plugins/kibana/public/discover/{helpers => np_ready}/register_feature.ts (58%) rename src/legacy/core_plugins/kibana/public/discover/{ => np_ready}/types.d.ts (94%) rename src/legacy/core_plugins/kibana/public/home/{render_app.tsx => np_ready/application.tsx} (96%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/__snapshots__/add_data.test.js.snap (100%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/__snapshots__/home.test.js.snap (100%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/__snapshots__/recently_accessed.test.js.snap (100%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/__snapshots__/sample_data_view_data_button.test.js.snap (100%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/__snapshots__/synopsis.test.js.snap (100%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/__snapshots__/welcome.test.tsx.snap (100%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/_add_data.scss (100%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/_home.scss (100%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/_index.scss (52%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/_sample_data_set_cards.scss (100%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/_synopsis.scss (100%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/_welcome.scss (100%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/add_data.js (99%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/add_data.test.js (95%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/feature_directory.js (98%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/home.js (98%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/home.test.js (98%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/home.test.mocks.ts (96%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/home_app.js (96%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/recently_accessed.js (100%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/recently_accessed.test.js (100%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/sample_data/index.tsx (100%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/sample_data_set_card.js (100%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/sample_data_set_cards.js (99%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/sample_data_view_data_button.js (98%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/sample_data_view_data_button.test.js (97%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/synopsis.js (100%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/synopsis.test.js (100%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/tutorial/__snapshots__/content.test.js.snap (100%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/tutorial/__snapshots__/footer.test.js.snap (100%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/tutorial/__snapshots__/instruction_set.test.js.snap (100%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/tutorial/__snapshots__/introduction.test.js.snap (100%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/tutorial/__snapshots__/saved_objects_installer.test.js.snap (100%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/tutorial/__snapshots__/tutorial.test.js.snap (100%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/tutorial/_tutorial.scss (100%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/tutorial/content.js (94%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/tutorial/content.test.js (95%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/tutorial/footer.js (100%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/tutorial/footer.test.js (100%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/tutorial/instruction.js (100%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/tutorial/instruction_set.js (99%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/tutorial/instruction_set.test.js (98%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/tutorial/introduction.js (100%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/tutorial/introduction.test.js (97%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/tutorial/number_parameter.js (100%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/tutorial/parameter_form.js (100%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/tutorial/replace_template_strings.js (97%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/tutorial/saved_objects_installer.js (100%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/tutorial/saved_objects_installer.test.js (100%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/tutorial/status_check_states.js (100%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/tutorial/string_parameter.js (100%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/tutorial/tutorial.js (99%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/tutorial/tutorial.test.js (97%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/tutorial_directory.js (99%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/welcome.test.tsx (98%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/components/welcome.tsx (99%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/load_tutorials.js (98%) rename src/legacy/core_plugins/kibana/public/home/{ => np_ready}/sample_data_client.js (97%) delete mode 100644 src/legacy/core_plugins/kibana/public/visualize/editor/_index.scss delete mode 100644 src/legacy/core_plugins/kibana/public/visualize/embeddable/_index.scss delete mode 100644 src/legacy/core_plugins/kibana/public/visualize/listing/_index.scss create mode 100644 src/legacy/core_plugins/kibana/public/visualize/np_ready/_index.scss rename src/legacy/core_plugins/kibana/public/visualize/{ => np_ready}/application.ts (97%) rename src/legacy/core_plugins/kibana/public/visualize/{ => np_ready}/breadcrumbs.ts (100%) rename src/legacy/core_plugins/kibana/public/visualize/{ => np_ready}/editor/_editor.scss (100%) create mode 100644 src/legacy/core_plugins/kibana/public/visualize/np_ready/editor/_index.scss rename src/legacy/core_plugins/kibana/public/visualize/{ => np_ready}/editor/editor.html (100%) rename src/legacy/core_plugins/kibana/public/visualize/{ => np_ready}/editor/editor.js (98%) rename src/legacy/core_plugins/kibana/public/visualize/{ => np_ready}/editor/lib/index.js (100%) rename src/legacy/core_plugins/kibana/public/visualize/{ => np_ready}/editor/lib/migrate_app_state.js (100%) rename src/legacy/core_plugins/kibana/public/visualize/{ => np_ready}/editor/visualization.js (100%) rename src/legacy/core_plugins/kibana/public/visualize/{ => np_ready}/editor/visualization_editor.js (100%) rename src/legacy/core_plugins/kibana/public/visualize/{ => np_ready}/global_state_sync.ts (97%) rename src/legacy/core_plugins/kibana/public/visualize/{ => np_ready}/help_menu/help_menu_util.js (100%) rename src/legacy/core_plugins/kibana/public/visualize/{ => np_ready}/legacy_app.js (99%) create mode 100644 src/legacy/core_plugins/kibana/public/visualize/np_ready/listing/_index.scss rename src/legacy/core_plugins/kibana/public/visualize/{ => np_ready}/listing/_listing.scss (100%) rename src/legacy/core_plugins/kibana/public/visualize/{ => np_ready}/listing/visualize_listing.html (93%) rename src/legacy/core_plugins/kibana/public/visualize/{ => np_ready}/listing/visualize_listing.js (95%) rename src/legacy/core_plugins/kibana/public/visualize/{ => np_ready}/listing/visualize_listing_table.js (98%) rename src/legacy/core_plugins/kibana/public/visualize/{ => np_ready}/types.d.ts (94%) rename src/legacy/core_plugins/kibana/public/visualize/{ => np_ready}/visualize_app.ts (94%) rename src/legacy/core_plugins/kibana/public/visualize/{ => np_ready}/visualize_constants.ts (100%) rename src/legacy/core_plugins/kibana/public/visualize/{ => np_ready}/wizard/__snapshots__/new_vis_modal.test.tsx.snap (100%) rename src/legacy/core_plugins/kibana/public/visualize/{ => np_ready}/wizard/_dialog.scss (100%) create mode 100644 src/legacy/core_plugins/kibana/public/visualize/np_ready/wizard/_index.scss rename src/legacy/core_plugins/kibana/public/visualize/{ => np_ready}/wizard/index.ts (100%) rename src/legacy/core_plugins/kibana/public/visualize/{ => np_ready}/wizard/new_vis_modal.test.tsx (97%) rename src/legacy/core_plugins/kibana/public/visualize/{ => np_ready}/wizard/new_vis_modal.tsx (86%) rename src/legacy/core_plugins/kibana/public/visualize/{ => np_ready}/wizard/search_selection/index.ts (100%) rename src/legacy/core_plugins/kibana/public/visualize/{ => np_ready}/wizard/search_selection/search_selection.tsx (95%) rename src/legacy/core_plugins/kibana/public/visualize/{ => np_ready}/wizard/show_new_vis.tsx (86%) rename src/legacy/core_plugins/kibana/public/visualize/{ => np_ready}/wizard/type_selection/index.ts (100%) rename src/legacy/core_plugins/kibana/public/visualize/{ => np_ready}/wizard/type_selection/new_vis_help.test.tsx (100%) rename src/legacy/core_plugins/kibana/public/visualize/{ => np_ready}/wizard/type_selection/new_vis_help.tsx (100%) rename src/legacy/core_plugins/kibana/public/visualize/{ => np_ready}/wizard/type_selection/type_selection.tsx (97%) rename src/legacy/core_plugins/kibana/public/visualize/{ => np_ready}/wizard/type_selection/vis_help_text.tsx (100%) rename src/legacy/core_plugins/kibana/public/visualize/{ => np_ready}/wizard/type_selection/vis_type_icon.tsx (100%) delete mode 100644 src/legacy/core_plugins/kibana/public/visualize/wizard/_index.scss rename src/legacy/core_plugins/kibana/public/{visualize/embeddable => visualize_embeddable}/_embeddables.scss (100%) create mode 100644 src/legacy/core_plugins/kibana/public/visualize_embeddable/_index.scss rename src/legacy/core_plugins/kibana/public/{visualize/embeddable => visualize_embeddable}/_visualize_lab_disabled.scss (100%) rename src/legacy/core_plugins/kibana/public/{visualize/embeddable => visualize_embeddable}/constants.ts (100%) rename src/legacy/core_plugins/kibana/public/{visualize/embeddable => visualize_embeddable}/disabled_lab_embeddable.tsx (94%) rename src/legacy/core_plugins/kibana/public/{visualize/embeddable => visualize_embeddable}/disabled_lab_visualization.tsx (100%) rename src/legacy/core_plugins/kibana/public/{visualize/embeddable => visualize_embeddable}/get_index_pattern.ts (95%) rename src/legacy/core_plugins/kibana/public/{visualize/embeddable => visualize_embeddable}/index.ts (100%) rename src/legacy/core_plugins/kibana/public/{visualize/embeddable => visualize_embeddable}/visualize_embeddable.ts (98%) rename src/legacy/core_plugins/kibana/public/{visualize/embeddable => visualize_embeddable}/visualize_embeddable_factory.tsx (93%) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index dccfe48d8f528..1137fb99f81a7 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -8,6 +8,16 @@ /src/plugins/share/ @elastic/kibana-app /src/legacy/server/url_shortening/ @elastic/kibana-app /src/legacy/server/sample_data/ @elastic/kibana-app +/src/legacy/core_plugins/kibana/public/dashboard/ @elastic/kibana-app +/src/legacy/core_plugins/kibana/public/discover/ @elastic/kibana-app +/src/legacy/core_plugins/kibana/public/visualize/ @elastic/kibana-app +/src/legacy/core_plugins/kibana/public/local_application_service/ @elastic/kibana-app +/src/legacy/core_plugins/kibana/public/home/ @elastic/kibana-app +/src/legacy/core_plugins/kibana/public/dev_tools/ @elastic/kibana-app +/src/plugins/home/ @elastic/kibana-app +/src/plugins/kibana_legacy/ @elastic/kibana-app +/src/plugins/timelion/ @elastic/kibana-app +/src/plugins/dev_tools/ @elastic/kibana-app # App Architecture /src/plugins/data/ @elastic/kibana-app-arch diff --git a/src/legacy/core_plugins/kibana/public/.eslintrc b/src/legacy/core_plugins/kibana/public/.eslintrc deleted file mode 100644 index cc44af915ba25..0000000000000 --- a/src/legacy/core_plugins/kibana/public/.eslintrc +++ /dev/null @@ -1,3 +0,0 @@ -rules: - no-console: 2 - 'import/no-default-export': error diff --git a/src/legacy/core_plugins/kibana/public/.eslintrc.js b/src/legacy/core_plugins/kibana/public/.eslintrc.js new file mode 100644 index 0000000000000..160adcc5b63f1 --- /dev/null +++ b/src/legacy/core_plugins/kibana/public/.eslintrc.js @@ -0,0 +1,72 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +const path = require('path'); + +/** + * Builds custom restricted paths configuration for the shimmed plugins within the kibana plugin. + * These custom rules extend the default checks in the top level `eslintrc.js` by also checking two other things: + * * Making sure nothing within np_ready imports from the `ui` directory + * * Making sure no other code is importing things deep from within the shimmed plugins + * @param shimmedPlugins List of plugin names within the kibana plugin that are partially np ready + * @returns zones configuration for the no-restricted-paths linter + */ +function buildRestrictedPaths(shimmedPlugins) { + return shimmedPlugins.map(shimmedPlugin => ([{ + target: [ + `src/legacy/core_plugins/kibana/public/${shimmedPlugin}/np_ready/**/*`, + ], + from: [ + 'ui/**/*', + 'src/legacy/ui/**/*', + 'src/legacy/core_plugins/kibana/public/**/*', + 'src/legacy/core_plugins/data/public/**/*', + '!src/legacy/core_plugins/data/public/index.ts', + `!src/legacy/core_plugins/kibana/public/${shimmedPlugin}/**/*`, + ], + allowSameFolder: false, + errorMessage: `${shimmedPlugin} is a shimmed plugin that is not allowed to import modules from the legacy platform. If you need legacy modules for the transition period, import them either in the legacy_imports, kibana_services or index module.`, + }, { + target: [ + 'src/**/*', + `!src/legacy/core_plugins/kibana/public/${shimmedPlugin}/**/*`, + 'x-pack/**/*', + ], + from: [ + `src/legacy/core_plugins/kibana/public/${shimmedPlugin}/**/*`, + `!src/legacy/core_plugins/kibana/public/${shimmedPlugin}/index.ts`, + ], + allowSameFolder: false, + errorMessage: `kibana/public/${shimmedPlugin} is behaving like a NP plugin and does not allow deep imports. If you need something from within ${shimmedPlugin} in another plugin, consider re-exporting it from the top level index module`, + }])).reduce((acc, part) => [...acc, ...part], []); +} + +module.exports = { + rules: { + 'no-console': 2, + 'import/no-default-export': 'error', + '@kbn/eslint/no-restricted-paths': [ + 'error', + { + basePath: path.resolve(__dirname, '../../../../../'), + zones: buildRestrictedPaths(['visualize', 'discover', 'dashboard', 'devTools', 'home']), + }, + ], + }, +}; diff --git a/src/legacy/core_plugins/kibana/public/dashboard/__tests__/dashboard_empty_screen.test.tsx b/src/legacy/core_plugins/kibana/public/dashboard/__tests__/dashboard_empty_screen.test.tsx index 653e7d4215eef..1c450879ee553 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/__tests__/dashboard_empty_screen.test.tsx +++ b/src/legacy/core_plugins/kibana/public/dashboard/__tests__/dashboard_empty_screen.test.tsx @@ -18,7 +18,10 @@ */ import React from 'react'; import { mountWithIntl } from 'test_utils/enzyme_helpers'; -import { DashboardEmptyScreen, DashboardEmptyScreenProps } from '../dashboard_empty_screen'; +import { + DashboardEmptyScreen, + DashboardEmptyScreenProps, +} from '../np_ready/dashboard_empty_screen'; // @ts-ignore import { findTestSubject } from '@elastic/eui/lib/test'; diff --git a/src/legacy/core_plugins/kibana/public/dashboard/__tests__/get_saved_dashboard_mock.ts b/src/legacy/core_plugins/kibana/public/dashboard/__tests__/get_saved_dashboard_mock.ts index bf7135098ea74..1c2405b5824f2 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/__tests__/get_saved_dashboard_mock.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/__tests__/get_saved_dashboard_mock.ts @@ -17,7 +17,7 @@ * under the License. */ -import { searchSourceMock } from '../../../../../ui/public/courier/search_source/mocks'; +import { searchSourceMock } from 'ui/courier/search_source/mocks'; import { SavedObjectDashboard } from '../saved_dashboard/saved_dashboard'; export function getSavedDashboardMock( diff --git a/src/legacy/core_plugins/kibana/public/dashboard/index.ts b/src/legacy/core_plugins/kibana/public/dashboard/index.ts index dccc4c11e334f..76d9933a3d567 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/index.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/index.ts @@ -30,6 +30,8 @@ import { start as embeddables } from '../../../embeddable_api/public/np_ready/pu import './saved_dashboard/saved_dashboards'; import './dashboard_config'; +export * from './np_ready/dashboard_constants'; + /** * Get dependencies relying on the global angular context. * They also have to get resolved together with the legacy imports above diff --git a/src/legacy/core_plugins/kibana/public/dashboard/legacy_imports.ts b/src/legacy/core_plugins/kibana/public/dashboard/legacy_imports.ts index adae063a1470b..d3c17d1176c10 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/legacy_imports.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/legacy_imports.ts @@ -57,7 +57,7 @@ export { createTopNavDirective, createTopNavHelper } from 'ui/kbn_top_nav/kbn_to // @ts-ignore export { PromiseServiceCreator } from 'ui/promises/promises'; // @ts-ignore -export { KbnUrlProvider, RedirectWhenMissingProvider } from 'ui/url'; +export { KbnUrlProvider, RedirectWhenMissingProvider } from 'ui/url/index'; // @ts-ignore export { confirmModalFactory } from 'ui/modals/confirm_modal'; export { configureAppAngularModule } from 'ui/legacy_compat'; @@ -65,3 +65,5 @@ export { stateMonitorFactory, StateMonitor } from 'ui/state_management/state_mon export { ensureDefaultIndexPattern } from 'ui/legacy_compat'; export { unhashUrl } from '../../../../../plugins/kibana_utils/public'; export { IInjector } from 'ui/chrome'; +export { VISUALIZE_EMBEDDABLE_TYPE } from '../visualize_embeddable'; +export { registerTimefilterWithGlobalStateFactory } from 'ui/timefilter/setup_router'; diff --git a/src/legacy/core_plugins/kibana/public/dashboard/migrations/migrate_to_730_panels.test.ts b/src/legacy/core_plugins/kibana/public/dashboard/migrations/migrate_to_730_panels.test.ts index 09677f149c064..ad4feacde0815 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/migrations/migrate_to_730_panels.test.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/migrations/migrate_to_730_panels.test.ts @@ -37,7 +37,7 @@ jest.mock( jest.mock('ui/new_platform'); import { migratePanelsTo730 } from './migrate_to_730_panels'; -import { SavedDashboardPanelTo60, SavedDashboardPanel730ToLatest } from '../types'; +import { SavedDashboardPanelTo60, SavedDashboardPanel730ToLatest } from '../np_ready/types'; import { RawSavedDashboardPanelTo60, RawSavedDashboardPanel610, diff --git a/src/legacy/core_plugins/kibana/public/dashboard/migrations/migrate_to_730_panels.ts b/src/legacy/core_plugins/kibana/public/dashboard/migrations/migrate_to_730_panels.ts index b1b5a57ca27dc..b0d20b4482728 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/migrations/migrate_to_730_panels.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/migrations/migrate_to_730_panels.ts @@ -34,7 +34,7 @@ import { SavedDashboardPanel620, SavedDashboardPanel630, SavedDashboardPanel610, -} from '../types'; +} from '../np_ready/types'; const PANEL_HEIGHT_SCALE_FACTOR = 5; const PANEL_HEIGHT_SCALE_FACTOR_WITH_MARGINS = 4; diff --git a/src/legacy/core_plugins/kibana/public/dashboard/migrations/types.ts b/src/legacy/core_plugins/kibana/public/dashboard/migrations/types.ts index 7fba2f4003f31..c264358a8f81f 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/migrations/types.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/migrations/types.ts @@ -17,7 +17,7 @@ * under the License. */ -import { GridData } from '../types'; +import { GridData } from '../np_ready/types'; import { Doc, DocPre700 } from '../../../migrations/types'; export interface SavedObjectAttributes { diff --git a/src/legacy/core_plugins/kibana/public/dashboard/application.ts b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/application.ts similarity index 95% rename from src/legacy/core_plugins/kibana/public/dashboard/application.ts rename to src/legacy/core_plugins/kibana/public/dashboard/np_ready/application.ts index 3482197e381e6..298dcee12dc35 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/application.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/application.ts @@ -19,7 +19,6 @@ import { EuiConfirmModal, EuiIcon } from '@elastic/eui'; import angular, { IModule } from 'angular'; -import { IPrivate } from 'ui/private'; import { i18nDirective, i18nFilter, I18nProvider } from '@kbn/i18n/angular'; import { AppMountContext, @@ -28,7 +27,7 @@ import { SavedObjectsClientContract, IUiSettingsClient, } from 'kibana/public'; -import { Storage } from '../../../../../plugins/kibana_utils/public'; +import { Storage } from '../../../../../../plugins/kibana_utils/public'; import { GlobalStateProvider, StateManagementConfigProvider, @@ -43,14 +42,15 @@ import { RedirectWhenMissingProvider, confirmModalFactory, configureAppAngularModule, -} from './legacy_imports'; + IPrivate, +} from '../legacy_imports'; // @ts-ignore import { initDashboardApp } from './legacy_app'; -import { IEmbeddableStart } from '../../../../../plugins/embeddable/public'; -import { NavigationPublicPluginStart as NavigationStart } from '../../../../../plugins/navigation/public'; -import { DataPublicPluginStart as NpDataStart } from '../../../../../plugins/data/public'; -import { SharePluginStart } from '../../../../../plugins/share/public'; +import { IEmbeddableStart } from '../../../../../../plugins/embeddable/public'; +import { NavigationPublicPluginStart as NavigationStart } from '../../../../../../plugins/navigation/public'; +import { DataPublicPluginStart as NpDataStart } from '../../../../../../plugins/data/public'; +import { SharePluginStart } from '../../../../../../plugins/share/public'; export interface RenderDeps { core: LegacyCoreStart; diff --git a/src/legacy/core_plugins/kibana/public/dashboard/dashboard_app.html b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_app.html similarity index 100% rename from src/legacy/core_plugins/kibana/public/dashboard/dashboard_app.html rename to src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_app.html diff --git a/src/legacy/core_plugins/kibana/public/dashboard/dashboard_app.tsx b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_app.tsx similarity index 94% rename from src/legacy/core_plugins/kibana/public/dashboard/dashboard_app.tsx rename to src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_app.tsx index 04a8e68276fc2..e9fdc335ba572 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/dashboard_app.tsx +++ b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_app.tsx @@ -25,10 +25,10 @@ import { AppState as TAppState, IInjector, KbnUrl, -} from './legacy_imports'; +} from '../legacy_imports'; -import { ViewMode } from '../../../embeddable_api/public/np_ready/public'; -import { SavedObjectDashboard } from './saved_dashboard/saved_dashboard'; +import { ViewMode } from '../../../../embeddable_api/public/np_ready/public'; +import { SavedObjectDashboard } from '../saved_dashboard/saved_dashboard'; import { DashboardAppState, SavedDashboardPanel, ConfirmModalFn } from './types'; import { IIndexPattern, @@ -36,7 +36,7 @@ import { Query, esFilters, SavedQuery, -} from '../../../../../../src/plugins/data/public'; +} from '../../../../../../plugins/data/public'; import { DashboardAppController } from './dashboard_app_controller'; import { RenderDeps } from './application'; diff --git a/src/legacy/core_plugins/kibana/public/dashboard/dashboard_app_controller.tsx b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_app_controller.tsx similarity index 98% rename from src/legacy/core_plugins/kibana/public/dashboard/dashboard_app_controller.tsx rename to src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_app_controller.tsx index 24b64a88998f4..5ba457b6c3362 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/dashboard_app_controller.tsx +++ b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_app_controller.tsx @@ -37,9 +37,10 @@ import { KbnUrl, SavedObjectSaveOpts, unhashUrl, -} from './legacy_imports'; -import { FilterStateManager, IndexPattern } from '../../../data/public'; -import { Query, SavedQuery, IndexPatternsContract } from '../../../../../plugins/data/public'; + VISUALIZE_EMBEDDABLE_TYPE, +} from '../legacy_imports'; +import { FilterStateManager, IndexPattern } from '../../../../data/public'; +import { Query, SavedQuery, IndexPatternsContract } from '../../../../../../plugins/data/public'; import { DashboardContainer, @@ -47,14 +48,14 @@ import { DashboardContainerFactory, DashboardContainerInput, DashboardPanelState, -} from '../../../dashboard_embeddable_container/public/np_ready/public'; +} from '../../../../dashboard_embeddable_container/public/np_ready/public'; import { isErrorEmbeddable, ErrorEmbeddable, ViewMode, openAddPanelFlyout, EmbeddableFactoryNotFoundError, -} from '../../../embeddable_api/public/np_ready/public'; +} from '../../../../embeddable_api/public/np_ready/public'; import { DashboardAppState, NavAction, ConfirmModalFn, SavedDashboardPanel } from './types'; import { showOptionsPopover } from './top_nav/show_options_popover'; @@ -67,13 +68,12 @@ import { getTopNavConfig } from './top_nav/get_top_nav_config'; import { TopNavIds } from './top_nav/top_nav_ids'; import { getDashboardTitle } from './dashboard_strings'; import { DashboardAppScope } from './dashboard_app'; -import { VISUALIZE_EMBEDDABLE_TYPE } from '../visualize/embeddable'; import { convertSavedDashboardPanelToPanelState } from './lib/embeddable_saved_object_converters'; import { RenderDeps } from './application'; import { SavedObjectFinderProps, SavedObjectFinderUi, -} from '../../../../../plugins/kibana_react/public'; +} from '../../../../../../plugins/kibana_react/public'; export interface DashboardAppControllerDependencies extends RenderDeps { $scope: DashboardAppScope; diff --git a/src/legacy/core_plugins/kibana/public/dashboard/dashboard_constants.ts b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_constants.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/dashboard/dashboard_constants.ts rename to src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_constants.ts diff --git a/src/legacy/core_plugins/kibana/public/dashboard/dashboard_empty_screen.tsx b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_empty_screen.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/dashboard/dashboard_empty_screen.tsx rename to src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_empty_screen.tsx diff --git a/src/legacy/core_plugins/kibana/public/dashboard/dashboard_empty_screen_constants.tsx b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_empty_screen_constants.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/dashboard/dashboard_empty_screen_constants.tsx rename to src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_empty_screen_constants.tsx diff --git a/src/legacy/core_plugins/kibana/public/dashboard/dashboard_state.test.ts b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_state.test.ts similarity index 96% rename from src/legacy/core_plugins/kibana/public/dashboard/dashboard_state.test.ts rename to src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_state.test.ts index 8b786144c7420..4d5101e1f9e5f 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/dashboard_state.test.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_state.test.ts @@ -19,8 +19,8 @@ import './np_core.test.mocks'; import { DashboardStateManager } from './dashboard_state_manager'; -import { getAppStateMock, getSavedDashboardMock } from './__tests__'; -import { AppStateClass } from './legacy_imports'; +import { getAppStateMock, getSavedDashboardMock } from '../__tests__'; +import { AppStateClass } from '../legacy_imports'; import { DashboardAppState } from './types'; import { TimeRange, TimefilterContract, InputTimeRange } from 'src/plugins/data/public'; import { ViewMode } from 'src/plugins/embeddable/public'; diff --git a/src/legacy/core_plugins/kibana/public/dashboard/dashboard_state_manager.ts b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_state_manager.ts similarity index 98% rename from src/legacy/core_plugins/kibana/public/dashboard/dashboard_state_manager.ts rename to src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_state_manager.ts index ac8628ec2a9d9..6df18757da6f5 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/dashboard_state_manager.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_state_manager.ts @@ -23,23 +23,23 @@ import _ from 'lodash'; import { Moment } from 'moment'; import { DashboardContainer } from 'src/legacy/core_plugins/dashboard_embeddable_container/public/np_ready/public'; -import { ViewMode } from '../../../../../../src/plugins/embeddable/public'; +import { ViewMode } from '../../../../../../plugins/embeddable/public'; import { stateMonitorFactory, StateMonitor, AppStateClass as TAppStateClass, migrateLegacyQuery, -} from './legacy_imports'; +} from '../legacy_imports'; import { Query, esFilters, TimefilterContract as Timefilter, -} from '../../../../../../src/plugins/data/public'; +} from '../../../../../../plugins/data/public'; import { getAppStateDefaults, migrateAppState } from './lib'; import { convertPanelStateToSavedDashboardPanel } from './lib/embeddable_saved_object_converters'; import { FilterUtils } from './lib/filter_utils'; -import { SavedObjectDashboard } from './saved_dashboard/saved_dashboard'; +import { SavedObjectDashboard } from '../saved_dashboard/saved_dashboard'; import { SavedDashboardPanel, DashboardAppState, DashboardAppStateDefaults } from './types'; diff --git a/src/legacy/core_plugins/kibana/public/dashboard/dashboard_strings.ts b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_strings.ts similarity index 96% rename from src/legacy/core_plugins/kibana/public/dashboard/dashboard_strings.ts rename to src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_strings.ts index d932116d08dc8..d9406ccba18ba 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/dashboard_strings.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_strings.ts @@ -18,7 +18,7 @@ */ import { i18n } from '@kbn/i18n'; -import { ViewMode } from '../../../../../../src/plugins/embeddable/public'; +import { ViewMode } from '../../../../../../plugins/embeddable/public'; /** * @param title {string} the current title of the dashboard diff --git a/src/legacy/core_plugins/kibana/public/dashboard/global_state_sync.ts b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/global_state_sync.ts similarity index 97% rename from src/legacy/core_plugins/kibana/public/dashboard/global_state_sync.ts rename to src/legacy/core_plugins/kibana/public/dashboard/np_ready/global_state_sync.ts index 8a733f940734b..1a6c2b09ee3fc 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/global_state_sync.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/global_state_sync.ts @@ -17,8 +17,8 @@ * under the License. */ -import { State } from './legacy_imports'; -import { DataPublicPluginStart as NpDataStart } from '../../../../../plugins/data/public'; +import { State } from '../legacy_imports'; +import { DataPublicPluginStart as NpDataStart } from '../../../../../../plugins/data/public'; /** * Helper function to sync the global state with the various state providers diff --git a/src/legacy/core_plugins/kibana/public/dashboard/help_menu/help_menu_util.js b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/help_menu/help_menu_util.ts similarity index 80% rename from src/legacy/core_plugins/kibana/public/dashboard/help_menu/help_menu_util.js rename to src/legacy/core_plugins/kibana/public/dashboard/np_ready/help_menu/help_menu_util.ts index 55abfa179b56d..bc281c6eb340f 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/help_menu/help_menu_util.js +++ b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/help_menu/help_menu_util.ts @@ -18,9 +18,12 @@ */ import { i18n } from '@kbn/i18n'; -import { ELASTIC_WEBSITE_URL, DOC_LINK_VERSION } from 'ui/documentation_links'; +import { CoreStart } from 'kibana/public'; -export function addHelpMenuToAppChrome(chrome) { +export function addHelpMenuToAppChrome( + chrome: CoreStart['chrome'], + docLinks: CoreStart['docLinks'] +) { chrome.setHelpExtension({ appName: i18n.translate('kbn.dashboard.helpMenu.appName', { defaultMessage: 'Dashboards', @@ -28,7 +31,7 @@ export function addHelpMenuToAppChrome(chrome) { links: [ { linkType: 'documentation', - href: `${ELASTIC_WEBSITE_URL}guide/en/kibana/${DOC_LINK_VERSION}/dashboard.html`, + href: `${docLinks.ELASTIC_WEBSITE_URL}guide/en/kibana/${docLinks.DOC_LINK_VERSION}/dashboard.html`, }, ], }); diff --git a/src/legacy/core_plugins/kibana/public/dashboard/legacy_app.js b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/legacy_app.js similarity index 92% rename from src/legacy/core_plugins/kibana/public/dashboard/legacy_app.js rename to src/legacy/core_plugins/kibana/public/dashboard/np_ready/legacy_app.js index 927717948168a..a4fda5eda8a32 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/legacy_app.js +++ b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/legacy_app.js @@ -22,23 +22,35 @@ import { i18n } from '@kbn/i18n'; import dashboardTemplate from './dashboard_app.html'; import dashboardListingTemplate from './listing/dashboard_listing_ng_wrapper.html'; -import { ensureDefaultIndexPattern } from './legacy_imports'; +import { + ensureDefaultIndexPattern, + registerTimefilterWithGlobalStateFactory, +} from '../legacy_imports'; import { initDashboardAppDirective } from './dashboard_app'; import { DashboardConstants, createDashboardEditUrl } from './dashboard_constants'; import { InvalidJSONProperty, SavedObjectNotFound, -} from '../../../../../plugins/kibana_utils/public'; +} from '../../../../../../plugins/kibana_utils/public'; import { DashboardListing, EMPTY_FILTER } from './listing/dashboard_listing'; import { addHelpMenuToAppChrome } from './help_menu/help_menu_util'; -import { registerTimefilterWithGlobalStateFactory } from '../../../../ui/public/timefilter/setup_router'; import { syncOnMount } from './global_state_sync'; export function initDashboardApp(app, deps) { initDashboardAppDirective(app, deps); app.directive('dashboardListing', function(reactDirective) { - return reactDirective(DashboardListing); + return reactDirective(DashboardListing, [ + ['core', { watchDepth: 'reference' }], + ['createItem', { watchDepth: 'reference' }], + ['getViewUrl', { watchDepth: 'reference' }], + ['editItem', { watchDepth: 'reference' }], + ['findItems', { watchDepth: 'reference' }], + ['deleteItems', { watchDepth: 'reference' }], + ['listingLimit', { watchDepth: 'reference' }], + ['hideWriteControls', { watchDepth: 'reference' }], + ['initialFilter', { watchDepth: 'reference' }], + ]); }); function createNewDashboardCtrl($scope) { @@ -116,6 +128,7 @@ export function initDashboardApp(app, deps) { }, ]); addHelpMenuToAppChrome(deps.chrome, deps.core.docLinks); + $scope.core = deps.core; }, resolve: { dash: function($rootScope, $route, redirectWhenMissing, kbnUrl) { diff --git a/src/legacy/core_plugins/kibana/public/dashboard/lib/embeddable_saved_object_converters.test.ts b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/lib/embeddable_saved_object_converters.test.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/dashboard/lib/embeddable_saved_object_converters.test.ts rename to src/legacy/core_plugins/kibana/public/dashboard/np_ready/lib/embeddable_saved_object_converters.test.ts diff --git a/src/legacy/core_plugins/kibana/public/dashboard/lib/embeddable_saved_object_converters.ts b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/lib/embeddable_saved_object_converters.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/dashboard/lib/embeddable_saved_object_converters.ts rename to src/legacy/core_plugins/kibana/public/dashboard/np_ready/lib/embeddable_saved_object_converters.ts diff --git a/src/legacy/core_plugins/kibana/public/dashboard/lib/filter_utils.ts b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/lib/filter_utils.ts similarity index 97% rename from src/legacy/core_plugins/kibana/public/dashboard/lib/filter_utils.ts rename to src/legacy/core_plugins/kibana/public/dashboard/np_ready/lib/filter_utils.ts index 19a0c32210737..6fbc04969b1c8 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/lib/filter_utils.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/lib/filter_utils.ts @@ -19,7 +19,7 @@ import _ from 'lodash'; import moment, { Moment } from 'moment'; -import { esFilters } from '../../../../../../plugins/data/public'; +import { esFilters } from '../../../../../../../plugins/data/public'; /** * @typedef {Object} QueryFilter diff --git a/src/legacy/core_plugins/kibana/public/dashboard/lib/get_app_state_defaults.ts b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/lib/get_app_state_defaults.ts similarity index 90% rename from src/legacy/core_plugins/kibana/public/dashboard/lib/get_app_state_defaults.ts rename to src/legacy/core_plugins/kibana/public/dashboard/np_ready/lib/get_app_state_defaults.ts index eb4a4356fb27a..eceb51f17d164 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/lib/get_app_state_defaults.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/lib/get_app_state_defaults.ts @@ -17,8 +17,8 @@ * under the License. */ -import { ViewMode } from '../../../../../../../src/plugins/embeddable/public'; -import { SavedObjectDashboard } from '../saved_dashboard/saved_dashboard'; +import { ViewMode } from '../../../../../../../plugins/embeddable/public'; +import { SavedObjectDashboard } from '../../saved_dashboard/saved_dashboard'; import { DashboardAppStateDefaults } from '../types'; export function getAppStateDefaults( diff --git a/src/legacy/core_plugins/kibana/public/dashboard/lib/index.ts b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/lib/index.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/dashboard/lib/index.ts rename to src/legacy/core_plugins/kibana/public/dashboard/np_ready/lib/index.ts diff --git a/src/legacy/core_plugins/kibana/public/dashboard/lib/migrate_app_state.test.ts b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/lib/migrate_app_state.test.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/dashboard/lib/migrate_app_state.test.ts rename to src/legacy/core_plugins/kibana/public/dashboard/np_ready/lib/migrate_app_state.test.ts diff --git a/src/legacy/core_plugins/kibana/public/dashboard/lib/migrate_app_state.ts b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/lib/migrate_app_state.ts similarity index 96% rename from src/legacy/core_plugins/kibana/public/dashboard/lib/migrate_app_state.ts rename to src/legacy/core_plugins/kibana/public/dashboard/np_ready/lib/migrate_app_state.ts index c4ad754548459..4083900c7ede7 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/lib/migrate_app_state.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/lib/migrate_app_state.ts @@ -19,7 +19,7 @@ import semver from 'semver'; import { i18n } from '@kbn/i18n'; -import { createUiStatsReporter, METRIC_TYPE } from '../../../../ui_metric/public'; +import { createUiStatsReporter, METRIC_TYPE } from '../../../../../ui_metric/public'; import { DashboardAppState, SavedDashboardPanelTo60, @@ -29,7 +29,7 @@ import { SavedDashboardPanel640To720, SavedDashboardPanel620, } from '../types'; -import { migratePanelsTo730 } from '../migrations/migrate_to_730_panels'; +import { migratePanelsTo730 } from '../../migrations/migrate_to_730_panels'; /** * Attempts to migrate the state stored in the URL into the latest version of it. diff --git a/src/legacy/core_plugins/kibana/public/dashboard/lib/save_dashboard.ts b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/lib/save_dashboard.ts similarity index 97% rename from src/legacy/core_plugins/kibana/public/dashboard/lib/save_dashboard.ts rename to src/legacy/core_plugins/kibana/public/dashboard/np_ready/lib/save_dashboard.ts index e322677433ce6..691c87122564f 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/lib/save_dashboard.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/lib/save_dashboard.ts @@ -18,7 +18,7 @@ */ import { TimefilterContract } from 'src/plugins/data/public'; -import { SavedObjectSaveOpts } from '../legacy_imports'; +import { SavedObjectSaveOpts } from '../../legacy_imports'; import { updateSavedDashboard } from './update_saved_dashboard'; import { DashboardStateManager } from '../dashboard_state_manager'; diff --git a/src/legacy/core_plugins/kibana/public/dashboard/lib/update_saved_dashboard.ts b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/lib/update_saved_dashboard.ts similarity index 93% rename from src/legacy/core_plugins/kibana/public/dashboard/lib/update_saved_dashboard.ts rename to src/legacy/core_plugins/kibana/public/dashboard/np_ready/lib/update_saved_dashboard.ts index ce9096b3a56f0..2072b5d4f6eb0 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/lib/update_saved_dashboard.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/lib/update_saved_dashboard.ts @@ -19,9 +19,9 @@ import _ from 'lodash'; import { RefreshInterval, TimefilterContract } from 'src/plugins/data/public'; -import { AppState } from '../legacy_imports'; +import { AppState } from '../../legacy_imports'; import { FilterUtils } from './filter_utils'; -import { SavedObjectDashboard } from '../saved_dashboard/saved_dashboard'; +import { SavedObjectDashboard } from '../../saved_dashboard/saved_dashboard'; export function updateSavedDashboard( savedDashboard: SavedObjectDashboard, diff --git a/src/legacy/core_plugins/kibana/public/dashboard/listing/__snapshots__/dashboard_listing.test.js.snap b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/listing/__snapshots__/dashboard_listing.test.js.snap similarity index 100% rename from src/legacy/core_plugins/kibana/public/dashboard/listing/__snapshots__/dashboard_listing.test.js.snap rename to src/legacy/core_plugins/kibana/public/dashboard/np_ready/listing/__snapshots__/dashboard_listing.test.js.snap diff --git a/src/legacy/core_plugins/kibana/public/dashboard/listing/dashboard_listing.js b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/listing/dashboard_listing.js similarity index 96% rename from src/legacy/core_plugins/kibana/public/dashboard/listing/dashboard_listing.js rename to src/legacy/core_plugins/kibana/public/dashboard/np_ready/listing/dashboard_listing.js index 2946597581fdb..827fe6eabe784 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/listing/dashboard_listing.js +++ b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/listing/dashboard_listing.js @@ -23,9 +23,8 @@ import PropTypes from 'prop-types'; import { FormattedMessage, I18nProvider } from '@kbn/i18n/react'; import { i18n } from '@kbn/i18n'; import { EuiLink, EuiButton, EuiEmptyPrompt } from '@elastic/eui'; -import { npStart } from 'ui/new_platform'; -import { TableListView } from '../../../../../../../src/plugins/kibana_react/public'; +import { TableListView } from '../../../../../../../plugins/kibana_react/public'; export const EMPTY_FILTER = ''; @@ -60,8 +59,8 @@ export class DashboardListing extends React.Component { tableListTitle={i18n.translate('kbn.dashboard.listing.dashboardsTitle', { defaultMessage: 'Dashboards', })} - toastNotifications={npStart.core.notifications.toasts} - uiSettings={npStart.core.uiSettings} + toastNotifications={this.props.core.notifications.toasts} + uiSettings={this.props.core.uiSettings} /> ); diff --git a/src/legacy/core_plugins/kibana/public/dashboard/listing/dashboard_listing.test.js b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/listing/dashboard_listing.test.js similarity index 90% rename from src/legacy/core_plugins/kibana/public/dashboard/listing/dashboard_listing.test.js rename to src/legacy/core_plugins/kibana/public/dashboard/np_ready/listing/dashboard_listing.test.js index a933607d256a9..c47a54ad60460 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/listing/dashboard_listing.test.js +++ b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/listing/dashboard_listing.test.js @@ -42,17 +42,6 @@ jest.mock( { virtual: true } ); -jest.mock('ui/new_platform', () => { - return { - npStart: { - core: { - notifications: { toasts: {} }, - uiSettings: { get: jest.fn(() => 10) }, - }, - }, - }; -}); - import React from 'react'; import { shallow } from 'enzyme'; @@ -83,6 +72,7 @@ test('renders empty page in before initial fetch to avoid flickering', () => { getViewUrl={() => {}} listingLimit={1000} hideWriteControls={false} + core={{ notifications: { toasts: {} }, uiSettings: { get: jest.fn(() => 10) } }} /> ); expect(component).toMatchSnapshot(); @@ -100,6 +90,7 @@ describe('after fetch', () => { listingLimit={1000} hideWriteControls={false} initialFilter="my dashboard" + core={{ notifications: { toasts: {} }, uiSettings: { get: jest.fn(() => 10) } }} /> ); @@ -121,6 +112,7 @@ describe('after fetch', () => { getViewUrl={() => {}} listingLimit={1000} hideWriteControls={false} + core={{ notifications: { toasts: {} }, uiSettings: { get: jest.fn(() => 10) } }} /> ); @@ -142,6 +134,7 @@ describe('after fetch', () => { getViewUrl={() => {}} listingLimit={1} hideWriteControls={false} + core={{ notifications: { toasts: {} }, uiSettings: { get: jest.fn(() => 10) } }} /> ); @@ -163,6 +156,7 @@ describe('after fetch', () => { getViewUrl={() => {}} listingLimit={1} hideWriteControls={true} + core={{ notifications: { toasts: {} }, uiSettings: { get: jest.fn(() => 10) } }} /> ); @@ -184,6 +178,7 @@ describe('after fetch', () => { getViewUrl={() => {}} listingLimit={1} hideWriteControls={false} + core={{ notifications: { toasts: {} }, uiSettings: { get: jest.fn(() => 10) } }} /> ); diff --git a/src/legacy/core_plugins/kibana/public/dashboard/listing/dashboard_listing_ng_wrapper.html b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/listing/dashboard_listing_ng_wrapper.html similarity index 94% rename from src/legacy/core_plugins/kibana/public/dashboard/listing/dashboard_listing_ng_wrapper.html rename to src/legacy/core_plugins/kibana/public/dashboard/np_ready/listing/dashboard_listing_ng_wrapper.html index a1dd9f30bdd81..f473e91af7ae9 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/listing/dashboard_listing_ng_wrapper.html +++ b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/listing/dashboard_listing_ng_wrapper.html @@ -1,4 +1,5 @@ ({ +jest.mock('../../legacy_imports', () => ({ SavedObjectSaveModal: () => null, })); diff --git a/src/legacy/core_plugins/kibana/public/dashboard/top_nav/save_modal.tsx b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/top_nav/save_modal.tsx similarity index 98% rename from src/legacy/core_plugins/kibana/public/dashboard/top_nav/save_modal.tsx rename to src/legacy/core_plugins/kibana/public/dashboard/np_ready/top_nav/save_modal.tsx index 0640b2be431be..bd53fd5a13083 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/top_nav/save_modal.tsx +++ b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/top_nav/save_modal.tsx @@ -21,7 +21,7 @@ import React, { Fragment } from 'react'; import { FormattedMessage } from '@kbn/i18n/react'; import { EuiFormRow, EuiTextArea, EuiSwitch } from '@elastic/eui'; -import { SavedObjectSaveModal } from '../legacy_imports'; +import { SavedObjectSaveModal } from '../../legacy_imports'; interface SaveOptions { newTitle: string; diff --git a/src/legacy/core_plugins/kibana/public/dashboard/top_nav/show_clone_modal.tsx b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/top_nav/show_clone_modal.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/dashboard/top_nav/show_clone_modal.tsx rename to src/legacy/core_plugins/kibana/public/dashboard/np_ready/top_nav/show_clone_modal.tsx diff --git a/src/legacy/core_plugins/kibana/public/dashboard/top_nav/show_options_popover.tsx b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/top_nav/show_options_popover.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/dashboard/top_nav/show_options_popover.tsx rename to src/legacy/core_plugins/kibana/public/dashboard/np_ready/top_nav/show_options_popover.tsx diff --git a/src/legacy/core_plugins/kibana/public/dashboard/top_nav/top_nav_ids.ts b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/top_nav/top_nav_ids.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/dashboard/top_nav/top_nav_ids.ts rename to src/legacy/core_plugins/kibana/public/dashboard/np_ready/top_nav/top_nav_ids.ts diff --git a/src/legacy/core_plugins/kibana/public/dashboard/types.ts b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/types.ts similarity index 96% rename from src/legacy/core_plugins/kibana/public/dashboard/types.ts rename to src/legacy/core_plugins/kibana/public/dashboard/np_ready/types.ts index 371274401739e..e3eb25a208856 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/types.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/types.ts @@ -18,7 +18,7 @@ */ import { ViewMode } from 'src/plugins/embeddable/public'; -import { AppState } from './legacy_imports'; +import { AppState } from '../legacy_imports'; import { RawSavedDashboardPanelTo60, RawSavedDashboardPanel610, @@ -26,8 +26,8 @@ import { RawSavedDashboardPanel630, RawSavedDashboardPanel640To720, RawSavedDashboardPanel730ToLatest, -} from './migrations/types'; -import { Query, esFilters } from '../../../../../plugins/data/public'; +} from '../migrations/types'; +import { Query, esFilters } from '../../../../../../plugins/data/public'; export type NavAction = (anchorElement?: any) => void; diff --git a/src/legacy/core_plugins/kibana/public/dashboard/plugin.ts b/src/legacy/core_plugins/kibana/public/dashboard/plugin.ts index 0e0d315ce592d..76deff201e5ee 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/plugin.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/plugin.ts @@ -26,13 +26,13 @@ import { SavedObjectsClientContract, } from 'kibana/public'; import { i18n } from '@kbn/i18n'; -import { RenderDeps } from './application'; +import { RenderDeps } from './np_ready/application'; import { DataStart } from '../../../data/public'; import { DataPublicPluginStart as NpDataStart } from '../../../../../plugins/data/public'; import { IEmbeddableStart } from '../../../../../plugins/embeddable/public'; import { Storage } from '../../../../../plugins/kibana_utils/public'; import { NavigationPublicPluginStart as NavigationStart } from '../../../../../plugins/navigation/public'; -import { DashboardConstants } from './dashboard_constants'; +import { DashboardConstants } from './np_ready/dashboard_constants'; import { FeatureCatalogueCategory, HomePublicPluginSetup, @@ -105,7 +105,7 @@ export class DashboardPlugin implements Plugin { dashboardCapabilities: contextCore.application.capabilities.dashboard, localStorage: new Storage(localStorage), }; - const { renderApp } = await import('./application'); + const { renderApp } = await import('./np_ready/application'); return renderApp(params.element, params.appBasePath, deps); }, }; diff --git a/src/legacy/core_plugins/kibana/public/dashboard/saved_dashboard/saved_dashboard.ts b/src/legacy/core_plugins/kibana/public/dashboard/saved_dashboard/saved_dashboard.ts index dc52b3ab7ad17..7f4d7402fcffc 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/saved_dashboard/saved_dashboard.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/saved_dashboard/saved_dashboard.ts @@ -20,9 +20,9 @@ import { SearchSourceContract } from 'ui/courier'; import { SavedObject, SavedObjectKibanaServices } from 'ui/saved_objects/types'; import { createSavedObjectClass } from 'ui/saved_objects/saved_object'; import { extractReferences, injectReferences } from './saved_dashboard_references'; -import { createDashboardEditUrl } from '../dashboard_constants'; import { esFilters, Query, RefreshInterval } from '../../../../../../plugins/data/public'; +import { createDashboardEditUrl } from '..'; export interface SavedObjectDashboard extends SavedObject { id?: string; diff --git a/src/legacy/core_plugins/kibana/public/discover/__tests__/directives/field_calculator.js b/src/legacy/core_plugins/kibana/public/discover/__tests__/directives/field_calculator.js index dcd04d31af076..378a9e9325655 100644 --- a/src/legacy/core_plugins/kibana/public/discover/__tests__/directives/field_calculator.js +++ b/src/legacy/core_plugins/kibana/public/discover/__tests__/directives/field_calculator.js @@ -20,7 +20,7 @@ import _ from 'lodash'; import { pluginInstance } from 'plugins/kibana/discover/index'; import ngMock from 'ng_mock'; -import { fieldCalculator } from '../../components/field_chooser/lib/field_calculator'; +import { fieldCalculator } from '../../np_ready/components/field_chooser/lib/field_calculator'; import expect from '@kbn/expect'; import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern'; diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/__tests__/doc_table.js b/src/legacy/core_plugins/kibana/public/discover/__tests__/doc_table/doc_table.js similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc_table/__tests__/doc_table.js rename to src/legacy/core_plugins/kibana/public/discover/__tests__/doc_table/doc_table.js diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/__tests__/lib/get_sort.js b/src/legacy/core_plugins/kibana/public/discover/__tests__/doc_table/lib/get_sort.js similarity index 98% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc_table/__tests__/lib/get_sort.js rename to src/legacy/core_plugins/kibana/public/discover/__tests__/doc_table/lib/get_sort.js index f264f0fb4d754..d9fdcc48608d2 100644 --- a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/__tests__/lib/get_sort.js +++ b/src/legacy/core_plugins/kibana/public/discover/__tests__/doc_table/lib/get_sort.js @@ -20,7 +20,7 @@ import expect from '@kbn/expect'; import ngMock from 'ng_mock'; -import { getSort } from '../../lib/get_sort'; +import { getSort } from '../../../np_ready/angular/doc_table/lib/get_sort'; import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern'; const defaultSort = [{ time: 'desc' }]; diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/__tests__/lib/rows_headers.js b/src/legacy/core_plugins/kibana/public/discover/__tests__/doc_table/lib/rows_headers.js similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc_table/__tests__/lib/rows_headers.js rename to src/legacy/core_plugins/kibana/public/discover/__tests__/doc_table/lib/rows_headers.js diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/context/query_parameters/__tests__/_utils.js b/src/legacy/core_plugins/kibana/public/discover/__tests__/query_parameters/_utils.js similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/context/query_parameters/__tests__/_utils.js rename to src/legacy/core_plugins/kibana/public/discover/__tests__/query_parameters/_utils.js diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/context/query_parameters/__tests__/action_add_filter.js b/src/legacy/core_plugins/kibana/public/discover/__tests__/query_parameters/action_add_filter.js similarity index 93% rename from src/legacy/core_plugins/kibana/public/discover/angular/context/query_parameters/__tests__/action_add_filter.js rename to src/legacy/core_plugins/kibana/public/discover/__tests__/query_parameters/action_add_filter.js index 1dbdea4c89f00..90614cf3c132c 100644 --- a/src/legacy/core_plugins/kibana/public/discover/angular/context/query_parameters/__tests__/action_add_filter.js +++ b/src/legacy/core_plugins/kibana/public/discover/__tests__/query_parameters/action_add_filter.js @@ -20,8 +20,8 @@ import expect from '@kbn/expect'; import ngMock from 'ng_mock'; import { createStateStub } from './_utils'; -import { getQueryParameterActions } from '../actions'; -import { createIndexPatternsStub } from '../../api/__tests__/_stubs'; +import { getQueryParameterActions } from '../../np_ready/angular/context/query_parameters/actions'; +import { createIndexPatternsStub } from '../../np_ready/angular/context/api/__tests__/_stubs'; import { pluginInstance } from 'plugins/kibana/discover/index'; import { npStart } from 'ui/new_platform'; diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/context/query_parameters/__tests__/action_set_predecessor_count.js b/src/legacy/core_plugins/kibana/public/discover/__tests__/query_parameters/action_set_predecessor_count.js similarity index 95% rename from src/legacy/core_plugins/kibana/public/discover/angular/context/query_parameters/__tests__/action_set_predecessor_count.js rename to src/legacy/core_plugins/kibana/public/discover/__tests__/query_parameters/action_set_predecessor_count.js index 52db1bab64945..1ad4bdbea210d 100644 --- a/src/legacy/core_plugins/kibana/public/discover/angular/context/query_parameters/__tests__/action_set_predecessor_count.js +++ b/src/legacy/core_plugins/kibana/public/discover/__tests__/query_parameters/action_set_predecessor_count.js @@ -21,7 +21,7 @@ import expect from '@kbn/expect'; import ngMock from 'ng_mock'; import { pluginInstance } from 'plugins/kibana/discover/index'; import { createStateStub } from './_utils'; -import { getQueryParameterActions } from '../actions'; +import { getQueryParameterActions } from '../../np_ready/angular/context/query_parameters/actions'; describe('context app', function() { beforeEach(() => pluginInstance.initializeInnerAngular()); diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/context/query_parameters/__tests__/action_set_query_parameters.js b/src/legacy/core_plugins/kibana/public/discover/__tests__/query_parameters/action_set_query_parameters.js similarity index 96% rename from src/legacy/core_plugins/kibana/public/discover/angular/context/query_parameters/__tests__/action_set_query_parameters.js rename to src/legacy/core_plugins/kibana/public/discover/__tests__/query_parameters/action_set_query_parameters.js index 6cc5e1ae6db04..e9ec2c300faa1 100644 --- a/src/legacy/core_plugins/kibana/public/discover/angular/context/query_parameters/__tests__/action_set_query_parameters.js +++ b/src/legacy/core_plugins/kibana/public/discover/__tests__/query_parameters/action_set_query_parameters.js @@ -22,7 +22,7 @@ import ngMock from 'ng_mock'; import { pluginInstance } from 'plugins/kibana/discover/index'; import { createStateStub } from './_utils'; -import { getQueryParameterActions } from '../actions'; +import { getQueryParameterActions } from '../../np_ready/angular/context/query_parameters/actions'; describe('context app', function() { beforeEach(() => pluginInstance.initializeInnerAngular()); diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/context/query_parameters/__tests__/action_set_successor_count.js b/src/legacy/core_plugins/kibana/public/discover/__tests__/query_parameters/action_set_successor_count.js similarity index 95% rename from src/legacy/core_plugins/kibana/public/discover/angular/context/query_parameters/__tests__/action_set_successor_count.js rename to src/legacy/core_plugins/kibana/public/discover/__tests__/query_parameters/action_set_successor_count.js index a976cf0d04d20..15f3eefac3fd1 100644 --- a/src/legacy/core_plugins/kibana/public/discover/angular/context/query_parameters/__tests__/action_set_successor_count.js +++ b/src/legacy/core_plugins/kibana/public/discover/__tests__/query_parameters/action_set_successor_count.js @@ -22,7 +22,7 @@ import ngMock from 'ng_mock'; import { pluginInstance } from 'plugins/kibana/discover/index'; import { createStateStub } from './_utils'; -import { getQueryParameterActions } from '../actions'; +import { getQueryParameterActions } from '../../np_ready/angular/context/query_parameters/actions'; describe('context app', function() { beforeEach(() => pluginInstance.initializeInnerAngular()); diff --git a/src/legacy/core_plugins/kibana/public/discover/_index.scss b/src/legacy/core_plugins/kibana/public/discover/_index.scss index 0d70bb993fac1..386472a9f6e01 100644 --- a/src/legacy/core_plugins/kibana/public/discover/_index.scss +++ b/src/legacy/core_plugins/kibana/public/discover/_index.scss @@ -1,26 +1,2 @@ // Discover plugin styles -@import 'mixins'; - -// Prefix all styles with "dsc" to avoid conflicts. -// Examples -// dscTable -// dscTable__footer -// monChart__legend--small -// monChart__legend-isLoading - -@import 'components/fetch_error/index'; -@import 'components/field_chooser/index'; -@import 'angular/directives/index'; -@import 'angular/doc_table/index'; - -@import 'hacks'; - -@import 'discover'; - -@import 'embeddable/index'; - -// Doc Viewer -@import 'components/doc_viewer/index'; - -// Context styles -@import 'angular/context/index'; +@import 'np_ready/index'; diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/_index.scss b/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/_index.scss deleted file mode 100644 index 23d6609a5cffb..0000000000000 --- a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/_index.scss +++ /dev/null @@ -1,2 +0,0 @@ -@import './doc_table'; -@import './components/index'; diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/_index.scss b/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/_index.scss deleted file mode 100644 index a73ff41db7c03..0000000000000 --- a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/_index.scss +++ /dev/null @@ -1,2 +0,0 @@ -@import './table_header'; -@import './table_row/index'; diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/table_row/_index.scss b/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/table_row/_index.scss deleted file mode 100644 index a452ce140ba93..0000000000000 --- a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/table_row/_index.scss +++ /dev/null @@ -1,3 +0,0 @@ -@import './cell'; -@import './details'; -@import './open'; diff --git a/src/legacy/core_plugins/kibana/public/discover/helpers/build_services.ts b/src/legacy/core_plugins/kibana/public/discover/build_services.ts similarity index 88% rename from src/legacy/core_plugins/kibana/public/discover/helpers/build_services.ts rename to src/legacy/core_plugins/kibana/public/discover/build_services.ts index 27c7c00fb729c..aaacde7e4060f 100644 --- a/src/legacy/core_plugins/kibana/public/discover/helpers/build_services.ts +++ b/src/legacy/core_plugins/kibana/public/discover/build_services.ts @@ -26,14 +26,13 @@ import { } from 'kibana/public'; import * as docViewsRegistry from 'ui/registry/doc_views'; import { FilterManager, TimefilterContract, IndexPatternsContract } from 'src/plugins/data/public'; +import { createSavedSearchesService } from './saved_searches'; // @ts-ignore -import { createSavedSearchesService } from '../saved_searches'; -// @ts-ignore -import { DiscoverStartPlugins } from '../plugin'; -import { DataStart } from '../../../../data/public'; -import { EuiUtilsStart } from '../../../../../../plugins/eui_utils/public'; -import { SavedSearch } from '../types'; -import { SharePluginStart } from '../../../../../../plugins/share/public'; +import { DiscoverStartPlugins } from './plugin'; +import { DataStart } from '../../../data/public'; +import { EuiUtilsStart } from '../../../../../plugins/eui_utils/public'; +import { SharePluginStart } from '../../../../../plugins/share/public'; +import { SavedSearch } from './np_ready/types'; export interface DiscoverServices { addBasePath: (path: string) => string; diff --git a/src/legacy/core_plugins/kibana/public/discover/components/field_chooser/_index.scss b/src/legacy/core_plugins/kibana/public/discover/components/field_chooser/_index.scss deleted file mode 100644 index ad65834519eb1..0000000000000 --- a/src/legacy/core_plugins/kibana/public/discover/components/field_chooser/_index.scss +++ /dev/null @@ -1 +0,0 @@ -@import './field_chooser'; diff --git a/src/legacy/core_plugins/kibana/public/discover/get_inner_angular.ts b/src/legacy/core_plugins/kibana/public/discover/get_inner_angular.ts index 1335dbb01d4a7..1cefabe08c2d5 100644 --- a/src/legacy/core_plugins/kibana/public/discover/get_inner_angular.ts +++ b/src/legacy/core_plugins/kibana/public/discover/get_inner_angular.ts @@ -69,24 +69,24 @@ import { configureAppAngularModule } from 'ui/legacy_compat'; import { IndexPatterns } from '../../../../../plugins/data/public'; import { Storage } from '../../../../../plugins/kibana_utils/public'; import { NavigationPublicPluginStart as NavigationStart } from '../../../../../plugins/navigation/public'; -import { createDocTableDirective } from './angular/doc_table/doc_table'; -import { createTableHeaderDirective } from './angular/doc_table/components/table_header'; +import { createDocTableDirective } from './np_ready/angular/doc_table/doc_table'; +import { createTableHeaderDirective } from './np_ready/angular/doc_table/components/table_header'; import { createToolBarPagerButtonsDirective, createToolBarPagerTextDirective, -} from './angular/doc_table/components/pager'; -import { createTableRowDirective } from './angular/doc_table/components/table_row'; -import { createPagerFactory } from './angular/doc_table/lib/pager/pager_factory'; -import { createInfiniteScrollDirective } from './angular/doc_table/infinite_scroll'; -import { createDocViewerDirective } from './angular/doc_viewer'; -import { createFieldSearchDirective } from './components/field_chooser/discover_field_search_directive'; -import { createIndexPatternSelectDirective } from './components/field_chooser/discover_index_pattern_directive'; -import { createStringFieldProgressBarDirective } from './components/field_chooser/string_progress_bar'; +} from './np_ready/angular/doc_table/components/pager'; +import { createTableRowDirective } from './np_ready/angular/doc_table/components/table_row'; +import { createPagerFactory } from './np_ready/angular/doc_table/lib/pager/pager_factory'; +import { createInfiniteScrollDirective } from './np_ready/angular/doc_table/infinite_scroll'; +import { createDocViewerDirective } from './np_ready/angular/doc_viewer'; +import { createFieldSearchDirective } from './np_ready/components/field_chooser/discover_field_search_directive'; +import { createIndexPatternSelectDirective } from './np_ready/components/field_chooser/discover_index_pattern_directive'; +import { createStringFieldProgressBarDirective } from './np_ready/components/field_chooser/string_progress_bar'; // @ts-ignore -import { createFieldChooserDirective } from './components/field_chooser/field_chooser'; +import { createFieldChooserDirective } from './np_ready/components/field_chooser/field_chooser'; // @ts-ignore -import { createDiscoverFieldDirective } from './components/field_chooser/discover_field'; +import { createDiscoverFieldDirective } from './np_ready/components/field_chooser/discover_field'; import { DiscoverStartPlugins } from './plugin'; /** diff --git a/src/legacy/core_plugins/kibana/public/discover/kibana_services.ts b/src/legacy/core_plugins/kibana/public/discover/kibana_services.ts index d13d0dc868a58..ae388a243dd2b 100644 --- a/src/legacy/core_plugins/kibana/public/discover/kibana_services.ts +++ b/src/legacy/core_plugins/kibana/public/discover/kibana_services.ts @@ -17,7 +17,7 @@ * under the License. */ import angular from 'angular'; // just used in embeddables and discover controller -import { DiscoverServices } from './helpers/build_services'; +import { DiscoverServices } from './build_services'; let angularModule: any = null; let services: DiscoverServices | null = null; @@ -47,6 +47,10 @@ export function setServices(newServices: any) { services = newServices; } +// import directives that +import 'ui/directives/css_truncate'; +import 'ui/directives/field_name'; + // EXPORT legacy static dependencies, should be migrated when available in a new version; export { angular }; export { wrapInI18nContext } from 'ui/i18n'; @@ -59,6 +63,9 @@ export { hasSearchStategyForIndexPattern, isDefaultTypeIndexPattern, SearchSource, + EsQuerySortValue, + SortDirection, + SearchSourceContract, } from '../../../../ui/public/courier'; // @ts-ignore export { intervalOptions } from 'ui/agg_types/buckets/_interval_options'; @@ -78,6 +85,8 @@ export { tabifyAggResponse } from 'ui/agg_response/tabify'; export { vislibSeriesResponseHandlerProvider } from 'ui/vis/response_handlers/vislib'; export { ensureDefaultIndexPattern } from 'ui/legacy_compat'; export { unhashUrl } from '../../../../../plugins/kibana_utils/public'; +// @ts-ignore +export { formatMsg, formatStack } from 'ui/notify/lib/index'; // EXPORT types export { Vis } from 'ui/vis'; @@ -90,3 +99,6 @@ export { export { ElasticSearchHit } from 'ui/registry/doc_views_types'; export { DocViewRenderProps, DocViewRenderFn } from 'ui/registry/doc_views'; export { Adapters } from 'ui/inspector/types'; +export { DocView, DocViewInput } from 'ui/registry/doc_views_types'; +export { registerTimefilterWithGlobalStateFactory } from 'ui/timefilter/setup_router'; +export { IInjector } from 'ui/chrome'; diff --git a/src/legacy/core_plugins/kibana/public/discover/_discover.scss b/src/legacy/core_plugins/kibana/public/discover/np_ready/_discover.scss similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/_discover.scss rename to src/legacy/core_plugins/kibana/public/discover/np_ready/_discover.scss diff --git a/src/legacy/core_plugins/kibana/public/discover/_hacks.scss b/src/legacy/core_plugins/kibana/public/discover/np_ready/_hacks.scss similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/_hacks.scss rename to src/legacy/core_plugins/kibana/public/discover/np_ready/_hacks.scss diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/_index.scss b/src/legacy/core_plugins/kibana/public/discover/np_ready/_index.scss new file mode 100644 index 0000000000000..0de036b1e1707 --- /dev/null +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/_index.scss @@ -0,0 +1,15 @@ +// Discover plugin styles +@import 'mixins'; +@import 'discover'; +@import 'hacks'; + +// Prefix all styles with "dsc" to avoid conflicts. +// Examples +// dscTable +// dscTable__footer +// monChart__legend--small +// monChart__legend-isLoading + +@import 'components/index'; +@import 'angular/index'; +@import 'embeddable/index'; diff --git a/src/legacy/core_plugins/kibana/public/discover/_mixins.scss b/src/legacy/core_plugins/kibana/public/discover/np_ready/_mixins.scss similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/_mixins.scss rename to src/legacy/core_plugins/kibana/public/discover/np_ready/_mixins.scss diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/_index.scss b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/_index.scss new file mode 100644 index 0000000000000..9e00ade3d41f6 --- /dev/null +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/_index.scss @@ -0,0 +1,3 @@ +@import 'directives/index'; +@import 'doc_table/index'; +@import 'context/index'; diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/context.html b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context.html similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/context.html rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context.html diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/context.js b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context.js similarity index 97% rename from src/legacy/core_plugins/kibana/public/discover/angular/context.js rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context.js index d33e3424e4647..a370c66ae330b 100644 --- a/src/legacy/core_plugins/kibana/public/discover/angular/context.js +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context.js @@ -19,12 +19,12 @@ import _ from 'lodash'; import { i18n } from '@kbn/i18n'; -import { getAngularModule, getServices, subscribeWithScope } from './../kibana_services'; +import { getAngularModule, getServices, subscribeWithScope } from '../../kibana_services'; import './context_app'; import contextAppRouteTemplate from './context.html'; import { getRootBreadcrumbs } from '../helpers/breadcrumbs'; -import { FilterStateManager } from '../../../../data/public/filter/filter_manager'; +import { FilterStateManager } from '../../../../../data/public'; const { chrome } = getServices(); const k7Breadcrumbs = $route => { diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/context/NOTES.md b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/NOTES.md similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/context/NOTES.md rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/NOTES.md diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/context/_index.scss b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/_index.scss similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/context/_index.scss rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/_index.scss diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/context/api/__tests__/_stubs.js b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/__tests__/_stubs.js similarity index 98% rename from src/legacy/core_plugins/kibana/public/discover/angular/context/api/__tests__/_stubs.js rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/__tests__/_stubs.js index 3bc83cacaaf28..53be4e5bd0f2d 100644 --- a/src/legacy/core_plugins/kibana/public/discover/angular/context/api/__tests__/_stubs.js +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/__tests__/_stubs.js @@ -19,7 +19,7 @@ import sinon from 'sinon'; import moment from 'moment'; -import { SearchSource } from '../../../../kibana_services'; +import { SearchSource } from '../../../../../kibana_services'; export function createIndexPatternsStub() { return { diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/context/api/__tests__/anchor.js b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/__tests__/anchor.js similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/context/api/__tests__/anchor.js rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/__tests__/anchor.js diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/context/api/__tests__/predecessors.js b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/__tests__/predecessors.js similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/context/api/__tests__/predecessors.js rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/__tests__/predecessors.js diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/context/api/__tests__/successors.js b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/__tests__/successors.js similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/context/api/__tests__/successors.js rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/__tests__/successors.js diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/context/api/anchor.js b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/anchor.js similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/context/api/anchor.js rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/anchor.js diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/context/api/context.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/context.ts similarity index 97% rename from src/legacy/core_plugins/kibana/public/discover/angular/context/api/context.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/context.ts index fd71b7c49e837..a6c6d91084625 100644 --- a/src/legacy/core_plugins/kibana/public/discover/angular/context/api/context.ts +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/context.ts @@ -17,14 +17,14 @@ * under the License. */ -import { IndexPattern, SearchSource } from '../../../kibana_services'; +import { IndexPattern, SearchSource } from '../../../../kibana_services'; import { reverseSortDir, SortDirection } from './utils/sorting'; import { extractNanos, convertIsoToMillis } from './utils/date_conversion'; import { fetchHitsInInterval } from './utils/fetch_hits_in_interval'; import { generateIntervals } from './utils/generate_intervals'; import { getEsQuerySearchAfter } from './utils/get_es_query_search_after'; import { getEsQuerySort } from './utils/get_es_query_sort'; -import { esFilters, IndexPatternsContract } from '../../../../../../../../plugins/data/public'; +import { esFilters, IndexPatternsContract } from '../../../../../../../../../plugins/data/public'; export type SurrDocType = 'successors' | 'predecessors'; export interface EsHitRecord { diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/context/api/utils/__tests__/date_conversion.test.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/utils/__tests__/date_conversion.test.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/context/api/utils/__tests__/date_conversion.test.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/utils/__tests__/date_conversion.test.ts diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/context/api/utils/__tests__/sorting.test.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/utils/__tests__/sorting.test.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/context/api/utils/__tests__/sorting.test.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/utils/__tests__/sorting.test.ts diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/context/api/utils/date_conversion.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/utils/date_conversion.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/context/api/utils/date_conversion.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/utils/date_conversion.ts diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/context/api/utils/fetch_hits_in_interval.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/utils/fetch_hits_in_interval.ts similarity index 97% rename from src/legacy/core_plugins/kibana/public/discover/angular/context/api/utils/fetch_hits_in_interval.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/utils/fetch_hits_in_interval.ts index 19c2ee2cdfe10..1351421e1af04 100644 --- a/src/legacy/core_plugins/kibana/public/discover/angular/context/api/utils/fetch_hits_in_interval.ts +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/utils/fetch_hits_in_interval.ts @@ -20,7 +20,7 @@ import { EsQuerySortValue, SortDirection, SearchSourceContract, -} from '../../../../../../../../ui/public/courier'; +} from '../../../../../kibana_services'; import { convertTimeValueToIso } from './date_conversion'; import { EsHitRecordList } from '../context'; import { IntervalValue } from './generate_intervals'; diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/context/api/utils/generate_intervals.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/utils/generate_intervals.ts similarity index 96% rename from src/legacy/core_plugins/kibana/public/discover/angular/context/api/utils/generate_intervals.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/utils/generate_intervals.ts index cb4878239ff92..373dc37e56f6f 100644 --- a/src/legacy/core_plugins/kibana/public/discover/angular/context/api/utils/generate_intervals.ts +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/utils/generate_intervals.ts @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -import { SortDirection } from '../../../../../../../../ui/public/courier'; +import { SortDirection } from '../../../../../kibana_services'; export type IntervalValue = number | null; diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/context/api/utils/get_es_query_search_after.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/utils/get_es_query_search_after.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/context/api/utils/get_es_query_search_after.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/utils/get_es_query_search_after.ts diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/context/api/utils/get_es_query_sort.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/utils/get_es_query_sort.ts similarity index 97% rename from src/legacy/core_plugins/kibana/public/discover/angular/context/api/utils/get_es_query_sort.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/utils/get_es_query_sort.ts index 39c69112e58cb..8bcf5328f24ba 100644 --- a/src/legacy/core_plugins/kibana/public/discover/angular/context/api/utils/get_es_query_sort.ts +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/utils/get_es_query_sort.ts @@ -17,7 +17,7 @@ * under the License. */ -import { EsQuerySortValue, SortDirection } from '../../../../../../../../ui/public/courier/types'; +import { EsQuerySortValue, SortDirection } from '../../../../../kibana_services'; /** * Returns `EsQuerySort` which is used to sort records in the ES query diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/context/api/utils/sorting.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/utils/sorting.ts similarity index 96% rename from src/legacy/core_plugins/kibana/public/discover/angular/context/api/utils/sorting.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/utils/sorting.ts index 4a0f531845f46..ef1be8d48d338 100644 --- a/src/legacy/core_plugins/kibana/public/discover/angular/context/api/utils/sorting.ts +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/utils/sorting.ts @@ -17,7 +17,7 @@ * under the License. */ -import { IndexPattern } from '../../../../kibana_services'; +import { IndexPattern } from '../../../../../kibana_services'; export enum SortDirection { asc = 'asc', diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/context/components/action_bar/_action_bar.scss b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/components/action_bar/_action_bar.scss similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/context/components/action_bar/_action_bar.scss rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/components/action_bar/_action_bar.scss diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/context/components/action_bar/_index.scss b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/components/action_bar/_index.scss similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/context/components/action_bar/_index.scss rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/components/action_bar/_index.scss diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/context/components/action_bar/action_bar.test.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/components/action_bar/action_bar.test.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/context/components/action_bar/action_bar.test.tsx rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/components/action_bar/action_bar.test.tsx diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/context/components/action_bar/action_bar.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/components/action_bar/action_bar.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/context/components/action_bar/action_bar.tsx rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/components/action_bar/action_bar.tsx diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/context/components/action_bar/action_bar_directive.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/components/action_bar/action_bar_directive.ts similarity index 97% rename from src/legacy/core_plugins/kibana/public/discover/angular/context/components/action_bar/action_bar_directive.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/components/action_bar/action_bar_directive.ts index 55a378367392c..697b039adde81 100644 --- a/src/legacy/core_plugins/kibana/public/discover/angular/context/components/action_bar/action_bar_directive.ts +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/components/action_bar/action_bar_directive.ts @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -import { getAngularModule, wrapInI18nContext } from '../../../../kibana_services'; +import { getAngularModule, wrapInI18nContext } from '../../../../../kibana_services'; import { ActionBar } from './action_bar'; getAngularModule().directive('contextActionBar', function(reactDirective: any) { diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/context/components/action_bar/action_bar_warning.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/components/action_bar/action_bar_warning.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/context/components/action_bar/action_bar_warning.tsx rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/components/action_bar/action_bar_warning.tsx diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/context/components/action_bar/index.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/components/action_bar/index.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/context/components/action_bar/index.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/components/action_bar/index.ts diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/context/query/actions.js b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/query/actions.js similarity index 97% rename from src/legacy/core_plugins/kibana/public/discover/angular/context/query/actions.js rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/query/actions.js index b7f6fab676a1e..966ecffda7755 100644 --- a/src/legacy/core_plugins/kibana/public/discover/angular/context/query/actions.js +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/query/actions.js @@ -20,13 +20,13 @@ import _ from 'lodash'; import { i18n } from '@kbn/i18n'; import React from 'react'; -import { getServices, SearchSource } from '../../../kibana_services'; +import { getServices, SearchSource } from '../../../../kibana_services'; import { fetchAnchorProvider } from '../api/anchor'; import { fetchContextProvider } from '../api/context'; import { getQueryParameterActions } from '../query_parameters'; import { FAILURE_REASONS, LOADING_STATUS } from './constants'; -import { MarkdownSimple } from '../../../../../../kibana_react/public'; +import { MarkdownSimple } from '../../../../../../../kibana_react/public'; export function QueryActionsProvider(Promise) { const fetchAnchor = fetchAnchorProvider(getServices().indexPatterns, new SearchSource()); diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/context/query/constants.js b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/query/constants.js similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/context/query/constants.js rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/query/constants.js diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/context/query/index.js b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/query/index.js similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/context/query/index.js rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/query/index.js diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/context/query/state.js b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/query/state.js similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/context/query/state.js rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/query/state.js diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/context/query_parameters/actions.js b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/query_parameters/actions.js similarity index 94% rename from src/legacy/core_plugins/kibana/public/discover/angular/context/query_parameters/actions.js rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/query_parameters/actions.js index 01573f8983d0f..c5f1836bcc0e1 100644 --- a/src/legacy/core_plugins/kibana/public/discover/angular/context/query_parameters/actions.js +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/query_parameters/actions.js @@ -18,8 +18,8 @@ */ import _ from 'lodash'; -import { getServices } from '../../../kibana_services'; -import { generateFilters } from '../../../../../../../../plugins/data/public'; +import { getServices } from '../../../../kibana_services'; +import { generateFilters } from '../../../../../../../../../plugins/data/public'; import { MAX_CONTEXT_SIZE, MIN_CONTEXT_SIZE, QUERY_PARAMETER_KEYS } from './constants'; diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/context/query_parameters/constants.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/query_parameters/constants.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/context/query_parameters/constants.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/query_parameters/constants.ts diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/context/query_parameters/index.js b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/query_parameters/index.js similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/context/query_parameters/index.js rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/query_parameters/index.js diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/context/query_parameters/state.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/query_parameters/state.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/context/query_parameters/state.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/query_parameters/state.ts diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/context_app.html b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context_app.html similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/context_app.html rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context_app.html diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/context_app.js b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context_app.js similarity index 97% rename from src/legacy/core_plugins/kibana/public/discover/angular/context_app.js rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context_app.js index 3f91980ccc50f..5fa0958249d79 100644 --- a/src/legacy/core_plugins/kibana/public/discover/angular/context_app.js +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context_app.js @@ -18,7 +18,7 @@ */ import _ from 'lodash'; -import { getServices, callAfterBindingsWorkaround, getAngularModule } from './../kibana_services'; +import { getServices, callAfterBindingsWorkaround, getAngularModule } from '../../kibana_services'; import contextAppTemplate from './context_app.html'; import './context/components/action_bar'; import { getFirstSortableField } from './context/api/utils/sorting'; @@ -36,9 +36,6 @@ import { const { timefilter } = getServices(); -// load directives -import '../../../../data/public/legacy'; - const module = getAngularModule(); module.directive('contextApp', function ContextApp() { diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/directives/__snapshots__/no_results.test.js.snap b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/__snapshots__/no_results.test.js.snap similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/directives/__snapshots__/no_results.test.js.snap rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/__snapshots__/no_results.test.js.snap diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/directives/_histogram.scss b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/_histogram.scss similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/directives/_histogram.scss rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/_histogram.scss diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/directives/_index.scss b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/_index.scss similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/directives/_index.scss rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/_index.scss diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/directives/_no_results.scss b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/_no_results.scss similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/directives/_no_results.scss rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/_no_results.scss diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/directives/histogram.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/histogram.tsx similarity index 99% rename from src/legacy/core_plugins/kibana/public/discover/angular/directives/histogram.tsx rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/histogram.tsx index 496e1cf375588..28ce64c0a5f9c 100644 --- a/src/legacy/core_plugins/kibana/public/discover/angular/directives/histogram.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/histogram.tsx @@ -45,7 +45,7 @@ import { import { i18n } from '@kbn/i18n'; import { EuiChartThemeType } from '@elastic/eui/src/themes/charts/themes'; import { Subscription } from 'rxjs'; -import { getServices, timezoneProvider } from '../../kibana_services'; +import { getServices, timezoneProvider } from '../../../kibana_services'; export interface DiscoverHistogramProps { chartData: any; diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/directives/index.js b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/index.js similarity index 91% rename from src/legacy/core_plugins/kibana/public/discover/angular/directives/index.js rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/index.js index eb4cf10a2d28f..1a3922dfc2008 100644 --- a/src/legacy/core_plugins/kibana/public/discover/angular/directives/index.js +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/index.js @@ -17,12 +17,11 @@ * under the License. */ -import '../../../../../../ui/public/render_complete/directive'; import { DiscoverNoResults } from './no_results'; import { DiscoverUninitialized } from './uninitialized'; import { DiscoverUnsupportedIndexPattern } from './unsupported_index_pattern'; import { DiscoverHistogram } from './histogram'; -import { getAngularModule, wrapInI18nContext } from '../../kibana_services'; +import { getAngularModule, wrapInI18nContext } from '../../../kibana_services'; const app = getAngularModule(); diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/directives/no_results.js b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/no_results.js similarity index 99% rename from src/legacy/core_plugins/kibana/public/discover/angular/directives/no_results.js rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/no_results.js index d22a8d495bd0e..ba02068590c14 100644 --- a/src/legacy/core_plugins/kibana/public/discover/angular/directives/no_results.js +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/no_results.js @@ -32,7 +32,7 @@ import { EuiSpacer, EuiText, } from '@elastic/eui'; -import { getServices } from '../../kibana_services'; +import { getServices } from '../../../kibana_services'; // eslint-disable-next-line react/prefer-stateless-function export class DiscoverNoResults extends Component { diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/directives/no_results.test.js b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/no_results.test.js similarity index 98% rename from src/legacy/core_plugins/kibana/public/discover/angular/directives/no_results.test.js rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/no_results.test.js index 33dff54f94c7f..7de792c612993 100644 --- a/src/legacy/core_plugins/kibana/public/discover/angular/directives/no_results.test.js +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/no_results.test.js @@ -22,7 +22,7 @@ import { renderWithIntl } from 'test_utils/enzyme_helpers'; import { DiscoverNoResults } from './no_results'; -jest.mock('../../kibana_services', () => { +jest.mock('../../../kibana_services', () => { return { getServices: () => ({ docLinks: { diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/directives/uninitialized.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/uninitialized.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/directives/uninitialized.tsx rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/uninitialized.tsx diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/directives/unsupported_index_pattern.js b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/unsupported_index_pattern.js similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/directives/unsupported_index_pattern.js rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/unsupported_index_pattern.js diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/discover.html b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/discover.html similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/discover.html rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/discover.html diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/discover.js b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/discover.js similarity index 99% rename from src/legacy/core_plugins/kibana/public/discover/angular/discover.js rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/discover.js index 39a7bb96e11e0..abf025524522b 100644 --- a/src/legacy/core_plugins/kibana/public/discover/angular/discover.js +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/discover.js @@ -57,7 +57,8 @@ import { SavedObjectSaveModal, getAngularModule, ensureDefaultIndexPattern, -} from '../kibana_services'; + registerTimefilterWithGlobalStateFactory, +} from '../../kibana_services'; const { core, @@ -72,10 +73,9 @@ const { } = getServices(); import { getRootBreadcrumbs, getSavedSearchBreadcrumbs } from '../helpers/breadcrumbs'; -import { generateFilters } from '../../../../../../plugins/data/public'; +import { generateFilters } from '../../../../../../../plugins/data/public'; import { getIndexPatternId } from '../helpers/get_index_pattern_id'; -import { registerTimefilterWithGlobalStateFactory } from '../../../../../ui/public/timefilter/setup_router'; -import { FilterStateManager } from '../../../../data/public/filter/filter_manager'; +import { FilterStateManager } from '../../../../../data/public'; const { getSavedQuery } = data.query.savedQueries; @@ -328,6 +328,7 @@ function discoverController( makeUrl: searchId => { return kbnUrl.eval('#/discover/{{id}}', { id: searchId }); }, + I18nContext: core.i18n.Context, }); }, }; diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc.html b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc.html similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc.html rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc.html diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc.ts similarity index 98% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc.ts index af9556656afab..459dcfb30d17b 100644 --- a/src/legacy/core_plugins/kibana/public/discover/angular/doc.ts +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc.ts @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -import { getAngularModule, wrapInI18nContext, getServices } from '../kibana_services'; +import { getAngularModule, wrapInI18nContext, getServices } from '../../kibana_services'; // @ts-ignore import { getRootBreadcrumbs } from '../helpers/breadcrumbs'; import html from './doc.html'; diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/_doc_table.scss b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/_doc_table.scss similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc_table/_doc_table.scss rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/_doc_table.scss diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/_index.scss b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/_index.scss new file mode 100644 index 0000000000000..3663d807851c4 --- /dev/null +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/_index.scss @@ -0,0 +1,2 @@ +@import 'doc_table'; +@import 'components/index'; diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/actions/columns.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/actions/columns.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc_table/actions/columns.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/actions/columns.ts diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/_index.scss b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/_index.scss new file mode 100644 index 0000000000000..6a294c1ed173d --- /dev/null +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/_index.scss @@ -0,0 +1,2 @@ +@import 'table_header'; +@import 'table_row/index'; diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/_table_header.scss b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/_table_header.scss similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/_table_header.scss rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/_table_header.scss diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/pager/__snapshots__/tool_bar_pager_buttons.test.tsx.snap b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/pager/__snapshots__/tool_bar_pager_buttons.test.tsx.snap similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/pager/__snapshots__/tool_bar_pager_buttons.test.tsx.snap rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/pager/__snapshots__/tool_bar_pager_buttons.test.tsx.snap diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/pager/__snapshots__/tool_bar_pager_text.test.tsx.snap b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/pager/__snapshots__/tool_bar_pager_text.test.tsx.snap similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/pager/__snapshots__/tool_bar_pager_text.test.tsx.snap rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/pager/__snapshots__/tool_bar_pager_text.test.tsx.snap diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/pager/index.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/pager/index.ts similarity index 94% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/pager/index.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/pager/index.ts index 3a037971a1253..f21f3b17c6955 100644 --- a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/pager/index.ts +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/pager/index.ts @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -import { wrapInI18nContext } from '../../../../kibana_services'; +import { wrapInI18nContext } from '../../../../../kibana_services'; import { ToolBarPagerText } from './tool_bar_pager_text'; import { ToolBarPagerButtons } from './tool_bar_pager_buttons'; diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/pager/tool_bar_pager_buttons.test.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/pager/tool_bar_pager_buttons.test.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/pager/tool_bar_pager_buttons.test.tsx rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/pager/tool_bar_pager_buttons.test.tsx diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/pager/tool_bar_pager_buttons.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/pager/tool_bar_pager_buttons.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/pager/tool_bar_pager_buttons.tsx rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/pager/tool_bar_pager_buttons.tsx diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/pager/tool_bar_pager_text.test.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/pager/tool_bar_pager_text.test.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/pager/tool_bar_pager_text.test.tsx rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/pager/tool_bar_pager_text.test.tsx diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/pager/tool_bar_pager_text.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/pager/tool_bar_pager_text.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/pager/tool_bar_pager_text.tsx rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/pager/tool_bar_pager_text.tsx diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/table_header.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/table_header.ts similarity index 96% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/table_header.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/table_header.ts index 055f14f164476..a5cb9180333a4 100644 --- a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/table_header.ts +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/table_header.ts @@ -16,9 +16,9 @@ * specific language governing permissions and limitations * under the License. */ -import { wrapInI18nContext } from 'ui/i18n'; import { IUiSettingsClient } from 'kibana/public'; import { TableHeader } from './table_header/table_header'; +import { wrapInI18nContext } from '../../../../kibana_services'; export function createTableHeaderDirective(reactDirective: any, config: IUiSettingsClient) { return reactDirective( diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/table_header/__snapshots__/table_header.test.tsx.snap b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/table_header/__snapshots__/table_header.test.tsx.snap similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/table_header/__snapshots__/table_header.test.tsx.snap rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/table_header/__snapshots__/table_header.test.tsx.snap diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/table_header/helpers.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/table_header/helpers.tsx similarity index 94% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/table_header/helpers.tsx rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/table_header/helpers.tsx index 80f963c8ccb3e..13833d724967a 100644 --- a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/table_header/helpers.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/table_header/helpers.tsx @@ -16,9 +16,9 @@ * specific language governing permissions and limitations * under the License. */ -import { IndexPattern } from '../../../../kibana_services'; +import { IndexPattern } from '../../../../../kibana_services'; // @ts-ignore -import { shortenDottedString } from '../../../../../../common/utils/shorten_dotted_string'; +import { shortenDottedString } from '../../../../../../../common/utils/shorten_dotted_string'; export type SortOrder = [string, 'asc' | 'desc']; export interface ColumnProps { diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/table_header/table_header.test.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/table_header/table_header.test.tsx similarity index 98% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/table_header/table_header.test.tsx rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/table_header/table_header.test.tsx index e5706b5e3c9bb..ef3d4ecc4b18f 100644 --- a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/table_header/table_header.test.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/table_header/table_header.test.tsx @@ -23,7 +23,7 @@ import { TableHeader } from './table_header'; // @ts-ignore import { findTestSubject } from '@elastic/eui/lib/test'; import { SortOrder } from './helpers'; -import { IndexPattern, IFieldType } from '../../../../kibana_services'; +import { IndexPattern, IFieldType } from '../../../../../kibana_services'; function getMockIndexPattern() { return ({ diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/table_header/table_header.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/table_header/table_header.tsx similarity index 96% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/table_header/table_header.tsx rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/table_header/table_header.tsx index 71674710ac855..17b961dbe6832 100644 --- a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/table_header/table_header.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/table_header/table_header.tsx @@ -17,7 +17,7 @@ * under the License. */ import React from 'react'; -import { IndexPattern } from '../../../../kibana_services'; +import { IndexPattern } from '../../../../../kibana_services'; // @ts-ignore import { TableHeaderColumn } from './table_header_column'; import { SortOrder, getDisplayedColumns } from './helpers'; diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/table_header/table_header_column.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/table_header/table_header_column.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/table_header/table_header_column.tsx rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/table_header/table_header_column.tsx diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/table_row.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/table_row.ts similarity index 97% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/table_row.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/table_row.ts index 8ff4ab46ef532..8df035d098469 100644 --- a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/table_row.ts +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/table_row.ts @@ -24,15 +24,15 @@ import { IUiSettingsClient } from 'kibana/public'; import rison from 'rison-node'; import '../../doc_viewer'; // @ts-ignore -import { noWhiteSpace } from '../../../../../common/utils/no_white_space'; +import { noWhiteSpace } from '../../../../../../common/utils/no_white_space'; import openRowHtml from './table_row/open.html'; import detailsHtml from './table_row/details.html'; -import { dispatchRenderComplete } from '../../../../../../../../plugins/kibana_utils/public'; +import { dispatchRenderComplete } from '../../../../../../../../../plugins/kibana_utils/public'; import cellTemplateHtml from '../components/table_row/cell.html'; import truncateByHeightTemplateHtml from '../components/table_row/truncate_by_height.html'; -import { esFilters } from '../../../../../../../../plugins/data/public'; +import { esFilters } from '../../../../../../../../../plugins/data/public'; // guesstimate at the minimum number of chars wide cells in the table should be const MIN_LINE_LENGTH = 20; diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/table_row/_cell.scss b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/table_row/_cell.scss similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/table_row/_cell.scss rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/table_row/_cell.scss diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/table_row/_details.scss b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/table_row/_details.scss similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/table_row/_details.scss rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/table_row/_details.scss diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/table_row/_index.scss b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/table_row/_index.scss new file mode 100644 index 0000000000000..c7ccdaa39ff65 --- /dev/null +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/table_row/_index.scss @@ -0,0 +1,3 @@ +@import 'cell'; +@import 'details'; +@import 'open'; diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/table_row/_open.scss b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/table_row/_open.scss similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/table_row/_open.scss rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/table_row/_open.scss diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/table_row/cell.html b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/table_row/cell.html similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/table_row/cell.html rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/table_row/cell.html diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/table_row/details.html b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/table_row/details.html similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/table_row/details.html rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/table_row/details.html diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/table_row/open.html b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/table_row/open.html similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/table_row/open.html rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/table_row/open.html diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/table_row/truncate_by_height.html b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/table_row/truncate_by_height.html similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc_table/components/table_row/truncate_by_height.html rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/components/table_row/truncate_by_height.html diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/doc_table.html b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/doc_table.html similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc_table/doc_table.html rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/doc_table.html diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/doc_table.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/doc_table.ts similarity index 97% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc_table/doc_table.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/doc_table.ts index 92ebc24c6e378..3329ffc7cd102 100644 --- a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/doc_table.ts +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/doc_table.ts @@ -23,7 +23,7 @@ import html from './doc_table.html'; import './infinite_scroll'; import './components/table_header'; import './components/table_row'; -import { dispatchRenderComplete } from '../../../../../../../plugins/kibana_utils/public'; +import { dispatchRenderComplete } from '../../../../../../../../plugins/kibana_utils/public'; import './components/pager'; import './lib/pager'; // @ts-ignore diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/doc_table_strings.js b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/doc_table_strings.js similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc_table/doc_table_strings.js rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/doc_table_strings.js diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/index.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/index.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc_table/index.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/index.ts diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/infinite_scroll.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/infinite_scroll.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc_table/infinite_scroll.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/infinite_scroll.ts diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/lib/get_sort.d.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/lib/get_sort.d.ts similarity index 92% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc_table/lib/get_sort.d.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/lib/get_sort.d.ts index ebf715a64d939..0bf8a93a88367 100644 --- a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/lib/get_sort.d.ts +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/lib/get_sort.d.ts @@ -17,7 +17,7 @@ * under the License. */ -import { IIndexPattern } from '../../../../../../../../plugins/data/public'; +import { IIndexPattern } from '../../../../../../../../../plugins/data/public'; import { SortOrder } from '../components/table_header/helpers'; export function getSort( diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/lib/get_sort.js b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/lib/get_sort.js similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc_table/lib/get_sort.js rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/lib/get_sort.js diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/lib/get_sort_for_search_source.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/lib/get_sort_for_search_source.ts similarity index 96% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc_table/lib/get_sort_for_search_source.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/lib/get_sort_for_search_source.ts index 952eadf7cbd94..26bba4589cf6a 100644 --- a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/lib/get_sort_for_search_source.ts +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/lib/get_sort_for_search_source.ts @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -import { IndexPattern } from '../../../kibana_services'; +import { IndexPattern } from '../../../../kibana_services'; import { SortOrder } from '../components/table_header/helpers'; import { getSort } from './get_sort'; diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/lib/pager/index.js b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/lib/pager/index.js similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc_table/lib/pager/index.js rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/lib/pager/index.js diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/lib/pager/pager.js b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/lib/pager/pager.js similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc_table/lib/pager/pager.js rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/lib/pager/pager.js diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_table/lib/pager/pager_factory.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/lib/pager/pager_factory.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc_table/lib/pager/pager_factory.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_table/lib/pager/pager_factory.ts diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/doc_viewer.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_viewer.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/doc_viewer.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_viewer.ts diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/get_painless_error.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/get_painless_error.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/get_painless_error.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/get_painless_error.ts diff --git a/src/legacy/core_plugins/kibana/public/discover/angular/index.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/index.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/angular/index.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/index.ts diff --git a/src/legacy/core_plugins/kibana/public/discover/application.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/application.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/application.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/application.ts diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/_index.scss b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/_index.scss new file mode 100644 index 0000000000000..0491430e5fddd --- /dev/null +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/_index.scss @@ -0,0 +1,3 @@ +@import 'fetch_error/index'; +@import 'field_chooser/index'; +@import 'doc_viewer/index'; diff --git a/src/legacy/core_plugins/kibana/public/discover/components/doc/doc.test.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc/doc.test.tsx similarity index 98% rename from src/legacy/core_plugins/kibana/public/discover/components/doc/doc.test.tsx rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc/doc.test.tsx index 4df56483fa5c6..656e8598aa12f 100644 --- a/src/legacy/core_plugins/kibana/public/discover/components/doc/doc.test.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc/doc.test.tsx @@ -28,7 +28,7 @@ jest.mock('../doc_viewer/doc_viewer', () => ({ DocViewer: 'test', })); -jest.mock('../../kibana_services', () => { +jest.mock('../../../kibana_services', () => { return { getServices: () => ({ metadata: { diff --git a/src/legacy/core_plugins/kibana/public/discover/components/doc/doc.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc/doc.tsx similarity index 98% rename from src/legacy/core_plugins/kibana/public/discover/components/doc/doc.tsx rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc/doc.tsx index 7020addb2bc6d..819eb9df592bd 100644 --- a/src/legacy/core_plugins/kibana/public/discover/components/doc/doc.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc/doc.tsx @@ -22,7 +22,7 @@ import { EuiCallOut, EuiLink, EuiLoadingSpinner, EuiPageContent } from '@elastic import { IndexPatternsContract } from 'src/plugins/data/public'; import { DocViewer } from '../doc_viewer/doc_viewer'; import { ElasticRequestState, useEsDocSearch } from './use_es_doc_search'; -import { ElasticSearchHit, getServices } from '../../kibana_services'; +import { ElasticSearchHit, getServices } from '../../../kibana_services'; export interface ElasticSearchResult { hits: { diff --git a/src/legacy/core_plugins/kibana/public/discover/components/doc/use_es_doc_search.test.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc/use_es_doc_search.test.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/components/doc/use_es_doc_search.test.tsx rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc/use_es_doc_search.test.tsx diff --git a/src/legacy/core_plugins/kibana/public/discover/components/doc/use_es_doc_search.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc/use_es_doc_search.ts similarity index 97% rename from src/legacy/core_plugins/kibana/public/discover/components/doc/use_es_doc_search.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc/use_es_doc_search.ts index 20bffe829de16..a40d9731a04f5 100644 --- a/src/legacy/core_plugins/kibana/public/discover/components/doc/use_es_doc_search.ts +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc/use_es_doc_search.ts @@ -17,7 +17,7 @@ * under the License. */ import { useEffect, useState } from 'react'; -import { ElasticSearchHit, IndexPattern } from '../../kibana_services'; +import { ElasticSearchHit, IndexPattern } from '../../../kibana_services'; import { DocProps } from './doc'; export enum ElasticRequestState { diff --git a/src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/__snapshots__/doc_viewer.test.tsx.snap b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/__snapshots__/doc_viewer.test.tsx.snap similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/__snapshots__/doc_viewer.test.tsx.snap rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/__snapshots__/doc_viewer.test.tsx.snap diff --git a/src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/__snapshots__/doc_viewer_render_tab.test.tsx.snap b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/__snapshots__/doc_viewer_render_tab.test.tsx.snap similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/__snapshots__/doc_viewer_render_tab.test.tsx.snap rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/__snapshots__/doc_viewer_render_tab.test.tsx.snap diff --git a/src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/_doc_viewer.scss b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/_doc_viewer.scss similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/_doc_viewer.scss rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/_doc_viewer.scss diff --git a/src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/_index.scss b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/_index.scss similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/_index.scss rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/_index.scss diff --git a/src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/doc_viewer.test.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/doc_viewer.test.tsx similarity index 79% rename from src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/doc_viewer.test.tsx rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/doc_viewer.test.tsx index 158ed4ccc7759..c0644a6458694 100644 --- a/src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/doc_viewer.test.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/doc_viewer.test.tsx @@ -21,33 +21,46 @@ import { mount, shallow } from 'enzyme'; import { DocViewer } from './doc_viewer'; // @ts-ignore import { findTestSubject } from '@elastic/eui/lib/test'; -import { - addDocView, - emptyDocViews, - DocViewRenderProps, - getDocViewsSorted as mockGetDocViewsSorted, -} from 'ui/registry/doc_views'; +import { DocViewRenderProps, DocViewInput, getServices } from '../../../kibana_services'; + +jest.mock('../../../kibana_services', () => { + const docViews: DocViewInput[] = []; + + function addDocView(docView: DocViewInput) { + docViews.push(docView); + } -jest.mock('../../kibana_services', () => { return { getServices: () => ({ docViewsRegistry: { - getDocViewsSorted: (hit: any) => { - return mockGetDocViewsSorted(hit); + getDocViewsSorted: () => { + return docViews; }, + addDocView, + docViews, }, }), + formatMsg: (x: any) => String(x), + formatStack: (x: any) => String(x), }; }); +const { + docViewsRegistry: { docViews, addDocView }, +} = getServices(); + +function emptyDocViews() { + docViews.length = 0; +} + beforeEach(() => { emptyDocViews(); jest.clearAllMocks(); }); test('Render with 3 different tabs', () => { - addDocView({ order: 20, title: 'React component', component: () =>

test
}); addDocView({ order: 10, title: 'Render function', render: jest.fn() }); + addDocView({ order: 20, title: 'React component', component: () =>
test
}); addDocView({ order: 30, title: 'Invalid doc view' }); const renderProps = { hit: {} } as DocViewRenderProps; diff --git a/src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/doc_viewer.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/doc_viewer.tsx similarity index 93% rename from src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/doc_viewer.tsx rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/doc_viewer.tsx index a2d58439ad031..00926d70db25c 100644 --- a/src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/doc_viewer.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/doc_viewer.tsx @@ -17,9 +17,8 @@ * under the License. */ import React from 'react'; -import { DocView } from 'ui/registry/doc_views_types'; import { EuiTabbedContent } from '@elastic/eui'; -import { getServices, DocViewRenderProps } from '../../kibana_services'; +import { getServices, DocViewRenderProps, DocView } from '../../../kibana_services'; import { DocViewerTab } from './doc_viewer_tab'; /** diff --git a/src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/doc_viewer_render_error.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/doc_viewer_render_error.tsx similarity index 94% rename from src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/doc_viewer_render_error.tsx rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/doc_viewer_render_error.tsx index 80b9cb5110db7..201ed562cfd6f 100644 --- a/src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/doc_viewer_render_error.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/doc_viewer_render_error.tsx @@ -18,8 +18,7 @@ */ import React from 'react'; import { EuiCallOut, EuiCodeBlock } from '@elastic/eui'; -// @ts-ignore -import { formatMsg, formatStack } from 'ui/notify/lib/index'; +import { formatMsg, formatStack } from '../../../kibana_services'; interface Props { error: Error | string | null; diff --git a/src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/doc_viewer_render_tab.test.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/doc_viewer_render_tab.test.tsx similarity index 95% rename from src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/doc_viewer_render_tab.test.tsx rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/doc_viewer_render_tab.test.tsx index 476d7cef159fb..c100e71b5f2b5 100644 --- a/src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/doc_viewer_render_tab.test.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/doc_viewer_render_tab.test.tsx @@ -19,7 +19,7 @@ import React from 'react'; import { mount } from 'enzyme'; import { DocViewRenderTab } from './doc_viewer_render_tab'; -import { DocViewRenderProps } from '../../kibana_services'; +import { DocViewRenderProps } from '../../../kibana_services'; test('Mounting and unmounting DocViewerRenderTab', () => { const unmountFn = jest.fn(); diff --git a/src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/doc_viewer_render_tab.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/doc_viewer_render_tab.tsx similarity index 94% rename from src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/doc_viewer_render_tab.tsx rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/doc_viewer_render_tab.tsx index 8ac11caefff90..31a8808a3a1c9 100644 --- a/src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/doc_viewer_render_tab.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/doc_viewer_render_tab.tsx @@ -17,7 +17,7 @@ * under the License. */ import React, { useRef, useEffect } from 'react'; -import { DocViewRenderFn, DocViewRenderProps } from '../../kibana_services'; +import { DocViewRenderFn, DocViewRenderProps } from '../../../kibana_services'; interface Props { render: DocViewRenderFn; diff --git a/src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/doc_viewer_tab.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/doc_viewer_tab.tsx similarity index 97% rename from src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/doc_viewer_tab.tsx rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/doc_viewer_tab.tsx index 19558129eae8d..e08b0b2323d81 100644 --- a/src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/doc_viewer_tab.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/doc_viewer_tab.tsx @@ -18,7 +18,7 @@ */ import React from 'react'; import { I18nProvider } from '@kbn/i18n/react'; -import { DocViewRenderProps, DocViewRenderFn } from '../../kibana_services'; +import { DocViewRenderProps, DocViewRenderFn } from '../../../kibana_services'; import { DocViewRenderTab } from './doc_viewer_render_tab'; import { DocViewerError } from './doc_viewer_render_error'; diff --git a/src/legacy/core_plugins/kibana/public/discover/components/fetch_error/_fetch_error.scss b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/fetch_error/_fetch_error.scss similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/components/fetch_error/_fetch_error.scss rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/fetch_error/_fetch_error.scss diff --git a/src/legacy/core_plugins/kibana/public/discover/components/fetch_error/_index.scss b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/fetch_error/_index.scss similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/components/fetch_error/_index.scss rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/fetch_error/_index.scss diff --git a/src/legacy/core_plugins/kibana/public/discover/components/fetch_error/fetch_error.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/fetch_error/fetch_error.tsx similarity index 99% rename from src/legacy/core_plugins/kibana/public/discover/components/fetch_error/fetch_error.tsx rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/fetch_error/fetch_error.tsx index 8f67c1952f998..d2dda32f318fe 100644 --- a/src/legacy/core_plugins/kibana/public/discover/components/fetch_error/fetch_error.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/fetch_error/fetch_error.tsx @@ -19,7 +19,7 @@ import React, { Fragment } from 'react'; import { FormattedMessage } from '@kbn/i18n/react'; import { EuiFlexGroup, EuiFlexItem, EuiCallOut, EuiCodeBlock, EuiSpacer } from '@elastic/eui'; -import { getAngularModule, wrapInI18nContext, getServices } from '../../kibana_services'; +import { getAngularModule, wrapInI18nContext, getServices } from '../../../kibana_services'; interface Props { fetchError: { diff --git a/src/legacy/core_plugins/kibana/public/discover/components/fetch_error/index.js b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/fetch_error/index.js similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/components/fetch_error/index.js rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/fetch_error/index.js diff --git a/src/legacy/core_plugins/kibana/public/discover/components/field_chooser/__snapshots__/discover_index_pattern.test.tsx.snap b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/__snapshots__/discover_index_pattern.test.tsx.snap similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/components/field_chooser/__snapshots__/discover_index_pattern.test.tsx.snap rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/__snapshots__/discover_index_pattern.test.tsx.snap diff --git a/src/legacy/core_plugins/kibana/public/discover/components/field_chooser/_field_chooser.scss b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/_field_chooser.scss similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/components/field_chooser/_field_chooser.scss rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/_field_chooser.scss diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/_index.scss b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/_index.scss new file mode 100644 index 0000000000000..91daed8ea048e --- /dev/null +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/_index.scss @@ -0,0 +1 @@ +@import 'field_chooser'; diff --git a/src/legacy/core_plugins/kibana/public/discover/components/field_chooser/change_indexpattern.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/change_indexpattern.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/components/field_chooser/change_indexpattern.tsx rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/change_indexpattern.tsx diff --git a/src/legacy/core_plugins/kibana/public/discover/components/field_chooser/discover_field.html b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_field.html similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/components/field_chooser/discover_field.html rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_field.html diff --git a/src/legacy/core_plugins/kibana/public/discover/components/field_chooser/discover_field.js b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_field.js similarity index 97% rename from src/legacy/core_plugins/kibana/public/discover/components/field_chooser/discover_field.js rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_field.js index 0d2d0788dd175..f7f219a287492 100644 --- a/src/legacy/core_plugins/kibana/public/discover/components/field_chooser/discover_field.js +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_field.js @@ -20,10 +20,8 @@ import $ from 'jquery'; import _ from 'lodash'; import { i18n } from '@kbn/i18n'; -import { getServices } from '../../kibana_services'; +import { getServices } from '../../../kibana_services'; import html from './discover_field.html'; -import 'ui/directives/css_truncate'; -import 'ui/directives/field_name'; import './string_progress_bar'; import detailsHtml from './lib/detail_views/string.html'; diff --git a/src/legacy/core_plugins/kibana/public/discover/components/field_chooser/discover_field_search.test.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_field_search.test.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/components/field_chooser/discover_field_search.test.tsx rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_field_search.test.tsx diff --git a/src/legacy/core_plugins/kibana/public/discover/components/field_chooser/discover_field_search.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_field_search.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/components/field_chooser/discover_field_search.tsx rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_field_search.tsx diff --git a/src/legacy/core_plugins/kibana/public/discover/components/field_chooser/discover_field_search_directive.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_field_search_directive.ts similarity index 94% rename from src/legacy/core_plugins/kibana/public/discover/components/field_chooser/discover_field_search_directive.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_field_search_directive.ts index 69865ec424325..6d570349ee0c6 100644 --- a/src/legacy/core_plugins/kibana/public/discover/components/field_chooser/discover_field_search_directive.ts +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_field_search_directive.ts @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -import { wrapInI18nContext } from '../../kibana_services'; +import { wrapInI18nContext } from '../../../kibana_services'; import { DiscoverFieldSearch } from './discover_field_search'; export function createFieldSearchDirective(reactDirective: any) { diff --git a/src/legacy/core_plugins/kibana/public/discover/components/field_chooser/discover_index_pattern.test.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_index_pattern.test.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/components/field_chooser/discover_index_pattern.test.tsx rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_index_pattern.test.tsx diff --git a/src/legacy/core_plugins/kibana/public/discover/components/field_chooser/discover_index_pattern.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_index_pattern.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/components/field_chooser/discover_index_pattern.tsx rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_index_pattern.tsx diff --git a/src/legacy/core_plugins/kibana/public/discover/components/field_chooser/discover_index_pattern_directive.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_index_pattern_directive.ts similarity index 95% rename from src/legacy/core_plugins/kibana/public/discover/components/field_chooser/discover_index_pattern_directive.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_index_pattern_directive.ts index 46c8fa854847a..8bbeac086f093 100644 --- a/src/legacy/core_plugins/kibana/public/discover/components/field_chooser/discover_index_pattern_directive.ts +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_index_pattern_directive.ts @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -import { wrapInI18nContext } from '../../kibana_services'; +import { wrapInI18nContext } from '../../../kibana_services'; import { DiscoverIndexPattern } from './discover_index_pattern'; export function createIndexPatternSelectDirective(reactDirective: any) { diff --git a/src/legacy/core_plugins/kibana/public/discover/components/field_chooser/field_chooser.html b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/field_chooser.html similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/components/field_chooser/field_chooser.html rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/field_chooser.html diff --git a/src/legacy/core_plugins/kibana/public/discover/components/field_chooser/field_chooser.js b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/field_chooser.js similarity index 99% rename from src/legacy/core_plugins/kibana/public/discover/components/field_chooser/field_chooser.js rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/field_chooser.js index cf636a1675eb0..47b3ec6b07e8e 100644 --- a/src/legacy/core_plugins/kibana/public/discover/components/field_chooser/field_chooser.js +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/field_chooser.js @@ -23,7 +23,7 @@ import { fieldCalculator } from './lib/field_calculator'; import './discover_field'; import './discover_field_search_directive'; import './discover_index_pattern_directive'; -import { FieldList } from '../../../../../../../plugins/data/public'; +import { FieldList } from '../../../../../../../../plugins/data/public'; import fieldChooserTemplate from './field_chooser.html'; export function createFieldChooserDirective($location, config, $route) { diff --git a/src/legacy/core_plugins/kibana/public/discover/components/field_chooser/lib/detail_views/string.html b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/lib/detail_views/string.html similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/components/field_chooser/lib/detail_views/string.html rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/lib/detail_views/string.html diff --git a/src/legacy/core_plugins/kibana/public/discover/components/field_chooser/lib/field_calculator.js b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/lib/field_calculator.js similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/components/field_chooser/lib/field_calculator.js rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/lib/field_calculator.js diff --git a/src/legacy/core_plugins/kibana/public/discover/components/field_chooser/string_progress_bar.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/string_progress_bar.tsx similarity index 96% rename from src/legacy/core_plugins/kibana/public/discover/components/field_chooser/string_progress_bar.tsx rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/string_progress_bar.tsx index 7e4fc79839a52..0c5e7fa69357d 100644 --- a/src/legacy/core_plugins/kibana/public/discover/components/field_chooser/string_progress_bar.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/string_progress_bar.tsx @@ -18,7 +18,7 @@ */ import React from 'react'; import { EuiFlexGroup, EuiFlexItem, EuiProgress, EuiText, EuiToolTip } from '@elastic/eui'; -import { wrapInI18nContext } from '../../kibana_services'; +import { wrapInI18nContext } from '../../../kibana_services'; interface Props { percent: number; diff --git a/src/legacy/core_plugins/kibana/public/discover/components/field_chooser/types.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/types.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/components/field_chooser/types.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/types.ts diff --git a/src/legacy/core_plugins/kibana/public/discover/components/help_menu/help_menu_util.js b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/help_menu/help_menu_util.js similarity index 95% rename from src/legacy/core_plugins/kibana/public/discover/components/help_menu/help_menu_util.js rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/help_menu/help_menu_util.js index eb40130137e00..37fa79b490d56 100644 --- a/src/legacy/core_plugins/kibana/public/discover/components/help_menu/help_menu_util.js +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/help_menu/help_menu_util.js @@ -18,7 +18,7 @@ */ import { i18n } from '@kbn/i18n'; -import { getServices } from '../../kibana_services'; +import { getServices } from '../../../kibana_services'; const { docLinks } = getServices(); export function addHelpMenuToAppChrome(chrome) { diff --git a/src/legacy/core_plugins/kibana/public/discover/components/top_nav/__snapshots__/open_search_panel.test.js.snap b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/top_nav/__snapshots__/open_search_panel.test.js.snap similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/components/top_nav/__snapshots__/open_search_panel.test.js.snap rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/top_nav/__snapshots__/open_search_panel.test.js.snap diff --git a/src/legacy/core_plugins/kibana/public/discover/components/top_nav/open_search_panel.js b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/top_nav/open_search_panel.js similarity index 95% rename from src/legacy/core_plugins/kibana/public/discover/components/top_nav/open_search_panel.js rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/top_nav/open_search_panel.js index ec1763f44f25f..ebe4cbb1ddb69 100644 --- a/src/legacy/core_plugins/kibana/public/discover/components/top_nav/open_search_panel.js +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/top_nav/open_search_panel.js @@ -32,8 +32,8 @@ import { EuiFlyoutBody, EuiTitle, } from '@elastic/eui'; -import { SavedObjectFinderUi } from '../../../../../../../plugins/kibana_react/public'; -import { getServices } from '../../kibana_services'; +import { SavedObjectFinderUi } from '../../../../../../../../plugins/kibana_react/public'; +import { getServices } from '../../../kibana_services'; const SEARCH_OBJECT_TYPE = 'search'; diff --git a/src/legacy/core_plugins/kibana/public/discover/components/top_nav/open_search_panel.test.js b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/top_nav/open_search_panel.test.js similarity index 96% rename from src/legacy/core_plugins/kibana/public/discover/components/top_nav/open_search_panel.test.js rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/top_nav/open_search_panel.test.js index 22487421bf61b..c8f2ca220386d 100644 --- a/src/legacy/core_plugins/kibana/public/discover/components/top_nav/open_search_panel.test.js +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/top_nav/open_search_panel.test.js @@ -20,7 +20,7 @@ import React from 'react'; import { shallow } from 'enzyme'; -jest.mock('../../kibana_services', () => { +jest.mock('../../../kibana_services', () => { return { getServices: () => ({ core: { uiSettings: {}, savedObjects: {} }, diff --git a/src/legacy/core_plugins/kibana/public/discover/components/top_nav/show_open_search_panel.js b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/top_nav/show_open_search_panel.js similarity index 93% rename from src/legacy/core_plugins/kibana/public/discover/components/top_nav/show_open_search_panel.js rename to src/legacy/core_plugins/kibana/public/discover/np_ready/components/top_nav/show_open_search_panel.js index 4beee3c02fa6f..e40d700b48885 100644 --- a/src/legacy/core_plugins/kibana/public/discover/components/top_nav/show_open_search_panel.js +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/top_nav/show_open_search_panel.js @@ -20,11 +20,10 @@ import React from 'react'; import ReactDOM from 'react-dom'; import { OpenSearchPanel } from './open_search_panel'; -import { I18nContext } from 'ui/i18n'; let isOpen = false; -export function showOpenSearchPanel({ makeUrl }) { +export function showOpenSearchPanel({ makeUrl, I18nContext }) { if (isOpen) { return; } diff --git a/src/legacy/core_plugins/kibana/public/discover/embeddable/_embeddables.scss b/src/legacy/core_plugins/kibana/public/discover/np_ready/embeddable/_embeddables.scss similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/embeddable/_embeddables.scss rename to src/legacy/core_plugins/kibana/public/discover/np_ready/embeddable/_embeddables.scss diff --git a/src/legacy/core_plugins/kibana/public/discover/embeddable/_index.scss b/src/legacy/core_plugins/kibana/public/discover/np_ready/embeddable/_index.scss similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/embeddable/_index.scss rename to src/legacy/core_plugins/kibana/public/discover/np_ready/embeddable/_index.scss diff --git a/src/legacy/core_plugins/kibana/public/discover/embeddable/constants.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/embeddable/constants.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/embeddable/constants.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/embeddable/constants.ts diff --git a/src/legacy/core_plugins/kibana/public/discover/embeddable/index.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/embeddable/index.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/embeddable/index.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/embeddable/index.ts diff --git a/src/legacy/core_plugins/kibana/public/discover/embeddable/search_embeddable.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/embeddable/search_embeddable.ts similarity index 98% rename from src/legacy/core_plugins/kibana/public/discover/embeddable/search_embeddable.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/embeddable/search_embeddable.ts index 273c7d80f216c..14f7057045251 100644 --- a/src/legacy/core_plugins/kibana/public/discover/embeddable/search_embeddable.ts +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/embeddable/search_embeddable.ts @@ -21,7 +21,6 @@ import * as Rx from 'rxjs'; import { Subscription } from 'rxjs'; import { i18n } from '@kbn/i18n'; import { TExecuteTriggerActions } from 'src/plugins/ui_actions/public'; -import { SearchSourceContract } from '../../../../../ui/public/courier'; import { esFilters, TimeRange, @@ -31,12 +30,12 @@ import { getTime, Query, IFieldType, -} from '../../../../../../plugins/data/public'; +} from '../../../../../../../plugins/data/public'; import { APPLY_FILTER_TRIGGER, Container, Embeddable, -} from '../../../../embeddable_api/public/np_ready/public'; +} from '../../../../../embeddable_api/public/np_ready/public'; import * as columnActions from '../angular/doc_table/actions/columns'; import { SavedSearch } from '../types'; import searchTemplate from './search_template.html'; @@ -51,7 +50,8 @@ import { getServices, IndexPattern, RequestAdapter, -} from '../kibana_services'; + SearchSourceContract, +} from '../../kibana_services'; import { SEARCH_EMBEDDABLE_TYPE } from './constants'; interface SearchScope extends ng.IScope { diff --git a/src/legacy/core_plugins/kibana/public/discover/embeddable/search_embeddable_factory.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/embeddable/search_embeddable_factory.ts similarity index 94% rename from src/legacy/core_plugins/kibana/public/discover/embeddable/search_embeddable_factory.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/embeddable/search_embeddable_factory.ts index b5475b2629c70..3226b3af93cee 100644 --- a/src/legacy/core_plugins/kibana/public/discover/embeddable/search_embeddable_factory.ts +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/embeddable/search_embeddable_factory.ts @@ -18,15 +18,14 @@ */ import { i18n } from '@kbn/i18n'; import { TExecuteTriggerActions } from 'src/plugins/ui_actions/public'; -import { IInjector } from 'ui/chrome'; -import { getServices } from '../kibana_services'; +import { getServices, IInjector } from '../../kibana_services'; import { EmbeddableFactory, ErrorEmbeddable, Container, -} from '../../../../../../plugins/embeddable/public'; +} from '../../../../../../../plugins/embeddable/public'; -import { TimeRange } from '../../../../../../plugins/data/public'; +import { TimeRange } from '../../../../../../../plugins/data/public'; import { SearchEmbeddable } from './search_embeddable'; import { SearchInput, SearchOutput } from './types'; import { SEARCH_EMBEDDABLE_TYPE } from './constants'; diff --git a/src/legacy/core_plugins/kibana/public/discover/embeddable/search_template.html b/src/legacy/core_plugins/kibana/public/discover/np_ready/embeddable/search_template.html similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/embeddable/search_template.html rename to src/legacy/core_plugins/kibana/public/discover/np_ready/embeddable/search_template.html diff --git a/src/legacy/core_plugins/kibana/public/discover/embeddable/types.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/embeddable/types.ts similarity index 92% rename from src/legacy/core_plugins/kibana/public/discover/embeddable/types.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/embeddable/types.ts index adfa3d5acbf7a..3d6acb0963bed 100644 --- a/src/legacy/core_plugins/kibana/public/discover/embeddable/types.ts +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/embeddable/types.ts @@ -20,7 +20,12 @@ import { EmbeddableInput, EmbeddableOutput, IEmbeddable } from 'src/plugins/embeddable/public'; import { SavedSearch } from '../types'; import { SortOrder } from '../angular/doc_table/components/table_header/helpers'; -import { esFilters, IIndexPattern, TimeRange, Query } from '../../../../../../plugins/data/public'; +import { + esFilters, + IIndexPattern, + TimeRange, + Query, +} from '../../../../../../../plugins/data/public'; export interface SearchInput extends EmbeddableInput { timeRange: TimeRange; diff --git a/src/legacy/core_plugins/kibana/public/discover/helpers/breadcrumbs.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/helpers/breadcrumbs.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/helpers/breadcrumbs.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/helpers/breadcrumbs.ts diff --git a/src/legacy/core_plugins/kibana/public/discover/helpers/get_index_pattern_id.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/helpers/get_index_pattern_id.ts similarity index 95% rename from src/legacy/core_plugins/kibana/public/discover/helpers/get_index_pattern_id.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/helpers/get_index_pattern_id.ts index bd62460fd6868..8f4d1b28624a4 100644 --- a/src/legacy/core_plugins/kibana/public/discover/helpers/get_index_pattern_id.ts +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/helpers/get_index_pattern_id.ts @@ -17,7 +17,7 @@ * under the License. */ -import { IIndexPattern } from '../../../../../../plugins/data/common/index_patterns'; +import { IIndexPattern } from '../../../../../../../plugins/data/common/index_patterns'; export function findIndexPatternById( indexPatterns: IIndexPattern[], diff --git a/src/legacy/core_plugins/kibana/public/discover/helpers/register_feature.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/register_feature.ts similarity index 58% rename from src/legacy/core_plugins/kibana/public/discover/helpers/register_feature.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/register_feature.ts index eb8c2aec91558..74255642ab2c9 100644 --- a/src/legacy/core_plugins/kibana/public/discover/helpers/register_feature.ts +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/register_feature.ts @@ -18,24 +18,22 @@ */ import { i18n } from '@kbn/i18n'; import { - FeatureCatalogueRegistryProvider, FeatureCatalogueCategory, -} from 'ui/registry/feature_catalogue'; + HomePublicPluginSetup, +} from '../../../../../../plugins/home/public'; -export function registerFeature() { - FeatureCatalogueRegistryProvider.register(() => { - return { - id: 'discover', - title: i18n.translate('kbn.discover.discoverTitle', { - defaultMessage: 'Discover', - }), - description: i18n.translate('kbn.discover.discoverDescription', { - defaultMessage: 'Interactively explore your data by querying and filtering raw documents.', - }), - icon: 'discoverApp', - path: '/app/kibana#/discover', - showOnHomePage: true, - category: FeatureCatalogueCategory.DATA, - }; +export function registerFeature(home: HomePublicPluginSetup) { + home.featureCatalogue.register({ + id: 'discover', + title: i18n.translate('kbn.discover.discoverTitle', { + defaultMessage: 'Discover', + }), + description: i18n.translate('kbn.discover.discoverDescription', { + defaultMessage: 'Interactively explore your data by querying and filtering raw documents.', + }), + icon: 'discoverApp', + path: '/app/kibana#/discover', + showOnHomePage: true, + category: FeatureCatalogueCategory.DATA, }); } diff --git a/src/legacy/core_plugins/kibana/public/discover/types.d.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/types.d.ts similarity index 94% rename from src/legacy/core_plugins/kibana/public/discover/types.d.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/types.d.ts index 6cdd802fa2800..c8920e351fcca 100644 --- a/src/legacy/core_plugins/kibana/public/discover/types.d.ts +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/types.d.ts @@ -17,7 +17,7 @@ * under the License. */ -import { SearchSourceContract } from '../../../../ui/public/courier'; +import { SearchSourceContract } from '../kibana_services'; import { SortOrder } from './angular/doc_table/components/table_header/helpers'; export { SortOrder } from './angular/doc_table/components/table_header/helpers'; diff --git a/src/legacy/core_plugins/kibana/public/discover/plugin.ts b/src/legacy/core_plugins/kibana/public/discover/plugin.ts index b5a8e25dc11ea..0cff1e66f3636 100644 --- a/src/legacy/core_plugins/kibana/public/discover/plugin.ts +++ b/src/legacy/core_plugins/kibana/public/discover/plugin.ts @@ -20,16 +20,17 @@ import { AppMountParameters, CoreSetup, CoreStart, Plugin } from 'kibana/public' import angular from 'angular'; import { IUiActionsStart } from 'src/plugins/ui_actions/public'; import { DataPublicPluginStart } from 'src/plugins/data/public'; -import { registerFeature } from './helpers/register_feature'; +import { registerFeature } from './np_ready/register_feature'; import './kibana_services'; import { IEmbeddableStart, IEmbeddableSetup } from '../../../../../plugins/embeddable/public'; import { getInnerAngularModule, getInnerAngularModuleEmbeddable } from './get_inner_angular'; import { setAngularModule, setServices } from './kibana_services'; import { NavigationPublicPluginStart as NavigationStart } from '../../../../../plugins/navigation/public'; import { EuiUtilsStart } from '../../../../../plugins/eui_utils/public'; -import { buildServices } from './helpers/build_services'; +import { buildServices } from './build_services'; import { SharePluginStart } from '../../../../../plugins/share/public'; import { KibanaLegacySetup } from '../../../../../plugins/kibana_legacy/public'; +import { HomePublicPluginSetup } from '../../../../../plugins/home/public'; /** * These are the interfaces with your public contracts. You should export these @@ -42,6 +43,7 @@ export interface DiscoverSetupPlugins { uiActions: IUiActionsStart; embeddable: IEmbeddableSetup; kibana_legacy: KibanaLegacySetup; + home: HomePublicPluginSetup; } export interface DiscoverStartPlugins { uiActions: IUiActionsStart; @@ -84,10 +86,11 @@ export class DiscoverPlugin implements Plugin { } await this.initializeServices(); await this.initializeInnerAngular(); - const { renderApp } = await import('./application'); + const { renderApp } = await import('./np_ready/application'); return renderApp(innerAngularName, params.element); }, }); + registerFeature(plugins.home); } start(core: CoreStart, plugins: DiscoverStartPlugins): DiscoverStart { @@ -115,14 +118,13 @@ export class DiscoverPlugin implements Plugin { }; this.registerEmbeddable(core, plugins); - registerFeature(); } /** * register embeddable with a slimmer embeddable version of inner angular */ private async registerEmbeddable(core: CoreStart, plugins: DiscoverStartPlugins) { - const { SearchEmbeddableFactory } = await import('./embeddable'); + const { SearchEmbeddableFactory } = await import('./np_ready/embeddable'); const getInjector = async () => { if (!this.initializeServices) { throw Error('Discover plugin registerEmbeddable: initializeServices is undefined'); diff --git a/src/legacy/core_plugins/kibana/public/home/_index.scss b/src/legacy/core_plugins/kibana/public/home/_index.scss index 192091fb04e3c..f42254c1096ce 100644 --- a/src/legacy/core_plugins/kibana/public/home/_index.scss +++ b/src/legacy/core_plugins/kibana/public/home/_index.scss @@ -1 +1 @@ -@import './components/index'; +@import 'np_ready/components/index'; diff --git a/src/legacy/core_plugins/kibana/public/home/render_app.tsx b/src/legacy/core_plugins/kibana/public/home/np_ready/application.tsx similarity index 96% rename from src/legacy/core_plugins/kibana/public/home/render_app.tsx rename to src/legacy/core_plugins/kibana/public/home/np_ready/application.tsx index a8c35144a45b0..8345491d99972 100644 --- a/src/legacy/core_plugins/kibana/public/home/render_app.tsx +++ b/src/legacy/core_plugins/kibana/public/home/np_ready/application.tsx @@ -22,7 +22,7 @@ import { render, unmountComponentAtNode } from 'react-dom'; import { i18n } from '@kbn/i18n'; // @ts-ignore import { HomeApp } from './components/home_app'; -import { getServices } from './kibana_services'; +import { getServices } from '../kibana_services'; export const renderApp = async (element: HTMLElement) => { const homeTitle = i18n.translate('kbn.home.breadcrumbs.homeTitle', { defaultMessage: 'Home' }); diff --git a/src/legacy/core_plugins/kibana/public/home/components/__snapshots__/add_data.test.js.snap b/src/legacy/core_plugins/kibana/public/home/np_ready/components/__snapshots__/add_data.test.js.snap similarity index 100% rename from src/legacy/core_plugins/kibana/public/home/components/__snapshots__/add_data.test.js.snap rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/__snapshots__/add_data.test.js.snap diff --git a/src/legacy/core_plugins/kibana/public/home/components/__snapshots__/home.test.js.snap b/src/legacy/core_plugins/kibana/public/home/np_ready/components/__snapshots__/home.test.js.snap similarity index 100% rename from src/legacy/core_plugins/kibana/public/home/components/__snapshots__/home.test.js.snap rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/__snapshots__/home.test.js.snap diff --git a/src/legacy/core_plugins/kibana/public/home/components/__snapshots__/recently_accessed.test.js.snap b/src/legacy/core_plugins/kibana/public/home/np_ready/components/__snapshots__/recently_accessed.test.js.snap similarity index 100% rename from src/legacy/core_plugins/kibana/public/home/components/__snapshots__/recently_accessed.test.js.snap rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/__snapshots__/recently_accessed.test.js.snap diff --git a/src/legacy/core_plugins/kibana/public/home/components/__snapshots__/sample_data_view_data_button.test.js.snap b/src/legacy/core_plugins/kibana/public/home/np_ready/components/__snapshots__/sample_data_view_data_button.test.js.snap similarity index 100% rename from src/legacy/core_plugins/kibana/public/home/components/__snapshots__/sample_data_view_data_button.test.js.snap rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/__snapshots__/sample_data_view_data_button.test.js.snap diff --git a/src/legacy/core_plugins/kibana/public/home/components/__snapshots__/synopsis.test.js.snap b/src/legacy/core_plugins/kibana/public/home/np_ready/components/__snapshots__/synopsis.test.js.snap similarity index 100% rename from src/legacy/core_plugins/kibana/public/home/components/__snapshots__/synopsis.test.js.snap rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/__snapshots__/synopsis.test.js.snap diff --git a/src/legacy/core_plugins/kibana/public/home/components/__snapshots__/welcome.test.tsx.snap b/src/legacy/core_plugins/kibana/public/home/np_ready/components/__snapshots__/welcome.test.tsx.snap similarity index 100% rename from src/legacy/core_plugins/kibana/public/home/components/__snapshots__/welcome.test.tsx.snap rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/__snapshots__/welcome.test.tsx.snap diff --git a/src/legacy/core_plugins/kibana/public/home/components/_add_data.scss b/src/legacy/core_plugins/kibana/public/home/np_ready/components/_add_data.scss similarity index 100% rename from src/legacy/core_plugins/kibana/public/home/components/_add_data.scss rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/_add_data.scss diff --git a/src/legacy/core_plugins/kibana/public/home/components/_home.scss b/src/legacy/core_plugins/kibana/public/home/np_ready/components/_home.scss similarity index 100% rename from src/legacy/core_plugins/kibana/public/home/components/_home.scss rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/_home.scss diff --git a/src/legacy/core_plugins/kibana/public/home/components/_index.scss b/src/legacy/core_plugins/kibana/public/home/np_ready/components/_index.scss similarity index 52% rename from src/legacy/core_plugins/kibana/public/home/components/_index.scss rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/_index.scss index af23752e54287..870099ffb350e 100644 --- a/src/legacy/core_plugins/kibana/public/home/components/_index.scss +++ b/src/legacy/core_plugins/kibana/public/home/np_ready/components/_index.scss @@ -5,10 +5,10 @@ // homChart__legend--small // homChart__legend-isLoading -@import './add_data'; -@import './home'; -@import './sample_data_set_cards'; -@import './synopsis'; -@import './welcome'; +@import 'add_data'; +@import 'home'; +@import 'sample_data_set_cards'; +@import 'synopsis'; +@import 'welcome'; -@import './tutorial/tutorial'; +@import 'tutorial/tutorial'; diff --git a/src/legacy/core_plugins/kibana/public/home/components/_sample_data_set_cards.scss b/src/legacy/core_plugins/kibana/public/home/np_ready/components/_sample_data_set_cards.scss similarity index 100% rename from src/legacy/core_plugins/kibana/public/home/components/_sample_data_set_cards.scss rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/_sample_data_set_cards.scss diff --git a/src/legacy/core_plugins/kibana/public/home/components/_synopsis.scss b/src/legacy/core_plugins/kibana/public/home/np_ready/components/_synopsis.scss similarity index 100% rename from src/legacy/core_plugins/kibana/public/home/components/_synopsis.scss rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/_synopsis.scss diff --git a/src/legacy/core_plugins/kibana/public/home/components/_welcome.scss b/src/legacy/core_plugins/kibana/public/home/np_ready/components/_welcome.scss similarity index 100% rename from src/legacy/core_plugins/kibana/public/home/components/_welcome.scss rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/_welcome.scss diff --git a/src/legacy/core_plugins/kibana/public/home/components/add_data.js b/src/legacy/core_plugins/kibana/public/home/np_ready/components/add_data.js similarity index 99% rename from src/legacy/core_plugins/kibana/public/home/components/add_data.js rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/add_data.js index 8ea9d78507ceb..a49620be2d229 100644 --- a/src/legacy/core_plugins/kibana/public/home/components/add_data.js +++ b/src/legacy/core_plugins/kibana/public/home/np_ready/components/add_data.js @@ -21,7 +21,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import { injectI18n, FormattedMessage } from '@kbn/i18n/react'; -import { getServices } from '../kibana_services'; +import { getServices } from '../../kibana_services'; import { EuiButton, diff --git a/src/legacy/core_plugins/kibana/public/home/components/add_data.test.js b/src/legacy/core_plugins/kibana/public/home/np_ready/components/add_data.test.js similarity index 95% rename from src/legacy/core_plugins/kibana/public/home/components/add_data.test.js rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/add_data.test.js index 9457f766409b8..86eec564f0b61 100644 --- a/src/legacy/core_plugins/kibana/public/home/components/add_data.test.js +++ b/src/legacy/core_plugins/kibana/public/home/np_ready/components/add_data.test.js @@ -20,9 +20,9 @@ import React from 'react'; import { AddData } from './add_data'; import { shallowWithIntl } from 'test_utils/enzyme_helpers'; -import { getServices } from '../kibana_services'; +import { getServices } from '../../kibana_services'; -jest.mock('../kibana_services', () => { +jest.mock('../../kibana_services', () => { const mock = { getBasePath: jest.fn(() => 'path'), }; diff --git a/src/legacy/core_plugins/kibana/public/home/components/feature_directory.js b/src/legacy/core_plugins/kibana/public/home/np_ready/components/feature_directory.js similarity index 98% rename from src/legacy/core_plugins/kibana/public/home/components/feature_directory.js rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/feature_directory.js index 447a54bd89701..5545944a1029f 100644 --- a/src/legacy/core_plugins/kibana/public/home/components/feature_directory.js +++ b/src/legacy/core_plugins/kibana/public/home/np_ready/components/feature_directory.js @@ -31,7 +31,7 @@ import { EuiSpacer, } from '@elastic/eui'; -import { FeatureCatalogueCategory } from 'ui/registry/feature_catalogue'; +import { FeatureCatalogueCategory } from '../../../../../../../plugins/home/public'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; diff --git a/src/legacy/core_plugins/kibana/public/home/components/home.js b/src/legacy/core_plugins/kibana/public/home/np_ready/components/home.js similarity index 98% rename from src/legacy/core_plugins/kibana/public/home/components/home.js rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/home.js index d552dd070c86d..5c32a463da115 100644 --- a/src/legacy/core_plugins/kibana/public/home/components/home.js +++ b/src/legacy/core_plugins/kibana/public/home/np_ready/components/home.js @@ -38,8 +38,8 @@ import { } from '@elastic/eui'; import { Welcome } from './welcome'; -import { FeatureCatalogueCategory } from 'ui/registry/feature_catalogue'; -import { getServices } from '../kibana_services'; +import { FeatureCatalogueCategory } from '../../../../../../../plugins/home/public'; +import { getServices } from '../../kibana_services'; const KEY_ENABLE_WELCOME = 'home:welcome:show'; diff --git a/src/legacy/core_plugins/kibana/public/home/components/home.test.js b/src/legacy/core_plugins/kibana/public/home/np_ready/components/home.test.js similarity index 98% rename from src/legacy/core_plugins/kibana/public/home/components/home.test.js rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/home.test.js index 1f46cf2875fee..be2ceb66f69d0 100644 --- a/src/legacy/core_plugins/kibana/public/home/components/home.test.js +++ b/src/legacy/core_plugins/kibana/public/home/np_ready/components/home.test.js @@ -23,9 +23,10 @@ import React from 'react'; import sinon from 'sinon'; import { shallow } from 'enzyme'; import { Home } from './home'; -import { FeatureCatalogueCategory } from 'ui/registry/feature_catalogue'; -jest.mock('../kibana_services', () => ({ +import { FeatureCatalogueCategory } from '../../../../../../../plugins/home/public'; + +jest.mock('../../kibana_services', () => ({ getServices: () => ({ getBasePath: () => 'path', getInjected: () => '', diff --git a/src/legacy/core_plugins/kibana/public/home/components/home.test.mocks.ts b/src/legacy/core_plugins/kibana/public/home/np_ready/components/home.test.mocks.ts similarity index 96% rename from src/legacy/core_plugins/kibana/public/home/components/home.test.mocks.ts rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/home.test.mocks.ts index cd7bc82fe3345..a0b9d7c779b02 100644 --- a/src/legacy/core_plugins/kibana/public/home/components/home.test.mocks.ts +++ b/src/legacy/core_plugins/kibana/public/home/np_ready/components/home.test.mocks.ts @@ -22,7 +22,7 @@ import { overlayServiceMock, httpServiceMock, injectedMetadataServiceMock, -} from '../../../../../../core/public/mocks'; +} from '../../../../../../../core/public/mocks'; jest.doMock('ui/new_platform', () => { return { diff --git a/src/legacy/core_plugins/kibana/public/home/components/home_app.js b/src/legacy/core_plugins/kibana/public/home/np_ready/components/home_app.js similarity index 96% rename from src/legacy/core_plugins/kibana/public/home/components/home_app.js rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/home_app.js index 29f24f5b841a3..6532737cc02e8 100644 --- a/src/legacy/core_plugins/kibana/public/home/components/home_app.js +++ b/src/legacy/core_plugins/kibana/public/home/np_ready/components/home_app.js @@ -27,7 +27,9 @@ import { Tutorial } from './tutorial/tutorial'; import { HashRouter as Router, Switch, Route, Redirect } from 'react-router-dom'; import { getTutorial } from '../load_tutorials'; import { replaceTemplateStrings } from './tutorial/replace_template_strings'; -import { getServices } from '../kibana_services'; +import { getServices } from '../../kibana_services'; +// TODO This is going to be refactored soon +// eslint-disable-next-line @kbn/eslint/no-restricted-paths import { npSetup } from 'ui/new_platform'; export function HomeApp({ directories }) { const { diff --git a/src/legacy/core_plugins/kibana/public/home/components/recently_accessed.js b/src/legacy/core_plugins/kibana/public/home/np_ready/components/recently_accessed.js similarity index 100% rename from src/legacy/core_plugins/kibana/public/home/components/recently_accessed.js rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/recently_accessed.js diff --git a/src/legacy/core_plugins/kibana/public/home/components/recently_accessed.test.js b/src/legacy/core_plugins/kibana/public/home/np_ready/components/recently_accessed.test.js similarity index 100% rename from src/legacy/core_plugins/kibana/public/home/components/recently_accessed.test.js rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/recently_accessed.test.js diff --git a/src/legacy/core_plugins/kibana/public/home/components/sample_data/index.tsx b/src/legacy/core_plugins/kibana/public/home/np_ready/components/sample_data/index.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/home/components/sample_data/index.tsx rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/sample_data/index.tsx diff --git a/src/legacy/core_plugins/kibana/public/home/components/sample_data_set_card.js b/src/legacy/core_plugins/kibana/public/home/np_ready/components/sample_data_set_card.js similarity index 100% rename from src/legacy/core_plugins/kibana/public/home/components/sample_data_set_card.js rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/sample_data_set_card.js diff --git a/src/legacy/core_plugins/kibana/public/home/components/sample_data_set_cards.js b/src/legacy/core_plugins/kibana/public/home/np_ready/components/sample_data_set_cards.js similarity index 99% rename from src/legacy/core_plugins/kibana/public/home/components/sample_data_set_cards.js rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/sample_data_set_cards.js index 7daf10e5f01f8..198e0d95271d7 100644 --- a/src/legacy/core_plugins/kibana/public/home/components/sample_data_set_cards.js +++ b/src/legacy/core_plugins/kibana/public/home/np_ready/components/sample_data_set_cards.js @@ -24,7 +24,7 @@ import { EuiFlexGrid, EuiFlexItem } from '@elastic/eui'; import { SampleDataSetCard, INSTALLED_STATUS, UNINSTALLED_STATUS } from './sample_data_set_card'; -import { getServices } from '../kibana_services'; +import { getServices } from '../../kibana_services'; import { listSampleDataSets, diff --git a/src/legacy/core_plugins/kibana/public/home/components/sample_data_view_data_button.js b/src/legacy/core_plugins/kibana/public/home/np_ready/components/sample_data_view_data_button.js similarity index 98% rename from src/legacy/core_plugins/kibana/public/home/components/sample_data_view_data_button.js rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/sample_data_view_data_button.js index c9bd32a7d14d5..e6f5c07c94f9f 100644 --- a/src/legacy/core_plugins/kibana/public/home/components/sample_data_view_data_button.js +++ b/src/legacy/core_plugins/kibana/public/home/np_ready/components/sample_data_view_data_button.js @@ -22,7 +22,7 @@ import PropTypes from 'prop-types'; import { EuiButton, EuiContextMenu, EuiIcon, EuiPopover } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; -import { getServices } from '../kibana_services'; +import { getServices } from '../../kibana_services'; export class SampleDataViewDataButton extends React.Component { addBasePath = getServices().addBasePath; diff --git a/src/legacy/core_plugins/kibana/public/home/components/sample_data_view_data_button.test.js b/src/legacy/core_plugins/kibana/public/home/np_ready/components/sample_data_view_data_button.test.js similarity index 97% rename from src/legacy/core_plugins/kibana/public/home/components/sample_data_view_data_button.test.js rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/sample_data_view_data_button.test.js index f594ec1264c94..e33c206ed8482 100644 --- a/src/legacy/core_plugins/kibana/public/home/components/sample_data_view_data_button.test.js +++ b/src/legacy/core_plugins/kibana/public/home/np_ready/components/sample_data_view_data_button.test.js @@ -22,7 +22,7 @@ import { shallow } from 'enzyme'; import { SampleDataViewDataButton } from './sample_data_view_data_button'; -jest.mock('../kibana_services', () => ({ +jest.mock('../../kibana_services', () => ({ getServices: () => ({ addBasePath: path => `root${path}`, }), diff --git a/src/legacy/core_plugins/kibana/public/home/components/synopsis.js b/src/legacy/core_plugins/kibana/public/home/np_ready/components/synopsis.js similarity index 100% rename from src/legacy/core_plugins/kibana/public/home/components/synopsis.js rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/synopsis.js diff --git a/src/legacy/core_plugins/kibana/public/home/components/synopsis.test.js b/src/legacy/core_plugins/kibana/public/home/np_ready/components/synopsis.test.js similarity index 100% rename from src/legacy/core_plugins/kibana/public/home/components/synopsis.test.js rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/synopsis.test.js diff --git a/src/legacy/core_plugins/kibana/public/home/components/tutorial/__snapshots__/content.test.js.snap b/src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/__snapshots__/content.test.js.snap similarity index 100% rename from src/legacy/core_plugins/kibana/public/home/components/tutorial/__snapshots__/content.test.js.snap rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/__snapshots__/content.test.js.snap diff --git a/src/legacy/core_plugins/kibana/public/home/components/tutorial/__snapshots__/footer.test.js.snap b/src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/__snapshots__/footer.test.js.snap similarity index 100% rename from src/legacy/core_plugins/kibana/public/home/components/tutorial/__snapshots__/footer.test.js.snap rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/__snapshots__/footer.test.js.snap diff --git a/src/legacy/core_plugins/kibana/public/home/components/tutorial/__snapshots__/instruction_set.test.js.snap b/src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/__snapshots__/instruction_set.test.js.snap similarity index 100% rename from src/legacy/core_plugins/kibana/public/home/components/tutorial/__snapshots__/instruction_set.test.js.snap rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/__snapshots__/instruction_set.test.js.snap diff --git a/src/legacy/core_plugins/kibana/public/home/components/tutorial/__snapshots__/introduction.test.js.snap b/src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/__snapshots__/introduction.test.js.snap similarity index 100% rename from src/legacy/core_plugins/kibana/public/home/components/tutorial/__snapshots__/introduction.test.js.snap rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/__snapshots__/introduction.test.js.snap diff --git a/src/legacy/core_plugins/kibana/public/home/components/tutorial/__snapshots__/saved_objects_installer.test.js.snap b/src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/__snapshots__/saved_objects_installer.test.js.snap similarity index 100% rename from src/legacy/core_plugins/kibana/public/home/components/tutorial/__snapshots__/saved_objects_installer.test.js.snap rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/__snapshots__/saved_objects_installer.test.js.snap diff --git a/src/legacy/core_plugins/kibana/public/home/components/tutorial/__snapshots__/tutorial.test.js.snap b/src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/__snapshots__/tutorial.test.js.snap similarity index 100% rename from src/legacy/core_plugins/kibana/public/home/components/tutorial/__snapshots__/tutorial.test.js.snap rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/__snapshots__/tutorial.test.js.snap diff --git a/src/legacy/core_plugins/kibana/public/home/components/tutorial/_tutorial.scss b/src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/_tutorial.scss similarity index 100% rename from src/legacy/core_plugins/kibana/public/home/components/tutorial/_tutorial.scss rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/_tutorial.scss diff --git a/src/legacy/core_plugins/kibana/public/home/components/tutorial/content.js b/src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/content.js similarity index 94% rename from src/legacy/core_plugins/kibana/public/home/components/tutorial/content.js rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/content.js index db1f55b503e84..669eb6c4c42cd 100644 --- a/src/legacy/core_plugins/kibana/public/home/components/tutorial/content.js +++ b/src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/content.js @@ -19,7 +19,7 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { Markdown } from '../../../../../kibana_react/public'; +import { Markdown } from '../../../../../../kibana_react/public'; const whiteListedRules = ['backticks', 'emphasis', 'link', 'list']; diff --git a/src/legacy/core_plugins/kibana/public/home/components/tutorial/content.test.js b/src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/content.test.js similarity index 95% rename from src/legacy/core_plugins/kibana/public/home/components/tutorial/content.test.js rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/content.test.js index d3a4d7085a0aa..64864b6a5404d 100644 --- a/src/legacy/core_plugins/kibana/public/home/components/tutorial/content.test.js +++ b/src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/content.test.js @@ -22,7 +22,7 @@ import { shallow } from 'enzyme'; import { Content } from './content'; -jest.mock('../../../../../kibana_react/public', () => { +jest.mock('../../../../../../kibana_react/public', () => { return { Markdown: () =>
, }; diff --git a/src/legacy/core_plugins/kibana/public/home/components/tutorial/footer.js b/src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/footer.js similarity index 100% rename from src/legacy/core_plugins/kibana/public/home/components/tutorial/footer.js rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/footer.js diff --git a/src/legacy/core_plugins/kibana/public/home/components/tutorial/footer.test.js b/src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/footer.test.js similarity index 100% rename from src/legacy/core_plugins/kibana/public/home/components/tutorial/footer.test.js rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/footer.test.js diff --git a/src/legacy/core_plugins/kibana/public/home/components/tutorial/instruction.js b/src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/instruction.js similarity index 100% rename from src/legacy/core_plugins/kibana/public/home/components/tutorial/instruction.js rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/instruction.js diff --git a/src/legacy/core_plugins/kibana/public/home/components/tutorial/instruction_set.js b/src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/instruction_set.js similarity index 99% rename from src/legacy/core_plugins/kibana/public/home/components/tutorial/instruction_set.js rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/instruction_set.js index 7ec2133a98ca1..4f60de00819e7 100644 --- a/src/legacy/core_plugins/kibana/public/home/components/tutorial/instruction_set.js +++ b/src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/instruction_set.js @@ -22,7 +22,7 @@ import PropTypes from 'prop-types'; import { Instruction } from './instruction'; import { ParameterForm } from './parameter_form'; import { Content } from './content'; -import { getDisplayText } from '../../../../common/tutorials/instruction_variant'; +import { getDisplayText } from '../../../../../common/tutorials/instruction_variant'; import { EuiTabs, EuiTab, diff --git a/src/legacy/core_plugins/kibana/public/home/components/tutorial/instruction_set.test.js b/src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/instruction_set.test.js similarity index 98% rename from src/legacy/core_plugins/kibana/public/home/components/tutorial/instruction_set.test.js rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/instruction_set.test.js index 6c9ce530f6b20..21c3ddeceff6b 100644 --- a/src/legacy/core_plugins/kibana/public/home/components/tutorial/instruction_set.test.js +++ b/src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/instruction_set.test.js @@ -45,7 +45,7 @@ const instructionVariants = [ }, ]; -jest.mock('../../../../../kibana_react/public', () => { +jest.mock('../../../../../../kibana_react/public', () => { return { Markdown: () =>
, }; diff --git a/src/legacy/core_plugins/kibana/public/home/components/tutorial/introduction.js b/src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/introduction.js similarity index 100% rename from src/legacy/core_plugins/kibana/public/home/components/tutorial/introduction.js rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/introduction.js diff --git a/src/legacy/core_plugins/kibana/public/home/components/tutorial/introduction.test.js b/src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/introduction.test.js similarity index 97% rename from src/legacy/core_plugins/kibana/public/home/components/tutorial/introduction.test.js rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/introduction.test.js index ae87bc6030c9a..8862ef7334f93 100644 --- a/src/legacy/core_plugins/kibana/public/home/components/tutorial/introduction.test.js +++ b/src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/introduction.test.js @@ -22,7 +22,7 @@ import { shallowWithIntl } from 'test_utils/enzyme_helpers'; import { Introduction } from './introduction'; -jest.mock('../../../../../kibana_react/public', () => { +jest.mock('../../../../../../kibana_react/public', () => { return { Markdown: () =>
, }; diff --git a/src/legacy/core_plugins/kibana/public/home/components/tutorial/number_parameter.js b/src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/number_parameter.js similarity index 100% rename from src/legacy/core_plugins/kibana/public/home/components/tutorial/number_parameter.js rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/number_parameter.js diff --git a/src/legacy/core_plugins/kibana/public/home/components/tutorial/parameter_form.js b/src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/parameter_form.js similarity index 100% rename from src/legacy/core_plugins/kibana/public/home/components/tutorial/parameter_form.js rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/parameter_form.js diff --git a/src/legacy/core_plugins/kibana/public/home/components/tutorial/replace_template_strings.js b/src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/replace_template_strings.js similarity index 97% rename from src/legacy/core_plugins/kibana/public/home/components/tutorial/replace_template_strings.js rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/replace_template_strings.js index 62116ae1a0663..daf996444eb3c 100644 --- a/src/legacy/core_plugins/kibana/public/home/components/tutorial/replace_template_strings.js +++ b/src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/replace_template_strings.js @@ -18,7 +18,7 @@ */ import { Writer } from 'mustache'; -import { getServices } from '../../kibana_services'; +import { getServices } from '../../../kibana_services'; const TEMPLATE_TAGS = ['{', '}']; diff --git a/src/legacy/core_plugins/kibana/public/home/components/tutorial/saved_objects_installer.js b/src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/saved_objects_installer.js similarity index 100% rename from src/legacy/core_plugins/kibana/public/home/components/tutorial/saved_objects_installer.js rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/saved_objects_installer.js diff --git a/src/legacy/core_plugins/kibana/public/home/components/tutorial/saved_objects_installer.test.js b/src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/saved_objects_installer.test.js similarity index 100% rename from src/legacy/core_plugins/kibana/public/home/components/tutorial/saved_objects_installer.test.js rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/saved_objects_installer.test.js diff --git a/src/legacy/core_plugins/kibana/public/home/components/tutorial/status_check_states.js b/src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/status_check_states.js similarity index 100% rename from src/legacy/core_plugins/kibana/public/home/components/tutorial/status_check_states.js rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/status_check_states.js diff --git a/src/legacy/core_plugins/kibana/public/home/components/tutorial/string_parameter.js b/src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/string_parameter.js similarity index 100% rename from src/legacy/core_plugins/kibana/public/home/components/tutorial/string_parameter.js rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/string_parameter.js diff --git a/src/legacy/core_plugins/kibana/public/home/components/tutorial/tutorial.js b/src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/tutorial.js similarity index 99% rename from src/legacy/core_plugins/kibana/public/home/components/tutorial/tutorial.js rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/tutorial.js index 7461db9c54cc8..314ddf2196f06 100644 --- a/src/legacy/core_plugins/kibana/public/home/components/tutorial/tutorial.js +++ b/src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/tutorial.js @@ -37,7 +37,7 @@ import { import * as StatusCheckStates from './status_check_states'; import { injectI18n, FormattedMessage } from '@kbn/i18n/react'; import { i18n } from '@kbn/i18n'; -import { getServices } from '../../kibana_services'; +import { getServices } from '../../../kibana_services'; const INSTRUCTIONS_TYPE = { ELASTIC_CLOUD: 'elasticCloud', diff --git a/src/legacy/core_plugins/kibana/public/home/components/tutorial/tutorial.test.js b/src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/tutorial.test.js similarity index 97% rename from src/legacy/core_plugins/kibana/public/home/components/tutorial/tutorial.test.js rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/tutorial.test.js index 41d83d7562f6e..733223fe79046 100644 --- a/src/legacy/core_plugins/kibana/public/home/components/tutorial/tutorial.test.js +++ b/src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/tutorial.test.js @@ -22,7 +22,7 @@ import { shallowWithIntl, mountWithIntl } from 'test_utils/enzyme_helpers'; import { Tutorial } from './tutorial'; -jest.mock('../../kibana_services', () => ({ +jest.mock('../../../kibana_services', () => ({ getServices: () => ({ getBasePath: jest.fn(() => 'path'), chrome: { @@ -30,7 +30,7 @@ jest.mock('../../kibana_services', () => ({ }, }), })); -jest.mock('../../../../../kibana_react/public', () => { +jest.mock('../../../../../../kibana_react/public', () => { return { Markdown: () =>
, }; diff --git a/src/legacy/core_plugins/kibana/public/home/components/tutorial_directory.js b/src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial_directory.js similarity index 99% rename from src/legacy/core_plugins/kibana/public/home/components/tutorial_directory.js rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial_directory.js index 0c537c8e9ae8a..06da6f35ee42e 100644 --- a/src/legacy/core_plugins/kibana/public/home/components/tutorial_directory.js +++ b/src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial_directory.js @@ -22,7 +22,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import { Synopsis } from './synopsis'; import { SampleDataSetCards } from './sample_data_set_cards'; -import { getServices } from '../kibana_services'; +import { getServices } from '../../kibana_services'; import { EuiPage, diff --git a/src/legacy/core_plugins/kibana/public/home/components/welcome.test.tsx b/src/legacy/core_plugins/kibana/public/home/np_ready/components/welcome.test.tsx similarity index 98% rename from src/legacy/core_plugins/kibana/public/home/components/welcome.test.tsx rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/welcome.test.tsx index 42c6e6ff6056a..28bdab14193c4 100644 --- a/src/legacy/core_plugins/kibana/public/home/components/welcome.test.tsx +++ b/src/legacy/core_plugins/kibana/public/home/np_ready/components/welcome.test.tsx @@ -21,7 +21,7 @@ import React from 'react'; import { shallow } from 'enzyme'; import { Welcome } from './welcome'; -jest.mock('../kibana_services', () => ({ +jest.mock('../../kibana_services', () => ({ getServices: () => ({ addBasePath: (path: string) => `root${path}`, trackUiMetric: () => {}, diff --git a/src/legacy/core_plugins/kibana/public/home/components/welcome.tsx b/src/legacy/core_plugins/kibana/public/home/np_ready/components/welcome.tsx similarity index 99% rename from src/legacy/core_plugins/kibana/public/home/components/welcome.tsx rename to src/legacy/core_plugins/kibana/public/home/np_ready/components/welcome.tsx index 435bf98ca7840..9bbb7aaceb915 100644 --- a/src/legacy/core_plugins/kibana/public/home/components/welcome.tsx +++ b/src/legacy/core_plugins/kibana/public/home/np_ready/components/welcome.tsx @@ -36,7 +36,7 @@ import { EuiPortal, } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; -import { getServices } from '../kibana_services'; +import { getServices } from '../../kibana_services'; import { SampleDataCard } from './sample_data'; interface Props { diff --git a/src/legacy/core_plugins/kibana/public/home/load_tutorials.js b/src/legacy/core_plugins/kibana/public/home/np_ready/load_tutorials.js similarity index 98% rename from src/legacy/core_plugins/kibana/public/home/load_tutorials.js rename to src/legacy/core_plugins/kibana/public/home/np_ready/load_tutorials.js index be84027296259..6a0a01ebda8db 100644 --- a/src/legacy/core_plugins/kibana/public/home/load_tutorials.js +++ b/src/legacy/core_plugins/kibana/public/home/np_ready/load_tutorials.js @@ -18,7 +18,7 @@ */ import _ from 'lodash'; -import { getServices } from './kibana_services'; +import { getServices } from '../kibana_services'; import { i18n } from '@kbn/i18n'; const baseUrlLP = getServices().addBasePath('/api/kibana/home/tutorials_LP'); diff --git a/src/legacy/core_plugins/kibana/public/home/sample_data_client.js b/src/legacy/core_plugins/kibana/public/home/np_ready/sample_data_client.js similarity index 97% rename from src/legacy/core_plugins/kibana/public/home/sample_data_client.js rename to src/legacy/core_plugins/kibana/public/home/np_ready/sample_data_client.js index 600b1c3cb7dff..34c85d8d2c350 100644 --- a/src/legacy/core_plugins/kibana/public/home/sample_data_client.js +++ b/src/legacy/core_plugins/kibana/public/home/np_ready/sample_data_client.js @@ -17,7 +17,7 @@ * under the License. */ -import { getServices } from './kibana_services'; +import { getServices } from '../kibana_services'; const sampleDataUrl = '/api/sample_data'; diff --git a/src/legacy/core_plugins/kibana/public/home/plugin.ts b/src/legacy/core_plugins/kibana/public/home/plugin.ts index fc1747d71d069..a998e4d07ab15 100644 --- a/src/legacy/core_plugins/kibana/public/home/plugin.ts +++ b/src/legacy/core_plugins/kibana/public/home/plugin.ts @@ -88,7 +88,7 @@ export class HomePlugin implements Plugin { indexPatternService: this.dataStart!.indexPatterns, ...angularDependencies, }); - const { renderApp } = await import('./render_app'); + const { renderApp } = await import('./np_ready/application'); return await renderApp(params.element); }, }); diff --git a/src/legacy/core_plugins/kibana/public/index.scss b/src/legacy/core_plugins/kibana/public/index.scss index 611fe613ad99c..3b49af9a4a6a6 100644 --- a/src/legacy/core_plugins/kibana/public/index.scss +++ b/src/legacy/core_plugins/kibana/public/index.scss @@ -11,13 +11,14 @@ @import './dev_tools/index'; // Discover styles -@import './discover/index'; +@import 'discover/index'; // Home styles @import './home/index'; // Visualize styles @import './visualize/index'; +@import './visualize_embeddable/index'; // Has to come after visualize because of some // bad cascading in the Editor layout @import 'src/legacy/ui/public/vis/index'; diff --git a/src/legacy/core_plugins/kibana/public/visualize/_index.scss b/src/legacy/core_plugins/kibana/public/visualize/_index.scss index fbd218a64b5fb..0632831578bd0 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/_index.scss +++ b/src/legacy/core_plugins/kibana/public/visualize/_index.scss @@ -1,11 +1,2 @@ -// Prefix all styles with "vis" to avoid conflicts. -// Examples -// visChart -// visChart__legend -// visChart__legend--small -// visChart__legend-isLoading - -@import './editor/index'; -@import './embeddable/index'; -@import './listing/index'; -@import './wizard/index'; +// Visualize plugin styles +@import 'np_ready/index'; diff --git a/src/legacy/core_plugins/kibana/public/visualize/editor/_index.scss b/src/legacy/core_plugins/kibana/public/visualize/editor/_index.scss deleted file mode 100644 index 15c3c6df0ac03..0000000000000 --- a/src/legacy/core_plugins/kibana/public/visualize/editor/_index.scss +++ /dev/null @@ -1 +0,0 @@ -@import './editor'; diff --git a/src/legacy/core_plugins/kibana/public/visualize/embeddable/_index.scss b/src/legacy/core_plugins/kibana/public/visualize/embeddable/_index.scss deleted file mode 100644 index 6b31803e7c8c5..0000000000000 --- a/src/legacy/core_plugins/kibana/public/visualize/embeddable/_index.scss +++ /dev/null @@ -1,2 +0,0 @@ -@import './visualize_lab_disabled'; -@import './embeddables'; diff --git a/src/legacy/core_plugins/kibana/public/visualize/index.ts b/src/legacy/core_plugins/kibana/public/visualize/index.ts index 7c22bb3d0eaeb..bd605c5393d21 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/index.ts +++ b/src/legacy/core_plugins/kibana/public/visualize/index.ts @@ -32,6 +32,9 @@ import { VisualizePlugin, LegacyAngularInjectedDependencies } from './plugin'; import { start as embeddables } from '../../../embeddable_api/public/np_ready/public/legacy'; import { start as visualizations } from '../../../visualizations/public/np_ready/public/legacy'; +export * from './np_ready/visualize_constants'; +export { showNewVisModal } from './np_ready/wizard'; + /** * Get dependencies relying on the global angular context. * They also have to get resolved together with the legacy imports above diff --git a/src/legacy/core_plugins/kibana/public/visualize/kibana_services.ts b/src/legacy/core_plugins/kibana/public/visualize/kibana_services.ts index 38cedc7463e7c..991ea9b214b0a 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/kibana_services.ts +++ b/src/legacy/core_plugins/kibana/public/visualize/kibana_services.ts @@ -31,7 +31,8 @@ import { IEmbeddableStart } from '../../../../../plugins/embeddable/public'; import { SharePluginStart } from '../../../../../plugins/share/public'; import { DataPublicPluginStart, IndexPatternsContract } from '../../../../../plugins/data/public'; import { VisualizationsStart } from '../../../visualizations/public'; -import { SavedVisualizations } from './types'; +import { SavedVisualizations } from './np_ready/types'; +import { UsageCollectionSetup } from '../../../../../plugins/usage_collection/public'; export interface VisualizeKibanaServices { addBasePath: (url: string) => string; @@ -54,6 +55,7 @@ export interface VisualizeKibanaServices { uiSettings: IUiSettingsClient; visualizeCapabilities: any; visualizations: VisualizationsStart; + usageCollection?: UsageCollectionSetup; } let services: VisualizeKibanaServices | null = null; diff --git a/src/legacy/core_plugins/kibana/public/visualize/legacy_imports.ts b/src/legacy/core_plugins/kibana/public/visualize/legacy_imports.ts index b9909e522b571..febd566539bbe 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/legacy_imports.ts +++ b/src/legacy/core_plugins/kibana/public/visualize/legacy_imports.ts @@ -72,4 +72,7 @@ export { defaultEditor } from 'ui/vis/editors/default/default'; export { VisType } from 'ui/vis'; export { wrapInI18nContext } from 'ui/i18n'; -export { VisSavedObject } from './embeddable/visualize_embeddable'; +export { DashboardConstants } from '../dashboard/np_ready/dashboard_constants'; +export { VisSavedObject } from '../visualize_embeddable/visualize_embeddable'; +export { VISUALIZE_EMBEDDABLE_TYPE } from '../visualize_embeddable'; +export { VisualizeEmbeddableFactory } from '../visualize_embeddable/visualize_embeddable_factory'; diff --git a/src/legacy/core_plugins/kibana/public/visualize/listing/_index.scss b/src/legacy/core_plugins/kibana/public/visualize/listing/_index.scss deleted file mode 100644 index 0829e9af7039b..0000000000000 --- a/src/legacy/core_plugins/kibana/public/visualize/listing/_index.scss +++ /dev/null @@ -1 +0,0 @@ -@import './listing'; diff --git a/src/legacy/core_plugins/kibana/public/visualize/np_ready/_index.scss b/src/legacy/core_plugins/kibana/public/visualize/np_ready/_index.scss new file mode 100644 index 0000000000000..f97ae012055b0 --- /dev/null +++ b/src/legacy/core_plugins/kibana/public/visualize/np_ready/_index.scss @@ -0,0 +1,10 @@ +// Prefix all styles with "vis" to avoid conflicts. +// Examples +// visChart +// visChart__legend +// visChart__legend--small +// visChart__legend-isLoading + +@import 'editor/index'; +@import 'listing/index'; +@import 'wizard/index'; diff --git a/src/legacy/core_plugins/kibana/public/visualize/application.ts b/src/legacy/core_plugins/kibana/public/visualize/np_ready/application.ts similarity index 97% rename from src/legacy/core_plugins/kibana/public/visualize/application.ts rename to src/legacy/core_plugins/kibana/public/visualize/np_ready/application.ts index 3161576eacf71..dcd68a26743ab 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/application.ts +++ b/src/legacy/core_plugins/kibana/public/visualize/np_ready/application.ts @@ -38,12 +38,12 @@ import { PrivateProvider, PromiseServiceCreator, StateManagementConfigProvider, -} from './legacy_imports'; -import { NavigationPublicPluginStart as NavigationStart } from '../../../../../plugins/navigation/public'; +} from '../legacy_imports'; +import { NavigationPublicPluginStart as NavigationStart } from '../../../../../../plugins/navigation/public'; // @ts-ignore import { initVisualizeApp } from './legacy_app'; -import { VisualizeKibanaServices } from './kibana_services'; +import { VisualizeKibanaServices } from '../kibana_services'; let angularModuleInstance: IModule | null = null; diff --git a/src/legacy/core_plugins/kibana/public/visualize/breadcrumbs.ts b/src/legacy/core_plugins/kibana/public/visualize/np_ready/breadcrumbs.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/visualize/breadcrumbs.ts rename to src/legacy/core_plugins/kibana/public/visualize/np_ready/breadcrumbs.ts diff --git a/src/legacy/core_plugins/kibana/public/visualize/editor/_editor.scss b/src/legacy/core_plugins/kibana/public/visualize/np_ready/editor/_editor.scss similarity index 100% rename from src/legacy/core_plugins/kibana/public/visualize/editor/_editor.scss rename to src/legacy/core_plugins/kibana/public/visualize/np_ready/editor/_editor.scss diff --git a/src/legacy/core_plugins/kibana/public/visualize/np_ready/editor/_index.scss b/src/legacy/core_plugins/kibana/public/visualize/np_ready/editor/_index.scss new file mode 100644 index 0000000000000..9d3ca4b539947 --- /dev/null +++ b/src/legacy/core_plugins/kibana/public/visualize/np_ready/editor/_index.scss @@ -0,0 +1 @@ +@import 'editor'; diff --git a/src/legacy/core_plugins/kibana/public/visualize/editor/editor.html b/src/legacy/core_plugins/kibana/public/visualize/np_ready/editor/editor.html similarity index 100% rename from src/legacy/core_plugins/kibana/public/visualize/editor/editor.html rename to src/legacy/core_plugins/kibana/public/visualize/np_ready/editor/editor.html diff --git a/src/legacy/core_plugins/kibana/public/visualize/editor/editor.js b/src/legacy/core_plugins/kibana/public/visualize/np_ready/editor/editor.js similarity index 98% rename from src/legacy/core_plugins/kibana/public/visualize/editor/editor.js rename to src/legacy/core_plugins/kibana/public/visualize/np_ready/editor/editor.js index f745e65cc5d1c..ed9bec9db4112 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/editor/editor.js +++ b/src/legacy/core_plugins/kibana/public/visualize/np_ready/editor/editor.js @@ -21,33 +21,33 @@ import angular from 'angular'; import _ from 'lodash'; import { Subscription } from 'rxjs'; import { i18n } from '@kbn/i18n'; -import '../saved_visualizations/saved_visualizations'; +import '../../saved_visualizations/saved_visualizations'; import React from 'react'; import { FormattedMessage } from '@kbn/i18n/react'; import { migrateAppState } from './lib'; -import { DashboardConstants } from '../../dashboard/dashboard_constants'; import { VisualizeConstants } from '../visualize_constants'; import { getEditBreadcrumbs } from '../breadcrumbs'; import { addHelpMenuToAppChrome } from '../help_menu/help_menu_util'; -import { FilterStateManager } from '../../../../data/public/filter/filter_manager'; -import { unhashUrl } from '../../../../../../plugins/kibana_utils/public'; +import { FilterStateManager } from '../../../../../data/public'; +import { unhashUrl } from '../../../../../../../plugins/kibana_utils/public'; import { initVisEditorDirective } from './visualization_editor'; import { initVisualizationDirective } from './visualization'; import { + subscribeWithScope, absoluteToParsedUrl, KibanaParsedUrl, migrateLegacyQuery, SavedObjectSaveModal, showSaveModal, stateMonitorFactory, - subscribeWithScope, -} from '../legacy_imports'; + DashboardConstants, +} from '../../legacy_imports'; -import { getServices } from '../kibana_services'; +import { getServices } from '../../kibana_services'; export function initEditorDirective(app, deps) { app.directive('visualizeApp', function() { diff --git a/src/legacy/core_plugins/kibana/public/visualize/editor/lib/index.js b/src/legacy/core_plugins/kibana/public/visualize/np_ready/editor/lib/index.js similarity index 100% rename from src/legacy/core_plugins/kibana/public/visualize/editor/lib/index.js rename to src/legacy/core_plugins/kibana/public/visualize/np_ready/editor/lib/index.js diff --git a/src/legacy/core_plugins/kibana/public/visualize/editor/lib/migrate_app_state.js b/src/legacy/core_plugins/kibana/public/visualize/np_ready/editor/lib/migrate_app_state.js similarity index 100% rename from src/legacy/core_plugins/kibana/public/visualize/editor/lib/migrate_app_state.js rename to src/legacy/core_plugins/kibana/public/visualize/np_ready/editor/lib/migrate_app_state.js diff --git a/src/legacy/core_plugins/kibana/public/visualize/editor/visualization.js b/src/legacy/core_plugins/kibana/public/visualize/np_ready/editor/visualization.js similarity index 100% rename from src/legacy/core_plugins/kibana/public/visualize/editor/visualization.js rename to src/legacy/core_plugins/kibana/public/visualize/np_ready/editor/visualization.js diff --git a/src/legacy/core_plugins/kibana/public/visualize/editor/visualization_editor.js b/src/legacy/core_plugins/kibana/public/visualize/np_ready/editor/visualization_editor.js similarity index 100% rename from src/legacy/core_plugins/kibana/public/visualize/editor/visualization_editor.js rename to src/legacy/core_plugins/kibana/public/visualize/np_ready/editor/visualization_editor.js diff --git a/src/legacy/core_plugins/kibana/public/visualize/global_state_sync.ts b/src/legacy/core_plugins/kibana/public/visualize/np_ready/global_state_sync.ts similarity index 97% rename from src/legacy/core_plugins/kibana/public/visualize/global_state_sync.ts rename to src/legacy/core_plugins/kibana/public/visualize/np_ready/global_state_sync.ts index 71156bc38d498..f29fb72a9fbc5 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/global_state_sync.ts +++ b/src/legacy/core_plugins/kibana/public/visualize/np_ready/global_state_sync.ts @@ -17,8 +17,8 @@ * under the License. */ -import { State } from './legacy_imports'; -import { DataPublicPluginStart as DataStart } from '../../../../../plugins/data/public'; +import { State } from '../legacy_imports'; +import { DataPublicPluginStart as DataStart } from '../../../../../../plugins/data/public'; /** * Helper function to sync the global state with the various state providers diff --git a/src/legacy/core_plugins/kibana/public/visualize/help_menu/help_menu_util.js b/src/legacy/core_plugins/kibana/public/visualize/np_ready/help_menu/help_menu_util.js similarity index 100% rename from src/legacy/core_plugins/kibana/public/visualize/help_menu/help_menu_util.js rename to src/legacy/core_plugins/kibana/public/visualize/np_ready/help_menu/help_menu_util.js diff --git a/src/legacy/core_plugins/kibana/public/visualize/legacy_app.js b/src/legacy/core_plugins/kibana/public/visualize/np_ready/legacy_app.js similarity index 99% rename from src/legacy/core_plugins/kibana/public/visualize/legacy_app.js rename to src/legacy/core_plugins/kibana/public/visualize/np_ready/legacy_app.js index e948862071f69..d99771ccc912d 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/legacy_app.js +++ b/src/legacy/core_plugins/kibana/public/visualize/np_ready/legacy_app.js @@ -29,7 +29,7 @@ import { VisualizeListingController } from './listing/visualize_listing'; import { ensureDefaultIndexPattern, registerTimefilterWithGlobalStateFactory, -} from './legacy_imports'; +} from '../legacy_imports'; import { syncOnMount } from './global_state_sync'; import { diff --git a/src/legacy/core_plugins/kibana/public/visualize/np_ready/listing/_index.scss b/src/legacy/core_plugins/kibana/public/visualize/np_ready/listing/_index.scss new file mode 100644 index 0000000000000..924c164e467d8 --- /dev/null +++ b/src/legacy/core_plugins/kibana/public/visualize/np_ready/listing/_index.scss @@ -0,0 +1 @@ +@import 'listing'; diff --git a/src/legacy/core_plugins/kibana/public/visualize/listing/_listing.scss b/src/legacy/core_plugins/kibana/public/visualize/np_ready/listing/_listing.scss similarity index 100% rename from src/legacy/core_plugins/kibana/public/visualize/listing/_listing.scss rename to src/legacy/core_plugins/kibana/public/visualize/np_ready/listing/_listing.scss diff --git a/src/legacy/core_plugins/kibana/public/visualize/listing/visualize_listing.html b/src/legacy/core_plugins/kibana/public/visualize/np_ready/listing/visualize_listing.html similarity index 93% rename from src/legacy/core_plugins/kibana/public/visualize/listing/visualize_listing.html rename to src/legacy/core_plugins/kibana/public/visualize/np_ready/listing/visualize_listing.html index 4ee8809fab228..522d20fffafd3 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/listing/visualize_listing.html +++ b/src/legacy/core_plugins/kibana/public/visualize/np_ready/listing/visualize_listing.html @@ -17,6 +17,7 @@ add-base-path="listingController.addBasePath" ui-settings="listingController.uiSettings" saved-objects="listingController.savedObjects" + usage-collection="listingController.usageCollection" >
diff --git a/src/legacy/core_plugins/kibana/public/visualize/listing/visualize_listing.js b/src/legacy/core_plugins/kibana/public/visualize/np_ready/listing/visualize_listing.js similarity index 95% rename from src/legacy/core_plugins/kibana/public/visualize/listing/visualize_listing.js rename to src/legacy/core_plugins/kibana/public/visualize/np_ready/listing/visualize_listing.js index ca6660f34a0a6..b7d034b78d13f 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/listing/visualize_listing.js +++ b/src/legacy/core_plugins/kibana/public/visualize/np_ready/listing/visualize_listing.js @@ -23,8 +23,8 @@ import { NewVisModal } from '../wizard/new_vis_modal'; import { VisualizeConstants } from '../visualize_constants'; import { i18n } from '@kbn/i18n'; -import { getServices } from '../kibana_services'; -import { wrapInI18nContext } from '../legacy_imports'; +import { getServices } from '../../kibana_services'; +import { wrapInI18nContext } from '../../legacy_imports'; export function initListingDirective(app) { app.directive('visualizeListingTable', reactDirective => @@ -37,6 +37,7 @@ export function initListingDirective(app) { ['addBasePath', { watchDepth: 'reference' }], ['uiSettings', { watchDepth: 'reference' }], ['savedObjects', { watchDepth: 'reference' }], + ['usageCollection', { watchDepth: 'reference' }], 'isOpen', ]) ); @@ -58,6 +59,7 @@ export function VisualizeListingController($injector, createNewVis) { uiSettings, visualizations, core: { docLinks, savedObjects }, + usageCollection, } = getServices(); const kbnUrl = $injector.get('kbnUrl'); @@ -68,6 +70,7 @@ export function VisualizeListingController($injector, createNewVis) { this.addBasePath = addBasePath; this.uiSettings = uiSettings; this.savedObjects = savedObjects; + this.usageCollection = usageCollection; this.createNewVis = () => { this.showNewVisModal = true; diff --git a/src/legacy/core_plugins/kibana/public/visualize/listing/visualize_listing_table.js b/src/legacy/core_plugins/kibana/public/visualize/np_ready/listing/visualize_listing_table.js similarity index 98% rename from src/legacy/core_plugins/kibana/public/visualize/listing/visualize_listing_table.js rename to src/legacy/core_plugins/kibana/public/visualize/np_ready/listing/visualize_listing_table.js index 890fa64af9693..840e647edcc86 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/listing/visualize_listing_table.js +++ b/src/legacy/core_plugins/kibana/public/visualize/np_ready/listing/visualize_listing_table.js @@ -21,11 +21,11 @@ import React, { Component, Fragment } from 'react'; import PropTypes from 'prop-types'; import { FormattedMessage } from '@kbn/i18n/react'; import { i18n } from '@kbn/i18n'; -import { TableListView } from '../../../../../../../src/plugins/kibana_react/public'; +import { TableListView } from '../../../../../../../plugins/kibana_react/public'; import { EuiIcon, EuiBetaBadge, EuiLink, EuiButton, EuiEmptyPrompt } from '@elastic/eui'; -import { getServices } from '../kibana_services'; +import { getServices } from '../../kibana_services'; class VisualizeListingTable extends Component { constructor(props) { diff --git a/src/legacy/core_plugins/kibana/public/visualize/types.d.ts b/src/legacy/core_plugins/kibana/public/visualize/np_ready/types.d.ts similarity index 94% rename from src/legacy/core_plugins/kibana/public/visualize/types.d.ts rename to src/legacy/core_plugins/kibana/public/visualize/np_ready/types.d.ts index b6a3981215384..f47a54baac9a1 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/types.d.ts +++ b/src/legacy/core_plugins/kibana/public/visualize/np_ready/types.d.ts @@ -17,7 +17,7 @@ * under the License. */ -import { VisSavedObject } from './legacy_imports'; +import { VisSavedObject } from '../legacy_imports'; export interface SavedVisualizations { urlFor: (id: string) => string; diff --git a/src/legacy/core_plugins/kibana/public/visualize/visualize_app.ts b/src/legacy/core_plugins/kibana/public/visualize/np_ready/visualize_app.ts similarity index 94% rename from src/legacy/core_plugins/kibana/public/visualize/visualize_app.ts rename to src/legacy/core_plugins/kibana/public/visualize/np_ready/visualize_app.ts index c64287a0e63b8..1e7ac668697de 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/visualize_app.ts +++ b/src/legacy/core_plugins/kibana/public/visualize/np_ready/visualize_app.ts @@ -18,7 +18,7 @@ */ import { IModule } from 'angular'; -import { VisualizeKibanaServices } from './kibana_services'; +import { VisualizeKibanaServices } from '../kibana_services'; // @ts-ignore import { initEditorDirective } from './editor/editor'; diff --git a/src/legacy/core_plugins/kibana/public/visualize/visualize_constants.ts b/src/legacy/core_plugins/kibana/public/visualize/np_ready/visualize_constants.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/visualize/visualize_constants.ts rename to src/legacy/core_plugins/kibana/public/visualize/np_ready/visualize_constants.ts diff --git a/src/legacy/core_plugins/kibana/public/visualize/wizard/__snapshots__/new_vis_modal.test.tsx.snap b/src/legacy/core_plugins/kibana/public/visualize/np_ready/wizard/__snapshots__/new_vis_modal.test.tsx.snap similarity index 100% rename from src/legacy/core_plugins/kibana/public/visualize/wizard/__snapshots__/new_vis_modal.test.tsx.snap rename to src/legacy/core_plugins/kibana/public/visualize/np_ready/wizard/__snapshots__/new_vis_modal.test.tsx.snap diff --git a/src/legacy/core_plugins/kibana/public/visualize/wizard/_dialog.scss b/src/legacy/core_plugins/kibana/public/visualize/np_ready/wizard/_dialog.scss similarity index 100% rename from src/legacy/core_plugins/kibana/public/visualize/wizard/_dialog.scss rename to src/legacy/core_plugins/kibana/public/visualize/np_ready/wizard/_dialog.scss diff --git a/src/legacy/core_plugins/kibana/public/visualize/np_ready/wizard/_index.scss b/src/legacy/core_plugins/kibana/public/visualize/np_ready/wizard/_index.scss new file mode 100644 index 0000000000000..a10b4b1b347b7 --- /dev/null +++ b/src/legacy/core_plugins/kibana/public/visualize/np_ready/wizard/_index.scss @@ -0,0 +1 @@ +@import 'dialog'; diff --git a/src/legacy/core_plugins/kibana/public/visualize/wizard/index.ts b/src/legacy/core_plugins/kibana/public/visualize/np_ready/wizard/index.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/visualize/wizard/index.ts rename to src/legacy/core_plugins/kibana/public/visualize/np_ready/wizard/index.ts diff --git a/src/legacy/core_plugins/kibana/public/visualize/wizard/new_vis_modal.test.tsx b/src/legacy/core_plugins/kibana/public/visualize/np_ready/wizard/new_vis_modal.test.tsx similarity index 97% rename from src/legacy/core_plugins/kibana/public/visualize/wizard/new_vis_modal.test.tsx rename to src/legacy/core_plugins/kibana/public/visualize/np_ready/wizard/new_vis_modal.test.tsx index 8e4d50d27a453..2005133e6d03e 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/wizard/new_vis_modal.test.tsx +++ b/src/legacy/core_plugins/kibana/public/visualize/np_ready/wizard/new_vis_modal.test.tsx @@ -20,11 +20,10 @@ import React from 'react'; import { mountWithIntl } from 'test_utils/enzyme_helpers'; -import { VisType } from '../legacy_imports'; -import { TypesStart } from '../../../../visualizations/public/np_ready/public/types'; +import { VisType } from '../../legacy_imports'; +import { TypesStart } from '../../../../../visualizations/public/np_ready/public/types'; -jest.mock('ui/new_platform'); -jest.mock('../legacy_imports', () => ({ +jest.mock('../../legacy_imports', () => ({ State: () => null, AppState: () => null, })); diff --git a/src/legacy/core_plugins/kibana/public/visualize/wizard/new_vis_modal.tsx b/src/legacy/core_plugins/kibana/public/visualize/np_ready/wizard/new_vis_modal.tsx similarity index 86% rename from src/legacy/core_plugins/kibana/public/visualize/wizard/new_vis_modal.tsx rename to src/legacy/core_plugins/kibana/public/visualize/np_ready/wizard/new_vis_modal.tsx index e84797302589d..9e8f46407f591 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/wizard/new_vis_modal.tsx +++ b/src/legacy/core_plugins/kibana/public/visualize/np_ready/wizard/new_vis_modal.tsx @@ -22,13 +22,17 @@ import React from 'react'; import { EuiModal, EuiOverlayMask } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; +import { METRIC_TYPE, UiStatsMetricType } from '@kbn/analytics'; import { IUiSettingsClient, SavedObjectsStart } from 'kibana/public'; -import { VisType } from '../legacy_imports'; +import { VisType } from '../../legacy_imports'; import { VisualizeConstants } from '../visualize_constants'; -import { createUiStatsReporter, METRIC_TYPE } from '../../../../ui_metric/public'; import { SearchSelection } from './search_selection'; import { TypeSelection } from './type_selection'; -import { TypesStart, VisTypeAlias } from '../../../../visualizations/public/np_ready/public/types'; +import { + TypesStart, + VisTypeAlias, +} from '../../../../../visualizations/public/np_ready/public/types'; +import { UsageCollectionSetup } from '../../../../../../../plugins/usage_collection/public'; interface TypeSelectionProps { isOpen: boolean; @@ -38,6 +42,7 @@ interface TypeSelectionProps { addBasePath: (path: string) => string; uiSettings: IUiSettingsClient; savedObjects: SavedObjectsStart; + usageCollection?: UsageCollectionSetup; } interface TypeSelectionState { @@ -53,7 +58,9 @@ class NewVisModal extends React.Component; + private readonly trackUiMetric: + | ((type: UiStatsMetricType, eventNames: string | string[], count?: number) => void) + | undefined; constructor(props: TypeSelectionProps) { super(props); @@ -63,7 +70,10 @@ class NewVisModal extends React.Component void; diff --git a/src/legacy/core_plugins/kibana/public/visualize/wizard/show_new_vis.tsx b/src/legacy/core_plugins/kibana/public/visualize/np_ready/wizard/show_new_vis.tsx similarity index 86% rename from src/legacy/core_plugins/kibana/public/visualize/wizard/show_new_vis.tsx rename to src/legacy/core_plugins/kibana/public/visualize/np_ready/wizard/show_new_vis.tsx index 88838e16c40e2..567b7e861ad8e 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/wizard/show_new_vis.tsx +++ b/src/legacy/core_plugins/kibana/public/visualize/np_ready/wizard/show_new_vis.tsx @@ -23,7 +23,8 @@ import ReactDOM from 'react-dom'; import { I18nProvider } from '@kbn/i18n/react'; import { IUiSettingsClient, SavedObjectsStart } from 'kibana/public'; import { NewVisModal } from './new_vis_modal'; -import { TypesStart } from '../../../../visualizations/public/np_ready/public/types'; +import { TypesStart } from '../../../../../visualizations/public/np_ready/public/types'; +import { UsageCollectionSetup } from '../../../../../../../plugins/usage_collection/public'; interface ShowNewVisModalParams { editorParams?: string[]; @@ -34,7 +35,8 @@ export function showNewVisModal( { editorParams = [] }: ShowNewVisModalParams = {}, addBasePath: (path: string) => string, uiSettings: IUiSettingsClient, - savedObjects: SavedObjectsStart + savedObjects: SavedObjectsStart, + usageCollection?: UsageCollectionSetup ) { const container = document.createElement('div'); const onClose = () => { @@ -53,6 +55,7 @@ export function showNewVisModal( addBasePath={addBasePath} uiSettings={uiSettings} savedObjects={savedObjects} + usageCollection={usageCollection} /> ); diff --git a/src/legacy/core_plugins/kibana/public/visualize/wizard/type_selection/index.ts b/src/legacy/core_plugins/kibana/public/visualize/np_ready/wizard/type_selection/index.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/visualize/wizard/type_selection/index.ts rename to src/legacy/core_plugins/kibana/public/visualize/np_ready/wizard/type_selection/index.ts diff --git a/src/legacy/core_plugins/kibana/public/visualize/wizard/type_selection/new_vis_help.test.tsx b/src/legacy/core_plugins/kibana/public/visualize/np_ready/wizard/type_selection/new_vis_help.test.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/visualize/wizard/type_selection/new_vis_help.test.tsx rename to src/legacy/core_plugins/kibana/public/visualize/np_ready/wizard/type_selection/new_vis_help.test.tsx diff --git a/src/legacy/core_plugins/kibana/public/visualize/wizard/type_selection/new_vis_help.tsx b/src/legacy/core_plugins/kibana/public/visualize/np_ready/wizard/type_selection/new_vis_help.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/visualize/wizard/type_selection/new_vis_help.tsx rename to src/legacy/core_plugins/kibana/public/visualize/np_ready/wizard/type_selection/new_vis_help.tsx diff --git a/src/legacy/core_plugins/kibana/public/visualize/wizard/type_selection/type_selection.tsx b/src/legacy/core_plugins/kibana/public/visualize/np_ready/wizard/type_selection/type_selection.tsx similarity index 97% rename from src/legacy/core_plugins/kibana/public/visualize/wizard/type_selection/type_selection.tsx rename to src/legacy/core_plugins/kibana/public/visualize/np_ready/wizard/type_selection/type_selection.tsx index 38cd7fbe315ad..28cafde45a714 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/wizard/type_selection/type_selection.tsx +++ b/src/legacy/core_plugins/kibana/public/visualize/np_ready/wizard/type_selection/type_selection.tsx @@ -34,13 +34,13 @@ import { EuiSpacer, EuiTitle, } from '@elastic/eui'; -import { VisType } from '../../legacy_imports'; -import { memoizeLast } from '../../../../../visualizations/public/np_ready/public/legacy/memoize'; -import { VisTypeAlias } from '../../../../../visualizations/public'; +import { VisType } from '../../../legacy_imports'; +import { memoizeLast } from '../../../../../../visualizations/public/np_ready/public/legacy/memoize'; +import { VisTypeAlias } from '../../../../../../visualizations/public'; import { NewVisHelp } from './new_vis_help'; import { VisHelpText } from './vis_help_text'; import { VisTypeIcon } from './vis_type_icon'; -import { TypesStart } from '../../../../../visualizations/public/np_ready/public/types'; +import { TypesStart } from '../../../../../../visualizations/public/np_ready/public/types'; export interface VisTypeListEntry extends VisType { highlighted: boolean; diff --git a/src/legacy/core_plugins/kibana/public/visualize/wizard/type_selection/vis_help_text.tsx b/src/legacy/core_plugins/kibana/public/visualize/np_ready/wizard/type_selection/vis_help_text.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/visualize/wizard/type_selection/vis_help_text.tsx rename to src/legacy/core_plugins/kibana/public/visualize/np_ready/wizard/type_selection/vis_help_text.tsx diff --git a/src/legacy/core_plugins/kibana/public/visualize/wizard/type_selection/vis_type_icon.tsx b/src/legacy/core_plugins/kibana/public/visualize/np_ready/wizard/type_selection/vis_type_icon.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/visualize/wizard/type_selection/vis_type_icon.tsx rename to src/legacy/core_plugins/kibana/public/visualize/np_ready/wizard/type_selection/vis_type_icon.tsx diff --git a/src/legacy/core_plugins/kibana/public/visualize/plugin.ts b/src/legacy/core_plugins/kibana/public/visualize/plugin.ts index 9dff936761a4b..d1afa2d065194 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/plugin.ts +++ b/src/legacy/core_plugins/kibana/public/visualize/plugin.ts @@ -34,16 +34,20 @@ import { NavigationPublicPluginStart as NavigationStart } from '../../../../../p import { SharePluginStart } from '../../../../../plugins/share/public'; import { KibanaLegacySetup } from '../../../../../plugins/kibana_legacy/public'; import { VisualizationsStart } from '../../../visualizations/public'; -import { VisualizeEmbeddableFactory } from './embeddable/visualize_embeddable_factory'; -import { VISUALIZE_EMBEDDABLE_TYPE } from './embeddable/constants'; -import { VisualizeConstants } from './visualize_constants'; +import { VisualizeConstants } from './np_ready/visualize_constants'; import { setServices, VisualizeKibanaServices } from './kibana_services'; import { FeatureCatalogueCategory, HomePublicPluginSetup, } from '../../../../../plugins/home/public'; -import { defaultEditor, VisEditorTypesRegistryProvider } from './legacy_imports'; -import { SavedVisualizations } from './types'; +import { + defaultEditor, + VisEditorTypesRegistryProvider, + VisualizeEmbeddableFactory, + VISUALIZE_EMBEDDABLE_TYPE, +} from './legacy_imports'; +import { SavedVisualizations } from './np_ready/types'; +import { UsageCollectionSetup } from '../../../../../plugins/usage_collection/public'; export interface LegacyAngularInjectedDependencies { legacyChrome: any; @@ -66,6 +70,7 @@ export interface VisualizePluginSetupDependencies { }; home: HomePublicPluginSetup; kibana_legacy: KibanaLegacySetup; + usageCollection?: UsageCollectionSetup; } export class VisualizePlugin implements Plugin { @@ -80,7 +85,12 @@ export class VisualizePlugin implements Plugin { public async setup( core: CoreSetup, - { home, kibana_legacy, __LEGACY: { getAngularDependencies } }: VisualizePluginSetupDependencies + { + home, + kibana_legacy, + __LEGACY: { getAngularDependencies }, + usageCollection, + }: VisualizePluginSetupDependencies ) { kibana_legacy.registerLegacyApp({ id: 'visualize', @@ -118,10 +128,11 @@ export class VisualizePlugin implements Plugin { uiSettings: contextCore.uiSettings, visualizeCapabilities: contextCore.application.capabilities.visualize, visualizations, + usageCollection, }; setServices(deps); - const { renderApp } = await import('./application'); + const { renderApp } = await import('./np_ready/application'); return renderApp(params.element, params.appBasePath, deps); }, }); diff --git a/src/legacy/core_plugins/kibana/public/visualize/saved_visualizations/_saved_vis.ts b/src/legacy/core_plugins/kibana/public/visualize/saved_visualizations/_saved_vis.ts index 3490e0ab127ed..9f7ba342d803f 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/saved_visualizations/_saved_vis.ts +++ b/src/legacy/core_plugins/kibana/public/visualize/saved_visualizations/_saved_vis.ts @@ -29,12 +29,12 @@ import { Vis } from 'ui/vis'; import { SavedObject, SavedObjectKibanaServices } from 'ui/saved_objects/types'; import { createSavedObjectClass } from 'ui/saved_objects/saved_object'; import { updateOldState } from '../../../../visualizations/public'; -import { VisualizeConstants } from '../visualize_constants'; import { extractReferences, injectReferences } from './saved_visualization_references'; import { IIndexPattern } from '../../../../../../plugins/data/public'; import { VisSavedObject } from '../legacy_imports'; import { createSavedSearchesService } from '../../discover'; +import { VisualizeConstants } from '..'; async function _afterEsResp(savedVis: VisSavedObject, services: any) { await _getLinkedSavedSearch(savedVis, services); diff --git a/src/legacy/core_plugins/kibana/public/visualize/saved_visualizations/saved_visualization_references.test.ts b/src/legacy/core_plugins/kibana/public/visualize/saved_visualizations/saved_visualization_references.test.ts index 6549b317d1634..b71a10ab000d8 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/saved_visualizations/saved_visualization_references.test.ts +++ b/src/legacy/core_plugins/kibana/public/visualize/saved_visualizations/saved_visualization_references.test.ts @@ -18,7 +18,7 @@ */ import { extractReferences, injectReferences } from './saved_visualization_references'; -import { VisSavedObject } from '../embeddable/visualize_embeddable'; +import { VisSavedObject } from '../../visualize_embeddable/visualize_embeddable'; describe('extractReferences', () => { test('extracts nothing if savedSearchId is empty', () => { diff --git a/src/legacy/core_plugins/kibana/public/visualize/saved_visualizations/saved_visualization_references.ts b/src/legacy/core_plugins/kibana/public/visualize/saved_visualizations/saved_visualization_references.ts index dd8c2e9d2b74f..0c76aaff4345d 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/saved_visualizations/saved_visualization_references.ts +++ b/src/legacy/core_plugins/kibana/public/visualize/saved_visualizations/saved_visualization_references.ts @@ -17,7 +17,7 @@ * under the License. */ import { SavedObjectAttributes, SavedObjectReference } from 'kibana/server'; -import { VisSavedObject } from '../embeddable/visualize_embeddable'; +import { VisSavedObject } from '../../visualize_embeddable/visualize_embeddable'; export function extractReferences({ attributes, diff --git a/src/legacy/core_plugins/kibana/public/visualize/saved_visualizations/saved_visualizations.ts b/src/legacy/core_plugins/kibana/public/visualize/saved_visualizations/saved_visualizations.ts index 7425250bffe1a..aa8d20fed4828 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/saved_visualizations/saved_visualizations.ts +++ b/src/legacy/core_plugins/kibana/public/visualize/saved_visualizations/saved_visualizations.ts @@ -22,10 +22,10 @@ import { uiModules } from 'ui/modules'; import { SavedObjectLoader } from 'ui/saved_objects'; import { start as visualizations } from '../../../../visualizations/public/np_ready/public/legacy'; -import { createVisualizeEditUrl } from '../visualize_constants'; // @ts-ignore import { findListItems } from './find_list_items'; import { createSavedVisClass } from './_saved_vis'; +import { createVisualizeEditUrl } from '..'; const app = uiModules.get('app/visualize'); app.service('savedVisualizations', function() { diff --git a/src/legacy/core_plugins/kibana/public/visualize/wizard/_index.scss b/src/legacy/core_plugins/kibana/public/visualize/wizard/_index.scss deleted file mode 100644 index 328af16f3eebd..0000000000000 --- a/src/legacy/core_plugins/kibana/public/visualize/wizard/_index.scss +++ /dev/null @@ -1 +0,0 @@ -@import './dialog'; diff --git a/src/legacy/core_plugins/kibana/public/visualize/embeddable/_embeddables.scss b/src/legacy/core_plugins/kibana/public/visualize_embeddable/_embeddables.scss similarity index 100% rename from src/legacy/core_plugins/kibana/public/visualize/embeddable/_embeddables.scss rename to src/legacy/core_plugins/kibana/public/visualize_embeddable/_embeddables.scss diff --git a/src/legacy/core_plugins/kibana/public/visualize_embeddable/_index.scss b/src/legacy/core_plugins/kibana/public/visualize_embeddable/_index.scss new file mode 100644 index 0000000000000..c1e3809657bfa --- /dev/null +++ b/src/legacy/core_plugins/kibana/public/visualize_embeddable/_index.scss @@ -0,0 +1,2 @@ +@import 'visualize_lab_disabled'; +@import 'embeddables'; diff --git a/src/legacy/core_plugins/kibana/public/visualize/embeddable/_visualize_lab_disabled.scss b/src/legacy/core_plugins/kibana/public/visualize_embeddable/_visualize_lab_disabled.scss similarity index 100% rename from src/legacy/core_plugins/kibana/public/visualize/embeddable/_visualize_lab_disabled.scss rename to src/legacy/core_plugins/kibana/public/visualize_embeddable/_visualize_lab_disabled.scss diff --git a/src/legacy/core_plugins/kibana/public/visualize/embeddable/constants.ts b/src/legacy/core_plugins/kibana/public/visualize_embeddable/constants.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/visualize/embeddable/constants.ts rename to src/legacy/core_plugins/kibana/public/visualize_embeddable/constants.ts diff --git a/src/legacy/core_plugins/kibana/public/visualize/embeddable/disabled_lab_embeddable.tsx b/src/legacy/core_plugins/kibana/public/visualize_embeddable/disabled_lab_embeddable.tsx similarity index 94% rename from src/legacy/core_plugins/kibana/public/visualize/embeddable/disabled_lab_embeddable.tsx rename to src/legacy/core_plugins/kibana/public/visualize_embeddable/disabled_lab_embeddable.tsx index d8792a761b186..f9dfd5d2b98f4 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/embeddable/disabled_lab_embeddable.tsx +++ b/src/legacy/core_plugins/kibana/public/visualize_embeddable/disabled_lab_embeddable.tsx @@ -19,7 +19,7 @@ import React from 'react'; import ReactDOM from 'react-dom'; -import { Embeddable, EmbeddableOutput } from '../../../../../../plugins/embeddable/public'; +import { Embeddable, EmbeddableOutput } from '../../../../../plugins/embeddable/public'; import { DisabledLabVisualization } from './disabled_lab_visualization'; import { VisualizeInput } from './visualize_embeddable'; diff --git a/src/legacy/core_plugins/kibana/public/visualize/embeddable/disabled_lab_visualization.tsx b/src/legacy/core_plugins/kibana/public/visualize_embeddable/disabled_lab_visualization.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/visualize/embeddable/disabled_lab_visualization.tsx rename to src/legacy/core_plugins/kibana/public/visualize_embeddable/disabled_lab_visualization.tsx diff --git a/src/legacy/core_plugins/kibana/public/visualize/embeddable/get_index_pattern.ts b/src/legacy/core_plugins/kibana/public/visualize_embeddable/get_index_pattern.ts similarity index 95% rename from src/legacy/core_plugins/kibana/public/visualize/embeddable/get_index_pattern.ts rename to src/legacy/core_plugins/kibana/public/visualize_embeddable/get_index_pattern.ts index 7fe3678bb1f77..36efc4b86d0d3 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/embeddable/get_index_pattern.ts +++ b/src/legacy/core_plugins/kibana/public/visualize_embeddable/get_index_pattern.ts @@ -20,7 +20,7 @@ import { npStart } from 'ui/new_platform'; import { VisSavedObject } from './visualize_embeddable'; -import { indexPatterns, IIndexPattern } from '../../../../../../plugins/data/public'; +import { indexPatterns, IIndexPattern } from '../../../../../plugins/data/public'; export async function getIndexPattern( savedVis: VisSavedObject diff --git a/src/legacy/core_plugins/kibana/public/visualize/embeddable/index.ts b/src/legacy/core_plugins/kibana/public/visualize_embeddable/index.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/visualize/embeddable/index.ts rename to src/legacy/core_plugins/kibana/public/visualize_embeddable/index.ts diff --git a/src/legacy/core_plugins/kibana/public/visualize/embeddable/visualize_embeddable.ts b/src/legacy/core_plugins/kibana/public/visualize_embeddable/visualize_embeddable.ts similarity index 98% rename from src/legacy/core_plugins/kibana/public/visualize/embeddable/visualize_embeddable.ts rename to src/legacy/core_plugins/kibana/public/visualize_embeddable/visualize_embeddable.ts index 45cc1dc5fb9dd..6aade246d5f65 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/embeddable/visualize_embeddable.ts +++ b/src/legacy/core_plugins/kibana/public/visualize_embeddable/visualize_embeddable.ts @@ -38,16 +38,16 @@ import { onlyDisabledFiltersChanged, esFilters, mapAndFlattenFilters, -} from '../../../../../../plugins/data/public'; +} from '../../../../../plugins/data/public'; import { EmbeddableInput, EmbeddableOutput, Embeddable, Container, APPLY_FILTER_TRIGGER, -} from '../../../../../../plugins/embeddable/public'; -import { dispatchRenderComplete } from '../../../../../../plugins/kibana_utils/public'; -import { SavedSearch } from '../../discover/types'; +} from '../../../../../plugins/embeddable/public'; +import { dispatchRenderComplete } from '../../../../../plugins/kibana_utils/public'; +import { SavedSearch } from '../discover/np_ready/types'; const getKeys = (o: T): Array => Object.keys(o) as Array; diff --git a/src/legacy/core_plugins/kibana/public/visualize/embeddable/visualize_embeddable_factory.tsx b/src/legacy/core_plugins/kibana/public/visualize_embeddable/visualize_embeddable_factory.tsx similarity index 93% rename from src/legacy/core_plugins/kibana/public/visualize/embeddable/visualize_embeddable_factory.tsx rename to src/legacy/core_plugins/kibana/public/visualize_embeddable/visualize_embeddable_factory.tsx index a377dafe9e512..dd6723fb578af 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/embeddable/visualize_embeddable_factory.tsx +++ b/src/legacy/core_plugins/kibana/public/visualize_embeddable/visualize_embeddable_factory.tsx @@ -35,7 +35,7 @@ import 'uiExports/visualize'; import { i18n } from '@kbn/i18n'; import chrome from 'ui/chrome'; -import { npStart } from 'ui/new_platform'; +import { npSetup, npStart } from 'ui/new_platform'; import { Legacy } from 'kibana'; @@ -45,10 +45,10 @@ import { ErrorEmbeddable, Container, EmbeddableOutput, -} from '../../../../../../plugins/embeddable/public'; -import { start as visualizations } from '../../../../visualizations/public/np_ready/public/legacy'; -import { showNewVisModal } from '../wizard'; -import { SavedVisualizations } from '../types'; +} from '../../../../../plugins/embeddable/public'; +import { start as visualizations } from '../../../visualizations/public/np_ready/public/legacy'; +import { showNewVisModal } from '../visualize'; +import { SavedVisualizations } from '../visualize/np_ready/types'; import { DisabledLabEmbeddable } from './disabled_lab_embeddable'; import { getIndexPattern } from './get_index_pattern'; import { @@ -58,7 +58,7 @@ import { VisSavedObject, } from './visualize_embeddable'; import { VISUALIZE_EMBEDDABLE_TYPE } from './constants'; -import { TypesStart } from '../../../../visualizations/public/np_ready/public/types'; +import { TypesStart } from '../../../visualizations/public/np_ready/public/types'; interface VisualizationAttributes extends SavedObjectAttributes { visState: string; @@ -200,7 +200,8 @@ export class VisualizeEmbeddableFactory extends EmbeddableFactory< }, npStart.core.http.basePath.prepend, npStart.core.uiSettings, - npStart.core.savedObjects + npStart.core.savedObjects, + npSetup.plugins.usageCollection ); } return undefined; diff --git a/src/legacy/core_plugins/timelion/index.ts b/src/legacy/core_plugins/timelion/index.ts index 77e62ed02718c..ec121647f4e47 100644 --- a/src/legacy/core_plugins/timelion/index.ts +++ b/src/legacy/core_plugins/timelion/index.ts @@ -31,7 +31,7 @@ const experimentalLabel = i18n.translate('timelion.uiSettings.experimentalLabel' const timelionPluginInitializer: LegacyPluginInitializer = ({ Plugin }: LegacyPluginApi) => new Plugin({ - require: ['kibana', 'elasticsearch'], + require: ['kibana', 'elasticsearch', 'data'], config(Joi: any) { return Joi.object({ enabled: Joi.boolean().default(true), diff --git a/src/legacy/core_plugins/timelion/public/app.js b/src/legacy/core_plugins/timelion/public/app.js index bff847becb7a8..365e74e93c4ad 100644 --- a/src/legacy/core_plugins/timelion/public/app.js +++ b/src/legacy/core_plugins/timelion/public/app.js @@ -40,6 +40,7 @@ import 'ui/directives/saved_object_finder'; import 'ui/directives/listen'; import 'ui/kbn_top_nav'; import 'ui/saved_objects/ui/saved_object_save_as_checkbox'; +import '../../data/public/legacy'; import './services/saved_sheets'; import './services/_saved_sheet'; import './services/saved_sheet_register'; diff --git a/src/legacy/ui/public/registry/doc_views_helpers.tsx b/src/legacy/ui/public/registry/doc_views_helpers.tsx index d9e42e71dfff1..61545609f205d 100644 --- a/src/legacy/ui/public/registry/doc_views_helpers.tsx +++ b/src/legacy/ui/public/registry/doc_views_helpers.tsx @@ -26,7 +26,7 @@ import { AngularController, AngularDirective, } from './doc_views_types'; -import { DocViewerError } from '../../../core_plugins/kibana/public/discover/components/doc_viewer/doc_viewer_render_error'; +import { DocViewerError } from '../../../core_plugins/kibana/public/discover/np_ready/components/doc_viewer/doc_viewer_render_error'; /** * Compiles and injects the give angular template into the given dom node diff --git a/src/legacy/ui/public/styles/_legacy/components/_table.scss b/src/legacy/ui/public/styles/_legacy/components/_table.scss index e7c1bda829f0e..c9472cbd2faa7 100644 --- a/src/legacy/ui/public/styles/_legacy/components/_table.scss +++ b/src/legacy/ui/public/styles/_legacy/components/_table.scss @@ -1,4 +1,4 @@ -@import '../../../../../core_plugins/kibana/public/discover/mixins'; +@import '../../../../../core_plugins/kibana/public/discover/np_ready/mixins'; .table { // Nesting diff --git a/src/plugins/kibana_react/public/saved_objects/saved_object_save_modal.tsx b/src/plugins/kibana_react/public/saved_objects/saved_object_save_modal.tsx index bab710cdca595..33d4dcfd6606a 100644 --- a/src/plugins/kibana_react/public/saved_objects/saved_object_save_modal.tsx +++ b/src/plugins/kibana_react/public/saved_objects/saved_object_save_modal.tsx @@ -39,7 +39,7 @@ import { FormattedMessage } from '@kbn/i18n/react'; import React from 'react'; import { EuiText } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; -import { VISUALIZE_EMBEDDABLE_TYPE } from '../../../../legacy/core_plugins/kibana/public/visualize/embeddable/constants'; +import { VISUALIZE_EMBEDDABLE_TYPE } from '../../../../legacy/core_plugins/kibana/public/visualize_embeddable/constants'; export interface OnSaveProps { newTitle: string; diff --git a/test/functional/apps/dashboard/create_and_add_embeddables.js b/test/functional/apps/dashboard/create_and_add_embeddables.js index 2e0c4d449d447..90f02c36b3b7f 100644 --- a/test/functional/apps/dashboard/create_and_add_embeddables.js +++ b/test/functional/apps/dashboard/create_and_add_embeddables.js @@ -19,7 +19,7 @@ import expect from '@kbn/expect'; -import { VisualizeConstants } from '../../../../src/legacy/core_plugins/kibana/public/visualize/visualize_constants'; +import { VisualizeConstants } from '../../../../src/legacy/core_plugins/kibana/public/visualize/np_ready/visualize_constants'; export default function({ getService, getPageObjects }) { const retry = getService('retry'); diff --git a/test/functional/apps/dashboard/panel_controls.js b/test/functional/apps/dashboard/panel_controls.js index b69e031f84667..683f3683e65e5 100644 --- a/test/functional/apps/dashboard/panel_controls.js +++ b/test/functional/apps/dashboard/panel_controls.js @@ -24,7 +24,7 @@ import { AREA_CHART_VIS_NAME, LINE_CHART_VIS_NAME, } from '../../page_objects/dashboard_page'; -import { VisualizeConstants } from '../../../../src/legacy/core_plugins/kibana/public/visualize/visualize_constants'; +import { VisualizeConstants } from '../../../../src/legacy/core_plugins/kibana/public/visualize/np_ready/visualize_constants'; export default function({ getService, getPageObjects }) { const browser = getService('browser'); diff --git a/test/functional/page_objects/dashboard_page.js b/test/functional/page_objects/dashboard_page.js index ec258aa823405..b0f1a3304a9b8 100644 --- a/test/functional/page_objects/dashboard_page.js +++ b/test/functional/page_objects/dashboard_page.js @@ -18,7 +18,7 @@ */ import _ from 'lodash'; -import { DashboardConstants } from '../../../src/legacy/core_plugins/kibana/public/dashboard/dashboard_constants'; +import { DashboardConstants } from '../../../src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_constants'; export const PIE_CHART_VIS_NAME = 'Visualization PieChart'; export const AREA_CHART_VIS_NAME = 'Visualization漢字 AreaChart'; diff --git a/test/functional/page_objects/visualize_page.js b/test/functional/page_objects/visualize_page.js index 33b7515b58d2d..c1ea8be9be98b 100644 --- a/test/functional/page_objects/visualize_page.js +++ b/test/functional/page_objects/visualize_page.js @@ -17,7 +17,7 @@ * under the License. */ -import { VisualizeConstants } from '../../../src/legacy/core_plugins/kibana/public/visualize/visualize_constants'; +import { VisualizeConstants } from '../../../src/legacy/core_plugins/kibana/public/visualize/np_ready/visualize_constants'; import Bluebird from 'bluebird'; import expect from '@kbn/expect'; diff --git a/x-pack/legacy/plugins/canvas/canvas_plugin_src/expression_types/embeddable_types.ts b/x-pack/legacy/plugins/canvas/canvas_plugin_src/expression_types/embeddable_types.ts index 546e8967a7439..3669bd3e08201 100644 --- a/x-pack/legacy/plugins/canvas/canvas_plugin_src/expression_types/embeddable_types.ts +++ b/x-pack/legacy/plugins/canvas/canvas_plugin_src/expression_types/embeddable_types.ts @@ -6,8 +6,8 @@ // @ts-ignore import { MAP_SAVED_OBJECT_TYPE } from '../../../maps/common/constants'; -import { VISUALIZE_EMBEDDABLE_TYPE } from '../../../../../../src/legacy/core_plugins/kibana/public/visualize/embeddable/constants'; -import { SEARCH_EMBEDDABLE_TYPE } from '../../../../../../src/legacy/core_plugins/kibana/public/discover/embeddable/constants'; +import { VISUALIZE_EMBEDDABLE_TYPE } from '../../../../../../src/legacy/core_plugins/kibana/public/visualize_embeddable/constants'; +import { SEARCH_EMBEDDABLE_TYPE } from '../../../../../../src/legacy/core_plugins/kibana/public/discover/np_ready/embeddable/constants'; export const EmbeddableTypes = { map: MAP_SAVED_OBJECT_TYPE, diff --git a/x-pack/legacy/plugins/canvas/canvas_plugin_src/functions/common/saved_search.ts b/x-pack/legacy/plugins/canvas/canvas_plugin_src/functions/common/saved_search.ts index 221469ad8ded1..4895571115898 100644 --- a/x-pack/legacy/plugins/canvas/canvas_plugin_src/functions/common/saved_search.ts +++ b/x-pack/legacy/plugins/canvas/canvas_plugin_src/functions/common/saved_search.ts @@ -5,7 +5,7 @@ */ import { ExpressionFunction } from 'src/plugins/expressions/common/types'; -import { SearchInput } from 'src/legacy/core_plugins/kibana/public/discover/embeddable'; +import { SearchInput } from 'src/legacy/core_plugins/kibana/public/discover/np_ready/embeddable'; import { EmbeddableTypes, EmbeddableExpressionType, diff --git a/x-pack/legacy/plugins/canvas/canvas_plugin_src/functions/common/saved_visualization.ts b/x-pack/legacy/plugins/canvas/canvas_plugin_src/functions/common/saved_visualization.ts index b00ee446a8724..f6eb377e2698b 100644 --- a/x-pack/legacy/plugins/canvas/canvas_plugin_src/functions/common/saved_visualization.ts +++ b/x-pack/legacy/plugins/canvas/canvas_plugin_src/functions/common/saved_visualization.ts @@ -5,7 +5,7 @@ */ import { ExpressionFunction } from 'src/plugins/expressions/common/types'; -import { VisualizeInput } from 'src/legacy/core_plugins/kibana/public/visualize/embeddable'; +import { VisualizeInput } from 'src/legacy/core_plugins/kibana/public/visualize_embeddable'; import { EmbeddableTypes, EmbeddableExpressionType, diff --git a/x-pack/legacy/plugins/dashboard_mode/public/dashboard_viewer.js b/x-pack/legacy/plugins/dashboard_mode/public/dashboard_viewer.js index f0a0bf90d9e49..470fa00734d27 100644 --- a/x-pack/legacy/plugins/dashboard_mode/public/dashboard_viewer.js +++ b/x-pack/legacy/plugins/dashboard_mode/public/dashboard_viewer.js @@ -30,7 +30,6 @@ import 'uiExports/shareContextMenuExtensions'; import _ from 'lodash'; import 'ui/autoload/all'; import 'ui/kbn_top_nav'; -import 'plugins/kibana/dashboard'; import 'ui/vislib'; import 'ui/agg_response'; import 'ui/agg_types'; @@ -39,10 +38,7 @@ import { npStart } from 'ui/new_platform'; import { localApplicationService } from 'plugins/kibana/local_application_service'; import { showAppRedirectNotification } from 'ui/notify'; -import { - DashboardConstants, - createDashboardEditUrl, -} from 'plugins/kibana/dashboard/dashboard_constants'; +import { DashboardConstants, createDashboardEditUrl } from 'plugins/kibana/dashboard'; uiModules .get('kibana') diff --git a/x-pack/legacy/plugins/reporting/public/panel_actions/get_csv_panel_action.tsx b/x-pack/legacy/plugins/reporting/public/panel_actions/get_csv_panel_action.tsx index ebb57d34c01a1..95ca1792a7eb1 100644 --- a/x-pack/legacy/plugins/reporting/public/panel_actions/get_csv_panel_action.tsx +++ b/x-pack/legacy/plugins/reporting/public/panel_actions/get_csv_panel_action.tsx @@ -19,8 +19,8 @@ import { IEmbeddable, CONTEXT_MENU_TRIGGER, } from '../../../../../../src/legacy/core_plugins/embeddable_api/public/np_ready/public'; -import { SEARCH_EMBEDDABLE_TYPE } from '../../../../../../src/legacy/core_plugins/kibana/public/discover/embeddable/constants'; -import { ISearchEmbeddable } from '../../../../../../src/legacy/core_plugins/kibana/public/discover/embeddable/types'; +import { SEARCH_EMBEDDABLE_TYPE } from '../../../../../../src/legacy/core_plugins/kibana/public/discover/np_ready/embeddable/constants'; +import { ISearchEmbeddable } from '../../../../../../src/legacy/core_plugins/kibana/public/discover/np_ready/embeddable/types'; import { API_BASE_URL_V1 } from '../../common/constants'; diff --git a/x-pack/legacy/plugins/transform/public/app/lib/kibana/kibana_context.tsx b/x-pack/legacy/plugins/transform/public/app/lib/kibana/kibana_context.tsx index 3a3bd33ff6d70..5b7702a0193ec 100644 --- a/x-pack/legacy/plugins/transform/public/app/lib/kibana/kibana_context.tsx +++ b/x-pack/legacy/plugins/transform/public/app/lib/kibana/kibana_context.tsx @@ -6,7 +6,7 @@ import React, { createContext, useContext, FC } from 'react'; -import { SavedSearch } from '../../../../../../../../src/legacy/core_plugins/kibana/public/discover/types'; +import { SavedSearch } from '../../../../../../../../src/legacy/core_plugins/kibana/public/discover/np_ready/types'; import { IndexPattern, IndexPatternsContract, diff --git a/x-pack/legacy/plugins/transform/public/plugin.ts b/x-pack/legacy/plugins/transform/public/plugin.ts index 08a3a06fc24fc..5d1c39add4ff6 100644 --- a/x-pack/legacy/plugins/transform/public/plugin.ts +++ b/x-pack/legacy/plugins/transform/public/plugin.ts @@ -7,7 +7,7 @@ import { unmountComponentAtNode } from 'react-dom'; import { i18n } from '@kbn/i18n'; -import { SavedSearchLoader } from '../../../../../src/legacy/core_plugins/kibana/public/discover/types'; +import { SavedSearchLoader } from '../../../../../src/legacy/core_plugins/kibana/public/discover/np_ready/types'; import { PLUGIN } from '../common/constants'; import { CLIENT_BASE_PATH } from './app/constants'; diff --git a/x-pack/legacy/plugins/transform/public/shim.ts b/x-pack/legacy/plugins/transform/public/shim.ts index 5d7c309ade211..f8edc752c9a21 100644 --- a/x-pack/legacy/plugins/transform/public/shim.ts +++ b/x-pack/legacy/plugins/transform/public/shim.ts @@ -12,7 +12,7 @@ import { docTitle } from 'ui/doc_title/doc_title'; // @ts-ignore: allow traversal to fail on x-pack build import { createUiStatsReporter } from '../../../../../src/legacy/core_plugins/ui_metric/public'; -import { SavedSearchLoader } from '../../../../../src/legacy/core_plugins/kibana/public/discover/types'; +import { SavedSearchLoader } from '../../../../../src/legacy/core_plugins/kibana/public/discover/np_ready/types'; export type npCore = typeof npStart.core; diff --git a/x-pack/test/functional/apps/dashboard/feature_controls/dashboard_security.ts b/x-pack/test/functional/apps/dashboard/feature_controls/dashboard_security.ts index efc1f9d5e5e40..c7a9764c6fb58 100644 --- a/x-pack/test/functional/apps/dashboard/feature_controls/dashboard_security.ts +++ b/x-pack/test/functional/apps/dashboard/feature_controls/dashboard_security.ts @@ -7,7 +7,7 @@ import expect from '@kbn/expect'; import { createDashboardEditUrl, DashboardConstants, -} from '../../../../../../src/legacy/core_plugins/kibana/public/dashboard/dashboard_constants'; +} from '../../../../../../src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_constants'; import { FtrProviderContext } from '../../../ftr_provider_context'; export default function({ getPageObjects, getService }: FtrProviderContext) { diff --git a/x-pack/test/functional/apps/dashboard/feature_controls/dashboard_spaces.ts b/x-pack/test/functional/apps/dashboard/feature_controls/dashboard_spaces.ts index d98ad2db09430..127141b156cd8 100644 --- a/x-pack/test/functional/apps/dashboard/feature_controls/dashboard_spaces.ts +++ b/x-pack/test/functional/apps/dashboard/feature_controls/dashboard_spaces.ts @@ -7,7 +7,7 @@ import expect from '@kbn/expect'; import { createDashboardEditUrl, DashboardConstants, -} from '../../../../../../src/legacy/core_plugins/kibana/public/dashboard/dashboard_constants'; +} from '../../../../../../src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_constants'; import { FtrProviderContext } from '../../../ftr_provider_context'; export default function({ getPageObjects, getService }: FtrProviderContext) { diff --git a/x-pack/test/functional/apps/visualize/feature_controls/visualize_spaces.ts b/x-pack/test/functional/apps/visualize/feature_controls/visualize_spaces.ts index 49ad137b8da6b..d0fdc7c95ea38 100644 --- a/x-pack/test/functional/apps/visualize/feature_controls/visualize_spaces.ts +++ b/x-pack/test/functional/apps/visualize/feature_controls/visualize_spaces.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ import expect from '@kbn/expect'; -import { VisualizeConstants } from '../../../../../../src/legacy/core_plugins/kibana/public/visualize/visualize_constants'; +import { VisualizeConstants } from '../../../../../../src/legacy/core_plugins/kibana/public/visualize/np_ready/visualize_constants'; import { FtrProviderContext } from '../../../ftr_provider_context'; export default function({ getPageObjects, getService }: FtrProviderContext) { From 97ed566245b9d87b238f811b152d06bc5323a57b Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Fri, 20 Dec 2019 19:05:28 +0100 Subject: [PATCH 06/14] Migrate kql telemetry and scripts api (#52651) --- .../kibana-plugin-server.basepath.get.md | 2 +- .../server/kibana-plugin-server.basepath.md | 4 +- .../kibana-plugin-server.basepath.set.md | 2 +- src/core/server/server.api.md | 4 +- src/legacy/core_plugins/kibana/index.js | 6 --- .../kibana/ui_setting_defaults.js | 3 +- .../data/common/constants.ts} | 6 +-- src/plugins/data/common/index.ts | 1 + src/plugins/data/kibana.json | 3 +- .../data/server/kql_telemetry/index.ts} | 10 +--- .../kql_telemetry/kql_telemetry_service.ts | 53 +++++++++++++++++++ .../data/server/kql_telemetry/route.ts} | 48 +++++++++-------- .../usage_collector/fetch.test.ts} | 30 ++++++----- .../kql_telemetry/usage_collector/fetch.ts} | 10 ++-- .../kql_telemetry/usage_collector/index.ts} | 0 .../make_kql_usage_collector.test.ts} | 29 ++++------ .../make_kql_usage_collector.ts} | 9 ++-- src/plugins/data/server/plugin.ts | 15 +++++- src/plugins/data/server/scripts/index.ts | 20 +++++++ src/plugins/data/server/scripts/route.ts | 31 +++++++++++ .../data/server/scripts/scripts_service.ts | 29 ++++++++++ 21 files changed, 226 insertions(+), 89 deletions(-) rename src/{legacy/core_plugins/kibana/server/routes/api/scripts/index.js => plugins/data/common/constants.ts} (86%) rename src/{legacy/core_plugins/kibana/server/routes/api/scripts/register_languages.js => plugins/data/server/kql_telemetry/index.ts} (79%) create mode 100644 src/plugins/data/server/kql_telemetry/kql_telemetry_service.ts rename src/{legacy/core_plugins/kibana/server/routes/api/kql_telemetry/index.js => plugins/data/server/kql_telemetry/route.ts} (57%) rename src/{legacy/core_plugins/kibana/server/lib/kql_usage_collector/fetch.test.js => plugins/data/server/kql_telemetry/usage_collector/fetch.test.ts} (85%) rename src/{legacy/core_plugins/kibana/server/lib/kql_usage_collector/fetch.js => plugins/data/server/kql_telemetry/usage_collector/fetch.ts} (89%) rename src/{legacy/core_plugins/kibana/server/lib/kql_usage_collector/index.js => plugins/data/server/kql_telemetry/usage_collector/index.ts} (100%) rename src/{legacy/core_plugins/kibana/server/lib/kql_usage_collector/make_kql_usage_collector.test.js => plugins/data/server/kql_telemetry/usage_collector/make_kql_usage_collector.test.ts} (62%) rename src/{legacy/core_plugins/kibana/server/lib/kql_usage_collector/make_kql_usage_collector.js => plugins/data/server/kql_telemetry/usage_collector/make_kql_usage_collector.ts} (81%) create mode 100644 src/plugins/data/server/scripts/index.ts create mode 100644 src/plugins/data/server/scripts/route.ts create mode 100644 src/plugins/data/server/scripts/scripts_service.ts diff --git a/docs/development/core/server/kibana-plugin-server.basepath.get.md b/docs/development/core/server/kibana-plugin-server.basepath.get.md index a20bc1a4e3174..6ef7022f10e62 100644 --- a/docs/development/core/server/kibana-plugin-server.basepath.get.md +++ b/docs/development/core/server/kibana-plugin-server.basepath.get.md @@ -9,5 +9,5 @@ returns `basePath` value, specific for an incoming request. Signature: ```typescript -get: (request: LegacyRequest | KibanaRequest) => string; +get: (request: KibanaRequest | LegacyRequest) => string; ``` diff --git a/docs/development/core/server/kibana-plugin-server.basepath.md b/docs/development/core/server/kibana-plugin-server.basepath.md index bf91619ac230b..77f50abc60369 100644 --- a/docs/development/core/server/kibana-plugin-server.basepath.md +++ b/docs/development/core/server/kibana-plugin-server.basepath.md @@ -16,11 +16,11 @@ export declare class BasePath | Property | Modifiers | Type | Description | | --- | --- | --- | --- | -| [get](./kibana-plugin-server.basepath.get.md) | | (request: LegacyRequest | KibanaRequest<unknown, unknown, unknown, any>) => string | returns basePath value, specific for an incoming request. | +| [get](./kibana-plugin-server.basepath.get.md) | | (request: KibanaRequest<unknown, unknown, unknown, any> | LegacyRequest) => string | returns basePath value, specific for an incoming request. | | [prepend](./kibana-plugin-server.basepath.prepend.md) | | (path: string) => string | Prepends path with the basePath. | | [remove](./kibana-plugin-server.basepath.remove.md) | | (path: string) => string | Removes the prepended basePath from the path. | | [serverBasePath](./kibana-plugin-server.basepath.serverbasepath.md) | | string | returns the server's basePathSee [BasePath.get](./kibana-plugin-server.basepath.get.md) for getting the basePath value for a specific request | -| [set](./kibana-plugin-server.basepath.set.md) | | (request: LegacyRequest | KibanaRequest<unknown, unknown, unknown, any>, requestSpecificBasePath: string) => void | sets basePath value, specific for an incoming request. | +| [set](./kibana-plugin-server.basepath.set.md) | | (request: KibanaRequest<unknown, unknown, unknown, any> | LegacyRequest, requestSpecificBasePath: string) => void | sets basePath value, specific for an incoming request. | ## Remarks diff --git a/docs/development/core/server/kibana-plugin-server.basepath.set.md b/docs/development/core/server/kibana-plugin-server.basepath.set.md index ac08baa0bb99e..56a7f644d34cc 100644 --- a/docs/development/core/server/kibana-plugin-server.basepath.set.md +++ b/docs/development/core/server/kibana-plugin-server.basepath.set.md @@ -9,5 +9,5 @@ sets `basePath` value, specific for an incoming request. Signature: ```typescript -set: (request: LegacyRequest | KibanaRequest, requestSpecificBasePath: string) => void; +set: (request: KibanaRequest | LegacyRequest, requestSpecificBasePath: string) => void; ``` diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md index dc4518ef41253..ef5368751c8f5 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -450,11 +450,11 @@ export interface AuthToolkit { export class BasePath { // @internal constructor(serverBasePath?: string); - get: (request: LegacyRequest | KibanaRequest) => string; + get: (request: KibanaRequest | LegacyRequest) => string; prepend: (path: string) => string; remove: (path: string) => string; readonly serverBasePath: string; - set: (request: LegacyRequest | KibanaRequest, requestSpecificBasePath: string) => void; + set: (request: KibanaRequest | LegacyRequest, requestSpecificBasePath: string) => void; } // Warning: (ae-forgotten-export) The symbol "BootstrapArgs" needs to be exported by the entry point index.d.ts diff --git a/src/legacy/core_plugins/kibana/index.js b/src/legacy/core_plugins/kibana/index.js index dd74119737657..111b74d8aa6af 100644 --- a/src/legacy/core_plugins/kibana/index.js +++ b/src/legacy/core_plugins/kibana/index.js @@ -26,14 +26,11 @@ import { importApi } from './server/routes/api/import'; import { exportApi } from './server/routes/api/export'; import { homeApi } from './server/routes/api/home'; import { managementApi } from './server/routes/api/management'; -import { scriptsApi } from './server/routes/api/scripts'; -import { registerKqlTelemetryApi } from './server/routes/api/kql_telemetry'; import { registerFieldFormats } from './server/field_formats/register'; import { registerTutorials } from './server/tutorials/register'; import * as systemApi from './server/lib/system_api'; import mappings from './mappings.json'; import { getUiSettingDefaults } from './ui_setting_defaults'; -import { makeKQLUsageCollector } from './server/lib/kql_usage_collector'; import { registerCspCollector } from './server/lib/csp_usage_collector'; import { injectVars } from './inject_vars'; import { i18n } from '@kbn/i18n'; @@ -325,15 +322,12 @@ export default function(kibana) { init: async function(server) { const { usageCollection } = server.newPlatform.setup.plugins; // routes - scriptsApi(server); importApi(server); exportApi(server); homeApi(server); managementApi(server); - registerKqlTelemetryApi(server); registerFieldFormats(server); registerTutorials(server); - makeKQLUsageCollector(usageCollection, server); registerCspCollector(usageCollection, server); server.expose('systemApi', systemApi); server.injectUiAppVars('kibana', () => injectVars(server)); diff --git a/src/legacy/core_plugins/kibana/ui_setting_defaults.js b/src/legacy/core_plugins/kibana/ui_setting_defaults.js index 682da20ca4118..196d9662f8b15 100644 --- a/src/legacy/core_plugins/kibana/ui_setting_defaults.js +++ b/src/legacy/core_plugins/kibana/ui_setting_defaults.js @@ -20,6 +20,7 @@ import moment from 'moment-timezone'; import numeralLanguages from '@elastic/numeral/languages'; import { i18n } from '@kbn/i18n'; +import { DEFAULT_QUERY_LANGUAGE } from '../../../plugins/data/common'; export function getUiSettingDefaults() { const weekdays = moment.weekdays().slice(); @@ -121,7 +122,7 @@ export function getUiSettingDefaults() { }, 'search:queryLanguage': { name: queryLanguageSettingName, - value: 'kuery', + value: DEFAULT_QUERY_LANGUAGE, description: i18n.translate('kbn.advancedSettings.searchQueryLanguageText', { defaultMessage: 'Query language used by the query bar. KQL is a new language built specifically for Kibana.', diff --git a/src/legacy/core_plugins/kibana/server/routes/api/scripts/index.js b/src/plugins/data/common/constants.ts similarity index 86% rename from src/legacy/core_plugins/kibana/server/routes/api/scripts/index.js rename to src/plugins/data/common/constants.ts index 441963b02f14f..00786a0c72cf1 100644 --- a/src/legacy/core_plugins/kibana/server/routes/api/scripts/index.js +++ b/src/plugins/data/common/constants.ts @@ -17,8 +17,4 @@ * under the License. */ -import { registerLanguages } from './register_languages'; - -export function scriptsApi(server) { - registerLanguages(server); -} +export const DEFAULT_QUERY_LANGUAGE = 'kuery'; diff --git a/src/plugins/data/common/index.ts b/src/plugins/data/common/index.ts index b334342a57ec6..e02045de24e8f 100644 --- a/src/plugins/data/common/index.ts +++ b/src/plugins/data/common/index.ts @@ -24,3 +24,4 @@ export * from './index_patterns'; export * from './es_query'; export * from './utils'; export * from './types'; +export * from './constants'; diff --git a/src/plugins/data/kibana.json b/src/plugins/data/kibana.json index 998eaa55858d2..6553ce8ce4d91 100644 --- a/src/plugins/data/kibana.json +++ b/src/plugins/data/kibana.json @@ -3,5 +3,6 @@ "version": "kibana", "server": true, "ui": true, - "requiredPlugins": ["uiActions"] + "requiredPlugins": ["uiActions"], + "optionalPlugins": ["usageCollection"] } diff --git a/src/legacy/core_plugins/kibana/server/routes/api/scripts/register_languages.js b/src/plugins/data/server/kql_telemetry/index.ts similarity index 79% rename from src/legacy/core_plugins/kibana/server/routes/api/scripts/register_languages.js rename to src/plugins/data/server/kql_telemetry/index.ts index d28ca50e32088..0191113d95007 100644 --- a/src/legacy/core_plugins/kibana/server/routes/api/scripts/register_languages.js +++ b/src/plugins/data/server/kql_telemetry/index.ts @@ -17,12 +17,4 @@ * under the License. */ -export function registerLanguages(server) { - server.route({ - path: '/api/kibana/scripts/languages', - method: 'GET', - handler: function() { - return ['painless', 'expression']; - }, - }); -} +export { KqlTelemetryService } from './kql_telemetry_service'; diff --git a/src/plugins/data/server/kql_telemetry/kql_telemetry_service.ts b/src/plugins/data/server/kql_telemetry/kql_telemetry_service.ts new file mode 100644 index 0000000000000..8f68e63703d40 --- /dev/null +++ b/src/plugins/data/server/kql_telemetry/kql_telemetry_service.ts @@ -0,0 +1,53 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { first } from 'rxjs/operators'; +import { CoreSetup, Plugin, PluginInitializerContext } from 'kibana/server'; +import { registerKqlTelemetryRoute } from './route'; +import { UsageCollectionSetup } from '../../../usage_collection/server'; +import { makeKQLUsageCollector } from './usage_collector'; + +export class KqlTelemetryService implements Plugin { + constructor(private initializerContext: PluginInitializerContext) {} + + public setup( + { http, savedObjects }: CoreSetup, + { usageCollection }: { usageCollection?: UsageCollectionSetup } + ) { + registerKqlTelemetryRoute( + http.createRouter(), + savedObjects, + this.initializerContext.logger.get('data', 'kql-telemetry') + ); + + if (usageCollection) { + this.initializerContext.config.legacy.globalConfig$ + .pipe(first()) + .toPromise() + .then(config => makeKQLUsageCollector(usageCollection, config.kibana.index)) + .catch(e => { + this.initializerContext.logger + .get('kql-telemetry') + .warn(`Registering KQL telemetry collector failed: ${e}`); + }); + } + } + + public start() {} +} diff --git a/src/legacy/core_plugins/kibana/server/routes/api/kql_telemetry/index.js b/src/plugins/data/server/kql_telemetry/route.ts similarity index 57% rename from src/legacy/core_plugins/kibana/server/routes/api/kql_telemetry/index.js rename to src/plugins/data/server/kql_telemetry/route.ts index 430240169c81c..3185da22b12b3 100644 --- a/src/legacy/core_plugins/kibana/server/routes/api/kql_telemetry/index.js +++ b/src/plugins/data/server/kql_telemetry/route.ts @@ -17,30 +17,28 @@ * under the License. */ -import Joi from 'joi'; -import Boom from 'boom'; +import { CoreSetup, IRouter, Logger } from 'kibana/server'; +import { schema } from '@kbn/config-schema'; -export function registerKqlTelemetryApi(server) { - server.route({ - path: '/api/kibana/kql_opt_in_telemetry', - method: 'POST', - config: { +export function registerKqlTelemetryRoute( + router: IRouter, + savedObjects: CoreSetup['savedObjects'], + logger: Logger +) { + router.post( + { + path: '/api/kibana/kql_opt_in_telemetry', validate: { - payload: Joi.object({ - opt_in: Joi.bool().required(), + body: schema.object({ + opt_in: schema.boolean(), }), }, - tags: ['api'], }, - handler: async function(request) { - const { - savedObjects: { getSavedObjectsRepository }, - } = server; - const { callWithInternalUser } = server.plugins.elasticsearch.getCluster('admin'); - const internalRepository = getSavedObjectsRepository(callWithInternalUser); + async (context, request, response) => { + const internalRepository = savedObjects.createScopedRepository(request); const { - payload: { opt_in: optIn }, + body: { opt_in: optIn }, } = request; const counterName = optIn ? 'optInCount' : 'optOutCount'; @@ -48,13 +46,19 @@ export function registerKqlTelemetryApi(server) { try { await internalRepository.incrementCounter('kql-telemetry', 'kql-telemetry', counterName); } catch (error) { - return new Boom('Something went wrong', { + logger.warn(`Unable to increment counter: ${error}`); + return response.customError({ statusCode: error.status, - data: { success: false }, + body: { + message: 'Something went wrong', + attributes: { + success: false, + }, + }, }); } - return { success: true }; - }, - }); + return response.ok({ body: { success: true } }); + } + ); } diff --git a/src/legacy/core_plugins/kibana/server/lib/kql_usage_collector/fetch.test.js b/src/plugins/data/server/kql_telemetry/usage_collector/fetch.test.ts similarity index 85% rename from src/legacy/core_plugins/kibana/server/lib/kql_usage_collector/fetch.test.js rename to src/plugins/data/server/kql_telemetry/usage_collector/fetch.test.ts index a5db4602872ee..446320b09757a 100644 --- a/src/legacy/core_plugins/kibana/server/lib/kql_usage_collector/fetch.test.js +++ b/src/plugins/data/server/kql_telemetry/usage_collector/fetch.test.ts @@ -17,18 +17,22 @@ * under the License. */ -jest.mock('../../../ui_setting_defaults', () => ({ - getUiSettingDefaults: () => ({ 'search:queryLanguage': { value: 'lucene' } }), -})); - import { fetchProvider } from './fetch'; +import { APICaller } from 'kibana/server'; + +jest.mock('../../../common', () => ({ + DEFAULT_QUERY_LANGUAGE: 'lucene', +})); -let fetch; -let callCluster; +let fetch: ReturnType; +let callCluster: APICaller; -function setupMockCallCluster(optCount, language) { - callCluster = jest.fn((method, params) => { - if ('id' in params && params.id === 'kql-telemetry:kql-telemetry') { +function setupMockCallCluster( + optCount: { optInCount?: number; optOutCount?: number } | null, + language: string | undefined | null +) { + callCluster = (jest.fn((method, params) => { + if (params && 'id' in params && params.id === 'kql-telemetry:kql-telemetry') { if (optCount === null) { return Promise.resolve({ _index: '.kibana_1', @@ -46,9 +50,9 @@ function setupMockCallCluster(optCount, language) { }, }); } - } else if ('body' in params && params.body.query.term.type === 'config') { + } else if (params && 'body' in params && params.body.query.term.type === 'config') { if (language === 'missingConfigDoc') { - Promise.resolve({ + return Promise.resolve({ hits: { hits: [], }, @@ -69,7 +73,9 @@ function setupMockCallCluster(optCount, language) { }); } } - }); + + throw new Error('invalid call'); + }) as unknown) as APICaller; } describe('makeKQLUsageCollector', () => { diff --git a/src/legacy/core_plugins/kibana/server/lib/kql_usage_collector/fetch.js b/src/plugins/data/server/kql_telemetry/usage_collector/fetch.ts similarity index 89% rename from src/legacy/core_plugins/kibana/server/lib/kql_usage_collector/fetch.js rename to src/plugins/data/server/kql_telemetry/usage_collector/fetch.ts index 0a886d364c6fd..9f3437161541f 100644 --- a/src/legacy/core_plugins/kibana/server/lib/kql_usage_collector/fetch.js +++ b/src/plugins/data/server/kql_telemetry/usage_collector/fetch.ts @@ -17,14 +17,14 @@ * under the License. */ -import { getUiSettingDefaults } from '../../../ui_setting_defaults'; import { get } from 'lodash'; +import { APICaller } from 'kibana/server'; +import { DEFAULT_QUERY_LANGUAGE } from '../../../common'; -const uiSettingDefaults = getUiSettingDefaults(); -const defaultSearchQueryLanguageSetting = uiSettingDefaults['search:queryLanguage'].value; +const defaultSearchQueryLanguageSetting = DEFAULT_QUERY_LANGUAGE; -export function fetchProvider(index) { - return async callCluster => { +export function fetchProvider(index: string) { + return async (callCluster: APICaller) => { const [response, config] = await Promise.all([ callCluster('get', { index, diff --git a/src/legacy/core_plugins/kibana/server/lib/kql_usage_collector/index.js b/src/plugins/data/server/kql_telemetry/usage_collector/index.ts similarity index 100% rename from src/legacy/core_plugins/kibana/server/lib/kql_usage_collector/index.js rename to src/plugins/data/server/kql_telemetry/usage_collector/index.ts diff --git a/src/legacy/core_plugins/kibana/server/lib/kql_usage_collector/make_kql_usage_collector.test.js b/src/plugins/data/server/kql_telemetry/usage_collector/make_kql_usage_collector.test.ts similarity index 62% rename from src/legacy/core_plugins/kibana/server/lib/kql_usage_collector/make_kql_usage_collector.test.js rename to src/plugins/data/server/kql_telemetry/usage_collector/make_kql_usage_collector.test.ts index 34503bf56ad84..97a714f09474b 100644 --- a/src/legacy/core_plugins/kibana/server/lib/kql_usage_collector/make_kql_usage_collector.test.js +++ b/src/plugins/data/server/kql_telemetry/usage_collector/make_kql_usage_collector.test.ts @@ -18,33 +18,26 @@ */ import { makeKQLUsageCollector } from './make_kql_usage_collector'; +import { UsageCollectionSetup } from '../../../../usage_collection/server'; describe('makeKQLUsageCollector', () => { - let server; - let makeUsageCollectorStub; - let registerStub; - let usageCollection; + let usageCollectionMock: jest.Mocked; beforeEach(() => { - makeUsageCollectorStub = jest.fn(); - registerStub = jest.fn(); - usageCollection = { - makeUsageCollector: makeUsageCollectorStub, - registerCollector: registerStub, - }; - server = { - config: () => ({ get: () => '.kibana' }), - }; + usageCollectionMock = ({ + makeUsageCollector: jest.fn(), + registerCollector: jest.fn(), + } as unknown) as jest.Mocked; }); it('should call registerCollector', () => { - makeKQLUsageCollector(usageCollection, server); - expect(registerStub).toHaveBeenCalledTimes(1); + makeKQLUsageCollector(usageCollectionMock, '.kibana'); + expect(usageCollectionMock.registerCollector).toHaveBeenCalledTimes(1); }); it('should call makeUsageCollector with type = kql', () => { - makeKQLUsageCollector(usageCollection, server); - expect(makeUsageCollectorStub).toHaveBeenCalledTimes(1); - expect(makeUsageCollectorStub.mock.calls[0][0].type).toBe('kql'); + makeKQLUsageCollector(usageCollectionMock, '.kibana'); + expect(usageCollectionMock.makeUsageCollector).toHaveBeenCalledTimes(1); + expect(usageCollectionMock.makeUsageCollector.mock.calls[0][0].type).toBe('kql'); }); }); diff --git a/src/legacy/core_plugins/kibana/server/lib/kql_usage_collector/make_kql_usage_collector.js b/src/plugins/data/server/kql_telemetry/usage_collector/make_kql_usage_collector.ts similarity index 81% rename from src/legacy/core_plugins/kibana/server/lib/kql_usage_collector/make_kql_usage_collector.js rename to src/plugins/data/server/kql_telemetry/usage_collector/make_kql_usage_collector.ts index 6d751a9e9ff45..db4c9a8f0b4c7 100644 --- a/src/legacy/core_plugins/kibana/server/lib/kql_usage_collector/make_kql_usage_collector.js +++ b/src/plugins/data/server/kql_telemetry/usage_collector/make_kql_usage_collector.ts @@ -18,10 +18,13 @@ */ import { fetchProvider } from './fetch'; +import { UsageCollectionSetup } from '../../../../usage_collection/server'; -export function makeKQLUsageCollector(usageCollection, server) { - const index = server.config().get('kibana.index'); - const fetch = fetchProvider(index); +export async function makeKQLUsageCollector( + usageCollection: UsageCollectionSetup, + kibanaIndex: string +) { + const fetch = fetchProvider(kibanaIndex); const kqlUsageCollector = usageCollection.makeUsageCollector({ type: 'kql', fetch, diff --git a/src/plugins/data/server/plugin.ts b/src/plugins/data/server/plugin.ts index 6df0a11e7538d..591fdb4c4080d 100644 --- a/src/plugins/data/server/plugin.ts +++ b/src/plugins/data/server/plugin.ts @@ -21,29 +21,42 @@ import { PluginInitializerContext, CoreSetup, CoreStart, Plugin } from '../../.. import { IndexPatternsService } from './index_patterns'; import { ISearchSetup } from './search'; import { SearchService } from './search/search_service'; +import { ScriptsService } from './scripts'; +import { KqlTelemetryService } from './kql_telemetry'; +import { UsageCollectionSetup } from '../../usage_collection/server'; import { AutocompleteService } from './autocomplete'; export interface DataPluginSetup { search: ISearchSetup; } +export interface DataPluginSetupDependencies { + usageCollection?: UsageCollectionSetup; +} export class DataServerPlugin implements Plugin { private readonly searchService: SearchService; + private readonly scriptsService: ScriptsService; + private readonly kqlTelemetryService: KqlTelemetryService; private readonly autocompleteService = new AutocompleteService(); private readonly indexPatterns = new IndexPatternsService(); constructor(initializerContext: PluginInitializerContext) { this.searchService = new SearchService(initializerContext); + this.scriptsService = new ScriptsService(); + this.kqlTelemetryService = new KqlTelemetryService(initializerContext); } - public setup(core: CoreSetup) { + public setup(core: CoreSetup, { usageCollection }: DataPluginSetupDependencies) { this.indexPatterns.setup(core); + this.scriptsService.setup(core); this.autocompleteService.setup(core); + this.kqlTelemetryService.setup(core, { usageCollection }); return { search: this.searchService.setup(core), }; } + public start(core: CoreStart) {} public stop() {} } diff --git a/src/plugins/data/server/scripts/index.ts b/src/plugins/data/server/scripts/index.ts new file mode 100644 index 0000000000000..d4a3e70fdbf53 --- /dev/null +++ b/src/plugins/data/server/scripts/index.ts @@ -0,0 +1,20 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export { ScriptsService } from './scripts_service'; diff --git a/src/plugins/data/server/scripts/route.ts b/src/plugins/data/server/scripts/route.ts new file mode 100644 index 0000000000000..3eb77f09b25cd --- /dev/null +++ b/src/plugins/data/server/scripts/route.ts @@ -0,0 +1,31 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { IRouter } from 'kibana/server'; + +export function registerScriptsRoute(router: IRouter) { + router.get( + { path: '/api/kibana/scripts/languages', validate: false }, + async (context, request, response) => { + return response.ok({ + body: ['painless', 'expression'], + }); + } + ); +} diff --git a/src/plugins/data/server/scripts/scripts_service.ts b/src/plugins/data/server/scripts/scripts_service.ts new file mode 100644 index 0000000000000..9a3a20a64276d --- /dev/null +++ b/src/plugins/data/server/scripts/scripts_service.ts @@ -0,0 +1,29 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { CoreSetup, Plugin } from 'kibana/server'; +import { registerScriptsRoute } from './route'; + +export class ScriptsService implements Plugin { + public setup({ http }: CoreSetup) { + registerScriptsRoute(http.createRouter()); + } + + public start() {} +} From c75cd9de19bfd10377fd3b93ae7731f987544e58 Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Fri, 20 Dec 2019 19:06:21 +0100 Subject: [PATCH 07/14] NP Migration: Sample data (#52753) --- .i18nrc.json | 1 + src/legacy/server/kbn_server.d.ts | 2 + src/legacy/server/kbn_server.js | 4 - src/legacy/server/sample_data/README.md | 20 -- .../server/sample_data/routes/install.js | 184 ----------------- .../routes/lib/create_index_name.test.js | 30 --- .../sample_data/routes/lib/load_data.test.js | 59 ------ .../routes/lib/translate_timestamp.test.js | 105 ---------- src/legacy/server/sample_data/routes/list.js | 92 --------- .../server/sample_data/routes/uninstall.js | 80 -------- .../server/sample_data/sample_data_mixin.js | 146 -------------- src/plugins/home/README.md | 29 ++- src/plugins/home/kibana.json | 3 +- src/plugins/home/server/index.ts | 4 +- src/plugins/home/server/plugin.test.mocks.ts | 7 +- src/plugins/home/server/plugin.test.ts | 27 ++- src/plugins/home/server/plugin.ts | 26 ++- src/plugins/home/server/services/index.ts | 8 + .../data_sets/ecommerce/ecommerce.json.gz | Bin .../data_sets/ecommerce/field_mappings.ts} | 0 .../sample_data/data_sets/ecommerce/index.ts} | 23 ++- .../data_sets/ecommerce/saved_objects.ts} | 75 ++++--- .../data_sets/flights/field_mappings.ts} | 0 .../data_sets/flights/flights.json.gz | Bin .../sample_data/data_sets/flights/index.ts} | 23 ++- .../data_sets/flights/saved_objects.ts} | 105 ++++++---- .../services/sample_data/data_sets/index.ts} | 0 .../data_sets/logs/field_mappings.ts} | 0 .../sample_data/data_sets/logs/index.ts} | 23 ++- .../sample_data/data_sets/logs/logs.json.gz | Bin .../data_sets/logs/saved_objects.ts} | 69 ++++--- .../server/services/sample_data/index.ts} | 7 +- .../sample_data/lib/create_index_name.ts} | 4 +- .../services/sample_data/lib/load_data.ts} | 16 +- .../lib/sample_dataset_registry_types.ts | 92 +++++++++ .../sample_data/lib/sample_dataset_schema.ts} | 0 .../sample_data/lib/translate_timestamp.ts} | 29 ++- .../services/sample_data/routes/index.ts} | 1 - .../services/sample_data/routes/install.ts | 186 ++++++++++++++++++ .../services/sample_data/routes/list.ts | 92 +++++++++ .../services/sample_data/routes/uninstall.ts | 96 +++++++++ .../sample_data/sample_data_registry.mock.ts | 56 ++++++ .../sample_data/sample_data_registry.ts | 182 +++++++++++++++++ .../services}/sample_data/usage/collector.ts | 12 +- .../sample_data/usage/collector_fetch.test.ts | 0 .../sample_data/usage/collector_fetch.ts | 0 .../services}/sample_data/usage/index.ts | 0 .../services}/sample_data/usage/usage.ts | 31 ++- .../apis/general/prototype_pollution.ts | 4 +- test/api_integration/apis/home/sample_data.js | 2 +- x-pack/legacy/plugins/canvas/server/plugin.ts | 4 +- .../server/sample_data/load_sample_data.ts | 43 ++-- x-pack/legacy/plugins/canvas/server/shim.ts | 14 +- x-pack/legacy/plugins/infra/index.ts | 15 +- .../lib/adapters/framework/adapter_types.ts | 2 + .../infra/server/new_platform_plugin.ts | 14 ++ x-pack/legacy/plugins/maps/index.js | 4 +- x-pack/legacy/plugins/maps/server/plugin.js | 112 +++++------ x-pack/legacy/plugins/ml/index.ts | 4 +- .../plugins/ml/server/new_platform/plugin.ts | 11 +- .../translations/translations/ja-JP.json | 106 +++++----- .../translations/translations/zh-CN.json | 106 +++++----- 62 files changed, 1275 insertions(+), 1115 deletions(-) delete mode 100644 src/legacy/server/sample_data/README.md delete mode 100644 src/legacy/server/sample_data/routes/install.js delete mode 100644 src/legacy/server/sample_data/routes/lib/create_index_name.test.js delete mode 100644 src/legacy/server/sample_data/routes/lib/load_data.test.js delete mode 100644 src/legacy/server/sample_data/routes/lib/translate_timestamp.test.js delete mode 100644 src/legacy/server/sample_data/routes/list.js delete mode 100644 src/legacy/server/sample_data/routes/uninstall.js delete mode 100644 src/legacy/server/sample_data/sample_data_mixin.js rename src/{legacy/server => plugins/home/server/services}/sample_data/data_sets/ecommerce/ecommerce.json.gz (100%) rename src/{legacy/server/sample_data/data_sets/ecommerce/field_mappings.js => plugins/home/server/services/sample_data/data_sets/ecommerce/field_mappings.ts} (100%) rename src/{legacy/server/sample_data/data_sets/ecommerce/index.js => plugins/home/server/services/sample_data/data_sets/ecommerce/index.ts} (71%) rename src/{legacy/server/sample_data/data_sets/ecommerce/saved_objects.js => plugins/home/server/services/sample_data/data_sets/ecommerce/saved_objects.ts} (94%) rename src/{legacy/server/sample_data/data_sets/flights/field_mappings.js => plugins/home/server/services/sample_data/data_sets/flights/field_mappings.ts} (100%) rename src/{legacy/server => plugins/home/server/services}/sample_data/data_sets/flights/flights.json.gz (100%) rename src/{legacy/server/sample_data/data_sets/flights/index.js => plugins/home/server/services/sample_data/data_sets/flights/index.ts} (71%) rename src/{legacy/server/sample_data/data_sets/flights/saved_objects.js => plugins/home/server/services/sample_data/data_sets/flights/saved_objects.ts} (94%) rename src/{legacy/server/sample_data/data_sets/index.js => plugins/home/server/services/sample_data/data_sets/index.ts} (100%) rename src/{legacy/server/sample_data/data_sets/logs/field_mappings.js => plugins/home/server/services/sample_data/data_sets/logs/field_mappings.ts} (100%) rename src/{legacy/server/sample_data/data_sets/logs/index.js => plugins/home/server/services/sample_data/data_sets/logs/index.ts} (72%) rename src/{legacy/server => plugins/home/server/services}/sample_data/data_sets/logs/logs.json.gz (100%) rename src/{legacy/server/sample_data/data_sets/logs/saved_objects.js => plugins/home/server/services/sample_data/data_sets/logs/saved_objects.ts} (96%) rename src/{legacy/server/sample_data/index.js => plugins/home/server/services/sample_data/index.ts} (78%) rename src/{legacy/server/sample_data/routes/lib/create_index_name.js => plugins/home/server/services/sample_data/lib/create_index_name.ts} (92%) rename src/{legacy/server/sample_data/routes/lib/load_data.js => plugins/home/server/services/sample_data/lib/load_data.ts} (90%) create mode 100644 src/plugins/home/server/services/sample_data/lib/sample_dataset_registry_types.ts rename src/{legacy/server/sample_data/data_set_schema.js => plugins/home/server/services/sample_data/lib/sample_dataset_schema.ts} (100%) rename src/{legacy/server/sample_data/routes/lib/translate_timestamp.js => plugins/home/server/services/sample_data/lib/translate_timestamp.ts} (79%) rename src/{legacy/server/sample_data/routes/index.js => plugins/home/server/services/sample_data/routes/index.ts} (99%) create mode 100644 src/plugins/home/server/services/sample_data/routes/install.ts create mode 100644 src/plugins/home/server/services/sample_data/routes/list.ts create mode 100644 src/plugins/home/server/services/sample_data/routes/uninstall.ts create mode 100644 src/plugins/home/server/services/sample_data/sample_data_registry.mock.ts create mode 100644 src/plugins/home/server/services/sample_data/sample_data_registry.ts rename src/{legacy/server => plugins/home/server/services}/sample_data/usage/collector.ts (75%) rename src/{legacy/server => plugins/home/server/services}/sample_data/usage/collector_fetch.test.ts (100%) rename src/{legacy/server => plugins/home/server/services}/sample_data/usage/collector_fetch.ts (100%) rename src/{legacy/server => plugins/home/server/services}/sample_data/usage/index.ts (100%) rename src/{legacy/server => plugins/home/server/services}/sample_data/usage/usage.ts (61%) diff --git a/.i18nrc.json b/.i18nrc.json index 23f3d6ee33829..4bc0f773ee8b5 100644 --- a/.i18nrc.json +++ b/.i18nrc.json @@ -11,6 +11,7 @@ "embeddableApi": "src/plugins/embeddable", "embeddableExamples": "examples/embeddable_examples", "share": "src/plugins/share", + "home": "src/plugins/home", "esUi": "src/plugins/es_ui_shared", "devTools": "src/plugins/dev_tools", "expressions": "src/plugins/expressions", diff --git a/src/legacy/server/kbn_server.d.ts b/src/legacy/server/kbn_server.d.ts index 9a18f7e8a3003..1cce1e1e6aeb6 100644 --- a/src/legacy/server/kbn_server.d.ts +++ b/src/legacy/server/kbn_server.d.ts @@ -44,6 +44,7 @@ import { UsageCollectionSetup } from '../../plugins/usage_collection/server'; import { IndexPatternsServiceFactory } from './index_patterns'; import { Capabilities } from '../../core/server'; import { UiSettingsServiceFactoryOptions } from '../../legacy/ui/ui_settings/ui_settings_service_factory'; +import { HomeServerPluginSetup } from '../../plugins/home/server'; // lot of legacy code was assuming this type only had these two methods export type KibanaConfig = Pick; @@ -99,6 +100,7 @@ type KbnMixinFunc = (kbnServer: KbnServer, server: Server, config: any) => Promi export interface PluginsSetup { usageCollection: UsageCollectionSetup; + home: HomeServerPluginSetup; [key: string]: object; } diff --git a/src/legacy/server/kbn_server.js b/src/legacy/server/kbn_server.js index ffa16fb0a0ad1..98484a0de6f65 100644 --- a/src/legacy/server/kbn_server.js +++ b/src/legacy/server/kbn_server.js @@ -35,7 +35,6 @@ import optimizeMixin from '../../optimize'; import * as Plugins from './plugins'; import { indexPatternsMixin } from './index_patterns'; import { savedObjectsMixin } from './saved_objects/saved_objects_mixin'; -import { sampleDataMixin } from './sample_data'; import { capabilitiesMixin } from './capabilities'; import { urlShorteningMixin } from './url_shortening'; import { serverExtensionsMixin } from './server_extensions'; @@ -112,9 +111,6 @@ export default class KbnServer { // setup capabilities routes capabilitiesMixin, - // setup routes for installing/uninstalling sample data sets - sampleDataMixin, - // setup routes for short urls urlShorteningMixin, diff --git a/src/legacy/server/sample_data/README.md b/src/legacy/server/sample_data/README.md deleted file mode 100644 index 9e93504348922..0000000000000 --- a/src/legacy/server/sample_data/README.md +++ /dev/null @@ -1,20 +0,0 @@ -### What happens when a user installs a sample data set? -1) Kibana deletes existing Elastic search indicies for the sample data set if they exist from previous installs. -2) Kibana creates Elasticsearch indicies with the provided field mappings. -3) Kibana uses bulk insert to ingest the new-line delimited json into the Elasticsearch index. Kibana migrates timestamps provided in new-line delimited json to the current time frame for any date field defined in `timeFields` -4) Kibana will install all saved objects for sample data set. This will override any saved objects previouslly installed for sample data set. - -Elasticsearch index names are prefixed with `kibana_sample_data_`. For more details see [createIndexName](/src/legacy/server/sample_data/routes/lib/create_index_name.js) - -Sample data sets typically provide data that spans 5 weeks from the past and 5 weeks into the future so users see data relative to `now` for a few weeks after installing sample data sets. - -### Adding new sample data sets -Use [existing sample data sets](/src/legacy/server/sample_data/data_sets) as examples. -To avoid bloating the Kibana distribution, keep data set size to a minimum. - -Follow the steps below to add new Sample data sets to Kibana. -1) Create new-line delimited json containing sample data. -2) Create file with Elasticsearch field mappings for sample data indices. -3) Create Kibana saved objects for sample data including index-patterns, visualizations, and dashboards. The best way to extract the saved objects is from the Kibana management -> saved objects [export UI](https://www.elastic.co/guide/en/kibana/current/managing-saved-objects.html#_export) -4) Define sample data spec conforming to [Data Set Schema](/src/legacy/server/sample_data/data_set_schema.js). -5) Register sample data by calling `server.registerSampleDataset(yourSpecProvider)` where `yourSpecProvider` is a function that returns an object containing your sample data spec from step 4. diff --git a/src/legacy/server/sample_data/routes/install.js b/src/legacy/server/sample_data/routes/install.js deleted file mode 100644 index 42635618e1ad6..0000000000000 --- a/src/legacy/server/sample_data/routes/install.js +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import Boom from 'boom'; -import Joi from 'joi'; -import { usage } from '../usage'; -import { loadData } from './lib/load_data'; -import { createIndexName } from './lib/create_index_name'; -import { - dateToIso8601IgnoringTime, - translateTimeRelativeToDifference, - translateTimeRelativeToWeek, -} from './lib/translate_timestamp'; - -function insertDataIntoIndex( - dataIndexConfig, - index, - nowReference, - request, - server, - callWithRequest -) { - const bulkInsert = async docs => { - function updateTimestamps(doc) { - dataIndexConfig.timeFields.forEach(timeFieldName => { - if (doc[timeFieldName]) { - doc[timeFieldName] = dataIndexConfig.preserveDayOfWeekTimeOfDay - ? translateTimeRelativeToWeek( - doc[timeFieldName], - dataIndexConfig.currentTimeMarker, - nowReference - ) - : translateTimeRelativeToDifference( - doc[timeFieldName], - dataIndexConfig.currentTimeMarker, - nowReference - ); - } - }); - return doc; - } - - const insertCmd = { index: { _index: index } }; - - const bulk = []; - docs.forEach(doc => { - bulk.push(insertCmd); - bulk.push(updateTimestamps(doc)); - }); - const resp = await callWithRequest(request, 'bulk', { body: bulk }); - if (resp.errors) { - server.log( - ['warning'], - `sample_data install errors while bulk inserting. Elasticsearch response: ${JSON.stringify( - resp, - null, - '' - )}` - ); - return Promise.reject( - new Error(`Unable to load sample data into index "${index}", see kibana logs for details`) - ); - } - }; - - return loadData(dataIndexConfig.dataPath, bulkInsert); -} - -export const createInstallRoute = () => ({ - path: '/api/sample_data/{id}', - method: 'POST', - config: { - validate: { - query: Joi.object().keys({ now: Joi.date().iso() }), - params: Joi.object() - .keys({ id: Joi.string().required() }) - .required(), - }, - handler: async (request, h) => { - const { server, params, query } = request; - - const sampleDataset = server.getSampleDatasets().find(({ id }) => id === params.id); - if (!sampleDataset) { - return h.response().code(404); - } - - const { callWithRequest } = server.plugins.elasticsearch.getCluster('data'); - - const now = query.now ? query.now : new Date(); - const nowReference = dateToIso8601IgnoringTime(now); - - const counts = {}; - for (let i = 0; i < sampleDataset.dataIndices.length; i++) { - const dataIndexConfig = sampleDataset.dataIndices[i]; - const index = createIndexName(sampleDataset.id, dataIndexConfig.id); - - // clean up any old installation of dataset - try { - await callWithRequest(request, 'indices.delete', { index }); - } catch (err) { - // ignore delete errors - } - - try { - const createIndexParams = { - index: index, - body: { - settings: { index: { number_of_shards: 1, auto_expand_replicas: '0-1' } }, - mappings: { properties: dataIndexConfig.fields }, - }, - }; - await callWithRequest(request, 'indices.create', createIndexParams); - } catch (err) { - const errMsg = `Unable to create sample data index "${index}", error: ${err.message}`; - server.log(['warning'], errMsg); - return h.response(errMsg).code(err.status); - } - - try { - const count = await insertDataIntoIndex( - dataIndexConfig, - index, - nowReference, - request, - server, - callWithRequest - ); - counts[index] = count; - } catch (err) { - server.log(['warning'], `sample_data install errors while loading data. Error: ${err}`); - return h.response(err.message).code(500); - } - } - - let createResults; - try { - createResults = await request - .getSavedObjectsClient() - .bulkCreate(sampleDataset.savedObjects, { overwrite: true }); - } catch (err) { - server.log(['warning'], `bulkCreate failed, error: ${err.message}`); - return Boom.badImplementation( - `Unable to load kibana saved objects, see kibana logs for details` - ); - } - const errors = createResults.saved_objects.filter(savedObjectCreateResult => { - return Boolean(savedObjectCreateResult.error); - }); - if (errors.length > 0) { - server.log( - ['warning'], - `sample_data install errors while loading saved objects. Errors: ${errors.join(',')}` - ); - return h - .response(`Unable to load kibana saved objects, see kibana logs for details`) - .code(403); - } - - // track the usage operation in a non-blocking way - usage(request).addInstall(params.id); - - return h.response({ - elasticsearchIndicesCreated: counts, - kibanaSavedObjectsLoaded: sampleDataset.savedObjects.length, - }); - }, - }, -}); diff --git a/src/legacy/server/sample_data/routes/lib/create_index_name.test.js b/src/legacy/server/sample_data/routes/lib/create_index_name.test.js deleted file mode 100644 index e285dc0120ac8..0000000000000 --- a/src/legacy/server/sample_data/routes/lib/create_index_name.test.js +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import { createIndexName } from './create_index_name'; - -test('should include sampleDataSetId and dataIndexId in elasticsearch index name', async () => { - expect(createIndexName('mySampleDataSetId', 'myDataIndexId')).toBe( - 'kibana_sample_data_mySampleDataSetId_myDataIndexId' - ); -}); - -test('should only include sampleDataSetId when sampleDataSetId and dataIndexId are identical', async () => { - expect(createIndexName('flights', 'flights')).toBe('kibana_sample_data_flights'); -}); diff --git a/src/legacy/server/sample_data/routes/lib/load_data.test.js b/src/legacy/server/sample_data/routes/lib/load_data.test.js deleted file mode 100644 index 0af07e14ff965..0000000000000 --- a/src/legacy/server/sample_data/routes/lib/load_data.test.js +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import { loadData } from './load_data'; - -test('load flight data', async () => { - let myDocsCount = 0; - const bulkInsertMock = docs => { - myDocsCount += docs.length; - }; - const count = await loadData( - './src/legacy/server/sample_data/data_sets/flights/flights.json.gz', - bulkInsertMock - ); - expect(myDocsCount).toBe(13059); - expect(count).toBe(13059); -}); - -test('load log data', async () => { - let myDocsCount = 0; - const bulkInsertMock = docs => { - myDocsCount += docs.length; - }; - const count = await loadData( - './src/legacy/server/sample_data/data_sets/logs/logs.json.gz', - bulkInsertMock - ); - expect(myDocsCount).toBe(14074); - expect(count).toBe(14074); -}); - -test('load ecommerce data', async () => { - let myDocsCount = 0; - const bulkInsertMock = docs => { - myDocsCount += docs.length; - }; - const count = await loadData( - './src/legacy/server/sample_data/data_sets/ecommerce/ecommerce.json.gz', - bulkInsertMock - ); - expect(myDocsCount).toBe(4675); - expect(count).toBe(4675); -}); diff --git a/src/legacy/server/sample_data/routes/lib/translate_timestamp.test.js b/src/legacy/server/sample_data/routes/lib/translate_timestamp.test.js deleted file mode 100644 index e03d4870ad064..0000000000000 --- a/src/legacy/server/sample_data/routes/lib/translate_timestamp.test.js +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import { translateTimeRelativeToWeek } from './translate_timestamp'; - -describe('translateTimeRelativeToWeek', () => { - const sourceReference = '2018-01-02T00:00:00'; //Tuesday - const targetReference = '2018-04-25T18:24:58.650'; // Wednesday - - describe('2 weeks before', () => { - test('should properly adjust timestamp when day is before targetReference day of week', () => { - const source = '2017-12-18T23:50:00'; // Monday, -2 week relative to sourceReference - const timestamp = translateTimeRelativeToWeek(source, sourceReference, targetReference); - expect(timestamp).toBe('2018-04-09T23:50:00'); // Monday 2 week before targetReference week - }); - - test('should properly adjust timestamp when day is same as targetReference day of week', () => { - const source = '2017-12-20T23:50:00'; // Wednesday, -2 week relative to sourceReference - const timestamp = translateTimeRelativeToWeek(source, sourceReference, targetReference); - expect(timestamp).toBe('2018-04-11T23:50:00'); // Wednesday 2 week before targetReference week - }); - - test('should properly adjust timestamp when day is after targetReference day of week', () => { - const source = '2017-12-22T16:16:50'; // Friday, -2 week relative to sourceReference - const timestamp = translateTimeRelativeToWeek(source, sourceReference, targetReference); - expect(timestamp).toBe('2018-04-13T16:16:50'); // Friday 2 week before targetReference week - }); - }); - - describe('week before', () => { - test('should properly adjust timestamp when day is before targetReference day of week', () => { - const source = '2017-12-25T23:50:00'; // Monday, -1 week relative to sourceReference - const timestamp = translateTimeRelativeToWeek(source, sourceReference, targetReference); - expect(timestamp).toBe('2018-04-16T23:50:00'); // Monday 1 week before targetReference week - }); - - test('should properly adjust timestamp when day is same as targetReference day of week', () => { - const source = '2017-12-27T23:50:00'; // Wednesday, -1 week relative to sourceReference - const timestamp = translateTimeRelativeToWeek(source, sourceReference, targetReference); - expect(timestamp).toBe('2018-04-18T23:50:00'); // Wednesday 1 week before targetReference week - }); - - test('should properly adjust timestamp when day is after targetReference day of week', () => { - const source = '2017-12-29T16:16:50'; // Friday, -1 week relative to sourceReference - const timestamp = translateTimeRelativeToWeek(source, sourceReference, targetReference); - expect(timestamp).toBe('2018-04-20T16:16:50'); // Friday 1 week before targetReference week - }); - }); - - describe('same week', () => { - test('should properly adjust timestamp when day is before targetReference day of week', () => { - const source = '2018-01-01T23:50:00'; // Monday, same week relative to sourceReference - const timestamp = translateTimeRelativeToWeek(source, sourceReference, targetReference); - expect(timestamp).toBe('2018-04-23T23:50:00'); // Monday same week as targetReference - }); - - test('should properly adjust timestamp when day is same as targetReference day of week', () => { - const source = '2018-01-03T23:50:00'; // Wednesday, same week relative to sourceReference - const timestamp = translateTimeRelativeToWeek(source, sourceReference, targetReference); - expect(timestamp).toBe('2018-04-25T23:50:00'); // Wednesday same week as targetReference - }); - - test('should properly adjust timestamp when day is after targetReference day of week', () => { - const source = '2018-01-05T16:16:50'; // Friday, same week relative to sourceReference - const timestamp = translateTimeRelativeToWeek(source, sourceReference, targetReference); - expect(timestamp).toBe('2018-04-27T16:16:50'); // Friday same week as targetReference - }); - }); - - describe('week after', () => { - test('should properly adjust timestamp when day is before targetReference day of week', () => { - const source = '2018-01-08T23:50:00'; // Monday, 1 week after relative to sourceReference - const timestamp = translateTimeRelativeToWeek(source, sourceReference, targetReference); - expect(timestamp).toBe('2018-04-30T23:50:00'); // Monday 1 week after targetReference week - }); - - test('should properly adjust timestamp when day is same as targetReference day of week', () => { - const source = '2018-01-10T23:50:00'; // Wednesday, same week relative to sourceReference - const timestamp = translateTimeRelativeToWeek(source, sourceReference, targetReference); - expect(timestamp).toBe('2018-05-02T23:50:00'); // Wednesday 1 week after targetReference week - }); - - test('should properly adjust timestamp when day is after targetReference day of week', () => { - const source = '2018-01-12T16:16:50'; // Friday, same week relative to sourceReference - const timestamp = translateTimeRelativeToWeek(source, sourceReference, targetReference); - expect(timestamp).toBe('2018-05-04T16:16:50'); // Friday 1 week after targetReference week - }); - }); -}); diff --git a/src/legacy/server/sample_data/routes/list.js b/src/legacy/server/sample_data/routes/list.js deleted file mode 100644 index 65370e6da9fb1..0000000000000 --- a/src/legacy/server/sample_data/routes/list.js +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import _ from 'lodash'; -import { createIndexName } from './lib/create_index_name'; - -const NOT_INSTALLED = 'not_installed'; -const INSTALLED = 'installed'; -const UNKNOWN = 'unknown'; - -export const createListRoute = () => ({ - path: '/api/sample_data', - method: 'GET', - config: { - handler: async request => { - const { callWithRequest } = request.server.plugins.elasticsearch.getCluster('data'); - - const sampleDatasets = request.server.getSampleDatasets().map(sampleDataset => { - return { - id: sampleDataset.id, - name: sampleDataset.name, - description: sampleDataset.description, - previewImagePath: sampleDataset.previewImagePath, - darkPreviewImagePath: sampleDataset.darkPreviewImagePath, - overviewDashboard: sampleDataset.overviewDashboard, - appLinks: sampleDataset.appLinks, - defaultIndex: sampleDataset.defaultIndex, - dataIndices: sampleDataset.dataIndices.map(({ id }) => ({ id })), - }; - }); - - const isInstalledPromises = sampleDatasets.map(async sampleDataset => { - for (let i = 0; i < sampleDataset.dataIndices.length; i++) { - const dataIndexConfig = sampleDataset.dataIndices[i]; - const index = createIndexName(sampleDataset.id, dataIndexConfig.id); - try { - const indexExists = await callWithRequest(request, 'indices.exists', { index: index }); - if (!indexExists) { - sampleDataset.status = NOT_INSTALLED; - return; - } - - const { count } = await callWithRequest(request, 'count', { index: index }); - if (count === 0) { - sampleDataset.status = NOT_INSTALLED; - return; - } - } catch (err) { - sampleDataset.status = UNKNOWN; - sampleDataset.statusMsg = err.message; - return; - } - } - - try { - await request.getSavedObjectsClient().get('dashboard', sampleDataset.overviewDashboard); - } catch (err) { - // savedObjectClient.get() throws an boom error when object is not found. - if (_.get(err, 'output.statusCode') === 404) { - sampleDataset.status = NOT_INSTALLED; - return; - } - - sampleDataset.status = UNKNOWN; - sampleDataset.statusMsg = err.message; - return; - } - - sampleDataset.status = INSTALLED; - }); - - await Promise.all(isInstalledPromises); - return sampleDatasets; - }, - }, -}); diff --git a/src/legacy/server/sample_data/routes/uninstall.js b/src/legacy/server/sample_data/routes/uninstall.js deleted file mode 100644 index 6177c0379cd68..0000000000000 --- a/src/legacy/server/sample_data/routes/uninstall.js +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import _ from 'lodash'; -import Joi from 'joi'; -import { usage } from '../usage'; -import { createIndexName } from './lib/create_index_name'; - -export const createUninstallRoute = () => ({ - path: '/api/sample_data/{id}', - method: 'DELETE', - config: { - validate: { - params: Joi.object() - .keys({ - id: Joi.string().required(), - }) - .required(), - }, - handler: async (request, h) => { - const { server, params } = request; - const sampleDataset = server.getSampleDatasets().find(({ id }) => id === params.id); - - if (!sampleDataset) { - return h.response().code(404); - } - - const { callWithRequest } = server.plugins.elasticsearch.getCluster('data'); - - for (let i = 0; i < sampleDataset.dataIndices.length; i++) { - const dataIndexConfig = sampleDataset.dataIndices[i]; - const index = createIndexName(sampleDataset.id, dataIndexConfig.id); - - try { - await callWithRequest(request, 'indices.delete', { index: index }); - } catch (err) { - return h - .response(`Unable to delete sample data index "${index}", error: ${err.message}`) - .code(err.status); - } - } - - const deletePromises = sampleDataset.savedObjects.map(({ type, id }) => - request.getSavedObjectsClient().delete(type, id) - ); - - try { - await Promise.all(deletePromises); - } catch (err) { - // ignore 404s since users could have deleted some of the saved objects via the UI - if (_.get(err, 'output.statusCode') !== 404) { - return h - .response(`Unable to delete sample dataset saved objects, error: ${err.message}`) - .code(403); - } - } - - // track the usage operation in a non-blocking way - usage(request).addUninstall(params.id); - - return {}; - }, - }, -}); diff --git a/src/legacy/server/sample_data/sample_data_mixin.js b/src/legacy/server/sample_data/sample_data_mixin.js deleted file mode 100644 index 338d6fd8cb5da..0000000000000 --- a/src/legacy/server/sample_data/sample_data_mixin.js +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import Joi from 'joi'; -import { sampleDataSchema } from './data_set_schema'; -import { createListRoute, createInstallRoute, createUninstallRoute } from './routes'; -import { flightsSpecProvider, logsSpecProvider, ecommerceSpecProvider } from './data_sets'; -import { makeSampleDataUsageCollector } from './usage'; - -export function sampleDataMixin(kbnServer, server) { - server.route(createListRoute()); - server.route(createInstallRoute()); - server.route(createUninstallRoute()); - - const sampleDatasets = []; - - server.decorate('server', 'getSampleDatasets', () => { - return sampleDatasets; - }); - - server.decorate('server', 'registerSampleDataset', specProvider => { - const { error, value } = Joi.validate(specProvider(server), sampleDataSchema); - - if (error) { - throw new Error(`Unable to register sample dataset spec because it's invalid. ${error}`); - } - - const defaultIndexSavedObjectJson = value.savedObjects.find(savedObjectJson => { - return savedObjectJson.type === 'index-pattern' && savedObjectJson.id === value.defaultIndex; - }); - if (!defaultIndexSavedObjectJson) { - throw new Error( - `Unable to register sample dataset spec, defaultIndex: "${value.defaultIndex}" does not exist in savedObjects list.` - ); - } - - const dashboardSavedObjectJson = value.savedObjects.find(savedObjectJson => { - return savedObjectJson.type === 'dashboard' && savedObjectJson.id === value.overviewDashboard; - }); - if (!dashboardSavedObjectJson) { - throw new Error( - `Unable to register sample dataset spec, overviewDashboard: "${value.overviewDashboard}" does not exist in savedObjects list.` - ); - } - - sampleDatasets.push(value); - }); - - server.decorate('server', 'addSavedObjectsToSampleDataset', (id, savedObjects) => { - const sampleDataset = sampleDatasets.find(sampleDataset => { - return sampleDataset.id === id; - }); - - if (!sampleDataset) { - throw new Error(`Unable to find sample dataset with id: ${id}`); - } - - sampleDataset.savedObjects = sampleDataset.savedObjects.concat(savedObjects); - }); - - server.decorate('server', 'addAppLinksToSampleDataset', (id, appLinks) => { - const sampleDataset = sampleDatasets.find(sampleDataset => { - return sampleDataset.id === id; - }); - - if (!sampleDataset) { - throw new Error(`Unable to find sample dataset with id: ${id}`); - } - - sampleDataset.appLinks = sampleDataset.appLinks.concat(appLinks); - }); - - server.decorate( - 'server', - 'replacePanelInSampleDatasetDashboard', - ({ - sampleDataId, - dashboardId, - oldEmbeddableId, - embeddableId, - embeddableType, - embeddableConfig = {}, - }) => { - const sampleDataset = sampleDatasets.find(sampleDataset => { - return sampleDataset.id === sampleDataId; - }); - if (!sampleDataset) { - throw new Error(`Unable to find sample dataset with id: ${sampleDataId}`); - } - - const dashboard = sampleDataset.savedObjects.find(savedObject => { - return savedObject.id === dashboardId && savedObject.type === 'dashboard'; - }); - if (!dashboard) { - throw new Error(`Unable to find dashboard with id: ${dashboardId}`); - } - - try { - const reference = dashboard.references.find(reference => { - return reference.id === oldEmbeddableId; - }); - if (!reference) { - throw new Error(`Unable to find reference for embeddable: ${oldEmbeddableId}`); - } - reference.type = embeddableType; - reference.id = embeddableId; - - const panels = JSON.parse(dashboard.attributes.panelsJSON); - const panel = panels.find(panel => { - return panel.panelRefName === reference.name; - }); - if (!panel) { - throw new Error(`Unable to find panel for reference: ${reference.name}`); - } - panel.embeddableConfig = embeddableConfig; - dashboard.attributes.panelsJSON = JSON.stringify(panels); - } catch (error) { - throw new Error( - `Unable to replace panel with embeddable ${oldEmbeddableId}, error: ${error}` - ); - } - } - ); - - server.registerSampleDataset(flightsSpecProvider); - server.registerSampleDataset(logsSpecProvider); - server.registerSampleDataset(ecommerceSpecProvider); - - makeSampleDataUsageCollector(server); -} diff --git a/src/plugins/home/README.md b/src/plugins/home/README.md index 74e12a799b1b7..1ce0ae0bf44d3 100644 --- a/src/plugins/home/README.md +++ b/src/plugins/home/README.md @@ -1,13 +1,13 @@ # home plugin Moves the legacy `ui/registry/feature_catalogue` module for registering "features" that should be shown in the home page's feature catalogue to a service within a "home" plugin. The feature catalogue refered to here should not be confused with the "feature" plugin for registering features used to derive UI capabilities for feature controls. -# Feature catalogue (public service) +## Feature catalogue (public service) Replaces the legacy `ui/registry/feature_catalogue` module for registering "features" that should be showed in the home page's feature catalogue. This should not be confused with the "feature" plugin for registering features used to derive UI capabilities for feature controls. -## Example registration +### Example registration ```ts // For legacy plugins @@ -27,3 +27,28 @@ class MyPlugin { ``` Note that the old module supported providing a Angular DI function to receive Angular dependencies. This is no longer supported as we migrate away from Angular and will be removed in 8.0. + +## Sample data + +Replaces the sample data mixin putting functions on the global `server` object. + +### What happens when a user installs a sample data set? +1) Kibana deletes existing Elastic search indicies for the sample data set if they exist from previous installs. +2) Kibana creates Elasticsearch indicies with the provided field mappings. +3) Kibana uses bulk insert to ingest the new-line delimited json into the Elasticsearch index. Kibana migrates timestamps provided in new-line delimited json to the current time frame for any date field defined in `timeFields` +4) Kibana will install all saved objects for sample data set. This will override any saved objects previouslly installed for sample data set. + +Elasticsearch index names are prefixed with `kibana_sample_data_`. For more details see [createIndexName](/src/plugins/home/server/services/sample_data/lib/create_index_name.js) + +Sample data sets typically provide data that spans 5 weeks from the past and 5 weeks into the future so users see data relative to `now` for a few weeks after installing sample data sets. + +### Adding new sample data sets +Use [existing sample data sets](/src/plugins/home/server/services/sample_data/data_sets) as examples. +To avoid bloating the Kibana distribution, keep data set size to a minimum. + +Follow the steps below to add new Sample data sets to Kibana. +1) Create new-line delimited json containing sample data. +2) Create file with Elasticsearch field mappings for sample data indices. +3) Create Kibana saved objects for sample data including index-patterns, visualizations, and dashboards. The best way to extract the saved objects is from the Kibana management -> saved objects [export UI](https://www.elastic.co/guide/en/kibana/current/managing-saved-objects.html#_export) +4) Define sample data spec conforming to [Data Set Schema](/src/plugins/home/server/services/sample_data/lib/sample_dataset_registry_types.ts). +5) Register sample data by calling `plguins.home.sampleData.registerSampleDataset(yourSpecProvider)` in your `setup` method where `yourSpecProvider` is a function that returns an object containing your sample data spec from step 4. diff --git a/src/plugins/home/kibana.json b/src/plugins/home/kibana.json index a5c65e3efa597..31e7ebc138dcb 100644 --- a/src/plugins/home/kibana.json +++ b/src/plugins/home/kibana.json @@ -2,5 +2,6 @@ "id": "home", "version": "kibana", "server": true, - "ui": true + "ui": true, + "optionalPlugins": ["usage_collection"] } diff --git a/src/plugins/home/server/index.ts b/src/plugins/home/server/index.ts index be4e20ab63d3c..ed336f4a41d6e 100644 --- a/src/plugins/home/server/index.ts +++ b/src/plugins/home/server/index.ts @@ -19,6 +19,8 @@ export { HomeServerPluginSetup, HomeServerPluginStart } from './plugin'; export { TutorialProvider } from './services'; +export { SampleDatasetProvider, SampleDataRegistrySetup } from './services'; +import { PluginInitializerContext } from 'src/core/server'; import { HomeServerPlugin } from './plugin'; -export const plugin = () => new HomeServerPlugin(); +export const plugin = (initContext: PluginInitializerContext) => new HomeServerPlugin(initContext); diff --git a/src/plugins/home/server/plugin.test.mocks.ts b/src/plugins/home/server/plugin.test.mocks.ts index a5640de579b15..ac11948c040d0 100644 --- a/src/plugins/home/server/plugin.test.mocks.ts +++ b/src/plugins/home/server/plugin.test.mocks.ts @@ -17,8 +17,11 @@ * under the License. */ import { tutorialsRegistryMock } from './services/tutorials/tutorials_registry.mock'; +import { sampleDataRegistryMock } from './services/sample_data/sample_data_registry.mock'; -export const registryMock = tutorialsRegistryMock.create(); +export const registryForTutorialsMock = tutorialsRegistryMock.create(); +export const registryForSampleDataMock = sampleDataRegistryMock.create(); jest.doMock('./services', () => ({ - TutorialsRegistry: jest.fn(() => registryMock), + TutorialsRegistry: jest.fn(() => registryForTutorialsMock), + SampleDataRegistry: jest.fn(() => registryForSampleDataMock), })); diff --git a/src/plugins/home/server/plugin.test.ts b/src/plugins/home/server/plugin.test.ts index eec6501436bf4..33d907315e512 100644 --- a/src/plugins/home/server/plugin.test.ts +++ b/src/plugins/home/server/plugin.test.ts @@ -17,7 +17,7 @@ * under the License. */ -import { registryMock } from './plugin.test.mocks'; +import { registryForTutorialsMock, registryForSampleDataMock } from './plugin.test.mocks'; import { HomeServerPlugin } from './plugin'; import { coreMock } from '../../../core/server/mocks'; import { CoreSetup } from '../../../core/server'; @@ -26,26 +26,41 @@ type MockedKeys = { [P in keyof T]: jest.Mocked }; describe('HomeServerPlugin', () => { beforeEach(() => { - registryMock.setup.mockClear(); - registryMock.start.mockClear(); + registryForTutorialsMock.setup.mockClear(); + registryForTutorialsMock.start.mockClear(); + registryForSampleDataMock.setup.mockClear(); + registryForSampleDataMock.start.mockClear(); }); describe('setup', () => { const mockCoreSetup: MockedKeys = coreMock.createSetup(); + const initContext = coreMock.createPluginInitializerContext(); - test('wires up and returns registerTutorial and addScopedTutorialContextFactory', () => { - const setup = new HomeServerPlugin().setup(mockCoreSetup); + test('wires up tutorials provider service and returns registerTutorial and addScopedTutorialContextFactory', () => { + const setup = new HomeServerPlugin(initContext).setup(mockCoreSetup, {}); expect(setup).toHaveProperty('tutorials'); expect(setup.tutorials).toHaveProperty('registerTutorial'); expect(setup.tutorials).toHaveProperty('addScopedTutorialContextFactory'); }); + + test('wires up sample data provider service and returns registerTutorial and addScopedTutorialContextFactory', () => { + const setup = new HomeServerPlugin(initContext).setup(mockCoreSetup, {}); + expect(setup).toHaveProperty('sampleData'); + expect(setup.sampleData).toHaveProperty('registerSampleDataset'); + expect(setup.sampleData).toHaveProperty('getSampleDatasets'); + expect(setup.sampleData).toHaveProperty('addSavedObjectsToSampleDataset'); + expect(setup.sampleData).toHaveProperty('addAppLinksToSampleDataset'); + expect(setup.sampleData).toHaveProperty('replacePanelInSampleDatasetDashboard'); + }); }); describe('start', () => { + const initContext = coreMock.createPluginInitializerContext(); test('is defined', () => { - const start = new HomeServerPlugin().start(); + const start = new HomeServerPlugin(initContext).start(); expect(start).toBeDefined(); expect(start).toHaveProperty('tutorials'); + expect(start).toHaveProperty('sampleData'); }); }); }); diff --git a/src/plugins/home/server/plugin.ts b/src/plugins/home/server/plugin.ts index 89dda8205ce02..23c236764cddc 100644 --- a/src/plugins/home/server/plugin.ts +++ b/src/plugins/home/server/plugin.ts @@ -16,21 +16,37 @@ * specific language governing permissions and limitations * under the License. */ -import { CoreSetup, Plugin } from 'src/core/server'; -import { TutorialsRegistry, TutorialsRegistrySetup, TutorialsRegistryStart } from './services'; +import { CoreSetup, Plugin, PluginInitializerContext } from 'src/core/server'; +import { + TutorialsRegistry, + TutorialsRegistrySetup, + TutorialsRegistryStart, + SampleDataRegistry, + SampleDataRegistrySetup, + SampleDataRegistryStart, +} from './services'; +import { UsageCollectionSetup } from '../../usage_collection/server'; + +interface HomeServerPluginSetupDependencies { + usage_collection?: UsageCollectionSetup; +} export class HomeServerPlugin implements Plugin { + constructor(private readonly initContext: PluginInitializerContext) {} private readonly tutorialsRegistry = new TutorialsRegistry(); + private readonly sampleDataRegistry = new SampleDataRegistry(this.initContext); - public setup(core: CoreSetup) { + public setup(core: CoreSetup, plugins: HomeServerPluginSetupDependencies): HomeServerPluginSetup { return { tutorials: { ...this.tutorialsRegistry.setup(core) }, + sampleData: { ...this.sampleDataRegistry.setup(core, plugins.usage_collection) }, }; } - public start() { + public start(): HomeServerPluginStart { return { tutorials: { ...this.tutorialsRegistry.start() }, + sampleData: { ...this.sampleDataRegistry.start() }, }; } } @@ -38,9 +54,11 @@ export class HomeServerPlugin implements Plugin [ +export const getSavedObjects = (): SavedObject[] => [ { id: '37cc8650-b882-11e8-a6d9-e546fe2bba5f', type: 'visualization', updated_at: '2018-10-01T15:13:03.270Z', - version: 1, + version: '1', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.ecommerceSpec.salesByCategoryTitle', { + title: i18n.translate('home.sampleData.ecommerceSpec.salesByCategoryTitle', { defaultMessage: '[eCommerce] Sales by Category', }), visState: @@ -40,15 +44,16 @@ export const getSavedObjects = () => [ '{"index":"ff959d40-b880-11e8-a6d9-e546fe2bba5f","query":{"query":"","language":"kuery"},"filter":[]}', }, }, + references: [], }, { id: 'ed8436b0-b88b-11e8-a6d9-e546fe2bba5f', type: 'visualization', updated_at: '2018-10-01T15:13:03.270Z', - version: 1, + version: '1', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.ecommerceSpec.salesByGenderTitle', { + title: i18n.translate('home.sampleData.ecommerceSpec.salesByGenderTitle', { defaultMessage: '[eCommerce] Sales by Gender', }), visState: @@ -61,15 +66,16 @@ export const getSavedObjects = () => [ '{"index":"ff959d40-b880-11e8-a6d9-e546fe2bba5f","query":{"query":"","language":"kuery"},"filter":[]}', }, }, + references: [], }, { id: '09ffee60-b88c-11e8-a6d9-e546fe2bba5f', type: 'visualization', updated_at: '2018-10-01T15:13:03.270Z', - version: 1, + version: '1', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.ecommerceSpec.markdownTitle', { + title: i18n.translate('home.sampleData.ecommerceSpec.markdownTitle', { defaultMessage: '[eCommerce] Markdown', }), visState: @@ -81,15 +87,16 @@ export const getSavedObjects = () => [ searchSourceJSON: '{"query":{"query":"","language":"kuery"},"filter":[]}', }, }, + references: [], }, { id: '1c389590-b88d-11e8-a6d9-e546fe2bba5f', type: 'visualization', updated_at: '2018-10-01T15:13:03.270Z', - version: 1, + version: '1', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.ecommerceSpec.controlsTitle', { + title: i18n.translate('home.sampleData.ecommerceSpec.controlsTitle', { defaultMessage: '[eCommerce] Controls', }), visState: @@ -101,15 +108,16 @@ export const getSavedObjects = () => [ searchSourceJSON: '{"query":{"query":"","language":"kuery"},"filter":[]}', }, }, + references: [], }, { id: '45e07720-b890-11e8-a6d9-e546fe2bba5f', type: 'visualization', updated_at: '2018-10-01T15:17:30.755Z', - version: 2, + version: '2', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.ecommerceSpec.promotionTrackingTitle', { + title: i18n.translate('home.sampleData.ecommerceSpec.promotionTrackingTitle', { defaultMessage: '[eCommerce] Promotion Tracking', }), visState: @@ -121,15 +129,16 @@ export const getSavedObjects = () => [ searchSourceJSON: '{"query":{"query":"","language":"kuery"},"filter":[]}', }, }, + references: [], }, { id: '10f1a240-b891-11e8-a6d9-e546fe2bba5f', type: 'visualization', updated_at: '2018-10-01T15:13:03.270Z', - version: 1, + version: '1', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.ecommerceSpec.totalRevenueTitle', { + title: i18n.translate('home.sampleData.ecommerceSpec.totalRevenueTitle', { defaultMessage: '[eCommerce] Total Revenue', }), visState: @@ -142,15 +151,16 @@ export const getSavedObjects = () => [ '{"index":"ff959d40-b880-11e8-a6d9-e546fe2bba5f","query":{"query":"","language":"kuery"},"filter":[]}', }, }, + references: [], }, { id: 'b80e6540-b891-11e8-a6d9-e546fe2bba5f', type: 'visualization', updated_at: '2018-10-01T15:13:03.270Z', - version: 1, + version: '1', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.ecommerceSpec.soldProductsPerDayTitle', { + title: i18n.translate('home.sampleData.ecommerceSpec.soldProductsPerDayTitle', { defaultMessage: '[eCommerce] Sold Products per Day', }), visState: @@ -162,15 +172,16 @@ export const getSavedObjects = () => [ searchSourceJSON: '{"query":{"query":"","language":"kuery"},"filter":[]}', }, }, + references: [], }, { id: '4b3ec120-b892-11e8-a6d9-e546fe2bba5f', type: 'visualization', updated_at: '2018-10-01T15:13:03.270Z', - version: 1, + version: '1', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.ecommerceSpec.averageSalesPriceTitle', { + title: i18n.translate('home.sampleData.ecommerceSpec.averageSalesPriceTitle', { defaultMessage: '[eCommerce] Average Sales Price', }), visState: @@ -184,15 +195,16 @@ export const getSavedObjects = () => [ '{"index":"ff959d40-b880-11e8-a6d9-e546fe2bba5f","query":{"query":"","language":"kuery"},"filter":[]}', }, }, + references: [], }, { id: '9ca7aa90-b892-11e8-a6d9-e546fe2bba5f', type: 'visualization', updated_at: '2018-10-01T15:13:03.270Z', - version: 1, + version: '1', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.ecommerceSpec.averageSoldQuantityTitle', { + title: i18n.translate('home.sampleData.ecommerceSpec.averageSoldQuantityTitle', { defaultMessage: '[eCommerce] Average Sold Quantity', }), visState: @@ -206,15 +218,16 @@ export const getSavedObjects = () => [ '{"index":"ff959d40-b880-11e8-a6d9-e546fe2bba5f","query":{"query":"","language":"kuery"},"filter":[]}', }, }, + references: [], }, { id: '3ba638e0-b894-11e8-a6d9-e546fe2bba5f', type: 'search', updated_at: '2018-10-01T15:13:03.270Z', - version: 1, + version: '1', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.ecommerceSpec.ordersTitle', { + title: i18n.translate('home.sampleData.ecommerceSpec.ordersTitle', { defaultMessage: '[eCommerce] Orders', }), description: '', @@ -227,15 +240,16 @@ export const getSavedObjects = () => [ '{"index":"ff959d40-b880-11e8-a6d9-e546fe2bba5f","highlightAll":true,"version":true,"query":{"query":"","language":"kuery"},"filter":[]}', }, }, + references: [], }, { id: '9c6f83f0-bb4d-11e8-9c84-77068524bcab', type: 'visualization', updated_at: '2018-10-01T15:13:03.270Z', - version: 1, + version: '1', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.ecommerceSpec.averageSalesPerRegionTitle', { + title: i18n.translate('home.sampleData.ecommerceSpec.averageSalesPerRegionTitle', { defaultMessage: '[eCommerce] Average Sales Per Region', }), visState: @@ -248,15 +262,16 @@ export const getSavedObjects = () => [ '{"index":"ff959d40-b880-11e8-a6d9-e546fe2bba5f","query":{"query":"","language":"kuery"},"filter":[]}', }, }, + references: [], }, { id: 'b72dd430-bb4d-11e8-9c84-77068524bcab', type: 'visualization', updated_at: '2018-10-01T15:13:03.270Z', - version: 1, + version: '1', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.ecommerceSpec.topSellingProductsTitle', { + title: i18n.translate('home.sampleData.ecommerceSpec.topSellingProductsTitle', { defaultMessage: '[eCommerce] Top Selling Products', }), visState: @@ -269,12 +284,13 @@ export const getSavedObjects = () => [ '{"index":"ff959d40-b880-11e8-a6d9-e546fe2bba5f","query":{"query":"","language":"kuery"},"filter":[]}', }, }, + references: [], }, { id: 'ff959d40-b880-11e8-a6d9-e546fe2bba5f', type: 'index-pattern', updated_at: '2018-10-01T15:13:03.270Z', - version: 1, + version: '1', migrationVersion: {}, attributes: { title: 'kibana_sample_data_ecommerce', @@ -283,12 +299,13 @@ export const getSavedObjects = () => [ '[{"name":"_id","type":"string","esTypes":["_id"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":false},{"name":"_index","type":"string","esTypes":["_index"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":false},{"name":"_score","type":"number","count":0,"scripted":false,"searchable":false,"aggregatable":false,"readFromDocValues":false},{"name":"_source","type":"_source","esTypes":["_source"],"count":0,"scripted":false,"searchable":false,"aggregatable":false,"readFromDocValues":false},{"name":"_type","type":"string","esTypes":["_type"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":false},{"name":"category","type":"string","esTypes":["text"],"count":0,"scripted":false,"searchable":true,"aggregatable":false,"readFromDocValues":false},{"name":"category.keyword","type":"string","esTypes":["keyword"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true,"subType":{"multi":{"parent": "category"}}},{"name":"currency","type":"string","esTypes":["keyword"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"customer_birth_date","type":"date","esTypes":["date"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"customer_first_name","type":"string","esTypes":["text"],"count":0,"scripted":false,"searchable":true,"aggregatable":false,"readFromDocValues":false},{"name":"customer_first_name.keyword","type":"string","esTypes":["keyword"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true,"subType":{"multi":{"parent": "customer_first_name"}}},{"name":"customer_full_name","type":"string","esTypes":["text"],"count":0,"scripted":false,"searchable":true,"aggregatable":false,"readFromDocValues":false},{"name":"customer_full_name.keyword","type":"string","esTypes":["keyword"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true,"subType":{"multi":{"parent": "customer_full_name"}}},{"name":"customer_gender","type":"string","esTypes":["keyword"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"customer_id","type":"string","esTypes":["keyword"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"customer_last_name","type":"string","esTypes":["text"],"count":0,"scripted":false,"searchable":true,"aggregatable":false,"readFromDocValues":false},{"name":"customer_last_name.keyword","type":"string","esTypes":["keyword"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true,"subType":{"multi":{"parent": "customer_last_name"}}},{"name":"customer_phone","type":"string","esTypes":["keyword"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"day_of_week","type":"string","esTypes":["keyword"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"day_of_week_i","type":"number","esTypes":["integer"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"email","type":"string","esTypes":["keyword"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"geoip.city_name","type":"string","esTypes":["keyword"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"geoip.continent_name","type":"string","esTypes":["keyword"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"geoip.country_iso_code","type":"string","esTypes":["keyword"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"geoip.location","type":"geo_point","esTypes":["geo_point"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"geoip.region_name","type":"string","esTypes":["keyword"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"manufacturer","type":"string","esTypes":["text"],"count":0,"scripted":false,"searchable":true,"aggregatable":false,"readFromDocValues":false},{"name":"manufacturer.keyword","type":"string","esTypes":["keyword"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true,"subType":{"multi":{"parent": "manufacturer"}}},{"name":"order_date","type":"date","esTypes":["date"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"order_id","type":"string","esTypes":["keyword"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"products._id","type":"string","esTypes":["text"],"count":0,"scripted":false,"searchable":true,"aggregatable":false,"readFromDocValues":false},{"name":"products._id.keyword","type":"string","esTypes":["keyword"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true,"subType":{"multi":{"parent": "products._id"}}},{"name":"products.base_price","type":"number","esTypes":["half_float"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"products.base_unit_price","type":"number","esTypes":["half_float"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"products.category","type":"string","esTypes":["text"],"count":0,"scripted":false,"searchable":true,"aggregatable":false,"readFromDocValues":false},{"name":"products.category.keyword","type":"string","esTypes":["keyword"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true,"subType":{"multi":{"parent": "products.category"}}},{"name":"products.created_on","type":"date","esTypes":["date"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"products.discount_amount","type":"number","esTypes":["half_float"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"products.discount_percentage","type":"number","esTypes":["half_float"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"products.manufacturer","type":"string","esTypes":["text"],"count":0,"scripted":false,"searchable":true,"aggregatable":false,"readFromDocValues":false},{"name":"products.manufacturer.keyword","type":"string","esTypes":["keyword"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true,"subType":{"multi":{"parent": "products.manufacturer"}}},{"name":"products.min_price","type":"number","esTypes":["half_float"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"products.price","type":"number","esTypes":["half_float"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"products.product_id","type":"number","esTypes":["long"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"products.product_name","type":"string","esTypes":["text"],"count":0,"scripted":false,"searchable":true,"aggregatable":false,"readFromDocValues":false},{"name":"products.product_name.keyword","type":"string","esTypes":["keyword"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true,"subType":{"multi":{"parent": "products.product_name"}}},{"name":"products.quantity","type":"number","esTypes":["integer"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"products.sku","type":"string","esTypes":["keyword"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"products.tax_amount","type":"number","esTypes":["half_float"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"products.taxful_price","type":"number","esTypes":["half_float"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"products.taxless_price","type":"number","esTypes":["half_float"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"products.unit_discount_amount","type":"number","esTypes":["half_float"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"sku","type":"string","esTypes":["keyword"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"taxful_total_price","type":"number","esTypes":["half_float"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"taxless_total_price","type":"number","esTypes":["half_float"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"total_quantity","type":"number","esTypes":["integer"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"total_unique_products","type":"number","esTypes":["integer"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"type","type":"string","esTypes":["keyword"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"user","type":"string","esTypes":["keyword"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true}]', fieldFormatMap: '{"taxful_total_price":{"id":"number","params":{"pattern":"$0,0.[00]"}}}', }, + references: [], }, { id: '722b74f0-b882-11e8-a6d9-e546fe2bba5f', type: 'dashboard', updated_at: '2018-10-01T15:13:03.270Z', - version: 1, + version: '1', references: [ { name: 'panel_0', @@ -355,11 +372,11 @@ export const getSavedObjects = () => [ dashboard: '7.0.0', }, attributes: { - title: i18n.translate('server.sampleData.ecommerceSpec.revenueDashboardTitle', { + title: i18n.translate('home.sampleData.ecommerceSpec.revenueDashboardTitle', { defaultMessage: '[eCommerce] Revenue Dashboard', }), hits: 0, - description: i18n.translate('server.sampleData.ecommerceSpec.revenueDashboardDescription', { + description: i18n.translate('home.sampleData.ecommerceSpec.revenueDashboardDescription', { defaultMessage: 'Analyze mock eCommerce orders and revenue', }), panelsJSON: diff --git a/src/legacy/server/sample_data/data_sets/flights/field_mappings.js b/src/plugins/home/server/services/sample_data/data_sets/flights/field_mappings.ts similarity index 100% rename from src/legacy/server/sample_data/data_sets/flights/field_mappings.js rename to src/plugins/home/server/services/sample_data/data_sets/flights/field_mappings.ts diff --git a/src/legacy/server/sample_data/data_sets/flights/flights.json.gz b/src/plugins/home/server/services/sample_data/data_sets/flights/flights.json.gz similarity index 100% rename from src/legacy/server/sample_data/data_sets/flights/flights.json.gz rename to src/plugins/home/server/services/sample_data/data_sets/flights/flights.json.gz diff --git a/src/legacy/server/sample_data/data_sets/flights/index.js b/src/plugins/home/server/services/sample_data/data_sets/flights/index.ts similarity index 71% rename from src/legacy/server/sample_data/data_sets/flights/index.js rename to src/plugins/home/server/services/sample_data/data_sets/flights/index.ts index 382f82de88305..d63ea8f7fb493 100644 --- a/src/legacy/server/sample_data/data_sets/flights/index.js +++ b/src/plugins/home/server/services/sample_data/data_sets/flights/index.ts @@ -21,19 +21,25 @@ import path from 'path'; import { i18n } from '@kbn/i18n'; import { getSavedObjects } from './saved_objects'; import { fieldMappings } from './field_mappings'; +import { SampleDatasetSchema, AppLinkSchema } from '../../lib/sample_dataset_registry_types'; -export function flightsSpecProvider() { +const flightsName = i18n.translate('home.sampleData.flightsSpecTitle', { + defaultMessage: 'Sample flight data', +}); +const flightsDescription = i18n.translate('home.sampleData.flightsSpecDescription', { + defaultMessage: 'Sample data, visualizations, and dashboards for monitoring flight routes.', +}); +const initialAppLinks = [] as AppLinkSchema[]; + +export const flightsSpecProvider = function(): SampleDatasetSchema { return { id: 'flights', - name: i18n.translate('server.sampleData.flightsSpecTitle', { - defaultMessage: 'Sample flight data', - }), - description: i18n.translate('server.sampleData.flightsSpecDescription', { - defaultMessage: 'Sample data, visualizations, and dashboards for monitoring flight routes.', - }), + name: flightsName, + description: flightsDescription, previewImagePath: '/plugins/kibana/home/sample_data_resources/flights/dashboard.png', darkPreviewImagePath: '/plugins/kibana/home/sample_data_resources/flights/dashboard_dark.png', overviewDashboard: '7adfa750-4c81-11e8-b3d7-01146121b73d', + appLinks: initialAppLinks, defaultIndex: 'd3d7af60-4c81-11e8-b3d7-01146121b73d', savedObjects: getSavedObjects(), dataIndices: [ @@ -46,5 +52,6 @@ export function flightsSpecProvider() { preserveDayOfWeekTimeOfDay: true, }, ], + status: 'not_installed', }; -} +}; diff --git a/src/legacy/server/sample_data/data_sets/flights/saved_objects.js b/src/plugins/home/server/services/sample_data/data_sets/flights/saved_objects.ts similarity index 94% rename from src/legacy/server/sample_data/data_sets/flights/saved_objects.js rename to src/plugins/home/server/services/sample_data/data_sets/flights/saved_objects.ts index 69e77e67c5d9c..1cce11aea37fb 100644 --- a/src/legacy/server/sample_data/data_sets/flights/saved_objects.js +++ b/src/plugins/home/server/services/sample_data/data_sets/flights/saved_objects.ts @@ -17,17 +17,21 @@ * under the License. */ +/* eslint max-len: 0 */ +/* eslint-disable */ + import { i18n } from '@kbn/i18n'; +import { SavedObject } from 'kibana/server'; -export const getSavedObjects = () => [ +export const getSavedObjects = (): SavedObject[] => [ { id: 'aeb212e0-4c84-11e8-b3d7-01146121b73d', type: 'visualization', updated_at: '2018-05-09T15:49:03.736Z', - version: 1, + version: '1', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.flightsSpec.controlsTitle', { + title: i18n.translate('home.sampleData.flightsSpec.controlsTitle', { defaultMessage: '[Flights] Controls', }), visState: @@ -39,15 +43,16 @@ export const getSavedObjects = () => [ searchSourceJSON: '{}', }, }, + references: [], }, { id: 'c8fc3d30-4c87-11e8-b3d7-01146121b73d', type: 'visualization', updated_at: '2018-05-09T15:49:03.736Z', - version: 1, + version: '1', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.flightsSpec.flightCountAndAverageTicketPriceTitle', { + title: i18n.translate('home.sampleData.flightsSpec.flightCountAndAverageTicketPriceTitle', { defaultMessage: '[Flights] Flight Count and Average Ticket Price', }), visState: @@ -61,15 +66,16 @@ export const getSavedObjects = () => [ '{"index":"d3d7af60-4c81-11e8-b3d7-01146121b73d","filter":[],"query":{"query":"","language":"kuery"}}', }, }, + references: [], }, { id: '571aaf70-4c88-11e8-b3d7-01146121b73d', type: 'search', updated_at: '2018-05-09T15:49:03.736Z', - version: 1, + version: '1', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.flightsSpec.flightLogTitle', { + title: i18n.translate('home.sampleData.flightsSpec.flightLogTitle', { defaultMessage: '[Flights] Flight Log', }), description: '', @@ -92,15 +98,16 @@ export const getSavedObjects = () => [ '{"index":"d3d7af60-4c81-11e8-b3d7-01146121b73d","highlightAll":true,"version":true,"query":{"language":"kuery","query":""},"filter":[]}', }, }, + references: [], }, { id: '8f4d0c00-4c86-11e8-b3d7-01146121b73d', type: 'visualization', updated_at: '2018-05-09T15:49:03.736Z', - version: 1, + version: '1', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.flightsSpec.airlineCarrierTitle', { + title: i18n.translate('home.sampleData.flightsSpec.airlineCarrierTitle', { defaultMessage: '[Flights] Airline Carrier', }), visState: @@ -113,15 +120,16 @@ export const getSavedObjects = () => [ '{"index":"d3d7af60-4c81-11e8-b3d7-01146121b73d","filter":[],"query":{"query":"","language":"kuery"}}', }, }, + references: [], }, { id: 'f8290060-4c88-11e8-b3d7-01146121b73d', type: 'visualization', updated_at: '2018-05-09T15:49:03.736Z', - version: 1, + version: '1', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.flightsSpec.delayTypeTitle', { + title: i18n.translate('home.sampleData.flightsSpec.delayTypeTitle', { defaultMessage: '[Flights] Delay Type', }), visState: @@ -134,15 +142,16 @@ export const getSavedObjects = () => [ '{"index":"d3d7af60-4c81-11e8-b3d7-01146121b73d","filter":[],"query":{"query":"","language":"kuery"}}', }, }, + references: [], }, { id: 'bcb63b50-4c89-11e8-b3d7-01146121b73d', type: 'visualization', updated_at: '2018-05-09T15:49:03.736Z', - version: 1, + version: '1', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.flightsSpec.delaysAndCancellationsTitle', { + title: i18n.translate('home.sampleData.flightsSpec.delaysAndCancellationsTitle', { defaultMessage: '[Flights] Delays & Cancellations', }), visState: @@ -154,15 +163,16 @@ export const getSavedObjects = () => [ searchSourceJSON: '{}', }, }, + references: [], }, { id: '9886b410-4c8b-11e8-b3d7-01146121b73d', type: 'visualization', updated_at: '2018-05-09T15:49:03.736Z', - version: 1, + version: '1', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.flightsSpec.delayBucketsTitle', { + title: i18n.translate('home.sampleData.flightsSpec.delayBucketsTitle', { defaultMessage: '[Flights] Delay Buckets', }), visState: @@ -175,15 +185,16 @@ export const getSavedObjects = () => [ '{"index":"d3d7af60-4c81-11e8-b3d7-01146121b73d","filter":[{"meta":{"index":"d3d7af60-4c81-11e8-b3d7-01146121b73d","negate":true,"disabled":false,"alias":null,"type":"phrase","key":"FlightDelayMin","value":"0","params":{"query":0,"type":"phrase"}},"query":{"match":{"FlightDelayMin":{"query":0,"type":"phrase"}}},"$state":{"store":"appState"}}],"query":{"query":"","language":"kuery"}}', }, }, + references: [], }, { id: '76e3c090-4c8c-11e8-b3d7-01146121b73d', type: 'visualization', updated_at: '2018-05-09T15:49:03.736Z', - version: 1, + version: '1', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.flightsSpec.flightDelaysTitle', { + title: i18n.translate('home.sampleData.flightsSpec.flightDelaysTitle', { defaultMessage: '[Flights] Flight Delays', }), visState: @@ -196,15 +207,16 @@ export const getSavedObjects = () => [ '{"index":"d3d7af60-4c81-11e8-b3d7-01146121b73d","filter":[],"query":{"query":"","language":"kuery"}}', }, }, + references: [], }, { id: '707665a0-4c8c-11e8-b3d7-01146121b73d', type: 'visualization', updated_at: '2018-05-09T15:49:03.736Z', - version: 1, + version: '1', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.flightsSpec.flightCancellationsTitle', { + title: i18n.translate('home.sampleData.flightsSpec.flightCancellationsTitle', { defaultMessage: '[Flights] Flight Cancellations', }), visState: @@ -217,15 +229,16 @@ export const getSavedObjects = () => [ '{"index":"d3d7af60-4c81-11e8-b3d7-01146121b73d","filter":[],"query":{"query":"","language":"kuery"}}', }, }, + references: [], }, { id: '293b5a30-4c8f-11e8-b3d7-01146121b73d', type: 'visualization', updated_at: '2018-05-09T15:49:03.736Z', - version: 1, + version: '1', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.flightsSpec.destinationWeatherTitle', { + title: i18n.translate('home.sampleData.flightsSpec.destinationWeatherTitle', { defaultMessage: '[Flights] Destination Weather', }), visState: @@ -238,15 +251,16 @@ export const getSavedObjects = () => [ '{"index":"d3d7af60-4c81-11e8-b3d7-01146121b73d","filter":[],"query":{"query":"","language":"kuery"}}', }, }, + references: [], }, { id: '129be430-4c93-11e8-b3d7-01146121b73d', type: 'visualization', updated_at: '2018-05-09T15:49:03.736Z', - version: 1, + version: '1', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.flightsSpec.markdownInstructionsTitle', { + title: i18n.translate('home.sampleData.flightsSpec.markdownInstructionsTitle', { defaultMessage: '[Flights] Markdown Instructions', }), visState: @@ -258,15 +272,16 @@ export const getSavedObjects = () => [ searchSourceJSON: '{}', }, }, + references: [], }, { id: '334084f0-52fd-11e8-a160-89cc2ad9e8e2', type: 'visualization', updated_at: '2018-05-09T15:49:03.736Z', - version: 1, + version: '1', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.flightsSpec.originCountryTicketPricesTitle', { + title: i18n.translate('home.sampleData.flightsSpec.originCountryTicketPricesTitle', { defaultMessage: '[Flights] Origin Country Ticket Prices', }), visState: @@ -279,15 +294,16 @@ export const getSavedObjects = () => [ '{"index":"d3d7af60-4c81-11e8-b3d7-01146121b73d","filter":[],"query":{"query":"","language":"kuery"}}', }, }, + references: [], }, { id: 'f8283bf0-52fd-11e8-a160-89cc2ad9e8e2', type: 'visualization', updated_at: '2018-05-09T15:49:03.736Z', - version: 1, + version: '1', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.flightsSpec.totalFlightDelaysTitle', { + title: i18n.translate('home.sampleData.flightsSpec.totalFlightDelaysTitle', { defaultMessage: '[Flights] Total Flight Delays', }), visState: @@ -301,15 +317,16 @@ export const getSavedObjects = () => [ '{"index":"d3d7af60-4c81-11e8-b3d7-01146121b73d","filter":[{"meta":{"index":"d3d7af60-4c81-11e8-b3d7-01146121b73d","negate":false,"disabled":false,"alias":null,"type":"phrase","key":"FlightDelay","value":"true","params":{"query":true,"type":"phrase"}},"query":{"match":{"FlightDelay":{"query":true,"type":"phrase"}}},"$state":{"store":"appState"}}],"query":{"query":"","language":"kuery"}}', }, }, + references: [], }, { id: '08884800-52fe-11e8-a160-89cc2ad9e8e2', type: 'visualization', updated_at: '2018-05-09T15:49:03.736Z', - version: 1, + version: '1', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.flightsSpec.totalFlightCancellationsTitle', { + title: i18n.translate('home.sampleData.flightsSpec.totalFlightCancellationsTitle', { defaultMessage: '[Flights] Total Flight Cancellations', }), visState: @@ -323,15 +340,16 @@ export const getSavedObjects = () => [ '{"index":"d3d7af60-4c81-11e8-b3d7-01146121b73d","filter":[{"meta":{"index":"d3d7af60-4c81-11e8-b3d7-01146121b73d","negate":false,"disabled":false,"alias":null,"type":"phrase","key":"Cancelled","value":"true","params":{"query":true,"type":"phrase"}},"query":{"match":{"Cancelled":{"query":true,"type":"phrase"}}},"$state":{"store":"appState"}}],"query":{"query":"","language":"kuery"}}', }, }, + references: [], }, { id: 'e6944e50-52fe-11e8-a160-89cc2ad9e8e2', type: 'visualization', updated_at: '2018-05-09T15:49:03.736Z', - version: 1, + version: '1', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.flightsSpec.originCountryTitle', { + title: i18n.translate('home.sampleData.flightsSpec.originCountryTitle', { defaultMessage: '[Flights] Origin Country vs. Destination Country', }), visState: @@ -345,15 +363,16 @@ export const getSavedObjects = () => [ '{"index":"d3d7af60-4c81-11e8-b3d7-01146121b73d","filter":[],"query":{"query":"","language":"kuery"}}', }, }, + references: [], }, { id: '01c413e0-5395-11e8-99bf-1ba7b1bdaa61', type: 'visualization', updated_at: '2018-05-09T15:49:03.736Z', - version: 1, + version: '1', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.flightsSpec.totalFlightsTitle', { + title: i18n.translate('home.sampleData.flightsSpec.totalFlightsTitle', { defaultMessage: '[Flights] Total Flights', }), visState: @@ -366,15 +385,16 @@ export const getSavedObjects = () => [ '{"index":"d3d7af60-4c81-11e8-b3d7-01146121b73d","filter":[],"query":{"query":"","language":"kuery"}}', }, }, + references: [], }, { id: '2edf78b0-5395-11e8-99bf-1ba7b1bdaa61', type: 'visualization', updated_at: '2018-05-09T15:49:03.736Z', - version: 1, + version: '1', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.flightsSpec.averageTicketPriceTitle', { + title: i18n.translate('home.sampleData.flightsSpec.averageTicketPriceTitle', { defaultMessage: '[Flights] Average Ticket Price', }), visState: @@ -387,15 +407,16 @@ export const getSavedObjects = () => [ '{"index":"d3d7af60-4c81-11e8-b3d7-01146121b73d","filter":[],"query":{"query":"","language":"kuery"}}', }, }, + references: [], }, { id: 'ed78a660-53a0-11e8-acbd-0be0ad9d822b', type: 'visualization', updated_at: '2018-05-09T15:55:51.195Z', - version: 3, + version: '3', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.flightsSpec.airportConnectionsTitle', { + title: i18n.translate('home.sampleData.flightsSpec.airportConnectionsTitle', { defaultMessage: '[Flights] Airport Connections (Hover Over Airport)', }), visState: @@ -407,12 +428,13 @@ export const getSavedObjects = () => [ searchSourceJSON: '{"query":{"query":"","language":"kuery"},"filter":[]}', }, }, + references: [], }, { id: 'd3d7af60-4c81-11e8-b3d7-01146121b73d', type: 'index-pattern', updated_at: '2018-05-09T15:49:03.736Z', - version: 1, + version: '1', migrationVersion: {}, attributes: { title: 'kibana_sample_data_flights', @@ -422,12 +444,13 @@ export const getSavedObjects = () => [ fieldFormatMap: '{"hour_of_day":{"id":"number","params":{"pattern":"00"}},"AvgTicketPrice":{"id":"number","params":{"pattern":"$0,0.[00]"}}}', }, + references: [], }, { id: '7adfa750-4c81-11e8-b3d7-01146121b73d', type: 'dashboard', updated_at: '2018-05-09T15:59:04.578Z', - version: 4, + version: '4', references: [ { name: 'panel_0', @@ -524,12 +547,12 @@ export const getSavedObjects = () => [ dashboard: '7.0.0', }, attributes: { - title: i18n.translate('server.sampleData.flightsSpec.globalFlightDashboardTitle', { + title: i18n.translate('home.sampleData.flightsSpec.globalFlightDashboardTitle', { defaultMessage: '[Flights] Global Flight Dashboard', }), hits: 0, description: i18n.translate( - 'server.sampleData.flightsSpec.globalFlightDashboardDescription', + 'home.sampleData.flightsSpec.globalFlightDashboardDescription', { defaultMessage: 'Analyze mock flight data for ES-Air, Logstash Airways, Kibana Airlines and JetBeats', diff --git a/src/legacy/server/sample_data/data_sets/index.js b/src/plugins/home/server/services/sample_data/data_sets/index.ts similarity index 100% rename from src/legacy/server/sample_data/data_sets/index.js rename to src/plugins/home/server/services/sample_data/data_sets/index.ts diff --git a/src/legacy/server/sample_data/data_sets/logs/field_mappings.js b/src/plugins/home/server/services/sample_data/data_sets/logs/field_mappings.ts similarity index 100% rename from src/legacy/server/sample_data/data_sets/logs/field_mappings.js rename to src/plugins/home/server/services/sample_data/data_sets/logs/field_mappings.ts diff --git a/src/legacy/server/sample_data/data_sets/logs/index.js b/src/plugins/home/server/services/sample_data/data_sets/logs/index.ts similarity index 72% rename from src/legacy/server/sample_data/data_sets/logs/index.js rename to src/plugins/home/server/services/sample_data/data_sets/logs/index.ts index c6d955eb2ff51..bb6e2982f59a0 100644 --- a/src/legacy/server/sample_data/data_sets/logs/index.js +++ b/src/plugins/home/server/services/sample_data/data_sets/logs/index.ts @@ -21,19 +21,25 @@ import path from 'path'; import { i18n } from '@kbn/i18n'; import { getSavedObjects } from './saved_objects'; import { fieldMappings } from './field_mappings'; +import { SampleDatasetSchema, AppLinkSchema } from '../../lib/sample_dataset_registry_types'; -export function logsSpecProvider() { +const logsName = i18n.translate('home.sampleData.logsSpecTitle', { + defaultMessage: 'Sample web logs', +}); +const logsDescription = i18n.translate('home.sampleData.logsSpecDescription', { + defaultMessage: 'Sample data, visualizations, and dashboards for monitoring web logs.', +}); +const initialAppLinks = [] as AppLinkSchema[]; + +export const logsSpecProvider = function(): SampleDatasetSchema { return { id: 'logs', - name: i18n.translate('server.sampleData.logsSpecTitle', { - defaultMessage: 'Sample web logs', - }), - description: i18n.translate('server.sampleData.logsSpecDescription', { - defaultMessage: 'Sample data, visualizations, and dashboards for monitoring web logs.', - }), + name: logsName, + description: logsDescription, previewImagePath: '/plugins/kibana/home/sample_data_resources/logs/dashboard.png', darkPreviewImagePath: '/plugins/kibana/home/sample_data_resources/logs/dashboard_dark.png', overviewDashboard: 'edf84fe0-e1a0-11e7-b6d5-4dc382ef7f5b', + appLinks: initialAppLinks, defaultIndex: '90943e30-9a47-11e8-b64d-95841ca0b247', savedObjects: getSavedObjects(), dataIndices: [ @@ -46,5 +52,6 @@ export function logsSpecProvider() { preserveDayOfWeekTimeOfDay: true, }, ], + status: 'not_installed', }; -} +}; diff --git a/src/legacy/server/sample_data/data_sets/logs/logs.json.gz b/src/plugins/home/server/services/sample_data/data_sets/logs/logs.json.gz similarity index 100% rename from src/legacy/server/sample_data/data_sets/logs/logs.json.gz rename to src/plugins/home/server/services/sample_data/data_sets/logs/logs.json.gz diff --git a/src/legacy/server/sample_data/data_sets/logs/saved_objects.js b/src/plugins/home/server/services/sample_data/data_sets/logs/saved_objects.ts similarity index 96% rename from src/legacy/server/sample_data/data_sets/logs/saved_objects.js rename to src/plugins/home/server/services/sample_data/data_sets/logs/saved_objects.ts index 9ce6e0d001e9e..883108651bfc5 100644 --- a/src/legacy/server/sample_data/data_sets/logs/saved_objects.js +++ b/src/plugins/home/server/services/sample_data/data_sets/logs/saved_objects.ts @@ -17,17 +17,20 @@ * under the License. */ +/* eslint max-len: 0 */ +/* eslint-disable */ import { i18n } from '@kbn/i18n'; +import { SavedObject } from 'kibana/server'; -export const getSavedObjects = () => [ +export const getSavedObjects = (): SavedObject[] => [ { id: 'e1d0f010-9ee7-11e7-8711-e7a007dcef99', type: 'visualization', updated_at: '2018-08-29T13:22:17.617Z', - version: 1, + version: '1', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.logsSpec.uniqueVisitorsTitle', { + title: i18n.translate('home.sampleData.logsSpec.uniqueVisitorsTitle', { defaultMessage: '[Logs] Unique Visitors vs. Average Bytes', }), visState: @@ -40,15 +43,16 @@ export const getSavedObjects = () => [ '{"index":"90943e30-9a47-11e8-b64d-95841ca0b247","filter":[],"query":{"query":"","language":"kuery"}}', }, }, + references: [], }, { id: '06cf9c40-9ee8-11e7-8711-e7a007dcef99', type: 'visualization', updated_at: '2018-08-29T13:22:17.617Z', - version: 1, + version: '1', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.logsSpec.uniqueVisitorsByCountryTitle', { + title: i18n.translate('home.sampleData.logsSpec.uniqueVisitorsByCountryTitle', { defaultMessage: '[Logs] Unique Visitors by Country', }), visState: @@ -61,15 +65,16 @@ export const getSavedObjects = () => [ '{"index":"90943e30-9a47-11e8-b64d-95841ca0b247","filter":[],"query":{"query":"","language":"kuery"}}', }, }, + references: [], }, { id: '935afa20-e0cd-11e7-9d07-1398ccfcefa3', type: 'visualization', updated_at: '2018-08-29T13:22:17.617Z', - version: 1, + version: '1', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.logsSpec.heatmapTitle', { + title: i18n.translate('home.sampleData.logsSpec.heatmapTitle', { defaultMessage: '[Logs] Heatmap', }), visState: @@ -83,15 +88,16 @@ export const getSavedObjects = () => [ '{"index":"90943e30-9a47-11e8-b64d-95841ca0b247","filter":[],"query":{"query":"","language":"kuery"}}', }, }, + references: [], }, { id: '4eb6e500-e1c7-11e7-b6d5-4dc382ef7f5b', type: 'visualization', updated_at: '2018-08-29T13:23:20.897Z', - version: 2, + version: '2', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.logsSpec.hostVisitsBytesTableTitle', { + title: i18n.translate('home.sampleData.logsSpec.hostVisitsBytesTableTitle', { defaultMessage: '[Logs] Host, Visits and Bytes Table', }), visState: @@ -103,15 +109,16 @@ export const getSavedObjects = () => [ searchSourceJSON: '{"query":{"query":"","language":"kuery"},"filter":[]}', }, }, + references: [], }, { id: '69a34b00-9ee8-11e7-8711-e7a007dcef99', type: 'visualization', updated_at: '2018-08-29T13:24:46.136Z', - version: 2, + version: '2', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.logsSpec.goalsTitle', { + title: i18n.translate('home.sampleData.logsSpec.goalsTitle', { defaultMessage: '[Logs] Goals', }), visState: @@ -125,15 +132,16 @@ export const getSavedObjects = () => [ '{"index":"90943e30-9a47-11e8-b64d-95841ca0b247","filter":[],"query":{"query":"","language":"kuery"}}', }, }, + references: [], }, { id: '42b997f0-0c26-11e8-b0ec-3bb475f6b6ff', type: 'visualization', updated_at: '2018-08-29T13:22:17.617Z', - version: 1, + version: '1', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.logsSpec.fileTypeScatterPlotTitle', { + title: i18n.translate('home.sampleData.logsSpec.fileTypeScatterPlotTitle', { defaultMessage: '[Logs] File Type Scatter Plot', }), visState: @@ -145,15 +153,16 @@ export const getSavedObjects = () => [ searchSourceJSON: '{"query":{"query":"","language":"kuery"},"filter":[]}', }, }, + references: [], }, { id: '7cbd2350-2223-11e8-b802-5bcf64c2cfb4', type: 'visualization', updated_at: '2018-08-29T13:22:17.617Z', - version: 1, + version: '1', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.logsSpec.sourceAndDestinationSankeyChartTitle', { + title: i18n.translate('home.sampleData.logsSpec.sourceAndDestinationSankeyChartTitle', { defaultMessage: '[Logs] Source and Destination Sankey Chart', }), visState: @@ -165,15 +174,16 @@ export const getSavedObjects = () => [ searchSourceJSON: '{"query":{"query":"","language":"kuery"},"filter":[]}', }, }, + references: [], }, { id: '314c6f60-2224-11e8-b802-5bcf64c2cfb4', type: 'visualization', updated_at: '2018-08-29T13:22:17.617Z', - version: 1, + version: '1', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.logsSpec.responseCodesOverTimeTitle', { + title: i18n.translate('home.sampleData.logsSpec.responseCodesOverTimeTitle', { defaultMessage: '[Logs] Response Codes Over Time + Annotations', }), visState: @@ -185,15 +195,16 @@ export const getSavedObjects = () => [ searchSourceJSON: '{"query":{"query":"","language":"kuery"},"filter":[]}', }, }, + references: [], }, { id: '24a3e970-4257-11e8-b3aa-73fdaf54bfc9', type: 'visualization', updated_at: '2018-08-29T13:22:17.617Z', - version: 1, + version: '1', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.logsSpec.inputControlsTitle', { + title: i18n.translate('home.sampleData.logsSpec.inputControlsTitle', { defaultMessage: '[Logs] Input Controls', }), visState: @@ -205,15 +216,16 @@ export const getSavedObjects = () => [ searchSourceJSON: '{"query":{"query":"","language":"kuery"},"filter":[]}', }, }, + references: [], }, { id: '14e2e710-4258-11e8-b3aa-73fdaf54bfc9', type: 'visualization', updated_at: '2018-08-29T13:22:17.617Z', - version: 1, + version: '1', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.logsSpec.visitorOSTitle', { + title: i18n.translate('home.sampleData.logsSpec.visitorOSTitle', { defaultMessage: '[Logs] Visitors by OS', }), visState: @@ -226,15 +238,16 @@ export const getSavedObjects = () => [ '{"index":"90943e30-9a47-11e8-b64d-95841ca0b247","filter":[],"query":{"query":"","language":"kuery"}}', }, }, + references: [], }, { id: '47f2c680-a6e3-11e8-94b4-c30c0228351b', type: 'visualization', updated_at: '2018-08-29T13:22:17.617Z', - version: 1, + version: '1', migrationVersion: {}, attributes: { - title: i18n.translate('server.sampleData.logsSpec.markdownInstructionsTitle', { + title: i18n.translate('home.sampleData.logsSpec.markdownInstructionsTitle', { defaultMessage: '[Logs] Markdown Instructions', }), visState: @@ -246,12 +259,13 @@ export const getSavedObjects = () => [ searchSourceJSON: '{"query":{"query":"","language":"kuery"},"filter":[]}', }, }, + references: [], }, { id: '90943e30-9a47-11e8-b64d-95841ca0b247', type: 'index-pattern', updated_at: '2018-08-29T13:22:17.617Z', - version: 1, + version: '1', migrationVersion: {}, attributes: { title: 'kibana_sample_data_logs', @@ -260,12 +274,13 @@ export const getSavedObjects = () => [ '[{"name":"@timestamp","type":"date","esTypes":["date"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"_id","type":"string","esTypes":["_id"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":false},{"name":"_index","type":"string","esTypes":["_index"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":false},{"name":"_score","type":"number","count":0,"scripted":false,"searchable":false,"aggregatable":false,"readFromDocValues":false},{"name":"_source","type":"_source","esTypes":["_source"],"count":0,"scripted":false,"searchable":false,"aggregatable":false,"readFromDocValues":false},{"name":"_type","type":"string","esTypes":["_type"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":false},{"name":"agent","type":"string","esTypes":["text"],"count":0,"scripted":false,"searchable":true,"aggregatable":false,"readFromDocValues":false},{"name":"agent.keyword","type":"string","esTypes":["keyword"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true,"subType":{"multi":{"parent": "agent"}}},{"name":"bytes","type":"number","esTypes":["long"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"clientip","type":"ip","esTypes":["ip"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"event.dataset","type":"string","esTypes":["keyword"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"extension","type":"string","esTypes":["text"],"count":0,"scripted":false,"searchable":true,"aggregatable":false,"readFromDocValues":false},{"name":"extension.keyword","type":"string","esTypes":["keyword"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true,"subType":{"multi":{"parent": "extension"}}},{"name":"geo.coordinates","type":"geo_point","esTypes":["geo_point"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"geo.dest","type":"string","esTypes":["keyword"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"geo.src","type":"string","esTypes":["keyword"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"geo.srcdest","type":"string","esTypes":["keyword"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"host","type":"string","esTypes":["text"],"count":0,"scripted":false,"searchable":true,"aggregatable":false,"readFromDocValues":false},{"name":"host.keyword","type":"string","esTypes":["keyword"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true,"subType":{"multi":{"parent": "host"}}},{"name":"index","type":"string","esTypes":["text"],"count":0,"scripted":false,"searchable":true,"aggregatable":false,"readFromDocValues":false},{"name":"index.keyword","type":"string","esTypes":["keyword"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true,"subType":{"multi":{"parent": "index"}}},{"name":"ip","type":"ip","esTypes":["ip"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"machine.os","type":"string","esTypes":["text"],"count":0,"scripted":false,"searchable":true,"aggregatable":false,"readFromDocValues":false},{"name":"machine.os.keyword","type":"string","esTypes":["keyword"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true,"subType":{"multi":{"parent": "machine.os"}}},{"name":"machine.ram","type":"number","esTypes":["long"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"memory","type":"number","esTypes":["double"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"message","type":"string","esTypes":["text"],"count":0,"scripted":false,"searchable":true,"aggregatable":false,"readFromDocValues":false},{"name":"message.keyword","type":"string","esTypes":["keyword"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true,"subType":{"multi":{"parent": "message"}}},{"name":"phpmemory","type":"number","esTypes":["long"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"referer","type":"string","esTypes":["keyword"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"request","type":"string","esTypes":["text"],"count":0,"scripted":false,"searchable":true,"aggregatable":false,"readFromDocValues":false},{"name":"request.keyword","type":"string","esTypes":["keyword"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true,"subType":{"multi":{"parent": "request"}}},{"name":"response","type":"string","esTypes":["text"],"count":0,"scripted":false,"searchable":true,"aggregatable":false,"readFromDocValues":false},{"name":"response.keyword","type":"string","esTypes":["keyword"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true,"subType":{"multi":{"parent": "response"}}},{"name":"tags","type":"string","esTypes":["text"],"count":0,"scripted":false,"searchable":true,"aggregatable":false,"readFromDocValues":false},{"name":"tags.keyword","type":"string","esTypes":["keyword"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true,"subType":{"multi":{"parent": "tags"}}},{"name":"timestamp","type":"date","esTypes":["date"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"url","type":"string","esTypes":["text"],"count":0,"scripted":false,"searchable":true,"aggregatable":false,"readFromDocValues":false},{"name":"url.keyword","type":"string","esTypes":["keyword"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true,"subType":{"multi":{"parent": "url"}}},{"name":"utc_time","type":"date","esTypes":["date"],"count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true},{"name":"hour_of_day","type":"number","count":0,"scripted":true,"script":"doc[\'timestamp\'].value.getHour()","lang":"painless","searchable":true,"aggregatable":true,"readFromDocValues":false}]', fieldFormatMap: '{"hour_of_day":{}}', }, + references: [], }, { id: 'edf84fe0-e1a0-11e7-b6d5-4dc382ef7f5b', type: 'dashboard', updated_at: '2018-08-29T13:26:13.463Z', - version: 3, + version: '3', references: [ { name: 'panel_0', @@ -327,11 +342,11 @@ export const getSavedObjects = () => [ dashboard: '7.0.0', }, attributes: { - title: i18n.translate('server.sampleData.logsSpec.webTrafficTitle', { + title: i18n.translate('home.sampleData.logsSpec.webTrafficTitle', { defaultMessage: '[Logs] Web Traffic', }), hits: 0, - description: i18n.translate('server.sampleData.logsSpec.webTrafficDescription', { + description: i18n.translate('home.sampleData.logsSpec.webTrafficDescription', { defaultMessage: "Analyze mock web traffic log data for Elastic's website", }), panelsJSON: diff --git a/src/legacy/server/sample_data/index.js b/src/plugins/home/server/services/sample_data/index.ts similarity index 78% rename from src/legacy/server/sample_data/index.js rename to src/plugins/home/server/services/sample_data/index.ts index 2e24946761f20..f9fbee8fc6e81 100644 --- a/src/legacy/server/sample_data/index.js +++ b/src/plugins/home/server/services/sample_data/index.ts @@ -16,5 +16,10 @@ * specific language governing permissions and limitations * under the License. */ +export { + SampleDataRegistry, + SampleDataRegistrySetup, + SampleDataRegistryStart, +} from './sample_data_registry'; -export { sampleDataMixin } from './sample_data_mixin'; +export { SampleDatasetSchema, SampleDatasetProvider } from './lib/sample_dataset_registry_types'; diff --git a/src/legacy/server/sample_data/routes/lib/create_index_name.js b/src/plugins/home/server/services/sample_data/lib/create_index_name.ts similarity index 92% rename from src/legacy/server/sample_data/routes/lib/create_index_name.js rename to src/plugins/home/server/services/sample_data/lib/create_index_name.ts index de9dac7c96fa0..9aecef405d7ce 100644 --- a/src/legacy/server/sample_data/routes/lib/create_index_name.js +++ b/src/plugins/home/server/services/sample_data/lib/create_index_name.ts @@ -17,7 +17,7 @@ * under the License. */ -export function createIndexName(sampleDataSetId, dataIndexId) { +export const createIndexName = function(sampleDataSetId: string, dataIndexId: string): string { // Sample data schema was updated to support multiple indices in 6.5. // This if statement ensures that sample data sets that used a single index prior to the schema change // have the same index name to avoid orphaned indices when uninstalling. @@ -25,4 +25,4 @@ export function createIndexName(sampleDataSetId, dataIndexId) { return `kibana_sample_data_${sampleDataSetId}`; } return `kibana_sample_data_${sampleDataSetId}_${dataIndexId}`; -} +}; diff --git a/src/legacy/server/sample_data/routes/lib/load_data.js b/src/plugins/home/server/services/sample_data/lib/load_data.ts similarity index 90% rename from src/legacy/server/sample_data/routes/lib/load_data.js rename to src/plugins/home/server/services/sample_data/lib/load_data.ts index 9e343b644ec7b..481ed8da93dba 100644 --- a/src/legacy/server/sample_data/routes/lib/load_data.js +++ b/src/plugins/home/server/services/sample_data/lib/load_data.ts @@ -19,20 +19,20 @@ import readline from 'readline'; import fs from 'fs'; -import zlib from 'zlib'; +import { createUnzip } from 'zlib'; const BULK_INSERT_SIZE = 500; -export function loadData(path, bulkInsert) { +export function loadData(path: any, bulkInsert: (docs: any[]) => Promise) { return new Promise((resolve, reject) => { - let count = 0; - let docs = []; - let isPaused = false; + let count: number = 0; + let docs: any[] = []; + let isPaused: boolean = false; // pause does not stop lines already in buffer. Use smaller buffer size to avoid bulk inserting to many records const readStream = fs.createReadStream(path, { highWaterMark: 1024 * 4 }); - // eslint-disable-next-line new-cap - const lineStream = readline.createInterface({ input: readStream.pipe(zlib.Unzip()) }); + + const lineStream = readline.createInterface({ input: readStream.pipe(createUnzip()) }); const onClose = async () => { if (docs.length > 0) { try { @@ -46,7 +46,7 @@ export function loadData(path, bulkInsert) { }; lineStream.on('close', onClose); - const closeWithError = err => { + const closeWithError = (err: any) => { lineStream.removeListener('close', onClose); lineStream.close(); reject(err); diff --git a/src/plugins/home/server/services/sample_data/lib/sample_dataset_registry_types.ts b/src/plugins/home/server/services/sample_data/lib/sample_dataset_registry_types.ts new file mode 100644 index 0000000000000..29cf2289fc5b3 --- /dev/null +++ b/src/plugins/home/server/services/sample_data/lib/sample_dataset_registry_types.ts @@ -0,0 +1,92 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import { SavedObject } from 'src/core/server'; + +export enum DatasetStatusTypes { + NOT_INSTALLED = 'not_installed', + INSTALLED = 'installed', + UNKNOWN = 'unknown', +} +export interface SampleDatasetDashboardPanel { + sampleDataId: string; + dashboardId: string; + oldEmbeddableId: string; + embeddableId: string; + embeddableType: EmbeddableTypes; + embeddableConfig: object; +} +export enum EmbeddableTypes { + MAP_SAVED_OBJECT_TYPE = 'map', + SEARCH_EMBEDDABLE_TYPE = 'search', + VISUALIZE_EMBEDDABLE_TYPE = 'visualization', +} +export interface DataIndexSchema { + id: string; + + // path to newline delimented JSON file containing data relative to KIBANA_HOME + dataPath: string; + + // Object defining Elasticsearch field mappings (contents of index.mappings.type.properties) + fields: object; + + // times fields that will be updated relative to now when data is installed + timeFields: string[]; + + // Reference to now in your test data set. + // When data is installed, timestamps are converted to the present time. + // The distance between a timestamp and currentTimeMarker is preserved but the date and time will change. + // For example: + // sample data set: timestamp: 2018-01-01T00:00:00Z, currentTimeMarker: 2018-01-01T12:00:00Z + // installed data set: timestamp: 2018-04-18T20:33:14Z, currentTimeMarker: 2018-04-19T08:33:14Z + currentTimeMarker: string; + + // Set to true to move timestamp to current week, preserving day of week and time of day + // Relative distance from timestamp to currentTimeMarker will not remain the same + preserveDayOfWeekTimeOfDay: boolean; +} + +export interface AppLinkSchema { + path: string; + icon: string; + label: string; +} + +export interface SampleDatasetSchema { + id: string; + name: string; + description: string; + previewImagePath: string; + darkPreviewImagePath: string; + + // saved object id of main dashboard for sample data set + overviewDashboard: string; + appLinks: AppLinkSchema[]; + + // saved object id of default index-pattern for sample data set + defaultIndex: string; + + // Kibana saved objects (index patter, visualizations, dashboard, ...) + // Should provide a nice demo of Kibana's functionality with the sample data set + savedObjects: SavedObject[]; + dataIndices: DataIndexSchema[]; + status?: string | undefined; + statusMsg?: unknown; +} + +export type SampleDatasetProvider = () => SampleDatasetSchema; diff --git a/src/legacy/server/sample_data/data_set_schema.js b/src/plugins/home/server/services/sample_data/lib/sample_dataset_schema.ts similarity index 100% rename from src/legacy/server/sample_data/data_set_schema.js rename to src/plugins/home/server/services/sample_data/lib/sample_dataset_schema.ts diff --git a/src/legacy/server/sample_data/routes/lib/translate_timestamp.js b/src/plugins/home/server/services/sample_data/lib/translate_timestamp.ts similarity index 79% rename from src/legacy/server/sample_data/routes/lib/translate_timestamp.js rename to src/plugins/home/server/services/sample_data/lib/translate_timestamp.ts index 5d98eb34af247..b4e56cdfe7f36 100644 --- a/src/legacy/server/sample_data/routes/lib/translate_timestamp.js +++ b/src/plugins/home/server/services/sample_data/lib/translate_timestamp.ts @@ -19,29 +19,34 @@ const MILLISECONDS_IN_DAY = 86400000; -function iso8601ToDateIgnoringTime(iso8601) { +function iso8601ToDateIgnoringTime(iso8601: string) { const split = iso8601.split('-'); if (split.length < 3) { throw new Error('Unexpected timestamp format, expecting YYYY-MM-DDTHH:mm:ss'); } - const year = parseInt(split[0]); - const month = parseInt(split[1]) - 1; // javascript months are zero-based indexed - const date = parseInt(split[2]); + const year = parseInt(split[0], 10); + const month = parseInt(split[1], 10) - 1; // javascript months are zero-based indexed + const date = parseInt(split[2], 10); return new Date(year, month, date); } -export function dateToIso8601IgnoringTime(date) { +export function dateToIso8601IgnoringTime(date: Date) { // not using "Date.toISOString" because only using Date methods that deal with local time - const year = date.getFullYear(); - const month = date.getMonth() + 1; + const dateItem = new Date(date); + const year = dateItem.getFullYear(); + const month = dateItem.getMonth() + 1; const monthString = month < 10 ? `0${month}` : `${month}`; - const dateString = date.getDate() < 10 ? `0${date.getDate()}` : `${date.getDate()}`; + const dateString = dateItem.getDate() < 10 ? `0${dateItem.getDate()}` : `${dateItem.getDate()}`; return `${year}-${monthString}-${dateString}`; } // Translate source timestamp by targetReference timestamp, // perserving the distance between source and sourceReference -export function translateTimeRelativeToDifference(source, sourceReference, targetReference) { +export function translateTimeRelativeToDifference( + source: string, + sourceReference: any, + targetReference: any +) { const sourceDate = iso8601ToDateIgnoringTime(source); const sourceReferenceDate = iso8601ToDateIgnoringTime(sourceReference); const targetReferenceDate = iso8601ToDateIgnoringTime(targetReference); @@ -54,7 +59,11 @@ export function translateTimeRelativeToDifference(source, sourceReference, targe // Translate source timestamp by targetReference timestamp, // perserving the week distance between source and sourceReference and day of week of the source timestamp -export function translateTimeRelativeToWeek(source, sourceReference, targetReference) { +export function translateTimeRelativeToWeek( + source: string, + sourceReference: any, + targetReference: any +) { const sourceReferenceDate = iso8601ToDateIgnoringTime(sourceReference); const targetReferenceDate = iso8601ToDateIgnoringTime(targetReference); diff --git a/src/legacy/server/sample_data/routes/index.js b/src/plugins/home/server/services/sample_data/routes/index.ts similarity index 99% rename from src/legacy/server/sample_data/routes/index.js rename to src/plugins/home/server/services/sample_data/routes/index.ts index 800c165e9eae6..41b9458b9fbb6 100644 --- a/src/legacy/server/sample_data/routes/index.js +++ b/src/plugins/home/server/services/sample_data/routes/index.ts @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - export { createListRoute } from './list'; export { createInstallRoute } from './install'; export { createUninstallRoute } from './uninstall'; diff --git a/src/plugins/home/server/services/sample_data/routes/install.ts b/src/plugins/home/server/services/sample_data/routes/install.ts new file mode 100644 index 0000000000000..e2c5ce6883230 --- /dev/null +++ b/src/plugins/home/server/services/sample_data/routes/install.ts @@ -0,0 +1,186 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import { schema } from '@kbn/config-schema'; +import { IRouter, Logger, RequestHandlerContext } from 'src/core/server'; +import { SampleDatasetSchema } from '../lib/sample_dataset_registry_types'; +import { createIndexName } from '../lib/create_index_name'; +import { + dateToIso8601IgnoringTime, + translateTimeRelativeToDifference, + translateTimeRelativeToWeek, +} from '../lib/translate_timestamp'; +import { loadData } from '../lib/load_data'; +import { SampleDataUsageTracker } from '../usage/usage'; + +const insertDataIntoIndex = ( + dataIndexConfig: any, + index: string, + nowReference: string, + context: RequestHandlerContext, + logger: Logger +) => { + function updateTimestamps(doc: any) { + dataIndexConfig.timeFields + .filter((timeFieldName: string) => doc[timeFieldName]) + .forEach((timeFieldName: string) => { + doc[timeFieldName] = dataIndexConfig.preserveDayOfWeekTimeOfDay + ? translateTimeRelativeToWeek( + doc[timeFieldName], + dataIndexConfig.currentTimeMarker, + nowReference + ) + : translateTimeRelativeToDifference( + doc[timeFieldName], + dataIndexConfig.currentTimeMarker, + nowReference + ); + }); + return doc; + } + + const bulkInsert = async (docs: any) => { + const insertCmd = { index: { _index: index } }; + const bulk: any[] = []; + docs.forEach((doc: any) => { + bulk.push(insertCmd); + bulk.push(updateTimestamps(doc)); + }); + const resp = await context.core.elasticsearch.adminClient.callAsCurrentUser('bulk', { + body: bulk, + }); + if (resp.errors) { + const errMsg = `sample_data install errors while bulk inserting. Elasticsearch response: ${JSON.stringify( + resp, + null, + '' + )}`; + logger.warn(errMsg); + return Promise.reject( + new Error(`Unable to load sample data into index "${index}", see kibana logs for details`) + ); + } + }; + return loadData(dataIndexConfig.dataPath, bulkInsert); // this returns a Promise +}; + +export function createInstallRoute( + router: IRouter, + sampleDatasets: SampleDatasetSchema[], + logger: Logger, + usageTracker: SampleDataUsageTracker +): void { + router.post( + { + path: '/api/sample_data/{id}', + validate: { + params: schema.object({ id: schema.string() }), + // TODO validate now as date + query: schema.object({ now: schema.maybe(schema.string()) }), + }, + }, + async (context, req, res) => { + const { params, query } = req; + const sampleDataset = sampleDatasets.find(({ id }) => id === params.id); + if (!sampleDataset) { + return res.notFound(); + } + // @ts-ignore Custom query validation used + const now = query.now ? new Date(query.now) : new Date(); + const nowReference = dateToIso8601IgnoringTime(now); + const counts = {}; + for (let i = 0; i < sampleDataset.dataIndices.length; i++) { + const dataIndexConfig = sampleDataset.dataIndices[i]; + const index = createIndexName(sampleDataset.id, dataIndexConfig.id); + + // clean up any old installation of dataset + try { + await context.core.elasticsearch.dataClient.callAsCurrentUser('indices.delete', { + index, + }); + } catch (err) { + // ignore delete errors + } + + try { + const createIndexParams = { + index, + body: { + settings: { index: { number_of_shards: 1, auto_expand_replicas: '0-1' } }, + mappings: { properties: dataIndexConfig.fields }, + }, + }; + await context.core.elasticsearch.dataClient.callAsCurrentUser( + 'indices.create', + createIndexParams + ); + } catch (err) { + const errMsg = `Unable to create sample data index "${index}", error: ${err.message}`; + logger.warn(errMsg); + return res.customError({ body: errMsg, statusCode: err.status }); + } + + try { + const count = await insertDataIntoIndex( + dataIndexConfig, + index, + nowReference, + context, + logger + ); + (counts as any)[index] = count; + } catch (err) { + const errMsg = `sample_data install errors while loading data. Error: ${err}`; + logger.warn(errMsg); + return res.internalError({ body: errMsg }); + } + } + + let createResults; + try { + createResults = await context.core.savedObjects.client.bulkCreate( + sampleDataset.savedObjects, + { overwrite: true } + ); + } catch (err) { + const errMsg = `bulkCreate failed, error: ${err.message}`; + logger.warn(errMsg); + return res.internalError({ body: errMsg }); + } + const errors = createResults.saved_objects.filter(savedObjectCreateResult => { + return Boolean(savedObjectCreateResult.error); + }); + if (errors.length > 0) { + const errMsg = `sample_data install errors while loading saved objects. Errors: ${errors.join( + ',' + )}`; + logger.warn(errMsg); + return res.customError({ body: errMsg, statusCode: 403 }); + } + usageTracker.addInstall(params.id); + + // FINALLY + return res.ok({ + body: { + elasticsearchIndicesCreated: counts, + kibanaSavedObjectsLoaded: sampleDataset.savedObjects.length, + }, + }); + } + ); +} diff --git a/src/plugins/home/server/services/sample_data/routes/list.ts b/src/plugins/home/server/services/sample_data/routes/list.ts new file mode 100644 index 0000000000000..37ebab1c168d2 --- /dev/null +++ b/src/plugins/home/server/services/sample_data/routes/list.ts @@ -0,0 +1,92 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import { isBoom } from 'boom'; +import { IRouter } from 'src/core/server'; +import { SampleDatasetSchema } from '../lib/sample_dataset_registry_types'; +import { createIndexName } from '../lib/create_index_name'; + +const NOT_INSTALLED = 'not_installed'; +const INSTALLED = 'installed'; +const UNKNOWN = 'unknown'; + +export const createListRoute = (router: IRouter, sampleDatasets: SampleDatasetSchema[]) => { + router.get({ path: '/api/sample_data', validate: false }, async (context, req, res) => { + const registeredSampleDatasets = sampleDatasets.map(sampleDataset => { + return { + id: sampleDataset.id, + name: sampleDataset.name, + description: sampleDataset.description, + previewImagePath: sampleDataset.previewImagePath, + darkPreviewImagePath: sampleDataset.darkPreviewImagePath, + overviewDashboard: sampleDataset.overviewDashboard, + appLinks: sampleDataset.appLinks, + defaultIndex: sampleDataset.defaultIndex, + dataIndices: sampleDataset.dataIndices.map(({ id }) => ({ id })), + status: sampleDataset.status, + statusMsg: sampleDataset.statusMsg, + }; + }); + const isInstalledPromises = registeredSampleDatasets.map(async sampleDataset => { + for (let i = 0; i < sampleDataset.dataIndices.length; i++) { + const dataIndexConfig = sampleDataset.dataIndices[i]; + const index = createIndexName(sampleDataset.id, dataIndexConfig.id); + try { + const indexExists = await context.core.elasticsearch.dataClient.callAsCurrentUser( + 'indices.exists', + { index } + ); + if (!indexExists) { + sampleDataset.status = NOT_INSTALLED; + return; + } + + const { count } = await context.core.elasticsearch.dataClient.callAsCurrentUser('count', { + index, + }); + if (count === 0) { + sampleDataset.status = NOT_INSTALLED; + return; + } + } catch (err) { + sampleDataset.status = UNKNOWN; + sampleDataset.statusMsg = err.message; + return; + } + } + try { + await context.core.savedObjects.client.get('dashboard', sampleDataset.overviewDashboard); + } catch (err) { + // savedObjectClient.get() throws an boom error when object is not found. + if (isBoom(err) && err.output.statusCode === 404) { + sampleDataset.status = NOT_INSTALLED; + return; + } + + sampleDataset.status = UNKNOWN; + sampleDataset.statusMsg = err.message; + return; + } + + sampleDataset.status = INSTALLED; + }); + + await Promise.all(isInstalledPromises); + return res.ok({ body: registeredSampleDatasets }); + }); +}; diff --git a/src/plugins/home/server/services/sample_data/routes/uninstall.ts b/src/plugins/home/server/services/sample_data/routes/uninstall.ts new file mode 100644 index 0000000000000..64fb2b8b3a547 --- /dev/null +++ b/src/plugins/home/server/services/sample_data/routes/uninstall.ts @@ -0,0 +1,96 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import { schema } from '@kbn/config-schema'; +import _ from 'lodash'; +import { IRouter } from 'src/core/server'; +import { SampleDatasetSchema } from '../lib/sample_dataset_registry_types'; +import { createIndexName } from '../lib/create_index_name'; +import { SampleDataUsageTracker } from '../usage/usage'; + +export function createUninstallRoute( + router: IRouter, + sampleDatasets: SampleDatasetSchema[], + usageTracker: SampleDataUsageTracker +): void { + router.delete( + { + path: '/api/sample_data/{id}', + validate: { + params: schema.object({ id: schema.string() }), + }, + }, + async ( + { + core: { + elasticsearch: { + dataClient: { callAsCurrentUser }, + }, + savedObjects: { client: savedObjectsClient }, + }, + }, + request, + response + ) => { + const sampleDataset = sampleDatasets.find(({ id }) => id === request.params.id); + + if (!sampleDataset) { + return response.notFound(); + } + + for (let i = 0; i < sampleDataset.dataIndices.length; i++) { + const dataIndexConfig = sampleDataset.dataIndices[i]; + const index = createIndexName(sampleDataset.id, dataIndexConfig.id); + + try { + await callAsCurrentUser('indices.delete', { index }); + } catch (err) { + return response.customError({ + statusCode: err.status, + body: { + message: `Unable to delete sample data index "${index}", error: ${err.message}`, + }, + }); + } + } + + const deletePromises = sampleDataset.savedObjects.map(({ type, id }) => + savedObjectsClient.delete(type, id) + ); + + try { + await Promise.all(deletePromises); + } catch (err) { + // ignore 404s since users could have deleted some of the saved objects via the UI + if (_.get(err, 'output.statusCode') !== 404) { + return response.customError({ + statusCode: err.status, + body: { + message: `Unable to delete sample dataset saved objects, error: ${err.message}`, + }, + }); + } + } + + // track the usage operation in a non-blocking way + usageTracker.addUninstall(request.params.id); + + return response.noContent(); + } + ); +} diff --git a/src/plugins/home/server/services/sample_data/sample_data_registry.mock.ts b/src/plugins/home/server/services/sample_data/sample_data_registry.mock.ts new file mode 100644 index 0000000000000..4d0fb4f96023a --- /dev/null +++ b/src/plugins/home/server/services/sample_data/sample_data_registry.mock.ts @@ -0,0 +1,56 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { + SampleDataRegistrySetup, + SampleDataRegistryStart, + SampleDataRegistry, +} from './sample_data_registry'; + +const createSetupMock = (): jest.Mocked => { + const setup = { + registerSampleDataset: jest.fn(), + getSampleDatasets: jest.fn(), + addSavedObjectsToSampleDataset: jest.fn(), + addAppLinksToSampleDataset: jest.fn(), + replacePanelInSampleDatasetDashboard: jest.fn(), + }; + return setup; +}; + +const createStartMock = (): jest.Mocked => { + const start = {}; + return start; +}; + +const createMock = (): jest.Mocked> => { + const service = { + setup: jest.fn(), + start: jest.fn(), + }; + service.setup.mockImplementation(createSetupMock); + service.start.mockImplementation(createStartMock); + return service; +}; + +export const sampleDataRegistryMock = { + createSetup: createSetupMock, + createStart: createStartMock, + create: createMock, +}; diff --git a/src/plugins/home/server/services/sample_data/sample_data_registry.ts b/src/plugins/home/server/services/sample_data/sample_data_registry.ts new file mode 100644 index 0000000000000..7a4909668fff2 --- /dev/null +++ b/src/plugins/home/server/services/sample_data/sample_data_registry.ts @@ -0,0 +1,182 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import Joi from 'joi'; +import { CoreSetup, PluginInitializerContext } from 'src/core/server'; +import { SavedObject } from 'src/core/public'; +import { + SampleDatasetProvider, + SampleDatasetSchema, + AppLinkSchema, + SampleDatasetDashboardPanel, +} from './lib/sample_dataset_registry_types'; +import { sampleDataSchema } from './lib/sample_dataset_schema'; + +import { flightsSpecProvider, logsSpecProvider, ecommerceSpecProvider } from './data_sets'; +import { createListRoute, createInstallRoute } from './routes'; +import { UsageCollectionSetup } from '../../../../usage_collection/server'; +import { makeSampleDataUsageCollector, usage } from './usage'; +import { createUninstallRoute } from './routes/uninstall'; + +const flightsSampleDataset = flightsSpecProvider(); +const logsSampleDataset = logsSpecProvider(); +const ecommerceSampleDataset = ecommerceSpecProvider(); + +export class SampleDataRegistry { + constructor(private readonly initContext: PluginInitializerContext) {} + private readonly sampleDatasets: SampleDatasetSchema[] = [ + flightsSampleDataset, + logsSampleDataset, + ecommerceSampleDataset, + ]; + + public setup(core: CoreSetup, usageCollections: UsageCollectionSetup | undefined) { + if (usageCollections) { + makeSampleDataUsageCollector(usageCollections, this.initContext); + } + const usageTracker = usage( + core.savedObjects, + this.initContext.logger.get('sample_data', 'telemetry') + ); + const router = core.http.createRouter(); + createListRoute(router, this.sampleDatasets); + createInstallRoute( + router, + this.sampleDatasets, + this.initContext.logger.get('sampleData'), + usageTracker + ); + createUninstallRoute(router, this.sampleDatasets, usageTracker); + + return { + registerSampleDataset: (specProvider: SampleDatasetProvider) => { + const { error, value } = Joi.validate(specProvider(), sampleDataSchema); + + if (error) { + throw new Error(`Unable to register sample dataset spec because it's invalid. ${error}`); + } + const defaultIndexSavedObjectJson = value.savedObjects.find((savedObjectJson: any) => { + return ( + savedObjectJson.type === 'index-pattern' && savedObjectJson.id === value.defaultIndex + ); + }); + if (!defaultIndexSavedObjectJson) { + throw new Error( + `Unable to register sample dataset spec, defaultIndex: "${value.defaultIndex}" does not exist in savedObjects list.` + ); + } + + const dashboardSavedObjectJson = value.savedObjects.find((savedObjectJson: any) => { + return ( + savedObjectJson.type === 'dashboard' && savedObjectJson.id === value.overviewDashboard + ); + }); + if (!dashboardSavedObjectJson) { + throw new Error( + `Unable to register sample dataset spec, overviewDashboard: "${value.overviewDashboard}" does not exist in savedObject list.` + ); + } + this.sampleDatasets.push(value); + }, + getSampleDatasets: () => this.sampleDatasets, + + addSavedObjectsToSampleDataset: (id: string, savedObjects: SavedObject[]) => { + const sampleDataset = this.sampleDatasets.find(dataset => { + return dataset.id === id; + }); + + if (!sampleDataset) { + throw new Error(`Unable to find sample dataset with id: ${id}`); + } + + sampleDataset.savedObjects = sampleDataset.savedObjects.concat(savedObjects); + }, + + addAppLinksToSampleDataset: (id: string, appLinks: AppLinkSchema[]) => { + const sampleDataset = this.sampleDatasets.find(dataset => { + return dataset.id === id; + }); + + if (!sampleDataset) { + throw new Error(`Unable to find sample dataset with id: ${id}`); + } + + sampleDataset.appLinks = sampleDataset.appLinks + ? sampleDataset.appLinks.concat(appLinks) + : []; + }, + + replacePanelInSampleDatasetDashboard: ({ + sampleDataId, + dashboardId, + oldEmbeddableId, + embeddableId, + embeddableType, + embeddableConfig, + }: SampleDatasetDashboardPanel) => { + const sampleDataset = this.sampleDatasets.find(dataset => { + return dataset.id === sampleDataId; + }); + if (!sampleDataset) { + throw new Error(`Unable to find sample dataset with id: ${sampleDataId}`); + } + + const dashboard = sampleDataset.savedObjects.find((savedObject: SavedObject) => { + return savedObject.id === dashboardId && savedObject.type === 'dashboard'; + }); + if (!dashboard) { + throw new Error(`Unable to find dashboard with id: ${dashboardId}`); + } + try { + const reference = dashboard.references.find((referenceItem: any) => { + return referenceItem.id === oldEmbeddableId; + }); + if (!reference) { + throw new Error(`Unable to find reference for embeddable: ${oldEmbeddableId}`); + } + reference.type = embeddableType; + reference.id = embeddableId; + + const panels = JSON.parse(dashboard.attributes.panelsJSON); + const panel = panels.find((panelItem: any) => { + return panelItem.panelRefName === reference.name; + }); + if (!panel) { + throw new Error(`Unable to find panel for reference: ${reference.name}`); + } + panel.embeddableConfig = embeddableConfig; + dashboard.attributes.panelsJSON = JSON.stringify(panels); + } catch (error) { + throw new Error( + `Unable to replace panel with embeddable ${oldEmbeddableId}, error: ${error}` + ); + } + }, + }; + } + + public start() { + return {}; + } +} +/** @public */ +export type SampleDataRegistrySetup = ReturnType; + +/** @public */ +export type SampleDataRegistryStart = ReturnType; diff --git a/src/legacy/server/sample_data/usage/collector.ts b/src/plugins/home/server/services/sample_data/usage/collector.ts similarity index 75% rename from src/legacy/server/sample_data/usage/collector.ts rename to src/plugins/home/server/services/sample_data/usage/collector.ts index bcb5e7be2597a..19ceceb4cba14 100644 --- a/src/legacy/server/sample_data/usage/collector.ts +++ b/src/plugins/home/server/services/sample_data/usage/collector.ts @@ -17,17 +17,19 @@ * under the License. */ -import { Server } from 'hapi'; +import { PluginInitializerContext } from 'kibana/server'; +import { first } from 'rxjs/operators'; import { fetchProvider } from './collector_fetch'; -import { UsageCollectionSetup } from '../../../../plugins/usage_collection/server'; +import { UsageCollectionSetup } from '../../../../../usage_collection/server'; -export function makeSampleDataUsageCollector( +export async function makeSampleDataUsageCollector( usageCollection: UsageCollectionSetup, - server: Server + context: PluginInitializerContext ) { let index: string; try { - index = server.config().get('kibana.index'); + const config = await context.config.legacy.globalConfig$.pipe(first()).toPromise(); + index = config.kibana.index; } catch (err) { return; // kibana plugin is not enabled (test environment) } diff --git a/src/legacy/server/sample_data/usage/collector_fetch.test.ts b/src/plugins/home/server/services/sample_data/usage/collector_fetch.test.ts similarity index 100% rename from src/legacy/server/sample_data/usage/collector_fetch.test.ts rename to src/plugins/home/server/services/sample_data/usage/collector_fetch.test.ts diff --git a/src/legacy/server/sample_data/usage/collector_fetch.ts b/src/plugins/home/server/services/sample_data/usage/collector_fetch.ts similarity index 100% rename from src/legacy/server/sample_data/usage/collector_fetch.ts rename to src/plugins/home/server/services/sample_data/usage/collector_fetch.ts diff --git a/src/legacy/server/sample_data/usage/index.ts b/src/plugins/home/server/services/sample_data/usage/index.ts similarity index 100% rename from src/legacy/server/sample_data/usage/index.ts rename to src/plugins/home/server/services/sample_data/usage/index.ts diff --git a/src/legacy/server/sample_data/usage/usage.ts b/src/plugins/home/server/services/sample_data/usage/usage.ts similarity index 61% rename from src/legacy/server/sample_data/usage/usage.ts rename to src/plugins/home/server/services/sample_data/usage/usage.ts index 0fb17128b102c..a06dde387bb36 100644 --- a/src/legacy/server/sample_data/usage/usage.ts +++ b/src/plugins/home/server/services/sample_data/usage/usage.ts @@ -17,40 +17,39 @@ * under the License. */ -import * as Hapi from 'hapi'; +import { Logger, SavedObjectsServiceSetup } from 'kibana/server'; const SAVED_OBJECT_ID = 'sample-data-telemetry'; -export function usage(request: Hapi.Request) { - const { server } = request; +export interface SampleDataUsageTracker { + addInstall(dataSet: string): void; + addUninstall(dataSet: string): void; +} +export function usage( + savedObjects: SavedObjectsServiceSetup, + logger: Logger +): SampleDataUsageTracker { const handleIncrementError = (err: Error) => { - if (err != null) { - server.log(['debug', 'sample_data', 'telemetry'], err.stack); + if (err && err.stack) { + logger.debug(err.stack); } - server.log( - ['warning', 'sample_data', 'telemetry'], - `saved objects repository incrementCounter encountered an error: ${err}` - ); + logger.warn(`saved objects repository incrementCounter encountered an error: ${err}`); }; - const { - savedObjects: { getSavedObjectsRepository }, - } = server; - const { callWithInternalUser } = server.plugins.elasticsearch.getCluster('admin'); - const internalRepository = getSavedObjectsRepository(callWithInternalUser); + const internalRepository = savedObjects.createInternalRepository(); return { addInstall: async (dataSet: string) => { try { - internalRepository.incrementCounter(SAVED_OBJECT_ID, dataSet, `installCount`); + await internalRepository.incrementCounter(SAVED_OBJECT_ID, dataSet, `installCount`); } catch (err) { handleIncrementError(err); } }, addUninstall: async (dataSet: string) => { try { - internalRepository.incrementCounter(SAVED_OBJECT_ID, dataSet, `unInstallCount`); + await internalRepository.incrementCounter(SAVED_OBJECT_ID, dataSet, `unInstallCount`); } catch (err) { handleIncrementError(err); } diff --git a/test/api_integration/apis/general/prototype_pollution.ts b/test/api_integration/apis/general/prototype_pollution.ts index 1b732dc81afa9..3e74480ebe9eb 100644 --- a/test/api_integration/apis/general/prototype_pollution.ts +++ b/test/api_integration/apis/general/prototype_pollution.ts @@ -26,7 +26,7 @@ export default function({ getService }: FtrProviderContext) { describe('prototype pollution smoke test', () => { it('prevents payloads with the "constructor.prototype" pollution vector from being accepted', async () => { await supertest - .post('/api/sample_data/some_data_id') + .post('/api/saved_objects/_log_legacy_import') .send([ { constructor: { @@ -44,7 +44,7 @@ export default function({ getService }: FtrProviderContext) { it('prevents payloads with the "__proto__" pollution vector from being accepted', async () => { await supertest - .post('/api/sample_data/some_data_id') + .post('/api/saved_objects/_log_legacy_import') .send(JSON.parse(`{"foo": { "__proto__": {} } }`)) .expect(400, { statusCode: 400, diff --git a/test/api_integration/apis/home/sample_data.js b/test/api_integration/apis/home/sample_data.js index 4aaf8c75092ae..d5f03cc714f2f 100644 --- a/test/api_integration/apis/home/sample_data.js +++ b/test/api_integration/apis/home/sample_data.js @@ -96,7 +96,7 @@ export default function({ getService }) { await supertest .delete(`/api/sample_data/flights`) .set('kbn-xsrf', 'kibana') - .expect(200); + .expect(204); }); it('should remove elasticsearch index containing sample data', async () => { diff --git a/x-pack/legacy/plugins/canvas/server/plugin.ts b/x-pack/legacy/plugins/canvas/server/plugin.ts index b338971103381..2dc87e4a61e04 100644 --- a/x-pack/legacy/plugins/canvas/server/plugin.ts +++ b/x-pack/legacy/plugins/canvas/server/plugin.ts @@ -63,8 +63,8 @@ export class Plugin { registerCanvasUsageCollector(plugins.usageCollection, core); loadSampleData( - plugins.sampleData.addSavedObjectsToSampleDataset, - plugins.sampleData.addAppLinksToSampleDataset + plugins.home.sampleData.addSavedObjectsToSampleDataset, + plugins.home.sampleData.addAppLinksToSampleDataset ); } } diff --git a/x-pack/legacy/plugins/canvas/server/sample_data/load_sample_data.ts b/x-pack/legacy/plugins/canvas/server/sample_data/load_sample_data.ts index 08a71badb33ed..ed505c09cc7a4 100644 --- a/x-pack/legacy/plugins/canvas/server/sample_data/load_sample_data.ts +++ b/x-pack/legacy/plugins/canvas/server/sample_data/load_sample_data.ts @@ -7,9 +7,12 @@ import { CANVAS as label } from '../../i18n'; // @ts-ignore Untyped local import { ecommerceSavedObjects, flightsSavedObjects, webLogsSavedObjects } from './index'; +import { SampleDataRegistrySetup } from '../../../../../../src/plugins/home/server'; -// @ts-ignore: Untyped in Kibana -export function loadSampleData(addSavedObjectsToSampleDataset, addAppLinksToSampleDataset) { +export function loadSampleData( + addSavedObjectsToSampleDataset: SampleDataRegistrySetup['addSavedObjectsToSampleDataset'], + addAppLinksToSampleDataset: SampleDataRegistrySetup['addAppLinksToSampleDataset'] +) { const now = new Date(); const nowTimestamp = now.toISOString(); @@ -27,23 +30,29 @@ export function loadSampleData(addSavedObjectsToSampleDataset, addAppLinksToSamp } addSavedObjectsToSampleDataset('ecommerce', updateCanvasWorkpadTimestamps(ecommerceSavedObjects)); - addAppLinksToSampleDataset('ecommerce', { - path: '/app/canvas#/workpad/workpad-e08b9bdb-ec14-4339-94c4-063bddfd610e', - icon: 'canvasApp', - label, - }); + addAppLinksToSampleDataset('ecommerce', [ + { + path: '/app/canvas#/workpad/workpad-e08b9bdb-ec14-4339-94c4-063bddfd610e', + icon: 'canvasApp', + label, + }, + ]); addSavedObjectsToSampleDataset('flights', updateCanvasWorkpadTimestamps(flightsSavedObjects)); - addAppLinksToSampleDataset('flights', { - path: '/app/canvas#/workpad/workpad-a474e74b-aedc-47c3-894a-db77e62c41e0', - icon: 'canvasApp', - label, - }); + addAppLinksToSampleDataset('flights', [ + { + path: '/app/canvas#/workpad/workpad-a474e74b-aedc-47c3-894a-db77e62c41e0', + icon: 'canvasApp', + label, + }, + ]); addSavedObjectsToSampleDataset('logs', updateCanvasWorkpadTimestamps(webLogsSavedObjects)); - addAppLinksToSampleDataset('logs', { - path: '/app/canvas#/workpad/workpad-ad72a4e9-b422-480c-be6d-a64a0b79541d', - icon: 'canvasApp', - label, - }); + addAppLinksToSampleDataset('logs', [ + { + path: '/app/canvas#/workpad/workpad-ad72a4e9-b422-480c-be6d-a64a0b79541d', + icon: 'canvasApp', + label, + }, + ]); } diff --git a/x-pack/legacy/plugins/canvas/server/shim.ts b/x-pack/legacy/plugins/canvas/server/shim.ts index 7641e51f14e56..1ca6e28bd347e 100644 --- a/x-pack/legacy/plugins/canvas/server/shim.ts +++ b/x-pack/legacy/plugins/canvas/server/shim.ts @@ -7,7 +7,7 @@ import { ElasticsearchPlugin } from 'src/legacy/core_plugins/elasticsearch'; import { Legacy } from 'kibana'; -import { CoreSetup as ExistingCoreSetup } from 'src/core/server'; +import { HomeServerPluginSetup } from 'src/plugins/home/server'; import { UsageCollectionSetup } from 'src/plugins/usage_collection/server'; import { PluginSetupContract } from '../../../../plugins/features/server'; @@ -23,6 +23,7 @@ export interface CoreSetup { export interface PluginsSetup { features: PluginSetupContract; + home: HomeServerPluginSetup; interpreter: { register: (specs: any) => any; }; @@ -39,9 +40,7 @@ export interface PluginsSetup { export async function createSetupShim( server: Legacy.Server ): Promise<{ coreSetup: CoreSetup; pluginsSetup: PluginsSetup }> { - // @ts-ignore: New Platform object not typed - const setup: ExistingCoreSetup = server.newPlatform.setup.core; - + const setup = server.newPlatform.setup.core; return { coreSetup: { ...setup, @@ -58,17 +57,12 @@ export async function createSetupShim( pluginsSetup: { // @ts-ignore: New Platform not typed features: server.newPlatform.setup.plugins.features, + home: server.newPlatform.setup.plugins.home, // @ts-ignore Interpreter plugin not typed on legacy server interpreter: server.plugins.interpreter, kibana: { injectedUiAppVars: await server.getInjectedUiAppVars('kibana'), }, - sampleData: { - // @ts-ignore: Missing from Legacy Server Type - addSavedObjectsToSampleDataset: server.addSavedObjectsToSampleDataset, - // @ts-ignore: Missing from Legacy Server Type - addAppLinksToSampleDataset: server.addAppLinksToSampleDataset, - }, usageCollection: server.newPlatform.setup.plugins.usageCollection, }, }; diff --git a/x-pack/legacy/plugins/infra/index.ts b/x-pack/legacy/plugins/infra/index.ts index e03b91c58f4a3..196950b51be3a 100644 --- a/x-pack/legacy/plugins/infra/index.ts +++ b/x-pack/legacy/plugins/infra/index.ts @@ -19,10 +19,7 @@ import { SpacesPluginSetup } from '../../../plugins/spaces/server'; import { VisTypeTimeseriesSetup } from '../../../../src/plugins/vis_type_timeseries/server'; import { APMPluginContract } from '../../../plugins/apm/server'; -const APP_ID = 'infra'; -const logsSampleDataLinkLabel = i18n.translate('xpack.infra.sampleDataLinkLabel', { - defaultMessage: 'Logs', -}); +export const APP_ID = 'infra'; export function infra(kibana: any) { return new kibana.Plugin({ @@ -89,6 +86,7 @@ export function infra(kibana: any) { } as unknown) as PluginInitializerContext; // NP_TODO: Use real types from the other plugins as they are migrated const pluginDeps: InfraServerPluginDeps = { + home: legacyServer.newPlatform.setup.plugins.home, usageCollection: plugins.usageCollection as UsageCollectionSetup, indexPatterns: { indexPatternsServiceFactory: legacyServer.indexPatternsServiceFactory, @@ -111,15 +109,6 @@ export function infra(kibana: any) { 'defineInternalSourceConfiguration', libs.sources.defineInternalSourceConfiguration.bind(libs.sources) ); - - // NP_TODO: How do we move this to new platform? - legacyServer.addAppLinksToSampleDataset('logs', [ - { - path: `/app/${APP_ID}#/logs`, - label: logsSampleDataLinkLabel, - icon: 'logsApp', - }, - ]); }, }); } diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/framework/adapter_types.ts b/x-pack/legacy/plugins/infra/server/lib/adapters/framework/adapter_types.ts index 71f6a4db8c30d..b14536275cec3 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/framework/adapter_types.ts +++ b/x-pack/legacy/plugins/infra/server/lib/adapters/framework/adapter_types.ts @@ -12,9 +12,11 @@ import { PluginSetupContract as FeaturesPluginSetup } from '../../../../../../.. import { SpacesPluginSetup } from '../../../../../../../plugins/spaces/server'; import { VisTypeTimeseriesSetup } from '../../../../../../../../src/plugins/vis_type_timeseries/server'; import { APMPluginContract } from '../../../../../../../plugins/apm/server'; +import { HomeServerPluginSetup } from '../../../../../../../../src/plugins/home/server'; // NP_TODO: Compose real types from plugins we depend on, no "any" export interface InfraServerPluginDeps { + home: HomeServerPluginSetup; spaces: SpacesPluginSetup; usageCollection: UsageCollectionSetup; metrics: VisTypeTimeseriesSetup; diff --git a/x-pack/legacy/plugins/infra/server/new_platform_plugin.ts b/x-pack/legacy/plugins/infra/server/new_platform_plugin.ts index ad26663402adc..147729a1d0b3e 100644 --- a/x-pack/legacy/plugins/infra/server/new_platform_plugin.ts +++ b/x-pack/legacy/plugins/infra/server/new_platform_plugin.ts @@ -4,6 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ import { CoreSetup, PluginInitializerContext } from 'src/core/server'; +import { i18n } from '@kbn/i18n'; import { Server } from 'hapi'; import { InfraConfig } from '../../../../plugins/infra/server'; import { initInfraServer } from './infra_server'; @@ -23,12 +24,17 @@ import { InfraSources } from './lib/sources'; import { InfraServerPluginDeps } from './lib/adapters/framework'; import { METRICS_FEATURE, LOGS_FEATURE } from './features'; import { UsageCollector } from './usage/usage_collector'; +import { APP_ID } from '../index'; import { InfraStaticSourceConfiguration } from './lib/sources/types'; export interface KbnServer extends Server { usage: any; } +const logsSampleDataLinkLabel = i18n.translate('xpack.infra.sampleDataLinkLabel', { + defaultMessage: 'Logs', +}); + export interface InfraPluginSetup { defineInternalSourceConfiguration: ( sourceId: string, @@ -107,6 +113,14 @@ export class InfraServerPlugin { plugins.features.registerFeature(METRICS_FEATURE); plugins.features.registerFeature(LOGS_FEATURE); + plugins.home.sampleData.addAppLinksToSampleDataset('logs', [ + { + path: `/app/${APP_ID}#/logs`, + label: logsSampleDataLinkLabel, + icon: 'logsApp', + }, + ]); + initInfraServer(this.libs); // Telemetry diff --git a/x-pack/legacy/plugins/maps/index.js b/x-pack/legacy/plugins/maps/index.js index a6e28c9c29a32..83362e73fb314 100644 --- a/x-pack/legacy/plugins/maps/index.js +++ b/x-pack/legacy/plugins/maps/index.js @@ -102,6 +102,7 @@ export function maps(kibana) { const pluginsSetup = { featuresPlugin: newPlatformPlugins.features, licensing: newPlatformPlugins.licensing, + home: newPlatformPlugins.home, }; // legacy dependencies @@ -117,9 +118,6 @@ export function maps(kibana) { savedObjects: { getSavedObjectsRepository: server.savedObjects.getSavedObjectsRepository, }, - addSavedObjectsToSampleDataset: server.addSavedObjectsToSampleDataset, - addAppLinksToSampleDataset: server.addAppLinksToSampleDataset, - replacePanelInSampleDatasetDashboard: server.replacePanelInSampleDatasetDashboard, injectUiAppVars: server.injectUiAppVars, getInjectedUiAppVars: server.getInjectedUiAppVars, }; diff --git a/x-pack/legacy/plugins/maps/server/plugin.js b/x-pack/legacy/plugins/maps/server/plugin.js index e6b474e1c78dd..6009cea330ab0 100644 --- a/x-pack/legacy/plugins/maps/server/plugin.js +++ b/x-pack/legacy/plugins/maps/server/plugin.js @@ -13,7 +13,7 @@ import { initRoutes } from './routes'; export class MapPlugin { setup(core, plugins, __LEGACY) { - const { featuresPlugin, licensing } = plugins; + const { featuresPlugin, home, licensing } = plugins; let routesInitialized = false; featuresPlugin.registerFeature({ @@ -54,66 +54,68 @@ export class MapPlugin { const sampleDataLinkLabel = i18n.translate('xpack.maps.sampleDataLinkLabel', { defaultMessage: 'Map', }); - __LEGACY.addSavedObjectsToSampleDataset('ecommerce', getEcommerceSavedObjects()); + if (home) { + home.sampleData.addSavedObjectsToSampleDataset('ecommerce', getEcommerceSavedObjects()); - __LEGACY.addAppLinksToSampleDataset('ecommerce', [ - { - path: createMapPath('2c9c1f60-1909-11e9-919b-ffe5949a18d2'), - label: sampleDataLinkLabel, - icon: APP_ICON, - }, - ]); + home.sampleData.addAppLinksToSampleDataset('ecommerce', [ + { + path: createMapPath('2c9c1f60-1909-11e9-919b-ffe5949a18d2'), + label: sampleDataLinkLabel, + icon: APP_ICON, + }, + ]); - __LEGACY.replacePanelInSampleDatasetDashboard({ - sampleDataId: 'ecommerce', - dashboardId: '722b74f0-b882-11e8-a6d9-e546fe2bba5f', - oldEmbeddableId: '9c6f83f0-bb4d-11e8-9c84-77068524bcab', - embeddableId: '2c9c1f60-1909-11e9-919b-ffe5949a18d2', - embeddableType: 'map', - embeddableConfig: { - isLayerTOCOpen: false, - }, - }); + home.sampleData.replacePanelInSampleDatasetDashboard({ + sampleDataId: 'ecommerce', + dashboardId: '722b74f0-b882-11e8-a6d9-e546fe2bba5f', + oldEmbeddableId: '9c6f83f0-bb4d-11e8-9c84-77068524bcab', + embeddableId: '2c9c1f60-1909-11e9-919b-ffe5949a18d2', + embeddableType: 'map', + embeddableConfig: { + isLayerTOCOpen: false, + }, + }); - __LEGACY.addSavedObjectsToSampleDataset('flights', getFlightsSavedObjects()); + home.sampleData.addSavedObjectsToSampleDataset('flights', getFlightsSavedObjects()); - __LEGACY.addAppLinksToSampleDataset('flights', [ - { - path: createMapPath('5dd88580-1906-11e9-919b-ffe5949a18d2'), - label: sampleDataLinkLabel, - icon: APP_ICON, - }, - ]); + home.sampleData.addAppLinksToSampleDataset('flights', [ + { + path: createMapPath('5dd88580-1906-11e9-919b-ffe5949a18d2'), + label: sampleDataLinkLabel, + icon: APP_ICON, + }, + ]); - __LEGACY.replacePanelInSampleDatasetDashboard({ - sampleDataId: 'flights', - dashboardId: '7adfa750-4c81-11e8-b3d7-01146121b73d', - oldEmbeddableId: '334084f0-52fd-11e8-a160-89cc2ad9e8e2', - embeddableId: '5dd88580-1906-11e9-919b-ffe5949a18d2', - embeddableType: MAP_SAVED_OBJECT_TYPE, - embeddableConfig: { - isLayerTOCOpen: true, - }, - }); + home.sampleData.replacePanelInSampleDatasetDashboard({ + sampleDataId: 'flights', + dashboardId: '7adfa750-4c81-11e8-b3d7-01146121b73d', + oldEmbeddableId: '334084f0-52fd-11e8-a160-89cc2ad9e8e2', + embeddableId: '5dd88580-1906-11e9-919b-ffe5949a18d2', + embeddableType: MAP_SAVED_OBJECT_TYPE, + embeddableConfig: { + isLayerTOCOpen: true, + }, + }); - __LEGACY.addSavedObjectsToSampleDataset('logs', getWebLogsSavedObjects()); - __LEGACY.addAppLinksToSampleDataset('logs', [ - { - path: createMapPath('de71f4f0-1902-11e9-919b-ffe5949a18d2'), - label: sampleDataLinkLabel, - icon: APP_ICON, - }, - ]); - __LEGACY.replacePanelInSampleDatasetDashboard({ - sampleDataId: 'logs', - dashboardId: 'edf84fe0-e1a0-11e7-b6d5-4dc382ef7f5b', - oldEmbeddableId: '06cf9c40-9ee8-11e7-8711-e7a007dcef99', - embeddableId: 'de71f4f0-1902-11e9-919b-ffe5949a18d2', - embeddableType: MAP_SAVED_OBJECT_TYPE, - embeddableConfig: { - isLayerTOCOpen: false, - }, - }); + home.sampleData.addSavedObjectsToSampleDataset('logs', getWebLogsSavedObjects()); + home.sampleData.addAppLinksToSampleDataset('logs', [ + { + path: createMapPath('de71f4f0-1902-11e9-919b-ffe5949a18d2'), + label: sampleDataLinkLabel, + icon: APP_ICON, + }, + ]); + home.sampleData.replacePanelInSampleDatasetDashboard({ + sampleDataId: 'logs', + dashboardId: 'edf84fe0-e1a0-11e7-b6d5-4dc382ef7f5b', + oldEmbeddableId: '06cf9c40-9ee8-11e7-8711-e7a007dcef99', + embeddableId: 'de71f4f0-1902-11e9-919b-ffe5949a18d2', + embeddableType: MAP_SAVED_OBJECT_TYPE, + embeddableConfig: { + isLayerTOCOpen: false, + }, + }); + } __LEGACY.injectUiAppVars(APP_ID, async () => { return await __LEGACY.getInjectedUiAppVars('kibana'); diff --git a/x-pack/legacy/plugins/ml/index.ts b/x-pack/legacy/plugins/ml/index.ts index 3078a0c812ff1..9fe55d15d34a7 100755 --- a/x-pack/legacy/plugins/ml/index.ts +++ b/x-pack/legacy/plugins/ml/index.ts @@ -78,17 +78,17 @@ export const ml = (kibana: any) => { }; const core: MlCoreSetup = { - addAppLinksToSampleDataset: server.addAppLinksToSampleDataset, injectUiAppVars: server.injectUiAppVars, http: mlHttpService, savedObjects: server.savedObjects, }; - const { usageCollection, cloud } = kbnServer.newPlatform.setup.plugins; + const { usageCollection, cloud, home } = kbnServer.newPlatform.setup.plugins; const plugins = { elasticsearch: server.plugins.elasticsearch, security: server.plugins.security, xpackMain: server.plugins.xpack_main, spaces: server.plugins.spaces, + home, usageCollection: usageCollection as UsageCollectionSetup, cloud: cloud as CloudSetup, ml: this, diff --git a/x-pack/legacy/plugins/ml/server/new_platform/plugin.ts b/x-pack/legacy/plugins/ml/server/new_platform/plugin.ts index c468c87d7abc8..7e22a9a5a4c8b 100644 --- a/x-pack/legacy/plugins/ml/server/new_platform/plugin.ts +++ b/x-pack/legacy/plugins/ml/server/new_platform/plugin.ts @@ -55,6 +55,7 @@ import { jobAuditMessagesRoutes } from '../routes/job_audit_messages'; // @ts-ignore: could not find declaration file for module import { fileDataVisualizerRoutes } from '../routes/file_data_visualizer'; import { initMlServerLog, LogInitialization } from '../client/log'; +import { HomeServerPluginSetup } from '../../../../../../src/plugins/home/server'; type CoreHttpSetup = CoreSetup['http']; export interface MlHttpServiceSetup extends CoreHttpSetup { @@ -66,7 +67,6 @@ export interface MlXpackMainPlugin extends XPackMainPlugin { } export interface MlCoreSetup { - addAppLinksToSampleDataset: () => any; injectUiAppVars: (id: string, callback: () => {}) => any; http: MlHttpServiceSetup; savedObjects: SavedObjectsLegacyService; @@ -82,6 +82,7 @@ export interface PluginsSetup { spaces: any; usageCollection?: UsageCollectionSetup; cloud?: CloudSetup; + home?: HomeServerPluginSetup; // TODO: this is temporary for `mirrorPluginStatus` ml: any; } @@ -112,7 +113,7 @@ export class Plugin { public setup(core: MlCoreSetup, plugins: PluginsSetup) { const xpackMainPlugin: MlXpackMainPlugin = plugins.xpackMain; - const { addAppLinksToSampleDataset, http, injectUiAppVars } = core; + const { http, injectUiAppVars } = core; const pluginId = this.pluginId; mirrorPluginStatus(xpackMainPlugin, plugins.ml); @@ -124,10 +125,12 @@ export class Plugin { // Add links to the Kibana sample data sets if ml is enabled // and there is a full license (trial or platinum). - if (mlFeature.isEnabled() === true) { + if (mlFeature.isEnabled() === true && plugins.home) { const licenseCheckResults = mlFeature.getLicenseCheckResults(); if (licenseCheckResults.licenseType === LICENSE_TYPE.FULL) { - addLinksToSampleDatasets({ addAppLinksToSampleDataset }); + addLinksToSampleDatasets({ + addAppLinksToSampleDataset: plugins.home.sampleData.addAppLinksToSampleDataset, + }); } } }); diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index 282af1d477489..b7bac7dd170ed 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -2755,59 +2755,59 @@ "regionMap.visParams.colorSchemaLabel": "カラー図表", "regionMap.visParams.layerSettingsTitle": "レイヤー設定", "regionMap.visParams.outlineWeightLabel": "境界の太さ", - "server.sampleData.ecommerceSpec.averageSalesPerRegionTitle": "[e コマース] 地域ごとの平均売上", - "server.sampleData.ecommerceSpec.averageSalesPriceTitle": "[e コマース] 平均販売価格", - "server.sampleData.ecommerceSpec.averageSoldQuantityTitle": "[e コマース] 平均販売数", - "server.sampleData.ecommerceSpec.controlsTitle": "[e コマース] コントロール", - "server.sampleData.ecommerceSpec.markdownTitle": "[e コマース] マークダウン", - "server.sampleData.ecommerceSpec.ordersTitle": "[e コマース] 注文", - "server.sampleData.ecommerceSpec.promotionTrackingTitle": "[e コマース] プロモーショントラッキング", - "server.sampleData.ecommerceSpec.revenueDashboardDescription": "サンプルの e コマースの注文と収益を分析します", - "server.sampleData.ecommerceSpec.revenueDashboardTitle": "[e コマース] 収益ダッシュボード", - "server.sampleData.ecommerceSpec.salesByCategoryTitle": "[e コマース] カテゴリーごとの売上", - "server.sampleData.ecommerceSpec.salesByGenderTitle": "[e コマース] 性別ごとの売上", - "server.sampleData.ecommerceSpec.soldProductsPerDayTitle": "[e コマース] 1 日の販売製品", - "server.sampleData.ecommerceSpec.topSellingProductsTitle": "[e コマース] トップセラー製品", - "server.sampleData.ecommerceSpec.totalRevenueTitle": "[e コマース] 合計収益", - "server.sampleData.ecommerceSpecDescription": "e コマースの注文をトラッキングするサンプルデータ、ビジュアライゼーション、ダッシュボードです。", - "server.sampleData.ecommerceSpecTitle": "サンプル e コマース注文", - "server.sampleData.flightsSpec.airlineCarrierTitle": "[フライト] 航空会社", - "server.sampleData.flightsSpec.airportConnectionsTitle": "[フライト] 空港乗り継ぎ (空港にカーソルを合わせてください)", - "server.sampleData.flightsSpec.averageTicketPriceTitle": "[フライト] 平均運賃", - "server.sampleData.flightsSpec.controlsTitle": "[フライト] コントロール", - "server.sampleData.flightsSpec.delayBucketsTitle": "[フライト] 遅延バケット", - "server.sampleData.flightsSpec.delaysAndCancellationsTitle": "[フライト] 遅延・欠航", - "server.sampleData.flightsSpec.delayTypeTitle": "[フライト] 遅延タイプ", - "server.sampleData.flightsSpec.destinationWeatherTitle": "[フライト] 目的地の天候", - "server.sampleData.flightsSpec.flightCancellationsTitle": "[フライト] フライト欠航", - "server.sampleData.flightsSpec.flightCountAndAverageTicketPriceTitle": "[フライト] カウントと平均運賃", - "server.sampleData.flightsSpec.flightDelaysTitle": "[フライト] フライトの遅延", - "server.sampleData.flightsSpec.flightLogTitle": "[フライト] 飛行記録", - "server.sampleData.flightsSpec.globalFlightDashboardDescription": "ES-Air、Logstash Airways、Kibana Airlines、JetBeats のサンプル飛行データを分析します", - "server.sampleData.flightsSpec.globalFlightDashboardTitle": "[フライト] グローバルフライトダッシュボード", - "server.sampleData.flightsSpec.markdownInstructionsTitle": "[フライト] マークダウンの指示", - "server.sampleData.flightsSpec.originCountryTicketPricesTitle": "[フライト] 出発国の運賃", - "server.sampleData.flightsSpec.originCountryTitle": "[Flights] 出発国と到着国の比較", - "server.sampleData.flightsSpec.totalFlightCancellationsTitle": "[フライト] フライト欠航合計", - "server.sampleData.flightsSpec.totalFlightDelaysTitle": "[フライト] フライト遅延合計", - "server.sampleData.flightsSpec.totalFlightsTitle": "[フライト] フライト合計", - "server.sampleData.flightsSpecDescription": "飛行ルートを監視するサンプルデータ、ビジュアライゼーション、ダッシュボードです。", - "server.sampleData.flightsSpecTitle": "サンプル飛行データ", - "server.sampleData.logsSpec.fileTypeScatterPlotTitle": "[ログ] ファイルタイプ散布図", - "server.sampleData.logsSpec.goalsTitle": "[ログ] 目標", - "server.sampleData.logsSpec.heatmapTitle": "[ログ] ヒートマップ", - "server.sampleData.logsSpec.hostVisitsBytesTableTitle": "[ログ] ホスト、訪問数、バイト表", - "server.sampleData.logsSpec.inputControlsTitle": "[ログ] インプットコントロール", - "server.sampleData.logsSpec.markdownInstructionsTitle": "[ログ] マークダウンの指示", - "server.sampleData.logsSpec.responseCodesOverTimeTitle": "[ログ] 一定期間の応答コードと注釈", - "server.sampleData.logsSpec.sourceAndDestinationSankeyChartTitle": "[ログ] ソースと行先のサンキーダイアグラム", - "server.sampleData.logsSpec.uniqueVisitorsByCountryTitle": "[ログ] 国ごとのユニークビジター", - "server.sampleData.logsSpec.uniqueVisitorsTitle": "[ログ] ユニークビジターと平均バイトの比較", - "server.sampleData.logsSpec.visitorOSTitle": "[ログ] OS 別のビジター", - "server.sampleData.logsSpec.webTrafficDescription": "Elastic Web サイトのサンプル Webトラフィックログデータを分析します", - "server.sampleData.logsSpec.webTrafficTitle": "[ログ] Web トラフィック", - "server.sampleData.logsSpecDescription": "Web ログを監視するサンプルデータ、ビジュアライゼーション、ダッシュボードです。", - "server.sampleData.logsSpecTitle": "サンプル Web ログ", + "home.sampleData.ecommerceSpec.averageSalesPerRegionTitle": "[e コマース] 地域ごとの平均売上", + "home.sampleData.ecommerceSpec.averageSalesPriceTitle": "[e コマース] 平均販売価格", + "home.sampleData.ecommerceSpec.averageSoldQuantityTitle": "[e コマース] 平均販売数", + "home.sampleData.ecommerceSpec.controlsTitle": "[e コマース] コントロール", + "home.sampleData.ecommerceSpec.markdownTitle": "[e コマース] マークダウン", + "home.sampleData.ecommerceSpec.ordersTitle": "[e コマース] 注文", + "home.sampleData.ecommerceSpec.promotionTrackingTitle": "[e コマース] プロモーショントラッキング", + "home.sampleData.ecommerceSpec.revenueDashboardDescription": "サンプルの e コマースの注文と収益を分析します", + "home.sampleData.ecommerceSpec.revenueDashboardTitle": "[e コマース] 収益ダッシュボード", + "home.sampleData.ecommerceSpec.salesByCategoryTitle": "[e コマース] カテゴリーごとの売上", + "home.sampleData.ecommerceSpec.salesByGenderTitle": "[e コマース] 性別ごとの売上", + "home.sampleData.ecommerceSpec.soldProductsPerDayTitle": "[e コマース] 1 日の販売製品", + "home.sampleData.ecommerceSpec.topSellingProductsTitle": "[e コマース] トップセラー製品", + "home.sampleData.ecommerceSpec.totalRevenueTitle": "[e コマース] 合計収益", + "home.sampleData.ecommerceSpecDescription": "e コマースの注文をトラッキングするサンプルデータ、ビジュアライゼーション、ダッシュボードです。", + "home.sampleData.ecommerceSpecTitle": "サンプル e コマース注文", + "home.sampleData.flightsSpec.airlineCarrierTitle": "[フライト] 航空会社", + "home.sampleData.flightsSpec.airportConnectionsTitle": "[フライト] 空港乗り継ぎ (空港にカーソルを合わせてください)", + "home.sampleData.flightsSpec.averageTicketPriceTitle": "[フライト] 平均運賃", + "home.sampleData.flightsSpec.controlsTitle": "[フライト] コントロール", + "home.sampleData.flightsSpec.delayBucketsTitle": "[フライト] 遅延バケット", + "home.sampleData.flightsSpec.delaysAndCancellationsTitle": "[フライト] 遅延・欠航", + "home.sampleData.flightsSpec.delayTypeTitle": "[フライト] 遅延タイプ", + "home.sampleData.flightsSpec.destinationWeatherTitle": "[フライト] 目的地の天候", + "home.sampleData.flightsSpec.flightCancellationsTitle": "[フライト] フライト欠航", + "home.sampleData.flightsSpec.flightCountAndAverageTicketPriceTitle": "[フライト] カウントと平均運賃", + "home.sampleData.flightsSpec.flightDelaysTitle": "[フライト] フライトの遅延", + "home.sampleData.flightsSpec.flightLogTitle": "[フライト] 飛行記録", + "home.sampleData.flightsSpec.globalFlightDashboardDescription": "ES-Air、Logstash Airways、Kibana Airlines、JetBeats のサンプル飛行データを分析します", + "home.sampleData.flightsSpec.globalFlightDashboardTitle": "[フライト] グローバルフライトダッシュボード", + "home.sampleData.flightsSpec.markdownInstructionsTitle": "[フライト] マークダウンの指示", + "home.sampleData.flightsSpec.originCountryTicketPricesTitle": "[フライト] 出発国の運賃", + "home.sampleData.flightsSpec.originCountryTitle": "[Flights] 出発国と到着国の比較", + "home.sampleData.flightsSpec.totalFlightCancellationsTitle": "[フライト] フライト欠航合計", + "home.sampleData.flightsSpec.totalFlightDelaysTitle": "[フライト] フライト遅延合計", + "home.sampleData.flightsSpec.totalFlightsTitle": "[フライト] フライト合計", + "home.sampleData.flightsSpecDescription": "飛行ルートを監視するサンプルデータ、ビジュアライゼーション、ダッシュボードです。", + "home.sampleData.flightsSpecTitle": "サンプル飛行データ", + "home.sampleData.logsSpec.fileTypeScatterPlotTitle": "[ログ] ファイルタイプ散布図", + "home.sampleData.logsSpec.goalsTitle": "[ログ] 目標", + "home.sampleData.logsSpec.heatmapTitle": "[ログ] ヒートマップ", + "home.sampleData.logsSpec.hostVisitsBytesTableTitle": "[ログ] ホスト、訪問数、バイト表", + "home.sampleData.logsSpec.inputControlsTitle": "[ログ] インプットコントロール", + "home.sampleData.logsSpec.markdownInstructionsTitle": "[ログ] マークダウンの指示", + "home.sampleData.logsSpec.responseCodesOverTimeTitle": "[ログ] 一定期間の応答コードと注釈", + "home.sampleData.logsSpec.sourceAndDestinationSankeyChartTitle": "[ログ] ソースと行先のサンキーダイアグラム", + "home.sampleData.logsSpec.uniqueVisitorsByCountryTitle": "[ログ] 国ごとのユニークビジター", + "home.sampleData.logsSpec.uniqueVisitorsTitle": "[ログ] ユニークビジターと平均バイトの比較", + "home.sampleData.logsSpec.visitorOSTitle": "[ログ] OS 別のビジター", + "home.sampleData.logsSpec.webTrafficDescription": "Elastic Web サイトのサンプル Webトラフィックログデータを分析します", + "home.sampleData.logsSpec.webTrafficTitle": "[ログ] Web トラフィック", + "home.sampleData.logsSpecDescription": "Web ログを監視するサンプルデータ、ビジュアライゼーション、ダッシュボードです。", + "home.sampleData.logsSpecTitle": "サンプル Web ログ", "server.stats.notReadyMessage": "まだ統計が準備できていません。後程再試行してください", "server.status.disabledTitle": "無効", "server.status.greenTitle": "緑", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index 47c7050ee5c74..7ade936ba1044 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -2756,59 +2756,59 @@ "regionMap.visParams.colorSchemaLabel": "颜色模式", "regionMap.visParams.layerSettingsTitle": "图层设置", "regionMap.visParams.outlineWeightLabel": "边框粗细", - "server.sampleData.ecommerceSpec.averageSalesPerRegionTitle": "[电子商务] 每地区平均销售额", - "server.sampleData.ecommerceSpec.averageSalesPriceTitle": "[电子商务] 平均销售价格", - "server.sampleData.ecommerceSpec.averageSoldQuantityTitle": "[电子商务] 平均销售数量", - "server.sampleData.ecommerceSpec.controlsTitle": "[电子商务] 控件", - "server.sampleData.ecommerceSpec.markdownTitle": "[电子商务] Markdown", - "server.sampleData.ecommerceSpec.ordersTitle": "[电子商务] 订单", - "server.sampleData.ecommerceSpec.promotionTrackingTitle": "[电子商务] 促销追踪", - "server.sampleData.ecommerceSpec.revenueDashboardDescription": "分析模拟的电子商务订单和收入", - "server.sampleData.ecommerceSpec.revenueDashboardTitle": "[电子商务] 收入仪表板", - "server.sampleData.ecommerceSpec.salesByCategoryTitle": "[电子商务] 按类别划分的销售额", - "server.sampleData.ecommerceSpec.salesByGenderTitle": "[电子商务] 按性别划分的销售额", - "server.sampleData.ecommerceSpec.soldProductsPerDayTitle": "[电子商务] 每天已售产品", - "server.sampleData.ecommerceSpec.topSellingProductsTitle": "[电子商务] 热卖产品", - "server.sampleData.ecommerceSpec.totalRevenueTitle": "[电子商务] 总收入", - "server.sampleData.ecommerceSpecDescription": "用于追踪电子商务订单的样例数据、可视化和仪表板。", - "server.sampleData.ecommerceSpecTitle": "样例电子商务订单", - "server.sampleData.flightsSpec.airlineCarrierTitle": "[航班] 航空公司", - "server.sampleData.flightsSpec.airportConnectionsTitle": "[航班] 机场航线(将鼠标悬停在机场上)", - "server.sampleData.flightsSpec.averageTicketPriceTitle": "[航班] 平均票价", - "server.sampleData.flightsSpec.controlsTitle": "[航班] 控件", - "server.sampleData.flightsSpec.delayBucketsTitle": "[航班] 延误存储桶", - "server.sampleData.flightsSpec.delaysAndCancellationsTitle": "[航班] 延误与取消", - "server.sampleData.flightsSpec.delayTypeTitle": "[航班] 延误类型", - "server.sampleData.flightsSpec.destinationWeatherTitle": "[航班] 到达地天气", - "server.sampleData.flightsSpec.flightCancellationsTitle": "[航班] 航班取消", - "server.sampleData.flightsSpec.flightCountAndAverageTicketPriceTitle": "[航班] 航班计数和平均票价", - "server.sampleData.flightsSpec.flightDelaysTitle": "[航班] 航班延误", - "server.sampleData.flightsSpec.flightLogTitle": "[航班] 飞行日志", - "server.sampleData.flightsSpec.globalFlightDashboardDescription": "分析 ES-Air、Logstash Airways、Kibana Airlines 和 JetBeats 的模拟航班数据", - "server.sampleData.flightsSpec.globalFlightDashboardTitle": "[航班] 全球航班仪表板", - "server.sampleData.flightsSpec.markdownInstructionsTitle": "[航班] Markdown 说明", - "server.sampleData.flightsSpec.originCountryTicketPricesTitle": "[航班] 始发国/地区票价", - "server.sampleData.flightsSpec.originCountryTitle": "[航班] 始发国/地区与到达国/地区", - "server.sampleData.flightsSpec.totalFlightCancellationsTitle": "[航班] 航班取消总数", - "server.sampleData.flightsSpec.totalFlightDelaysTitle": "[航班] 航班延误总数", - "server.sampleData.flightsSpec.totalFlightsTitle": "[航班] 航班总数", - "server.sampleData.flightsSpecDescription": "用于监测航班路线的样例数据、可视化和仪表板。", - "server.sampleData.flightsSpecTitle": "样例航班数据", - "server.sampleData.logsSpec.fileTypeScatterPlotTitle": "[日志] 文件类型散点图", - "server.sampleData.logsSpec.goalsTitle": "[日志] 目标", - "server.sampleData.logsSpec.heatmapTitle": "[日志] 热图", - "server.sampleData.logsSpec.hostVisitsBytesTableTitle": "[日志] 主机、访问和字节表", - "server.sampleData.logsSpec.inputControlsTitle": "[日志] 输入控件", - "server.sampleData.logsSpec.markdownInstructionsTitle": "[日志] Markdown 说明", - "server.sampleData.logsSpec.responseCodesOverTimeTitle": "[日志] 时移响应代码 + 注释", - "server.sampleData.logsSpec.sourceAndDestinationSankeyChartTitle": "[日志] 始发地和到达地 Sankey 图", - "server.sampleData.logsSpec.uniqueVisitorsByCountryTitle": "[日志] 按国家/地区划分的独立访客", - "server.sampleData.logsSpec.uniqueVisitorsTitle": "[日志] 独立访客与平均字节数", - "server.sampleData.logsSpec.visitorOSTitle": "[日志] 按 OS 划分的访客", - "server.sampleData.logsSpec.webTrafficDescription": "分析 Elastic 网站的模拟网络流量日志数据", - "server.sampleData.logsSpec.webTrafficTitle": "[日志] 网络流量", - "server.sampleData.logsSpecDescription": "用于监测 Web 日志的样例数据、可视化和仪表板。", - "server.sampleData.logsSpecTitle": "样例 Web 日志", + "home.sampleData.ecommerceSpec.averageSalesPerRegionTitle": "[电子商务] 每地区平均销售额", + "home.sampleData.ecommerceSpec.averageSalesPriceTitle": "[电子商务] 平均销售价格", + "home.sampleData.ecommerceSpec.averageSoldQuantityTitle": "[电子商务] 平均销售数量", + "home.sampleData.ecommerceSpec.controlsTitle": "[电子商务] 控件", + "home.sampleData.ecommerceSpec.markdownTitle": "[电子商务] Markdown", + "home.sampleData.ecommerceSpec.ordersTitle": "[电子商务] 订单", + "home.sampleData.ecommerceSpec.promotionTrackingTitle": "[电子商务] 促销追踪", + "home.sampleData.ecommerceSpec.revenueDashboardDescription": "分析模拟的电子商务订单和收入", + "home.sampleData.ecommerceSpec.revenueDashboardTitle": "[电子商务] 收入仪表板", + "home.sampleData.ecommerceSpec.salesByCategoryTitle": "[电子商务] 按类别划分的销售额", + "home.sampleData.ecommerceSpec.salesByGenderTitle": "[电子商务] 按性别划分的销售额", + "home.sampleData.ecommerceSpec.soldProductsPerDayTitle": "[电子商务] 每天已售产品", + "home.sampleData.ecommerceSpec.topSellingProductsTitle": "[电子商务] 热卖产品", + "home.sampleData.ecommerceSpec.totalRevenueTitle": "[电子商务] 总收入", + "home.sampleData.ecommerceSpecDescription": "用于追踪电子商务订单的样例数据、可视化和仪表板。", + "home.sampleData.ecommerceSpecTitle": "样例电子商务订单", + "home.sampleData.flightsSpec.airlineCarrierTitle": "[航班] 航空公司", + "home.sampleData.flightsSpec.airportConnectionsTitle": "[航班] 机场航线(将鼠标悬停在机场上)", + "home.sampleData.flightsSpec.averageTicketPriceTitle": "[航班] 平均票价", + "home.sampleData.flightsSpec.controlsTitle": "[航班] 控件", + "home.sampleData.flightsSpec.delayBucketsTitle": "[航班] 延误存储桶", + "home.sampleData.flightsSpec.delaysAndCancellationsTitle": "[航班] 延误与取消", + "home.sampleData.flightsSpec.delayTypeTitle": "[航班] 延误类型", + "home.sampleData.flightsSpec.destinationWeatherTitle": "[航班] 到达地天气", + "home.sampleData.flightsSpec.flightCancellationsTitle": "[航班] 航班取消", + "home.sampleData.flightsSpec.flightCountAndAverageTicketPriceTitle": "[航班] 航班计数和平均票价", + "home.sampleData.flightsSpec.flightDelaysTitle": "[航班] 航班延误", + "home.sampleData.flightsSpec.flightLogTitle": "[航班] 飞行日志", + "home.sampleData.flightsSpec.globalFlightDashboardDescription": "分析 ES-Air、Logstash Airways、Kibana Airlines 和 JetBeats 的模拟航班数据", + "home.sampleData.flightsSpec.globalFlightDashboardTitle": "[航班] 全球航班仪表板", + "home.sampleData.flightsSpec.markdownInstructionsTitle": "[航班] Markdown 说明", + "home.sampleData.flightsSpec.originCountryTicketPricesTitle": "[航班] 始发国/地区票价", + "home.sampleData.flightsSpec.originCountryTitle": "[航班] 始发国/地区与到达国/地区", + "home.sampleData.flightsSpec.totalFlightCancellationsTitle": "[航班] 航班取消总数", + "home.sampleData.flightsSpec.totalFlightDelaysTitle": "[航班] 航班延误总数", + "home.sampleData.flightsSpec.totalFlightsTitle": "[航班] 航班总数", + "home.sampleData.flightsSpecDescription": "用于监测航班路线的样例数据、可视化和仪表板。", + "home.sampleData.flightsSpecTitle": "样例航班数据", + "home.sampleData.logsSpec.fileTypeScatterPlotTitle": "[日志] 文件类型散点图", + "home.sampleData.logsSpec.goalsTitle": "[日志] 目标", + "home.sampleData.logsSpec.heatmapTitle": "[日志] 热图", + "home.sampleData.logsSpec.hostVisitsBytesTableTitle": "[日志] 主机、访问和字节表", + "home.sampleData.logsSpec.inputControlsTitle": "[日志] 输入控件", + "home.sampleData.logsSpec.markdownInstructionsTitle": "[日志] Markdown 说明", + "home.sampleData.logsSpec.responseCodesOverTimeTitle": "[日志] 时移响应代码 + 注释", + "home.sampleData.logsSpec.sourceAndDestinationSankeyChartTitle": "[日志] 始发地和到达地 Sankey 图", + "home.sampleData.logsSpec.uniqueVisitorsByCountryTitle": "[日志] 按国家/地区划分的独立访客", + "home.sampleData.logsSpec.uniqueVisitorsTitle": "[日志] 独立访客与平均字节数", + "home.sampleData.logsSpec.visitorOSTitle": "[日志] 按 OS 划分的访客", + "home.sampleData.logsSpec.webTrafficDescription": "分析 Elastic 网站的模拟网络流量日志数据", + "home.sampleData.logsSpec.webTrafficTitle": "[日志] 网络流量", + "home.sampleData.logsSpecDescription": "用于监测 Web 日志的样例数据、可视化和仪表板。", + "home.sampleData.logsSpecTitle": "样例 Web 日志", "server.stats.notReadyMessage": "统计尚未就绪。请稍后重试", "server.status.disabledTitle": "已禁用", "server.status.greenTitle": "绿", From b8233ad4cf3b9e9e9a2471ff7d9f815b40910a81 Mon Sep 17 00:00:00 2001 From: Lisa Cawley Date: Fri, 20 Dec 2019 11:02:58 -0800 Subject: [PATCH 08/14] [DOCS] Fixes ML links (#53713) --- docs/limitations.asciidoc | 2 +- docs/user/ml/index.asciidoc | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/limitations.asciidoc b/docs/limitations.asciidoc index 0b26a3cdcf71a..9bcba3b65d660 100644 --- a/docs/limitations.asciidoc +++ b/docs/limitations.asciidoc @@ -12,7 +12,7 @@ These {stack} features also have limitations that affect {kib}: * {ref}/watcher-limitations.html[Alerting] -* {stack-ov}/ml-limitations.html[Machine learning] +* {ml-docs}/ml-limitations.html[Machine learning] * {ref}/security-limitations.html[Security] -- diff --git a/docs/user/ml/index.asciidoc b/docs/user/ml/index.asciidoc index a2c23aad98d5b..cca0dc5e4530f 100644 --- a/docs/user/ml/index.asciidoc +++ b/docs/user/ml/index.asciidoc @@ -50,8 +50,8 @@ pane: image::user/ml/images/ml-job-management.jpg[Job Management] You can use the *Settings* pane to create and edit -{stack-ov}/ml-calendars.html[calendars] and the filters that are used in -{stack-ov}/ml-rules.html[custom rules]: +{ml-docs}/ml-calendars.html[calendars] and the filters that are used in +{ml-docs}/ml-rules.html[custom rules]: [role="screenshot"] image::user/ml/images/ml-settings.jpg[Calendar Management] @@ -73,7 +73,7 @@ image::user/ml/images/ml-annotations-list.jpg[Single Metric Viewer with annotati In some circumstances, annotations are also added automatically. For example, if the {anomaly-job} detects that there is missing data, it annotates the affected time period. For more information, see -{stack-ov}/ml-delayed-data-detection.html[Handling delayed data]. The +{ml-docs}/ml-delayed-data-detection.html[Handling delayed data]. The *Job Management* pane shows the full list of annotations for each job. NOTE: The {kib} {ml-features} use pop-ups. You must configure your web @@ -82,7 +82,7 @@ browser so that it does not block pop-up windows or create an exception for your For more information about the {anomaly-detect} feature, see https://www.elastic.co/what-is/elastic-stack-machine-learning[{ml-cap} in the {stack}] -and {stack-ov}/xpack-ml.html[{ml-cap} {anomaly-detect}]. +and {ml-docs}/xpack-ml.html[{ml-cap} {anomaly-detect}]. [[xpack-ml-dfanalytics]] == {dfanalytics-cap} @@ -99,4 +99,4 @@ in {kib}. For example: image::user/ml/images/outliers.jpg[{oldetection-cap} results in {kib}] For more information about the {dfanalytics} feature, see -{stack-ov}/ml-dfanalytics.html[{ml-cap} {dfanalytics}]. \ No newline at end of file +{ml-docs}/ml-dfanalytics.html[{ml-cap} {dfanalytics}]. \ No newline at end of file From 8d6cfa5c0c758ef1c1ce88219e089c02427354c2 Mon Sep 17 00:00:00 2001 From: Ryland Herrick Date: Fri, 20 Dec 2019 14:23:01 -0600 Subject: [PATCH 09/14] [SIEM] Migrating frontend services to NP (#53669) * [SIEM] Migrating frontend services to NP (#52783) * Remove legacy index_patterns import We'd already brought in the new interface in a previous commit; this was just used as an unnecessary type assertion. * Update snapshots following new docLink mocks * Remove unused manual mocks These are not picked up by jest; calling jest.mock('lib/compose/kibana_core') has the same effect whether or not these files exist. * WIP: Use kibana core mock everywhere we're doing it manually The timeline tests are the last place we're explicitly mocking useKibanaCore; removing the mocks cause tests to hang. I think hey're relying on the side effects of importing the mock/ui_settings file, but I'll figure that out next. * Replace ui/documentation_links with core NP service In most instances, this meant using the useContext hook with our NP core context. This also updates our mocks to leverage the factory so graciously provided by platform. There are a few failing tests, mostly due to links being previously undefined in tests. * Use new mocks on timeline test that doesn't hang The rest of these do, though. * Remove remaining uses of mockUiSettings in useKibanaCore mocks These have to be evaluated immediately so that we always return the same core object. Otherwise we get stuck in a loop between render/useEffect/setState due to the savedObjects client being different on each invocation. * Invoke platform's mock factory at mock time Previously, we were invoking it any time someone called `useKibanaCore`, getting a new object back each time. This both caused some bugs (looping with useEffect) and was not representative of how the actual hook worked. This also moves that invokation into the mock function, along with shaping the mocked module so that we don't have to do it in every call to jest.mock. * WIP: migrating to use kibana_react's provider and helpers We're re-exporting these locally to have more control around mocking them (until platform implements that). This breaks everything that was using the old mocks. Will fix. * WIP: Migrating to use kibana_react Instead of our homegrown hooks we can use these utilities instead. Unfortunately kibana_react doesn't yet have mocks, so we had to implement that ourselves. Luckily, we already had local mocks for the settings service. This migrates to a the new format. For clarity and consistency, we also re-export new platform's mocks here and use them to populate our kibana_react mocks. We started by migrating the UiSettings service to new platform, and let that drive the rest. With the mocks in place for kibana_react, removing the usage of useKibanaCore was a natural step as well. The next step is removing the usage of chrome.getUiSettingsClient with our useUiSetting$ hook, and with that (and maybe some config setup; I'm seeing errors at runtime), we should be ready to start migrating other services. * Bind a copy of kibana at mock creation We were previously returning a new copy any time e.g. useKibana was called, which is not the contract that consumers are expecting. and in fact caused looping with components employing useEffect etc. * Remove internal context providers and last usage We're now using kibana_react fully. * Fix tests failing due to wrong mocks Remaining failures are either due to a date format issue, or something being rendered differently. Those are up next. Still haven't touched use of chrome.getUiSettingsClient, that's after. * Fix test failures related to date formatting * mocks missing UI Setting (DEFAULT_TIMEZONE_BROWSER) which is required by our formatted_date utilities * mock timepicker ranges in the one test that uses it (SuperDatePicker) * Remove unnecessary and/or redundant mocks Since our TestProvider now mocks new platform, the only tests that should need to mock uiSettings related stuff (e.g. timezone preferences) would be the tests that (directly or no) use kibana_react to get it. * Refactor kibana_react mocks * adds a mock for the non-observable useUiSetting * removes the unmockable HOC withKibana * Replace usage of chrome.getUiSettingsClient with useUiSetting We're opting for the non-observable behavior here because I believe that's more analagous. There are a few remaining usages in non-react code. Tests are still using the mocks, those'll be removed next. * Remove ui_settings mocks Now that we're not using this hook there's no need for the mocks. Tests are green. * Remove siem's UI settings hook We're now using the ones provided by kibana_react. * Use withKibana HOC on our component classes React was kind enough to remind me that I can't put hooks in classes. Whoops. * Set defaults for some unknown UI settings The service claims not to know about these settings we're retrieving. Until I can figure out where they should come from, we're going to initialize them with what seem to be the defaults at plugin initialization. * Remove old hooks These have now been replaced with kibana_react's equivalents. * Fix type error on usage of useKibana hook This is one of the few places where we're using another plugin, which are not present in the default typings due to their opt-in nature. * Fix type error on ML call The indexPattern we get back is actually an array. The endpoint seems to handle this just fine (at least, it doesn't blow up), but once we started retrieving a typed value this error surfaced. * Export a 'bound' version of the useKibana function Rather than having to type this on each invocation. This requires us to define which plugins we depend on, which is a good thing. * Instantiate our mock function We aren't using these right now I didn't notice, but that wasn't the right reference. * Fix test that relies on unmocked service Our QueryBar component relies very (very, very) indirectly on a storage service that does not exist in New Platform, nor its corresponding mocks. To get it passing for now, we're just gonna pretend like it's there. * Remove use of ui/chrome in our charts Replaces with hooks that accomplish the same. * Remove last use of chrome.getUiSettingsClient This function is itself a hook, so we should be good here. * Remove unnecessary non-null assertions Now that we're using our typed version of the useKibana hook, typescript knows that these services will be available (once we actually enforce that in our kibana.json, of course). * Fix chart tests These rely on a kibana hook now, so we need to mock it out for these renders lest we blow up when the context isn't there. * Replace missing mock I deleted this in a previous commit, thinking it unneeded. However, getHostDetailsBreadcrumbs ultimately asks for some default date parameters for the timerange boundaries. * Add back tests for our theming hook * Style: cleanup * Remove unneeded default UI Settings values We were previously getting errors due to these values not being known to the client, but it looks like that was either fixed upstream, or a temporary issue caused by some improper context setup. * Simplify kibana_react mocks Let's leave JSX out of it. Co-authored-by: Elastic Machine * Update references to now-deleted hooks These hooks were deleted on a recent branch, but new usages were merged to master in the meantime. * Fix remaining uses of hooks/chrome that were not merge conflicts * Use HOC on class component Co-authored-by: Elastic Machine --- .../plugins/siem/public/apps/plugin.tsx | 8 +- .../plugins/siem/public/apps/start_app.tsx | 40 ++---- .../public/components/bytes/index.test.tsx | 2 - .../components/charts/areachart.test.tsx | 2 + .../public/components/charts/areachart.tsx | 8 +- .../components/charts/barchart.test.tsx | 2 + .../public/components/charts/barchart.tsx | 10 +- .../public/components/charts/common.test.tsx | 44 +++--- .../siem/public/components/charts/common.tsx | 50 +++---- .../utility_bar/utility_bar.test.tsx | 3 - .../utility_bar/utility_bar_action.test.tsx | 3 - .../utility_bar/utility_bar_group.test.tsx | 3 - .../utility_bar/utility_bar_section.test.tsx | 3 - .../utility_bar/utility_bar_text.test.tsx | 3 - .../__snapshots__/embedded_map.test.tsx.snap | 2 +- ...ndex_patterns_missing_prompt.test.tsx.snap | 2 +- .../embeddables/embeddable.test.tsx | 3 - .../embeddables/embeddable_header.test.tsx | 3 - .../embeddables/embedded_map.test.tsx | 21 +-- .../components/embeddables/embedded_map.tsx | 28 ++-- .../embeddables/embedded_map_helpers.test.tsx | 1 - .../index_patterns_missing_prompt.test.tsx | 6 +- .../index_patterns_missing_prompt.tsx | 116 +++++++-------- .../event_details/event_details.test.tsx | 2 - .../event_fields_browser.test.tsx | 2 +- .../events_viewer/events_viewer.test.tsx | 10 +- .../events_viewer/events_viewer.tsx | 6 +- .../components/events_viewer/index.test.tsx | 10 +- .../public/components/events_viewer/index.tsx | 4 +- .../public/components/flyout/index.test.tsx | 2 - .../components/flyout/pane/index.test.tsx | 15 +- .../components/formatted_bytes/index.test.tsx | 22 ++- .../components/formatted_bytes/index.tsx | 4 +- .../components/formatted_date/index.test.tsx | 60 +++----- .../components/formatted_date/index.tsx | 9 +- .../components/header_global/index.test.tsx | 3 +- .../components/header_page/index.test.tsx | 3 - .../components/header_section/index.test.tsx | 3 - .../components/last_event_time/index.test.tsx | 1 - .../components/link_icon/index.test.tsx | 3 - .../matrix_histogram/index.test.tsx | 11 +- .../components/matrix_histogram/index.tsx | 4 +- .../ml/anomaly/use_anomalies_table_data.ts | 8 +- .../permissions/ml_capabilities_provider.tsx | 4 +- .../ml/score/anomaly_score.test.tsx | 2 - .../ml/score/anomaly_scores.test.tsx | 2 - .../score/create_descriptions_list.test.tsx | 2 +- .../ml_popover/hooks/use_siem_jobs.tsx | 6 +- .../components/ml_popover/ml_popover.test.tsx | 3 +- .../components/ml_popover/ml_popover.tsx | 8 +- .../public/components/ml_popover/types.ts | 2 +- .../public/components/netflow/index.test.tsx | 2 - .../components/open_timeline/index.test.tsx | 2 +- .../open_timeline/open_timeline.test.tsx | 2 +- .../open_timeline_modal/index.test.tsx | 2 +- .../open_timeline_modal_body.test.tsx | 2 +- .../open_timeline_modal_button.test.tsx | 2 - .../timelines_table/actions_columns.test.tsx | 2 +- .../timelines_table/common_columns.test.tsx | 2 +- .../timelines_table/extended_columns.test.tsx | 2 +- .../icon_header_columns.test.tsx | 2 +- .../timelines_table/index.test.tsx | 2 +- .../histogram_signals/index.test.tsx | 3 - .../hosts/first_last_seen_host/index.test.tsx | 23 ++- .../page/hosts/host_overview/index.tsx | 4 +- .../page/hosts/hosts_table/index.test.tsx | 8 -- .../page/network/ip_overview/index.tsx | 4 +- .../network/network_dns_table/index.test.tsx | 2 - .../network/network_http_table/index.test.tsx | 2 - .../index.test.tsx | 1 - .../network_top_n_flow_table/index.test.tsx | 2 - .../page/network/tls_table/index.test.tsx | 2 - .../page/network/users_table/index.test.tsx | 2 - .../components/progress_inline/index.test.tsx | 3 - .../components/query_bar/index.test.tsx | 25 ++-- .../public/components/query_bar/index.tsx | 3 +- .../public/components/search_bar/index.tsx | 3 +- .../source_destination/index.test.tsx | 2 - .../source_destination_ip.test.tsx | 2 - .../public/components/subtitle/index.test.tsx | 3 - .../super_date_picker/index.test.tsx | 67 ++++++++- .../components/super_date_picker/index.tsx | 12 +- .../components/timeline/body/index.test.tsx | 2 - .../body/renderers/formatted_field.test.tsx | 2 +- .../netflow/netflow_row_renderer.test.tsx | 2 - .../renderers/plain_column_renderer.test.tsx | 2 +- .../system/generic_row_renderer.test.tsx | 2 +- .../components/timeline/header/index.test.tsx | 9 +- .../timeline/properties/index.test.tsx | 12 +- .../timeline/query_bar/index.test.tsx | 9 +- .../components/timeline/query_bar/index.tsx | 6 +- .../components/timeline/timeline.test.tsx | 9 +- .../public/components/timeline/timeline.tsx | 6 +- .../components/wrapper_page/index.test.tsx | 3 - .../alerts/alerts_over_time/index.tsx | 13 +- .../anomalies_query_tab_body/index.tsx | 4 +- .../authentications_over_time/index.tsx | 17 ++- .../containers/authentications/index.tsx | 13 +- .../detection_engine/rules/persist_rule.tsx | 4 +- .../detection_engine/rules/use_rule.tsx | 4 +- .../detection_engine/rules/use_rules.tsx | 4 +- .../detection_engine/signals/use_query.tsx | 4 +- .../events/events_over_time/index.tsx | 13 +- .../events/last_event_time/index.ts | 5 +- .../containers/hosts/first_last_seen/index.ts | 5 +- .../siem/public/containers/hosts/index.tsx | 14 +- .../containers/hosts/overview/index.tsx | 18 ++- .../public/containers/ip_overview/index.tsx | 4 +- .../containers/kpi_host_details/index.tsx | 4 +- .../public/containers/kpi_hosts/index.tsx | 4 +- .../public/containers/kpi_network/index.tsx | 4 +- .../containers/kuery_autocompletion/index.tsx | 6 +- .../public/containers/network_dns/index.tsx | 21 ++- .../public/containers/network_http/index.tsx | 10 +- .../network_top_countries/index.tsx | 10 +- .../containers/network_top_n_flow/index.tsx | 10 +- .../overview/overview_host/index.tsx | 4 +- .../overview/overview_network/index.tsx | 4 +- .../public/containers/source/index.test.tsx | 4 +- .../siem/public/containers/source/index.tsx | 13 +- .../containers/timeline/details/index.tsx | 4 +- .../siem/public/containers/timeline/index.tsx | 16 ++- .../siem/public/containers/tls/index.tsx | 14 +- .../containers/uncommon_processes/index.tsx | 13 +- .../siem/public/containers/users/index.tsx | 13 +- .../siem/public/hooks/use_index_patterns.tsx | 4 +- .../lib/compose/__mocks__/kibana_core.ts | 13 -- .../lib/compose/__mocks__/kibana_plugins.ts | 13 -- .../siem/public/lib/compose/kibana_core.tsx | 25 ---- .../public/lib/compose/kibana_plugins.tsx | 27 ---- .../siem/public/lib/kibana/__mocks__/index.ts | 19 +++ .../plugins/siem/public/lib/kibana/index.ts | 31 ++++ .../__mocks__/use_kibana_ui_setting.ts | 13 -- .../lib/settings/use_kibana_ui_setting.ts | 55 -------- .../settings/use_kibana_ui_settings.test.tsx | 50 ------- .../public/lib/settings/use_observable.ts | 21 --- .../siem/public/lib/theme/use_eui_theme.tsx | 4 +- .../plugins/siem/public/mock/kibana_core.ts | 13 ++ .../plugins/siem/public/mock/kibana_react.ts | 95 +++++++++++++ .../siem/public/mock/test_providers.tsx | 34 +---- .../plugins/siem/public/mock/ui_settings.ts | 75 ---------- .../components/signals/index.tsx | 9 +- .../signals/signals_utility_bar/index.tsx | 4 +- .../detection_engine_empty_page.tsx | 4 +- .../detection_engine/rules/all/index.tsx | 4 +- .../components/description_step/index.tsx | 6 +- .../import_rule_modal/index.test.tsx | 11 +- .../components/import_rule_modal/index.tsx | 4 +- .../rules/components/query_bar/index.tsx | 6 +- .../components/rule_switch/index.test.tsx | 14 +- .../rules/components/rule_switch/index.tsx | 4 +- .../components/step_define_rule/index.tsx | 2 +- .../pages/hosts/details/details_tabs.test.tsx | 10 +- .../siem/public/pages/hosts/details/index.tsx | 6 +- .../siem/public/pages/hosts/hosts.test.tsx | 19 +-- .../plugins/siem/public/pages/hosts/hosts.tsx | 6 +- .../public/pages/hosts/hosts_empty_page.tsx | 32 +++-- .../pages/network/ip_details/index.test.tsx | 16 +-- .../public/pages/network/ip_details/index.tsx | 6 +- .../public/pages/network/network.test.tsx | 16 +-- .../siem/public/pages/network/network.tsx | 6 +- .../pages/network/network_empty_page.tsx | 33 +++-- .../public/pages/overview/overview.test.tsx | 12 +- .../siem/public/pages/overview/overview.tsx | 5 +- .../siem/public/pages/overview/summary.tsx | 132 ++++++++++-------- .../utils/saved_query_services/index.tsx | 12 +- 166 files changed, 853 insertions(+), 1127 deletions(-) delete mode 100644 x-pack/legacy/plugins/siem/public/lib/compose/__mocks__/kibana_core.ts delete mode 100644 x-pack/legacy/plugins/siem/public/lib/compose/__mocks__/kibana_plugins.ts delete mode 100644 x-pack/legacy/plugins/siem/public/lib/compose/kibana_core.tsx delete mode 100644 x-pack/legacy/plugins/siem/public/lib/compose/kibana_plugins.tsx create mode 100644 x-pack/legacy/plugins/siem/public/lib/kibana/__mocks__/index.ts create mode 100644 x-pack/legacy/plugins/siem/public/lib/kibana/index.ts delete mode 100644 x-pack/legacy/plugins/siem/public/lib/settings/__mocks__/use_kibana_ui_setting.ts delete mode 100644 x-pack/legacy/plugins/siem/public/lib/settings/use_kibana_ui_setting.ts delete mode 100644 x-pack/legacy/plugins/siem/public/lib/settings/use_kibana_ui_settings.test.tsx delete mode 100644 x-pack/legacy/plugins/siem/public/lib/settings/use_observable.ts create mode 100644 x-pack/legacy/plugins/siem/public/mock/kibana_core.ts create mode 100644 x-pack/legacy/plugins/siem/public/mock/kibana_react.ts delete mode 100644 x-pack/legacy/plugins/siem/public/mock/ui_settings.ts diff --git a/x-pack/legacy/plugins/siem/public/apps/plugin.tsx b/x-pack/legacy/plugins/siem/public/apps/plugin.tsx index 1f19841788ddb..700fec2557b1b 100644 --- a/x-pack/legacy/plugins/siem/public/apps/plugin.tsx +++ b/x-pack/legacy/plugins/siem/public/apps/plugin.tsx @@ -15,6 +15,12 @@ import template from './template.html'; export const ROOT_ELEMENT_ID = 'react-siem-root'; +export type StartCore = LegacyCoreStart; +export type StartPlugins = Required< + Pick +>; +export type StartServices = StartCore & StartPlugins; + export class Plugin { constructor( // @ts-ignore this is added to satisfy the New Platform typing constraint, @@ -25,7 +31,7 @@ export class Plugin { this.chrome = chrome; } - public start(core: LegacyCoreStart, plugins: PluginsStart) { + public start(core: StartCore, plugins: StartPlugins) { // @ts-ignore improper type description this.chrome.setRootTemplate(template); const checkForRoot = () => { diff --git a/x-pack/legacy/plugins/siem/public/apps/start_app.tsx b/x-pack/legacy/plugins/siem/public/apps/start_app.tsx index 4549db946b815..6b7e3a7b8084f 100644 --- a/x-pack/legacy/plugins/siem/public/apps/start_app.tsx +++ b/x-pack/legacy/plugins/siem/public/apps/start_app.tsx @@ -9,8 +9,6 @@ import React, { memo, FC } from 'react'; import { ApolloProvider } from 'react-apollo'; import { Provider as ReduxStoreProvider } from 'react-redux'; import { ThemeProvider } from 'styled-components'; -import { LegacyCoreStart } from 'kibana/public'; -import { PluginsStart } from 'ui/new_platform/new_platform'; import { EuiErrorBoundary } from '@elastic/eui'; import euiDarkVars from '@elastic/eui/dist/eui_theme_dark.json'; @@ -19,16 +17,14 @@ import { BehaviorSubject } from 'rxjs'; import { pluck } from 'rxjs/operators'; import { I18nContext } from 'ui/i18n'; -import { KibanaContextProvider } from '../../../../../../src/plugins/kibana_react/public'; +import { KibanaContextProvider, useUiSetting$ } from '../lib/kibana'; import { Storage } from '../../../../../../src/plugins/kibana_utils/public'; import { DEFAULT_DARK_MODE } from '../../common/constants'; import { ErrorToastDispatcher } from '../components/error_toast_dispatcher'; import { compose } from '../lib/compose/kibana_compose'; import { AppFrontendLibs } from '../lib/lib'; -import { KibanaCoreContextProvider } from '../lib/compose/kibana_core'; -import { KibanaPluginsContextProvider } from '../lib/compose/kibana_plugins'; -import { useKibanaUiSetting } from '../lib/settings/use_kibana_ui_setting'; +import { StartCore, StartPlugins } from './plugin'; import { PageRouter } from '../routes'; import { createStore } from '../store'; import { GlobalToaster, ManageGlobalToaster } from '../components/toasters'; @@ -44,7 +40,7 @@ const StartApp: FC = memo(libs => { const store = createStore(undefined, libs$.pipe(pluck('apolloClient'))); const AppPluginRoot = memo(() => { - const [darkMode] = useKibanaUiSetting(DEFAULT_DARK_MODE); + const [darkMode] = useUiSetting$(DEFAULT_DARK_MODE); return ( @@ -77,21 +73,15 @@ const StartApp: FC = memo(libs => { export const ROOT_ELEMENT_ID = 'react-siem-root'; -export const SiemApp = memo<{ core: LegacyCoreStart; plugins: PluginsStart }>( - ({ core, plugins }) => ( - - - - - - - - ) -); +export const SiemApp = memo<{ core: StartCore; plugins: StartPlugins }>(({ core, plugins }) => ( + + + +)); diff --git a/x-pack/legacy/plugins/siem/public/components/bytes/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/bytes/index.test.tsx index 2321b06c07cc0..6816bff24f1cd 100644 --- a/x-pack/legacy/plugins/siem/public/components/bytes/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/bytes/index.test.tsx @@ -12,8 +12,6 @@ import { useMountAppended } from '../../utils/use_mount_appended'; import { Bytes } from '.'; -jest.mock('../../lib/settings/use_kibana_ui_setting'); - describe('Bytes', () => { const mount = useMountAppended(); diff --git a/x-pack/legacy/plugins/siem/public/components/charts/areachart.test.tsx b/x-pack/legacy/plugins/siem/public/components/charts/areachart.test.tsx index 25bd2a9d56059..2b99efc05fd8c 100644 --- a/x-pack/legacy/plugins/siem/public/components/charts/areachart.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/charts/areachart.test.tsx @@ -11,6 +11,8 @@ import { AreaChartBaseComponent, AreaChartComponent } from './areachart'; import { ChartSeriesData } from './common'; import { ScaleType, AreaSeries, Axis } from '@elastic/charts'; +jest.mock('../../lib/kibana'); + const customHeight = '100px'; const customWidth = '120px'; const chartDataSets = [ diff --git a/x-pack/legacy/plugins/siem/public/components/charts/areachart.tsx b/x-pack/legacy/plugins/siem/public/components/charts/areachart.tsx index c644d148cc1c3..297563c8e31cf 100644 --- a/x-pack/legacy/plugins/siem/public/components/charts/areachart.tsx +++ b/x-pack/legacy/plugins/siem/public/components/charts/areachart.tsx @@ -21,7 +21,6 @@ import { getOr, get, isNull, isNumber } from 'lodash/fp'; import { AutoSizer } from '../auto_sizer'; import { ChartPlaceHolder } from './chart_place_holder'; import { - browserTimezone, chartDefaultSettings, ChartSeriesConfigs, ChartSeriesData, @@ -29,6 +28,8 @@ import { getChartWidth, getSeriesStyle, WrappedByAutoSizer, + useTheme, + useBrowserTimeZone, } from './common'; // custom series styles: https://ela.st/areachart-styling @@ -72,12 +73,15 @@ export const AreaChartBaseComponent = ({ height: string | null | undefined; configs?: ChartSeriesConfigs | undefined; }) => { + const theme = useTheme(); + const timeZone = useBrowserTimeZone(); const xTickFormatter = get('configs.axis.xTickFormatter', chartConfigs); const yTickFormatter = get('configs.axis.yTickFormatter', chartConfigs); const xAxisId = getAxisId(`group-${data[0].key}-x`); const yAxisId = getAxisId(`group-${data[0].key}-y`); const settings = { ...chartDefaultSettings, + theme, ...get('configs.settings', chartConfigs), }; return chartConfigs.width && chartConfigs.height ? ( @@ -95,7 +99,7 @@ export const AreaChartBaseComponent = ({ data={series.value || undefined} xScaleType={getOr(ScaleType.Linear, 'configs.series.xScaleType', chartConfigs)} yScaleType={getOr(ScaleType.Linear, 'configs.series.yScaleType', chartConfigs)} - timeZone={browserTimezone} + timeZone={timeZone} xAccessor="x" yAccessors={['y']} areaSeriesStyle={getSeriesLineStyle()} diff --git a/x-pack/legacy/plugins/siem/public/components/charts/barchart.test.tsx b/x-pack/legacy/plugins/siem/public/components/charts/barchart.test.tsx index e28d330d31ba9..506b1ceb5ed83 100644 --- a/x-pack/legacy/plugins/siem/public/components/charts/barchart.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/charts/barchart.test.tsx @@ -11,6 +11,8 @@ import { BarChartBaseComponent, BarChartComponent } from './barchart'; import { ChartSeriesData } from './common'; import { BarSeries, ScaleType, Axis } from '@elastic/charts'; +jest.mock('../../lib/kibana'); + const customHeight = '100px'; const customWidth = '120px'; const chartDataSets = [ diff --git a/x-pack/legacy/plugins/siem/public/components/charts/barchart.tsx b/x-pack/legacy/plugins/siem/public/components/charts/barchart.tsx index 99ad995e48852..ee8b4eaf6b08c 100644 --- a/x-pack/legacy/plugins/siem/public/components/charts/barchart.tsx +++ b/x-pack/legacy/plugins/siem/public/components/charts/barchart.tsx @@ -19,16 +19,17 @@ import { getOr, get, isNumber } from 'lodash/fp'; import { AutoSizer } from '../auto_sizer'; import { ChartPlaceHolder } from './chart_place_holder'; import { - browserTimezone, chartDefaultSettings, ChartSeriesConfigs, ChartSeriesData, checkIfAllValuesAreZero, - getSeriesStyle, getChartHeight, getChartWidth, + getSeriesStyle, SeriesType, WrappedByAutoSizer, + useBrowserTimeZone, + useTheme, } from './common'; const checkIfAllTheDataInTheSeriesAreValid = (series: ChartSeriesData): series is ChartSeriesData => @@ -53,6 +54,8 @@ export const BarChartBaseComponent = ({ height: string | null | undefined; configs?: ChartSeriesConfigs | undefined; }) => { + const theme = useTheme(); + const timeZone = useBrowserTimeZone(); const xTickFormatter = get('configs.axis.xTickFormatter', chartConfigs); const yTickFormatter = get('configs.axis.yTickFormatter', chartConfigs); const tickSize = getOr(0, 'configs.axis.tickSize', chartConfigs); @@ -60,6 +63,7 @@ export const BarChartBaseComponent = ({ const yAxisId = getAxisId(`stat-items-barchart-${data[0].key}-y`); const settings = { ...chartDefaultSettings, + theme, ...get('configs.settings', chartConfigs), }; @@ -79,7 +83,7 @@ export const BarChartBaseComponent = ({ yScaleType={getOr(ScaleType.Linear, 'configs.series.yScaleType', chartConfigs)} xAccessor="x" yAccessors={['y']} - timeZone={browserTimezone} + timeZone={timeZone} splitSeriesAccessors={['g']} data={series.value!} stackAccessors={get('configs.series.stackAccessors', chartConfigs)} diff --git a/x-pack/legacy/plugins/siem/public/components/charts/common.test.tsx b/x-pack/legacy/plugins/siem/public/components/charts/common.test.tsx index 0bb4da69a978a..e9df0d3885a18 100644 --- a/x-pack/legacy/plugins/siem/public/components/charts/common.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/charts/common.test.tsx @@ -5,23 +5,27 @@ */ import { shallow } from 'enzyme'; import React from 'react'; +import { renderHook } from '@testing-library/react-hooks'; + +import { useUiSetting } from '../../lib/kibana'; import { checkIfAllValuesAreZero, defaultChartHeight, getChartHeight, getChartWidth, getSeriesStyle, - getTheme, SeriesType, WrappedByAutoSizer, ChartSeriesData, + useTheme, } from './common'; -import { mergeWithDefaultTheme, LIGHT_THEME } from '@elastic/charts'; + +jest.mock('../../lib/kibana'); jest.mock('@elastic/charts', () => { return { + ...jest.requireActual('@elastic/charts'), getSpecId: jest.fn(() => {}), - mergeWithDefaultTheme: jest.fn(), }; }); @@ -57,21 +61,6 @@ describe('getSeriesStyle', () => { }); }); -describe('getTheme', () => { - it('should merge custom theme with default theme', () => { - const defaultTheme = { - chartMargins: { bottom: 0, left: 0, right: 0, top: 4 }, - chartPaddings: { bottom: 0, left: 0, right: 0, top: 0 }, - scales: { - barsPadding: 0.05, - }, - }; - getTheme(); - expect((mergeWithDefaultTheme as jest.Mock).mock.calls[0][0]).toMatchObject(defaultTheme); - expect((mergeWithDefaultTheme as jest.Mock).mock.calls[0][1]).toEqual(LIGHT_THEME); - }); -}); - describe('getChartHeight', () => { it('should render customHeight', () => { const height = getChartHeight(10, 100); @@ -197,4 +186,23 @@ describe('checkIfAllValuesAreZero', () => { expect(result).toBeTruthy(); }); }); + + describe('useTheme', () => { + it('merges our spacing with the default theme', () => { + const { result } = renderHook(() => useTheme()); + + expect(result.current).toEqual( + expect.objectContaining({ chartMargins: expect.objectContaining({ top: 4, bottom: 0 }) }) + ); + }); + + it('returns a different theme depending on user settings', () => { + const { result: defaultResult } = renderHook(() => useTheme()); + (useUiSetting as jest.Mock).mockImplementation(() => true); + + const { result: darkResult } = renderHook(() => useTheme()); + + expect(defaultResult.current).not.toMatchObject(darkResult.current); + }); + }); }); diff --git a/x-pack/legacy/plugins/siem/public/components/charts/common.tsx b/x-pack/legacy/plugins/siem/public/components/charts/common.tsx index 7ac91437920e5..dfb201fc3d927 100644 --- a/x-pack/legacy/plugins/siem/public/components/charts/common.tsx +++ b/x-pack/legacy/plugins/siem/public/components/charts/common.tsx @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import chrome from 'ui/chrome'; import { CustomSeriesColorsMap, DARK_THEME, @@ -21,6 +20,7 @@ import { } from '@elastic/charts'; import moment from 'moment-timezone'; import styled from 'styled-components'; +import { useUiSetting } from '../../lib/kibana'; import { DEFAULT_DATE_FORMAT_TZ, DEFAULT_DARK_MODE } from '../../../common/constants'; export const defaultChartHeight = '100%'; @@ -95,27 +95,28 @@ export const getSeriesStyle = ( }; // Apply margins and paddings: https://ela.st/charts-spacing -export const getTheme = () => { - const theme: PartialTheme = { - chartMargins: { - left: 0, - right: 0, - // Apply some paddings to the top to avoid chopping the y tick https://ela.st/chopping-edge - top: 4, - bottom: 0, - }, - chartPaddings: { - left: 0, - right: 0, - top: 0, - bottom: 0, - }, - scales: { - barsPadding: 0.05, - }, - }; - const isDarkMode: boolean = chrome.getUiSettingsClient().get(DEFAULT_DARK_MODE); +const theme: PartialTheme = { + chartMargins: { + left: 0, + right: 0, + // Apply some paddings to the top to avoid chopping the y tick https://ela.st/chopping-edge + top: 4, + bottom: 0, + }, + chartPaddings: { + left: 0, + right: 0, + top: 0, + bottom: 0, + }, + scales: { + barsPadding: 0.05, + }, +}; +export const useTheme = () => { + const isDarkMode = useUiSetting(DEFAULT_DARK_MODE); const defaultTheme = isDarkMode ? DARK_THEME : LIGHT_THEME; + return mergeWithDefaultTheme(theme, defaultTheme); }; @@ -126,11 +127,12 @@ export const chartDefaultSettings = { showLegend: false, showLegendDisplayValue: false, debug: false, - theme: getTheme(), }; -const kibanaTimezone: string = chrome.getUiSettingsClient().get(DEFAULT_DATE_FORMAT_TZ); -export const browserTimezone = kibanaTimezone === 'Browser' ? moment.tz.guess() : kibanaTimezone; +export const useBrowserTimeZone = () => { + const kibanaTimezone = useUiSetting(DEFAULT_DATE_FORMAT_TZ); + return kibanaTimezone === 'Browser' ? moment.tz.guess() : kibanaTimezone; +}; export const getChartHeight = (customHeight?: number, autoSizerHeight?: number): string => { const height = customHeight || autoSizerHeight; diff --git a/x-pack/legacy/plugins/siem/public/components/detection_engine/utility_bar/utility_bar.test.tsx b/x-pack/legacy/plugins/siem/public/components/detection_engine/utility_bar/utility_bar.test.tsx index 68522377bd847..a5eac381f9215 100644 --- a/x-pack/legacy/plugins/siem/public/components/detection_engine/utility_bar/utility_bar.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/detection_engine/utility_bar/utility_bar.test.tsx @@ -9,7 +9,6 @@ import { mount, shallow } from 'enzyme'; import toJson from 'enzyme-to-json'; import React from 'react'; -import '../../../mock/ui_settings'; import { TestProviders } from '../../../mock'; import { UtilityBar, @@ -19,8 +18,6 @@ import { UtilityBarText, } from './index'; -jest.mock('../../../lib/settings/use_kibana_ui_setting'); - describe('UtilityBar', () => { test('it renders', () => { const wrapper = shallow( diff --git a/x-pack/legacy/plugins/siem/public/components/detection_engine/utility_bar/utility_bar_action.test.tsx b/x-pack/legacy/plugins/siem/public/components/detection_engine/utility_bar/utility_bar_action.test.tsx index 7921c1ef42200..2610fb44532f5 100644 --- a/x-pack/legacy/plugins/siem/public/components/detection_engine/utility_bar/utility_bar_action.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/detection_engine/utility_bar/utility_bar_action.test.tsx @@ -8,12 +8,9 @@ import { mount, shallow } from 'enzyme'; import toJson from 'enzyme-to-json'; import React from 'react'; -import '../../../mock/ui_settings'; import { TestProviders } from '../../../mock'; import { UtilityBarAction } from './index'; -jest.mock('../../../lib/settings/use_kibana_ui_setting'); - describe('UtilityBarAction', () => { test('it renders', () => { const wrapper = shallow( diff --git a/x-pack/legacy/plugins/siem/public/components/detection_engine/utility_bar/utility_bar_group.test.tsx b/x-pack/legacy/plugins/siem/public/components/detection_engine/utility_bar/utility_bar_group.test.tsx index 294d27fa95b3d..59ef7021d4049 100644 --- a/x-pack/legacy/plugins/siem/public/components/detection_engine/utility_bar/utility_bar_group.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/detection_engine/utility_bar/utility_bar_group.test.tsx @@ -8,12 +8,9 @@ import { shallow } from 'enzyme'; import toJson from 'enzyme-to-json'; import React from 'react'; -import '../../../mock/ui_settings'; import { TestProviders } from '../../../mock'; import { UtilityBarGroup, UtilityBarText } from './index'; -jest.mock('../../../lib/settings/use_kibana_ui_setting'); - describe('UtilityBarGroup', () => { test('it renders', () => { const wrapper = shallow( diff --git a/x-pack/legacy/plugins/siem/public/components/detection_engine/utility_bar/utility_bar_section.test.tsx b/x-pack/legacy/plugins/siem/public/components/detection_engine/utility_bar/utility_bar_section.test.tsx index e0e0acc3a71c9..baa4331ced8f8 100644 --- a/x-pack/legacy/plugins/siem/public/components/detection_engine/utility_bar/utility_bar_section.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/detection_engine/utility_bar/utility_bar_section.test.tsx @@ -8,12 +8,9 @@ import { shallow } from 'enzyme'; import toJson from 'enzyme-to-json'; import React from 'react'; -import '../../../mock/ui_settings'; import { TestProviders } from '../../../mock'; import { UtilityBarGroup, UtilityBarSection, UtilityBarText } from './index'; -jest.mock('../../../lib/settings/use_kibana_ui_setting'); - describe('UtilityBarSection', () => { test('it renders', () => { const wrapper = shallow( diff --git a/x-pack/legacy/plugins/siem/public/components/detection_engine/utility_bar/utility_bar_text.test.tsx b/x-pack/legacy/plugins/siem/public/components/detection_engine/utility_bar/utility_bar_text.test.tsx index 29e1844bb2d4f..794f207fd88e3 100644 --- a/x-pack/legacy/plugins/siem/public/components/detection_engine/utility_bar/utility_bar_text.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/detection_engine/utility_bar/utility_bar_text.test.tsx @@ -8,12 +8,9 @@ import { shallow } from 'enzyme'; import toJson from 'enzyme-to-json'; import React from 'react'; -import '../../../mock/ui_settings'; import { TestProviders } from '../../../mock'; import { UtilityBarText } from './index'; -jest.mock('../../../lib/settings/use_kibana_ui_setting'); - describe('UtilityBarText', () => { test('it renders', () => { const wrapper = shallow( diff --git a/x-pack/legacy/plugins/siem/public/components/embeddables/__snapshots__/embedded_map.test.tsx.snap b/x-pack/legacy/plugins/siem/public/components/embeddables/__snapshots__/embedded_map.test.tsx.snap index 2444fd0bc2b7d..d5de7ab508a73 100644 --- a/x-pack/legacy/plugins/siem/public/components/embeddables/__snapshots__/embedded_map.test.tsx.snap +++ b/x-pack/legacy/plugins/siem/public/components/embeddables/__snapshots__/embedded_map.test.tsx.snap @@ -9,7 +9,7 @@ exports[`EmbeddedMapComponent renders correctly against snapshot 1`] = ` size="xs" > Map configuration help diff --git a/x-pack/legacy/plugins/siem/public/components/embeddables/__snapshots__/index_patterns_missing_prompt.test.tsx.snap b/x-pack/legacy/plugins/siem/public/components/embeddables/__snapshots__/index_patterns_missing_prompt.test.tsx.snap index 6794aab205703..2eefdf767dce1 100644 --- a/x-pack/legacy/plugins/siem/public/components/embeddables/__snapshots__/index_patterns_missing_prompt.test.tsx.snap +++ b/x-pack/legacy/plugins/siem/public/components/embeddables/__snapshots__/index_patterns_missing_prompt.test.tsx.snap @@ -21,7 +21,7 @@ exports[`IndexPatternsMissingPrompt renders correctly against snapshot 1`] = ` values={ Object { "beats": diff --git a/x-pack/legacy/plugins/siem/public/components/embeddables/embeddable.test.tsx b/x-pack/legacy/plugins/siem/public/components/embeddables/embeddable.test.tsx index c0d70754e78bd..884d5bc348d6f 100644 --- a/x-pack/legacy/plugins/siem/public/components/embeddables/embeddable.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/embeddables/embeddable.test.tsx @@ -8,11 +8,8 @@ import { shallow } from 'enzyme'; import toJson from 'enzyme-to-json'; import React from 'react'; -import '../../mock/ui_settings'; import { Embeddable } from './embeddable'; -jest.mock('../../lib/settings/use_kibana_ui_setting'); - describe('Embeddable', () => { test('it renders', () => { const wrapper = shallow( diff --git a/x-pack/legacy/plugins/siem/public/components/embeddables/embeddable_header.test.tsx b/x-pack/legacy/plugins/siem/public/components/embeddables/embeddable_header.test.tsx index 6387de30aa265..aa247b69eb4eb 100644 --- a/x-pack/legacy/plugins/siem/public/components/embeddables/embeddable_header.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/embeddables/embeddable_header.test.tsx @@ -8,12 +8,9 @@ import { mount, shallow } from 'enzyme'; import toJson from 'enzyme-to-json'; import React from 'react'; -import '../../mock/ui_settings'; import { TestProviders } from '../../mock'; import { EmbeddableHeader } from './embeddable_header'; -jest.mock('../../lib/settings/use_kibana_ui_setting'); - describe('EmbeddableHeader', () => { test('it renders', () => { const wrapper = shallow(); diff --git a/x-pack/legacy/plugins/siem/public/components/embeddables/embedded_map.test.tsx b/x-pack/legacy/plugins/siem/public/components/embeddables/embedded_map.test.tsx index 1ed1075542f71..007916595fd6a 100644 --- a/x-pack/legacy/plugins/siem/public/components/embeddables/embedded_map.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/embeddables/embedded_map.test.tsx @@ -7,10 +7,10 @@ import { shallow } from 'enzyme'; import toJson from 'enzyme-to-json'; import * as React from 'react'; + +import { useIndexPatterns } from '../../hooks/use_index_patterns'; import { EmbeddedMapComponent } from './embedded_map'; import { SetQuery } from './types'; -import { useKibanaCore } from '../../lib/compose/kibana_core'; -import { useIndexPatterns } from '../../hooks/use_index_patterns'; jest.mock('../search_bar', () => ({ siemFilterManager: { @@ -22,22 +22,7 @@ const mockUseIndexPatterns = useIndexPatterns as jest.Mock; jest.mock('../../hooks/use_index_patterns'); mockUseIndexPatterns.mockImplementation(() => [true, []]); -const mockUseKibanaCore = useKibanaCore as jest.Mock; -jest.mock('../../lib/compose/kibana_core'); -mockUseKibanaCore.mockImplementation(() => ({ - uiSettings: { - get$: () => 'world', - }, - injectedMetadata: { - getKibanaVersion: () => '8.0.0', - }, -})); - -jest.mock('../../lib/compose/kibana_plugins'); - -jest.mock('ui/vis/lib/timezone', () => ({ - timezoneProvider: () => () => 'America/New_York', -})); +jest.mock('../../lib/kibana'); describe('EmbeddedMapComponent', () => { let setQuery: SetQuery; diff --git a/x-pack/legacy/plugins/siem/public/components/embeddables/embedded_map.tsx b/x-pack/legacy/plugins/siem/public/components/embeddables/embedded_map.tsx index e33539af0bfe8..b39d43cc01b42 100644 --- a/x-pack/legacy/plugins/siem/public/components/embeddables/embedded_map.tsx +++ b/x-pack/legacy/plugins/siem/public/components/embeddables/embedded_map.tsx @@ -8,16 +8,12 @@ import { EuiLink, EuiText } from '@elastic/eui'; import React, { useEffect, useState } from 'react'; import { createPortalNode, InPortal } from 'react-reverse-portal'; import styled, { css } from 'styled-components'; -import { ELASTIC_WEBSITE_URL, DOC_LINK_VERSION } from 'ui/documentation_links'; import { EmbeddablePanel } from '../../../../../../../src/legacy/core_plugins/embeddable_api/public/np_ready/public'; import { start } from '../../../../../../../src/legacy/core_plugins/embeddable_api/public/np_ready/public/legacy'; import { DEFAULT_INDEX_KEY } from '../../../common/constants'; import { getIndexPatternTitleIdMapping } from '../../hooks/api/helpers'; import { useIndexPatterns } from '../../hooks/use_index_patterns'; -import { useKibanaCore } from '../../lib/compose/kibana_core'; -import { useKibanaPlugins } from '../../lib/compose/kibana_plugins'; -import { useKibanaUiSetting } from '../../lib/settings/use_kibana_ui_setting'; import { Loader } from '../loader'; import { useStateToaster } from '../toasters'; import { Embeddable } from './embeddable'; @@ -28,6 +24,7 @@ import { MapToolTip } from './map_tool_tip/map_tool_tip'; import * as i18n from './translations'; import { MapEmbeddable, SetQuery } from './types'; import { Query, esFilters } from '../../../../../../../src/plugins/data/public'; +import { useKibana, useUiSetting$ } from '../../lib/kibana'; import { SavedObjectFinderProps, SavedObjectFinderUi, @@ -96,7 +93,7 @@ export const EmbeddedMapComponent = ({ const [, dispatchToaster] = useStateToaster(); const [loadingKibanaIndexPatterns, kibanaIndexPatterns] = useIndexPatterns(); - const [siemDefaultIndices] = useKibanaUiSetting(DEFAULT_INDEX_KEY); + const [siemDefaultIndices] = useUiSetting$(DEFAULT_INDEX_KEY); // This portalNode provided by react-reverse-portal allows us re-parent the MapToolTip within our // own component tree instead of the embeddables (default). This is necessary to have access to @@ -104,8 +101,7 @@ export const EmbeddedMapComponent = ({ // Search InPortal/OutPortal for implementation touch points const portalNode = React.useMemo(() => createPortalNode(), []); - const plugins = useKibanaPlugins(); - const core = useKibanaCore(); + const { services } = useKibana(); // Initial Load useEffect useEffect(() => { @@ -131,7 +127,7 @@ export const EmbeddedMapComponent = ({ endDate, setQuery, portalNode, - plugins.embeddable + services.embeddable ); if (isSubscribed) { setEmbeddable(embeddableObject); @@ -180,7 +176,11 @@ export const EmbeddedMapComponent = ({ }, [startDate, endDate]); const SavedObjectFinder = (props: SavedObjectFinderProps) => ( - + ); return isError ? null : ( @@ -188,7 +188,7 @@ export const EmbeddedMapComponent = ({ {i18n.EMBEDDABLE_HEADER_HELP} @@ -205,12 +205,12 @@ export const EmbeddedMapComponent = ({ ) : !isLoading && isIndexError ? ( diff --git a/x-pack/legacy/plugins/siem/public/components/embeddables/embedded_map_helpers.test.tsx b/x-pack/legacy/plugins/siem/public/components/embeddables/embedded_map_helpers.test.tsx index b4b2b98ddb8d6..4e5fcee439827 100644 --- a/x-pack/legacy/plugins/siem/public/components/embeddables/embedded_map_helpers.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/embeddables/embedded_map_helpers.test.tsx @@ -9,7 +9,6 @@ import { createUiNewPlatformMock } from 'ui/new_platform/__mocks__/helpers'; import { createPortalNode } from 'react-reverse-portal'; jest.mock('ui/new_platform'); -jest.mock('../../lib/settings/use_kibana_ui_setting'); jest.mock('uuid', () => { return { diff --git a/x-pack/legacy/plugins/siem/public/components/embeddables/index_patterns_missing_prompt.test.tsx b/x-pack/legacy/plugins/siem/public/components/embeddables/index_patterns_missing_prompt.test.tsx index d32b62900431c..d04329edff475 100644 --- a/x-pack/legacy/plugins/siem/public/components/embeddables/index_patterns_missing_prompt.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/embeddables/index_patterns_missing_prompt.test.tsx @@ -7,12 +7,10 @@ import { shallow } from 'enzyme'; import toJson from 'enzyme-to-json'; import * as React from 'react'; + import { IndexPatternsMissingPromptComponent } from './index_patterns_missing_prompt'; -jest.mock('ui/documentation_links', () => ({ - ELASTIC_WEBSITE_URL: 'https://www.elastic.co', - DOC_LINK_VERSION: 'current', -})); +jest.mock('../../lib/kibana'); describe('IndexPatternsMissingPrompt', () => { test('renders correctly against snapshot', () => { diff --git a/x-pack/legacy/plugins/siem/public/components/embeddables/index_patterns_missing_prompt.tsx b/x-pack/legacy/plugins/siem/public/components/embeddables/index_patterns_missing_prompt.tsx index 6533be49c3430..798e3d2c10f97 100644 --- a/x-pack/legacy/plugins/siem/public/components/embeddables/index_patterns_missing_prompt.tsx +++ b/x-pack/legacy/plugins/siem/public/components/embeddables/index_patterns_missing_prompt.tsx @@ -8,66 +8,70 @@ import { EuiButton, EuiCode, EuiEmptyPrompt } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; import * as React from 'react'; import chrome from 'ui/chrome'; -import { ELASTIC_WEBSITE_URL, DOC_LINK_VERSION } from 'ui/documentation_links'; +import { useKibana } from '../../lib/kibana'; import * as i18n from './translations'; -export const IndexPatternsMissingPromptComponent = () => ( - {i18n.ERROR_TITLE}} - titleSize="xs" - body={ - <> -

- - {'siem:defaultIndex'} - - ), - beats: ( - - {'beats'} - - ), - setup: {'setup'}, - example: {'./packetbeat setup'}, - }} - /> -

+export const IndexPatternsMissingPromptComponent = () => { + const docLinks = useKibana().services.docLinks; -

- -

- - } - actions={ - - {i18n.ERROR_BUTTON} - - } - /> -); + return ( + {i18n.ERROR_TITLE}} + titleSize="xs" + body={ + <> +

+ + {'siem:defaultIndex'} + + ), + beats: ( + + {'beats'} + + ), + setup: {'setup'}, + example: {'./packetbeat setup'}, + }} + /> +

+ +

+ +

+ + } + actions={ + + {i18n.ERROR_BUTTON} + + } + /> + ); +}; IndexPatternsMissingPromptComponent.displayName = 'IndexPatternsMissingPromptComponent'; diff --git a/x-pack/legacy/plugins/siem/public/components/event_details/event_details.test.tsx b/x-pack/legacy/plugins/siem/public/components/event_details/event_details.test.tsx index f1e96392d6afc..d97da7797bb45 100644 --- a/x-pack/legacy/plugins/siem/public/components/event_details/event_details.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/event_details/event_details.test.tsx @@ -16,8 +16,6 @@ import { mockBrowserFields } from '../../containers/source/mock'; import { defaultHeaders } from '../../mock/header'; import { useMountAppended } from '../../utils/use_mount_appended'; -jest.mock('../../lib/settings/use_kibana_ui_setting'); - describe('EventDetails', () => { const mount = useMountAppended(); diff --git a/x-pack/legacy/plugins/siem/public/components/event_details/event_fields_browser.test.tsx b/x-pack/legacy/plugins/siem/public/components/event_details/event_fields_browser.test.tsx index 2c28ab8696f0e..25f95bfa1d383 100644 --- a/x-pack/legacy/plugins/siem/public/components/event_details/event_fields_browser.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/event_details/event_fields_browser.test.tsx @@ -14,7 +14,7 @@ import { mockBrowserFields } from '../../containers/source/mock'; import { defaultHeaders } from '../../mock/header'; import { useMountAppended } from '../../utils/use_mount_appended'; -jest.mock('../../lib/settings/use_kibana_ui_setting'); +jest.mock('../../lib/kibana'); describe('EventFieldsBrowser', () => { const mount = useMountAppended(); diff --git a/x-pack/legacy/plugins/siem/public/components/events_viewer/events_viewer.test.tsx b/x-pack/legacy/plugins/siem/public/components/events_viewer/events_viewer.test.tsx index 5ddf17bd77d74..b44d83c27a60d 100644 --- a/x-pack/legacy/plugins/siem/public/components/events_viewer/events_viewer.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/events_viewer/events_viewer.test.tsx @@ -8,25 +8,17 @@ import React from 'react'; import { MockedProvider } from 'react-apollo/test-utils'; import { mockIndexPattern, TestProviders } from '../../mock'; -import { mockUiSettings } from '../../mock/ui_settings'; import { wait } from '../../lib/helpers'; import { mockEventViewerResponse } from './mock'; import { StatefulEventsViewer } from '.'; import { defaultHeaders } from './default_headers'; -import { useKibanaCore } from '../../lib/compose/kibana_core'; import { useFetchIndexPatterns } from '../../containers/detection_engine/rules/fetch_index_patterns'; import { mockBrowserFields } from '../../containers/source/mock'; import { eventsDefaultModel } from './default_model'; import { useMountAppended } from '../../utils/use_mount_appended'; -jest.mock('../../lib/settings/use_kibana_ui_setting'); - -const mockUseKibanaCore = useKibanaCore as jest.Mock; -jest.mock('../../lib/compose/kibana_core'); -mockUseKibanaCore.mockImplementation(() => ({ - uiSettings: mockUiSettings, -})); +jest.mock('../../lib/kibana'); const mockUseFetchIndexPatterns: jest.Mock = useFetchIndexPatterns as jest.Mock; jest.mock('../../containers/detection_engine/rules/fetch_index_patterns'); diff --git a/x-pack/legacy/plugins/siem/public/components/events_viewer/events_viewer.tsx b/x-pack/legacy/plugins/siem/public/components/events_viewer/events_viewer.tsx index 7c4369e952d6f..aaf88e68684ca 100644 --- a/x-pack/legacy/plugins/siem/public/components/events_viewer/events_viewer.tsx +++ b/x-pack/legacy/plugins/siem/public/components/events_viewer/events_viewer.tsx @@ -12,7 +12,7 @@ import styled from 'styled-components'; import { BrowserFields } from '../../containers/source'; import { TimelineQuery } from '../../containers/timeline'; import { Direction } from '../../graphql/types'; -import { useKibanaCore } from '../../lib/compose/kibana_core'; +import { useKibana } from '../../lib/kibana'; import { KqlMode } from '../../store/timeline/model'; import { AutoSizer } from '../auto_sizer'; import { HeaderSection } from '../header_section'; @@ -93,9 +93,9 @@ export const EventsViewer = React.memo( utilityBar, }) => { const columnsHeader = isEmpty(columns) ? defaultHeaders : columns; - const core = useKibanaCore(); + const kibana = useKibana(); const combinedQueries = combineQueries({ - config: esQuery.getEsQueryConfig(core.uiSettings), + config: esQuery.getEsQueryConfig(kibana.services.uiSettings), dataProviders, indexPattern, browserFields, diff --git a/x-pack/legacy/plugins/siem/public/components/events_viewer/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/events_viewer/index.test.tsx index e46153c18c2b5..27c3abf7f6824 100644 --- a/x-pack/legacy/plugins/siem/public/components/events_viewer/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/events_viewer/index.test.tsx @@ -7,10 +7,8 @@ import React from 'react'; import { MockedProvider } from 'react-apollo/test-utils'; -import { useKibanaCore } from '../../lib/compose/kibana_core'; import { wait } from '../../lib/helpers'; import { mockIndexPattern, TestProviders } from '../../mock'; -import { mockUiSettings } from '../../mock/ui_settings'; import { useMountAppended } from '../../utils/use_mount_appended'; import { mockEventViewerResponse } from './mock'; @@ -19,13 +17,7 @@ import { useFetchIndexPatterns } from '../../containers/detection_engine/rules/f import { mockBrowserFields } from '../../containers/source/mock'; import { eventsDefaultModel } from './default_model'; -jest.mock('../../lib/settings/use_kibana_ui_setting'); - -const mockUseKibanaCore = useKibanaCore as jest.Mock; -jest.mock('../../lib/compose/kibana_core'); -mockUseKibanaCore.mockImplementation(() => ({ - uiSettings: mockUiSettings, -})); +jest.mock('../../lib/kibana'); const mockUseFetchIndexPatterns: jest.Mock = useFetchIndexPatterns as jest.Mock; jest.mock('../../containers/detection_engine/rules/fetch_index_patterns'); diff --git a/x-pack/legacy/plugins/siem/public/components/events_viewer/index.tsx b/x-pack/legacy/plugins/siem/public/components/events_viewer/index.tsx index 385352a62d5b3..9b8ec243d5f38 100644 --- a/x-pack/legacy/plugins/siem/public/components/events_viewer/index.tsx +++ b/x-pack/legacy/plugins/siem/public/components/events_viewer/index.tsx @@ -8,7 +8,6 @@ import { isEqual } from 'lodash/fp'; import React, { useCallback, useEffect, useState } from 'react'; import { connect } from 'react-redux'; import { ActionCreator } from 'typescript-fsa'; -import chrome from 'ui/chrome'; import { inputsModel, inputsSelectors, State, timelineSelectors } from '../../store'; import { inputsActions, timelineActions } from '../../store/actions'; import { KqlMode, SubsetTimelineModel, TimelineModel } from '../../store/timeline/model'; @@ -18,6 +17,7 @@ import { Sort } from '../timeline/body/sort'; import { OnChangeItemsPerPage } from '../timeline/events'; import { esFilters, Query } from '../../../../../../../src/plugins/data/public'; +import { useUiSetting } from '../../lib/kibana'; import { EventsViewer } from './events_viewer'; import { InputsModelId } from '../../store/inputs/constants'; import { useFetchIndexPatterns } from '../../containers/detection_engine/rules/fetch_index_patterns'; @@ -116,7 +116,7 @@ const StatefulEventsViewerComponent = React.memo( }) => { const [showInspect, setShowInspect] = useState(false); const [{ browserFields, indexPatterns }] = useFetchIndexPatterns( - defaultIndices ?? chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY) + defaultIndices ?? useUiSetting(DEFAULT_INDEX_KEY) ); useEffect(() => { diff --git a/x-pack/legacy/plugins/siem/public/components/flyout/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/flyout/index.test.tsx index 86a8952a10efa..be7e8fac70bf5 100644 --- a/x-pack/legacy/plugins/siem/public/components/flyout/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/flyout/index.test.tsx @@ -20,8 +20,6 @@ import { FlyoutButton } from './button'; const testFlyoutHeight = 980; const usersViewing = ['elastic']; -jest.mock('../../lib/settings/use_kibana_ui_setting'); - describe('Flyout', () => { const state: State = mockGlobalState; diff --git a/x-pack/legacy/plugins/siem/public/components/flyout/pane/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/flyout/pane/index.test.tsx index 66e9bc700b3a1..246261035508b 100644 --- a/x-pack/legacy/plugins/siem/public/components/flyout/pane/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/flyout/pane/index.test.tsx @@ -8,26 +8,15 @@ import { mount, shallow } from 'enzyme'; import toJson from 'enzyme-to-json'; import * as React from 'react'; -import { flyoutHeaderHeight } from '../'; -import { useKibanaCore } from '../../../lib/compose/kibana_core'; import { TestProviders } from '../../../mock'; -import { mockUiSettings } from '../../../mock/ui_settings'; +import { flyoutHeaderHeight } from '..'; import { Pane } from '.'; const testFlyoutHeight = 980; const testWidth = 640; const usersViewing = ['elastic']; -const mockUseKibanaCore = useKibanaCore as jest.Mock; -jest.mock('ui/new_platform'); -jest.mock('../../../lib/compose/kibana_core'); -mockUseKibanaCore.mockImplementation(() => ({ - uiSettings: mockUiSettings, -})); - -jest.mock('ui/vis/lib/timezone', () => ({ - timezoneProvider: () => () => 'America/New_York', -})); +jest.mock('../../../lib/kibana'); describe('Pane', () => { test('renders correctly against snapshot', () => { diff --git a/x-pack/legacy/plugins/siem/public/components/formatted_bytes/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/formatted_bytes/index.test.tsx index a517820361f9f..8c27a55d3a6b0 100644 --- a/x-pack/legacy/plugins/siem/public/components/formatted_bytes/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/formatted_bytes/index.test.tsx @@ -8,27 +8,25 @@ import { mount, shallow } from 'enzyme'; import toJson from 'enzyme-to-json'; import * as React from 'react'; -import { useKibanaUiSetting } from '../../lib/settings/use_kibana_ui_setting'; import { mockFrameworks, getMockKibanaUiSetting } from '../../mock'; +import { useUiSetting$ } from '../../lib/kibana'; import { PreferenceFormattedBytesComponent } from '.'; -const mockUseKibanaUiSetting: jest.Mock = useKibanaUiSetting as jest.Mock; -jest.mock('../../lib/settings/use_kibana_ui_setting', () => ({ - useKibanaUiSetting: jest.fn(), -})); +jest.mock('../../lib/kibana'); +const mockUseUiSetting$ = useUiSetting$ as jest.Mock; describe('formatted_bytes', () => { describe('PreferenceFormattedBytes', () => { describe('rendering', () => { beforeEach(() => { - mockUseKibanaUiSetting.mockClear(); + mockUseUiSetting$.mockClear(); }); const bytes = '2806422'; test('renders correctly against snapshot', () => { - mockUseKibanaUiSetting.mockImplementation( + mockUseUiSetting$.mockImplementation( getMockKibanaUiSetting(mockFrameworks.default_browser) ); const wrapper = shallow(); @@ -36,13 +34,13 @@ describe('formatted_bytes', () => { }); test('it renders bytes to hardcoded format when no configuration exists', () => { - mockUseKibanaUiSetting.mockImplementation(() => [null]); + mockUseUiSetting$.mockImplementation(() => [null]); const wrapper = mount(); expect(wrapper.text()).toEqual('2.7MB'); }); test('it renders bytes according to the default format', () => { - mockUseKibanaUiSetting.mockImplementation( + mockUseUiSetting$.mockImplementation( getMockKibanaUiSetting(mockFrameworks.default_browser) ); const wrapper = mount(); @@ -50,7 +48,7 @@ describe('formatted_bytes', () => { }); test('it renders bytes supplied as a number according to the default format', () => { - mockUseKibanaUiSetting.mockImplementation( + mockUseUiSetting$.mockImplementation( getMockKibanaUiSetting(mockFrameworks.default_browser) ); const wrapper = mount(); @@ -58,9 +56,7 @@ describe('formatted_bytes', () => { }); test('it renders bytes according to new format', () => { - mockUseKibanaUiSetting.mockImplementation( - getMockKibanaUiSetting(mockFrameworks.bytes_short) - ); + mockUseUiSetting$.mockImplementation(getMockKibanaUiSetting(mockFrameworks.bytes_short)); const wrapper = mount(); expect(wrapper.text()).toEqual('3MB'); }); diff --git a/x-pack/legacy/plugins/siem/public/components/formatted_bytes/index.tsx b/x-pack/legacy/plugins/siem/public/components/formatted_bytes/index.tsx index 408e8d7ad4d80..003ce0879b7b5 100644 --- a/x-pack/legacy/plugins/siem/public/components/formatted_bytes/index.tsx +++ b/x-pack/legacy/plugins/siem/public/components/formatted_bytes/index.tsx @@ -8,10 +8,10 @@ import * as React from 'react'; import numeral from '@elastic/numeral'; import { DEFAULT_BYTES_FORMAT } from '../../../common/constants'; -import { useKibanaUiSetting } from '../../lib/settings/use_kibana_ui_setting'; +import { useUiSetting$ } from '../../lib/kibana'; export const PreferenceFormattedBytesComponent = ({ value }: { value: string | number }) => { - const [bytesFormat] = useKibanaUiSetting(DEFAULT_BYTES_FORMAT); + const [bytesFormat] = useUiSetting$(DEFAULT_BYTES_FORMAT); return ( <>{bytesFormat ? numeral(value).format(bytesFormat) : numeral(value).format('0,0.[0]b')} ); diff --git a/x-pack/legacy/plugins/siem/public/components/formatted_date/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/formatted_date/index.test.tsx index df361a06d3805..dad1d5feb5c6e 100644 --- a/x-pack/legacy/plugins/siem/public/components/formatted_date/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/formatted_date/index.test.tsx @@ -9,24 +9,18 @@ import toJson from 'enzyme-to-json'; import moment from 'moment-timezone'; import * as React from 'react'; -import { useKibanaUiSetting } from '../../lib/settings/use_kibana_ui_setting'; +import { useUiSetting$ } from '../../lib/kibana'; import { mockFrameworks, TestProviders, MockFrameworks, getMockKibanaUiSetting } from '../../mock'; - -import { PreferenceFormattedDate, FormattedDate, FormattedRelativePreferenceDate } from '.'; import { getEmptyString, getEmptyValue } from '../empty_value'; +import { PreferenceFormattedDate, FormattedDate, FormattedRelativePreferenceDate } from '.'; -const mockUseKibanaUiSetting: jest.Mock = useKibanaUiSetting as jest.Mock; -jest.mock('../../lib/settings/use_kibana_ui_setting', () => ({ - useKibanaUiSetting: jest.fn(), -})); +jest.mock('../../lib/kibana'); +const mockUseUiSetting$ = useUiSetting$ as jest.Mock; describe('formatted_date', () => { describe('PreferenceFormattedDate', () => { describe('rendering', () => { - beforeEach(() => { - mockUseKibanaUiSetting.mockClear(); - }); const isoDateString = '2019-02-25T22:27:05.000Z'; const isoDate = new Date(isoDateString); const configFormattedDateString = (dateString: string, config: MockFrameworks): string => @@ -38,21 +32,19 @@ describe('formatted_date', () => { .format(config.dateFormat); test('renders correctly against snapshot', () => { - mockUseKibanaUiSetting.mockImplementation(() => [null]); + mockUseUiSetting$.mockImplementation(() => [null]); const wrapper = mount(); expect(toJson(wrapper)).toMatchSnapshot(); }); test('it renders the UTC ISO8601 date string supplied when no configuration exists', () => { - mockUseKibanaUiSetting.mockImplementation(() => [null]); + mockUseUiSetting$.mockImplementation(() => [null]); const wrapper = mount(); expect(wrapper.text()).toEqual(isoDateString); }); test('it renders the UTC ISO8601 date supplied when the default configuration exists', () => { - mockUseKibanaUiSetting.mockImplementation( - getMockKibanaUiSetting(mockFrameworks.default_UTC) - ); + mockUseUiSetting$.mockImplementation(getMockKibanaUiSetting(mockFrameworks.default_UTC)); const wrapper = mount(); expect(wrapper.text()).toEqual( @@ -61,7 +53,7 @@ describe('formatted_date', () => { }); test('it renders the correct tz when the default browser configuration exists', () => { - mockUseKibanaUiSetting.mockImplementation( + mockUseUiSetting$.mockImplementation( getMockKibanaUiSetting(mockFrameworks.default_browser) ); const wrapper = mount(); @@ -71,9 +63,7 @@ describe('formatted_date', () => { }); test('it renders the correct tz when a non-UTC configuration exists', () => { - mockUseKibanaUiSetting.mockImplementation( - getMockKibanaUiSetting(mockFrameworks.default_MT) - ); + mockUseUiSetting$.mockImplementation(getMockKibanaUiSetting(mockFrameworks.default_MT)); const wrapper = mount(); expect(wrapper.text()).toEqual( configFormattedDateString(isoDateString, mockFrameworks.default_MT) @@ -84,30 +74,20 @@ describe('formatted_date', () => { describe('FormattedDate', () => { describe('rendering', () => { - beforeEach(() => { - mockUseKibanaUiSetting.mockClear(); - }); - test('it renders against a numeric epoch', () => { - mockUseKibanaUiSetting.mockImplementation( - getMockKibanaUiSetting(mockFrameworks.default_UTC) - ); + mockUseUiSetting$.mockImplementation(getMockKibanaUiSetting(mockFrameworks.default_UTC)); const wrapper = mount(); expect(wrapper.text()).toEqual('May 28, 2019 @ 21:35:39.000'); }); test('it renders against a string epoch', () => { - mockUseKibanaUiSetting.mockImplementation( - getMockKibanaUiSetting(mockFrameworks.default_UTC) - ); + mockUseUiSetting$.mockImplementation(getMockKibanaUiSetting(mockFrameworks.default_UTC)); const wrapper = mount(); expect(wrapper.text()).toEqual('May 28, 2019 @ 21:35:39.000'); }); test('it renders against a ISO string', () => { - mockUseKibanaUiSetting.mockImplementation( - getMockKibanaUiSetting(mockFrameworks.default_UTC) - ); + mockUseUiSetting$.mockImplementation(getMockKibanaUiSetting(mockFrameworks.default_UTC)); const wrapper = mount( ); @@ -115,9 +95,7 @@ describe('formatted_date', () => { }); test('it renders against an empty string as an empty string placeholder', () => { - mockUseKibanaUiSetting.mockImplementation( - getMockKibanaUiSetting(mockFrameworks.default_UTC) - ); + mockUseUiSetting$.mockImplementation(getMockKibanaUiSetting(mockFrameworks.default_UTC)); const wrapper = mount( @@ -127,9 +105,7 @@ describe('formatted_date', () => { }); test('it renders against an null as a EMPTY_VALUE', () => { - mockUseKibanaUiSetting.mockImplementation( - getMockKibanaUiSetting(mockFrameworks.default_UTC) - ); + mockUseUiSetting$.mockImplementation(getMockKibanaUiSetting(mockFrameworks.default_UTC)); const wrapper = mount( @@ -139,9 +115,7 @@ describe('formatted_date', () => { }); test('it renders against an undefined as a EMPTY_VALUE', () => { - mockUseKibanaUiSetting.mockImplementation( - getMockKibanaUiSetting(mockFrameworks.default_UTC) - ); + mockUseUiSetting$.mockImplementation(getMockKibanaUiSetting(mockFrameworks.default_UTC)); const wrapper = mount( @@ -151,9 +125,7 @@ describe('formatted_date', () => { }); test('it renders against an invalid date time as just the string its self', () => { - mockUseKibanaUiSetting.mockImplementation( - getMockKibanaUiSetting(mockFrameworks.default_UTC) - ); + mockUseUiSetting$.mockImplementation(getMockKibanaUiSetting(mockFrameworks.default_UTC)); const wrapper = mount( diff --git a/x-pack/legacy/plugins/siem/public/components/formatted_date/index.tsx b/x-pack/legacy/plugins/siem/public/components/formatted_date/index.tsx index 37bf3653f3b62..19e8ec3f95d26 100644 --- a/x-pack/legacy/plugins/siem/public/components/formatted_date/index.tsx +++ b/x-pack/legacy/plugins/siem/public/components/formatted_date/index.tsx @@ -8,20 +8,21 @@ import moment from 'moment-timezone'; import * as React from 'react'; import { FormattedRelative } from '@kbn/i18n/react'; +import { useUiSetting$ } from '../../lib/kibana'; + import { DEFAULT_DATE_FORMAT, DEFAULT_DATE_FORMAT_TZ, DEFAULT_TIMEZONE_BROWSER, } from '../../../common/constants'; -import { useKibanaUiSetting } from '../../lib/settings/use_kibana_ui_setting'; import { getOrEmptyTagFromValue } from '../empty_value'; import { LocalizedDateTooltip } from '../localized_date_tooltip'; import { getMaybeDate } from './maybe_date'; export const PreferenceFormattedDate = React.memo<{ value: Date }>(({ value }) => { - const [dateFormat] = useKibanaUiSetting(DEFAULT_DATE_FORMAT); - const [dateFormatTz] = useKibanaUiSetting(DEFAULT_DATE_FORMAT_TZ); - const [timezone] = useKibanaUiSetting(DEFAULT_TIMEZONE_BROWSER); + const [dateFormat] = useUiSetting$(DEFAULT_DATE_FORMAT); + const [dateFormatTz] = useUiSetting$(DEFAULT_DATE_FORMAT_TZ); + const [timezone] = useUiSetting$(DEFAULT_TIMEZONE_BROWSER); return ( <> diff --git a/x-pack/legacy/plugins/siem/public/components/header_global/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/header_global/index.test.tsx index b3eb599af9407..a45bed87829bf 100644 --- a/x-pack/legacy/plugins/siem/public/components/header_global/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/header_global/index.test.tsx @@ -9,10 +9,9 @@ import toJson from 'enzyme-to-json'; import React from 'react'; import '../../mock/match_media'; -import '../../mock/ui_settings'; import { HeaderGlobal } from './index'; -jest.mock('../../lib/settings/use_kibana_ui_setting'); +jest.mock('ui/new_platform'); // Test will fail because we will to need to mock some core services to make the test work // For now let's forget about SiemSearchBar diff --git a/x-pack/legacy/plugins/siem/public/components/header_page/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/header_page/index.test.tsx index 5644a344f91d6..633ff90524de6 100644 --- a/x-pack/legacy/plugins/siem/public/components/header_page/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/header_page/index.test.tsx @@ -10,12 +10,9 @@ import toJson from 'enzyme-to-json'; import React from 'react'; import { TestProviders } from '../../mock'; -import '../../mock/ui_settings'; import { HeaderPage } from './index'; import { useMountAppended } from '../../utils/use_mount_appended'; -jest.mock('../../lib/settings/use_kibana_ui_setting'); - describe('HeaderPage', () => { const mount = useMountAppended(); diff --git a/x-pack/legacy/plugins/siem/public/components/header_section/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/header_section/index.test.tsx index 8606758c68d2c..fbd8642c01fac 100644 --- a/x-pack/legacy/plugins/siem/public/components/header_section/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/header_section/index.test.tsx @@ -10,11 +10,8 @@ import toJson from 'enzyme-to-json'; import React from 'react'; import { TestProviders } from '../../mock'; -import '../../mock/ui_settings'; import { HeaderSection } from './index'; -jest.mock('../../lib/settings/use_kibana_ui_setting'); - describe('HeaderSection', () => { test('it renders', () => { const wrapper = shallow(); diff --git a/x-pack/legacy/plugins/siem/public/components/last_event_time/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/last_event_time/index.test.tsx index e2ada4682fdec..dcecc636d9f0f 100644 --- a/x-pack/legacy/plugins/siem/public/components/last_event_time/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/last_event_time/index.test.tsx @@ -13,7 +13,6 @@ import { mockLastEventTimeQuery } from '../../containers/events/last_event_time/ import { useMountAppended } from '../../utils/use_mount_appended'; import { useLastEventTimeQuery } from '../../containers/events/last_event_time'; import { TestProviders } from '../../mock'; -import '../../mock/ui_settings'; import { LastEventTime } from '.'; diff --git a/x-pack/legacy/plugins/siem/public/components/link_icon/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/link_icon/index.test.tsx index 7f9133a0de7c0..87761a51a431f 100644 --- a/x-pack/legacy/plugins/siem/public/components/link_icon/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/link_icon/index.test.tsx @@ -9,11 +9,8 @@ import toJson from 'enzyme-to-json'; import React from 'react'; import { TestProviders } from '../../mock'; -import '../../mock/ui_settings'; import { LinkIcon } from './index'; -jest.mock('../../lib/settings/use_kibana_ui_setting'); - describe('LinkIcon', () => { test('it renders', () => { const wrapper = shallow( diff --git a/x-pack/legacy/plugins/siem/public/components/matrix_histogram/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/matrix_histogram/index.test.tsx index bdd8a0c544ed8..87d4e072e4299 100644 --- a/x-pack/legacy/plugins/siem/public/components/matrix_histogram/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/matrix_histogram/index.test.tsx @@ -9,12 +9,7 @@ import * as React from 'react'; import { MatrixHistogram } from '.'; -jest.mock('@elastic/eui', () => { - return { - EuiPanel: (children: JSX.Element) => <>{children}, - EuiLoadingContent: () =>
, - }; -}); +jest.mock('../../lib/kibana'); jest.mock('../loader', () => { return { @@ -22,10 +17,6 @@ jest.mock('../loader', () => { }; }); -jest.mock('../../lib/settings/use_kibana_ui_setting', () => { - return { useKibanaUiSetting: () => [false] }; -}); - jest.mock('../header_section', () => { return { HeaderSection: () =>
, diff --git a/x-pack/legacy/plugins/siem/public/components/matrix_histogram/index.tsx b/x-pack/legacy/plugins/siem/public/components/matrix_histogram/index.tsx index e1ccfd79a89a0..c29b5282e13af 100644 --- a/x-pack/legacy/plugins/siem/public/components/matrix_histogram/index.tsx +++ b/x-pack/legacy/plugins/siem/public/components/matrix_histogram/index.tsx @@ -14,7 +14,7 @@ import { BarChart } from '../charts/barchart'; import { HeaderSection } from '../header_section'; import { ChartSeriesData } from '../charts/common'; import { DEFAULT_DARK_MODE } from '../../../common/constants'; -import { useKibanaUiSetting } from '../../lib/settings/use_kibana_ui_setting'; +import { useUiSetting$ } from '../../lib/kibana'; import { Loader } from '../loader'; import { Panel } from '../panel'; import { getBarchartConfigs, getCustomChartData } from './utils'; @@ -45,7 +45,7 @@ export const MatrixHistogram = ({ showLegend, }); const [showInspect, setShowInspect] = useState(false); - const [darkMode] = useKibanaUiSetting(DEFAULT_DARK_MODE); + const [darkMode] = useUiSetting$(DEFAULT_DARK_MODE); const [loadingInitial, setLoadingInitial] = useState(false); const barChartData: ChartSeriesData[] = getCustomChartData(data, mapping); diff --git a/x-pack/legacy/plugins/siem/public/components/ml/anomaly/use_anomalies_table_data.ts b/x-pack/legacy/plugins/siem/public/components/ml/anomaly/use_anomalies_table_data.ts index 130c326339b1b..bce99c943c7a5 100644 --- a/x-pack/legacy/plugins/siem/public/components/ml/anomaly/use_anomalies_table_data.ts +++ b/x-pack/legacy/plugins/siem/public/components/ml/anomaly/use_anomalies_table_data.ts @@ -14,7 +14,7 @@ import { useStateToaster } from '../../toasters'; import { errorToToaster } from '../api/error_to_toaster'; import * as i18n from './translations'; -import { useKibanaUiSetting } from '../../../lib/settings/use_kibana_ui_setting'; +import { useUiSetting$ } from '../../../lib/kibana'; import { DEFAULT_ANOMALY_SCORE, DEFAULT_TIMEZONE_BROWSER, @@ -67,9 +67,9 @@ export const useAnomaliesTableData = ({ const capabilities = useContext(MlCapabilitiesContext); const userPermissions = hasMlUserPermissions(capabilities); const [, dispatchToaster] = useStateToaster(); - const [timezone] = useKibanaUiSetting(DEFAULT_TIMEZONE_BROWSER); - const [anomalyScore] = useKibanaUiSetting(DEFAULT_ANOMALY_SCORE); - const [kbnVersion] = useKibanaUiSetting(DEFAULT_KBN_VERSION); + const [timezone] = useUiSetting$(DEFAULT_TIMEZONE_BROWSER); + const [anomalyScore] = useUiSetting$(DEFAULT_ANOMALY_SCORE); + const [kbnVersion] = useUiSetting$(DEFAULT_KBN_VERSION); const siemJobIds = siemJobs.filter(job => job.isInstalled).map(job => job.id); diff --git a/x-pack/legacy/plugins/siem/public/components/ml/permissions/ml_capabilities_provider.tsx b/x-pack/legacy/plugins/siem/public/components/ml/permissions/ml_capabilities_provider.tsx index 352f39a75ded1..b8d6908df464e 100644 --- a/x-pack/legacy/plugins/siem/public/components/ml/permissions/ml_capabilities_provider.tsx +++ b/x-pack/legacy/plugins/siem/public/components/ml/permissions/ml_capabilities_provider.tsx @@ -11,7 +11,7 @@ import { getMlCapabilities } from '../api/get_ml_capabilities'; import { emptyMlCapabilities } from '../empty_ml_capabilities'; import { errorToToaster } from '../api/error_to_toaster'; import { useStateToaster } from '../../toasters'; -import { useKibanaUiSetting } from '../../../lib/settings/use_kibana_ui_setting'; +import { useUiSetting$ } from '../../../lib/kibana'; import { DEFAULT_KBN_VERSION } from '../../../../common/constants'; import * as i18n from './translations'; @@ -36,7 +36,7 @@ export const MlCapabilitiesProvider = React.memo<{ children: JSX.Element }>(({ c emptyMlCapabilitiesProvider ); const [, dispatchToaster] = useStateToaster(); - const [kbnVersion] = useKibanaUiSetting(DEFAULT_KBN_VERSION); + const [kbnVersion] = useUiSetting$(DEFAULT_KBN_VERSION); useEffect(() => { let isSubscribed = true; diff --git a/x-pack/legacy/plugins/siem/public/components/ml/score/anomaly_score.test.tsx b/x-pack/legacy/plugins/siem/public/components/ml/score/anomaly_score.test.tsx index f7d9052b19a2f..cf24d6c02a138 100644 --- a/x-pack/legacy/plugins/siem/public/components/ml/score/anomaly_score.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/ml/score/anomaly_score.test.tsx @@ -17,8 +17,6 @@ import { Anomalies } from '../types'; const endDate: number = new Date('3000-01-01T00:00:00.000Z').valueOf(); const narrowDateRange = jest.fn(); -jest.mock('../../../lib/settings/use_kibana_ui_setting'); - describe('anomaly_scores', () => { let anomalies: Anomalies = cloneDeep(mockAnomalies); const mount = useMountAppended(); diff --git a/x-pack/legacy/plugins/siem/public/components/ml/score/anomaly_scores.test.tsx b/x-pack/legacy/plugins/siem/public/components/ml/score/anomaly_scores.test.tsx index f01df38138456..759e84e36f4ac 100644 --- a/x-pack/legacy/plugins/siem/public/components/ml/score/anomaly_scores.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/ml/score/anomaly_scores.test.tsx @@ -18,8 +18,6 @@ import { useMountAppended } from '../../../utils/use_mount_appended'; const endDate: number = new Date('3000-01-01T00:00:00.000Z').valueOf(); const narrowDateRange = jest.fn(); -jest.mock('../../../lib/settings/use_kibana_ui_setting'); - describe('anomaly_scores', () => { let anomalies: Anomalies = cloneDeep(mockAnomalies); const mount = useMountAppended(); diff --git a/x-pack/legacy/plugins/siem/public/components/ml/score/create_descriptions_list.test.tsx b/x-pack/legacy/plugins/siem/public/components/ml/score/create_descriptions_list.test.tsx index d55c6972d5cac..f00fb62d74ac3 100644 --- a/x-pack/legacy/plugins/siem/public/components/ml/score/create_descriptions_list.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/ml/score/create_descriptions_list.test.tsx @@ -12,7 +12,7 @@ import { createDescriptionList } from './create_description_list'; import { EuiDescriptionList } from '@elastic/eui'; import { Anomaly } from '../types'; -jest.mock('../../../lib/settings/use_kibana_ui_setting'); +jest.mock('../../../lib/kibana'); const endDate: number = new Date('3000-01-01T00:00:00.000Z').valueOf(); diff --git a/x-pack/legacy/plugins/siem/public/components/ml_popover/hooks/use_siem_jobs.tsx b/x-pack/legacy/plugins/siem/public/components/ml_popover/hooks/use_siem_jobs.tsx index 0bef34a7edc44..f9d110d711d07 100644 --- a/x-pack/legacy/plugins/siem/public/components/ml_popover/hooks/use_siem_jobs.tsx +++ b/x-pack/legacy/plugins/siem/public/components/ml_popover/hooks/use_siem_jobs.tsx @@ -12,7 +12,7 @@ import { hasMlUserPermissions } from '../../ml/permissions/has_ml_user_permissio import { MlCapabilitiesContext } from '../../ml/permissions/ml_capabilities_provider'; import { useStateToaster } from '../../toasters'; import { errorToToaster } from '../../ml/api/error_to_toaster'; -import { useKibanaUiSetting } from '../../../lib/settings/use_kibana_ui_setting'; +import { useUiSetting$ } from '../../../lib/kibana'; import { DEFAULT_INDEX_KEY, DEFAULT_KBN_VERSION } from '../../../../common/constants'; import * as i18n from './translations'; @@ -33,8 +33,8 @@ export const useSiemJobs = (refetchData: boolean): Return => { const [loading, setLoading] = useState(true); const capabilities = useContext(MlCapabilitiesContext); const userPermissions = hasMlUserPermissions(capabilities); - const [siemDefaultIndex] = useKibanaUiSetting(DEFAULT_INDEX_KEY); - const [kbnVersion] = useKibanaUiSetting(DEFAULT_KBN_VERSION); + const [siemDefaultIndex] = useUiSetting$(DEFAULT_INDEX_KEY); + const [kbnVersion] = useUiSetting$(DEFAULT_KBN_VERSION); const [, dispatchToaster] = useStateToaster(); useEffect(() => { diff --git a/x-pack/legacy/plugins/siem/public/components/ml_popover/ml_popover.test.tsx b/x-pack/legacy/plugins/siem/public/components/ml_popover/ml_popover.test.tsx index 1a8360fe82c58..987c63be3f7be 100644 --- a/x-pack/legacy/plugins/siem/public/components/ml_popover/ml_popover.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/ml_popover/ml_popover.test.tsx @@ -9,7 +9,8 @@ import { mountWithIntl } from 'test_utils/enzyme_helpers'; import { MlPopover } from './ml_popover'; -jest.mock('../../lib/settings/use_kibana_ui_setting'); +jest.mock('ui/new_platform'); +jest.mock('../../lib/kibana'); jest.mock('../ml/permissions/has_ml_admin_permissions', () => ({ hasMlAdminPermissions: () => true, diff --git a/x-pack/legacy/plugins/siem/public/components/ml_popover/ml_popover.tsx b/x-pack/legacy/plugins/siem/public/components/ml_popover/ml_popover.tsx index 0b33ab83d2a47..c34ed51d22994 100644 --- a/x-pack/legacy/plugins/siem/public/components/ml_popover/ml_popover.tsx +++ b/x-pack/legacy/plugins/siem/public/components/ml_popover/ml_popover.tsx @@ -9,10 +9,9 @@ import { FormattedMessage } from '@kbn/i18n/react'; import moment from 'moment'; import React, { useContext, useReducer, useState } from 'react'; import styled from 'styled-components'; -import { DOC_LINK_VERSION, ELASTIC_WEBSITE_URL } from 'ui/documentation_links'; import { DEFAULT_KBN_VERSION } from '../../../common/constants'; -import { useKibanaUiSetting } from '../../lib/settings/use_kibana_ui_setting'; +import { useKibana, useUiSetting$ } from '../../lib/kibana'; import { METRIC_TYPE, TELEMETRY_EVENT, trackUiAction as track } from '../../lib/track_usage'; import { errorToToaster } from '../ml/api/error_to_toaster'; import { hasMlAdminPermissions } from '../ml/permissions/has_ml_admin_permissions'; @@ -98,10 +97,11 @@ export const MlPopover = React.memo(() => { const [isPopoverOpen, setIsPopoverOpen] = useState(false); const [filterProperties, setFilterProperties] = useState(defaultFilterProps); - const [kbnVersion] = useKibanaUiSetting(DEFAULT_KBN_VERSION); + const [kbnVersion] = useUiSetting$(DEFAULT_KBN_VERSION); const [isLoadingSiemJobs, siemJobs] = useSiemJobs(refreshToggle); const [, dispatchToaster] = useStateToaster(); const capabilities = useContext(MlCapabilitiesContext); + const docLinks = useKibana().services.docLinks; // Enable/Disable Job & Datafeed -- passed to JobsTable for use as callback on JobSwitch const enableDatafeed = async (job: SiemJob, latestTimestampMs: number, enable: boolean) => { @@ -226,7 +226,7 @@ export const MlPopover = React.memo(() => { values={{ mlDocs: ( diff --git a/x-pack/legacy/plugins/siem/public/components/ml_popover/types.ts b/x-pack/legacy/plugins/siem/public/components/ml_popover/types.ts index 88481e140cb03..f8794c1963961 100644 --- a/x-pack/legacy/plugins/siem/public/components/ml_popover/types.ts +++ b/x-pack/legacy/plugins/siem/public/components/ml_popover/types.ts @@ -13,7 +13,7 @@ export interface Group { } export interface CheckRecognizerProps { - indexPatternName: string; + indexPatternName: string[]; kbnVersion: string; signal: AbortSignal; } diff --git a/x-pack/legacy/plugins/siem/public/components/netflow/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/netflow/index.test.tsx index 2d8c201e41462..22531983b2399 100644 --- a/x-pack/legacy/plugins/siem/public/components/netflow/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/netflow/index.test.tsx @@ -57,8 +57,6 @@ import { } from '../source_destination/field_names'; import { useMountAppended } from '../../utils/use_mount_appended'; -jest.mock('../../lib/settings/use_kibana_ui_setting'); - const getNetflowInstance = () => ( { const theme = () => ({ eui: euiDarkVars, darkMode: true }); diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline.test.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline.test.tsx index 690e8877b5019..dbc7199aac725 100644 --- a/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline.test.tsx @@ -17,7 +17,7 @@ import { mockTimelineResults } from '../../mock/timeline_results'; import { OpenTimeline } from './open_timeline'; import { DEFAULT_SORT_DIRECTION, DEFAULT_SORT_FIELD } from './constants'; -jest.mock('../../lib/settings/use_kibana_ui_setting'); +jest.mock('../../lib/kibana'); describe('OpenTimeline', () => { const theme = () => ({ eui: euiDarkVars, darkMode: true }); diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline_modal/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline_modal/index.test.tsx index 03383a6cb6612..e3dc6d974b5e0 100644 --- a/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline_modal/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline_modal/index.test.tsx @@ -16,7 +16,7 @@ import { mockOpenTimelineQueryResults } from '../../../mock/timeline_results'; import { OpenTimelineModal } from '.'; -jest.mock('../../../lib/settings/use_kibana_ui_setting'); +jest.mock('../../../lib/kibana'); jest.mock('../../../utils/apollo_context', () => ({ useApolloClient: () => ({}), })); diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline_modal/open_timeline_modal_body.test.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline_modal/open_timeline_modal_body.test.tsx index 4237caf8f3c51..a5abb42c2e3b6 100644 --- a/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline_modal/open_timeline_modal_body.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline_modal/open_timeline_modal_body.test.tsx @@ -17,7 +17,7 @@ import { mockTimelineResults } from '../../../mock/timeline_results'; import { OpenTimelineModalBody } from './open_timeline_modal_body'; import { DEFAULT_SORT_DIRECTION, DEFAULT_SORT_FIELD } from '../constants'; -jest.mock('../../../lib/settings/use_kibana_ui_setting'); +jest.mock('../../../lib/kibana'); describe('OpenTimelineModal', () => { const theme = () => ({ eui: euiDarkVars, darkMode: true }); diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline_modal/open_timeline_modal_button.test.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline_modal/open_timeline_modal_button.test.tsx index a5e436c73f93b..9a70fd476e89e 100644 --- a/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline_modal/open_timeline_modal_button.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline_modal/open_timeline_modal_button.test.tsx @@ -17,8 +17,6 @@ import * as i18n from '../translations'; import { OpenTimelineModalButton } from './open_timeline_modal_button'; -jest.mock('../../../lib/settings/use_kibana_ui_setting'); - describe('OpenTimelineModalButton', () => { const theme = () => ({ eui: euiDarkVars, darkMode: true }); diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/actions_columns.test.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/actions_columns.test.tsx index 30a02a974ba92..749ba8672abea 100644 --- a/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/actions_columns.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/actions_columns.test.tsx @@ -17,7 +17,7 @@ import { OpenTimelineResult } from '../types'; import { TimelinesTable } from '.'; import { DEFAULT_SORT_DIRECTION, DEFAULT_SORT_FIELD } from '../constants'; -jest.mock('../../../lib/settings/use_kibana_ui_setting'); +jest.mock('../../../lib/kibana'); describe('#getActionsColumns', () => { const theme = () => ({ eui: euiDarkVars, darkMode: true }); diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/common_columns.test.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/common_columns.test.tsx index ae68019c2fe69..fa08df1df4785 100644 --- a/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/common_columns.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/common_columns.test.tsx @@ -21,7 +21,7 @@ import { TimelinesTable } from '.'; import * as i18n from '../translations'; import { DEFAULT_SORT_DIRECTION, DEFAULT_SORT_FIELD } from '../constants'; -jest.mock('../../../lib/settings/use_kibana_ui_setting'); +jest.mock('../../../lib/kibana'); describe('#getCommonColumns', () => { const theme = () => ({ eui: euiDarkVars, darkMode: true }); diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/extended_columns.test.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/extended_columns.test.tsx index bf5adc8aca533..13362e0f43a28 100644 --- a/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/extended_columns.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/extended_columns.test.tsx @@ -20,7 +20,7 @@ import { TimelinesTable } from '.'; import * as i18n from '../translations'; import { DEFAULT_SORT_DIRECTION, DEFAULT_SORT_FIELD } from '../constants'; -jest.mock('../../../lib/settings/use_kibana_ui_setting'); +jest.mock('../../../lib/kibana'); describe('#getExtendedColumns', () => { const theme = () => ({ eui: euiDarkVars, darkMode: true }); diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/icon_header_columns.test.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/icon_header_columns.test.tsx index e5047662eef67..b6048b85eea75 100644 --- a/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/icon_header_columns.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/icon_header_columns.test.tsx @@ -16,7 +16,7 @@ import { TimelinesTable } from '.'; import { OpenTimelineResult } from '../types'; import { DEFAULT_SORT_DIRECTION, DEFAULT_SORT_FIELD } from '../constants'; -jest.mock('../../../lib/settings/use_kibana_ui_setting'); +jest.mock('../../../lib/kibana'); describe('#getActionsColumns', () => { const theme = () => ({ eui: euiDarkVars, darkMode: true }); diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/index.test.tsx index 6cf56ad6a770f..d75863d1ccb8b 100644 --- a/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/index.test.tsx @@ -18,7 +18,7 @@ import { TimelinesTable, TimelinesTableProps } from '.'; import * as i18n from '../translations'; import { DEFAULT_SORT_DIRECTION, DEFAULT_SORT_FIELD } from '../constants'; -jest.mock('../../../lib/settings/use_kibana_ui_setting'); +jest.mock('../../../lib/kibana'); describe('TimelinesTable', () => { const theme = () => ({ eui: euiDarkVars, darkMode: true }); diff --git a/x-pack/legacy/plugins/siem/public/components/page/detection_engine/histogram_signals/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/page/detection_engine/histogram_signals/index.test.tsx index c0d0feca5d53c..ad1d80a761854 100644 --- a/x-pack/legacy/plugins/siem/public/components/page/detection_engine/histogram_signals/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/page/detection_engine/histogram_signals/index.test.tsx @@ -8,12 +8,9 @@ import { shallow } from 'enzyme'; import toJson from 'enzyme-to-json'; import React from 'react'; -import '../../../../mock/ui_settings'; import { TestProviders } from '../../../../mock'; import { HistogramSignals } from './index'; -jest.mock('../../../../lib/settings/use_kibana_ui_setting'); - describe('HistogramSignals', () => { test('it renders', () => { const wrapper = shallow( diff --git a/x-pack/legacy/plugins/siem/public/components/page/hosts/first_last_seen_host/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/page/hosts/first_last_seen_host/index.test.tsx index 6c3ab04849236..35c1eded18f15 100644 --- a/x-pack/legacy/plugins/siem/public/components/page/hosts/first_last_seen_host/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/page/hosts/first_last_seen_host/index.test.tsx @@ -12,26 +12,25 @@ import { render, act } from '@testing-library/react'; import { mockFirstLastSeenHostQuery } from '../../../../containers/hosts/first_last_seen/mock'; import { wait } from '../../../../lib/helpers'; import { TestProviders } from '../../../../mock'; -import '../../../../mock/ui_settings'; import { FirstLastSeenHost, FirstLastSeenHostType } from '.'; -jest.mock('../../../../lib/settings/use_kibana_ui_setting'); - -// Suppress warnings about "react-apollo" until we migrate to apollo@3 -/* eslint-disable no-console */ -const originalError = console.error; -beforeAll(() => { - console.error = jest.fn(); -}); -afterAll(() => { - console.error = originalError; -}); +jest.mock('../../../../lib/kibana'); describe('FirstLastSeen Component', () => { const firstSeen = 'Apr 8, 2019 @ 16:09:40.692'; const lastSeen = 'Apr 8, 2019 @ 18:35:45.064'; + // Suppress warnings about "react-apollo" until we migrate to apollo@3 + /* eslint-disable no-console */ + const originalError = console.error; + beforeAll(() => { + console.error = jest.fn(); + }); + afterAll(() => { + console.error = originalError; + }); + test('Loading', async () => { const { container } = render( diff --git a/x-pack/legacy/plugins/siem/public/components/page/hosts/host_overview/index.tsx b/x-pack/legacy/plugins/siem/public/components/page/hosts/host_overview/index.tsx index 437d14edeb5c8..9e3f8f91d5cf7 100644 --- a/x-pack/legacy/plugins/siem/public/components/page/hosts/host_overview/index.tsx +++ b/x-pack/legacy/plugins/siem/public/components/page/hosts/host_overview/index.tsx @@ -12,7 +12,7 @@ import React, { useContext, useState, useCallback } from 'react'; import { DEFAULT_DARK_MODE } from '../../../../../common/constants'; import { DescriptionList } from '../../../../../common/utility_types'; -import { useKibanaUiSetting } from '../../../../lib/settings/use_kibana_ui_setting'; +import { useUiSetting$ } from '../../../../lib/kibana'; import { getEmptyTagValue } from '../../../empty_value'; import { DefaultFieldRenderer, hostIdRenderer } from '../../../field_renderers/field_renderers'; import { InspectButton } from '../../../inspect'; @@ -59,7 +59,7 @@ export const HostOverview = React.memo( const [showInspect, setShowInspect] = useState(false); const capabilities = useContext(MlCapabilitiesContext); const userPermissions = hasMlUserPermissions(capabilities); - const [darkMode] = useKibanaUiSetting(DEFAULT_DARK_MODE); + const [darkMode] = useUiSetting$(DEFAULT_DARK_MODE); const getDefaultRenderer = (fieldName: string, fieldData: HostItem) => ( ({ - uiSettings: mockUiSettings, -})); - // Test will fail because we will to need to mock some core services to make the test work // For now let's forget about SiemSearchBar and QueryBar jest.mock('../../../search_bar', () => ({ diff --git a/x-pack/legacy/plugins/siem/public/components/page/network/ip_overview/index.tsx b/x-pack/legacy/plugins/siem/public/components/page/network/ip_overview/index.tsx index 8cb55f0d0fb58..0c4e594399517 100644 --- a/x-pack/legacy/plugins/siem/public/components/page/network/ip_overview/index.tsx +++ b/x-pack/legacy/plugins/siem/public/components/page/network/ip_overview/index.tsx @@ -11,7 +11,7 @@ import React, { useContext, useState, useCallback } from 'react'; import { DEFAULT_DARK_MODE } from '../../../../../common/constants'; import { DescriptionList } from '../../../../../common/utility_types'; -import { useKibanaUiSetting } from '../../../../lib/settings/use_kibana_ui_setting'; +import { useUiSetting$ } from '../../../../lib/kibana'; import { FlowTarget, IpOverviewData, Overview } from '../../../../graphql/types'; import { networkModel } from '../../../../store'; import { getEmptyTagValue } from '../../../empty_value'; @@ -74,7 +74,7 @@ export const IpOverview = React.memo( const [showInspect, setShowInspect] = useState(false); const capabilities = useContext(MlCapabilitiesContext); const userPermissions = hasMlUserPermissions(capabilities); - const [darkMode] = useKibanaUiSetting(DEFAULT_DARK_MODE); + const [darkMode] = useUiSetting$(DEFAULT_DARK_MODE); const typeData: Overview = data[flowTarget]!; const column: DescriptionList[] = [ { diff --git a/x-pack/legacy/plugins/siem/public/components/page/network/network_dns_table/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/page/network/network_dns_table/index.test.tsx index 0537b95ca6cf7..b88653bcadde8 100644 --- a/x-pack/legacy/plugins/siem/public/components/page/network/network_dns_table/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/page/network/network_dns_table/index.test.tsx @@ -18,8 +18,6 @@ import { useMountAppended } from '../../../../utils/use_mount_appended'; import { NetworkDnsTable } from '.'; import { mockData } from './mock'; -jest.mock('../../../../lib/settings/use_kibana_ui_setting'); - describe('NetworkTopNFlow Table Component', () => { const loadPage = jest.fn(); const state: State = mockGlobalState; diff --git a/x-pack/legacy/plugins/siem/public/components/page/network/network_http_table/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/page/network/network_http_table/index.test.tsx index 50d64817f81f8..81e0c7fad7b39 100644 --- a/x-pack/legacy/plugins/siem/public/components/page/network/network_http_table/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/page/network/network_http_table/index.test.tsx @@ -18,8 +18,6 @@ import { createStore, networkModel, State } from '../../../../store'; import { NetworkHttpTable } from '.'; import { mockData } from './mock'; -jest.mock('../../../../lib/settings/use_kibana_ui_setting'); - describe('NetworkHttp Table Component', () => { const loadPage = jest.fn(); const state: State = mockGlobalState; diff --git a/x-pack/legacy/plugins/siem/public/components/page/network/network_top_countries_table/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/page/network/network_top_countries_table/index.test.tsx index eb4179a040431..8fd245b077243 100644 --- a/x-pack/legacy/plugins/siem/public/components/page/network/network_top_countries_table/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/page/network/network_top_countries_table/index.test.tsx @@ -24,7 +24,6 @@ import { createStore, networkModel, State } from '../../../../store'; import { NetworkTopCountriesTable } from '.'; import { mockData } from './mock'; -jest.mock('../../../../lib/settings/use_kibana_ui_setting'); describe('NetworkTopCountries Table Component', () => { const loadPage = jest.fn(); const state: State = mockGlobalState; diff --git a/x-pack/legacy/plugins/siem/public/components/page/network/network_top_n_flow_table/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/page/network/network_top_n_flow_table/index.test.tsx index 3157847b32376..5c4aa862283f2 100644 --- a/x-pack/legacy/plugins/siem/public/components/page/network/network_top_n_flow_table/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/page/network/network_top_n_flow_table/index.test.tsx @@ -24,8 +24,6 @@ import { createStore, networkModel, State } from '../../../../store'; import { NetworkTopNFlowTable } from '.'; import { mockData } from './mock'; -jest.mock('../../../../lib/settings/use_kibana_ui_setting'); - describe('NetworkTopNFlow Table Component', () => { const loadPage = jest.fn(); const state: State = mockGlobalState; diff --git a/x-pack/legacy/plugins/siem/public/components/page/network/tls_table/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/page/network/tls_table/index.test.tsx index 4313c455a0df1..920d1cd8210e5 100644 --- a/x-pack/legacy/plugins/siem/public/components/page/network/tls_table/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/page/network/tls_table/index.test.tsx @@ -18,8 +18,6 @@ import { createStore, networkModel, State } from '../../../../store'; import { TlsTable } from '.'; import { mockTlsData } from './mock'; -jest.mock('../../../../lib/settings/use_kibana_ui_setting'); - describe('Tls Table Component', () => { const loadPage = jest.fn(); const state: State = mockGlobalState; diff --git a/x-pack/legacy/plugins/siem/public/components/page/network/users_table/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/page/network/users_table/index.test.tsx index d6b9ec24de0aa..d01923f01543f 100644 --- a/x-pack/legacy/plugins/siem/public/components/page/network/users_table/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/page/network/users_table/index.test.tsx @@ -19,8 +19,6 @@ import { createStore, networkModel, State } from '../../../../store'; import { UsersTable } from '.'; import { mockUsersData } from './mock'; -jest.mock('../../../../lib/settings/use_kibana_ui_setting'); - jest.mock('../../../search_bar', () => ({ siemFilterManager: { addFilters: jest.fn(), diff --git a/x-pack/legacy/plugins/siem/public/components/progress_inline/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/progress_inline/index.test.tsx index d99a4201c4c72..8ecc50402cef1 100644 --- a/x-pack/legacy/plugins/siem/public/components/progress_inline/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/progress_inline/index.test.tsx @@ -8,11 +8,8 @@ import { shallow } from 'enzyme'; import toJson from 'enzyme-to-json'; import React from 'react'; -import '../../mock/ui_settings'; import { ProgressInline } from './index'; -jest.mock('../../lib/settings/use_kibana_ui_setting'); - describe('ProgressInline', () => { test('it renders', () => { const wrapper = shallow( diff --git a/x-pack/legacy/plugins/siem/public/components/query_bar/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/query_bar/index.test.tsx index 10b769e2a791c..e403963cbbe20 100644 --- a/x-pack/legacy/plugins/siem/public/components/query_bar/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/query_bar/index.test.tsx @@ -7,23 +7,16 @@ import { mount } from 'enzyme'; import React from 'react'; -import { FilterManager, SearchBar } from '../../../../../../../src/plugins/data/public'; -import { uiSettingsServiceMock } from '../../../../../../../src/core/public/ui_settings/ui_settings_service.mock'; -import { useKibanaCore } from '../../lib/compose/kibana_core'; import { TestProviders, mockIndexPattern } from '../../mock'; -import { QueryBar, QueryBarComponentProps } from '.'; +import { createKibanaCoreStartMock } from '../../mock/kibana_core'; import { DEFAULT_FROM, DEFAULT_TO } from '../../../common/constants'; -import { mockUiSettings } from '../../mock/ui_settings'; +import { FilterManager, SearchBar } from '../../../../../../../src/plugins/data/public'; +import { QueryBar, QueryBarComponentProps } from '.'; +import { createKibanaContextProviderMock } from '../../mock/kibana_react'; -jest.mock('ui/new_platform'); +jest.mock('../../lib/kibana'); -const mockUseKibanaCore = useKibanaCore as jest.Mock; -const mockUiSettingsForFilterManager = uiSettingsServiceMock.createSetupContract(); -jest.mock('../../lib/compose/kibana_core'); -mockUseKibanaCore.mockImplementation(() => ({ - uiSettings: mockUiSettings, - savedObjects: {}, -})); +const mockUiSettingsForFilterManager = createKibanaCoreStartMock().uiSettings; describe('QueryBar ', () => { // We are doing that because we need to wrapped this component with redux @@ -196,9 +189,13 @@ describe('QueryBar ', () => { describe('#onQueryChange', () => { test(' is the only reference that changed when filterQueryDraft props get updated', () => { + const KibanaWithStorageProvider = createKibanaContextProviderMock(); + const Proxy = (props: QueryBarComponentProps) => ( - + + + ); diff --git a/x-pack/legacy/plugins/siem/public/components/query_bar/index.tsx b/x-pack/legacy/plugins/siem/public/components/query_bar/index.tsx index 9f706790bec67..b2843348cc2e3 100644 --- a/x-pack/legacy/plugins/siem/public/components/query_bar/index.tsx +++ b/x-pack/legacy/plugins/siem/public/components/query_bar/index.tsx @@ -6,7 +6,6 @@ import { isEqual } from 'lodash/fp'; import React, { memo, useState, useEffect, useMemo, useCallback } from 'react'; -import { IndexPattern } from 'ui/index_patterns'; import { esFilters, @@ -118,7 +117,7 @@ export const QueryBar = memo( ); const CustomButton = <>{null}; - const indexPatterns = useMemo(() => [indexPattern as IndexPattern], [indexPattern]); + const indexPatterns = useMemo(() => [indexPattern], [indexPattern]); const searchBarProps = savedQuery != null ? { savedQuery } : {}; diff --git a/x-pack/legacy/plugins/siem/public/components/search_bar/index.tsx b/x-pack/legacy/plugins/siem/public/components/search_bar/index.tsx index 3d02cff7b72e8..089bade4a4144 100644 --- a/x-pack/legacy/plugins/siem/public/components/search_bar/index.tsx +++ b/x-pack/legacy/plugins/siem/public/components/search_bar/index.tsx @@ -10,7 +10,6 @@ import { connect } from 'react-redux'; import { Dispatch } from 'redux'; import { Subscription } from 'rxjs'; import styled from 'styled-components'; -import { IndexPattern } from 'ui/index_patterns'; import { IIndexPattern } from 'src/plugins/data/public'; import { SavedQuery } from 'src/legacy/core_plugins/data/public'; @@ -254,7 +253,7 @@ const SearchBarComponent = memo [indexPattern as IndexPattern], [indexPattern]); + const indexPatterns = useMemo(() => [indexPattern], [indexPattern]); return ( ( { const mount = useMountAppended(); diff --git a/x-pack/legacy/plugins/siem/public/components/subtitle/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/subtitle/index.test.tsx index b54f3133de472..3424c05f32d63 100644 --- a/x-pack/legacy/plugins/siem/public/components/subtitle/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/subtitle/index.test.tsx @@ -8,12 +8,9 @@ import { mount, shallow } from 'enzyme'; import toJson from 'enzyme-to-json'; import React from 'react'; -import '../../mock/ui_settings'; import { TestProviders } from '../../mock'; import { Subtitle } from './index'; -jest.mock('../../lib/settings/use_kibana_ui_setting'); - describe('Subtitle', () => { test('it renders', () => { const wrapper = shallow(); diff --git a/x-pack/legacy/plugins/siem/public/components/super_date_picker/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/super_date_picker/index.test.tsx index 011e2ddcdbde7..013104da7c612 100644 --- a/x-pack/legacy/plugins/siem/public/components/super_date_picker/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/super_date_picker/index.test.tsx @@ -8,13 +8,69 @@ import { mount } from 'enzyme'; import * as React from 'react'; import { Provider as ReduxStoreProvider } from 'react-redux'; +import { useUiSetting$ } from '../../lib/kibana'; import { apolloClientObservable, mockGlobalState } from '../../mock'; +import { createUseUiSetting$Mock } from '../../mock/kibana_react'; import { createStore, State } from '../../store'; import { SuperDatePicker, makeMapStateToProps } from '.'; import { cloneDeep } from 'lodash/fp'; - -jest.mock('../../lib/settings/use_kibana_ui_setting'); +import { DEFAULT_TIMEPICKER_QUICK_RANGES } from '../../../common/constants'; + +jest.mock('../../lib/kibana'); +const mockUseUiSetting$ = useUiSetting$ as jest.Mock; +const timepickerRanges = [ + { + from: 'now/d', + to: 'now/d', + display: 'Today', + }, + { + from: 'now/w', + to: 'now/w', + display: 'This week', + }, + { + from: 'now-15m', + to: 'now', + display: 'Last 15 minutes', + }, + { + from: 'now-30m', + to: 'now', + display: 'Last 30 minutes', + }, + { + from: 'now-1h', + to: 'now', + display: 'Last 1 hour', + }, + { + from: 'now-24h', + to: 'now', + display: 'Last 24 hours', + }, + { + from: 'now-7d', + to: 'now', + display: 'Last 7 days', + }, + { + from: 'now-30d', + to: 'now', + display: 'Last 30 days', + }, + { + from: 'now-90d', + to: 'now', + display: 'Last 90 days', + }, + { + from: 'now-1y', + to: 'now', + display: 'Last 1 year', + }, +]; describe('SIEM Super Date Picker', () => { describe('#SuperDatePicker', () => { @@ -24,6 +80,13 @@ describe('SIEM Super Date Picker', () => { beforeEach(() => { jest.clearAllMocks(); store = createStore(state, apolloClientObservable); + mockUseUiSetting$.mockImplementation((key, defaultValue) => { + const useUiSetting$Mock = createUseUiSetting$Mock(); + + return key === DEFAULT_TIMEPICKER_QUICK_RANGES + ? [timepickerRanges, jest.fn()] + : useUiSetting$Mock(key, defaultValue); + }); }); describe('Pick Relative Date', () => { diff --git a/x-pack/legacy/plugins/siem/public/components/super_date_picker/index.tsx b/x-pack/legacy/plugins/siem/public/components/super_date_picker/index.tsx index a2e190da0f7bc..0877906c721ce 100644 --- a/x-pack/legacy/plugins/siem/public/components/super_date_picker/index.tsx +++ b/x-pack/legacy/plugins/siem/public/components/super_date_picker/index.tsx @@ -18,7 +18,7 @@ import { connect } from 'react-redux'; import { Dispatch } from 'redux'; import { DEFAULT_TIMEPICKER_QUICK_RANGES } from '../../../common/constants'; -import { useKibanaUiSetting } from '../../lib/settings/use_kibana_ui_setting'; +import { useUiSetting$ } from '../../lib/kibana'; import { inputsModel, State } from '../../store'; import { inputsActions, timelineActions } from '../../store/actions'; import { InputsModelId } from '../../store/inputs/constants'; @@ -38,6 +38,12 @@ import { InputsRange, Policy } from '../../store/inputs/model'; const MAX_RECENTLY_USED_RANGES = 9; +interface Range { + from: string; + to: string; + display: string; +} + interface SuperDatePickerStateRedux { duration: number; end: number; @@ -196,10 +202,10 @@ export const SuperDatePickerComponent = React.memo( const endDate = kind === 'relative' ? toStr : new Date(end).toISOString(); const startDate = kind === 'relative' ? fromStr : new Date(start).toISOString(); - const [quickRanges] = useKibanaUiSetting(DEFAULT_TIMEPICKER_QUICK_RANGES); + const [quickRanges] = useUiSetting$(DEFAULT_TIMEPICKER_QUICK_RANGES); const commonlyUsedRanges = isEmpty(quickRanges) ? [] - : quickRanges.map(({ from, to, display }: { from: string; to: string; display: string }) => ({ + : quickRanges.map(({ from, to, display }) => ({ start: from, end: to, label: display, diff --git a/x-pack/legacy/plugins/siem/public/components/timeline/body/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/timeline/body/index.test.tsx index d3eaedb3ef23e..5c6a0872ce340 100644 --- a/x-pack/legacy/plugins/siem/public/components/timeline/body/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/timeline/body/index.test.tsx @@ -17,8 +17,6 @@ import { Sort } from './sort'; import { wait } from '../../../lib/helpers'; import { useMountAppended } from '../../../utils/use_mount_appended'; -jest.mock('../../../lib/settings/use_kibana_ui_setting'); - const testBodyHeight = 700; const mockGetNotesByIds = (eventId: string[]) => []; const mockSort: Sort = { diff --git a/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/formatted_field.test.tsx b/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/formatted_field.test.tsx index 3f27abfd2176c..5c54e5be3374c 100644 --- a/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/formatted_field.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/formatted_field.test.tsx @@ -18,7 +18,7 @@ import { useMountAppended } from '../../../../utils/use_mount_appended'; import { FormattedFieldValue } from './formatted_field'; import { HOST_NAME_FIELD_NAME } from './constants'; -jest.mock('../../../../lib/settings/use_kibana_ui_setting'); +jest.mock('../../../../lib/kibana'); describe('Events', () => { const theme = () => ({ eui: euiDarkVars, darkMode: true }); diff --git a/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/netflow/netflow_row_renderer.test.tsx b/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/netflow/netflow_row_renderer.test.tsx index 9f73d86dec402..6ba8f3f28dae8 100644 --- a/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/netflow/netflow_row_renderer.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/netflow/netflow_row_renderer.test.tsx @@ -25,8 +25,6 @@ export const justIdAndTimestamp: Ecs = { timestamp: '2018-11-12T19:03:25.936Z', }; -jest.mock('../../../../../lib/settings/use_kibana_ui_setting'); - describe('netflowRowRenderer', () => { const mount = useMountAppended(); diff --git a/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/plain_column_renderer.test.tsx b/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/plain_column_renderer.test.tsx index 96865fd928216..008885b5264c8 100644 --- a/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/plain_column_renderer.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/plain_column_renderer.test.tsx @@ -18,7 +18,7 @@ import { useMountAppended } from '../../../../utils/use_mount_appended'; import { plainColumnRenderer } from './plain_column_renderer'; import { getValues, deleteItemIdx, findItem } from './helpers'; -jest.mock('../../../../lib/settings/use_kibana_ui_setting'); +jest.mock('../../../../lib/kibana'); const mockFramework = mockFrameworks.default_UTC; diff --git a/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/system/generic_row_renderer.test.tsx b/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/system/generic_row_renderer.test.tsx index 3727e82c1d2a0..b2dbdb6b0e45c 100644 --- a/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/system/generic_row_renderer.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/system/generic_row_renderer.test.tsx @@ -49,7 +49,7 @@ import { } from './generic_row_renderer'; import * as i18n from './translations'; -jest.mock('../../../../../lib/settings/use_kibana_ui_setting'); +jest.mock('../../../../../lib/kibana'); describe('GenericRowRenderer', () => { const mount = useMountAppended(); diff --git a/x-pack/legacy/plugins/siem/public/components/timeline/header/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/timeline/header/index.test.tsx index 977764803acbb..4527e39128f89 100644 --- a/x-pack/legacy/plugins/siem/public/components/timeline/header/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/timeline/header/index.test.tsx @@ -9,21 +9,14 @@ import toJson from 'enzyme-to-json'; import * as React from 'react'; import { Direction } from '../../../graphql/types'; -import { useKibanaCore } from '../../../lib/compose/kibana_core'; import { mockIndexPattern } from '../../../mock'; import { TestProviders } from '../../../mock/test_providers'; -import { mockUiSettings } from '../../../mock/ui_settings'; import { mockDataProviders } from '../data_providers/mock/mock_data_providers'; import { useMountAppended } from '../../../utils/use_mount_appended'; import { TimelineHeaderComponent } from '.'; -const mockUseKibanaCore = useKibanaCore as jest.Mock; -jest.mock('../../../lib/compose/kibana_core'); -mockUseKibanaCore.mockImplementation(() => ({ - uiSettings: mockUiSettings, - savedObjects: {}, -})); +jest.mock('../../../lib/kibana'); describe('Header', () => { const indexPattern = mockIndexPattern; diff --git a/x-pack/legacy/plugins/siem/public/components/timeline/properties/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/timeline/properties/index.test.tsx index eb82241b04124..bc05204cc47fe 100644 --- a/x-pack/legacy/plugins/siem/public/components/timeline/properties/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/timeline/properties/index.test.tsx @@ -8,22 +8,12 @@ import { mount } from 'enzyme'; import * as React from 'react'; import { Provider as ReduxStoreProvider } from 'react-redux'; -import { useKibanaCore } from '../../../lib/compose/kibana_core'; import { mockGlobalState, apolloClientObservable } from '../../../mock'; -import { mockUiSettings } from '../../../mock/ui_settings'; import { createStore, State } from '../../../store'; import { Properties, showDescriptionThreshold, showNotesThreshold } from '.'; -const mockUseKibanaCore = useKibanaCore as jest.Mock; -jest.mock('../../../lib/compose/kibana_core'); -mockUseKibanaCore.mockImplementation(() => ({ - uiSettings: mockUiSettings, -})); - -jest.mock('ui/vis/lib/timezone', () => ({ - timezoneProvider: () => () => 'America/New_York', -})); +jest.mock('../../../lib/kibana'); describe('Properties', () => { const usersViewing = ['elastic']; diff --git a/x-pack/legacy/plugins/siem/public/components/timeline/query_bar/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/timeline/query_bar/index.test.tsx index b78691fabdcbf..b978ef3d478d8 100644 --- a/x-pack/legacy/plugins/siem/public/components/timeline/query_bar/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/timeline/query_bar/index.test.tsx @@ -9,22 +9,15 @@ import React from 'react'; import { DEFAULT_FROM, DEFAULT_TO } from '../../../../common/constants'; import { mockBrowserFields } from '../../../containers/source/mock'; -import { useKibanaCore } from '../../../lib/compose/kibana_core'; import { convertKueryToElasticSearchQuery } from '../../../lib/keury'; import { mockIndexPattern, TestProviders } from '../../../mock'; -import { mockUiSettings } from '../../../mock/ui_settings'; import { QueryBar } from '../../query_bar'; import { mockDataProviders } from '../data_providers/mock/mock_data_providers'; import { buildGlobalQuery } from '../helpers'; import { QueryBarTimeline, QueryBarTimelineComponentProps, getDataProviderFilter } from './index'; -const mockUseKibanaCore = useKibanaCore as jest.Mock; -jest.mock('../../../lib/compose/kibana_core'); -mockUseKibanaCore.mockImplementation(() => ({ - uiSettings: mockUiSettings, - savedObjects: {}, -})); +jest.mock('../../../lib/kibana'); describe('Timeline QueryBar ', () => { // We are doing that because we need to wrapped this component with redux diff --git a/x-pack/legacy/plugins/siem/public/components/timeline/query_bar/index.tsx b/x-pack/legacy/plugins/siem/public/components/timeline/query_bar/index.tsx index c55ead5e2d5d5..c3b46c6cd0f72 100644 --- a/x-pack/legacy/plugins/siem/public/components/timeline/query_bar/index.tsx +++ b/x-pack/legacy/plugins/siem/public/components/timeline/query_bar/index.tsx @@ -19,7 +19,7 @@ import { import { BrowserFields } from '../../../containers/source'; import { convertKueryToElasticSearchQuery } from '../../../lib/keury'; -import { useKibanaCore } from '../../../lib/compose/kibana_core'; +import { useKibana } from '../../../lib/kibana'; import { KueryFilterQuery, KueryFilterQueryKind } from '../../../store'; import { KqlMode } from '../../../store/timeline/model'; import { useSavedQueryServices } from '../../../utils/saved_query_services'; @@ -92,8 +92,8 @@ export const QueryBarTimeline = memo( const [dataProvidersDsl, setDataProvidersDsl] = useState( convertKueryToElasticSearchQuery(buildGlobalQuery(dataProviders, browserFields), indexPattern) ); - const core = useKibanaCore(); - const [filterManager] = useState(new FilterManager(core.uiSettings)); + const kibana = useKibana(); + const [filterManager] = useState(new FilterManager(kibana.services.uiSettings)); const savedQueryServices = useSavedQueryServices(); diff --git a/x-pack/legacy/plugins/siem/public/components/timeline/timeline.test.tsx b/x-pack/legacy/plugins/siem/public/components/timeline/timeline.test.tsx index 180af88f21e4d..bb500de239da7 100644 --- a/x-pack/legacy/plugins/siem/public/components/timeline/timeline.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/timeline/timeline.test.tsx @@ -12,10 +12,8 @@ import { MockedProvider } from 'react-apollo/test-utils'; import { timelineQuery } from '../../containers/timeline/index.gql_query'; import { mockBrowserFields } from '../../containers/source/mock'; import { Direction } from '../../graphql/types'; -import { useKibanaCore } from '../../lib/compose/kibana_core'; import { defaultHeaders, mockTimelineData, mockIndexPattern } from '../../mock'; import { TestProviders } from '../../mock/test_providers'; -import { mockUiSettings } from '../../mock/ui_settings'; import { flyoutHeaderHeight } from '../flyout'; import { @@ -30,12 +28,7 @@ import { useMountAppended } from '../../utils/use_mount_appended'; const testFlyoutHeight = 980; -const mockUseKibanaCore = useKibanaCore as jest.Mock; -jest.mock('../../lib/compose/kibana_core'); -mockUseKibanaCore.mockImplementation(() => ({ - uiSettings: mockUiSettings, - savedObjects: {}, -})); +jest.mock('../../lib/kibana'); describe('Timeline', () => { const sort: Sort = { diff --git a/x-pack/legacy/plugins/siem/public/components/timeline/timeline.tsx b/x-pack/legacy/plugins/siem/public/components/timeline/timeline.tsx index ec7d10d2373d4..5646b26428bf8 100644 --- a/x-pack/legacy/plugins/siem/public/components/timeline/timeline.tsx +++ b/x-pack/legacy/plugins/siem/public/components/timeline/timeline.tsx @@ -12,7 +12,7 @@ import styled from 'styled-components'; import { BrowserFields } from '../../containers/source'; import { TimelineQuery } from '../../containers/timeline'; import { Direction } from '../../graphql/types'; -import { useKibanaCore } from '../../lib/compose/kibana_core'; +import { useKibana } from '../../lib/kibana'; import { KqlMode } from '../../store/timeline/model'; import { AutoSizer } from '../auto_sizer'; import { ColumnHeader } from './body/column_headers/column_header'; @@ -113,9 +113,9 @@ export const TimelineComponent = ({ sort, toggleColumn, }: Props) => { - const core = useKibanaCore(); + const kibana = useKibana(); const combinedQueries = combineQueries({ - config: esQuery.getEsQueryConfig(core.uiSettings), + config: esQuery.getEsQueryConfig(kibana.services.uiSettings), dataProviders, indexPattern, browserFields, diff --git a/x-pack/legacy/plugins/siem/public/components/wrapper_page/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/wrapper_page/index.test.tsx index 3ea243fe5cfe7..5d73e9bcf8e71 100644 --- a/x-pack/legacy/plugins/siem/public/components/wrapper_page/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/wrapper_page/index.test.tsx @@ -9,11 +9,8 @@ import toJson from 'enzyme-to-json'; import React from 'react'; import { TestProviders } from '../../mock'; -import '../../mock/ui_settings'; import { WrapperPage } from './index'; -jest.mock('../../lib/settings/use_kibana_ui_setting'); - describe('WrapperPage', () => { test('it renders', () => { const wrapper = shallow( diff --git a/x-pack/legacy/plugins/siem/public/containers/alerts/alerts_over_time/index.tsx b/x-pack/legacy/plugins/siem/public/containers/alerts/alerts_over_time/index.tsx index 98dcef51292ae..9541e6d39d669 100644 --- a/x-pack/legacy/plugins/siem/public/containers/alerts/alerts_over_time/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/alerts/alerts_over_time/index.tsx @@ -8,10 +8,11 @@ import { getOr } from 'lodash/fp'; import React from 'react'; import { Query } from 'react-apollo'; import { connect } from 'react-redux'; +import { compose } from 'redux'; -import chrome from 'ui/chrome'; import { DEFAULT_INDEX_KEY } from '../../../../common/constants'; import { inputsModel, State, inputsSelectors, hostsModel } from '../../../store'; +import { withKibana, WithKibanaProps } from '../../../lib/kibana'; import { createFilter, getDefaultFetchPolicy } from '../../helpers'; import { QueryTemplate, QueryTemplateProps } from '../../query_template'; @@ -40,7 +41,7 @@ export interface AlertsOverTimeComponentReduxProps { isInspected: boolean; } -type AlertsOverTimeProps = OwnProps & AlertsOverTimeComponentReduxProps; +type AlertsOverTimeProps = OwnProps & AlertsOverTimeComponentReduxProps & WithKibanaProps; class AlertsOverTimeComponentQuery extends QueryTemplate< AlertsOverTimeProps, @@ -54,6 +55,7 @@ class AlertsOverTimeComponentQuery extends QueryTemplate< filterQuery, id = ID, isInspected, + kibana, sourceId, startDate, } = this.props; @@ -70,7 +72,7 @@ class AlertsOverTimeComponentQuery extends QueryTemplate< from: startDate!, to: endDate!, }, - defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + defaultIndex: kibana.services.uiSettings.get(DEFAULT_INDEX_KEY), inspect: isInspected, }} > @@ -105,4 +107,7 @@ const makeMapStateToProps = () => { return mapStateToProps; }; -export const AlertsOverTimeQuery = connect(makeMapStateToProps)(AlertsOverTimeComponentQuery); +export const AlertsOverTimeQuery = compose>( + connect(makeMapStateToProps), + withKibana +)(AlertsOverTimeComponentQuery); diff --git a/x-pack/legacy/plugins/siem/public/containers/anomalies/anomalies_query_tab_body/index.tsx b/x-pack/legacy/plugins/siem/public/containers/anomalies/anomalies_query_tab_body/index.tsx index 917f4dbcc211b..f2c00cbae1a74 100644 --- a/x-pack/legacy/plugins/siem/public/containers/anomalies/anomalies_query_tab_body/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/anomalies/anomalies_query_tab_body/index.tsx @@ -12,7 +12,7 @@ import { AnomaliesOverTimeHistogram } from '../../../components/anomalies_over_t import { AnomaliesOverTimeQuery } from '../anomalies_over_time'; import { getAnomaliesFilterQuery } from './utils'; import { useSiemJobs } from '../../../components/ml_popover/hooks/use_siem_jobs'; -import { useKibanaUiSetting } from '../../../lib/settings/use_kibana_ui_setting'; +import { useUiSetting$ } from '../../../lib/kibana'; import { DEFAULT_ANOMALY_SCORE } from '../../../../common/constants'; const AnomaliesOverTimeManage = manageQuery(AnomaliesOverTimeHistogram); @@ -33,7 +33,7 @@ export const AnomaliesQueryTabBody = ({ ip, }: AnomaliesQueryTabBodyProps) => { const [siemJobsLoading, siemJobs] = useSiemJobs(true); - const [anomalyScore] = useKibanaUiSetting(DEFAULT_ANOMALY_SCORE); + const [anomalyScore] = useUiSetting$(DEFAULT_ANOMALY_SCORE); const mergedFilterQuery = getAnomaliesFilterQuery( filterQuery, diff --git a/x-pack/legacy/plugins/siem/public/containers/authentications/authentications_over_time/index.tsx b/x-pack/legacy/plugins/siem/public/containers/authentications/authentications_over_time/index.tsx index 1d6d96869b6a9..8f363d49f1851 100644 --- a/x-pack/legacy/plugins/siem/public/containers/authentications/authentications_over_time/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/authentications/authentications_over_time/index.tsx @@ -8,10 +8,11 @@ import { getOr } from 'lodash/fp'; import React from 'react'; import { Query } from 'react-apollo'; import { connect } from 'react-redux'; +import { compose } from 'redux'; -import chrome from 'ui/chrome'; import { DEFAULT_INDEX_KEY } from '../../../../common/constants'; import { inputsModel, State, inputsSelectors, hostsModel } from '../../../store'; +import { withKibana, WithKibanaProps } from '../../../lib/kibana'; import { createFilter, getDefaultFetchPolicy } from '../../helpers'; import { QueryTemplate, QueryTemplateProps } from '../../query_template'; @@ -43,7 +44,9 @@ export interface AuthenticationsOverTimeComponentReduxProps { isInspected: boolean; } -type AuthenticationsOverTimeProps = OwnProps & AuthenticationsOverTimeComponentReduxProps; +type AuthenticationsOverTimeProps = OwnProps & + AuthenticationsOverTimeComponentReduxProps & + WithKibanaProps; class AuthenticationsOverTimeComponentQuery extends QueryTemplate< AuthenticationsOverTimeProps, @@ -56,6 +59,7 @@ class AuthenticationsOverTimeComponentQuery extends QueryTemplate< filterQuery, id = ID, isInspected, + kibana, sourceId, startDate, endDate, @@ -73,7 +77,7 @@ class AuthenticationsOverTimeComponentQuery extends QueryTemplate< from: startDate!, to: endDate!, }, - defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + defaultIndex: kibana.services.uiSettings.get(DEFAULT_INDEX_KEY), inspect: isInspected, }} > @@ -108,6 +112,7 @@ const makeMapStateToProps = () => { return mapStateToProps; }; -export const AuthenticationsOverTimeQuery = connect(makeMapStateToProps)( - AuthenticationsOverTimeComponentQuery -); +export const AuthenticationsOverTimeQuery = compose>( + connect(makeMapStateToProps), + withKibana +)(AuthenticationsOverTimeComponentQuery); diff --git a/x-pack/legacy/plugins/siem/public/containers/authentications/index.tsx b/x-pack/legacy/plugins/siem/public/containers/authentications/index.tsx index 6f896cfd95901..6d4a88c45a768 100644 --- a/x-pack/legacy/plugins/siem/public/containers/authentications/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/authentications/index.tsx @@ -8,8 +8,8 @@ import { getOr } from 'lodash/fp'; import React from 'react'; import { Query } from 'react-apollo'; import { connect } from 'react-redux'; +import { compose } from 'redux'; -import chrome from 'ui/chrome'; import { DEFAULT_INDEX_KEY } from '../../../common/constants'; import { AuthenticationsEdges, @@ -19,6 +19,7 @@ import { import { hostsModel, hostsSelectors, inputsModel, State, inputsSelectors } from '../../store'; import { createFilter, getDefaultFetchPolicy } from '../helpers'; import { generateTablePaginationOptions } from '../../components/paginated_table/helpers'; +import { withKibana, WithKibanaProps } from '../../lib/kibana'; import { QueryTemplatePaginated, QueryTemplatePaginatedProps } from '../query_template_paginated'; import { authenticationsQuery } from './index.gql_query'; @@ -48,7 +49,7 @@ export interface AuthenticationsComponentReduxProps { limit: number; } -type AuthenticationsProps = OwnProps & AuthenticationsComponentReduxProps; +type AuthenticationsProps = OwnProps & AuthenticationsComponentReduxProps & WithKibanaProps; class AuthenticationsComponentQuery extends QueryTemplatePaginated< AuthenticationsProps, @@ -63,6 +64,7 @@ class AuthenticationsComponentQuery extends QueryTemplatePaginated< filterQuery, id = ID, isInspected, + kibana, limit, skip, sourceId, @@ -77,7 +79,7 @@ class AuthenticationsComponentQuery extends QueryTemplatePaginated< }, pagination: generateTablePaginationOptions(activePage, limit), filterQuery: createFilter(filterQuery), - defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + defaultIndex: kibana.services.uiSettings.get(DEFAULT_INDEX_KEY), inspect: isInspected, }; return ( @@ -142,4 +144,7 @@ const makeMapStateToProps = () => { return mapStateToProps; }; -export const AuthenticationsQuery = connect(makeMapStateToProps)(AuthenticationsComponentQuery); +export const AuthenticationsQuery = compose>( + connect(makeMapStateToProps), + withKibana +)(AuthenticationsComponentQuery); diff --git a/x-pack/legacy/plugins/siem/public/containers/detection_engine/rules/persist_rule.tsx b/x-pack/legacy/plugins/siem/public/containers/detection_engine/rules/persist_rule.tsx index 371d28aebf7f7..82490991236de 100644 --- a/x-pack/legacy/plugins/siem/public/containers/detection_engine/rules/persist_rule.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/detection_engine/rules/persist_rule.tsx @@ -6,7 +6,7 @@ import { useEffect, useState, Dispatch } from 'react'; -import { useKibanaUiSetting } from '../../../lib/settings/use_kibana_ui_setting'; +import { useUiSetting$ } from '../../../lib/kibana'; import { DEFAULT_KBN_VERSION } from '../../../../common/constants'; import { useStateToaster } from '../../../components/toasters'; import { errorToToaster } from '../../../components/ml/api/error_to_toaster'; @@ -26,7 +26,7 @@ export const usePersistRule = (): Return => { const [rule, setRule] = useState(null); const [isSaved, setIsSaved] = useState(false); const [isLoading, setIsLoading] = useState(false); - const [kbnVersion] = useKibanaUiSetting(DEFAULT_KBN_VERSION); + const [kbnVersion] = useUiSetting$(DEFAULT_KBN_VERSION); const [, dispatchToaster] = useStateToaster(); useEffect(() => { diff --git a/x-pack/legacy/plugins/siem/public/containers/detection_engine/rules/use_rule.tsx b/x-pack/legacy/plugins/siem/public/containers/detection_engine/rules/use_rule.tsx index 8ba59a86a2b85..ad0b87385ee79 100644 --- a/x-pack/legacy/plugins/siem/public/containers/detection_engine/rules/use_rule.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/detection_engine/rules/use_rule.tsx @@ -6,7 +6,7 @@ import { useEffect, useState } from 'react'; -import { useKibanaUiSetting } from '../../../lib/settings/use_kibana_ui_setting'; +import { useUiSetting$ } from '../../../lib/kibana'; import { DEFAULT_KBN_VERSION } from '../../../../common/constants'; import { useStateToaster } from '../../../components/toasters'; import { errorToToaster } from '../../../components/ml/api/error_to_toaster'; @@ -25,7 +25,7 @@ type Return = [boolean, Rule | null]; export const useRule = (id: string | undefined): Return => { const [rule, setRule] = useState(null); const [loading, setLoading] = useState(true); - const [kbnVersion] = useKibanaUiSetting(DEFAULT_KBN_VERSION); + const [kbnVersion] = useUiSetting$(DEFAULT_KBN_VERSION); const [, dispatchToaster] = useStateToaster(); useEffect(() => { diff --git a/x-pack/legacy/plugins/siem/public/containers/detection_engine/rules/use_rules.tsx b/x-pack/legacy/plugins/siem/public/containers/detection_engine/rules/use_rules.tsx index 2b8bb986a296a..66285c804aa28 100644 --- a/x-pack/legacy/plugins/siem/public/containers/detection_engine/rules/use_rules.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/detection_engine/rules/use_rules.tsx @@ -6,7 +6,7 @@ import { useEffect, useState } from 'react'; -import { useKibanaUiSetting } from '../../../lib/settings/use_kibana_ui_setting'; +import { useUiSetting$ } from '../../../lib/kibana'; import { DEFAULT_KBN_VERSION } from '../../../../common/constants'; import { FetchRulesResponse, FilterOptions, PaginationOptions } from './types'; import { useStateToaster } from '../../../components/toasters'; @@ -35,7 +35,7 @@ export const useRules = ( data: [], }); const [loading, setLoading] = useState(true); - const [kbnVersion] = useKibanaUiSetting(DEFAULT_KBN_VERSION); + const [kbnVersion] = useUiSetting$(DEFAULT_KBN_VERSION); const [, dispatchToaster] = useStateToaster(); useEffect(() => { diff --git a/x-pack/legacy/plugins/siem/public/containers/detection_engine/signals/use_query.tsx b/x-pack/legacy/plugins/siem/public/containers/detection_engine/signals/use_query.tsx index a1b3907e2b31b..d865625288550 100644 --- a/x-pack/legacy/plugins/siem/public/containers/detection_engine/signals/use_query.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/detection_engine/signals/use_query.tsx @@ -6,7 +6,7 @@ import { useEffect, useState } from 'react'; -import { useKibanaUiSetting } from '../../../lib/settings/use_kibana_ui_setting'; +import { useUiSetting$ } from '../../../lib/kibana'; import { DEFAULT_KBN_VERSION } from '../../../../common/constants'; import { errorToToaster } from '../../../components/ml/api/error_to_toaster'; import { useStateToaster } from '../../../components/toasters'; @@ -26,7 +26,7 @@ type Return = [boolean, SignalSearchResponse | null]; export const useQuerySignals = (query: string): Return => { const [signals, setSignals] = useState | null>(null); const [loading, setLoading] = useState(true); - const [kbnVersion] = useKibanaUiSetting(DEFAULT_KBN_VERSION); + const [kbnVersion] = useUiSetting$(DEFAULT_KBN_VERSION); const [, dispatchToaster] = useStateToaster(); useEffect(() => { diff --git a/x-pack/legacy/plugins/siem/public/containers/events/events_over_time/index.tsx b/x-pack/legacy/plugins/siem/public/containers/events/events_over_time/index.tsx index 77ce98e180ab0..e102cd11f108e 100644 --- a/x-pack/legacy/plugins/siem/public/containers/events/events_over_time/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/events/events_over_time/index.tsx @@ -8,12 +8,13 @@ import { getOr } from 'lodash/fp'; import React from 'react'; import { Query } from 'react-apollo'; import { connect } from 'react-redux'; +import { compose } from 'redux'; -import chrome from 'ui/chrome'; import { DEFAULT_INDEX_KEY } from '../../../../common/constants'; import { inputsModel, State, inputsSelectors, hostsModel } from '../../../store'; import { createFilter, getDefaultFetchPolicy } from '../../helpers'; import { QueryTemplate, QueryTemplateProps } from '../../query_template'; +import { withKibana, WithKibanaProps } from '../../../lib/kibana'; import { EventsOverTimeGqlQuery } from './events_over_time.gql_query'; import { GetEventsOverTimeQuery, MatrixOverTimeHistogramData } from '../../../graphql/types'; @@ -40,7 +41,7 @@ export interface EventsOverTimeComponentReduxProps { isInspected: boolean; } -type EventsOverTimeProps = OwnProps & EventsOverTimeComponentReduxProps; +type EventsOverTimeProps = OwnProps & EventsOverTimeComponentReduxProps & WithKibanaProps; class EventsOverTimeComponentQuery extends QueryTemplate< EventsOverTimeProps, @@ -54,6 +55,7 @@ class EventsOverTimeComponentQuery extends QueryTemplate< filterQuery, id = ID, isInspected, + kibana, sourceId, startDate, } = this.props; @@ -70,7 +72,7 @@ class EventsOverTimeComponentQuery extends QueryTemplate< from: startDate!, to: endDate!, }, - defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + defaultIndex: kibana.services.uiSettings.get(DEFAULT_INDEX_KEY), inspect: isInspected, }} > @@ -105,4 +107,7 @@ const makeMapStateToProps = () => { return mapStateToProps; }; -export const EventsOverTimeQuery = connect(makeMapStateToProps)(EventsOverTimeComponentQuery); +export const EventsOverTimeQuery = compose>( + connect(makeMapStateToProps), + withKibana +)(EventsOverTimeComponentQuery); diff --git a/x-pack/legacy/plugins/siem/public/containers/events/last_event_time/index.ts b/x-pack/legacy/plugins/siem/public/containers/events/last_event_time/index.ts index 3bfdbae8d30f7..9cae503d30940 100644 --- a/x-pack/legacy/plugins/siem/public/containers/events/last_event_time/index.ts +++ b/x-pack/legacy/plugins/siem/public/containers/events/last_event_time/index.ts @@ -7,11 +7,11 @@ import { get } from 'lodash/fp'; import React, { useEffect, useState } from 'react'; -import chrome from 'ui/chrome'; import { DEFAULT_INDEX_KEY } from '../../../../common/constants'; import { GetLastEventTimeQuery, LastEventIndexKey, LastTimeDetails } from '../../../graphql/types'; import { inputsModel } from '../../../store'; import { QueryTemplateProps } from '../../query_template'; +import { useUiSetting$ } from '../../../lib/kibana'; import { LastEventTimeGqlQuery } from './last_event_time.gql_query'; import { useApolloClient } from '../../../utils/apollo_context'; @@ -38,6 +38,7 @@ export function useLastEventTimeQuery( const [lastSeen, updateLastSeen] = useState(null); const [errorMessage, updateErrorMessage] = useState(null); const [currentIndexKey, updateCurrentIndexKey] = useState(null); + const [defaultIndex] = useUiSetting$(DEFAULT_INDEX_KEY); const apolloClient = useApolloClient(); async function fetchLastEventTime(signal: AbortSignal) { updateLoading(true); @@ -50,7 +51,7 @@ export function useLastEventTimeQuery( sourceId, indexKey, details, - defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + defaultIndex, }, context: { fetchOptions: { diff --git a/x-pack/legacy/plugins/siem/public/containers/hosts/first_last_seen/index.ts b/x-pack/legacy/plugins/siem/public/containers/hosts/first_last_seen/index.ts index 042de56fbd99d..e36da5bfbe4ee 100644 --- a/x-pack/legacy/plugins/siem/public/containers/hosts/first_last_seen/index.ts +++ b/x-pack/legacy/plugins/siem/public/containers/hosts/first_last_seen/index.ts @@ -8,7 +8,7 @@ import ApolloClient from 'apollo-client'; import { get } from 'lodash/fp'; import React, { useEffect, useState } from 'react'; -import chrome from 'ui/chrome'; +import { useUiSetting$ } from '../../../lib/kibana'; import { DEFAULT_INDEX_KEY } from '../../../../common/constants'; import { GetHostFirstLastSeenQuery } from '../../../graphql/types'; import { inputsModel } from '../../../store'; @@ -39,6 +39,7 @@ export function useFirstLastSeenHostQuery( const [firstSeen, updateFirstSeen] = useState(null); const [lastSeen, updateLastSeen] = useState(null); const [errorMessage, updateErrorMessage] = useState(null); + const [defaultIndex] = useUiSetting$(DEFAULT_INDEX_KEY); async function fetchFirstLastSeenHost(signal: AbortSignal) { updateLoading(true); @@ -49,7 +50,7 @@ export function useFirstLastSeenHostQuery( variables: { sourceId, hostName, - defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + defaultIndex, }, context: { fetchOptions: { diff --git a/x-pack/legacy/plugins/siem/public/containers/hosts/index.tsx b/x-pack/legacy/plugins/siem/public/containers/hosts/index.tsx index d2be29e3e9e29..733c2224d840a 100644 --- a/x-pack/legacy/plugins/siem/public/containers/hosts/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/hosts/index.tsx @@ -9,8 +9,8 @@ import memoizeOne from 'memoize-one'; import React from 'react'; import { Query } from 'react-apollo'; import { connect } from 'react-redux'; +import { compose } from 'redux'; -import chrome from 'ui/chrome'; import { DEFAULT_INDEX_KEY } from '../../../common/constants'; import { Direction, @@ -22,6 +22,7 @@ import { import { hostsModel, hostsSelectors, inputsModel, State, inputsSelectors } from '../../store'; import { createFilter, getDefaultFetchPolicy } from '../helpers'; import { QueryTemplatePaginated, QueryTemplatePaginatedProps } from '../query_template_paginated'; +import { withKibana, WithKibanaProps } from '../../lib/kibana'; import { HostsTableQuery } from './hosts_table.gql_query'; import { generateTablePaginationOptions } from '../../components/paginated_table/helpers'; @@ -57,7 +58,7 @@ export interface HostsComponentReduxProps { direction: Direction; } -type HostsProps = OwnProps & HostsComponentReduxProps; +type HostsProps = OwnProps & HostsComponentReduxProps & WithKibanaProps; class HostsComponentQuery extends QueryTemplatePaginated< HostsProps, @@ -83,12 +84,14 @@ class HostsComponentQuery extends QueryTemplatePaginated< direction, filterQuery, endDate, + kibana, limit, startDate, skip, sourceId, sortField, } = this.props; + const defaultIndex = kibana.services.uiSettings.get(DEFAULT_INDEX_KEY); const variables: GetHostsTableQuery.Variables = { sourceId, @@ -103,7 +106,7 @@ class HostsComponentQuery extends QueryTemplatePaginated< }, pagination: generateTablePaginationOptions(activePage, limit), filterQuery: createFilter(filterQuery), - defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + defaultIndex, inspect: isInspected, }; return ( @@ -174,4 +177,7 @@ const makeMapStateToProps = () => { return mapStateToProps; }; -export const HostsQuery = connect(makeMapStateToProps)(HostsComponentQuery); +export const HostsQuery = compose>( + connect(makeMapStateToProps), + withKibana +)(HostsComponentQuery); diff --git a/x-pack/legacy/plugins/siem/public/containers/hosts/overview/index.tsx b/x-pack/legacy/plugins/siem/public/containers/hosts/overview/index.tsx index a9223143462fd..5057e872b5313 100644 --- a/x-pack/legacy/plugins/siem/public/containers/hosts/overview/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/hosts/overview/index.tsx @@ -7,12 +7,14 @@ import { getOr } from 'lodash/fp'; import React from 'react'; import { Query } from 'react-apollo'; -import chrome from 'ui/chrome'; import { connect } from 'react-redux'; +import { compose } from 'redux'; + import { DEFAULT_INDEX_KEY } from '../../../../common/constants'; import { inputsModel, inputsSelectors, State } from '../../../store'; import { getDefaultFetchPolicy } from '../../helpers'; import { QueryTemplate, QueryTemplateProps } from '../../query_template'; +import { withKibana, WithKibanaProps } from '../../../lib/kibana'; import { HostOverviewQuery } from './host_overview.gql_query'; import { GetHostOverviewQuery, HostItem } from '../../../graphql/types'; @@ -40,8 +42,10 @@ export interface OwnProps extends QueryTemplateProps { endDate: number; } +type HostsOverViewProps = OwnProps & HostOverviewReduxProps & WithKibanaProps; + class HostOverviewByNameComponentQuery extends QueryTemplate< - OwnProps & HostOverviewReduxProps, + HostsOverViewProps, GetHostOverviewQuery.Query, GetHostOverviewQuery.Variables > { @@ -51,6 +55,7 @@ class HostOverviewByNameComponentQuery extends QueryTemplate< isInspected, children, hostName, + kibana, skip, sourceId, startDate, @@ -70,7 +75,7 @@ class HostOverviewByNameComponentQuery extends QueryTemplate< from: startDate, to: endDate, }, - defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + defaultIndex: kibana.services.uiSettings.get(DEFAULT_INDEX_KEY), inspect: isInspected, }} > @@ -102,6 +107,7 @@ const makeMapStateToProps = () => { return mapStateToProps; }; -export const HostOverviewByNameQuery = connect(makeMapStateToProps)( - HostOverviewByNameComponentQuery -); +export const HostOverviewByNameQuery = compose>( + connect(makeMapStateToProps), + withKibana +)(HostOverviewByNameComponentQuery); diff --git a/x-pack/legacy/plugins/siem/public/containers/ip_overview/index.tsx b/x-pack/legacy/plugins/siem/public/containers/ip_overview/index.tsx index 003032493fca2..9576c66c4c9a5 100644 --- a/x-pack/legacy/plugins/siem/public/containers/ip_overview/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/ip_overview/index.tsx @@ -9,10 +9,10 @@ import React from 'react'; import { Query } from 'react-apollo'; import { connect } from 'react-redux'; -import chrome from 'ui/chrome'; import { DEFAULT_INDEX_KEY } from '../../../common/constants'; import { GetIpOverviewQuery, IpOverviewData } from '../../graphql/types'; import { networkModel, inputsModel, inputsSelectors, State } from '../../store'; +import { useUiSetting } from '../../lib/kibana'; import { createFilter, getDefaultFetchPolicy } from '../helpers'; import { QueryTemplateProps } from '../query_template'; @@ -49,7 +49,7 @@ const IpOverviewComponentQuery = React.memo(DEFAULT_INDEX_KEY), inspect: isInspected, }} > diff --git a/x-pack/legacy/plugins/siem/public/containers/kpi_host_details/index.tsx b/x-pack/legacy/plugins/siem/public/containers/kpi_host_details/index.tsx index 20ed7fa991d15..501bc8472b5e2 100644 --- a/x-pack/legacy/plugins/siem/public/containers/kpi_host_details/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/kpi_host_details/index.tsx @@ -8,11 +8,11 @@ import { getOr } from 'lodash/fp'; import React from 'react'; import { Query } from 'react-apollo'; import { connect } from 'react-redux'; -import chrome from 'ui/chrome'; import { DEFAULT_INDEX_KEY } from '../../../common/constants'; import { KpiHostDetailsData, GetKpiHostDetailsQuery } from '../../graphql/types'; import { inputsModel, inputsSelectors, State } from '../../store'; +import { useUiSetting } from '../../lib/kibana'; import { createFilter, getDefaultFetchPolicy } from '../helpers'; import { QueryTemplateProps } from '../query_template'; @@ -51,7 +51,7 @@ const KpiHostDetailsComponentQuery = React.memo(DEFAULT_INDEX_KEY), inspect: isInspected, }} > diff --git a/x-pack/legacy/plugins/siem/public/containers/kpi_hosts/index.tsx b/x-pack/legacy/plugins/siem/public/containers/kpi_hosts/index.tsx index f8aa8aa38e8e1..32472ba6deedf 100644 --- a/x-pack/legacy/plugins/siem/public/containers/kpi_hosts/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/kpi_hosts/index.tsx @@ -8,11 +8,11 @@ import { getOr } from 'lodash/fp'; import React from 'react'; import { Query } from 'react-apollo'; import { connect } from 'react-redux'; -import chrome from 'ui/chrome'; import { DEFAULT_INDEX_KEY } from '../../../common/constants'; import { GetKpiHostsQuery, KpiHostsData } from '../../graphql/types'; import { inputsModel, inputsSelectors, State } from '../../store'; +import { useUiSetting } from '../../lib/kibana'; import { createFilter, getDefaultFetchPolicy } from '../helpers'; import { QueryTemplateProps } from '../query_template'; @@ -51,7 +51,7 @@ const KpiHostsComponentQuery = React.memo( to: endDate!, }, filterQuery: createFilter(filterQuery), - defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + defaultIndex: useUiSetting(DEFAULT_INDEX_KEY), inspect: isInspected, }} > diff --git a/x-pack/legacy/plugins/siem/public/containers/kpi_network/index.tsx b/x-pack/legacy/plugins/siem/public/containers/kpi_network/index.tsx index 269c3593d4d73..52b8814958ba0 100644 --- a/x-pack/legacy/plugins/siem/public/containers/kpi_network/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/kpi_network/index.tsx @@ -8,11 +8,11 @@ import { getOr } from 'lodash/fp'; import React from 'react'; import { Query } from 'react-apollo'; import { connect } from 'react-redux'; -import chrome from 'ui/chrome'; import { DEFAULT_INDEX_KEY } from '../../../common/constants'; import { GetKpiNetworkQuery, KpiNetworkData } from '../../graphql/types'; import { inputsModel, inputsSelectors, State } from '../../store'; +import { useUiSetting } from '../../lib/kibana'; import { createFilter, getDefaultFetchPolicy } from '../helpers'; import { QueryTemplateProps } from '../query_template'; @@ -51,7 +51,7 @@ const KpiNetworkComponentQuery = React.memo to: endDate!, }, filterQuery: createFilter(filterQuery), - defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + defaultIndex: useUiSetting(DEFAULT_INDEX_KEY), inspect: isInspected, }} > diff --git a/x-pack/legacy/plugins/siem/public/containers/kuery_autocompletion/index.tsx b/x-pack/legacy/plugins/siem/public/containers/kuery_autocompletion/index.tsx index d06f4f6fbbbfa..6361f7abcf977 100644 --- a/x-pack/legacy/plugins/siem/public/containers/kuery_autocompletion/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/kuery_autocompletion/index.tsx @@ -9,7 +9,7 @@ import { AutocompleteSuggestion, IIndexPattern, } from '../../../../../../../src/plugins/data/public'; -import { useKibanaPlugins } from '../../lib/compose/kibana_plugins'; +import { useKibana } from '../../lib/kibana'; type RendererResult = React.ReactElement | null; type RendererFunction = (args: RenderArgs) => Result; @@ -34,13 +34,13 @@ export const KueryAutocompletion = React.memo null ); const [suggestions, setSuggestions] = useState([]); - const plugins = useKibanaPlugins(); + const kibana = useKibana(); const loadSuggestions = async ( expression: string, cursorPosition: number, maxSuggestions?: number ) => { - const autocompletionProvider = plugins.data.autocomplete.getProvider('kuery'); + const autocompletionProvider = kibana.services.data.autocomplete.getProvider('kuery'); const config = { get: () => true, }; diff --git a/x-pack/legacy/plugins/siem/public/containers/network_dns/index.tsx b/x-pack/legacy/plugins/siem/public/containers/network_dns/index.tsx index 592fe43b9873f..b5ebf3deacd0a 100644 --- a/x-pack/legacy/plugins/siem/public/containers/network_dns/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/network_dns/index.tsx @@ -8,8 +8,8 @@ import { getOr } from 'lodash/fp'; import React from 'react'; import { Query } from 'react-apollo'; import { connect } from 'react-redux'; +import { compose } from 'redux'; -import chrome from 'ui/chrome'; import { DEFAULT_INDEX_KEY } from '../../../common/constants'; import { GetNetworkDnsQuery, @@ -19,6 +19,7 @@ import { MatrixOverOrdinalHistogramData, } from '../../graphql/types'; import { inputsModel, networkModel, networkSelectors, State, inputsSelectors } from '../../store'; +import { withKibana, WithKibanaProps } from '../../lib/kibana'; import { generateTablePaginationOptions } from '../../components/paginated_table/helpers'; import { createFilter, getDefaultFetchPolicy } from '../helpers'; import { QueryTemplatePaginated, QueryTemplatePaginatedProps } from '../query_template_paginated'; @@ -53,7 +54,7 @@ export interface NetworkDnsComponentReduxProps { limit: number; } -type NetworkDnsProps = OwnProps & NetworkDnsComponentReduxProps; +type NetworkDnsProps = OwnProps & NetworkDnsComponentReduxProps & WithKibanaProps; export class NetworkDnsComponentQuery extends QueryTemplatePaginated< NetworkDnsProps, @@ -70,13 +71,14 @@ export class NetworkDnsComponentQuery extends QueryTemplatePaginated< id = ID, isInspected, isPtrIncluded, + kibana, limit, skip, sourceId, startDate, } = this.props; const variables: GetNetworkDnsQuery.Variables = { - defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + defaultIndex: kibana.services.uiSettings.get(DEFAULT_INDEX_KEY), filterQuery: createFilter(filterQuery), inspect: isInspected, isPtrIncluded, @@ -172,7 +174,12 @@ const makeMapHistogramStateToProps = () => { return mapStateToProps; }; -export const NetworkDnsQuery = connect(makeMapStateToProps)(NetworkDnsComponentQuery); -export const NetworkDnsHistogramQuery = connect(makeMapHistogramStateToProps)( - NetworkDnsComponentQuery -); +export const NetworkDnsQuery = compose>( + connect(makeMapStateToProps), + withKibana +)(NetworkDnsComponentQuery); + +export const NetworkDnsHistogramQuery = compose>( + connect(makeMapHistogramStateToProps), + withKibana +)(NetworkDnsComponentQuery); diff --git a/x-pack/legacy/plugins/siem/public/containers/network_http/index.tsx b/x-pack/legacy/plugins/siem/public/containers/network_http/index.tsx index d76ab53b2de3a..bf4e64f63d559 100644 --- a/x-pack/legacy/plugins/siem/public/containers/network_http/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/network_http/index.tsx @@ -9,7 +9,6 @@ import React from 'react'; import { Query } from 'react-apollo'; import { connect } from 'react-redux'; import { compose } from 'redux'; -import chrome from 'ui/chrome'; import { DEFAULT_INDEX_KEY } from '../../../common/constants'; import { @@ -19,6 +18,7 @@ import { PageInfoPaginated, } from '../../graphql/types'; import { inputsModel, inputsSelectors, networkModel, networkSelectors, State } from '../../store'; +import { withKibana, WithKibanaProps } from '../../lib/kibana'; import { generateTablePaginationOptions } from '../../components/paginated_table/helpers'; import { createFilter, getDefaultFetchPolicy } from '../helpers'; import { QueryTemplatePaginated, QueryTemplatePaginatedProps } from '../query_template_paginated'; @@ -52,7 +52,7 @@ export interface NetworkHttpComponentReduxProps { sort: NetworkHttpSortField; } -type NetworkHttpProps = OwnProps & NetworkHttpComponentReduxProps; +type NetworkHttpProps = OwnProps & NetworkHttpComponentReduxProps & WithKibanaProps; class NetworkHttpComponentQuery extends QueryTemplatePaginated< NetworkHttpProps, @@ -68,6 +68,7 @@ class NetworkHttpComponentQuery extends QueryTemplatePaginated< id = ID, ip, isInspected, + kibana, limit, skip, sourceId, @@ -75,7 +76,7 @@ class NetworkHttpComponentQuery extends QueryTemplatePaginated< startDate, } = this.props; const variables: GetNetworkHttpQuery.Variables = { - defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + defaultIndex: kibana.services.uiSettings.get(DEFAULT_INDEX_KEY), filterQuery: createFilter(filterQuery), inspect: isInspected, ip, @@ -150,5 +151,6 @@ const makeMapStateToProps = () => { }; export const NetworkHttpQuery = compose>( - connect(makeMapStateToProps) + connect(makeMapStateToProps), + withKibana )(NetworkHttpComponentQuery); diff --git a/x-pack/legacy/plugins/siem/public/containers/network_top_countries/index.tsx b/x-pack/legacy/plugins/siem/public/containers/network_top_countries/index.tsx index b179745dafa51..bd1e1a002bbcd 100644 --- a/x-pack/legacy/plugins/siem/public/containers/network_top_countries/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/network_top_countries/index.tsx @@ -10,7 +10,6 @@ import { Query } from 'react-apollo'; import { connect } from 'react-redux'; import { compose } from 'redux'; -import chrome from 'ui/chrome'; import { DEFAULT_INDEX_KEY } from '../../../common/constants'; import { FlowTargetSourceDest, @@ -20,6 +19,7 @@ import { PageInfoPaginated, } from '../../graphql/types'; import { inputsModel, inputsSelectors, networkModel, networkSelectors, State } from '../../store'; +import { withKibana, WithKibanaProps } from '../../lib/kibana'; import { generateTablePaginationOptions } from '../../components/paginated_table/helpers'; import { createFilter, getDefaultFetchPolicy } from '../helpers'; import { QueryTemplatePaginated, QueryTemplatePaginatedProps } from '../query_template_paginated'; @@ -54,7 +54,7 @@ export interface NetworkTopCountriesComponentReduxProps { sort: NetworkTopTablesSortField; } -type NetworkTopCountriesProps = OwnProps & NetworkTopCountriesComponentReduxProps; +type NetworkTopCountriesProps = OwnProps & NetworkTopCountriesComponentReduxProps & WithKibanaProps; class NetworkTopCountriesComponentQuery extends QueryTemplatePaginated< NetworkTopCountriesProps, @@ -68,6 +68,7 @@ class NetworkTopCountriesComponentQuery extends QueryTemplatePaginated< endDate, flowTarget, filterQuery, + kibana, id = `${ID}-${flowTarget}`, ip, isInspected, @@ -78,7 +79,7 @@ class NetworkTopCountriesComponentQuery extends QueryTemplatePaginated< sort, } = this.props; const variables: GetNetworkTopCountriesQuery.Variables = { - defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + defaultIndex: kibana.services.uiSettings.get(DEFAULT_INDEX_KEY), filterQuery: createFilter(filterQuery), flowTarget, inspect: isInspected, @@ -154,5 +155,6 @@ const makeMapStateToProps = () => { }; export const NetworkTopCountriesQuery = compose>( - connect(makeMapStateToProps) + connect(makeMapStateToProps), + withKibana )(NetworkTopCountriesComponentQuery); diff --git a/x-pack/legacy/plugins/siem/public/containers/network_top_n_flow/index.tsx b/x-pack/legacy/plugins/siem/public/containers/network_top_n_flow/index.tsx index 239576a48c49f..f0f1f8257f29f 100644 --- a/x-pack/legacy/plugins/siem/public/containers/network_top_n_flow/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/network_top_n_flow/index.tsx @@ -9,7 +9,6 @@ import React from 'react'; import { Query } from 'react-apollo'; import { connect } from 'react-redux'; import { compose } from 'redux'; -import chrome from 'ui/chrome'; import { DEFAULT_INDEX_KEY } from '../../../common/constants'; import { @@ -19,6 +18,7 @@ import { NetworkTopTablesSortField, PageInfoPaginated, } from '../../graphql/types'; +import { withKibana, WithKibanaProps } from '../../lib/kibana'; import { inputsModel, inputsSelectors, networkModel, networkSelectors, State } from '../../store'; import { generateTablePaginationOptions } from '../../components/paginated_table/helpers'; import { createFilter, getDefaultFetchPolicy } from '../helpers'; @@ -54,7 +54,7 @@ export interface NetworkTopNFlowComponentReduxProps { sort: NetworkTopTablesSortField; } -type NetworkTopNFlowProps = OwnProps & NetworkTopNFlowComponentReduxProps; +type NetworkTopNFlowProps = OwnProps & NetworkTopNFlowComponentReduxProps & WithKibanaProps; class NetworkTopNFlowComponentQuery extends QueryTemplatePaginated< NetworkTopNFlowProps, @@ -68,6 +68,7 @@ class NetworkTopNFlowComponentQuery extends QueryTemplatePaginated< endDate, flowTarget, filterQuery, + kibana, id = `${ID}-${flowTarget}`, ip, isInspected, @@ -78,7 +79,7 @@ class NetworkTopNFlowComponentQuery extends QueryTemplatePaginated< sort, } = this.props; const variables: GetNetworkTopNFlowQuery.Variables = { - defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + defaultIndex: kibana.services.uiSettings.get(DEFAULT_INDEX_KEY), filterQuery: createFilter(filterQuery), flowTarget, inspect: isInspected, @@ -154,5 +155,6 @@ const makeMapStateToProps = () => { }; export const NetworkTopNFlowQuery = compose>( - connect(makeMapStateToProps) + connect(makeMapStateToProps), + withKibana )(NetworkTopNFlowComponentQuery); diff --git a/x-pack/legacy/plugins/siem/public/containers/overview/overview_host/index.tsx b/x-pack/legacy/plugins/siem/public/containers/overview/overview_host/index.tsx index 6ef0ee7b33589..36cadd7872cc8 100644 --- a/x-pack/legacy/plugins/siem/public/containers/overview/overview_host/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/overview/overview_host/index.tsx @@ -8,10 +8,10 @@ import { getOr } from 'lodash/fp'; import React from 'react'; import { Query } from 'react-apollo'; import { connect } from 'react-redux'; -import chrome from 'ui/chrome'; import { DEFAULT_INDEX_KEY } from '../../../../common/constants'; import { GetOverviewHostQuery, OverviewHostData } from '../../../graphql/types'; +import { useUiSetting } from '../../../lib/kibana'; import { inputsModel, inputsSelectors } from '../../../store/inputs'; import { State } from '../../../store'; import { createFilter, getDefaultFetchPolicy } from '../../helpers'; @@ -53,7 +53,7 @@ const OverviewHostComponentQuery = React.memo(DEFAULT_INDEX_KEY), inspect: isInspected, }} > diff --git a/x-pack/legacy/plugins/siem/public/containers/overview/overview_network/index.tsx b/x-pack/legacy/plugins/siem/public/containers/overview/overview_network/index.tsx index 677d96c10eee2..9e7d59de0e546 100644 --- a/x-pack/legacy/plugins/siem/public/containers/overview/overview_network/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/overview/overview_network/index.tsx @@ -9,9 +9,9 @@ import React from 'react'; import { Query } from 'react-apollo'; import { connect } from 'react-redux'; -import chrome from 'ui/chrome'; import { DEFAULT_INDEX_KEY } from '../../../../common/constants'; import { GetOverviewNetworkQuery, OverviewNetworkData } from '../../../graphql/types'; +import { useUiSetting } from '../../../lib/kibana'; import { State } from '../../../store'; import { inputsModel, inputsSelectors } from '../../../store/inputs'; import { createFilter, getDefaultFetchPolicy } from '../../helpers'; @@ -55,7 +55,7 @@ export const OverviewNetworkComponentQuery = React.memo< to: endDate, }, filterQuery: createFilter(filterQuery), - defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + defaultIndex: useUiSetting(DEFAULT_INDEX_KEY), inspect: isInspected, }} > diff --git a/x-pack/legacy/plugins/siem/public/containers/source/index.test.tsx b/x-pack/legacy/plugins/siem/public/containers/source/index.test.tsx index 7d6ac73357b15..d1a183a402e37 100644 --- a/x-pack/legacy/plugins/siem/public/containers/source/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/source/index.test.tsx @@ -11,11 +11,11 @@ import { MockedProvider } from 'react-apollo/test-utils'; import { wait } from '../../lib/helpers'; -import '../../mock/ui_settings'; - import { WithSource, indicesExistOrDataTemporarilyUnavailable } from '.'; import { mockBrowserFields, mockIndexFields, mocksSource } from './mock'; +jest.mock('../../lib/kibana'); + describe('Index Fields & Browser Fields', () => { test('Index Fields', async () => { mount( diff --git a/x-pack/legacy/plugins/siem/public/containers/source/index.tsx b/x-pack/legacy/plugins/siem/public/containers/source/index.tsx index 8bddbd14a367c..94524dedbcd59 100644 --- a/x-pack/legacy/plugins/siem/public/containers/source/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/source/index.tsx @@ -10,7 +10,7 @@ import { Query } from 'react-apollo'; import React, { useEffect, useState } from 'react'; import memoizeOne from 'memoize-one'; import { IIndexPattern } from 'src/plugins/data/public'; -import chrome from 'ui/chrome'; +import { useUiSetting$ } from '../../lib/kibana'; import { DEFAULT_INDEX_KEY } from '../../../common/constants'; import { IndexField, SourceQuery } from '../../graphql/types'; @@ -82,6 +82,7 @@ export const getBrowserFields = memoizeOne( ); export const WithSource = React.memo(({ children, sourceId }) => { + const [defaultIndex] = useUiSetting$(DEFAULT_INDEX_KEY); return ( query={sourceQuery} @@ -89,20 +90,14 @@ export const WithSource = React.memo(({ children, sourceId }) = notifyOnNetworkStatusChange variables={{ sourceId, - defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + defaultIndex, }} > {({ data }) => children({ indicesExist: get('source.status.indicesExist', data), browserFields: getBrowserFields(get('source.status.indexFields', data)), - indexPattern: getIndexFields( - chrome - .getUiSettingsClient() - .get(DEFAULT_INDEX_KEY) - .join(), - get('source.status.indexFields', data) - ), + indexPattern: getIndexFields(defaultIndex.join(), get('source.status.indexFields', data)), }) } diff --git a/x-pack/legacy/plugins/siem/public/containers/timeline/details/index.tsx b/x-pack/legacy/plugins/siem/public/containers/timeline/details/index.tsx index cfb3f8bd8dc77..721cfefe01780 100644 --- a/x-pack/legacy/plugins/siem/public/containers/timeline/details/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/timeline/details/index.tsx @@ -8,10 +8,10 @@ import { getOr } from 'lodash/fp'; import memoizeOne from 'memoize-one'; import React from 'react'; import { Query } from 'react-apollo'; -import chrome from 'ui/chrome'; import { DEFAULT_INDEX_KEY } from '../../../../common/constants'; import { DetailItem, GetTimelineDetailsQuery } from '../../../graphql/types'; +import { useUiSetting } from '../../../lib/kibana'; import { timelineDetailsQuery } from './index.gql_query'; @@ -38,7 +38,7 @@ export const TimelineDetailsComponentQuery = React.memo( sourceId, indexName, eventId, - defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + defaultIndex: useUiSetting(DEFAULT_INDEX_KEY), }; return executeQuery ? ( diff --git a/x-pack/legacy/plugins/siem/public/containers/timeline/index.tsx b/x-pack/legacy/plugins/siem/public/containers/timeline/index.tsx index 40ed3b3747c10..f7c2d067a29f5 100644 --- a/x-pack/legacy/plugins/siem/public/containers/timeline/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/timeline/index.tsx @@ -8,9 +8,9 @@ import { getOr } from 'lodash/fp'; import memoizeOne from 'memoize-one'; import React from 'react'; import { Query } from 'react-apollo'; - -import chrome from 'ui/chrome'; +import { compose } from 'redux'; import { connect } from 'react-redux'; + import { DEFAULT_INDEX_KEY } from '../../../common/constants'; import { GetTimelineQuery, @@ -20,6 +20,7 @@ import { TimelineItem, } from '../../graphql/types'; import { inputsModel, inputsSelectors, State } from '../../store'; +import { withKibana, WithKibanaProps } from '../../lib/kibana'; import { createFilter } from '../helpers'; import { QueryTemplate, QueryTemplateProps } from '../query_template'; @@ -50,7 +51,7 @@ export interface OwnProps extends QueryTemplateProps { sortField: SortField; fields: string[]; } -type TimelineQueryProps = OwnProps & TimelineQueryReduxProps; +type TimelineQueryProps = OwnProps & TimelineQueryReduxProps & WithKibanaProps; class TimelineQueryComponent extends QueryTemplate< TimelineQueryProps, @@ -71,6 +72,7 @@ class TimelineQueryComponent extends QueryTemplate< id, indexPattern, isInspected, + kibana, limit, fields, filterQuery, @@ -84,7 +86,8 @@ class TimelineQueryComponent extends QueryTemplate< pagination: { limit, cursor: null, tiebreaker: null }, sortField, defaultIndex: - indexPattern?.title.split(',') ?? chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + indexPattern?.title.split(',') ?? + kibana.services.uiSettings.get(DEFAULT_INDEX_KEY), inspect: isInspected, }; return ( @@ -158,4 +161,7 @@ const makeMapStateToProps = () => { return mapStateToProps; }; -export const TimelineQuery = connect(makeMapStateToProps)(TimelineQueryComponent); +export const TimelineQuery = compose>( + connect(makeMapStateToProps), + withKibana +)(TimelineQueryComponent); diff --git a/x-pack/legacy/plugins/siem/public/containers/tls/index.tsx b/x-pack/legacy/plugins/siem/public/containers/tls/index.tsx index 7abe14ae745c5..3738355c8846e 100644 --- a/x-pack/legacy/plugins/siem/public/containers/tls/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/tls/index.tsx @@ -10,7 +10,6 @@ import { Query } from 'react-apollo'; import { connect } from 'react-redux'; import { compose } from 'redux'; -import chrome from 'ui/chrome'; import { DEFAULT_INDEX_KEY } from '../../../common/constants'; import { PageInfoPaginated, @@ -20,6 +19,7 @@ import { FlowTargetSourceDest, } from '../../graphql/types'; import { inputsModel, networkModel, networkSelectors, State, inputsSelectors } from '../../store'; +import { withKibana, WithKibanaProps } from '../../lib/kibana'; import { createFilter, getDefaultFetchPolicy } from '../helpers'; import { generateTablePaginationOptions } from '../../components/paginated_table/helpers'; import { QueryTemplatePaginated, QueryTemplatePaginatedProps } from '../query_template_paginated'; @@ -53,7 +53,7 @@ export interface TlsComponentReduxProps { sort: TlsSortField; } -type TlsProps = OwnProps & TlsComponentReduxProps; +type TlsProps = OwnProps & TlsComponentReduxProps & WithKibanaProps; class TlsComponentQuery extends QueryTemplatePaginated< TlsProps, @@ -70,6 +70,7 @@ class TlsComponentQuery extends QueryTemplatePaginated< id = ID, ip, isInspected, + kibana, limit, skip, sourceId, @@ -77,7 +78,7 @@ class TlsComponentQuery extends QueryTemplatePaginated< sort, } = this.props; const variables: GetTlsQuery.Variables = { - defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + defaultIndex: kibana.services.uiSettings.get(DEFAULT_INDEX_KEY), filterQuery: createFilter(filterQuery), flowTarget, inspect: isInspected, @@ -152,6 +153,7 @@ const makeMapStateToProps = () => { }; }; -export const TlsQuery = compose>(connect(makeMapStateToProps))( - TlsComponentQuery -); +export const TlsQuery = compose>( + connect(makeMapStateToProps), + withKibana +)(TlsComponentQuery); diff --git a/x-pack/legacy/plugins/siem/public/containers/uncommon_processes/index.tsx b/x-pack/legacy/plugins/siem/public/containers/uncommon_processes/index.tsx index e623110fb7178..520ade954eb5c 100644 --- a/x-pack/legacy/plugins/siem/public/containers/uncommon_processes/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/uncommon_processes/index.tsx @@ -8,8 +8,8 @@ import { getOr } from 'lodash/fp'; import React from 'react'; import { Query } from 'react-apollo'; import { connect } from 'react-redux'; +import { compose } from 'redux'; -import chrome from 'ui/chrome'; import { DEFAULT_INDEX_KEY } from '../../../common/constants'; import { GetUncommonProcessesQuery, @@ -17,6 +17,7 @@ import { UncommonProcessesEdges, } from '../../graphql/types'; import { hostsModel, hostsSelectors, inputsModel, State, inputsSelectors } from '../../store'; +import { withKibana, WithKibanaProps } from '../../lib/kibana'; import { generateTablePaginationOptions } from '../../components/paginated_table/helpers'; import { createFilter, getDefaultFetchPolicy } from '../helpers'; import { QueryTemplatePaginated, QueryTemplatePaginatedProps } from '../query_template_paginated'; @@ -48,7 +49,7 @@ export interface UncommonProcessesComponentReduxProps { limit: number; } -type UncommonProcessesProps = OwnProps & UncommonProcessesComponentReduxProps; +type UncommonProcessesProps = OwnProps & UncommonProcessesComponentReduxProps & WithKibanaProps; class UncommonProcessesComponentQuery extends QueryTemplatePaginated< UncommonProcessesProps, @@ -63,13 +64,14 @@ class UncommonProcessesComponentQuery extends QueryTemplatePaginated< filterQuery, id = ID, isInspected, + kibana, limit, skip, sourceId, startDate, } = this.props; const variables: GetUncommonProcessesQuery.Variables = { - defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + defaultIndex: kibana.services.uiSettings.get(DEFAULT_INDEX_KEY), filterQuery: createFilter(filterQuery), inspect: isInspected, pagination: generateTablePaginationOptions(activePage, limit), @@ -142,4 +144,7 @@ const makeMapStateToProps = () => { return mapStateToProps; }; -export const UncommonProcessesQuery = connect(makeMapStateToProps)(UncommonProcessesComponentQuery); +export const UncommonProcessesQuery = compose>( + connect(makeMapStateToProps), + withKibana +)(UncommonProcessesComponentQuery); diff --git a/x-pack/legacy/plugins/siem/public/containers/users/index.tsx b/x-pack/legacy/plugins/siem/public/containers/users/index.tsx index ea6453b5c5dd4..ece73b7b10ff0 100644 --- a/x-pack/legacy/plugins/siem/public/containers/users/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/users/index.tsx @@ -8,8 +8,8 @@ import { getOr } from 'lodash/fp'; import React from 'react'; import { Query } from 'react-apollo'; import { connect } from 'react-redux'; +import { compose } from 'redux'; -import chrome from 'ui/chrome'; import { DEFAULT_INDEX_KEY } from '../../../common/constants'; import { GetUsersQuery, @@ -19,6 +19,7 @@ import { UsersSortField, } from '../../graphql/types'; import { inputsModel, networkModel, networkSelectors, State, inputsSelectors } from '../../store'; +import { withKibana, WithKibanaProps } from '../../lib/kibana'; import { createFilter, getDefaultFetchPolicy } from '../helpers'; import { generateTablePaginationOptions } from '../../components/paginated_table/helpers'; import { QueryTemplatePaginated, QueryTemplatePaginatedProps } from '../query_template_paginated'; @@ -53,7 +54,7 @@ export interface UsersComponentReduxProps { sort: UsersSortField; } -type UsersProps = OwnProps & UsersComponentReduxProps; +type UsersProps = OwnProps & UsersComponentReduxProps & WithKibanaProps; class UsersComponentQuery extends QueryTemplatePaginated< UsersProps, @@ -70,6 +71,7 @@ class UsersComponentQuery extends QueryTemplatePaginated< id = ID, ip, isInspected, + kibana, limit, skip, sourceId, @@ -77,7 +79,7 @@ class UsersComponentQuery extends QueryTemplatePaginated< sort, } = this.props; const variables: GetUsersQuery.Variables = { - defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + defaultIndex: kibana.services.uiSettings.get(DEFAULT_INDEX_KEY), filterQuery: createFilter(filterQuery), flowTarget, inspect: isInspected, @@ -154,4 +156,7 @@ const makeMapStateToProps = () => { return mapStateToProps; }; -export const UsersQuery = connect(makeMapStateToProps)(UsersComponentQuery); +export const UsersQuery = compose>( + connect(makeMapStateToProps), + withKibana +)(UsersComponentQuery); diff --git a/x-pack/legacy/plugins/siem/public/hooks/use_index_patterns.tsx b/x-pack/legacy/plugins/siem/public/hooks/use_index_patterns.tsx index 091315df314d9..f5b595b0d01c6 100644 --- a/x-pack/legacy/plugins/siem/public/hooks/use_index_patterns.tsx +++ b/x-pack/legacy/plugins/siem/public/hooks/use_index_patterns.tsx @@ -10,7 +10,7 @@ import { DEFAULT_KBN_VERSION } from '../../common/constants'; import { useStateToaster } from '../components/toasters'; import { errorToToaster } from '../components/ml/api/error_to_toaster'; import { IndexPatternSavedObject } from '../components/ml_popover/types'; -import { useKibanaUiSetting } from '../lib/settings/use_kibana_ui_setting'; +import { useUiSetting$ } from '../lib/kibana'; import { getIndexPatterns } from './api/api'; import * as i18n from './translations'; @@ -21,7 +21,7 @@ export const useIndexPatterns = (refreshToggle = false): Return => { const [indexPatterns, setIndexPatterns] = useState([]); const [isLoading, setIsLoading] = useState(true); const [, dispatchToaster] = useStateToaster(); - const [kbnVersion] = useKibanaUiSetting(DEFAULT_KBN_VERSION); + const [kbnVersion] = useUiSetting$(DEFAULT_KBN_VERSION); useEffect(() => { let isSubscribed = true; diff --git a/x-pack/legacy/plugins/siem/public/lib/compose/__mocks__/kibana_core.ts b/x-pack/legacy/plugins/siem/public/lib/compose/__mocks__/kibana_core.ts deleted file mode 100644 index 7511f65dfb309..0000000000000 --- a/x-pack/legacy/plugins/siem/public/lib/compose/__mocks__/kibana_core.ts +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { createUiNewPlatformMock } from 'ui/new_platform/__mocks__/helpers'; - -const npStart = createUiNewPlatformMock().npStart; - -export function useKibanaCore() { - return npStart.core; -} diff --git a/x-pack/legacy/plugins/siem/public/lib/compose/__mocks__/kibana_plugins.ts b/x-pack/legacy/plugins/siem/public/lib/compose/__mocks__/kibana_plugins.ts deleted file mode 100644 index ab255f7c73a06..0000000000000 --- a/x-pack/legacy/plugins/siem/public/lib/compose/__mocks__/kibana_plugins.ts +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { createUiNewPlatformMock } from 'ui/new_platform/__mocks__/helpers'; - -const npStart = createUiNewPlatformMock().npStart; - -export function useKibanaPlugins() { - return npStart.plugins; -} diff --git a/x-pack/legacy/plugins/siem/public/lib/compose/kibana_core.tsx b/x-pack/legacy/plugins/siem/public/lib/compose/kibana_core.tsx deleted file mode 100644 index f2fa261bf3eb4..0000000000000 --- a/x-pack/legacy/plugins/siem/public/lib/compose/kibana_core.tsx +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import React, { createContext, useContext } from 'react'; -import { LegacyCoreStart } from 'src/core/public'; - -interface CoreMountContext { - core: LegacyCoreStart; -} - -// TODO: Replace CoreStart/CoreSetup with AppMountContext -// see: https://github.com/elastic/kibana/pull/41007 - -export const KibanaCoreContext = createContext({} as CoreMountContext['core']); - -export const KibanaCoreContextProvider: React.FC<{ core: CoreMountContext['core'] }> = props => ( - -); - -export function useKibanaCore() { - return useContext(KibanaCoreContext); -} diff --git a/x-pack/legacy/plugins/siem/public/lib/compose/kibana_plugins.tsx b/x-pack/legacy/plugins/siem/public/lib/compose/kibana_plugins.tsx deleted file mode 100644 index 7d1f1bc01edd3..0000000000000 --- a/x-pack/legacy/plugins/siem/public/lib/compose/kibana_plugins.tsx +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import React, { createContext, useContext } from 'react'; -import { PluginsStart } from 'ui/new_platform/new_platform'; - -interface PluginsMountContext { - plugins: PluginsStart; -} - -// TODO: Replace CoreStart/CoreSetup with AppMountContext -// see: https://github.com/elastic/kibana/pull/41007 - -export const KibanaPluginsContext = createContext({} as PluginsMountContext['plugins']); - -export const KibanaPluginsContextProvider: React.FC<{ - plugins: PluginsMountContext['plugins']; -}> = props => ( - -); - -export function useKibanaPlugins() { - return useContext(KibanaPluginsContext); -} diff --git a/x-pack/legacy/plugins/siem/public/lib/kibana/__mocks__/index.ts b/x-pack/legacy/plugins/siem/public/lib/kibana/__mocks__/index.ts new file mode 100644 index 0000000000000..93fd37c4d14cb --- /dev/null +++ b/x-pack/legacy/plugins/siem/public/lib/kibana/__mocks__/index.ts @@ -0,0 +1,19 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { + createKibanaContextProviderMock, + createUseUiSettingMock, + createUseUiSetting$Mock, + createUseKibanaMock, + createWithKibanaMock, +} from '../../../mock/kibana_react'; + +export const useKibana = jest.fn(createUseKibanaMock()); +export const useUiSetting = jest.fn(createUseUiSettingMock()); +export const useUiSetting$ = jest.fn(createUseUiSetting$Mock()); +export const withKibana = jest.fn(createWithKibanaMock()); +export const KibanaContextProvider = jest.fn(createKibanaContextProviderMock()); diff --git a/x-pack/legacy/plugins/siem/public/lib/kibana/index.ts b/x-pack/legacy/plugins/siem/public/lib/kibana/index.ts new file mode 100644 index 0000000000000..96d9c8330d265 --- /dev/null +++ b/x-pack/legacy/plugins/siem/public/lib/kibana/index.ts @@ -0,0 +1,31 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { + KibanaContextProvider, + KibanaReactContextValue, + useKibana, + useUiSetting, + useUiSetting$, + withKibana, +} from '../../../../../../../src/plugins/kibana_react/public'; +import { StartServices } from '../../apps/plugin'; + +export type KibanaContext = KibanaReactContextValue; +export interface WithKibanaProps { + kibana: KibanaContext; +} + +// eslint-disable-next-line react-hooks/rules-of-hooks +const typedUseKibana = () => useKibana(); + +export { + KibanaContextProvider, + typedUseKibana as useKibana, + useUiSetting, + useUiSetting$, + withKibana, +}; diff --git a/x-pack/legacy/plugins/siem/public/lib/settings/__mocks__/use_kibana_ui_setting.ts b/x-pack/legacy/plugins/siem/public/lib/settings/__mocks__/use_kibana_ui_setting.ts deleted file mode 100644 index 9f5639ce19997..0000000000000 --- a/x-pack/legacy/plugins/siem/public/lib/settings/__mocks__/use_kibana_ui_setting.ts +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { mockFrameworks, getMockKibanaUiSetting } from '../../../mock'; - -type GenericValue = string | boolean | number; - -export const useKibanaUiSetting = (key: string, defaultValue?: GenericValue) => { - return getMockKibanaUiSetting(mockFrameworks.default_UTC)(key); -}; diff --git a/x-pack/legacy/plugins/siem/public/lib/settings/use_kibana_ui_setting.ts b/x-pack/legacy/plugins/siem/public/lib/settings/use_kibana_ui_setting.ts deleted file mode 100644 index 0a89edb85e6ea..0000000000000 --- a/x-pack/legacy/plugins/siem/public/lib/settings/use_kibana_ui_setting.ts +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { useCallback, useMemo } from 'react'; -// @ts-ignore: path dynamic for kibana -import { timezoneProvider } from 'ui/vis/lib/timezone'; - -import { DEFAULT_KBN_VERSION, DEFAULT_TIMEZONE_BROWSER } from '../../../common/constants'; -import { useKibanaCore } from '../compose/kibana_core'; -import { useObservable } from './use_observable'; - -type GenericValue = string | boolean | number; - -/** - * This hook behaves like a `useState` hook in that it provides a requested - * setting value (with an optional default) from the Kibana UI settings (also - * known as "advanced settings") and a setter to change that setting: - * - * ``` - * const [darkMode, setDarkMode] = useKibanaUiSetting('theme:darkMode'); - * ``` - * - * This is not just a static consumption of the value, but will reactively - * update when the underlying setting subscription of the `UiSettingsClient` - * notifies of a change. - * - * Unlike the `useState`, it doesn't give type guarantees for the value, - * because the underlying `UiSettingsClient` doesn't support that. - */ -export const useKibanaUiSetting = (key: string, defaultValue?: GenericValue) => { - const core = useKibanaCore(); - const uiSettingsClient = core.uiSettings; - const uiInjectedMetadata = core.injectedMetadata; - - if (key === DEFAULT_KBN_VERSION) { - return [uiInjectedMetadata.getKibanaVersion()]; - } - - /* eslint-disable react-hooks/rules-of-hooks */ - if (key === DEFAULT_TIMEZONE_BROWSER) { - return [useMemo(() => timezoneProvider(uiSettingsClient)(), [uiSettingsClient])]; - } - - const uiSetting$ = useMemo(() => uiSettingsClient.get$(key, defaultValue), [uiSettingsClient]); - const uiSetting = useObservable(uiSetting$); - const setUiSetting = useCallback((value: GenericValue) => uiSettingsClient.set(key, value), [ - uiSettingsClient, - ]); - /* eslint-enable react-hooks/rules-of-hooks */ - - return [uiSetting, setUiSetting]; -}; diff --git a/x-pack/legacy/plugins/siem/public/lib/settings/use_kibana_ui_settings.test.tsx b/x-pack/legacy/plugins/siem/public/lib/settings/use_kibana_ui_settings.test.tsx deleted file mode 100644 index 9af4759b25608..0000000000000 --- a/x-pack/legacy/plugins/siem/public/lib/settings/use_kibana_ui_settings.test.tsx +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ -import * as React from 'react'; - -import { DEFAULT_KBN_VERSION, DEFAULT_TIMEZONE_BROWSER } from '../../../common/constants'; -import { HookWrapper } from '../../mock/hook_wrapper'; -import { useKibanaCore } from '../compose/kibana_core'; -import { useKibanaUiSetting } from './use_kibana_ui_setting'; -import { mount } from 'enzyme'; - -const mockUseKibanaCore = useKibanaCore as jest.Mock; -jest.mock('../compose/kibana_core'); -mockUseKibanaCore.mockImplementation(() => ({ - injectedMetadata: { - getKibanaVersion: () => '8.0.0', - }, - uiSettings: { - get$: () => 'world', - }, -})); - -jest.mock('ui/vis/lib/timezone', () => ({ - timezoneProvider: () => () => 'America/New_York', -})); - -jest.mock('./use_observable', () => ({ - useObservable: (val: string) => val, -})); - -describe('useKibanaUiSetting', () => { - test('getKibanaVersion', () => { - const wrapper = mount( useKibanaUiSetting(DEFAULT_KBN_VERSION)} />); - expect(wrapper.text()).toEqual('["8.0.0"]'); - }); - - test('getTimezone', () => { - const wrapper = mount( - useKibanaUiSetting(DEFAULT_TIMEZONE_BROWSER)} /> - ); - expect(wrapper.text()).toEqual('["America/New_York"]'); - }); - - test('get any ui settings', () => { - const wrapper = mount( useKibanaUiSetting('hello')} />); - expect(wrapper.text()).toEqual('["world",null]'); - }); -}); diff --git a/x-pack/legacy/plugins/siem/public/lib/settings/use_observable.ts b/x-pack/legacy/plugins/siem/public/lib/settings/use_observable.ts deleted file mode 100644 index 536b6b2723ae0..0000000000000 --- a/x-pack/legacy/plugins/siem/public/lib/settings/use_observable.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { useEffect, useState } from 'react'; -import { Observable } from 'rxjs'; - -export function useObservable(observable$: Observable): T | undefined; -export function useObservable(observable$: Observable, initialValue: T): T; -export function useObservable(observable$: Observable, initialValue?: T): T | undefined { - const [value, update] = useState(initialValue); - - useEffect(() => { - const s = observable$.subscribe(update); - return () => s.unsubscribe(); - }, [observable$]); - - return value; -} diff --git a/x-pack/legacy/plugins/siem/public/lib/theme/use_eui_theme.tsx b/x-pack/legacy/plugins/siem/public/lib/theme/use_eui_theme.tsx index b1defcb34066d..1696001203bc8 100644 --- a/x-pack/legacy/plugins/siem/public/lib/theme/use_eui_theme.tsx +++ b/x-pack/legacy/plugins/siem/public/lib/theme/use_eui_theme.tsx @@ -8,9 +8,9 @@ import darkTheme from '@elastic/eui/dist/eui_theme_dark.json'; import lightTheme from '@elastic/eui/dist/eui_theme_light.json'; import { DEFAULT_DARK_MODE } from '../../../common/constants'; -import { useKibanaUiSetting } from '../settings/use_kibana_ui_setting'; +import { useUiSetting$ } from '../kibana'; export const useEuiTheme = () => { - const [darkMode] = useKibanaUiSetting(DEFAULT_DARK_MODE); + const [darkMode] = useUiSetting$(DEFAULT_DARK_MODE); return darkMode ? darkTheme : lightTheme; }; diff --git a/x-pack/legacy/plugins/siem/public/mock/kibana_core.ts b/x-pack/legacy/plugins/siem/public/mock/kibana_core.ts new file mode 100644 index 0000000000000..cf3523a6260bb --- /dev/null +++ b/x-pack/legacy/plugins/siem/public/mock/kibana_core.ts @@ -0,0 +1,13 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { createUiNewPlatformMock } from 'ui/new_platform/__mocks__/helpers'; + +export const createKibanaCoreSetupMock = () => createUiNewPlatformMock().npSetup.core; +export const createKibanaPluginsSetupMock = () => createUiNewPlatformMock().npSetup.plugins; + +export const createKibanaCoreStartMock = () => createUiNewPlatformMock().npStart.core; +export const createKibanaPluginsStartMock = () => createUiNewPlatformMock().npStart.plugins; diff --git a/x-pack/legacy/plugins/siem/public/mock/kibana_react.ts b/x-pack/legacy/plugins/siem/public/mock/kibana_react.ts new file mode 100644 index 0000000000000..15944df1822b3 --- /dev/null +++ b/x-pack/legacy/plugins/siem/public/mock/kibana_react.ts @@ -0,0 +1,95 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React from 'react'; +import { KibanaContextProvider } from '../../../../../../src/plugins/kibana_react/public'; + +import { + DEFAULT_SIEM_TIME_RANGE, + DEFAULT_SIEM_REFRESH_INTERVAL, + DEFAULT_INDEX_KEY, + DEFAULT_DATE_FORMAT, + DEFAULT_DATE_FORMAT_TZ, + DEFAULT_DARK_MODE, + DEFAULT_TIME_RANGE, + DEFAULT_REFRESH_RATE_INTERVAL, + DEFAULT_FROM, + DEFAULT_TO, + DEFAULT_INTERVAL_PAUSE, + DEFAULT_INTERVAL_VALUE, + DEFAULT_TIMEZONE_BROWSER, +} from '../../common/constants'; +import { defaultIndexPattern } from '../../default_index_pattern'; +import { createKibanaCoreStartMock, createKibanaPluginsStartMock } from './kibana_core'; + +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export const mockUiSettings: Record = { + [DEFAULT_TIME_RANGE]: { from: 'now-15m', to: 'now', mode: 'quick' }, + [DEFAULT_REFRESH_RATE_INTERVAL]: { pause: false, value: 0 }, + [DEFAULT_SIEM_TIME_RANGE]: { + from: DEFAULT_FROM, + to: DEFAULT_TO, + }, + [DEFAULT_SIEM_REFRESH_INTERVAL]: { + pause: DEFAULT_INTERVAL_PAUSE, + value: DEFAULT_INTERVAL_VALUE, + }, + [DEFAULT_INDEX_KEY]: defaultIndexPattern, + [DEFAULT_DATE_FORMAT_TZ]: 'UTC', + [DEFAULT_TIMEZONE_BROWSER]: 'America/New_York', + [DEFAULT_DATE_FORMAT]: 'MMM D, YYYY @ HH:mm:ss.SSS', + [DEFAULT_DARK_MODE]: false, +}; + +export const createUseUiSettingMock = () => ( + key: string, + defaultValue?: T +): T => { + const result = mockUiSettings[key]; + + if (typeof result != null) return result; + + if (defaultValue != null) { + return defaultValue; + } + + throw new Error(`Unexpected config key: ${key}`); +}; + +export const createUseUiSetting$Mock = () => { + const useUiSettingMock = createUseUiSettingMock(); + + return ( + key: string, + defaultValue?: T + ): [T, () => void] | undefined => [useUiSettingMock(key, defaultValue), jest.fn()]; +}; + +export const createUseKibanaMock = () => { + const services = { ...createKibanaCoreStartMock(), ...createKibanaPluginsStartMock() }; + + return () => ({ services }); +}; + +export const createWithKibanaMock = () => { + const kibana = createUseKibanaMock()(); + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return (Component: any) => (props: any) => { + return React.createElement(Component, { ...props, kibana }); + }; +}; + +export const createKibanaContextProviderMock = () => { + const kibana = createUseKibanaMock()(); + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return ({ services, ...rest }: any) => + React.createElement(KibanaContextProvider, { + ...rest, + services: { ...kibana.services, ...services }, + }); +}; diff --git a/x-pack/legacy/plugins/siem/public/mock/test_providers.tsx b/x-pack/legacy/plugins/siem/public/mock/test_providers.tsx index d4c06d998c5a2..6c0a85e3ef778 100644 --- a/x-pack/legacy/plugins/siem/public/mock/test_providers.tsx +++ b/x-pack/legacy/plugins/siem/public/mock/test_providers.tsx @@ -17,12 +17,9 @@ import { Store } from 'redux'; import { BehaviorSubject } from 'rxjs'; import { ThemeProvider } from 'styled-components'; -import { CoreStart } from 'src/core/public'; -import { KibanaContextProvider } from '../../../../../../src/plugins/kibana_react/public'; - import { createStore, State } from '../store'; import { mockGlobalState } from './global_state'; -import { mockUiSettings } from './ui_settings'; +import { createKibanaContextProviderMock } from './kibana_react'; jest.mock('ui/new_platform'); @@ -41,29 +38,6 @@ export const apolloClient = new ApolloClient({ export const apolloClientObservable = new BehaviorSubject(apolloClient); -const services = { - uiSettings: mockUiSettings, - savedObjects: {} as CoreStart['savedObjects'], - notifications: {} as CoreStart['notifications'], - docLinks: { - links: { - query: { - kueryQuerySyntax: '', - }, - }, - } as CoreStart['docLinks'], - http: {} as CoreStart['http'], - overlays: {} as CoreStart['overlays'], - storage: { - get: () => {}, - }, - data: { - query: { - savedQueries: {}, - }, - }, -}; - const localStorageMock = () => { let store: Record = {}; @@ -84,11 +58,13 @@ Object.defineProperty(window, 'localStorage', { value: localStorageMock(), }); +const MockKibanaContextProvider = createKibanaContextProviderMock(); + /** A utility for wrapping children in the providers required to run most tests */ export const TestProviders = React.memo( ({ children, store = createStore(state, apolloClientObservable), onDragEnd = jest.fn() }) => ( - + ({ eui: euiDarkVars, darkMode: true })}> @@ -96,7 +72,7 @@ export const TestProviders = React.memo( - + ) ); diff --git a/x-pack/legacy/plugins/siem/public/mock/ui_settings.ts b/x-pack/legacy/plugins/siem/public/mock/ui_settings.ts deleted file mode 100644 index 6c6411c6bda53..0000000000000 --- a/x-pack/legacy/plugins/siem/public/mock/ui_settings.ts +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import chrome from 'ui/chrome'; -import { - DEFAULT_SIEM_TIME_RANGE, - DEFAULT_SIEM_REFRESH_INTERVAL, - DEFAULT_INDEX_KEY, - DEFAULT_DATE_FORMAT, - DEFAULT_DATE_FORMAT_TZ, - DEFAULT_DARK_MODE, - DEFAULT_TIME_RANGE, - DEFAULT_REFRESH_RATE_INTERVAL, - DEFAULT_FROM, - DEFAULT_TO, - DEFAULT_INTERVAL_PAUSE, - DEFAULT_INTERVAL_VALUE, -} from '../../common/constants'; -import { defaultIndexPattern } from '../../default_index_pattern'; - -chrome.getUiSettingsClient().get.mockImplementation((key: string) => { - switch (key) { - case DEFAULT_TIME_RANGE: - return { from: 'now-15m', to: 'now', mode: 'quick' }; - case DEFAULT_REFRESH_RATE_INTERVAL: - return { pause: false, value: 0 }; - case DEFAULT_SIEM_TIME_RANGE: - return { - from: DEFAULT_FROM, - to: DEFAULT_TO, - }; - case DEFAULT_SIEM_REFRESH_INTERVAL: - return { - pause: DEFAULT_INTERVAL_PAUSE, - value: DEFAULT_INTERVAL_VALUE, - }; - case DEFAULT_INDEX_KEY: - return defaultIndexPattern; - case DEFAULT_DATE_FORMAT_TZ: - return 'Asia/Taipei'; - case DEFAULT_DATE_FORMAT: - return 'MMM D, YYYY @ HH:mm:ss.SSS'; - case DEFAULT_DARK_MODE: - return false; - default: - throw new Error(`Unexpected config key: ${key}`); - } -}); - -export interface MockNpSetUp { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - core: { uiSettings: any }; -} - -type Config = - | 'query:allowLeadingWildcards' - | 'query:queryString:options' - | 'courier:ignoreFilterIfFieldNotInIndex' - | 'dateFormat:tz'; - -export const mockUiSettings = { - get: (item: Config) => { - return mockUiSettings[item]; - }, - get$: () => ({ - subscribe: jest.fn(), - }), - 'query:allowLeadingWildcards': true, - 'query:queryString:options': {}, - 'courier:ignoreFilterIfFieldNotInIndex': true, - 'dateFormat:tz': 'Browser', -}; diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/components/signals/index.tsx b/x-pack/legacy/plugins/siem/public/pages/detection_engine/components/signals/index.tsx index 599870117890d..aeb5e677374fc 100644 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/components/signals/index.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/detection_engine/components/signals/index.tsx @@ -25,7 +25,7 @@ import { SignalFilterOption, SignalsTableFilterGroup, } from './signals_filter_group'; -import { useKibanaUiSetting } from '../../../../lib/settings/use_kibana_ui_setting'; +import { useKibana, useUiSetting$ } from '../../../../lib/kibana'; import { DEFAULT_KBN_VERSION, DEFAULT_SIGNALS_INDEX } from '../../../../../common/constants'; import { defaultHeaders } from '../../../../components/timeline/body/column_headers/default_headers'; import { ColumnHeader } from '../../../../components/timeline/body/column_headers/column_header'; @@ -43,7 +43,6 @@ import { } from './types'; import { inputsActions } from '../../../../store/inputs'; import { combineQueries } from '../../../../components/timeline/helpers'; -import { useKibanaCore } from '../../../../lib/compose/kibana_core'; import { useFetchIndexPatterns } from '../../../../containers/detection_engine/rules/fetch_index_patterns'; import { InputsRange } from '../../../../store/inputs/model'; import { Query } from '../../../../../../../../../src/plugins/data/common/query'; @@ -122,13 +121,13 @@ export const SignalsTableComponent = React.memo( const [{ browserFields, indexPatterns }] = useFetchIndexPatterns([ `${DEFAULT_SIGNALS_INDEX}-default`, ]); // TODO Get from new FrankInspired XavierHook - const [kbnVersion] = useKibanaUiSetting(DEFAULT_KBN_VERSION); - const core = useKibanaCore(); + const [kbnVersion] = useUiSetting$(DEFAULT_KBN_VERSION); + const kibana = useKibana(); const getGlobalQuery = useCallback(() => { if (browserFields != null && indexPatterns != null) { return combineQueries({ - config: esQuery.getEsQueryConfig(core.uiSettings), + config: esQuery.getEsQueryConfig(kibana.services.uiSettings), dataProviders: [], indexPattern: indexPatterns, browserFields, diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/components/signals/signals_utility_bar/index.tsx b/x-pack/legacy/plugins/siem/public/pages/detection_engine/components/signals/signals_utility_bar/index.tsx index 8d754eb1d3e1b..72b250470d19b 100644 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/components/signals/signals_utility_bar/index.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/detection_engine/components/signals/signals_utility_bar/index.tsx @@ -16,7 +16,7 @@ import { } from '../../../../../components/detection_engine/utility_bar'; import * as i18n from './translations'; import { getBatchItems } from './batch_actions'; -import { useKibanaUiSetting } from '../../../../../lib/settings/use_kibana_ui_setting'; +import { useUiSetting$ } from '../../../../../lib/kibana'; import { DEFAULT_NUMBER_FORMAT } from '../../../../../../common/constants'; import { TimelineNonEcsData } from '../../../../../graphql/types'; import { SendSignalsToTimeline, UpdateSignalsStatus } from '../types'; @@ -45,7 +45,7 @@ export const SignalsUtilityBar = React.memo( updateSignalsStatus, sendSignalsToTimeline, }) => { - const [defaultNumberFormat] = useKibanaUiSetting(DEFAULT_NUMBER_FORMAT); + const [defaultNumberFormat] = useUiSetting$(DEFAULT_NUMBER_FORMAT); const getBatchItemsPopoverContent = useCallback( (closePopover: () => void) => ( diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/detection_engine_empty_page.tsx b/x-pack/legacy/plugins/siem/public/pages/detection_engine/detection_engine_empty_page.tsx index cb3e690615395..a217fd6a737e7 100644 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/detection_engine_empty_page.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/detection_engine/detection_engine_empty_page.tsx @@ -6,8 +6,8 @@ import React from 'react'; import chrome from 'ui/chrome'; -import { documentationLinks } from 'ui/documentation_links'; +import { useKibana } from '../../lib/kibana'; import { EmptyPage } from '../../components/empty_page'; import * as i18n from './translations'; @@ -21,7 +21,7 @@ export const DetectionEngineEmptyPage = React.memo(() => ( actionSecondaryIcon="popout" actionSecondaryLabel={i18n.EMPTY_ACTION_SECONDARY} actionSecondaryTarget="_blank" - actionSecondaryUrl={documentationLinks.siem} + actionSecondaryUrl={useKibana().services.docLinks.links.siem} data-test-subj="empty-page" title={i18n.EMPTY_TITLE} /> diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/all/index.tsx b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/all/index.tsx index 4497474b387b1..442360bbf1484 100644 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/all/index.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/all/index.tsx @@ -31,7 +31,7 @@ import { getBatchItems } from './batch_actions'; import { EuiBasicTableOnChange, TableData } from '../types'; import { allRulesReducer, State } from './reducer'; import * as i18n from '../translations'; -import { useKibanaUiSetting } from '../../../../lib/settings/use_kibana_ui_setting'; +import { useUiSetting$ } from '../../../../lib/kibana'; import { DEFAULT_KBN_VERSION } from '../../../../../common/constants'; import { JSONDownloader } from '../components/json_downloader'; import { useStateToaster } from '../../../../components/toasters'; @@ -78,7 +78,7 @@ export const AllRules = React.memo<{ importCompleteToggle: boolean }>(importComp const history = useHistory(); const [isInitialLoad, setIsInitialLoad] = useState(true); const [isLoadingRules, rulesData] = useRules(pagination, filterOptions, refreshToggle); - const [kbnVersion] = useKibanaUiSetting(DEFAULT_KBN_VERSION); + const [kbnVersion] = useUiSetting$(DEFAULT_KBN_VERSION); const [, dispatchToaster] = useStateToaster(); const getBatchItemsPopoverContent = useCallback( diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/description_step/index.tsx b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/description_step/index.tsx index f2fbd373cf4bc..39c660a0079a6 100644 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/description_step/index.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/description_step/index.tsx @@ -25,7 +25,7 @@ import { FilterManager, Query, } from '../../../../../../../../../../src/plugins/data/public'; -import { useKibanaCore } from '../../../../../lib/compose/kibana_core'; +import { useKibana } from '../../../../../lib/kibana'; import { FilterLabel } from './filter_label'; import { FormSchema } from '../shared_imports'; import * as I18n from './translations'; @@ -70,8 +70,8 @@ const MyEuiTextArea = styled(EuiTextArea)` export const StepRuleDescription = memo( ({ data, direction = 'row', indexPatterns, schema }) => { - const core = useKibanaCore(); - const [filterManager] = useState(new FilterManager(core.uiSettings)); + const kibana = useKibana(); + const [filterManager] = useState(new FilterManager(kibana.services.uiSettings)); const keys = Object.keys(schema); const listItems = keys.reduce( diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/import_rule_modal/index.test.tsx b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/import_rule_modal/index.test.tsx index 8dcce36e1a409..381a3138bf617 100644 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/import_rule_modal/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/import_rule_modal/index.test.tsx @@ -8,20 +8,11 @@ import { shallow } from 'enzyme'; import toJson from 'enzyme-to-json'; import * as React from 'react'; import { ImportRuleModalComponent } from './index'; -import { useKibanaUiSetting } from '../../../../../lib/settings/use_kibana_ui_setting'; -import { getMockKibanaUiSetting, MockFrameworks } from '../../../../../mock'; -import { DEFAULT_KBN_VERSION } from '../../../../../../common/constants'; -const mockUseKibanaUiSetting: jest.Mock = useKibanaUiSetting as jest.Mock; -jest.mock('../../../../../lib/settings/use_kibana_ui_setting', () => ({ - useKibanaUiSetting: jest.fn(), -})); +jest.mock('../../../../../lib/kibana'); describe('ImportRuleModal', () => { test('renders correctly against snapshot', () => { - mockUseKibanaUiSetting.mockImplementation( - getMockKibanaUiSetting((DEFAULT_KBN_VERSION as unknown) as MockFrameworks) - ); const wrapper = shallow( { const [selectedFiles, setSelectedFiles] = useState(null); const [isImporting, setIsImporting] = useState(false); - const [kbnVersion] = useKibanaUiSetting(DEFAULT_KBN_VERSION); + const [kbnVersion] = useUiSetting$(DEFAULT_KBN_VERSION); const [, dispatchToaster] = useStateToaster(); const cleanupAndCloseModal = () => { diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/query_bar/index.tsx b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/query_bar/index.tsx index d8d77fcf8abff..c294ec24c4cb7 100644 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/query_bar/index.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/query_bar/index.tsx @@ -20,7 +20,7 @@ import { } from '../../../../../../../../../../src/plugins/data/public'; import { QueryBar } from '../../../../../components/query_bar'; -import { useKibanaCore } from '../../../../../lib/compose/kibana_core'; +import { useKibana } from '../../../../../lib/kibana'; import { useSavedQueryServices } from '../../../../../utils/saved_query_services'; import { FieldHook, getFieldValidityAndErrorMessage } from '../shared_imports'; @@ -68,8 +68,8 @@ export const QueryBarDefineRule = ({ const [queryDraft, setQueryDraft] = useState({ query: '', language: 'kuery' }); const { isInvalid, errorMessage } = getFieldValidityAndErrorMessage(field); - const core = useKibanaCore(); - const [filterManager] = useState(new FilterManager(core.uiSettings)); + const kibana = useKibana(); + const [filterManager] = useState(new FilterManager(kibana.services.uiSettings)); const savedQueryServices = useSavedQueryServices(); diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/rule_switch/index.test.tsx b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/rule_switch/index.test.tsx index 6809acd4b33f6..7a3a99b183971 100644 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/rule_switch/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/rule_switch/index.test.tsx @@ -8,20 +8,8 @@ import { shallow } from 'enzyme'; import toJson from 'enzyme-to-json'; import * as React from 'react'; -import { useKibanaCore } from '../../../../../lib/compose/kibana_core'; - import { RuleSwitchComponent } from './index'; - -const mockUseKibanaCore = useKibanaCore as jest.Mock; -jest.mock('../../../../../lib/compose/kibana_core'); -mockUseKibanaCore.mockImplementation(() => ({ - uiSettings: { - get$: () => 'world', - }, - injectedMetadata: { - getKibanaVersion: () => '8.0.0', - }, -})); +jest.mock('../../../../../lib/kibana'); describe('RuleSwitch', () => { test('renders correctly against snapshot', () => { diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/rule_switch/index.tsx b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/rule_switch/index.tsx index a5d983ec8e224..54f0fc453830e 100644 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/rule_switch/index.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/rule_switch/index.tsx @@ -17,7 +17,7 @@ import React, { useCallback, useState, useEffect } from 'react'; import { DEFAULT_KBN_VERSION } from '../../../../../../common/constants'; import { enableRules } from '../../../../../containers/detection_engine/rules'; -import { useKibanaUiSetting } from '../../../../../lib/settings/use_kibana_ui_setting'; +import { useUiSetting$ } from '../../../../../lib/kibana'; import { enableRulesAction } from '../../all/actions'; import { Action } from '../../all/reducer'; @@ -50,7 +50,7 @@ export const RuleSwitchComponent = ({ }: RuleSwitchProps) => { const [myIsLoading, setMyIsLoading] = useState(false); const [myEnabled, setMyEnabled] = useState(enabled ?? false); - const [kbnVersion] = useKibanaUiSetting(DEFAULT_KBN_VERSION); + const [kbnVersion] = useUiSetting$(DEFAULT_KBN_VERSION); const onRuleStateChange = useCallback( async (event: EuiSwitchEvent) => { diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/step_define_rule/index.tsx b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/step_define_rule/index.tsx index b94e3c35f3ea0..cc4e959cc9c78 100644 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/step_define_rule/index.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/step_define_rule/index.tsx @@ -9,9 +9,9 @@ import { isEqual, get } from 'lodash/fp'; import React, { memo, useCallback, useState, useEffect } from 'react'; import { IIndexPattern } from '../../../../../../../../../../src/plugins/data/public'; -import { useUiSetting$ } from '../../../../../../../../../../src/plugins/kibana_react/public'; import { useFetchIndexPatterns } from '../../../../../containers/detection_engine/rules'; import { DEFAULT_INDEX_KEY } from '../../../../../../common/constants'; +import { useUiSetting$ } from '../../../../../lib/kibana'; import * as RuleI18n from '../../translations'; import { DefineStepRule, RuleStep, RuleStepProps } from '../../types'; import { StepRuleDescription } from '../description_step'; diff --git a/x-pack/legacy/plugins/siem/public/pages/hosts/details/details_tabs.test.tsx b/x-pack/legacy/plugins/siem/public/pages/hosts/details/details_tabs.test.tsx index 8d45bbbe34d33..092c2463419d1 100644 --- a/x-pack/legacy/plugins/siem/public/pages/hosts/details/details_tabs.test.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/hosts/details/details_tabs.test.tsx @@ -10,21 +10,13 @@ import { MemoryRouter } from 'react-router-dom'; import { mockIndexPattern } from '../../../mock/index_pattern'; import { TestProviders } from '../../../mock/test_providers'; -import { mockUiSettings } from '../../../mock/ui_settings'; import { HostDetailsTabs } from './details_tabs'; import { SetAbsoluteRangeDatePicker } from './types'; import { hostDetailsPagePath } from '../types'; import { type } from './utils'; -import { useKibanaCore } from '../../../lib/compose/kibana_core'; import { useMountAppended } from '../../../utils/use_mount_appended'; -jest.mock('../../../lib/settings/use_kibana_ui_setting'); - -const mockUseKibanaCore = useKibanaCore as jest.Mock; -jest.mock('../../../lib/compose/kibana_core'); -mockUseKibanaCore.mockImplementation(() => ({ - uiSettings: mockUiSettings, -})); +jest.mock('../../../lib/kibana'); jest.mock('../../../containers/source', () => ({ indicesExistOrDataTemporarilyUnavailable: () => true, diff --git a/x-pack/legacy/plugins/siem/public/pages/hosts/details/index.tsx b/x-pack/legacy/plugins/siem/public/pages/hosts/details/index.tsx index e062e65bde496..b548d91615d19 100644 --- a/x-pack/legacy/plugins/siem/public/pages/hosts/details/index.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/hosts/details/index.tsx @@ -28,7 +28,7 @@ import { HostOverviewByNameQuery } from '../../../containers/hosts/overview'; import { KpiHostDetailsQuery } from '../../../containers/kpi_host_details'; import { indicesExistOrDataTemporarilyUnavailable, WithSource } from '../../../containers/source'; import { LastEventIndexKey } from '../../../graphql/types'; -import { useKibanaCore } from '../../../lib/compose/kibana_core'; +import { useKibana } from '../../../lib/kibana'; import { convertToBuildEsQuery } from '../../../lib/keury'; import { inputsSelectors, State } from '../../../store'; import { setHostDetailsTablesActivePageToZero as dispatchHostDetailsTablesActivePageToZero } from '../../../store/hosts/actions'; @@ -63,7 +63,7 @@ const HostDetailsComponent = React.memo( setHostDetailsTablesActivePageToZero(null); }, [setHostDetailsTablesActivePageToZero, detailName]); const capabilities = useContext(MlCapabilitiesContext); - const core = useKibanaCore(); + const kibana = useKibana(); const hostDetailsPageFilters: esFilters.Filter[] = [ { meta: { @@ -100,7 +100,7 @@ const HostDetailsComponent = React.memo( {({ indicesExist, indexPattern }) => { const filterQuery = convertToBuildEsQuery({ - config: esQuery.getEsQueryConfig(core.uiSettings), + config: esQuery.getEsQueryConfig(kibana.services.uiSettings), indexPattern, queries: [query], filters: getFilters(), diff --git a/x-pack/legacy/plugins/siem/public/pages/hosts/hosts.test.tsx b/x-pack/legacy/plugins/siem/public/pages/hosts/hosts.test.tsx index f08cee824afa7..00dcb5908a98b 100644 --- a/x-pack/legacy/plugins/siem/public/pages/hosts/hosts.test.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/hosts/hosts.test.tsx @@ -12,30 +12,15 @@ import { MockedProvider } from 'react-apollo/test-utils'; import { ActionCreator } from 'typescript-fsa'; import '../../mock/match_media'; - -import { SiemNavigation } from '../../components/navigation'; import { mocksSource } from '../../containers/source/mock'; import { wait } from '../../lib/helpers'; import { TestProviders } from '../../mock'; -import { mockUiSettings } from '../../mock/ui_settings'; import { InputsModelId } from '../../store/inputs/constants'; +import { SiemNavigation } from '../../components/navigation'; import { HostsComponentProps } from './types'; import { Hosts } from './hosts'; -import { useKibanaCore } from '../../lib/compose/kibana_core'; - -jest.mock('../../lib/settings/use_kibana_ui_setting'); -const mockUseKibanaCore = useKibanaCore as jest.Mock; -jest.mock('../../lib/compose/kibana_core'); -mockUseKibanaCore.mockImplementation(() => ({ - uiSettings: mockUiSettings, -})); - -jest.mock('ui/documentation_links', () => ({ - documentationLinks: { - kibana: 'http://www.example.com', - }, -})); +jest.mock('../../lib/kibana'); // Test will fail because we will to need to mock some core services to make the test work // For now let's forget about SiemSearchBar and QueryBar diff --git a/x-pack/legacy/plugins/siem/public/pages/hosts/hosts.tsx b/x-pack/legacy/plugins/siem/public/pages/hosts/hosts.tsx index 6d217a9301884..6b69f06b97b83 100644 --- a/x-pack/legacy/plugins/siem/public/pages/hosts/hosts.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/hosts/hosts.tsx @@ -25,7 +25,7 @@ import { GlobalTimeArgs } from '../../containers/global_time'; import { KpiHostsQuery } from '../../containers/kpi_hosts'; import { indicesExistOrDataTemporarilyUnavailable, WithSource } from '../../containers/source'; import { LastEventIndexKey } from '../../graphql/types'; -import { useKibanaCore } from '../../lib/compose/kibana_core'; +import { useKibana } from '../../lib/kibana'; import { convertToBuildEsQuery } from '../../lib/keury'; import { inputsSelectors, State, hostsModel } from '../../store'; import { setAbsoluteRangeDatePicker as dispatchSetAbsoluteRangeDatePicker } from '../../store/inputs/actions'; @@ -54,7 +54,7 @@ const HostsComponent = React.memo( hostsPagePath, }) => { const capabilities = React.useContext(MlCapabilitiesContext); - const core = useKibanaCore(); + const kibana = useKibana(); const { tabName } = useParams(); const hostsFilters = React.useMemo(() => { @@ -75,7 +75,7 @@ const HostsComponent = React.memo( {({ indicesExist, indexPattern }) => { const filterQuery = convertToBuildEsQuery({ - config: esQuery.getEsQueryConfig(core.uiSettings), + config: esQuery.getEsQueryConfig(kibana.services.uiSettings), indexPattern, queries: [query], filters: hostsFilters, diff --git a/x-pack/legacy/plugins/siem/public/pages/hosts/hosts_empty_page.tsx b/x-pack/legacy/plugins/siem/public/pages/hosts/hosts_empty_page.tsx index ecd1e4f378cc5..1d2a3f83e8808 100644 --- a/x-pack/legacy/plugins/siem/public/pages/hosts/hosts_empty_page.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/hosts/hosts_empty_page.tsx @@ -6,26 +6,30 @@ import React from 'react'; import chrome from 'ui/chrome'; -import { documentationLinks } from 'ui/documentation_links'; import { EmptyPage } from '../../components/empty_page'; +import { useKibana } from '../../lib/kibana'; import * as i18n from './translations'; const basePath = chrome.getBasePath(); -export const HostsEmptyPage = React.memo(() => ( - -)); +export const HostsEmptyPage = React.memo(() => { + const docLinks = useKibana().services.docLinks; + + return ( + + ); +}); HostsEmptyPage.displayName = 'HostsEmptyPage'; diff --git a/x-pack/legacy/plugins/siem/public/pages/network/ip_details/index.test.tsx b/x-pack/legacy/plugins/siem/public/pages/network/ip_details/index.test.tsx index 72f7858847649..d624631c1feae 100644 --- a/x-pack/legacy/plugins/siem/public/pages/network/ip_details/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/network/ip_details/index.test.tsx @@ -16,27 +16,19 @@ import '../../../mock/match_media'; import { mocksSource } from '../../../containers/source/mock'; import { FlowTarget } from '../../../graphql/types'; -import { useKibanaCore } from '../../../lib/compose/kibana_core'; import { apolloClientObservable, mockGlobalState, TestProviders } from '../../../mock'; import { useMountAppended } from '../../../utils/use_mount_appended'; -import { mockUiSettings } from '../../../mock/ui_settings'; import { createStore, State } from '../../../store'; import { InputsModelId } from '../../../store/inputs/constants'; import { IPDetailsComponent, IPDetails } from './index'; -jest.mock('../../../lib/settings/use_kibana_ui_setting'); - type Action = 'PUSH' | 'POP' | 'REPLACE'; const pop: Action = 'POP'; type GlobalWithFetch = NodeJS.Global & { fetch: jest.Mock }; -const mockUseKibanaCore = useKibanaCore as jest.Mock; -jest.mock('../../../lib/compose/kibana_core'); -mockUseKibanaCore.mockImplementation(() => ({ - uiSettings: mockUiSettings, -})); +jest.mock('../../../lib/kibana'); // Test will fail because we will to need to mock some core services to make the test work // For now let's forget about SiemSearchBar and QueryBar @@ -106,12 +98,6 @@ const getMockProps = (ip: string) => ({ setIpDetailsTablesActivePageToZero: (jest.fn() as unknown) as ActionCreator, }); -jest.mock('ui/documentation_links', () => ({ - documentationLinks: { - siem: 'http://www.example.com', - }, -})); - describe('Ip Details', () => { const mount = useMountAppended(); diff --git a/x-pack/legacy/plugins/siem/public/pages/network/ip_details/index.tsx b/x-pack/legacy/plugins/siem/public/pages/network/ip_details/index.tsx index 97db422b539e8..99ca12292a52c 100644 --- a/x-pack/legacy/plugins/siem/public/pages/network/ip_details/index.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/network/ip_details/index.tsx @@ -24,7 +24,7 @@ import { WrapperPage } from '../../../components/wrapper_page'; import { IpOverviewQuery } from '../../../containers/ip_overview'; import { indicesExistOrDataTemporarilyUnavailable, WithSource } from '../../../containers/source'; import { FlowTargetSourceDest, LastEventIndexKey } from '../../../graphql/types'; -import { useKibanaCore } from '../../../lib/compose/kibana_core'; +import { useKibana } from '../../../lib/kibana'; import { decodeIpv6 } from '../../../lib/helpers'; import { convertToBuildEsQuery } from '../../../lib/keury'; import { ConditionalFlexGroup } from '../../../pages/network/navigation/conditional_flex_group'; @@ -70,7 +70,7 @@ export const IPDetailsComponent = ({ }, [setAbsoluteRangeDatePicker] ); - const core = useKibanaCore(); + const kibana = useKibana(); useEffect(() => { setIpDetailsTablesActivePageToZero(null); @@ -82,7 +82,7 @@ export const IPDetailsComponent = ({ {({ indicesExist, indexPattern }) => { const ip = decodeIpv6(detailName); const filterQuery = convertToBuildEsQuery({ - config: esQuery.getEsQueryConfig(core.uiSettings), + config: esQuery.getEsQueryConfig(kibana.services.uiSettings), indexPattern, queries: [query], filters, diff --git a/x-pack/legacy/plugins/siem/public/pages/network/network.test.tsx b/x-pack/legacy/plugins/siem/public/pages/network/network.test.tsx index 327b0fb4c1e5b..335bb62c5c852 100644 --- a/x-pack/legacy/plugins/siem/public/pages/network/network.test.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/network/network.test.tsx @@ -13,24 +13,10 @@ import { MockedProvider } from 'react-apollo/test-utils'; import '../../mock/match_media'; import { mocksSource } from '../../containers/source/mock'; -import { useKibanaCore } from '../../lib/compose/kibana_core'; import { TestProviders } from '../../mock'; -import { mockUiSettings } from '../../mock/ui_settings'; import { Network } from './network'; -jest.mock('../../lib/settings/use_kibana_ui_setting'); - -jest.mock('ui/documentation_links', () => ({ - documentationLinks: { - kibana: 'http://www.example.com', - }, -})); - -const mockUseKibanaCore = useKibanaCore as jest.Mock; -jest.mock('../../lib/compose/kibana_core'); -mockUseKibanaCore.mockImplementation(() => ({ - uiSettings: mockUiSettings, -})); +jest.mock('../../lib/kibana'); // Test will fail because we will to need to mock some core services to make the test work // For now let's forget about SiemSearchBar and QueryBar diff --git a/x-pack/legacy/plugins/siem/public/pages/network/network.tsx b/x-pack/legacy/plugins/siem/public/pages/network/network.tsx index 0d8d3a6753c59..c39935742a2e0 100644 --- a/x-pack/legacy/plugins/siem/public/pages/network/network.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/network/network.tsx @@ -23,7 +23,7 @@ import { WrapperPage } from '../../components/wrapper_page'; import { KpiNetworkQuery } from '../../containers/kpi_network'; import { indicesExistOrDataTemporarilyUnavailable, WithSource } from '../../containers/source'; import { LastEventIndexKey } from '../../graphql/types'; -import { useKibanaCore } from '../../lib/compose/kibana_core'; +import { useKibana } from '../../lib/kibana'; import { convertToBuildEsQuery } from '../../lib/keury'; import { networkModel, State, inputsSelectors } from '../../store'; import { setAbsoluteRangeDatePicker as dispatchSetAbsoluteRangeDatePicker } from '../../store/inputs/actions'; @@ -51,7 +51,7 @@ const NetworkComponent = React.memo( hasMlUserPermissions, capabilitiesFetched, }) => { - const core = useKibanaCore(); + const kibana = useKibana(); const { tabName } = useParams(); const networkFilters = useMemo(() => { @@ -72,7 +72,7 @@ const NetworkComponent = React.memo( {({ indicesExist, indexPattern }) => { const filterQuery = convertToBuildEsQuery({ - config: esQuery.getEsQueryConfig(core.uiSettings), + config: esQuery.getEsQueryConfig(kibana.services.uiSettings), indexPattern, queries: [query], filters: networkFilters, diff --git a/x-pack/legacy/plugins/siem/public/pages/network/network_empty_page.tsx b/x-pack/legacy/plugins/siem/public/pages/network/network_empty_page.tsx index 34e7f49bd9bd5..e22802fd29d49 100644 --- a/x-pack/legacy/plugins/siem/public/pages/network/network_empty_page.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/network/network_empty_page.tsx @@ -6,26 +6,29 @@ import React from 'react'; import chrome from 'ui/chrome'; -import { documentationLinks } from 'ui/documentation_links'; +import { useKibana } from '../../lib/kibana'; import { EmptyPage } from '../../components/empty_page'; - import * as i18n from './translations'; const basePath = chrome.getBasePath(); -export const NetworkEmptyPage = React.memo(() => ( - -)); +export const NetworkEmptyPage = React.memo(() => { + const docLinks = useKibana().services.docLinks; + + return ( + + ); +}); NetworkEmptyPage.displayName = 'NetworkEmptyPage'; diff --git a/x-pack/legacy/plugins/siem/public/pages/overview/overview.test.tsx b/x-pack/legacy/plugins/siem/public/pages/overview/overview.test.tsx index 833030e0dc8a1..300df4a742adf 100644 --- a/x-pack/legacy/plugins/siem/public/pages/overview/overview.test.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/overview/overview.test.tsx @@ -10,17 +10,11 @@ import * as React from 'react'; import { MockedProvider } from 'react-apollo/test-utils'; import { MemoryRouter } from 'react-router-dom'; -import { Overview } from './index'; - -import '../../mock/ui_settings'; -import { mocksSource } from '../../containers/source/mock'; import { TestProviders } from '../../mock'; +import { mocksSource } from '../../containers/source/mock'; +import { Overview } from './index'; -jest.mock('ui/documentation_links', () => ({ - documentationLinks: { - kibana: 'http://www.example.com', - }, -})); +jest.mock('../../lib/kibana'); let localSource: Array<{ request: {}; diff --git a/x-pack/legacy/plugins/siem/public/pages/overview/overview.tsx b/x-pack/legacy/plugins/siem/public/pages/overview/overview.tsx index de976b1a5c5a3..a0e94431054cc 100644 --- a/x-pack/legacy/plugins/siem/public/pages/overview/overview.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/overview/overview.tsx @@ -8,8 +8,8 @@ import { EuiFlexGroup } from '@elastic/eui'; import moment from 'moment'; import React from 'react'; import chrome from 'ui/chrome'; -import { documentationLinks } from 'ui/documentation_links'; +import { useKibana } from '../../lib/kibana'; import { EmptyPage } from '../../components/empty_page'; import { HeaderPage } from '../../components/header_page'; import { OverviewHost } from '../../components/page/overview/overview_host'; @@ -24,6 +24,7 @@ import * as i18n from './translations'; const basePath = chrome.getBasePath(); export const OverviewComponent = React.memo(() => { + const docLinks = useKibana().services.docLinks; const dateEnd = Date.now(); const dateRange = moment.duration(24, 'hours').asMilliseconds(); const dateStart = dateEnd - dateRange; @@ -62,7 +63,7 @@ export const OverviewComponent = React.memo(() => { actionSecondaryIcon="popout" actionSecondaryLabel={i18n.EMPTY_ACTION_SECONDARY} actionSecondaryTarget="_blank" - actionSecondaryUrl={documentationLinks.siem} + actionSecondaryUrl={docLinks.links.siem} data-test-subj="empty-page" title={i18n.EMPTY_TITLE} /> diff --git a/x-pack/legacy/plugins/siem/public/pages/overview/summary.tsx b/x-pack/legacy/plugins/siem/public/pages/overview/summary.tsx index 7fd8f84129d89..51cfcbe9374ab 100644 --- a/x-pack/legacy/plugins/siem/public/pages/overview/summary.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/overview/summary.tsx @@ -4,73 +4,81 @@ * you may not use this file except in compliance with the Elastic License. */ +import React from 'react'; import { EuiFlexItem, EuiLink, EuiText } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; -import React from 'react'; -import { documentationLinks } from 'ui/documentation_links'; -export const Summary = React.memo(() => ( - - -

- -

+import { useKibana } from '../../lib/kibana'; + +export const Summary = React.memo(() => { + const docLinks = useKibana().services.docLinks; + + return ( + + +

+ +

-

- - - - ), - data: ( - - - - ), - siemSolution: ( - - - - ), - }} - /> -

+

+ + + + ), + data: ( + + + + ), + siemSolution: ( + + + + ), + }} + /> +

-

- -

+

+ +

-

- - - - ), - }} - /> -

-
-
-)); +

+ + + + ), + }} + /> +

+
+
+ ); +}); Summary.displayName = 'Summary'; diff --git a/x-pack/legacy/plugins/siem/public/utils/saved_query_services/index.tsx b/x-pack/legacy/plugins/siem/public/utils/saved_query_services/index.tsx index cda6882fe1714..a8ee10ba2b801 100644 --- a/x-pack/legacy/plugins/siem/public/utils/saved_query_services/index.tsx +++ b/x-pack/legacy/plugins/siem/public/utils/saved_query_services/index.tsx @@ -10,16 +10,18 @@ import { createSavedQueryService, } from '../../../../../../../src/plugins/data/public'; -import { useKibanaCore } from '../../lib/compose/kibana_core'; +import { useKibana } from '../../lib/kibana'; export const useSavedQueryServices = () => { - const core = useKibanaCore(); + const kibana = useKibana(); + const client = kibana.services.savedObjects.client; + const [savedQueryService, setSavedQueryService] = useState( - createSavedQueryService(core.savedObjects.client) + createSavedQueryService(client) ); useEffect(() => { - setSavedQueryService(createSavedQueryService(core.savedObjects.client)); - }, [core.savedObjects.client]); + setSavedQueryService(createSavedQueryService(client)); + }, [client]); return savedQueryService; }; From f89ddc6bfaf0b9ec4daa985ca863f3ce08b62d8e Mon Sep 17 00:00:00 2001 From: Frank Hassanabad Date: Fri, 20 Dec 2019 13:34:42 -0700 Subject: [PATCH 10/14] [SIEM][Detection Engine] More updates with more rules ## Summary * Adds more rules from detection groups ### Checklist Use ~~strikethroughs~~ to remove checklist items you don't feel are applicable to this PR. ~~- [ ] This was checked for cross-browser compatibility, [including a check against IE11](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#cross-browser-compatibility)~~ ~~- [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/master/packages/kbn-i18n/README.md)~~ ~~- [ ] [Documentation](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#writing-documentation) was added for features that require explanation or tutorials~~ - [x] [Unit or functional tests](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#cross-browser-compatibility) were updated or added to match the most common scenarios ~~- [ ] This was checked for [keyboard-only and screenreader accessibility](https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Cross_browser_testing/Accessibility#Accessibility_testing_checklist)~~ ### For maintainers ~~- [ ] This was checked for breaking API changes and was [labeled appropriately](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#release-notes-process)~~ - [x] This includes a feature addition or change that requires a release note and was [labeled appropriately](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#release-notes-process) --- .../rules/prepackaged_rules/index.ts | 464 +++++++++++------- .../zeek_notice_capturelosstoo_much_loss.json | 17 + .../zeek_notice_conncontent_gap.json | 17 + ...tice_connretransmission_inconsistency.json | 17 + .../zeek_notice_dnsexternal_name.json | 17 + .../zeek_notice_ftpbruteforcing.json | 17 + .../zeek_notice_ftpsite_exec_success.json | 17 + ...notice_heartbleedssl_heartbeat_attack.json | 17 + ...eartbleedssl_heartbeat_attack_success.json | 17 + ...heartbleedssl_heartbeat_many_requests.json | 17 + ...ce_heartbleedssl_heartbeat_odd_length.json | 17 + ...eek_notice_httpsql_injection_attacker.json | 17 + .../zeek_notice_httpsql_injection_victim.json | 17 + .../zeek_notice_intelnotice.json | 17 + .../zeek_notice_noticetally.json | 17 + ...ice_packetfiltercannot_bpf_shunt_conn.json | 17 + ...ek_notice_packetfiltercompile_failure.json | 17 + ...ek_notice_packetfilterdropped_packets.json | 17 + ...ek_notice_packetfilterinstall_failure.json | 17 + ...etfilterno_more_conn_shunts_available.json | 17 + ...acketfiltertoo_long_to_compile_filter.json | 17 + ...notice_protocoldetectorprotocol_found.json | 17 + ...k_notice_protocoldetectorserver_found.json | 17 + .../zeek_notice_scanaddress_scan.json | 17 + .../zeek_notice_scanport_scan.json | 17 + ...zeek_notice_signaturescount_signature.json | 17 + ...ice_signaturesmultiple_sig_responders.json | 17 + ..._notice_signaturesmultiple_signatures.json | 17 + ..._notice_signaturessensitive_signature.json | 17 + ...ek_notice_signaturessignature_summary.json | 17 + ...eek_notice_smtpblocklist_blocked_host.json | 17 + ...ek_notice_smtpblocklist_error_message.json | 17 + ...eek_notice_smtpsuspicious_origination.json | 17 + ...otice_softwaresoftware_version_change.json | 17 + ...eek_notice_softwarevulnerable_version.json | 17 + ..._notice_sshinteresting_hostname_login.json | 17 + ...k_notice_sshlogin_by_password_guesser.json | 17 + .../zeek_notice_sshpassword_guessing.json | 17 + .../zeek_notice_sshwatched_country_login.json | 17 + .../zeek_notice_sslcertificate_expired.json | 17 + ...ek_notice_sslcertificate_expires_soon.json | 17 + ...k_notice_sslcertificate_not_valid_yet.json | 17 + .../zeek_notice_sslinvalid_ocsp_response.json | 17 + .../zeek_notice_sslinvalid_server_cert.json | 17 + .../zeek_notice_sslold_version.json | 17 + .../zeek_notice_sslweak_cipher.json | 17 + .../zeek_notice_sslweak_key.json | 17 + ...ice_teamcymrumalwarehashregistrymatch.json | 17 + .../zeek_notice_traceroutedetected.json | 17 + .../zeek_notice_weirdactivity.json | 17 + 50 files changed, 1114 insertions(+), 183 deletions(-) create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_capturelosstoo_much_loss.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_conncontent_gap.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_connretransmission_inconsistency.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_dnsexternal_name.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_ftpbruteforcing.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_ftpsite_exec_success.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_heartbleedssl_heartbeat_attack.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_heartbleedssl_heartbeat_attack_success.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_heartbleedssl_heartbeat_many_requests.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_heartbleedssl_heartbeat_odd_length.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_httpsql_injection_attacker.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_httpsql_injection_victim.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_intelnotice.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_noticetally.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_packetfiltercannot_bpf_shunt_conn.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_packetfiltercompile_failure.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_packetfilterdropped_packets.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_packetfilterinstall_failure.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_packetfilterno_more_conn_shunts_available.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_packetfiltertoo_long_to_compile_filter.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_protocoldetectorprotocol_found.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_protocoldetectorserver_found.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_scanaddress_scan.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_scanport_scan.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_signaturescount_signature.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_signaturesmultiple_sig_responders.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_signaturesmultiple_signatures.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_signaturessensitive_signature.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_signaturessignature_summary.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_smtpblocklist_blocked_host.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_smtpblocklist_error_message.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_smtpsuspicious_origination.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_softwaresoftware_version_change.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_softwarevulnerable_version.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sshinteresting_hostname_login.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sshlogin_by_password_guesser.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sshpassword_guessing.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sshwatched_country_login.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sslcertificate_expired.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sslcertificate_expires_soon.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sslcertificate_not_valid_yet.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sslinvalid_ocsp_response.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sslinvalid_server_cert.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sslold_version.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sslweak_cipher.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sslweak_key.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_teamcymrumalwarehashregistrymatch.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_traceroutedetected.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_weirdactivity.json diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/index.ts b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/index.ts index 69fc9a26e921a..39ed673adb73e 100644 --- a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/index.ts +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/index.ts @@ -41,189 +41,238 @@ import rule31 from './eql_audio_capture_via_powershell.json'; import rule32 from './eql_unusual_parentchild_relationship.json'; import rule33 from './eql_modification_of_boot_configuration.json'; import rule34 from './eql_volume_shadow_copy_deletion_via_vssadmin.json'; -import rule35 from './suricata_category_large_scale_information_leak.json'; -import rule36 from './suricata_category_attempted_information_leak.json'; -import rule37 from './suricata_category_not_suspicious_traffic.json'; -import rule38 from './suricata_category_potentially_bad_traffic.json'; -import rule39 from './suricata_category_information_leak.json'; -import rule40 from './suricata_category_unknown_traffic.json'; -import rule41 from './suricata_category_successful_administrator_privilege_gain.json'; -import rule42 from './suricata_category_attempted_administrator_privilege_gain.json'; -import rule43 from './suricata_category_unsuccessful_user_privilege_gain.json'; -import rule44 from './suricata_category_successful_user_privilege_gain.json'; -import rule45 from './suricata_category_attempted_user_privilege_gain.json'; -import rule46 from './suricata_category_attempted_denial_of_service.json'; -import rule47 from './suricata_category_decode_of_an_rpc_query.json'; -import rule48 from './suricata_category_denial_of_service.json'; -import rule49 from './suricata_category_attempted_login_with_suspicious_username.json'; -import rule50 from './suricata_category_client_using_unusual_port.json'; -import rule51 from './suricata_category_suspicious_filename_detected.json'; -import rule52 from './suricata_category_a_suspicious_string_was_detected.json'; -import rule53 from './suricata_category_tcp_connection_detected.json'; -import rule54 from './suricata_category_executable_code_was_detected.json'; -import rule55 from './suricata_category_network_trojan_detected.json'; -import rule56 from './suricata_category_system_call_detected.json'; -import rule57 from './suricata_category_potentially_vulnerable_web_application_access.json'; -import rule58 from './suricata_category_nonstandard_protocol_or_event.json'; -import rule59 from './suricata_category_denial_of_service_attack.json'; -import rule60 from './suricata_category_generic_protocol_command_decode.json'; -import rule61 from './suricata_category_network_scan_detected.json'; -import rule62 from './suricata_category_web_application_attack.json'; -import rule63 from './suricata_category_generic_icmp_event.json'; -import rule64 from './suricata_category_misc_attack.json'; -import rule65 from './suricata_category_default_username_and_password_login_attempt.json'; -import rule66 from './suricata_category_external_ip_address_retrieval.json'; -import rule67 from './suricata_category_potential_corporate_privacy_violation.json'; -import rule68 from './suricata_category_targeted_malicious_activity.json'; -import rule69 from './suricata_category_observed_c2_domain.json'; -import rule70 from './suricata_category_exploit_kit_activity.json'; -import rule71 from './suricata_category_possibly_unwanted_program.json'; -import rule72 from './suricata_category_successful_credential_theft.json'; -import rule73 from './suricata_category_possible_social_engineering_attempted.json'; -import rule74 from './suricata_category_crypto_currency_mining_activity.json'; -import rule75 from './suricata_category_malware_command_and_control_activity.json'; -import rule76 from './suricata_category_misc_activity.json'; -import rule77 from './windows_powershell_connecting_to_the_internet.json'; -import rule78 from './windows_net_user_command_activity.json'; -import rule79 from './windows_image_load_from_a_temp_directory.json'; -import rule80 from './network_ssh_secure_shell_to_the_internet.json'; -import rule81 from './suricata_nonhttp_traffic_on_tcp_port_80.json'; -import rule82 from './windows_misc_lolbin_connecting_to_the_internet.json'; -import rule83 from './linux_strace_activity.json'; -import rule84 from './suricata_directory_reversal_characters_in_an_http_request.json'; -import rule85 from './suricata_dns_traffic_on_unusual_udp_port.json'; -import rule86 from './network_telnet_port_activity.json'; -import rule87 from './suricata_directory_traversal_in_downloaded_zip_file.json'; -import rule88 from './windows_execution_via_microsoft_html_application_hta.json'; -import rule89 from './windows_credential_dumping_commands.json'; -import rule90 from './windows_net_command_activity_by_the_system_account.json'; -import rule91 from './windows_register_server_program_connecting_to_the_internet.json'; -import rule92 from './linux_java_process_connecting_to_the_internet.json'; -import rule93 from './suricata_imap_traffic_on_unusual_port_internet_destination.json'; -import rule94 from './suricata_double_encoded_characters_in_a_uri.json'; -import rule95 from './network_tor_activity_to_the_internet.json'; -import rule96 from './windows_registry_query_local.json'; -import rule97 from './linux_netcat_network_connection.json'; -import rule98 from './windows_defense_evasion_via_filter_manager.json'; -import rule99 from './suricata_nondns_traffic_on_udp_port_53.json'; -import rule100 from './suricata_double_encoded_characters_in_an_http_post.json'; -import rule101 from './command_shell_started_by_internet_explorer.json'; -import rule102 from './network_vnc_virtual_network_computing_from_the_internet.json'; -import rule103 from './windows_nmap_activity.json'; -import rule104 from './suspicious_process_started_by_a_script.json'; -import rule105 from './windows_network_anomalous_windows_process_using_https_ports.json'; -import rule106 from './powershell_network_connection.json'; -import rule107 from './windows_signed_binary_proxy_execution.json'; -import rule108 from './linux_kernel_module_activity.json'; -import rule109 from './network_vnc_virtual_network_computing_to_the_internet.json'; -import rule110 from './suricata_mimikatz_string_detected_in_http_response.json'; -import rule111 from './command_shell_started_by_svchost.json'; -import rule112 from './linux_tcpdump_activity.json'; -import rule113 from './process_started_by_ms_office_program_possible_payload.json'; -import rule114 from './windows_signed_binary_proxy_execution_download.json'; -import rule115 from './suricata_base64_encoded_startprocess_powershell_execution.json'; -import rule116 from './suricata_base64_encoded_invokecommand_powershell_execution.json'; -import rule117 from './suricata_directory_traversal_characters_in_http_response.json'; -import rule118 from './windows_microsoft_html_application_hta_connecting_to_the_internet.json'; -import rule119 from './suricata_tls_traffic_on_unusual_port_internet_destination.json'; -import rule120 from './process_started_by_acrobat_reader_possible_payload.json'; -import rule121 from './suricata_http_traffic_on_unusual_port_internet_destination.json'; -import rule122 from './windows_persistence_via_modification_of_existing_service.json'; -import rule123 from './windows_defense_evasion_or_persistence_via_hidden_files.json'; -import rule124 from './windows_execution_via_compiled_html_file.json'; -import rule125 from './linux_ptrace_activity.json'; -import rule126 from './suricata_nonimap_traffic_on_port_1443_imap.json'; -import rule127 from './windows_scheduled_task_activity.json'; -import rule128 from './suricata_ftp_traffic_on_unusual_port_internet_destination.json'; -import rule129 from './windows_wireshark_activity.json'; -import rule130 from './windows_execution_via_trusted_developer_utilities.json'; -import rule131 from './suricata_rpc_traffic_on_http_ports.json'; -import rule132 from './windows_process_discovery_via_tasklist_command.json'; -import rule133 from './suricata_cobaltstrike_artifact_in_an_dns_request.json'; -import rule134 from './suricata_serialized_php_detected.json'; -import rule135 from './windows_background_intelligent_transfer_service_bits_connecting_to_the_internet.json'; -import rule136 from './windows_registry_query_network.json'; -import rule137 from './windows_persistence_via_application_shimming.json'; -import rule138 from './network_proxy_port_activity_to_the_internet.json'; -import rule139 from './windows_whoami_command_activity.json'; -import rule140 from './suricata_shell_exec_php_function_in_an_http_post.json'; -import rule141 from './windump_activity.json'; -import rule142 from './windows_management_instrumentation_wmi_execution.json'; -import rule143 from './network_rdp_remote_desktop_protocol_from_the_internet.json'; -import rule144 from './windows_priv_escalation_via_accessibility_features.json'; -import rule145 from './psexec_activity.json'; -import rule146 from './linux_rawshark_activity.json'; -import rule147 from './suricata_nonftp_traffic_on_port_21.json'; -import rule148 from './network_ftp_file_transfer_protocol_activity_to_the_internet.json'; -import rule149 from './windows_certutil_connecting_to_the_internet.json'; -import rule150 from './suricata_nonsmb_traffic_on_tcp_port_139_smb.json'; -import rule151 from './network_rdp_remote_desktop_protocol_to_the_internet.json'; -import rule152 from './linux_whoami_commmand.json'; -import rule153 from './windows_persistence_or_priv_escalation_via_hooking.json'; -import rule154 from './linux_lzop_activity_possible_julianrunnels.json'; -import rule155 from './suricata_nontls_on_tls_port.json'; -import rule156 from './network_irc_internet_relay_chat_protocol_activity_to_the_internet.json'; -import rule157 from './linux_network_anomalous_process_using_https_ports.json'; -import rule158 from './windows_credential_dumping_via_registry_save.json'; -import rule159 from './network_rpc_remote_procedure_call_from_the_internet.json'; -import rule160 from './windows_credential_dumping_via_imageload.json'; -import rule161 from './windows_burp_ce_activity.json'; -import rule162 from './linux_hping_activity.json'; -import rule163 from './windows_command_prompt_connecting_to_the_internet.json'; -import rule164 from './network_nat_traversal_port_activity.json'; -import rule165 from './network_rpc_remote_procedure_call_to_the_internet.json'; -import rule166 from './suricata_possible_cobalt_strike_malleable_c2_null_response.json'; -import rule167 from './windows_remote_management_execution.json'; -import rule168 from './suricata_lazagne_artifact_in_an_http_post.json'; -import rule169 from './windows_netcat_network_activity.json'; -import rule170 from './windows_iodine_activity.json'; -import rule171 from './network_port_26_activity.json'; -import rule172 from './windows_execution_via_connection_manager.json'; -import rule173 from './linux_process_started_in_temp_directory.json'; -import rule174 from './suricata_eval_php_function_in_an_http_request.json'; -import rule175 from './linux_web_download.json'; -import rule176 from './suricata_ssh_traffic_not_on_port_22_internet_destination.json'; -import rule177 from './network_port_8000_activity.json'; -import rule178 from './windows_process_started_by_the_java_runtime.json'; -import rule179 from './suricata_possible_sql_injection_sql_commands_in_http_transactions.json'; -import rule180 from './network_smb_windows_file_sharing_activity_to_the_internet.json'; -import rule181 from './network_port_8000_activity_to_the_internet.json'; -import rule182 from './command_shell_started_by_powershell.json'; -import rule183 from './linux_nmap_activity.json'; -import rule184 from './search_windows_10.json'; -import rule185 from './network_smtp_to_the_internet.json'; -import rule186 from './windows_payload_obfuscation_via_certutil.json'; -import rule187 from './network_pptp_point_to_point_tunneling_protocol_activity.json'; -import rule188 from './linux_unusual_shell_activity.json'; -import rule189 from './linux_mknod_activity.json'; -import rule190 from './network_sql_server_port_activity_to_the_internet.json'; -import rule191 from './suricata_commonly_abused_dns_domain_detected.json'; -import rule192 from './linux_iodine_activity.json'; -import rule193 from './suricata_mimikatz_artifacts_in_an_http_post.json'; -import rule194 from './windows_execution_via_net_com_assemblies.json'; -import rule195 from './suricata_dns_traffic_on_unusual_tcp_port.json'; -import rule196 from './suricata_base64_encoded_newobject_powershell_execution.json'; -import rule197 from './windows_netcat_activity.json'; -import rule198 from './windows_persistence_via_bits_jobs.json'; -import rule199 from './linux_nping_activity.json'; -import rule200 from './windows_execution_via_regsvr32.json'; -import rule201 from './process_started_by_windows_defender.json'; -import rule202 from './windows_indirect_command_execution.json'; -import rule203 from './network_ssh_secure_shell_from_the_internet.json'; -import rule204 from './windows_html_help_executable_program_connecting_to_the_internet.json'; -import rule205 from './suricata_windows_executable_served_by_jpeg_web_content.json'; -import rule206 from './network_dns_directly_to_the_internet.json'; -import rule207 from './windows_defense_evasion_via_windows_event_log_tools.json'; -import rule208 from './suricata_nondns_traffic_on_tcp_port_53.json'; -import rule209 from './windows_persistence_via_netshell_helper_dll.json'; -import rule210 from './windows_script_interpreter_connecting_to_the_internet.json'; -import rule211 from './windows_defense_evasion_decoding_using_certutil.json'; -import rule212 from './linux_shell_activity_by_web_server.json'; -import rule213 from './linux_ldso_process_activity.json'; -import rule214 from './windows_mimikatz_activity.json'; -import rule215 from './suricata_nonssh_traffic_on_port_22.json'; -import rule216 from './windows_data_compression_using_powershell.json'; -import rule217 from './windows_nmap_scan_activity.json'; +import rule35 from './zeek_notice_signaturesmultiple_sig_responders.json'; +import rule36 from './zeek_notice_packetfiltercompile_failure.json'; +import rule37 from './zeek_notice_signaturescount_signature.json'; +import rule38 from './zeek_notice_signaturesmultiple_signatures.json'; +import rule39 from './zeek_notice_signaturessignature_summary.json'; +import rule40 from './zeek_notice_signaturessensitive_signature.json'; +import rule41 from './zeek_notice_packetfilterinstall_failure.json'; +import rule42 from './zeek_notice_weirdactivity.json'; +import rule43 from './zeek_notice_noticetally.json'; +import rule44 from './zeek_notice_packetfilterno_more_conn_shunts_available.json'; +import rule45 from './zeek_notice_packetfiltercannot_bpf_shunt_conn.json'; +import rule46 from './zeek_notice_teamcymrumalwarehashregistrymatch.json'; +import rule47 from './zeek_notice_softwaresoftware_version_change.json'; +import rule48 from './zeek_notice_protocoldetectorserver_found.json'; +import rule49 from './zeek_notice_packetfiltertoo_long_to_compile_filter.json'; +import rule50 from './zeek_notice_protocoldetectorprotocol_found.json'; +import rule51 from './zeek_notice_intelnotice.json'; +import rule52 from './zeek_notice_packetfilterdropped_packets.json'; +import rule53 from './zeek_notice_scanaddress_scan.json'; +import rule54 from './zeek_notice_ftpbruteforcing.json'; +import rule55 from './zeek_notice_scanport_scan.json'; +import rule56 from './zeek_notice_dnsexternal_name.json'; +import rule57 from './zeek_notice_capturelosstoo_much_loss.json'; +import rule58 from './zeek_notice_softwarevulnerable_version.json'; +import rule59 from './zeek_notice_connretransmission_inconsistency.json'; +import rule60 from './zeek_notice_traceroutedetected.json'; +import rule61 from './zeek_notice_conncontent_gap.json'; +import rule62 from './zeek_notice_smtpblocklist_blocked_host.json'; +import rule63 from './zeek_notice_httpsql_injection_victim.json'; +import rule64 from './zeek_notice_sshlogin_by_password_guesser.json'; +import rule65 from './zeek_notice_sshpassword_guessing.json'; +import rule66 from './zeek_notice_sshwatched_country_login.json'; +import rule67 from './zeek_notice_ftpsite_exec_success.json'; +import rule68 from './zeek_notice_smtpsuspicious_origination.json'; +import rule69 from './zeek_notice_httpsql_injection_attacker.json'; +import rule70 from './zeek_notice_smtpblocklist_error_message.json'; +import rule71 from './zeek_notice_sshinteresting_hostname_login.json'; +import rule72 from './zeek_notice_sslinvalid_server_cert.json'; +import rule73 from './zeek_notice_heartbleedssl_heartbeat_many_requests.json'; +import rule74 from './zeek_notice_heartbleedssl_heartbeat_odd_length.json'; +import rule75 from './zeek_notice_sslcertificate_expired.json'; +import rule76 from './zeek_notice_sslcertificate_expires_soon.json'; +import rule77 from './zeek_notice_heartbleedssl_heartbeat_attack_success.json'; +import rule78 from './zeek_notice_sslcertificate_not_valid_yet.json'; +import rule79 from './zeek_notice_heartbleedssl_heartbeat_attack.json'; +import rule80 from './zeek_notice_sslinvalid_ocsp_response.json'; +import rule81 from './zeek_notice_sslweak_key.json'; +import rule82 from './zeek_notice_sslold_version.json'; +import rule83 from './zeek_notice_sslweak_cipher.json'; +import rule84 from './suricata_category_large_scale_information_leak.json'; +import rule85 from './suricata_category_attempted_information_leak.json'; +import rule86 from './suricata_category_not_suspicious_traffic.json'; +import rule87 from './suricata_category_potentially_bad_traffic.json'; +import rule88 from './suricata_category_information_leak.json'; +import rule89 from './suricata_category_unknown_traffic.json'; +import rule90 from './suricata_category_successful_administrator_privilege_gain.json'; +import rule91 from './suricata_category_attempted_administrator_privilege_gain.json'; +import rule92 from './suricata_category_unsuccessful_user_privilege_gain.json'; +import rule93 from './suricata_category_successful_user_privilege_gain.json'; +import rule94 from './suricata_category_attempted_user_privilege_gain.json'; +import rule95 from './suricata_category_attempted_denial_of_service.json'; +import rule96 from './suricata_category_decode_of_an_rpc_query.json'; +import rule97 from './suricata_category_denial_of_service.json'; +import rule98 from './suricata_category_attempted_login_with_suspicious_username.json'; +import rule99 from './suricata_category_client_using_unusual_port.json'; +import rule100 from './suricata_category_suspicious_filename_detected.json'; +import rule101 from './suricata_category_a_suspicious_string_was_detected.json'; +import rule102 from './suricata_category_tcp_connection_detected.json'; +import rule103 from './suricata_category_executable_code_was_detected.json'; +import rule104 from './suricata_category_network_trojan_detected.json'; +import rule105 from './suricata_category_system_call_detected.json'; +import rule106 from './suricata_category_potentially_vulnerable_web_application_access.json'; +import rule107 from './suricata_category_nonstandard_protocol_or_event.json'; +import rule108 from './suricata_category_denial_of_service_attack.json'; +import rule109 from './suricata_category_generic_protocol_command_decode.json'; +import rule110 from './suricata_category_network_scan_detected.json'; +import rule111 from './suricata_category_web_application_attack.json'; +import rule112 from './suricata_category_generic_icmp_event.json'; +import rule113 from './suricata_category_misc_attack.json'; +import rule114 from './suricata_category_default_username_and_password_login_attempt.json'; +import rule115 from './suricata_category_external_ip_address_retrieval.json'; +import rule116 from './suricata_category_potential_corporate_privacy_violation.json'; +import rule117 from './suricata_category_targeted_malicious_activity.json'; +import rule118 from './suricata_category_observed_c2_domain.json'; +import rule119 from './suricata_category_exploit_kit_activity.json'; +import rule120 from './suricata_category_possibly_unwanted_program.json'; +import rule121 from './suricata_category_successful_credential_theft.json'; +import rule122 from './suricata_category_possible_social_engineering_attempted.json'; +import rule123 from './suricata_category_crypto_currency_mining_activity.json'; +import rule124 from './suricata_category_malware_command_and_control_activity.json'; +import rule125 from './suricata_category_misc_activity.json'; +import rule126 from './windows_powershell_connecting_to_the_internet.json'; +import rule127 from './windows_net_user_command_activity.json'; +import rule128 from './windows_image_load_from_a_temp_directory.json'; +import rule129 from './network_ssh_secure_shell_to_the_internet.json'; +import rule130 from './suricata_nonhttp_traffic_on_tcp_port_80.json'; +import rule131 from './windows_misc_lolbin_connecting_to_the_internet.json'; +import rule132 from './linux_strace_activity.json'; +import rule133 from './suricata_directory_reversal_characters_in_an_http_request.json'; +import rule134 from './suricata_dns_traffic_on_unusual_udp_port.json'; +import rule135 from './network_telnet_port_activity.json'; +import rule136 from './suricata_directory_traversal_in_downloaded_zip_file.json'; +import rule137 from './windows_execution_via_microsoft_html_application_hta.json'; +import rule138 from './windows_credential_dumping_commands.json'; +import rule139 from './windows_net_command_activity_by_the_system_account.json'; +import rule140 from './windows_register_server_program_connecting_to_the_internet.json'; +import rule141 from './linux_java_process_connecting_to_the_internet.json'; +import rule142 from './suricata_imap_traffic_on_unusual_port_internet_destination.json'; +import rule143 from './suricata_double_encoded_characters_in_a_uri.json'; +import rule144 from './network_tor_activity_to_the_internet.json'; +import rule145 from './windows_registry_query_local.json'; +import rule146 from './linux_netcat_network_connection.json'; +import rule147 from './windows_defense_evasion_via_filter_manager.json'; +import rule148 from './suricata_nondns_traffic_on_udp_port_53.json'; +import rule149 from './suricata_double_encoded_characters_in_an_http_post.json'; +import rule150 from './command_shell_started_by_internet_explorer.json'; +import rule151 from './network_vnc_virtual_network_computing_from_the_internet.json'; +import rule152 from './windows_nmap_activity.json'; +import rule153 from './suspicious_process_started_by_a_script.json'; +import rule154 from './windows_network_anomalous_windows_process_using_https_ports.json'; +import rule155 from './powershell_network_connection.json'; +import rule156 from './windows_signed_binary_proxy_execution.json'; +import rule157 from './linux_kernel_module_activity.json'; +import rule158 from './network_vnc_virtual_network_computing_to_the_internet.json'; +import rule159 from './suricata_mimikatz_string_detected_in_http_response.json'; +import rule160 from './command_shell_started_by_svchost.json'; +import rule161 from './linux_tcpdump_activity.json'; +import rule162 from './process_started_by_ms_office_program_possible_payload.json'; +import rule163 from './windows_signed_binary_proxy_execution_download.json'; +import rule164 from './suricata_base64_encoded_startprocess_powershell_execution.json'; +import rule165 from './suricata_base64_encoded_invokecommand_powershell_execution.json'; +import rule166 from './suricata_directory_traversal_characters_in_http_response.json'; +import rule167 from './windows_microsoft_html_application_hta_connecting_to_the_internet.json'; +import rule168 from './suricata_tls_traffic_on_unusual_port_internet_destination.json'; +import rule169 from './process_started_by_acrobat_reader_possible_payload.json'; +import rule170 from './suricata_http_traffic_on_unusual_port_internet_destination.json'; +import rule171 from './windows_persistence_via_modification_of_existing_service.json'; +import rule172 from './windows_defense_evasion_or_persistence_via_hidden_files.json'; +import rule173 from './windows_execution_via_compiled_html_file.json'; +import rule174 from './linux_ptrace_activity.json'; +import rule175 from './suricata_nonimap_traffic_on_port_1443_imap.json'; +import rule176 from './windows_scheduled_task_activity.json'; +import rule177 from './suricata_ftp_traffic_on_unusual_port_internet_destination.json'; +import rule178 from './windows_wireshark_activity.json'; +import rule179 from './windows_execution_via_trusted_developer_utilities.json'; +import rule180 from './suricata_rpc_traffic_on_http_ports.json'; +import rule181 from './windows_process_discovery_via_tasklist_command.json'; +import rule182 from './suricata_cobaltstrike_artifact_in_an_dns_request.json'; +import rule183 from './suricata_serialized_php_detected.json'; +import rule184 from './windows_background_intelligent_transfer_service_bits_connecting_to_the_internet.json'; +import rule185 from './windows_registry_query_network.json'; +import rule186 from './windows_persistence_via_application_shimming.json'; +import rule187 from './network_proxy_port_activity_to_the_internet.json'; +import rule188 from './windows_whoami_command_activity.json'; +import rule189 from './suricata_shell_exec_php_function_in_an_http_post.json'; +import rule190 from './windump_activity.json'; +import rule191 from './windows_management_instrumentation_wmi_execution.json'; +import rule192 from './network_rdp_remote_desktop_protocol_from_the_internet.json'; +import rule193 from './windows_priv_escalation_via_accessibility_features.json'; +import rule194 from './psexec_activity.json'; +import rule195 from './linux_rawshark_activity.json'; +import rule196 from './suricata_nonftp_traffic_on_port_21.json'; +import rule197 from './network_ftp_file_transfer_protocol_activity_to_the_internet.json'; +import rule198 from './windows_certutil_connecting_to_the_internet.json'; +import rule199 from './suricata_nonsmb_traffic_on_tcp_port_139_smb.json'; +import rule200 from './network_rdp_remote_desktop_protocol_to_the_internet.json'; +import rule201 from './linux_whoami_commmand.json'; +import rule202 from './windows_persistence_or_priv_escalation_via_hooking.json'; +import rule203 from './linux_lzop_activity_possible_julianrunnels.json'; +import rule204 from './suricata_nontls_on_tls_port.json'; +import rule205 from './network_irc_internet_relay_chat_protocol_activity_to_the_internet.json'; +import rule206 from './linux_network_anomalous_process_using_https_ports.json'; +import rule207 from './windows_credential_dumping_via_registry_save.json'; +import rule208 from './network_rpc_remote_procedure_call_from_the_internet.json'; +import rule209 from './windows_credential_dumping_via_imageload.json'; +import rule210 from './windows_burp_ce_activity.json'; +import rule211 from './linux_hping_activity.json'; +import rule212 from './windows_command_prompt_connecting_to_the_internet.json'; +import rule213 from './network_nat_traversal_port_activity.json'; +import rule214 from './network_rpc_remote_procedure_call_to_the_internet.json'; +import rule215 from './suricata_possible_cobalt_strike_malleable_c2_null_response.json'; +import rule216 from './windows_remote_management_execution.json'; +import rule217 from './suricata_lazagne_artifact_in_an_http_post.json'; +import rule218 from './windows_netcat_network_activity.json'; +import rule219 from './windows_iodine_activity.json'; +import rule220 from './network_port_26_activity.json'; +import rule221 from './windows_execution_via_connection_manager.json'; +import rule222 from './linux_process_started_in_temp_directory.json'; +import rule223 from './suricata_eval_php_function_in_an_http_request.json'; +import rule224 from './linux_web_download.json'; +import rule225 from './suricata_ssh_traffic_not_on_port_22_internet_destination.json'; +import rule226 from './network_port_8000_activity.json'; +import rule227 from './windows_process_started_by_the_java_runtime.json'; +import rule228 from './suricata_possible_sql_injection_sql_commands_in_http_transactions.json'; +import rule229 from './network_smb_windows_file_sharing_activity_to_the_internet.json'; +import rule230 from './network_port_8000_activity_to_the_internet.json'; +import rule231 from './command_shell_started_by_powershell.json'; +import rule232 from './linux_nmap_activity.json'; +import rule233 from './search_windows_10.json'; +import rule234 from './network_smtp_to_the_internet.json'; +import rule235 from './windows_payload_obfuscation_via_certutil.json'; +import rule236 from './network_pptp_point_to_point_tunneling_protocol_activity.json'; +import rule237 from './linux_unusual_shell_activity.json'; +import rule238 from './linux_mknod_activity.json'; +import rule239 from './network_sql_server_port_activity_to_the_internet.json'; +import rule240 from './suricata_commonly_abused_dns_domain_detected.json'; +import rule241 from './linux_iodine_activity.json'; +import rule242 from './suricata_mimikatz_artifacts_in_an_http_post.json'; +import rule243 from './windows_execution_via_net_com_assemblies.json'; +import rule244 from './suricata_dns_traffic_on_unusual_tcp_port.json'; +import rule245 from './suricata_base64_encoded_newobject_powershell_execution.json'; +import rule246 from './windows_netcat_activity.json'; +import rule247 from './windows_persistence_via_bits_jobs.json'; +import rule248 from './linux_nping_activity.json'; +import rule249 from './windows_execution_via_regsvr32.json'; +import rule250 from './process_started_by_windows_defender.json'; +import rule251 from './windows_indirect_command_execution.json'; +import rule252 from './network_ssh_secure_shell_from_the_internet.json'; +import rule253 from './windows_html_help_executable_program_connecting_to_the_internet.json'; +import rule254 from './suricata_windows_executable_served_by_jpeg_web_content.json'; +import rule255 from './network_dns_directly_to_the_internet.json'; +import rule256 from './windows_defense_evasion_via_windows_event_log_tools.json'; +import rule257 from './suricata_nondns_traffic_on_tcp_port_53.json'; +import rule258 from './windows_persistence_via_netshell_helper_dll.json'; +import rule259 from './windows_script_interpreter_connecting_to_the_internet.json'; +import rule260 from './windows_defense_evasion_decoding_using_certutil.json'; +import rule261 from './linux_shell_activity_by_web_server.json'; +import rule262 from './linux_ldso_process_activity.json'; +import rule263 from './windows_mimikatz_activity.json'; +import rule264 from './suricata_nonssh_traffic_on_port_22.json'; +import rule265 from './windows_data_compression_using_powershell.json'; +import rule266 from './windows_nmap_scan_activity.json'; export const rawRules = [ rule1, @@ -443,4 +492,53 @@ export const rawRules = [ rule215, rule216, rule217, + rule218, + rule219, + rule220, + rule221, + rule222, + rule223, + rule224, + rule225, + rule226, + rule227, + rule228, + rule229, + rule230, + rule231, + rule232, + rule233, + rule234, + rule235, + rule236, + rule237, + rule238, + rule239, + rule240, + rule241, + rule242, + rule243, + rule244, + rule245, + rule246, + rule247, + rule248, + rule249, + rule250, + rule251, + rule252, + rule253, + rule254, + rule255, + rule256, + rule257, + rule258, + rule259, + rule260, + rule261, + rule262, + rule263, + rule264, + rule265, + rule266, ]; diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_capturelosstoo_much_loss.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_capturelosstoo_much_loss.json new file mode 100644 index 0000000000000..32d722ce42bab --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_capturelosstoo_much_loss.json @@ -0,0 +1,17 @@ +{ + "rule_id": "c115a407-799b-45d6-962e-a639bb764c06", + "risk_score": 50, + "description": "Detected Zeek capture loss exceeds the percentage threshold", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice CaptureLoss::Too_Much_Loss", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"CaptureLoss::Too_Much_Loss\" or rule.name: \"CaptureLoss::Too_Much_Loss\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_conncontent_gap.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_conncontent_gap.json new file mode 100644 index 0000000000000..a707c4647b1ea --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_conncontent_gap.json @@ -0,0 +1,17 @@ +{ + "rule_id": "22d12b64-33f4-40ce-ad57-49dd870bc8e5", + "risk_score": 50, + "description": "Data has sequence hole; perhaps due to filtering.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice Conn::Content_Gap", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"Conn::Content_Gap\" or rule.name: \"Conn::Content_Gap\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_connretransmission_inconsistency.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_connretransmission_inconsistency.json new file mode 100644 index 0000000000000..06f413ce93787 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_connretransmission_inconsistency.json @@ -0,0 +1,17 @@ +{ + "rule_id": "53719624-55f0-4541-8370-f27f6766fb9e", + "risk_score": 50, + "description": "Possible evasion; usually just chud.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice Conn::Retransmission_Inconsistency", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"Conn::Retransmission_Inconsistency\" or rule.name: \"Conn::Retransmission_Inconsistency\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_dnsexternal_name.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_dnsexternal_name.json new file mode 100644 index 0000000000000..a664b1314fb36 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_dnsexternal_name.json @@ -0,0 +1,17 @@ +{ + "rule_id": "39c40c5a-110c-45b1-876f-969212e8814b", + "risk_score": 50, + "description": "Raised when a non-local name is found to be pointing at a local host.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice DNS::External_Name", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"DNS::External_Name\" or rule.name: \"DNS::External_Name\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_ftpbruteforcing.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_ftpbruteforcing.json new file mode 100644 index 0000000000000..73c78ee4354e2 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_ftpbruteforcing.json @@ -0,0 +1,17 @@ +{ + "rule_id": "7e069475-817e-4e89-9245-1dfaa3083b11", + "risk_score": 50, + "description": "Indicates a host bruteforcing FTP logins by watching for too many rejected usernames or failed passwords.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice FTP::Bruteforcing", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"FTP::Bruteforcing\" or rule.name: \"FTP::Bruteforcing\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_ftpsite_exec_success.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_ftpsite_exec_success.json new file mode 100644 index 0000000000000..69e2087c8800e --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_ftpsite_exec_success.json @@ -0,0 +1,17 @@ +{ + "rule_id": "4b9cb3e9-e26a-4bd2-bd1f-8d451b49838f", + "risk_score": 50, + "description": "Indicates that a successful response to a “SITE EXEC” command/arg pair was seen.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice FTP::Site_Exec_Success", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"FTP::Site_Exec_Success\" or rule.name: \"FTP::Site_Exec_Success\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_heartbleedssl_heartbeat_attack.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_heartbleedssl_heartbeat_attack.json new file mode 100644 index 0000000000000..b14eabc3352b0 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_heartbleedssl_heartbeat_attack.json @@ -0,0 +1,17 @@ +{ + "rule_id": "68a33102-3680-4581-a48a-210b23925905", + "risk_score": 50, + "description": "Indicates that a host performed a heartbleed attack or scan.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice Heartbleed::SSL_Heartbeat_Attack", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"Heartbleed::SSL_Heartbeat_Attack\" or rule.name: \"Heartbleed::SSL_Heartbeat_Attack\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_heartbleedssl_heartbeat_attack_success.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_heartbleedssl_heartbeat_attack_success.json new file mode 100644 index 0000000000000..160f2728cdd50 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_heartbleedssl_heartbeat_attack_success.json @@ -0,0 +1,17 @@ +{ + "rule_id": "241a61ae-b385-4f36-96c4-b2fb5446cc43", + "risk_score": 50, + "description": "Indicates that a host performing a heartbleed attack was probably successful.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice Heartbleed::SSL_Heartbeat_Attack_Success", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"Heartbleed::SSL_Heartbeat_Attack_Success\" or rule.name: \"Heartbleed::SSL_Heartbeat_Attack_Success\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_heartbleedssl_heartbeat_many_requests.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_heartbleedssl_heartbeat_many_requests.json new file mode 100644 index 0000000000000..cfee395989376 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_heartbleedssl_heartbeat_many_requests.json @@ -0,0 +1,17 @@ +{ + "rule_id": "59d6a32c-753e-4c19-bb77-1befdc6e0e6a", + "risk_score": 50, + "description": "Indicates we saw many heartbeat requests without a reply. Might be an attack.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice Heartbleed::SSL_Heartbeat_Many_Requests", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"Heartbleed::SSL_Heartbeat_Many_Requests\" or rule.name: \"Heartbleed::SSL_Heartbeat_Many_Requests\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_heartbleedssl_heartbeat_odd_length.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_heartbleedssl_heartbeat_odd_length.json new file mode 100644 index 0000000000000..a6456e63a3ec0 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_heartbleedssl_heartbeat_odd_length.json @@ -0,0 +1,17 @@ +{ + "rule_id": "0c6e7be4-6cab-4ee1-ad51-7c1ffd0e9002", + "risk_score": 50, + "description": "Indicates we saw heartbeat requests with odd length. Probably an attack or scan.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice Heartbleed::SSL_Heartbeat_Odd_Length", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"Heartbleed::SSL_Heartbeat_Odd_Length\" or rule.name: \"Heartbleed::SSL_Heartbeat_Odd_Length\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_httpsql_injection_attacker.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_httpsql_injection_attacker.json new file mode 100644 index 0000000000000..517a03834d57e --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_httpsql_injection_attacker.json @@ -0,0 +1,17 @@ +{ + "rule_id": "4ca9ef93-7e7e-40a4-8d71-9130204d86e6", + "risk_score": 50, + "description": "Indicates that a host performing SQL injection attacks was detected.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice HTTP::SQL_Injection_Attacker", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"HTTP::SQL_Injection_Attacker\" or rule.name: \"HTTP::SQL_Injection_Attacker\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_httpsql_injection_victim.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_httpsql_injection_victim.json new file mode 100644 index 0000000000000..b00e49c89e402 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_httpsql_injection_victim.json @@ -0,0 +1,17 @@ +{ + "rule_id": "dda43d7f-69bc-487f-b05c-2b518e9db622", + "risk_score": 50, + "description": "Indicates that a host was seen to have SQL injection attacks against it. This is tracked by IP address as opposed to hostname.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice HTTP::SQL_Injection_Victim", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"HTTP::SQL_Injection_Victim\" or rule.name: \"HTTP::SQL_Injection_Victim\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_intelnotice.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_intelnotice.json new file mode 100644 index 0000000000000..27cfe2036744e --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_intelnotice.json @@ -0,0 +1,17 @@ +{ + "rule_id": "122e153a-78f3-4e7e-a5b5-cfe0b917f109", + "risk_score": 50, + "description": "This notice is generated when an intelligence indicator is denoted to be notice-worthy.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice Intel::Notice", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"Intel::Notice\" or rule.name: \"Intel::Notice\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_noticetally.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_noticetally.json new file mode 100644 index 0000000000000..16e22585d6e13 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_noticetally.json @@ -0,0 +1,17 @@ +{ + "rule_id": "7581fd81-25e8-489e-bcf3-69db068b7a6c", + "risk_score": 50, + "description": "Zeek notice reporting a count of how often a notice occurred.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice Notice::Tally", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"Notice::Tally\" or rule.name: \"Notice::Tally\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_packetfiltercannot_bpf_shunt_conn.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_packetfiltercannot_bpf_shunt_conn.json new file mode 100644 index 0000000000000..3e8704dee917a --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_packetfiltercannot_bpf_shunt_conn.json @@ -0,0 +1,17 @@ +{ + "rule_id": "0031d83e-1fb4-4dd6-b938-97ae7044b051", + "risk_score": 50, + "description": "Limitations in BPF make shunting some connections with BPF impossible. This notice encompasses those various cases.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice PacketFilter::Cannot_BPF_Shunt_Conn", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"PacketFilter::Cannot_BPF_Shunt_Conn\" or rule.name: \"PacketFilter::Cannot_BPF_Shunt_Conn\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_packetfiltercompile_failure.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_packetfiltercompile_failure.json new file mode 100644 index 0000000000000..63567a6ebbd90 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_packetfiltercompile_failure.json @@ -0,0 +1,17 @@ +{ + "rule_id": "335b2ddc-f806-46e8-8ffa-114d613aac92", + "risk_score": 50, + "description": "This notice is generated if a packet filter cannot be compiled.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice PacketFilter::Compile_Failure", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"PacketFilter::Compile_Failure\" or rule.name: \"PacketFilter::Compile_Failure\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_packetfilterdropped_packets.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_packetfilterdropped_packets.json new file mode 100644 index 0000000000000..78b664f573b6b --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_packetfilterdropped_packets.json @@ -0,0 +1,17 @@ +{ + "rule_id": "4f212278-329b-4088-ae59-9091003dff22", + "risk_score": 50, + "description": "Indicates packets were dropped by the packet filter.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice PacketFilter::Dropped_Packets", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"PacketFilter::Dropped_Packets\" or rule.name: \"PacketFilter::Dropped_Packets\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_packetfilterinstall_failure.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_packetfilterinstall_failure.json new file mode 100644 index 0000000000000..7fec89f251e80 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_packetfilterinstall_failure.json @@ -0,0 +1,17 @@ +{ + "rule_id": "235988ec-d037-4f5f-a211-74106512b36d", + "risk_score": 50, + "description": "Generated if a packet filter fails to install.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice PacketFilter::Install_Failure", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"PacketFilter::Install_Failure\" or rule.name: \"PacketFilter::Install_Failure\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_packetfilterno_more_conn_shunts_available.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_packetfilterno_more_conn_shunts_available.json new file mode 100644 index 0000000000000..176c4373e8e96 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_packetfilterno_more_conn_shunts_available.json @@ -0,0 +1,17 @@ +{ + "rule_id": "de4016de-3374-41a0-a678-21d36c70af9a", + "risk_score": 50, + "description": "Indicative that PacketFilter::max_bpf_shunts connections are already being shunted with BPF filters and no more are allowed.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice PacketFilter::No_More_Conn_Shunts_Available", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"PacketFilter::No_More_Conn_Shunts_Available\" or rule.name: \"PacketFilter::No_More_Conn_Shunts_Available\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_packetfiltertoo_long_to_compile_filter.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_packetfiltertoo_long_to_compile_filter.json new file mode 100644 index 0000000000000..6077e494779e3 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_packetfiltertoo_long_to_compile_filter.json @@ -0,0 +1,17 @@ +{ + "rule_id": "71e93c42-7990-4233-a8a5-2631193df7db", + "risk_score": 50, + "description": "Generated when a notice takes too long to compile.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice PacketFilter::Too_Long_To_Compile_Filter", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"PacketFilter::Too_Long_To_Compile_Filter\" or rule.name: \"PacketFilter::Too_Long_To_Compile_Filter\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_protocoldetectorprotocol_found.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_protocoldetectorprotocol_found.json new file mode 100644 index 0000000000000..2375fce0cf2b1 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_protocoldetectorprotocol_found.json @@ -0,0 +1,17 @@ +{ + "rule_id": "777586b6-4757-489e-a6e8-676b7df70b39", + "risk_score": 50, + "description": "Indicates a protocol was detected on a non-standard port.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice ProtocolDetector::Protocol_Found", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"ProtocolDetector::Protocol_Found\" or rule.name: \"ProtocolDetector::Protocol_Found\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_protocoldetectorserver_found.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_protocoldetectorserver_found.json new file mode 100644 index 0000000000000..6fd75bd759121 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_protocoldetectorserver_found.json @@ -0,0 +1,17 @@ +{ + "rule_id": "7d7f7635-6900-4f63-b14b-477a909ea90a", + "risk_score": 50, + "description": "Indicates a server was detected on a non-standard port for the protocol.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice ProtocolDetector::Server_Found", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"ProtocolDetector::Server_Found\" or rule.name: \"ProtocolDetector::Server_Found\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_scanaddress_scan.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_scanaddress_scan.json new file mode 100644 index 0000000000000..fe0508f08ab1d --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_scanaddress_scan.json @@ -0,0 +1,17 @@ +{ + "rule_id": "9d320fca-4ec1-4511-bdbc-7edf9673c07d", + "risk_score": 50, + "description": "Address scans detect that a host appears to be scanning some number of destinations on a single port.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice Scan::Address_Scan", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"Scan::Address_Scan\" or rule.name: \"Scan::Address_Scan\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_scanport_scan.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_scanport_scan.json new file mode 100644 index 0000000000000..007e5fd94ae5f --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_scanport_scan.json @@ -0,0 +1,17 @@ +{ + "rule_id": "d09fbf7a-47a7-4130-8dd7-b386cca81a42", + "risk_score": 50, + "description": "Port scans detect that an attacking host appears to be scanning a single victim host on several ports.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice Scan::Port_Scan", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"Scan::Port_Scan\" or rule.name: \"Scan::Port_Scan\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_signaturescount_signature.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_signaturescount_signature.json new file mode 100644 index 0000000000000..f5b708dce484f --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_signaturescount_signature.json @@ -0,0 +1,17 @@ +{ + "rule_id": "a704589c-8ba9-4a3c-8e39-ab9360cade17", + "risk_score": 50, + "description": "The same signature has triggered multiple times for a host.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice Signatures::Count_Signature", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"Signatures::Count_Signature\" or rule.name: \"Signatures::Count_Signature\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_signaturesmultiple_sig_responders.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_signaturesmultiple_sig_responders.json new file mode 100644 index 0000000000000..8e8b9ae8793ae --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_signaturesmultiple_sig_responders.json @@ -0,0 +1,17 @@ +{ + "rule_id": "4f313ae8-cbc6-4082-9599-526f8ccb7303", + "risk_score": 50, + "description": "Host has triggered the same signature on multiple hosts.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice Signatures::Multiple_Sig_Responders", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"Signatures::Multiple_Sig_Responders\" or rule.name: \"Signatures::Multiple_Sig_Responders\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_signaturesmultiple_signatures.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_signaturesmultiple_signatures.json new file mode 100644 index 0000000000000..0d24f030472c6 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_signaturesmultiple_signatures.json @@ -0,0 +1,17 @@ +{ + "rule_id": "ab90d81c-79e1-4f62-a61e-484c4bedb2b0", + "risk_score": 50, + "description": "Host has triggered many signatures on the same host.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice Signatures::Multiple_Signatures", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"Signatures::Multiple_Signatures\" or rule.name: \"Signatures::Multiple_Signatures\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_signaturessensitive_signature.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_signaturessensitive_signature.json new file mode 100644 index 0000000000000..545c653690493 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_signaturessensitive_signature.json @@ -0,0 +1,17 @@ +{ + "rule_id": "ac394dec-67e8-417f-bb06-ae0bd75556b0", + "risk_score": 50, + "description": "Generic notice type for notice-worthy signature matches.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice Signatures::Sensitive_Signature", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"Signatures::Sensitive_Signature\" or rule.name: \"Signatures::Sensitive_Signature\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_signaturessignature_summary.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_signaturessignature_summary.json new file mode 100644 index 0000000000000..76fb44b6bd24a --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_signaturessignature_summary.json @@ -0,0 +1,17 @@ +{ + "rule_id": "d17fe857-eb67-4843-ab63-bf4852e49396", + "risk_score": 50, + "description": "Summarize the number of times a host triggered a signature.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice Signatures::Signature_Summary", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"Signatures::Signature_Summary\" or rule.name: \"Signatures::Signature_Summary\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_smtpblocklist_blocked_host.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_smtpblocklist_blocked_host.json new file mode 100644 index 0000000000000..b1b52dc6c08f2 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_smtpblocklist_blocked_host.json @@ -0,0 +1,17 @@ +{ + "rule_id": "402d5f78-82cd-4320-8b69-3185e44daf07", + "risk_score": 50, + "description": "The originator’s address is seen in the block list error message. This is useful to detect local hosts sending SPAM with a high positive rate.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice SMTP::Blocklist_Blocked_Host", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"SMTP::Blocklist_Blocked_Host\" or rule.name: \"SMTP::Blocklist_Blocked_Host\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_smtpblocklist_error_message.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_smtpblocklist_error_message.json new file mode 100644 index 0000000000000..69adf95592dd7 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_smtpblocklist_error_message.json @@ -0,0 +1,17 @@ +{ + "rule_id": "b9bb4a93-8c5c-4942-9193-e2dc97230034", + "risk_score": 50, + "description": "An SMTP server sent a reply mentioning an SMTP block list.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice SMTP::Blocklist_Error_Message", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"SMTP::Blocklist_Error_Message\" or rule.name: \"SMTP::Blocklist_Error_Message\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_smtpsuspicious_origination.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_smtpsuspicious_origination.json new file mode 100644 index 0000000000000..2414a8a7669a4 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_smtpsuspicious_origination.json @@ -0,0 +1,17 @@ +{ + "rule_id": "cc6e9fef-d936-4faf-8936-e576c089d8b2", + "risk_score": 50, + "description": "SMTP message orignated from country or network configured to be suspicious.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice SMTP::Suspicious_Origination", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"SMTP::Suspicious_Origination\" or rule.name: \"SMTP::Suspicious_Origination\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_softwaresoftware_version_change.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_softwaresoftware_version_change.json new file mode 100644 index 0000000000000..87f1472a0420d --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_softwaresoftware_version_change.json @@ -0,0 +1,17 @@ +{ + "rule_id": "ea1d2c1b-ecfe-42a5-bd0b-56c7a1bd8075", + "risk_score": 50, + "description": "Indicates that an interesting software application changed versions on a host.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice Software::Software_Version_Change", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"Software::Software_Version_Change\" or rule.name: \"Software::Software_Version_Change\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_softwarevulnerable_version.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_softwarevulnerable_version.json new file mode 100644 index 0000000000000..24b803e654fcf --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_softwarevulnerable_version.json @@ -0,0 +1,17 @@ +{ + "rule_id": "97b4d80c-7671-4301-85a6-954aa0ba96ce", + "risk_score": 50, + "description": "Indicates that a vulnerable version of software was detected.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice Software::Vulnerable_Version", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"Software::Vulnerable_Version\" or rule.name: \"Software::Vulnerable_Version\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sshinteresting_hostname_login.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sshinteresting_hostname_login.json new file mode 100644 index 0000000000000..70e20f85d9b49 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sshinteresting_hostname_login.json @@ -0,0 +1,17 @@ +{ + "rule_id": "6a7f2b0a-3f24-4d58-aa84-243f1f0556d9", + "risk_score": 50, + "description": "Generated if a login originates or responds with a host where the reverse hostname lookup resolves to a name matched by the SSH::interesting_hostnames regular expression.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice SSH::Interesting_Hostname_Login", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"SSH::Interesting_Hostname_Login\" or rule.name: \"SSH::Interesting_Hostname_Login\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sshlogin_by_password_guesser.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sshlogin_by_password_guesser.json new file mode 100644 index 0000000000000..7d9402f7a1ec4 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sshlogin_by_password_guesser.json @@ -0,0 +1,17 @@ +{ + "rule_id": "5600ad95-2244-43db-8a7d-77eea95f80db", + "risk_score": 50, + "description": "Indicates that a host previously identified as a \"password guesser\" has now had a successful login attempt.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice SSH::Login_By_Password_Guesser", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"SSH::Login_By_Password_Guesser\" or rule.name: \"SSH::Login_By_Password_Guesser\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sshpassword_guessing.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sshpassword_guessing.json new file mode 100644 index 0000000000000..00c346bc0ecc7 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sshpassword_guessing.json @@ -0,0 +1,17 @@ +{ + "rule_id": "e278142a-4ee7-4443-9b1f-421174b0dabf", + "risk_score": 50, + "description": "Indicates that a host has been identified as crossing the SSH::password_guesses_limit threshold with failed logins.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice SSH::Password_Guessing", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"SSH::Password_Guessing\" or rule.name: \"SSH::Password_Guessing\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sshwatched_country_login.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sshwatched_country_login.json new file mode 100644 index 0000000000000..943f56b7c9368 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sshwatched_country_login.json @@ -0,0 +1,17 @@ +{ + "rule_id": "983f4b7e-38cd-4d7f-8be6-40447431561e", + "risk_score": 50, + "description": "SSH login was seen to or from a \"watched\" country based on the SSH::watched_countries variable", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice SSH::Watched_Country_Login", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"SSH::Watched_Country_Login\" or rule.name: \"SSH::Watched_Country_Login\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sslcertificate_expired.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sslcertificate_expired.json new file mode 100644 index 0000000000000..030b56cc57782 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sslcertificate_expired.json @@ -0,0 +1,17 @@ +{ + "rule_id": "3981f48e-49a5-4a3e-9b44-900a0887526c", + "risk_score": 50, + "description": "Indicates that a certificate’s NotValidAfter date has lapsed and the certificate is now invalid.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice SSL::Certificate_Expired", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"SSL::Certificate_Expired\" or rule.name: \"SSL::Certificate_Expired\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sslcertificate_expires_soon.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sslcertificate_expires_soon.json new file mode 100644 index 0000000000000..702724abcfa64 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sslcertificate_expires_soon.json @@ -0,0 +1,17 @@ +{ + "rule_id": "e8207172-3478-4b2c-85b7-6f13d97fff43", + "risk_score": 50, + "description": "Indicates that a certificate is going to expire within SSL::notify_when_cert_expiring_in.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice SSL::Certificate_Expires_Soon", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"SSL::Certificate_Expires_Soon\" or rule.name: \"SSL::Certificate_Expires_Soon\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sslcertificate_not_valid_yet.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sslcertificate_not_valid_yet.json new file mode 100644 index 0000000000000..258fb0cf78b60 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sslcertificate_not_valid_yet.json @@ -0,0 +1,17 @@ +{ + "rule_id": "45586490-99f6-4e11-8228-2229d727a3b4", + "risk_score": 50, + "description": "Indicates that a certificate’s NotValidBefore date is future dated.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice SSL::Certificate_Not_Valid_Yet", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"SSL::Certificate_Not_Valid_Yet\" or rule.name: \"SSL::Certificate_Not_Valid_Yet\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sslinvalid_ocsp_response.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sslinvalid_ocsp_response.json new file mode 100644 index 0000000000000..43c4b46e36c07 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sslinvalid_ocsp_response.json @@ -0,0 +1,17 @@ +{ + "rule_id": "eb17fcbb-de22-4aa0-81aa-1c059bdd4f2b", + "risk_score": 50, + "description": "This indicates that the OCSP response was not deemed to be valid.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice SSL::Invalid_Ocsp_Response", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"SSL::Invalid_Ocsp_Response\" or rule.name: \"SSL::Invalid_Ocsp_Response\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sslinvalid_server_cert.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sslinvalid_server_cert.json new file mode 100644 index 0000000000000..8c473f0007624 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sslinvalid_server_cert.json @@ -0,0 +1,17 @@ +{ + "rule_id": "13f51fe0-fc74-4c45-90f3-6fb1cd26ec66", + "risk_score": 50, + "description": "This notice indicates that the result of validating the certificate along with its full certificate chain was invalid.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice SSL::Invalid_Server_Cert", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"SSL::Invalid_Server_Cert\" or rule.name: \"SSL::Invalid_Server_Cert\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sslold_version.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sslold_version.json new file mode 100644 index 0000000000000..ba60fa82a5bae --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sslold_version.json @@ -0,0 +1,17 @@ +{ + "rule_id": "260b680e-c3d6-4c03-90cd-03c86e9f8ec1", + "risk_score": 50, + "description": "Indicates that a server is using a potentially unsafe version", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice SSL::Old_Version", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"SSL::Old_Version\" or rule.name: \"SSL::Old_Version\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sslweak_cipher.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sslweak_cipher.json new file mode 100644 index 0000000000000..786b42cb8db50 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sslweak_cipher.json @@ -0,0 +1,17 @@ +{ + "rule_id": "25886074-6ae1-41c0-8546-e8cf55ed1b4b", + "risk_score": 50, + "description": "Indicates that a server is using a potentially unsafe cipher", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice SSL::Weak_Cipher", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"SSL::Weak_Cipher\" or rule.name: \"SSL::Weak_Cipher\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sslweak_key.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sslweak_key.json new file mode 100644 index 0000000000000..7120cfe5e81ad --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_sslweak_key.json @@ -0,0 +1,17 @@ +{ + "rule_id": "e020f504-c0e5-4768-8e1f-1e2ec7bac961", + "risk_score": 50, + "description": "Indicates that a server is using a potentially unsafe key.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice SSL::Weak_Key", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"SSL::Weak_Key\" or rule.name: \"SSL::Weak_Key\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_teamcymrumalwarehashregistrymatch.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_teamcymrumalwarehashregistrymatch.json new file mode 100644 index 0000000000000..47817a05ea570 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_teamcymrumalwarehashregistrymatch.json @@ -0,0 +1,17 @@ +{ + "rule_id": "a130a0ba-b083-4630-b0ea-cceb80d7720b", + "risk_score": 50, + "description": "The hash value of a file transferred over HTTP matched in the malware hash registry.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice TeamCymruMalwareHashRegistry::Match", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"TeamCymruMalwareHashRegistry::Match\" or rule.name: \"TeamCymruMalwareHashRegistry::Match\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_traceroutedetected.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_traceroutedetected.json new file mode 100644 index 0000000000000..c676c84347cb5 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_traceroutedetected.json @@ -0,0 +1,17 @@ +{ + "rule_id": "aeefe077-f05d-44a7-b757-272fc51c334c", + "risk_score": 50, + "description": "Indicates that a host was seen running traceroutes.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice Traceroute::Detected", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"Traceroute::Detected\" or rule.name: \"Traceroute::Detected\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_weirdactivity.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_weirdactivity.json new file mode 100644 index 0000000000000..fc1da9e414cc5 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/zeek_notice_weirdactivity.json @@ -0,0 +1,17 @@ +{ + "rule_id": "d5ad39d0-8421-4f79-ad93-8ddbf7f553b3", + "risk_score": 50, + "description": "Generic unusual but notice-worthy weird activity.", + "immutable": true, + "interval": "5m", + "name": "Zeek Notice Weird::Activity", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.module: zeek and event.dataset: zeek.notice and (zeek.notice.note: \"Weird::Activity\" or rule.name: \"Weird::Activity\")", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} From e08e28b1f58c758e92cd318b106d888a8c22ff58 Mon Sep 17 00:00:00 2001 From: Frank Hassanabad Date: Fri, 20 Dec 2019 15:33:54 -0700 Subject: [PATCH 11/14] [SIEM][Detection Engine] Added 10 more rules for prepackaging ## Summary * Added 10 more rules for prepackaging ### Checklist Use ~~strikethroughs~~ to remove checklist items you don't feel are applicable to this PR. ~~- [ ] This was checked for cross-browser compatibility, [including a check against IE11](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#cross-browser-compatibility)~~ ~~- [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/master/packages/kbn-i18n/README.md)~~ ~~- [ ] [Documentation](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#writing-documentation) was added for features that require explanation or tutorials~~ ~~- [ ] [Unit or functional tests](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#cross-browser-compatibility) were updated or added to match the most common scenarios~~ ~~- [ ] This was checked for [keyboard-only and screenreader accessibility](https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Cross_browser_testing/Accessibility#Accessibility_testing_checklist)~~ ### For maintainers ~~- [ ] This was checked for breaking API changes and was [labeled appropriately](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#release-notes-process)~~ - [x] This includes a feature addition or change that requires a release note and was [labeled appropriately](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#release-notes-process) --- .../rules/prepackaged_rules/index.ts | 20 +++++++++++++++++++ .../splunk_child_processes_of_spoolsvexe.json | 17 ++++++++++++++++ ...nk_detect_large_outbound_icmp_packets.json | 17 ++++++++++++++++ ...k_detect_long_dns_txt_record_response.json | 17 ++++++++++++++++ ...splunk_detect_new_local_admin_account.json | 17 ++++++++++++++++ ...nk_detect_psexec_with_accepteula_flag.json | 17 ++++++++++++++++ ..._cmdexe_to_launch_script_interpreters.json | 17 ++++++++++++++++ .../splunk_processes_created_by_netsh.json | 17 ++++++++++++++++ .../splunk_processes_launching_netsh.json | 17 ++++++++++++++++ ...s_passing_authentication_in_cleartext.json | 17 ++++++++++++++++ .../splunk_windows_event_log_cleared.json | 17 ++++++++++++++++ 11 files changed, 190 insertions(+) create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/splunk_child_processes_of_spoolsvexe.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/splunk_detect_large_outbound_icmp_packets.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/splunk_detect_long_dns_txt_record_response.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/splunk_detect_new_local_admin_account.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/splunk_detect_psexec_with_accepteula_flag.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/splunk_detect_use_of_cmdexe_to_launch_script_interpreters.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/splunk_processes_created_by_netsh.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/splunk_processes_launching_netsh.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/splunk_protocols_passing_authentication_in_cleartext.json create mode 100644 x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/splunk_windows_event_log_cleared.json diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/index.ts b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/index.ts index 39ed673adb73e..4e370bfdc5bc9 100644 --- a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/index.ts +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/index.ts @@ -273,6 +273,16 @@ import rule263 from './windows_mimikatz_activity.json'; import rule264 from './suricata_nonssh_traffic_on_port_22.json'; import rule265 from './windows_data_compression_using_powershell.json'; import rule266 from './windows_nmap_scan_activity.json'; +import rule267 from './splunk_windows_event_log_cleared.json'; +import rule268 from './splunk_detect_long_dns_txt_record_response.json'; +import rule269 from './splunk_processes_launching_netsh.json'; +import rule270 from './splunk_detect_large_outbound_icmp_packets.json'; +import rule271 from './splunk_detect_new_local_admin_account.json'; +import rule272 from './splunk_protocols_passing_authentication_in_cleartext.json'; +import rule273 from './splunk_detect_use_of_cmdexe_to_launch_script_interpreters.json'; +import rule274 from './splunk_child_processes_of_spoolsvexe.json'; +import rule275 from './splunk_detect_psexec_with_accepteula_flag.json'; +import rule276 from './splunk_processes_created_by_netsh.json'; export const rawRules = [ rule1, @@ -541,4 +551,14 @@ export const rawRules = [ rule264, rule265, rule266, + rule267, + rule268, + rule269, + rule270, + rule271, + rule272, + rule273, + rule274, + rule275, + rule276, ]; diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/splunk_child_processes_of_spoolsvexe.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/splunk_child_processes_of_spoolsvexe.json new file mode 100644 index 0000000000000..554ddb1468d0b --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/splunk_child_processes_of_spoolsvexe.json @@ -0,0 +1,17 @@ +{ + "rule_id": "2f026c73-bb63-455e-abdf-f11f463acf0d", + "risk_score": 50, + "description": "Splunk - Child Processes of Spoolsv.exe", + "immutable": true, + "interval": "5m", + "name": "Splunk - Child Processes of Spoolsv.exe", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "process.parent.name:spoolsv.exe and not process.name:regsvr32.exe ", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/splunk_detect_large_outbound_icmp_packets.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/splunk_detect_large_outbound_icmp_packets.json new file mode 100644 index 0000000000000..30dd0023b4491 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/splunk_detect_large_outbound_icmp_packets.json @@ -0,0 +1,17 @@ +{ + "rule_id": "e108c0c6-5ee8-47a0-8c23-ec47ba3a9b00", + "risk_score": 50, + "description": "Splunk - Detect Large Outbound ICMP Packets", + "immutable": true, + "interval": "5m", + "name": "Splunk - Detect Large Outbound ICMP Packets", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "network.transport:icmp and network.bytes>1000 and not destination.ip:10.0.0.0/8 and not destination.ip:172.16.0.0/12 and not destination.ip:192.168.0.0/16", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/splunk_detect_long_dns_txt_record_response.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/splunk_detect_long_dns_txt_record_response.json new file mode 100644 index 0000000000000..8ae0c57d6aeaa --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/splunk_detect_long_dns_txt_record_response.json @@ -0,0 +1,17 @@ +{ + "rule_id": "2cdf84be-1c9c-4184-9880-75b9a6ddeaba", + "risk_score": 50, + "description": "Splunk - Detect Long DNS TXT Record Response", + "immutable": true, + "interval": "5m", + "name": "Splunk - Detect Long DNS TXT Record Response", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "network.protocol:dns and server.bytes>100 and not destination.ip:10.0.0.0/8 and not destination.ip:172.16.0.0/12 and not destination.ip:192.168.0.0/16 and not destination.ip:169.254.169.254 and not destination.ip:127.0.0.53", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/splunk_detect_new_local_admin_account.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/splunk_detect_new_local_admin_account.json new file mode 100644 index 0000000000000..39cb60d130a69 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/splunk_detect_new_local_admin_account.json @@ -0,0 +1,17 @@ +{ + "rule_id": "030fc8e4-2c5f-4cc9-a6bd-2b6b7b98ae16", + "risk_score": 50, + "description": "Splunk - Detect New Local Admin account", + "immutable": true, + "interval": "5m", + "name": "Splunk - Detect New Local Admin account", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.code:(4720 or 4732) and winlog.event_data.TargetUserName:Administrators", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/splunk_detect_psexec_with_accepteula_flag.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/splunk_detect_psexec_with_accepteula_flag.json new file mode 100644 index 0000000000000..b8b4d5f34037d --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/splunk_detect_psexec_with_accepteula_flag.json @@ -0,0 +1,17 @@ +{ + "rule_id": "4b63cf13-9043-41e3-84ec-6e39eb0d407e", + "risk_score": 50, + "description": "Splunk - Detect PsExec With accepteula Flag", + "immutable": true, + "interval": "5m", + "name": "Splunk - Detect PsExec With accepteula Flag", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "process.name:PsExec.exe and process.args:\"-accepteula\"", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/splunk_detect_use_of_cmdexe_to_launch_script_interpreters.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/splunk_detect_use_of_cmdexe_to_launch_script_interpreters.json new file mode 100644 index 0000000000000..1cd29886f3cd0 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/splunk_detect_use_of_cmdexe_to_launch_script_interpreters.json @@ -0,0 +1,17 @@ +{ + "rule_id": "f4388e4c-ec3d-41b3-be5c-27c11f61473c", + "risk_score": 50, + "description": "Splunk - Detect Use of cmd.exe to Launch Script Interpreters", + "immutable": true, + "interval": "5m", + "name": "Splunk - Detect Use of cmd.exe to Launch Script Interpreters", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.action:\"Process Create (rule: ProcessCreate)\" and process.name:(\"wscript.exe\" or \"cscript.exe\") and process.parent.name:\"cmd.exe\"", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/splunk_processes_created_by_netsh.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/splunk_processes_created_by_netsh.json new file mode 100644 index 0000000000000..cbedcb655990f --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/splunk_processes_created_by_netsh.json @@ -0,0 +1,17 @@ +{ + "rule_id": "ce7a0bde-7406-4729-a075-a215f4571ff6", + "risk_score": 50, + "description": "Splunk - Processes created by netsh", + "immutable": true, + "interval": "5m", + "name": "Splunk - Processes created by netsh", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "process.parent.name:netsh.exe", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/splunk_processes_launching_netsh.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/splunk_processes_launching_netsh.json new file mode 100644 index 0000000000000..c25e6211a3bb9 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/splunk_processes_launching_netsh.json @@ -0,0 +1,17 @@ +{ + "rule_id": "600dba95-f1c6-4a4d-aae1-c79cbd8a5ddd", + "risk_score": 50, + "description": "Splunk - Processes launching netsh", + "immutable": true, + "interval": "5m", + "name": "Splunk - Processes launching netsh", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "process.name:netsh.exe and event.action:\"Process Create (rule: ProcessCreate)\" ", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/splunk_protocols_passing_authentication_in_cleartext.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/splunk_protocols_passing_authentication_in_cleartext.json new file mode 100644 index 0000000000000..12eafea8d88c9 --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/splunk_protocols_passing_authentication_in_cleartext.json @@ -0,0 +1,17 @@ +{ + "rule_id": "f4442e7f-856a-4a4a-851b-c1f9b97b0d39", + "risk_score": 50, + "description": "Splunk - Protocols passing authentication in cleartext", + "immutable": true, + "interval": "5m", + "name": "Splunk - Protocols passing authentication in cleartext", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "destination.port:(21 or 23 or 110 or 143) and network.transport:tcp", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/splunk_windows_event_log_cleared.json b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/splunk_windows_event_log_cleared.json new file mode 100644 index 0000000000000..7317f491d1a9d --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules/splunk_windows_event_log_cleared.json @@ -0,0 +1,17 @@ +{ + "rule_id": "c0747553-4652-4e74-bc86-898f2daa2bde", + "risk_score": 50, + "description": "Splunk - Windows Event Log Cleared", + "immutable": true, + "interval": "5m", + "name": "Splunk - Windows Event Log Cleared", + "severity": "low", + "type": "query", + "from": "now-6m", + "to": "now", + "query": "event.code:(1102 or 1100)", + "language": "kuery", + "filters": [], + "enabled": false, + "version": 1 +} From 24c75e545bf6f7a7d2c68e3d465a1be84b8cf1f4 Mon Sep 17 00:00:00 2001 From: Ryland Herrick Date: Fri, 20 Dec 2019 17:11:47 -0600 Subject: [PATCH 12/14] Fix outstanding NP issues in SIEM frontend (#53735) * Injects all required plugins into our context provider (not just data) * Sets defaults for two UI settings that the client doesn't know about (and blow up when trying to retrieve). --- x-pack/legacy/plugins/siem/public/apps/index.ts | 5 ++++- x-pack/legacy/plugins/siem/public/apps/plugin.tsx | 5 +++++ x-pack/legacy/plugins/siem/public/apps/start_app.tsx | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/x-pack/legacy/plugins/siem/public/apps/index.ts b/x-pack/legacy/plugins/siem/public/apps/index.ts index 73f9b65ba3546..0cc5c5584e1b7 100644 --- a/x-pack/legacy/plugins/siem/public/apps/index.ts +++ b/x-pack/legacy/plugins/siem/public/apps/index.ts @@ -8,8 +8,11 @@ import chrome from 'ui/chrome'; import { npStart } from 'ui/new_platform'; import { Plugin } from './plugin'; +const { data, embeddable, inspector, uiActions } = npStart.plugins; +const startPlugins = { data, embeddable, inspector, uiActions }; + new Plugin( // eslint-disable-next-line @typescript-eslint/no-explicit-any { opaqueId: Symbol('siem'), env: {} as any, config: { get: () => ({} as any) } }, chrome -).start(npStart.core, npStart.plugins); +).start(npStart.core, startPlugins); diff --git a/x-pack/legacy/plugins/siem/public/apps/plugin.tsx b/x-pack/legacy/plugins/siem/public/apps/plugin.tsx index 700fec2557b1b..aa42504e07635 100644 --- a/x-pack/legacy/plugins/siem/public/apps/plugin.tsx +++ b/x-pack/legacy/plugins/siem/public/apps/plugin.tsx @@ -10,6 +10,7 @@ import { LegacyCoreStart, PluginInitializerContext } from 'src/core/public'; import { PluginsStart } from 'ui/new_platform/new_platform'; import { Chrome } from 'ui/chrome'; +import { DEFAULT_KBN_VERSION, DEFAULT_TIMEZONE_BROWSER } from '../../common/constants'; import { SiemApp } from './start_app'; import template from './template.html'; @@ -32,6 +33,10 @@ export class Plugin { } public start(core: StartCore, plugins: StartPlugins) { + // TODO(rylnd): These are unknown by uiSettings by default + core.uiSettings.set(DEFAULT_KBN_VERSION, '8.0.0'); + core.uiSettings.set(DEFAULT_TIMEZONE_BROWSER, 'UTC'); + // @ts-ignore improper type description this.chrome.setRootTemplate(template); const checkForRoot = () => { diff --git a/x-pack/legacy/plugins/siem/public/apps/start_app.tsx b/x-pack/legacy/plugins/siem/public/apps/start_app.tsx index 6b7e3a7b8084f..54180b51fe039 100644 --- a/x-pack/legacy/plugins/siem/public/apps/start_app.tsx +++ b/x-pack/legacy/plugins/siem/public/apps/start_app.tsx @@ -77,9 +77,9 @@ export const SiemApp = memo<{ core: StartCore; plugins: StartPlugins }>(({ core, From fc8bc82fb3e5ee1639fd727404812a32ce008870 Mon Sep 17 00:00:00 2001 From: Luke Elmers Date: Fri, 20 Dec 2019 21:08:05 -0700 Subject: [PATCH 13/14] Move ui/courier into data shim plugin (#52359) --- src/legacy/core_plugins/data/public/index.ts | 9 +- src/legacy/core_plugins/data/public/plugin.ts | 17 +- .../data/public/search/expressions/esaggs.ts | 4 +- .../public/search}/fetch/call_client.test.ts | 0 .../data/public/search}/fetch/call_client.ts | 0 .../__mocks__/shard_failure_request.ts | 0 .../__mocks__/shard_failure_response.ts | 0 .../shard_failure_description.test.tsx.snap | 0 .../shard_failure_modal.test.tsx.snap | 2 +- .../shard_failure_table.test.tsx.snap | 0 .../components/_shard_failure_modal.scss | 0 .../shard_failure_description.test.tsx | 0 .../components/shard_failure_description.tsx | 2 +- .../shard_failure_description_header.tsx | 2 +- .../components/shard_failure_modal.test.tsx | 0 .../fetch/components/shard_failure_modal.tsx | 19 +- ...d_failure_open_modal_button.test.mocks.tsx | 0 .../shard_failure_open_modal_button.test.tsx | 0 .../shard_failure_open_modal_button.tsx | 4 +- .../components/shard_failure_table.test.tsx | 0 .../fetch/components/shard_failure_table.tsx | 12 +- .../fetch/components/shard_failure_types.ts | 0 .../data/public/search}/fetch/errors.ts | 5 +- .../public/search}/fetch/fetch_soon.test.ts | 2 +- .../data/public/search}/fetch/fetch_soon.ts | 0 .../search}/fetch/get_search_params.test.ts | 2 +- .../public/search}/fetch/get_search_params.ts | 2 +- .../search}/fetch/handle_response.test.ts | 4 +- .../public/search}/fetch/handle_response.tsx | 10 +- .../data/public/search}/fetch/index.ts | 0 .../data/public/search}/fetch/types.ts | 2 +- .../core_plugins/data/public/search/index.ts | 4 + .../data/public/search/search_service.ts | 51 +++ .../filter_docvalue_fields.test.ts | 0 .../search_source/filter_docvalue_fields.ts | 0 .../data/public/search/search_source/index.ts | 20 + .../data/public/search/search_source/mocks.ts | 59 +++ .../normalize_sort_request.test.ts | 4 +- .../search_source/normalize_sort_request.ts | 6 +- .../search_source/search_source.test.ts | 4 +- .../search/search_source/search_source.ts | 410 ++++++++++++++++++ .../public/search}/search_source/types.ts | 4 +- .../default_search_strategy.test.ts | 2 +- .../default_search_strategy.ts | 78 ++++ .../public/search/search_strategy/index.ts | 31 ++ .../is_default_type_index_pattern.ts | 2 +- .../search_strategy/no_op_search_strategy.ts | 11 +- .../search/search_strategy/search_error.ts | 62 +++ .../search_strategy_registry.test.ts | 2 +- .../search_strategy_registry.ts | 2 +- .../public/search}/search_strategy/types.ts | 2 +- .../core_plugins/data/public/search/types.ts | 23 + .../search}/utils/courier_inspector_utils.ts | 34 +- .../data/public/search/utils/index.ts | 20 + .../data/public/search}/utils/types.ts | 0 .../public/legacy_imports.ts | 6 +- .../public/views/table/table.test.tsx | 2 + .../saved_dashboard/saved_dashboard.ts | 4 +- .../kibana/public/discover/kibana_services.ts | 4 +- .../api/utils/fetch_hits_in_interval.ts | 8 +- .../np_ready/embeddable/search_embeddable.ts | 4 +- .../public/discover/np_ready/types.d.ts | 5 +- .../visualize_embeddable.ts | 4 +- .../np_ready/public/legacy/build_pipeline.ts | 6 +- src/legacy/ui/public/agg_types/agg_config.ts | 4 +- src/legacy/ui/public/agg_types/agg_configs.ts | 4 +- src/legacy/ui/public/agg_types/agg_type.ts | 6 +- .../ui/public/agg_types/buckets/terms.ts | 4 +- .../ui/public/agg_types/param_types/base.ts | 4 +- src/legacy/ui/public/courier/_index.scss | 2 +- src/legacy/ui/public/courier/index.ts | 47 +- .../ui/public/courier/search_source/index.ts | 2 +- .../ui/public/courier/search_source/mocks.ts | 6 +- .../courier/search_source/search_source.ts | 392 +---------------- .../default_search_strategy.ts | 63 +-- .../public/courier/search_strategy/index.ts | 10 +- .../courier/search_strategy/search_error.ts | 44 +- src/legacy/ui/public/courier/types.ts | 10 +- src/legacy/ui/public/saved_objects/types.ts | 7 +- .../loader/utils/query_geohash_bounds.ts | 4 +- .../editor_frame_plugin/merge_tables.test.ts | 2 + .../definitions/date_histogram.test.tsx | 36 +- .../translations/translations/ja-JP.json | 64 +-- .../translations/translations/zh-CN.json | 64 +-- 84 files changed, 1035 insertions(+), 712 deletions(-) rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/fetch/call_client.test.ts (100%) rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/fetch/call_client.ts (100%) rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/fetch/components/__mocks__/shard_failure_request.ts (100%) rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/fetch/components/__mocks__/shard_failure_response.ts (100%) rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/fetch/components/__snapshots__/shard_failure_description.test.tsx.snap (100%) rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/fetch/components/__snapshots__/shard_failure_modal.test.tsx.snap (98%) rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/fetch/components/__snapshots__/shard_failure_table.test.tsx.snap (100%) rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/fetch/components/_shard_failure_modal.scss (100%) rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/fetch/components/shard_failure_description.test.tsx (100%) rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/fetch/components/shard_failure_description.tsx (96%) rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/fetch/components/shard_failure_description_header.tsx (96%) rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/fetch/components/shard_failure_modal.test.tsx (100%) rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/fetch/components/shard_failure_modal.tsx (85%) rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/fetch/components/shard_failure_open_modal_button.test.mocks.tsx (100%) rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/fetch/components/shard_failure_open_modal_button.test.tsx (100%) rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/fetch/components/shard_failure_open_modal_button.tsx (92%) rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/fetch/components/shard_failure_table.test.tsx (100%) rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/fetch/components/shard_failure_table.tsx (87%) rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/fetch/components/shard_failure_types.ts (100%) rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/fetch/errors.ts (91%) rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/fetch/fetch_soon.test.ts (98%) rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/fetch/fetch_soon.ts (100%) rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/fetch/get_search_params.test.ts (98%) rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/fetch/get_search_params.ts (97%) rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/fetch/handle_response.test.ts (95%) rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/fetch/handle_response.tsx (84%) rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/fetch/index.ts (100%) rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/fetch/types.ts (95%) create mode 100644 src/legacy/core_plugins/data/public/search/search_service.ts rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/search_source/filter_docvalue_fields.test.ts (100%) rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/search_source/filter_docvalue_fields.ts (100%) create mode 100644 src/legacy/core_plugins/data/public/search/search_source/index.ts create mode 100644 src/legacy/core_plugins/data/public/search/search_source/mocks.ts rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/search_source/normalize_sort_request.test.ts (97%) rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/search_source/normalize_sort_request.ts (93%) rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/search_source/search_source.test.ts (98%) create mode 100644 src/legacy/core_plugins/data/public/search/search_source/search_source.ts rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/search_source/types.ts (94%) rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/search_strategy/default_search_strategy.test.ts (98%) create mode 100644 src/legacy/core_plugins/data/public/search/search_strategy/default_search_strategy.ts create mode 100644 src/legacy/core_plugins/data/public/search/search_strategy/index.ts rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/search_strategy/is_default_type_index_pattern.ts (93%) rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/search_strategy/no_op_search_strategy.ts (83%) create mode 100644 src/legacy/core_plugins/data/public/search/search_strategy/search_error.ts rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/search_strategy/search_strategy_registry.test.ts (98%) rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/search_strategy/search_strategy_registry.ts (97%) rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/search_strategy/types.ts (94%) create mode 100644 src/legacy/core_plugins/data/public/search/types.ts rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/utils/courier_inspector_utils.ts (72%) create mode 100644 src/legacy/core_plugins/data/public/search/utils/index.ts rename src/legacy/{ui/public/courier => core_plugins/data/public/search}/utils/types.ts (100%) diff --git a/src/legacy/core_plugins/data/public/index.ts b/src/legacy/core_plugins/data/public/index.ts index c9ce825f3596e..09881c00c63b6 100644 --- a/src/legacy/core_plugins/data/public/index.ts +++ b/src/legacy/core_plugins/data/public/index.ts @@ -30,9 +30,16 @@ export function plugin() { export { DataStart }; export { Field, FieldType, IFieldList, IndexPattern } from './index_patterns'; -export { SavedQuery, SavedQueryTimeFilter } from '../../../../plugins/data/public'; +export { EsQuerySortValue, FetchOptions, ISearchSource, SortDirection } from './search/types'; +export { SearchSourceFields } from './search/types'; +export { + SavedQueryAttributes, + SavedQuery, + SavedQueryTimeFilter, +} from '../../../../plugins/data/public'; /** @public static code */ export * from '../common'; export { FilterStateManager } from './filter/filter_manager'; export { getFromSavedObject, getRoutes, flattenHitWrapper } from './index_patterns'; +export { getRequestInspectorStats, getResponseInspectorStats } from './search'; diff --git a/src/legacy/core_plugins/data/public/plugin.ts b/src/legacy/core_plugins/data/public/plugin.ts index 676904faf6f2f..6c67408158b51 100644 --- a/src/legacy/core_plugins/data/public/plugin.ts +++ b/src/legacy/core_plugins/data/public/plugin.ts @@ -18,6 +18,7 @@ */ import { CoreSetup, CoreStart, Plugin } from 'kibana/public'; +import { SearchService, SearchStart } from './search'; import { DataPublicPluginStart } from '../../../../plugins/data/public'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths @@ -32,8 +33,9 @@ export interface DataPluginStartDependencies { * * @public */ -// eslint-disable-next-line @typescript-eslint/no-empty-interface -export interface DataStart {} +export interface DataStart { + search: SearchStart; +} /** * Data Plugin - public @@ -48,13 +50,20 @@ export interface DataStart {} */ export class DataPlugin implements Plugin { + private readonly search = new SearchService(); + public setup(core: CoreSetup) {} public start(core: CoreStart, { data }: DataPluginStartDependencies): DataStart { // This is required for when Angular code uses Field and FieldList. setFieldFormats(data.fieldFormats); - return {}; + + return { + search: this.search.start(core), + }; } - public stop() {} + public stop() { + this.search.stop(); + } } diff --git a/src/legacy/core_plugins/data/public/search/expressions/esaggs.ts b/src/legacy/core_plugins/data/public/search/expressions/esaggs.ts index c94d35d1f7f2a..a14e2c8492648 100644 --- a/src/legacy/core_plugins/data/public/search/expressions/esaggs.ts +++ b/src/legacy/core_plugins/data/public/search/expressions/esaggs.ts @@ -32,7 +32,7 @@ import { import { npStart } from 'ui/new_platform'; import { SearchSource, - SearchSourceContract, + ISearchSource, getRequestInspectorStats, getResponseInspectorStats, } from '../../../../../ui/public/courier'; @@ -51,7 +51,7 @@ import { PersistedState } from '../../../../../ui/public/persisted_state'; import { Adapters } from '../../../../../../plugins/inspector/public'; export interface RequestHandlerParams { - searchSource: SearchSourceContract; + searchSource: ISearchSource; aggs: AggConfigs; timeRange?: TimeRange; query?: Query; diff --git a/src/legacy/ui/public/courier/fetch/call_client.test.ts b/src/legacy/core_plugins/data/public/search/fetch/call_client.test.ts similarity index 100% rename from src/legacy/ui/public/courier/fetch/call_client.test.ts rename to src/legacy/core_plugins/data/public/search/fetch/call_client.test.ts diff --git a/src/legacy/ui/public/courier/fetch/call_client.ts b/src/legacy/core_plugins/data/public/search/fetch/call_client.ts similarity index 100% rename from src/legacy/ui/public/courier/fetch/call_client.ts rename to src/legacy/core_plugins/data/public/search/fetch/call_client.ts diff --git a/src/legacy/ui/public/courier/fetch/components/__mocks__/shard_failure_request.ts b/src/legacy/core_plugins/data/public/search/fetch/components/__mocks__/shard_failure_request.ts similarity index 100% rename from src/legacy/ui/public/courier/fetch/components/__mocks__/shard_failure_request.ts rename to src/legacy/core_plugins/data/public/search/fetch/components/__mocks__/shard_failure_request.ts diff --git a/src/legacy/ui/public/courier/fetch/components/__mocks__/shard_failure_response.ts b/src/legacy/core_plugins/data/public/search/fetch/components/__mocks__/shard_failure_response.ts similarity index 100% rename from src/legacy/ui/public/courier/fetch/components/__mocks__/shard_failure_response.ts rename to src/legacy/core_plugins/data/public/search/fetch/components/__mocks__/shard_failure_response.ts diff --git a/src/legacy/ui/public/courier/fetch/components/__snapshots__/shard_failure_description.test.tsx.snap b/src/legacy/core_plugins/data/public/search/fetch/components/__snapshots__/shard_failure_description.test.tsx.snap similarity index 100% rename from src/legacy/ui/public/courier/fetch/components/__snapshots__/shard_failure_description.test.tsx.snap rename to src/legacy/core_plugins/data/public/search/fetch/components/__snapshots__/shard_failure_description.test.tsx.snap diff --git a/src/legacy/ui/public/courier/fetch/components/__snapshots__/shard_failure_modal.test.tsx.snap b/src/legacy/core_plugins/data/public/search/fetch/components/__snapshots__/shard_failure_modal.test.tsx.snap similarity index 98% rename from src/legacy/ui/public/courier/fetch/components/__snapshots__/shard_failure_modal.test.tsx.snap rename to src/legacy/core_plugins/data/public/search/fetch/components/__snapshots__/shard_failure_modal.test.tsx.snap index 9a47fff2745c3..f7f3d1c1fbd0c 100644 --- a/src/legacy/ui/public/courier/fetch/components/__snapshots__/shard_failure_modal.test.tsx.snap +++ b/src/legacy/core_plugins/data/public/search/fetch/components/__snapshots__/shard_failure_modal.test.tsx.snap @@ -181,7 +181,7 @@ exports[`ShardFailureModal renders matching snapshot given valid properties 1`] diff --git a/src/legacy/ui/public/courier/fetch/components/__snapshots__/shard_failure_table.test.tsx.snap b/src/legacy/core_plugins/data/public/search/fetch/components/__snapshots__/shard_failure_table.test.tsx.snap similarity index 100% rename from src/legacy/ui/public/courier/fetch/components/__snapshots__/shard_failure_table.test.tsx.snap rename to src/legacy/core_plugins/data/public/search/fetch/components/__snapshots__/shard_failure_table.test.tsx.snap diff --git a/src/legacy/ui/public/courier/fetch/components/_shard_failure_modal.scss b/src/legacy/core_plugins/data/public/search/fetch/components/_shard_failure_modal.scss similarity index 100% rename from src/legacy/ui/public/courier/fetch/components/_shard_failure_modal.scss rename to src/legacy/core_plugins/data/public/search/fetch/components/_shard_failure_modal.scss diff --git a/src/legacy/ui/public/courier/fetch/components/shard_failure_description.test.tsx b/src/legacy/core_plugins/data/public/search/fetch/components/shard_failure_description.test.tsx similarity index 100% rename from src/legacy/ui/public/courier/fetch/components/shard_failure_description.test.tsx rename to src/legacy/core_plugins/data/public/search/fetch/components/shard_failure_description.test.tsx diff --git a/src/legacy/ui/public/courier/fetch/components/shard_failure_description.tsx b/src/legacy/core_plugins/data/public/search/fetch/components/shard_failure_description.tsx similarity index 96% rename from src/legacy/ui/public/courier/fetch/components/shard_failure_description.tsx rename to src/legacy/core_plugins/data/public/search/fetch/components/shard_failure_description.tsx index 6028a50cf9c3e..60e0e35a0f152 100644 --- a/src/legacy/ui/public/courier/fetch/components/shard_failure_description.tsx +++ b/src/legacy/core_plugins/data/public/search/fetch/components/shard_failure_description.tsx @@ -19,7 +19,7 @@ import React from 'react'; import { EuiCodeBlock, EuiDescriptionList, EuiSpacer } from '@elastic/eui'; import { ShardFailure } from './shard_failure_types'; -import { getFlattenedObject } from '../../../../../../legacy/utils/get_flattened_object'; +import { getFlattenedObject } from '../../../../../../../legacy/utils/get_flattened_object'; import { ShardFailureDescriptionHeader } from './shard_failure_description_header'; /** diff --git a/src/legacy/ui/public/courier/fetch/components/shard_failure_description_header.tsx b/src/legacy/core_plugins/data/public/search/fetch/components/shard_failure_description_header.tsx similarity index 96% rename from src/legacy/ui/public/courier/fetch/components/shard_failure_description_header.tsx rename to src/legacy/core_plugins/data/public/search/fetch/components/shard_failure_description_header.tsx index ea4f33f9e914e..947f33efa242c 100644 --- a/src/legacy/ui/public/courier/fetch/components/shard_failure_description_header.tsx +++ b/src/legacy/core_plugins/data/public/search/fetch/components/shard_failure_description_header.tsx @@ -35,7 +35,7 @@ export function getFailureSummaryText(failure: ShardFailure, failureDetails?: st const displayDetails = typeof failureDetails === 'string' ? failureDetails : getFailureSummaryDetailsText(failure); - return i18n.translate('common.ui.courier.fetch.shardsFailedModal.failureHeader', { + return i18n.translate('data.search.searchSource.fetch.shardsFailedModal.failureHeader', { defaultMessage: '{failureName} at {failureDetails}', values: { failureName, failureDetails: displayDetails }, description: 'Summary of shard failures, e.g. "IllegalArgumentException at shard 0 node xyz"', diff --git a/src/legacy/ui/public/courier/fetch/components/shard_failure_modal.test.tsx b/src/legacy/core_plugins/data/public/search/fetch/components/shard_failure_modal.test.tsx similarity index 100% rename from src/legacy/ui/public/courier/fetch/components/shard_failure_modal.test.tsx rename to src/legacy/core_plugins/data/public/search/fetch/components/shard_failure_modal.test.tsx diff --git a/src/legacy/ui/public/courier/fetch/components/shard_failure_modal.tsx b/src/legacy/core_plugins/data/public/search/fetch/components/shard_failure_modal.tsx similarity index 85% rename from src/legacy/ui/public/courier/fetch/components/shard_failure_modal.tsx rename to src/legacy/core_plugins/data/public/search/fetch/components/shard_failure_modal.tsx index d028a831a6e39..65cb49c611575 100644 --- a/src/legacy/ui/public/courier/fetch/components/shard_failure_modal.tsx +++ b/src/legacy/core_plugins/data/public/search/fetch/components/shard_failure_modal.tsx @@ -59,15 +59,18 @@ export function ShardFailureModal({ request, response, title, onClose }: Props) const tabs = [ { id: 'table', - name: i18n.translate('common.ui.courier.fetch.shardsFailedModal.tabHeaderShardFailures', { - defaultMessage: 'Shard failures', - description: 'Name of the tab displaying shard failures', - }), + name: i18n.translate( + 'data.search.searchSource.fetch.shardsFailedModal.tabHeaderShardFailures', + { + defaultMessage: 'Shard failures', + description: 'Name of the tab displaying shard failures', + } + ), content: , }, { id: 'json-request', - name: i18n.translate('common.ui.courier.fetch.shardsFailedModal.tabHeaderRequest', { + name: i18n.translate('data.search.searchSource.fetch.shardsFailedModal.tabHeaderRequest', { defaultMessage: 'Request', description: 'Name of the tab displaying the JSON request', }), @@ -79,7 +82,7 @@ export function ShardFailureModal({ request, response, title, onClose }: Props) }, { id: 'json-response', - name: i18n.translate('common.ui.courier.fetch.shardsFailedModal.tabHeaderResponse', { + name: i18n.translate('data.search.searchSource.fetch.shardsFailedModal.tabHeaderResponse', { defaultMessage: 'Response', description: 'Name of the tab displaying the JSON response', }), @@ -104,7 +107,7 @@ export function ShardFailureModal({ request, response, title, onClose }: Props) {copy => ( @@ -112,7 +115,7 @@ export function ShardFailureModal({ request, response, title, onClose }: Props) onClose()} fill data-test-sub="closeShardFailureModal"> diff --git a/src/legacy/ui/public/courier/fetch/components/shard_failure_open_modal_button.test.mocks.tsx b/src/legacy/core_plugins/data/public/search/fetch/components/shard_failure_open_modal_button.test.mocks.tsx similarity index 100% rename from src/legacy/ui/public/courier/fetch/components/shard_failure_open_modal_button.test.mocks.tsx rename to src/legacy/core_plugins/data/public/search/fetch/components/shard_failure_open_modal_button.test.mocks.tsx diff --git a/src/legacy/ui/public/courier/fetch/components/shard_failure_open_modal_button.test.tsx b/src/legacy/core_plugins/data/public/search/fetch/components/shard_failure_open_modal_button.test.tsx similarity index 100% rename from src/legacy/ui/public/courier/fetch/components/shard_failure_open_modal_button.test.tsx rename to src/legacy/core_plugins/data/public/search/fetch/components/shard_failure_open_modal_button.test.tsx diff --git a/src/legacy/ui/public/courier/fetch/components/shard_failure_open_modal_button.tsx b/src/legacy/core_plugins/data/public/search/fetch/components/shard_failure_open_modal_button.tsx similarity index 92% rename from src/legacy/ui/public/courier/fetch/components/shard_failure_open_modal_button.tsx rename to src/legacy/core_plugins/data/public/search/fetch/components/shard_failure_open_modal_button.tsx index b02344ce6dd72..d81ee70a4611c 100644 --- a/src/legacy/ui/public/courier/fetch/components/shard_failure_open_modal_button.tsx +++ b/src/legacy/core_plugins/data/public/search/fetch/components/shard_failure_open_modal_button.tsx @@ -22,7 +22,7 @@ import { npStart } from 'ui/new_platform'; import { FormattedMessage } from '@kbn/i18n/react'; import { EuiButton, EuiTextAlign } from '@elastic/eui'; -import { toMountPoint } from '../../../../../../plugins/kibana_react/public'; +import { toMountPoint } from '../../../../../../../plugins/kibana_react/public'; import { ShardFailureModal } from './shard_failure_modal'; import { ResponseWithShardFailure, Request } from './shard_failure_types'; @@ -57,7 +57,7 @@ export function ShardFailureOpenModalButton({ request, response, title }: Props) data-test-subj="openShardFailureModalBtn" > diff --git a/src/legacy/ui/public/courier/fetch/components/shard_failure_table.test.tsx b/src/legacy/core_plugins/data/public/search/fetch/components/shard_failure_table.test.tsx similarity index 100% rename from src/legacy/ui/public/courier/fetch/components/shard_failure_table.test.tsx rename to src/legacy/core_plugins/data/public/search/fetch/components/shard_failure_table.test.tsx diff --git a/src/legacy/ui/public/courier/fetch/components/shard_failure_table.tsx b/src/legacy/core_plugins/data/public/search/fetch/components/shard_failure_table.tsx similarity index 87% rename from src/legacy/ui/public/courier/fetch/components/shard_failure_table.tsx rename to src/legacy/core_plugins/data/public/search/fetch/components/shard_failure_table.tsx index 54de64e52f745..5d5047631231a 100644 --- a/src/legacy/ui/public/courier/fetch/components/shard_failure_table.tsx +++ b/src/legacy/core_plugins/data/public/search/fetch/components/shard_failure_table.tsx @@ -44,7 +44,7 @@ export function ShardFailureTable({ failures }: { failures: ShardFailure[] }) { render: (item: ListItem) => { const failureSummeryText = getFailureSummaryText(item); const collapseLabel = i18n.translate( - 'common.ui.courier.fetch.shardsFailedModal.tableRowCollapse', + 'data.search.searchSource.fetch.shardsFailedModal.tableRowCollapse', { defaultMessage: 'Collapse {rowDescription}', description: 'Collapse a row of a table with failures', @@ -53,7 +53,7 @@ export function ShardFailureTable({ failures }: { failures: ShardFailure[] }) { ); const expandLabel = i18n.translate( - 'common.ui.courier.fetch.shardsFailedModal.tableRowExpand', + 'data.search.searchSource.fetch.shardsFailedModal.tableRowExpand', { defaultMessage: 'Expand {rowDescription}', description: 'Expand a row of a table with failures', @@ -81,7 +81,7 @@ export function ShardFailureTable({ failures }: { failures: ShardFailure[] }) { }, { field: 'shard', - name: i18n.translate('common.ui.courier.fetch.shardsFailedModal.tableColShard', { + name: i18n.translate('data.search.searchSource.fetch.shardsFailedModal.tableColShard', { defaultMessage: 'Shard', }), sortable: true, @@ -90,7 +90,7 @@ export function ShardFailureTable({ failures }: { failures: ShardFailure[] }) { }, { field: 'index', - name: i18n.translate('common.ui.courier.fetch.shardsFailedModal.tableColIndex', { + name: i18n.translate('data.search.searchSource.fetch.shardsFailedModal.tableColIndex', { defaultMessage: 'Index', }), sortable: true, @@ -98,7 +98,7 @@ export function ShardFailureTable({ failures }: { failures: ShardFailure[] }) { }, { field: 'node', - name: i18n.translate('common.ui.courier.fetch.shardsFailedModal.tableColNode', { + name: i18n.translate('data.search.searchSource.fetch.shardsFailedModal.tableColNode', { defaultMessage: 'Node', }), sortable: true, @@ -106,7 +106,7 @@ export function ShardFailureTable({ failures }: { failures: ShardFailure[] }) { }, { field: 'reason.type', - name: i18n.translate('common.ui.courier.fetch.shardsFailedModal.tableColReason', { + name: i18n.translate('data.search.searchSource.fetch.shardsFailedModal.tableColReason', { defaultMessage: 'Reason', }), truncateText: true, diff --git a/src/legacy/ui/public/courier/fetch/components/shard_failure_types.ts b/src/legacy/core_plugins/data/public/search/fetch/components/shard_failure_types.ts similarity index 100% rename from src/legacy/ui/public/courier/fetch/components/shard_failure_types.ts rename to src/legacy/core_plugins/data/public/search/fetch/components/shard_failure_types.ts diff --git a/src/legacy/ui/public/courier/fetch/errors.ts b/src/legacy/core_plugins/data/public/search/fetch/errors.ts similarity index 91% rename from src/legacy/ui/public/courier/fetch/errors.ts rename to src/legacy/core_plugins/data/public/search/fetch/errors.ts index a2ac013915b4b..5f5dc0452df51 100644 --- a/src/legacy/ui/public/courier/fetch/errors.ts +++ b/src/legacy/core_plugins/data/public/search/fetch/errors.ts @@ -17,9 +17,10 @@ * under the License. */ -import { SearchError } from '../../courier'; -import { KbnError } from '../../../../../plugins/kibana_utils/public'; +import { SearchError } from '../search_strategy'; +import { KbnError } from '../../../../../../plugins/kibana_utils/public'; import { SearchResponse } from '../types'; + /** * Request Failure - When an entire multi request fails * @param {Error} err - the Error that came back diff --git a/src/legacy/ui/public/courier/fetch/fetch_soon.test.ts b/src/legacy/core_plugins/data/public/search/fetch/fetch_soon.test.ts similarity index 98% rename from src/legacy/ui/public/courier/fetch/fetch_soon.test.ts rename to src/legacy/core_plugins/data/public/search/fetch/fetch_soon.test.ts index d96fb536985da..69a343c78b1e1 100644 --- a/src/legacy/ui/public/courier/fetch/fetch_soon.test.ts +++ b/src/legacy/core_plugins/data/public/search/fetch/fetch_soon.test.ts @@ -19,7 +19,7 @@ import { fetchSoon } from './fetch_soon'; import { callClient } from './call_client'; -import { IUiSettingsClient } from '../../../../../core/public'; +import { IUiSettingsClient } from '../../../../../../core/public'; import { FetchHandlers, FetchOptions } from './types'; import { SearchRequest, SearchResponse } from '../types'; diff --git a/src/legacy/ui/public/courier/fetch/fetch_soon.ts b/src/legacy/core_plugins/data/public/search/fetch/fetch_soon.ts similarity index 100% rename from src/legacy/ui/public/courier/fetch/fetch_soon.ts rename to src/legacy/core_plugins/data/public/search/fetch/fetch_soon.ts diff --git a/src/legacy/ui/public/courier/fetch/get_search_params.test.ts b/src/legacy/core_plugins/data/public/search/fetch/get_search_params.test.ts similarity index 98% rename from src/legacy/ui/public/courier/fetch/get_search_params.test.ts rename to src/legacy/core_plugins/data/public/search/fetch/get_search_params.test.ts index 76f3105d7f942..f856aa77bf1f8 100644 --- a/src/legacy/ui/public/courier/fetch/get_search_params.test.ts +++ b/src/legacy/core_plugins/data/public/search/fetch/get_search_params.test.ts @@ -18,7 +18,7 @@ */ import { getMSearchParams, getSearchParams } from './get_search_params'; -import { IUiSettingsClient } from '../../../../../core/public'; +import { IUiSettingsClient } from '../../../../../../core/public'; function getConfigStub(config: any = {}) { return { diff --git a/src/legacy/ui/public/courier/fetch/get_search_params.ts b/src/legacy/core_plugins/data/public/search/fetch/get_search_params.ts similarity index 97% rename from src/legacy/ui/public/courier/fetch/get_search_params.ts rename to src/legacy/core_plugins/data/public/search/fetch/get_search_params.ts index 9fb8f2c728c6f..de9ec4cb920e8 100644 --- a/src/legacy/ui/public/courier/fetch/get_search_params.ts +++ b/src/legacy/core_plugins/data/public/search/fetch/get_search_params.ts @@ -17,7 +17,7 @@ * under the License. */ -import { IUiSettingsClient } from '../../../../../core/public'; +import { IUiSettingsClient } from '../../../../../../core/public'; const sessionId = Date.now(); diff --git a/src/legacy/ui/public/courier/fetch/handle_response.test.ts b/src/legacy/core_plugins/data/public/search/fetch/handle_response.test.ts similarity index 95% rename from src/legacy/ui/public/courier/fetch/handle_response.test.ts rename to src/legacy/core_plugins/data/public/search/fetch/handle_response.test.ts index 0163aca777161..f8763a71d840e 100644 --- a/src/legacy/ui/public/courier/fetch/handle_response.test.ts +++ b/src/legacy/core_plugins/data/public/search/fetch/handle_response.test.ts @@ -18,9 +18,9 @@ */ import { handleResponse } from './handle_response'; -import { toastNotifications } from '../../notify/toasts'; +import { toastNotifications } from 'ui/notify/toasts'; -jest.mock('../../notify/toasts', () => { +jest.mock('ui/notify/toasts', () => { return { toastNotifications: { addWarning: jest.fn(), diff --git a/src/legacy/ui/public/courier/fetch/handle_response.tsx b/src/legacy/core_plugins/data/public/search/fetch/handle_response.tsx similarity index 84% rename from src/legacy/ui/public/courier/fetch/handle_response.tsx rename to src/legacy/core_plugins/data/public/search/fetch/handle_response.tsx index d7f2263268f8c..e3fd5ad15242d 100644 --- a/src/legacy/ui/public/courier/fetch/handle_response.tsx +++ b/src/legacy/core_plugins/data/public/search/fetch/handle_response.tsx @@ -20,23 +20,23 @@ import React from 'react'; import { i18n } from '@kbn/i18n'; import { EuiSpacer } from '@elastic/eui'; -import { toastNotifications } from '../../notify/toasts'; +import { toastNotifications } from 'ui/notify/toasts'; import { ShardFailureOpenModalButton } from './components/shard_failure_open_modal_button'; import { Request, ResponseWithShardFailure } from './components/shard_failure_types'; import { SearchRequest, SearchResponse } from '../types'; -import { toMountPoint } from '../../../../../plugins/kibana_react/public'; +import { toMountPoint } from '../../../../../../plugins/kibana_react/public'; export function handleResponse(request: SearchRequest, response: SearchResponse) { if (response.timed_out) { toastNotifications.addWarning({ - title: i18n.translate('common.ui.courier.fetch.requestTimedOutNotificationMessage', { + title: i18n.translate('data.search.searchSource.fetch.requestTimedOutNotificationMessage', { defaultMessage: 'Data might be incomplete because your request timed out', }), }); } if (response._shards && response._shards.failed) { - const title = i18n.translate('common.ui.courier.fetch.shardsFailedNotificationMessage', { + const title = i18n.translate('data.search.searchSource.fetch.shardsFailedNotificationMessage', { defaultMessage: '{shardsFailed} of {shardsTotal} shards failed', values: { shardsFailed: response._shards.failed, @@ -44,7 +44,7 @@ export function handleResponse(request: SearchRequest, response: SearchResponse) }, }); const description = i18n.translate( - 'common.ui.courier.fetch.shardsFailedNotificationDescription', + 'data.search.searchSource.fetch.shardsFailedNotificationDescription', { defaultMessage: 'The data you are seeing might be incomplete or wrong.', } diff --git a/src/legacy/ui/public/courier/fetch/index.ts b/src/legacy/core_plugins/data/public/search/fetch/index.ts similarity index 100% rename from src/legacy/ui/public/courier/fetch/index.ts rename to src/legacy/core_plugins/data/public/search/fetch/index.ts diff --git a/src/legacy/ui/public/courier/fetch/types.ts b/src/legacy/core_plugins/data/public/search/fetch/types.ts similarity index 95% rename from src/legacy/ui/public/courier/fetch/types.ts rename to src/legacy/core_plugins/data/public/search/fetch/types.ts index 03bf51ae15d45..0887a1f84c7c8 100644 --- a/src/legacy/ui/public/courier/fetch/types.ts +++ b/src/legacy/core_plugins/data/public/search/fetch/types.ts @@ -17,7 +17,7 @@ * under the License. */ -import { IUiSettingsClient } from '../../../../../core/public'; +import { IUiSettingsClient } from '../../../../../../core/public'; import { SearchRequest, SearchResponse } from '../types'; export interface ApiCaller { diff --git a/src/legacy/core_plugins/data/public/search/index.ts b/src/legacy/core_plugins/data/public/search/index.ts index 9880b336e76e5..d930a47219514 100644 --- a/src/legacy/core_plugins/data/public/search/index.ts +++ b/src/legacy/core_plugins/data/public/search/index.ts @@ -16,3 +16,7 @@ * specific language governing permissions and limitations * under the License. */ + +export { SearchService, SearchSetup, SearchStart } from './search_service'; + +export { getRequestInspectorStats, getResponseInspectorStats } from './utils'; diff --git a/src/legacy/core_plugins/data/public/search/search_service.ts b/src/legacy/core_plugins/data/public/search/search_service.ts new file mode 100644 index 0000000000000..85701187fb31d --- /dev/null +++ b/src/legacy/core_plugins/data/public/search/search_service.ts @@ -0,0 +1,51 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { Plugin, CoreSetup, CoreStart } from '../../../../../core/public'; +import { SearchSource } from './search_source'; +import { defaultSearchStrategy } from './search_strategy'; +import { SearchStrategyProvider } from './search_strategy/types'; + +export interface SearchSetup {} // eslint-disable-line @typescript-eslint/no-empty-interface + +export interface SearchStart { + defaultSearchStrategy: SearchStrategyProvider; + SearchSource: typeof SearchSource; +} + +/** + * The contract provided here is a new platform shim for ui/courier. + * + * Once it has been refactored to work with new platform services, + * it will move into the existing search service in src/plugins/data/public/search + */ +export class SearchService implements Plugin { + public setup(core: CoreSetup): SearchSetup { + return {}; + } + + public start(core: CoreStart): SearchStart { + return { + defaultSearchStrategy, + SearchSource, + }; + } + + public stop() {} +} diff --git a/src/legacy/ui/public/courier/search_source/filter_docvalue_fields.test.ts b/src/legacy/core_plugins/data/public/search/search_source/filter_docvalue_fields.test.ts similarity index 100% rename from src/legacy/ui/public/courier/search_source/filter_docvalue_fields.test.ts rename to src/legacy/core_plugins/data/public/search/search_source/filter_docvalue_fields.test.ts diff --git a/src/legacy/ui/public/courier/search_source/filter_docvalue_fields.ts b/src/legacy/core_plugins/data/public/search/search_source/filter_docvalue_fields.ts similarity index 100% rename from src/legacy/ui/public/courier/search_source/filter_docvalue_fields.ts rename to src/legacy/core_plugins/data/public/search/search_source/filter_docvalue_fields.ts diff --git a/src/legacy/core_plugins/data/public/search/search_source/index.ts b/src/legacy/core_plugins/data/public/search/search_source/index.ts new file mode 100644 index 0000000000000..72170adc2b129 --- /dev/null +++ b/src/legacy/core_plugins/data/public/search/search_source/index.ts @@ -0,0 +1,20 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export * from './search_source'; diff --git a/src/legacy/core_plugins/data/public/search/search_source/mocks.ts b/src/legacy/core_plugins/data/public/search/search_source/mocks.ts new file mode 100644 index 0000000000000..fd72158012de6 --- /dev/null +++ b/src/legacy/core_plugins/data/public/search/search_source/mocks.ts @@ -0,0 +1,59 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"), you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { ISearchSource } from './search_source'; + +export const searchSourceMock: MockedKeys = { + setPreferredSearchStrategyId: jest.fn(), + setFields: jest.fn().mockReturnThis(), + setField: jest.fn().mockReturnThis(), + getId: jest.fn(), + getFields: jest.fn(), + getField: jest.fn(), + getOwnField: jest.fn(), + create: jest.fn().mockReturnThis(), + createCopy: jest.fn().mockReturnThis(), + createChild: jest.fn().mockReturnThis(), + setParent: jest.fn(), + getParent: jest.fn().mockReturnThis(), + fetch: jest.fn().mockResolvedValue({}), + onRequestStart: jest.fn(), + getSearchRequestBody: jest.fn(), + destroy: jest.fn(), + history: [], +}; diff --git a/src/legacy/ui/public/courier/search_source/normalize_sort_request.test.ts b/src/legacy/core_plugins/data/public/search/search_source/normalize_sort_request.test.ts similarity index 97% rename from src/legacy/ui/public/courier/search_source/normalize_sort_request.test.ts rename to src/legacy/core_plugins/data/public/search/search_source/normalize_sort_request.test.ts index d27b01eb5cf7c..22d1d931a9d09 100644 --- a/src/legacy/ui/public/courier/search_source/normalize_sort_request.test.ts +++ b/src/legacy/core_plugins/data/public/search/search_source/normalize_sort_request.test.ts @@ -19,7 +19,7 @@ import { normalizeSortRequest } from './normalize_sort_request'; import { SortDirection } from './types'; -import { IndexPattern } from '../../../../core_plugins/data/public/index_patterns'; +import { IIndexPattern } from '../../../../../../plugins/data/public'; jest.mock('ui/new_platform'); @@ -40,7 +40,7 @@ describe('SearchSource#normalizeSortRequest', function() { }; const indexPattern = { fields: [scriptedField, murmurScriptedField], - } as IndexPattern; + } as IIndexPattern; it('should return an array', function() { const sortable = { someField: SortDirection.desc }; diff --git a/src/legacy/ui/public/courier/search_source/normalize_sort_request.ts b/src/legacy/core_plugins/data/public/search/search_source/normalize_sort_request.ts similarity index 93% rename from src/legacy/ui/public/courier/search_source/normalize_sort_request.ts rename to src/legacy/core_plugins/data/public/search/search_source/normalize_sort_request.ts index 0f8fc8076caa0..93834c95514dc 100644 --- a/src/legacy/ui/public/courier/search_source/normalize_sort_request.ts +++ b/src/legacy/core_plugins/data/public/search/search_source/normalize_sort_request.ts @@ -17,12 +17,12 @@ * under the License. */ -import { IndexPattern } from '../../../../core_plugins/data/public'; +import { IIndexPattern } from '../../../../../../plugins/data/public'; import { EsQuerySortValue, SortOptions } from './types'; export function normalizeSortRequest( sortObject: EsQuerySortValue | EsQuerySortValue[], - indexPattern: IndexPattern | string | undefined, + indexPattern: IIndexPattern | string | undefined, defaultSortOptions: SortOptions = {} ) { const sortArray: EsQuerySortValue[] = Array.isArray(sortObject) ? sortObject : [sortObject]; @@ -38,7 +38,7 @@ export function normalizeSortRequest( */ function normalize( sortable: EsQuerySortValue, - indexPattern: IndexPattern | string | undefined, + indexPattern: IIndexPattern | string | undefined, defaultSortOptions: any ) { const [[sortField, sortOrder]] = Object.entries(sortable); diff --git a/src/legacy/ui/public/courier/search_source/search_source.test.ts b/src/legacy/core_plugins/data/public/search/search_source/search_source.test.ts similarity index 98% rename from src/legacy/ui/public/courier/search_source/search_source.test.ts rename to src/legacy/core_plugins/data/public/search/search_source/search_source.test.ts index ddd3717f55e29..28f8dba9a75de 100644 --- a/src/legacy/ui/public/courier/search_source/search_source.test.ts +++ b/src/legacy/core_plugins/data/public/search/search_source/search_source.test.ts @@ -18,7 +18,7 @@ */ import { SearchSource } from '../search_source'; -import { IndexPattern } from '../../../../core_plugins/data/public'; +import { IndexPattern } from '../../../../../../plugins/data/public'; jest.mock('ui/new_platform'); @@ -26,7 +26,7 @@ jest.mock('../fetch', () => ({ fetchSoon: jest.fn().mockResolvedValue({}), })); -jest.mock('../../chrome', () => ({ +jest.mock('ui/chrome', () => ({ dangerouslyGetActiveInjector: () => ({ get: jest.fn(), }), diff --git a/src/legacy/core_plugins/data/public/search/search_source/search_source.ts b/src/legacy/core_plugins/data/public/search/search_source/search_source.ts new file mode 100644 index 0000000000000..01fc34e230a31 --- /dev/null +++ b/src/legacy/core_plugins/data/public/search/search_source/search_source.ts @@ -0,0 +1,410 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * @name SearchSource + * + * @description A promise-based stream of search results that can inherit from other search sources. + * + * Because filters/queries in Kibana have different levels of persistence and come from different + * places, it is important to keep track of where filters come from for when they are saved back to + * the savedObject store in the Kibana index. To do this, we create trees of searchSource objects + * that can have associated query parameters (index, query, filter, etc) which can also inherit from + * other searchSource objects. + * + * At query time, all of the searchSource objects that have subscribers are "flattened", at which + * point the query params from the searchSource are collected while traversing up the inheritance + * chain. At each link in the chain a decision about how to merge the query params is made until a + * single set of query parameters is created for each active searchSource (a searchSource with + * subscribers). + * + * That set of query parameters is then sent to elasticsearch. This is how the filter hierarchy + * works in Kibana. + * + * Visualize, starting from a new search: + * + * - the `savedVis.searchSource` is set as the `appSearchSource`. + * - The `savedVis.searchSource` would normally inherit from the `appSearchSource`, but now it is + * upgraded to inherit from the `rootSearchSource`. + * - Any interaction with the visualization will still apply filters to the `appSearchSource`, so + * they will be stored directly on the `savedVis.searchSource`. + * - Any interaction with the time filter will be written to the `rootSearchSource`, so those + * filters will not be saved by the `savedVis`. + * - When the `savedVis` is saved to elasticsearch, it takes with it all the filters that are + * defined on it directly, but none of the ones that it inherits from other places. + * + * Visualize, starting from an existing search: + * + * - The `savedVis` loads the `savedSearch` on which it is built. + * - The `savedVis.searchSource` is set to inherit from the `saveSearch.searchSource` and set as + * the `appSearchSource`. + * - The `savedSearch.searchSource`, is set to inherit from the `rootSearchSource`. + * - Then the `savedVis` is written to elasticsearch it will be flattened and only include the + * filters created in the visualize application and will reconnect the filters from the + * `savedSearch` at runtime to prevent losing the relationship + * + * Dashboard search sources: + * + * - Each panel in a dashboard has a search source. + * - The `savedDashboard` also has a searchsource, and it is set as the `appSearchSource`. + * - Each panel's search source inherits from the `appSearchSource`, meaning that they inherit from + * the dashboard search source. + * - When a filter is added to the search box, or via a visualization, it is written to the + * `appSearchSource`. + */ + +import _ from 'lodash'; +import { npSetup } from 'ui/new_platform'; +import chrome from 'ui/chrome'; +import { fieldWildcardFilter } from 'ui/field_wildcard'; +import { normalizeSortRequest } from './normalize_sort_request'; +import { fetchSoon } from '../fetch'; +import { getHighlightRequest, esFilters, esQuery } from '../../../../../../plugins/data/public'; +import { RequestFailure } from '../fetch/errors'; +import { filterDocvalueFields } from './filter_docvalue_fields'; +import { SearchSourceOptions, SearchSourceFields, SearchRequest } from './types'; +import { FetchOptions, ApiCaller } from '../fetch/types'; + +const esShardTimeout = npSetup.core.injectedMetadata.getInjectedVar('esShardTimeout') as number; +const config = npSetup.core.uiSettings; + +export type ISearchSource = Pick; + +export class SearchSource { + private id: string = _.uniqueId('data_source'); + private searchStrategyId?: string; + private parent?: SearchSource; + private requestStartHandlers: Array< + (searchSource: ISearchSource, options?: FetchOptions) => Promise + > = []; + private inheritOptions: SearchSourceOptions = {}; + public history: SearchRequest[] = []; + + constructor(private fields: SearchSourceFields = {}) {} + + /** *** + * PUBLIC API + *****/ + + setPreferredSearchStrategyId(searchStrategyId: string) { + this.searchStrategyId = searchStrategyId; + } + + setFields(newFields: SearchSourceFields) { + this.fields = newFields; + return this; + } + + setField(field: K, value: SearchSourceFields[K]) { + if (value == null) { + delete this.fields[field]; + } else { + this.fields[field] = value; + } + return this; + } + + getId() { + return this.id; + } + + getFields() { + return { ...this.fields }; + } + + /** + * Get fields from the fields + */ + getField(field: K, recurse = true): SearchSourceFields[K] { + if (!recurse || this.fields[field] !== void 0) { + return this.fields[field]; + } + const parent = this.getParent(); + return parent && parent.getField(field); + } + + /** + * Get the field from our own fields, don't traverse up the chain + */ + getOwnField(field: K): SearchSourceFields[K] { + return this.getField(field, false); + } + + create() { + return new SearchSource(); + } + + createCopy() { + const newSearchSource = new SearchSource(); + newSearchSource.setFields({ ...this.fields }); + // when serializing the internal fields we lose the internal classes used in the index + // pattern, so we have to set it again to workaround this behavior + newSearchSource.setField('index', this.getField('index')); + newSearchSource.setParent(this.getParent()); + return newSearchSource; + } + + createChild(options = {}) { + const childSearchSource = new SearchSource(); + childSearchSource.setParent(this, options); + return childSearchSource; + } + + /** + * Set a searchSource that this source should inherit from + * @param {SearchSource} parent - the parent searchSource + * @param {SearchSourceOptions} options - the inherit options + * @return {this} - chainable + */ + setParent(parent?: ISearchSource, options: SearchSourceOptions = {}) { + this.parent = parent as SearchSource; + this.inheritOptions = options; + return this; + } + + /** + * Get the parent of this SearchSource + * @return {undefined|searchSource} + */ + getParent() { + return this.parent; + } + + /** + * Fetch this source and reject the returned Promise on error + * + * @async + */ + async fetch(options: FetchOptions = {}) { + const $injector = await chrome.dangerouslyGetActiveInjector(); + const es = $injector.get('es') as ApiCaller; + + await this.requestIsStarting(options); + + const searchRequest = await this.flatten(); + this.history = [searchRequest]; + + const response = await fetchSoon( + searchRequest, + { + ...(this.searchStrategyId && { searchStrategyId: this.searchStrategyId }), + ...options, + }, + { es, config, esShardTimeout } + ); + + if (response.error) { + throw new RequestFailure(null, response); + } + + return response; + } + + /** + * Add a handler that will be notified whenever requests start + * @param {Function} handler + * @return {undefined} + */ + onRequestStart( + handler: (searchSource: ISearchSource, options?: FetchOptions) => Promise + ) { + this.requestStartHandlers.push(handler); + } + + async getSearchRequestBody() { + const searchRequest = await this.flatten(); + return searchRequest.body; + } + + /** + * Completely destroy the SearchSource. + * @return {undefined} + */ + destroy() { + this.requestStartHandlers.length = 0; + } + + /** **** + * PRIVATE APIS + ******/ + + /** + * Called by requests of this search source when they are started + * @param {Courier.Request} request + * @param options + * @return {Promise} + */ + private requestIsStarting(options: FetchOptions = {}) { + const handlers = [...this.requestStartHandlers]; + // If callParentStartHandlers has been set to true, we also call all + // handlers of parent search sources. + if (this.inheritOptions.callParentStartHandlers) { + let searchSource = this.getParent(); + while (searchSource) { + handlers.push(...searchSource.requestStartHandlers); + searchSource = searchSource.getParent(); + } + } + + return Promise.all(handlers.map(fn => fn(this, options))); + } + + /** + * Used to merge properties into the data within ._flatten(). + * The data is passed in and modified by the function + * + * @param {object} data - the current merged data + * @param {*} val - the value at `key` + * @param {*} key - The key of `val` + * @return {undefined} + */ + private mergeProp( + data: SearchRequest, + val: SearchSourceFields[K], + key: K + ) { + val = typeof val === 'function' ? val(this) : val; + if (val == null || !key) return; + + const addToRoot = (rootKey: string, value: any) => { + data[rootKey] = value; + }; + + /** + * Add the key and val to the body of the request + */ + const addToBody = (bodyKey: string, value: any) => { + // ignore if we already have a value + if (data.body[bodyKey] == null) { + data.body[bodyKey] = value; + } + }; + + switch (key) { + case 'filter': + return addToRoot('filters', (data.filters || []).concat(val)); + case 'query': + return addToRoot(key, (data[key] || []).concat(val)); + case 'fields': + const fields = _.uniq((data[key] || []).concat(val)); + return addToRoot(key, fields); + case 'index': + case 'type': + case 'highlightAll': + return key && data[key] == null && addToRoot(key, val); + case 'searchAfter': + return addToBody('search_after', val); + case 'source': + return addToBody('_source', val); + case 'sort': + const sort = normalizeSortRequest(val, this.getField('index'), config.get('sort:options')); + return addToBody(key, sort); + default: + return addToBody(key, val); + } + } + + /** + * Walk the inheritance chain of a source and return its + * flat representation (taking into account merging rules) + * @returns {Promise} + * @resolved {Object|null} - the flat data of the SearchSource + */ + private mergeProps(root = this, searchRequest: SearchRequest = { body: {} }) { + Object.entries(this.fields).forEach(([key, value]) => { + this.mergeProp(searchRequest, value, key as keyof SearchSourceFields); + }); + if (this.parent) { + this.parent.mergeProps(root, searchRequest); + } + return searchRequest; + } + + private flatten() { + const searchRequest = this.mergeProps(); + + searchRequest.body = searchRequest.body || {}; + const { body, index, fields, query, filters, highlightAll } = searchRequest; + + const computedFields = index ? index.getComputedFields() : {}; + + body.stored_fields = computedFields.storedFields; + body.script_fields = body.script_fields || {}; + _.extend(body.script_fields, computedFields.scriptFields); + + const defaultDocValueFields = computedFields.docvalueFields + ? computedFields.docvalueFields + : []; + body.docvalue_fields = body.docvalue_fields || defaultDocValueFields; + + if (!body.hasOwnProperty('_source') && index) { + body._source = index.getSourceFiltering(); + } + + if (body._source) { + // exclude source fields for this index pattern specified by the user + const filter = fieldWildcardFilter(body._source.excludes, config.get('metaFields')); + body.docvalue_fields = body.docvalue_fields.filter((docvalueField: any) => + filter(docvalueField.field) + ); + } + + // if we only want to search for certain fields + if (fields) { + // filter out the docvalue_fields, and script_fields to only include those that we are concerned with + body.docvalue_fields = filterDocvalueFields(body.docvalue_fields, fields); + body.script_fields = _.pick(body.script_fields, fields); + + // request the remaining fields from both stored_fields and _source + const remainingFields = _.difference(fields, _.keys(body.script_fields)); + body.stored_fields = remainingFields; + _.set(body, '_source.includes', remainingFields); + } + + const esQueryConfigs = esQuery.getEsQueryConfig(config); + body.query = esQuery.buildEsQuery(index, query, filters, esQueryConfigs); + + if (highlightAll && body.query) { + body.highlight = getHighlightRequest(body.query, config.get('doc_table:highlight')); + delete searchRequest.highlightAll; + } + + const translateToQuery = (filter: esFilters.Filter) => filter && (filter.query || filter); + + // re-write filters within filter aggregations + (function recurse(aggBranch) { + if (!aggBranch) return; + Object.keys(aggBranch).forEach(function(id) { + const agg = aggBranch[id]; + + if (agg.filters) { + // translate filters aggregations + const { filters: aggFilters } = agg.filters; + Object.keys(aggFilters).forEach(filterId => { + aggFilters[filterId] = translateToQuery(aggFilters[filterId]); + }); + } + + recurse(agg.aggs || agg.aggregations); + }); + })(body.aggs || body.aggregations); + + return searchRequest; + } +} diff --git a/src/legacy/ui/public/courier/search_source/types.ts b/src/legacy/core_plugins/data/public/search/search_source/types.ts similarity index 94% rename from src/legacy/ui/public/courier/search_source/types.ts rename to src/legacy/core_plugins/data/public/search/search_source/types.ts index 8fd6d8cfa5fa0..9c5b57519d75f 100644 --- a/src/legacy/ui/public/courier/search_source/types.ts +++ b/src/legacy/core_plugins/data/public/search/search_source/types.ts @@ -17,7 +17,7 @@ * under the License. */ import { NameList } from 'elasticsearch'; -import { esFilters, Query, IndexPattern } from '../../../../../plugins/data/public'; +import { esFilters, IndexPattern, Query } from '../../../../../../plugins/data/public'; export type EsQuerySearchAfter = [string | number, string | number]; @@ -54,7 +54,7 @@ export interface SearchSourceOptions { callParentStartHandlers?: boolean; } -export { SearchSourceContract } from './search_source'; +export { ISearchSource } from './search_source'; export interface SortOptions { mode?: 'min' | 'max' | 'sum' | 'avg' | 'median'; diff --git a/src/legacy/ui/public/courier/search_strategy/default_search_strategy.test.ts b/src/legacy/core_plugins/data/public/search/search_strategy/default_search_strategy.test.ts similarity index 98% rename from src/legacy/ui/public/courier/search_strategy/default_search_strategy.test.ts rename to src/legacy/core_plugins/data/public/search/search_strategy/default_search_strategy.test.ts index 53a857a72c1a3..0ec6a6c2e143e 100644 --- a/src/legacy/ui/public/courier/search_strategy/default_search_strategy.test.ts +++ b/src/legacy/core_plugins/data/public/search/search_strategy/default_search_strategy.test.ts @@ -18,7 +18,7 @@ */ import { defaultSearchStrategy } from './default_search_strategy'; -import { IUiSettingsClient } from '../../../../../core/public'; +import { IUiSettingsClient } from '../../../../../../core/public'; import { SearchStrategySearchParams } from './types'; const { search } = defaultSearchStrategy; diff --git a/src/legacy/core_plugins/data/public/search/search_strategy/default_search_strategy.ts b/src/legacy/core_plugins/data/public/search/search_strategy/default_search_strategy.ts new file mode 100644 index 0000000000000..9bfa1df71aa81 --- /dev/null +++ b/src/legacy/core_plugins/data/public/search/search_strategy/default_search_strategy.ts @@ -0,0 +1,78 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { SearchStrategyProvider, SearchStrategySearchParams } from './types'; +import { isDefaultTypeIndexPattern } from './is_default_type_index_pattern'; +import { + getSearchParams, + getMSearchParams, + getPreference, + getTimeout, +} from '../fetch/get_search_params'; + +export const defaultSearchStrategy: SearchStrategyProvider = { + id: 'default', + + search: params => { + return params.config.get('courier:batchSearches') ? msearch(params) : search(params); + }, + + isViable: indexPattern => { + return indexPattern && isDefaultTypeIndexPattern(indexPattern); + }, +}; + +function msearch({ searchRequests, es, config, esShardTimeout }: SearchStrategySearchParams) { + const inlineRequests = searchRequests.map(({ index, body, search_type: searchType }) => { + const inlineHeader = { + index: index.title || index, + search_type: searchType, + ignore_unavailable: true, + preference: getPreference(config), + }; + const inlineBody = { + ...body, + timeout: getTimeout(esShardTimeout), + }; + return `${JSON.stringify(inlineHeader)}\n${JSON.stringify(inlineBody)}`; + }); + + const searching = es.msearch({ + ...getMSearchParams(config), + body: `${inlineRequests.join('\n')}\n`, + }); + return { + searching: searching.then(({ responses }) => responses), + abort: searching.abort, + }; +} + +function search({ searchRequests, es, config, esShardTimeout }: SearchStrategySearchParams) { + const abortController = new AbortController(); + const searchParams = getSearchParams(config, esShardTimeout); + const promises = searchRequests.map(({ index, body }) => { + const searching = es.search({ index: index.title || index, body, ...searchParams }); + abortController.signal.addEventListener('abort', searching.abort); + return searching.catch(({ response }) => JSON.parse(response)); + }); + return { + searching: Promise.all(promises), + abort: () => abortController.abort(), + }; +} diff --git a/src/legacy/core_plugins/data/public/search/search_strategy/index.ts b/src/legacy/core_plugins/data/public/search/search_strategy/index.ts new file mode 100644 index 0000000000000..1584baa4faade --- /dev/null +++ b/src/legacy/core_plugins/data/public/search/search_strategy/index.ts @@ -0,0 +1,31 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export { + addSearchStrategy, + hasSearchStategyForIndexPattern, + getSearchStrategyById, + getSearchStrategyForSearchRequest, +} from './search_strategy_registry'; + +export { defaultSearchStrategy } from './default_search_strategy'; + +export { isDefaultTypeIndexPattern } from './is_default_type_index_pattern'; + +export { SearchError, getSearchErrorType } from './search_error'; diff --git a/src/legacy/ui/public/courier/search_strategy/is_default_type_index_pattern.ts b/src/legacy/core_plugins/data/public/search/search_strategy/is_default_type_index_pattern.ts similarity index 93% rename from src/legacy/ui/public/courier/search_strategy/is_default_type_index_pattern.ts rename to src/legacy/core_plugins/data/public/search/search_strategy/is_default_type_index_pattern.ts index 3785ce6341078..7d03b1dc9e0b1 100644 --- a/src/legacy/ui/public/courier/search_strategy/is_default_type_index_pattern.ts +++ b/src/legacy/core_plugins/data/public/search/search_strategy/is_default_type_index_pattern.ts @@ -17,7 +17,7 @@ * under the License. */ -import { IndexPattern } from '../../../../core_plugins/data/public'; +import { IndexPattern } from '../../../../../../plugins/data/public'; export const isDefaultTypeIndexPattern = (indexPattern: IndexPattern) => { // Default index patterns don't have `type` defined. diff --git a/src/legacy/ui/public/courier/search_strategy/no_op_search_strategy.ts b/src/legacy/core_plugins/data/public/search/search_strategy/no_op_search_strategy.ts similarity index 83% rename from src/legacy/ui/public/courier/search_strategy/no_op_search_strategy.ts rename to src/legacy/core_plugins/data/public/search/search_strategy/no_op_search_strategy.ts index 24c3876cfcc05..dc7331e614a0e 100644 --- a/src/legacy/ui/public/courier/search_strategy/no_op_search_strategy.ts +++ b/src/legacy/core_plugins/data/public/search/search_strategy/no_op_search_strategy.ts @@ -27,11 +27,14 @@ export const noOpSearchStrategy: SearchStrategyProvider = { search: () => { const searchError = new SearchError({ status: '418', // "I'm a teapot" error - title: i18n.translate('common.ui.courier.noSearchStrategyRegisteredErrorMessageTitle', { - defaultMessage: 'No search strategy registered', - }), + title: i18n.translate( + 'data.search.searchSource.noSearchStrategyRegisteredErrorMessageTitle', + { + defaultMessage: 'No search strategy registered', + } + ), message: i18n.translate( - 'common.ui.courier.noSearchStrategyRegisteredErrorMessageDescription', + 'data.search.searchSource.noSearchStrategyRegisteredErrorMessageDescription', { defaultMessage: `Couldn't find a search strategy for the search request`, } diff --git a/src/legacy/core_plugins/data/public/search/search_strategy/search_error.ts b/src/legacy/core_plugins/data/public/search/search_strategy/search_error.ts new file mode 100644 index 0000000000000..d4042fb17499c --- /dev/null +++ b/src/legacy/core_plugins/data/public/search/search_strategy/search_error.ts @@ -0,0 +1,62 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +interface SearchErrorOptions { + status: string; + title: string; + message: string; + path: string; + type: string; +} + +export class SearchError extends Error { + public name: string; + public status: string; + public title: string; + public message: string; + public path: string; + public type: string; + + constructor({ status, title, message, path, type }: SearchErrorOptions) { + super(message); + this.name = 'SearchError'; + this.status = status; + this.title = title; + this.message = message; + this.path = path; + this.type = type; + + // captureStackTrace is only available in the V8 engine, so any browser using + // a different JS engine won't have access to this method. + if (Error.captureStackTrace) { + Error.captureStackTrace(this, SearchError); + } + + // Babel doesn't support traditional `extends` syntax for built-in classes. + // https://babeljs.io/docs/en/caveats/#classes + Object.setPrototypeOf(this, SearchError.prototype); + } +} + +export function getSearchErrorType({ message }: Pick) { + const msg = message.toLowerCase(); + if (msg.indexOf('unsupported query') > -1) { + return 'UNSUPPORTED_QUERY'; + } +} diff --git a/src/legacy/ui/public/courier/search_strategy/search_strategy_registry.test.ts b/src/legacy/core_plugins/data/public/search/search_strategy/search_strategy_registry.test.ts similarity index 98% rename from src/legacy/ui/public/courier/search_strategy/search_strategy_registry.test.ts rename to src/legacy/core_plugins/data/public/search/search_strategy/search_strategy_registry.test.ts index ae2ed6128c8ea..73b011896a97d 100644 --- a/src/legacy/ui/public/courier/search_strategy/search_strategy_registry.test.ts +++ b/src/legacy/core_plugins/data/public/search/search_strategy/search_strategy_registry.test.ts @@ -17,7 +17,7 @@ * under the License. */ -import { IndexPattern } from '../../../../core_plugins/data/public'; +import { IndexPattern } from '../../../../../../plugins/data/public'; import { noOpSearchStrategy } from './no_op_search_strategy'; import { searchStrategies, diff --git a/src/legacy/ui/public/courier/search_strategy/search_strategy_registry.ts b/src/legacy/core_plugins/data/public/search/search_strategy/search_strategy_registry.ts similarity index 97% rename from src/legacy/ui/public/courier/search_strategy/search_strategy_registry.ts rename to src/legacy/core_plugins/data/public/search/search_strategy/search_strategy_registry.ts index 9ef007f97531e..d814a04737f75 100644 --- a/src/legacy/ui/public/courier/search_strategy/search_strategy_registry.ts +++ b/src/legacy/core_plugins/data/public/search/search_strategy/search_strategy_registry.ts @@ -17,7 +17,7 @@ * under the License. */ -import { IndexPattern } from '../../../../core_plugins/data/public'; +import { IndexPattern } from '../../../../../../plugins/data/public'; import { SearchStrategyProvider } from './types'; import { noOpSearchStrategy } from './no_op_search_strategy'; import { SearchResponse } from '../types'; diff --git a/src/legacy/ui/public/courier/search_strategy/types.ts b/src/legacy/core_plugins/data/public/search/search_strategy/types.ts similarity index 94% rename from src/legacy/ui/public/courier/search_strategy/types.ts rename to src/legacy/core_plugins/data/public/search/search_strategy/types.ts index 1542f9824a5b1..ad8576589e4e3 100644 --- a/src/legacy/ui/public/courier/search_strategy/types.ts +++ b/src/legacy/core_plugins/data/public/search/search_strategy/types.ts @@ -17,7 +17,7 @@ * under the License. */ -import { IndexPattern } from '../../../../core_plugins/data/public'; +import { IndexPattern } from '../../../../../../plugins/data/public'; import { FetchHandlers } from '../fetch/types'; import { SearchRequest, SearchResponse } from '../types'; diff --git a/src/legacy/core_plugins/data/public/search/types.ts b/src/legacy/core_plugins/data/public/search/types.ts new file mode 100644 index 0000000000000..23d74ce6a57da --- /dev/null +++ b/src/legacy/core_plugins/data/public/search/types.ts @@ -0,0 +1,23 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export * from './fetch/types'; +export * from './search_source/types'; +export * from './search_strategy/types'; +export * from './utils/types'; diff --git a/src/legacy/ui/public/courier/utils/courier_inspector_utils.ts b/src/legacy/core_plugins/data/public/search/utils/courier_inspector_utils.ts similarity index 72% rename from src/legacy/ui/public/courier/utils/courier_inspector_utils.ts rename to src/legacy/core_plugins/data/public/search/utils/courier_inspector_utils.ts index b4d5d5537333e..7f7d216d8f0f3 100644 --- a/src/legacy/ui/public/courier/utils/courier_inspector_utils.ts +++ b/src/legacy/core_plugins/data/public/search/utils/courier_inspector_utils.ts @@ -26,28 +26,28 @@ import { i18n } from '@kbn/i18n'; import { SearchResponse } from 'elasticsearch'; -import { SearchSourceContract, RequestInspectorStats } from '../types'; +import { ISearchSource, RequestInspectorStats } from '../types'; -export function getRequestInspectorStats(searchSource: SearchSourceContract) { +export function getRequestInspectorStats(searchSource: ISearchSource) { const stats: RequestInspectorStats = {}; const index = searchSource.getField('index'); if (index) { stats.indexPattern = { - label: i18n.translate('common.ui.courier.indexPatternLabel', { + label: i18n.translate('data.search.searchSource.indexPatternLabel', { defaultMessage: 'Index pattern', }), value: index.title, - description: i18n.translate('common.ui.courier.indexPatternDescription', { + description: i18n.translate('data.search.searchSource.indexPatternDescription', { defaultMessage: 'The index pattern that connected to the Elasticsearch indices.', }), }; stats.indexPatternId = { - label: i18n.translate('common.ui.courier.indexPatternIdLabel', { + label: i18n.translate('data.search.searchSource.indexPatternIdLabel', { defaultMessage: 'Index pattern ID', }), value: index.id!, - description: i18n.translate('common.ui.courier.indexPatternIdDescription', { + description: i18n.translate('data.search.searchSource.indexPatternIdDescription', { defaultMessage: 'The ID in the {kibanaIndexPattern} index.', values: { kibanaIndexPattern: '.kibana' }, }), @@ -58,7 +58,7 @@ export function getRequestInspectorStats(searchSource: SearchSourceContract) { } export function getResponseInspectorStats( - searchSource: SearchSourceContract, + searchSource: ISearchSource, resp: SearchResponse ) { const lastRequest = searchSource.history && searchSource.history[searchSource.history.length - 1]; @@ -66,14 +66,14 @@ export function getResponseInspectorStats( if (resp && resp.took) { stats.queryTime = { - label: i18n.translate('common.ui.courier.queryTimeLabel', { + label: i18n.translate('data.search.searchSource.queryTimeLabel', { defaultMessage: 'Query time', }), - value: i18n.translate('common.ui.courier.queryTimeValue', { + value: i18n.translate('data.search.searchSource.queryTimeValue', { defaultMessage: '{queryTime}ms', values: { queryTime: resp.took }, }), - description: i18n.translate('common.ui.courier.queryTimeDescription', { + description: i18n.translate('data.search.searchSource.queryTimeDescription', { defaultMessage: 'The time it took to process the query. ' + 'Does not include the time to send the request or parse it in the browser.', @@ -83,21 +83,21 @@ export function getResponseInspectorStats( if (resp && resp.hits) { stats.hitsTotal = { - label: i18n.translate('common.ui.courier.hitsTotalLabel', { + label: i18n.translate('data.search.searchSource.hitsTotalLabel', { defaultMessage: 'Hits (total)', }), value: `${resp.hits.total}`, - description: i18n.translate('common.ui.courier.hitsTotalDescription', { + description: i18n.translate('data.search.searchSource.hitsTotalDescription', { defaultMessage: 'The number of documents that match the query.', }), }; stats.hits = { - label: i18n.translate('common.ui.courier.hitsLabel', { + label: i18n.translate('data.search.searchSource.hitsLabel', { defaultMessage: 'Hits', }), value: `${resp.hits.hits.length}`, - description: i18n.translate('common.ui.courier.hitsDescription', { + description: i18n.translate('data.search.searchSource.hitsDescription', { defaultMessage: 'The number of documents returned by the query.', }), }; @@ -105,14 +105,14 @@ export function getResponseInspectorStats( if (lastRequest && (lastRequest.ms === 0 || lastRequest.ms)) { stats.requestTime = { - label: i18n.translate('common.ui.courier.requestTimeLabel', { + label: i18n.translate('data.search.searchSource.requestTimeLabel', { defaultMessage: 'Request time', }), - value: i18n.translate('common.ui.courier.requestTimeValue', { + value: i18n.translate('data.search.searchSource.requestTimeValue', { defaultMessage: '{requestTime}ms', values: { requestTime: lastRequest.ms }, }), - description: i18n.translate('common.ui.courier.requestTimeDescription', { + description: i18n.translate('data.search.searchSource.requestTimeDescription', { defaultMessage: 'The time of the request from the browser to Elasticsearch and back. ' + 'Does not include the time the requested waited in the queue.', diff --git a/src/legacy/core_plugins/data/public/search/utils/index.ts b/src/legacy/core_plugins/data/public/search/utils/index.ts new file mode 100644 index 0000000000000..021ece8701e98 --- /dev/null +++ b/src/legacy/core_plugins/data/public/search/utils/index.ts @@ -0,0 +1,20 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export * from './courier_inspector_utils'; diff --git a/src/legacy/ui/public/courier/utils/types.ts b/src/legacy/core_plugins/data/public/search/utils/types.ts similarity index 100% rename from src/legacy/ui/public/courier/utils/types.ts rename to src/legacy/core_plugins/data/public/search/utils/types.ts diff --git a/src/legacy/core_plugins/input_control_vis/public/legacy_imports.ts b/src/legacy/core_plugins/input_control_vis/public/legacy_imports.ts index 864ce3b146689..176fe68fe4788 100644 --- a/src/legacy/core_plugins/input_control_vis/public/legacy_imports.ts +++ b/src/legacy/core_plugins/input_control_vis/public/legacy_imports.ts @@ -17,13 +17,13 @@ * under the License. */ -import { SearchSource as SearchSourceClass } from 'ui/courier'; +import { SearchSource as SearchSourceClass, ISearchSource } from 'ui/courier'; import { Class } from '@kbn/utility-types'; export { Vis, VisParams } from 'ui/vis'; export { VisOptionsProps } from 'ui/vis/editors/default'; export { ValidatedDualRange } from 'ui/validated_range'; -export { SearchSourceFields } from 'ui/courier/types'; +export { SearchSourceFields } from '../../data/public'; -export type SearchSource = Class; +export type SearchSource = Class; export const SearchSource = SearchSourceClass; diff --git a/src/legacy/core_plugins/kbn_doc_views/public/views/table/table.test.tsx b/src/legacy/core_plugins/kbn_doc_views/public/views/table/table.test.tsx index bad006aa8c7d5..24efbc2d41f4f 100644 --- a/src/legacy/core_plugins/kbn_doc_views/public/views/table/table.test.tsx +++ b/src/legacy/core_plugins/kbn_doc_views/public/views/table/table.test.tsx @@ -24,6 +24,8 @@ import { findTestSubject } from '@elastic/eui/lib/test'; import { flattenHitWrapper } from '../../../../data/public/'; import { DocViewTable } from './table'; +jest.mock('ui/new_platform'); + // @ts-ignore const indexPattern = { fields: { diff --git a/src/legacy/core_plugins/kibana/public/dashboard/saved_dashboard/saved_dashboard.ts b/src/legacy/core_plugins/kibana/public/dashboard/saved_dashboard/saved_dashboard.ts index 7f4d7402fcffc..18e15b215523e 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/saved_dashboard/saved_dashboard.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/saved_dashboard/saved_dashboard.ts @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -import { SearchSourceContract } from 'ui/courier'; +import { ISearchSource } from 'ui/courier'; import { SavedObject, SavedObjectKibanaServices } from 'ui/saved_objects/types'; import { createSavedObjectClass } from 'ui/saved_objects/saved_object'; import { extractReferences, injectReferences } from './saved_dashboard_references'; @@ -36,7 +36,7 @@ export interface SavedObjectDashboard extends SavedObject { uiStateJSON?: string; lastSavedTitle: string; refreshInterval?: RefreshInterval; - searchSource: SearchSourceContract; + searchSource: ISearchSource; getQuery(): Query; getFilters(): esFilters.Filter[]; } diff --git a/src/legacy/core_plugins/kibana/public/discover/kibana_services.ts b/src/legacy/core_plugins/kibana/public/discover/kibana_services.ts index ae388a243dd2b..ca169e5f803ab 100644 --- a/src/legacy/core_plugins/kibana/public/discover/kibana_services.ts +++ b/src/legacy/core_plugins/kibana/public/discover/kibana_services.ts @@ -65,8 +65,8 @@ export { SearchSource, EsQuerySortValue, SortDirection, - SearchSourceContract, -} from '../../../../ui/public/courier'; + ISearchSource, +} from 'ui/courier'; // @ts-ignore export { intervalOptions } from 'ui/agg_types/buckets/_interval_options'; // @ts-ignore diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/utils/fetch_hits_in_interval.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/utils/fetch_hits_in_interval.ts index 1351421e1af04..e7df44e6fe61c 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/utils/fetch_hits_in_interval.ts +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/utils/fetch_hits_in_interval.ts @@ -16,11 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -import { - EsQuerySortValue, - SortDirection, - SearchSourceContract, -} from '../../../../../kibana_services'; +import { EsQuerySortValue, SortDirection, ISearchSource } from '../../../../../kibana_services'; import { convertTimeValueToIso } from './date_conversion'; import { EsHitRecordList } from '../context'; import { IntervalValue } from './generate_intervals'; @@ -40,7 +36,7 @@ interface RangeQuery { * and filters set. */ export async function fetchHitsInInterval( - searchSource: SearchSourceContract, + searchSource: ISearchSource, timeField: string, sort: [EsQuerySortValue, EsQuerySortValue], sortDir: SortDirection, diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/embeddable/search_embeddable.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/embeddable/search_embeddable.ts index 14f7057045251..3aa8dea816694 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/embeddable/search_embeddable.ts +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/embeddable/search_embeddable.ts @@ -50,7 +50,7 @@ import { getServices, IndexPattern, RequestAdapter, - SearchSourceContract, + ISearchSource, } from '../../kibana_services'; import { SEARCH_EMBEDDABLE_TYPE } from './constants'; @@ -89,7 +89,7 @@ export class SearchEmbeddable extends Embeddable private inspectorAdaptors: Adapters; private searchScope?: SearchScope; private panelTitle: string = ''; - private filtersSearchSource?: SearchSourceContract; + private filtersSearchSource?: ISearchSource; private searchInstance?: JQLite; private autoRefreshFetchSubscription?: Subscription; private subscription?: Subscription; diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/types.d.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/types.d.ts index c8920e351fcca..d36a6b02e1f7a 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/types.d.ts +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/types.d.ts @@ -17,14 +17,13 @@ * under the License. */ -import { SearchSourceContract } from '../kibana_services'; +import { ISearchSource } from '../kibana_services'; import { SortOrder } from './angular/doc_table/components/table_header/helpers'; -export { SortOrder } from './angular/doc_table/components/table_header/helpers'; export interface SavedSearch { readonly id: string; title: string; - searchSource: SearchSourceContract; + searchSource: ISearchSource; description?: string; columns: string[]; sort: SortOrder[]; diff --git a/src/legacy/core_plugins/kibana/public/visualize_embeddable/visualize_embeddable.ts b/src/legacy/core_plugins/kibana/public/visualize_embeddable/visualize_embeddable.ts index 6aade246d5f65..4d45b0d86023e 100644 --- a/src/legacy/core_plugins/kibana/public/visualize_embeddable/visualize_embeddable.ts +++ b/src/legacy/core_plugins/kibana/public/visualize_embeddable/visualize_embeddable.ts @@ -29,7 +29,7 @@ import { getTableAggs } from 'ui/visualize/loader/pipeline_helpers/utilities'; import { AppState } from 'ui/state_management/app_state'; import { npStart } from 'ui/new_platform'; import { IExpressionLoaderParams } from 'src/plugins/expressions/public'; -import { SearchSourceContract } from 'ui/courier'; +import { ISearchSource } from 'ui/courier'; import { VISUALIZE_EMBEDDABLE_TYPE } from './constants'; import { IIndexPattern, @@ -54,7 +54,7 @@ const getKeys = (o: T): Array => Object.keys(o) as Array< export interface VisSavedObject extends SavedObject { vis: Vis; description?: string; - searchSource: SearchSourceContract; + searchSource: ISearchSource; title: string; uiStateJSON?: string; destroy: () => void; diff --git a/src/legacy/core_plugins/visualizations/public/np_ready/public/legacy/build_pipeline.ts b/src/legacy/core_plugins/visualizations/public/np_ready/public/legacy/build_pipeline.ts index 0f9e9c11a9dbc..59c6bddb64521 100644 --- a/src/legacy/core_plugins/visualizations/public/np_ready/public/legacy/build_pipeline.ts +++ b/src/legacy/core_plugins/visualizations/public/np_ready/public/legacy/build_pipeline.ts @@ -28,7 +28,7 @@ import { createFormat, } from '../../../legacy_imports'; // eslint-disable-next-line -import { SearchSourceContract } from '../../../../../../ui/public/courier/search_source/search_source'; +import { ISearchSource } from '../../../../../../ui/public/courier/search_source/search_source'; import { Vis, VisParams, VisState } from '..'; interface SchemaConfigParams { @@ -466,7 +466,7 @@ export const buildVislibDimensions = async ( // take a Vis object and decorate it with the necessary params (dimensions, bucket, metric, etc) export const getVisParams = async ( vis: Vis, - params: { searchSource: SearchSourceContract; timeRange?: any; abortSignal?: AbortSignal } + params: { searchSource: ISearchSource; timeRange?: any; abortSignal?: AbortSignal } ) => { const schemas = getSchemas(vis, params.timeRange); let visConfig = cloneDeep(vis.params); @@ -484,7 +484,7 @@ export const getVisParams = async ( export const buildPipeline = async ( vis: Vis, params: { - searchSource: SearchSourceContract; + searchSource: ISearchSource; timeRange?: any; } ) => { diff --git a/src/legacy/ui/public/agg_types/agg_config.ts b/src/legacy/ui/public/agg_types/agg_config.ts index 9306ffcaff9fd..07e0d46e4eb70 100644 --- a/src/legacy/ui/public/agg_types/agg_config.ts +++ b/src/legacy/ui/public/agg_types/agg_config.ts @@ -27,7 +27,7 @@ import _ from 'lodash'; import { i18n } from '@kbn/i18n'; import { npStart } from 'ui/new_platform'; -import { SearchSourceContract, FetchOptions } from '../courier/types'; +import { ISearchSource, FetchOptions } from '../courier/types'; import { AggType } from './agg_type'; import { AggGroupNames } from '../vis/editors/default/agg_groups'; import { writeParams } from './agg_params'; @@ -236,7 +236,7 @@ export class AggConfig { * @param {Courier.FetchOptions} options * @return {Promise} */ - onSearchRequestStart(searchSource: SearchSourceContract, options?: FetchOptions) { + onSearchRequestStart(searchSource: ISearchSource, options?: FetchOptions) { if (!this.type) { return Promise.resolve(); } diff --git a/src/legacy/ui/public/agg_types/agg_configs.ts b/src/legacy/ui/public/agg_types/agg_configs.ts index b5a7474c99b0e..ece9c90d09b68 100644 --- a/src/legacy/ui/public/agg_types/agg_configs.ts +++ b/src/legacy/ui/public/agg_types/agg_configs.ts @@ -32,7 +32,7 @@ import { Schema } from '../vis/editors/default/schemas'; import { AggConfig, AggConfigOptions } from './agg_config'; import { AggGroupNames } from '../vis/editors/default/agg_groups'; import { IndexPattern } from '../../../core_plugins/data/public'; -import { SearchSourceContract, FetchOptions } from '../courier/types'; +import { ISearchSource, FetchOptions } from '../courier/types'; type Schemas = Record; @@ -306,7 +306,7 @@ export class AggConfigs { return _.find(reqAgg.getResponseAggs(), { id }); } - onSearchRequestStart(searchSource: SearchSourceContract, options?: FetchOptions) { + onSearchRequestStart(searchSource: ISearchSource, options?: FetchOptions) { return Promise.all( // @ts-ignore this.getRequestAggs().map((agg: AggConfig) => agg.onSearchRequestStart(searchSource, options)) diff --git a/src/legacy/ui/public/agg_types/agg_type.ts b/src/legacy/ui/public/agg_types/agg_type.ts index ff4c6875ec6c0..39be1983223bc 100644 --- a/src/legacy/ui/public/agg_types/agg_type.ts +++ b/src/legacy/ui/public/agg_types/agg_type.ts @@ -24,7 +24,7 @@ import { initParams } from './agg_params'; import { AggConfig } from '../vis'; import { AggConfigs } from './agg_configs'; -import { SearchSource } from '../courier'; +import { ISearchSource } from '../courier'; import { Adapters } from '../inspector'; import { BaseParamType } from './param_types/base'; import { AggParamType } from '../agg_types/param_types/agg'; @@ -51,7 +51,7 @@ export interface AggTypeConfig< resp: any, aggConfigs: AggConfigs, aggConfig: TAggConfig, - searchSource: SearchSource, + searchSource: ISearchSource, inspectorAdapters: Adapters, abortSignal?: AbortSignal ) => Promise; @@ -180,7 +180,7 @@ export class AggType< resp: any, aggConfigs: AggConfigs, aggConfig: TAggConfig, - searchSource: SearchSource, + searchSource: ISearchSource, inspectorAdapters: Adapters, abortSignal?: AbortSignal ) => Promise; diff --git a/src/legacy/ui/public/agg_types/buckets/terms.ts b/src/legacy/ui/public/agg_types/buckets/terms.ts index ef9ceb96b005d..c805e53eb2b91 100644 --- a/src/legacy/ui/public/agg_types/buckets/terms.ts +++ b/src/legacy/ui/public/agg_types/buckets/terms.ts @@ -19,7 +19,7 @@ import { noop } from 'lodash'; import { i18n } from '@kbn/i18n'; -import { SearchSource, getRequestInspectorStats, getResponseInspectorStats } from '../../courier'; +import { ISearchSource, getRequestInspectorStats, getResponseInspectorStats } from '../../courier'; import { BucketAggType } from './_bucket_agg_type'; import { BUCKET_TYPES } from './bucket_agg_types'; import { IBucketAggConfig } from './_bucket_agg_type'; @@ -90,7 +90,7 @@ export const termsBucketAgg = new BucketAggType({ resp: any, aggConfigs: AggConfigs, aggConfig: IBucketAggConfig, - searchSource: SearchSource, + searchSource: ISearchSource, inspectorAdapters: Adapters, abortSignal?: AbortSignal ) => { diff --git a/src/legacy/ui/public/agg_types/param_types/base.ts b/src/legacy/ui/public/agg_types/param_types/base.ts index bc8fd30e6324e..f466a9512edf9 100644 --- a/src/legacy/ui/public/agg_types/param_types/base.ts +++ b/src/legacy/ui/public/agg_types/param_types/base.ts @@ -19,7 +19,7 @@ import { AggConfigs } from '../agg_configs'; import { AggConfig } from '../../vis'; -import { SearchSourceContract, FetchOptions } from '../../courier/types'; +import { ISearchSource, FetchOptions } from '../../courier/types'; export class BaseParamType { name: string; @@ -54,7 +54,7 @@ export class BaseParamType { */ modifyAggConfigOnSearchRequestStart: ( aggConfig: TAggConfig, - searchSource?: SearchSourceContract, + searchSource?: ISearchSource, options?: FetchOptions ) => void; diff --git a/src/legacy/ui/public/courier/_index.scss b/src/legacy/ui/public/courier/_index.scss index a5b3911b1d53c..17382cfa30ce5 100644 --- a/src/legacy/ui/public/courier/_index.scss +++ b/src/legacy/ui/public/courier/_index.scss @@ -1 +1 @@ -@import './fetch/components/shard_failure_modal'; \ No newline at end of file +@import '../../../core_plugins/data/public/search/fetch/components/shard_failure_modal'; \ No newline at end of file diff --git a/src/legacy/ui/public/courier/index.ts b/src/legacy/ui/public/courier/index.ts index c8a06ec2a5518..709ff1c11e901 100644 --- a/src/legacy/ui/public/courier/index.ts +++ b/src/legacy/ui/public/courier/index.ts @@ -17,31 +17,46 @@ * under the License. */ -export { SearchSource } from './search_source'; +/** + * Nothing to see here! + * + * Courier / SearchSource has moved to the data plugin, and is being + * re-exported from ui/courier for backwards compatibility. + */ + +import { start as dataStart } from '../../../core_plugins/data/public/legacy'; + +// runtime contracts +export const { defaultSearchStrategy, SearchSource } = dataStart.search; + +// types +export { + ISearchSource, + EsQuerySortValue, // used externally by Discover + FetchOptions, // used externally by AggTypes + SortDirection, // used externally by Discover +} from '../../../core_plugins/data/public'; + +// static code +export { + getRequestInspectorStats, + getResponseInspectorStats, +} from '../../../core_plugins/data/public'; // TODO: Exporting this mock outside of jest tests causes errors because // jest is undefined. Need to refactor the mock to be consistent with // other NP-style mocks. // export { searchSourceMock } from './search_source/mocks'; +// Most these can probably be made internal to the search +// service, so we are temporarily deeply importing them +// until we relocate them to a longer-term home. +/* eslint-disable @kbn/eslint/no-restricted-paths */ export { addSearchStrategy, // used externally by Rollups getSearchErrorType, // used externally by Rollups hasSearchStategyForIndexPattern, // used externally by Discover isDefaultTypeIndexPattern, // used externally by Discover SearchError, // used externally by Visualizations & Rollups -} from './search_strategy'; - -export { - getRequestInspectorStats, - getResponseInspectorStats, -} from './utils/courier_inspector_utils'; - -// types -export { SearchSourceContract } from './search_source'; - -export { - EsQuerySortValue, // used externally by Discover - FetchOptions, // used externally by AggTypes - SortDirection, // used externally by Discover -} from './types'; +} from '../../../core_plugins/data/public/search/search_strategy'; +/* eslint-enable @kbn/eslint/no-restricted-paths */ diff --git a/src/legacy/ui/public/courier/search_source/index.ts b/src/legacy/ui/public/courier/search_source/index.ts index 72170adc2b129..e7ca48a894b3d 100644 --- a/src/legacy/ui/public/courier/search_source/index.ts +++ b/src/legacy/ui/public/courier/search_source/index.ts @@ -17,4 +17,4 @@ * under the License. */ -export * from './search_source'; +export { SearchSource, ISearchSource } from '../index'; diff --git a/src/legacy/ui/public/courier/search_source/mocks.ts b/src/legacy/ui/public/courier/search_source/mocks.ts index 2b83f379b4f09..7b7843d22f519 100644 --- a/src/legacy/ui/public/courier/search_source/mocks.ts +++ b/src/legacy/ui/public/courier/search_source/mocks.ts @@ -36,9 +36,11 @@ * under the License. */ -import { SearchSourceContract } from './search_source'; +// This mock is here for BWC, but will be left behind and replaced by +// the data service mock in the new platform. +import { ISearchSource } from '../index'; -export const searchSourceMock: MockedKeys = { +export const searchSourceMock: MockedKeys = { setPreferredSearchStrategyId: jest.fn(), setFields: jest.fn().mockReturnThis(), setField: jest.fn().mockReturnThis(), diff --git a/src/legacy/ui/public/courier/search_source/search_source.ts b/src/legacy/ui/public/courier/search_source/search_source.ts index e862bb1118a74..e7ca48a894b3d 100644 --- a/src/legacy/ui/public/courier/search_source/search_source.ts +++ b/src/legacy/ui/public/courier/search_source/search_source.ts @@ -17,394 +17,4 @@ * under the License. */ -/** - * @name SearchSource - * - * @description A promise-based stream of search results that can inherit from other search sources. - * - * Because filters/queries in Kibana have different levels of persistence and come from different - * places, it is important to keep track of where filters come from for when they are saved back to - * the savedObject store in the Kibana index. To do this, we create trees of searchSource objects - * that can have associated query parameters (index, query, filter, etc) which can also inherit from - * other searchSource objects. - * - * At query time, all of the searchSource objects that have subscribers are "flattened", at which - * point the query params from the searchSource are collected while traversing up the inheritance - * chain. At each link in the chain a decision about how to merge the query params is made until a - * single set of query parameters is created for each active searchSource (a searchSource with - * subscribers). - * - * That set of query parameters is then sent to elasticsearch. This is how the filter hierarchy - * works in Kibana. - * - * Visualize, starting from a new search: - * - * - the `savedVis.searchSource` is set as the `appSearchSource`. - * - The `savedVis.searchSource` would normally inherit from the `appSearchSource`, but now it is - * upgraded to inherit from the `rootSearchSource`. - * - Any interaction with the visualization will still apply filters to the `appSearchSource`, so - * they will be stored directly on the `savedVis.searchSource`. - * - Any interaction with the time filter will be written to the `rootSearchSource`, so those - * filters will not be saved by the `savedVis`. - * - When the `savedVis` is saved to elasticsearch, it takes with it all the filters that are - * defined on it directly, but none of the ones that it inherits from other places. - * - * Visualize, starting from an existing search: - * - * - The `savedVis` loads the `savedSearch` on which it is built. - * - The `savedVis.searchSource` is set to inherit from the `saveSearch.searchSource` and set as - * the `appSearchSource`. - * - The `savedSearch.searchSource`, is set to inherit from the `rootSearchSource`. - * - Then the `savedVis` is written to elasticsearch it will be flattened and only include the - * filters created in the visualize application and will reconnect the filters from the - * `savedSearch` at runtime to prevent losing the relationship - * - * Dashboard search sources: - * - * - Each panel in a dashboard has a search source. - * - The `savedDashboard` also has a searchsource, and it is set as the `appSearchSource`. - * - Each panel's search source inherits from the `appSearchSource`, meaning that they inherit from - * the dashboard search source. - * - When a filter is added to the search box, or via a visualization, it is written to the - * `appSearchSource`. - */ - -import _ from 'lodash'; -import { npSetup } from 'ui/new_platform'; -import { normalizeSortRequest } from './normalize_sort_request'; -import { fetchSoon } from '../fetch'; -import { fieldWildcardFilter } from '../../field_wildcard'; -import { getHighlightRequest, esFilters, esQuery } from '../../../../../plugins/data/public'; -import chrome from '../../chrome'; -import { RequestFailure } from '../fetch/errors'; -import { filterDocvalueFields } from './filter_docvalue_fields'; -import { SearchSourceOptions, SearchSourceFields, SearchRequest } from './types'; -import { FetchOptions, ApiCaller } from '../fetch/types'; - -const esShardTimeout = npSetup.core.injectedMetadata.getInjectedVar('esShardTimeout') as number; -const config = npSetup.core.uiSettings; - -export type SearchSourceContract = Pick; - -export class SearchSource { - private id: string = _.uniqueId('data_source'); - private searchStrategyId?: string; - private parent?: SearchSource; - private requestStartHandlers: Array< - (searchSource: SearchSourceContract, options?: FetchOptions) => Promise - > = []; - private inheritOptions: SearchSourceOptions = {}; - public history: SearchRequest[] = []; - - constructor(private fields: SearchSourceFields = {}) {} - - /** *** - * PUBLIC API - *****/ - - setPreferredSearchStrategyId(searchStrategyId: string) { - this.searchStrategyId = searchStrategyId; - } - - setFields(newFields: SearchSourceFields) { - this.fields = newFields; - return this; - } - - setField(field: K, value: SearchSourceFields[K]) { - if (value == null) { - delete this.fields[field]; - } else { - this.fields[field] = value; - } - return this; - } - - getId() { - return this.id; - } - - getFields() { - return { ...this.fields }; - } - - /** - * Get fields from the fields - */ - getField(field: K, recurse = true): SearchSourceFields[K] { - if (!recurse || this.fields[field] !== void 0) { - return this.fields[field]; - } - const parent = this.getParent(); - return parent && parent.getField(field); - } - - /** - * Get the field from our own fields, don't traverse up the chain - */ - getOwnField(field: K): SearchSourceFields[K] { - return this.getField(field, false); - } - - create() { - return new SearchSource(); - } - - createCopy() { - const newSearchSource = new SearchSource(); - newSearchSource.setFields({ ...this.fields }); - // when serializing the internal fields we lose the internal classes used in the index - // pattern, so we have to set it again to workaround this behavior - newSearchSource.setField('index', this.getField('index')); - newSearchSource.setParent(this.getParent()); - return newSearchSource; - } - - createChild(options = {}) { - const childSearchSource = new SearchSource(); - childSearchSource.setParent(this, options); - return childSearchSource; - } - - /** - * Set a searchSource that this source should inherit from - * @param {SearchSource} parent - the parent searchSource - * @param {SearchSourceOptions} options - the inherit options - * @return {this} - chainable - */ - setParent(parent?: SearchSourceContract, options: SearchSourceOptions = {}) { - this.parent = parent as SearchSource; - this.inheritOptions = options; - return this; - } - - /** - * Get the parent of this SearchSource - * @return {undefined|searchSource} - */ - getParent() { - return this.parent; - } - - /** - * Fetch this source and reject the returned Promise on error - * - * @async - */ - async fetch(options: FetchOptions = {}) { - const $injector = await chrome.dangerouslyGetActiveInjector(); - const es = $injector.get('es') as ApiCaller; - - await this.requestIsStarting(options); - - const searchRequest = await this.flatten(); - this.history = [searchRequest]; - - const response = await fetchSoon( - searchRequest, - { - ...(this.searchStrategyId && { searchStrategyId: this.searchStrategyId }), - ...options, - }, - { es, config, esShardTimeout } - ); - - if (response.error) { - throw new RequestFailure(null, response); - } - - return response; - } - - /** - * Add a handler that will be notified whenever requests start - * @param {Function} handler - * @return {undefined} - */ - onRequestStart( - handler: (searchSource: SearchSourceContract, options?: FetchOptions) => Promise - ) { - this.requestStartHandlers.push(handler); - } - - async getSearchRequestBody() { - const searchRequest = await this.flatten(); - return searchRequest.body; - } - - /** - * Completely destroy the SearchSource. - * @return {undefined} - */ - destroy() { - this.requestStartHandlers.length = 0; - } - - /** **** - * PRIVATE APIS - ******/ - - /** - * Called by requests of this search source when they are started - * @param {Courier.Request} request - * @param options - * @return {Promise} - */ - private requestIsStarting(options: FetchOptions = {}) { - const handlers = [...this.requestStartHandlers]; - // If callParentStartHandlers has been set to true, we also call all - // handlers of parent search sources. - if (this.inheritOptions.callParentStartHandlers) { - let searchSource = this.getParent(); - while (searchSource) { - handlers.push(...searchSource.requestStartHandlers); - searchSource = searchSource.getParent(); - } - } - - return Promise.all(handlers.map(fn => fn(this, options))); - } - - /** - * Used to merge properties into the data within ._flatten(). - * The data is passed in and modified by the function - * - * @param {object} data - the current merged data - * @param {*} val - the value at `key` - * @param {*} key - The key of `val` - * @return {undefined} - */ - private mergeProp( - data: SearchRequest, - val: SearchSourceFields[K], - key: K - ) { - val = typeof val === 'function' ? val(this) : val; - if (val == null || !key) return; - - const addToRoot = (rootKey: string, value: any) => { - data[rootKey] = value; - }; - - /** - * Add the key and val to the body of the request - */ - const addToBody = (bodyKey: string, value: any) => { - // ignore if we already have a value - if (data.body[bodyKey] == null) { - data.body[bodyKey] = value; - } - }; - - switch (key) { - case 'filter': - return addToRoot('filters', (data.filters || []).concat(val)); - case 'query': - return addToRoot(key, (data[key] || []).concat(val)); - case 'fields': - const fields = _.uniq((data[key] || []).concat(val)); - return addToRoot(key, fields); - case 'index': - case 'type': - case 'highlightAll': - return key && data[key] == null && addToRoot(key, val); - case 'searchAfter': - return addToBody('search_after', val); - case 'source': - return addToBody('_source', val); - case 'sort': - const sort = normalizeSortRequest(val, this.getField('index'), config.get('sort:options')); - return addToBody(key, sort); - default: - return addToBody(key, val); - } - } - - /** - * Walk the inheritance chain of a source and return its - * flat representation (taking into account merging rules) - * @returns {Promise} - * @resolved {Object|null} - the flat data of the SearchSource - */ - private mergeProps(root = this, searchRequest: SearchRequest = { body: {} }) { - Object.entries(this.fields).forEach(([key, value]) => { - this.mergeProp(searchRequest, value, key as keyof SearchSourceFields); - }); - if (this.parent) { - this.parent.mergeProps(root, searchRequest); - } - return searchRequest; - } - - private flatten() { - const searchRequest = this.mergeProps(); - - searchRequest.body = searchRequest.body || {}; - const { body, index, fields, query, filters, highlightAll } = searchRequest; - - const computedFields = index ? index.getComputedFields() : {}; - - body.stored_fields = computedFields.storedFields; - body.script_fields = body.script_fields || {}; - _.extend(body.script_fields, computedFields.scriptFields); - - const defaultDocValueFields = computedFields.docvalueFields - ? computedFields.docvalueFields - : []; - body.docvalue_fields = body.docvalue_fields || defaultDocValueFields; - - if (!body.hasOwnProperty('_source') && index) { - body._source = index.getSourceFiltering(); - } - - if (body._source) { - // exclude source fields for this index pattern specified by the user - const filter = fieldWildcardFilter(body._source.excludes, config.get('metaFields')); - body.docvalue_fields = body.docvalue_fields.filter((docvalueField: any) => - filter(docvalueField.field) - ); - } - - // if we only want to search for certain fields - if (fields) { - // filter out the docvalue_fields, and script_fields to only include those that we are concerned with - body.docvalue_fields = filterDocvalueFields(body.docvalue_fields, fields); - body.script_fields = _.pick(body.script_fields, fields); - - // request the remaining fields from both stored_fields and _source - const remainingFields = _.difference(fields, _.keys(body.script_fields)); - body.stored_fields = remainingFields; - _.set(body, '_source.includes', remainingFields); - } - - const esQueryConfigs = esQuery.getEsQueryConfig(config); - body.query = esQuery.buildEsQuery(index, query, filters, esQueryConfigs); - - if (highlightAll && body.query) { - body.highlight = getHighlightRequest(body.query, config.get('doc_table:highlight')); - delete searchRequest.highlightAll; - } - - const translateToQuery = (filter: esFilters.Filter) => filter && (filter.query || filter); - - // re-write filters within filter aggregations - (function recurse(aggBranch) { - if (!aggBranch) return; - Object.keys(aggBranch).forEach(function(id) { - const agg = aggBranch[id]; - - if (agg.filters) { - // translate filters aggregations - const { filters: aggFilters } = agg.filters; - Object.keys(aggFilters).forEach(filterId => { - aggFilters[filterId] = translateToQuery(aggFilters[filterId]); - }); - } - - recurse(agg.aggs || agg.aggregations); - }); - })(body.aggs || body.aggregations); - - return searchRequest; - } -} +export { SearchSource, ISearchSource } from '../index'; diff --git a/src/legacy/ui/public/courier/search_strategy/default_search_strategy.ts b/src/legacy/ui/public/courier/search_strategy/default_search_strategy.ts index 5be4fef076655..55dee19cae32a 100644 --- a/src/legacy/ui/public/courier/search_strategy/default_search_strategy.ts +++ b/src/legacy/ui/public/courier/search_strategy/default_search_strategy.ts @@ -17,65 +17,8 @@ * under the License. */ -import { SearchStrategyProvider, SearchStrategySearchParams } from './types'; -import { addSearchStrategy } from './search_strategy_registry'; -import { isDefaultTypeIndexPattern } from './is_default_type_index_pattern'; -import { - getSearchParams, - getMSearchParams, - getPreference, - getTimeout, -} from '../fetch/get_search_params'; - -export const defaultSearchStrategy: SearchStrategyProvider = { - id: 'default', - - search: params => { - return params.config.get('courier:batchSearches') ? msearch(params) : search(params); - }, - - isViable: indexPattern => { - return indexPattern && isDefaultTypeIndexPattern(indexPattern); - }, -}; - -function msearch({ searchRequests, es, config, esShardTimeout }: SearchStrategySearchParams) { - const inlineRequests = searchRequests.map(({ index, body, search_type: searchType }) => { - const inlineHeader = { - index: index.title || index, - search_type: searchType, - ignore_unavailable: true, - preference: getPreference(config), - }; - const inlineBody = { - ...body, - timeout: getTimeout(esShardTimeout), - }; - return `${JSON.stringify(inlineHeader)}\n${JSON.stringify(inlineBody)}`; - }); - - const searching = es.msearch({ - ...getMSearchParams(config), - body: `${inlineRequests.join('\n')}\n`, - }); - return { - searching: searching.then(({ responses }) => responses), - abort: searching.abort, - }; -} - -function search({ searchRequests, es, config, esShardTimeout }: SearchStrategySearchParams) { - const abortController = new AbortController(); - const searchParams = getSearchParams(config, esShardTimeout); - const promises = searchRequests.map(({ index, body }) => { - const searching = es.search({ index: index.title || index, body, ...searchParams }); - abortController.signal.addEventListener('abort', searching.abort); - return searching.catch(({ response }) => JSON.parse(response)); - }); - return { - searching: Promise.all(promises), - abort: () => abortController.abort(), - }; -} +import { addSearchStrategy, defaultSearchStrategy } from '../index'; addSearchStrategy(defaultSearchStrategy); + +export { defaultSearchStrategy }; diff --git a/src/legacy/ui/public/courier/search_strategy/index.ts b/src/legacy/ui/public/courier/search_strategy/index.ts index 229d0cbb1da5d..1dce0316596d0 100644 --- a/src/legacy/ui/public/courier/search_strategy/index.ts +++ b/src/legacy/ui/public/courier/search_strategy/index.ts @@ -20,10 +20,6 @@ export { addSearchStrategy, hasSearchStategyForIndexPattern, - getSearchStrategyById, - getSearchStrategyForSearchRequest, -} from './search_strategy_registry'; - -export { isDefaultTypeIndexPattern } from './is_default_type_index_pattern'; - -export { SearchError, getSearchErrorType } from './search_error'; + isDefaultTypeIndexPattern, + SearchError, +} from '../index'; diff --git a/src/legacy/ui/public/courier/search_strategy/search_error.ts b/src/legacy/ui/public/courier/search_strategy/search_error.ts index d4042fb17499c..a815ac4ff008f 100644 --- a/src/legacy/ui/public/courier/search_strategy/search_error.ts +++ b/src/legacy/ui/public/courier/search_strategy/search_error.ts @@ -17,46 +17,4 @@ * under the License. */ -interface SearchErrorOptions { - status: string; - title: string; - message: string; - path: string; - type: string; -} - -export class SearchError extends Error { - public name: string; - public status: string; - public title: string; - public message: string; - public path: string; - public type: string; - - constructor({ status, title, message, path, type }: SearchErrorOptions) { - super(message); - this.name = 'SearchError'; - this.status = status; - this.title = title; - this.message = message; - this.path = path; - this.type = type; - - // captureStackTrace is only available in the V8 engine, so any browser using - // a different JS engine won't have access to this method. - if (Error.captureStackTrace) { - Error.captureStackTrace(this, SearchError); - } - - // Babel doesn't support traditional `extends` syntax for built-in classes. - // https://babeljs.io/docs/en/caveats/#classes - Object.setPrototypeOf(this, SearchError.prototype); - } -} - -export function getSearchErrorType({ message }: Pick) { - const msg = message.toLowerCase(); - if (msg.indexOf('unsupported query') > -1) { - return 'UNSUPPORTED_QUERY'; - } -} +export { SearchError } from '../index'; diff --git a/src/legacy/ui/public/courier/types.ts b/src/legacy/ui/public/courier/types.ts index 23d74ce6a57da..75035ceef321f 100644 --- a/src/legacy/ui/public/courier/types.ts +++ b/src/legacy/ui/public/courier/types.ts @@ -17,7 +17,9 @@ * under the License. */ -export * from './fetch/types'; -export * from './search_source/types'; -export * from './search_strategy/types'; -export * from './utils/types'; +export { + ISearchSource, + EsQuerySortValue, // used externally by Discover + FetchOptions, // used externally by AggTypes + SortDirection, // used externally by Discover +} from './index'; diff --git a/src/legacy/ui/public/saved_objects/types.ts b/src/legacy/ui/public/saved_objects/types.ts index c4e6438424046..2578c2015e819 100644 --- a/src/legacy/ui/public/saved_objects/types.ts +++ b/src/legacy/ui/public/saved_objects/types.ts @@ -16,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ + import { ChromeStart, OverlayStart, @@ -23,7 +24,7 @@ import { SavedObjectAttributes, SavedObjectReference, } from 'kibana/public'; -import { SearchSource, SearchSourceContract } from 'ui/courier'; +import { ISearchSource } from 'ui/courier'; import { IIndexPattern, IndexPatternsContract } from '../../../../plugins/data/public'; export interface SavedObject { @@ -46,7 +47,7 @@ export interface SavedObject { lastSavedTitle: string; migrationVersion?: Record; save: (saveOptions: SavedObjectSaveOpts) => Promise; - searchSource?: SearchSourceContract; + searchSource?: ISearchSource; showInRecentlyAccessed: boolean; title: string; } @@ -88,7 +89,7 @@ export interface SavedObjectConfig { mapping?: any; migrationVersion?: Record; path?: string; - searchSource?: SearchSource | boolean; + searchSource?: ISearchSource | boolean; type?: string; } diff --git a/src/legacy/ui/public/visualize/loader/utils/query_geohash_bounds.ts b/src/legacy/ui/public/visualize/loader/utils/query_geohash_bounds.ts index a9203415321fa..5054c34118f78 100644 --- a/src/legacy/ui/public/visualize/loader/utils/query_geohash_bounds.ts +++ b/src/legacy/ui/public/visualize/loader/utils/query_geohash_bounds.ts @@ -24,13 +24,13 @@ import { toastNotifications } from 'ui/notify'; import { AggConfig } from 'ui/vis'; import { timefilter } from 'ui/timefilter'; import { Vis } from '../../../vis'; -import { SearchSource, SearchSourceContract } from '../../../courier'; +import { SearchSource, ISearchSource } from '../../../courier'; import { esFilters, Query } from '../../../../../../plugins/data/public'; interface QueryGeohashBoundsParams { filters?: esFilters.Filter[]; query?: Query; - searchSource?: SearchSourceContract; + searchSource?: ISearchSource; } /** diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/merge_tables.test.ts b/x-pack/legacy/plugins/lens/public/editor_frame_plugin/merge_tables.test.ts index 8f124c25542c7..ffb8be1deaa9e 100644 --- a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/merge_tables.test.ts +++ b/x-pack/legacy/plugins/lens/public/editor_frame_plugin/merge_tables.test.ts @@ -8,6 +8,8 @@ import moment from 'moment'; import { mergeTables } from './merge_tables'; import { KibanaDatatable } from 'src/plugins/expressions/public'; +jest.mock('ui/new_platform'); + describe('lens_merge_tables', () => { it('should produce a row with the nested table as defined', () => { const sampleTable1: KibanaDatatable = { diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/date_histogram.test.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/date_histogram.test.tsx index ea9fa516d4d91..2bd6c7106a952 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/date_histogram.test.tsx +++ b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/date_histogram.test.tsx @@ -14,19 +14,35 @@ import { IStorageWrapper } from 'src/plugins/kibana_utils/public'; import { createMockedIndexPattern } from '../../mocks'; import { IndexPatternPrivateState } from '../../types'; -jest.mock('ui/new_platform', () => ({ - npStart: { - core: { - uiSettings: { - get: (path: string) => { - if (path === 'histogram:maxBars') { - return 10; - } +jest.mock('ui/new_platform', () => { + // Due to the way we are handling shims in the NP migration, we need + // to mock core here so that upstream services don't cause these + // tests to fail. Ordinarly `jest.mock('ui/new_platform')` would be + // sufficient, however we need to mock one of the `uiSettings` return + // values for this suite, so we must manually assemble the mock. + // Because babel hoists `jest` we must use an inline `require` + // to ensure the core mocks are available (`jest.doMock` doesn't + // work in this case). This mock should be able to be replaced + // altogether once Lens has migrated to the new platform. + const { coreMock } = require('src/core/public/mocks'); // eslint-disable-line @typescript-eslint/no-var-requires + return { + npSetup: { + core: coreMock.createSetup(), + }, + npStart: { + core: { + ...coreMock.createStart(), + uiSettings: { + get: (path: string) => { + if (path === 'histogram:maxBars') { + return 10; + } + }, }, }, }, - }, -})); + }; +}); const defaultOptions = { storage: {} as IStorageWrapper, diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index b7bac7dd170ed..c79969154d05c 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -261,24 +261,6 @@ "common.ui.aggTypes.timeInterval.scaledHelpText": "現在 {bucketDescription} にスケーリングされています", "common.ui.aggTypes.timeInterval.selectIntervalPlaceholder": "間隔を選択", "common.ui.aggTypes.timeInterval.selectOptionHelpText": "オプションを選択するかカスタム値を作成します。例30s、20m、24h、2d、1w、1M", - "common.ui.courier.fetch.requestTimedOutNotificationMessage": "リクエストがタイムアウトしたため、データが不完全な可能性があります", - "common.ui.courier.fetch.shardsFailedNotificationMessage": "{shardsTotal} 件中 {shardsFailed} 件のシャードでエラーが発生しました", - "common.ui.courier.hitsDescription": "クエリにより返されたドキュメントの数です。", - "common.ui.courier.hitsLabel": "ヒット数", - "common.ui.courier.hitsTotalDescription": "クエリに一致するドキュメントの数です。", - "common.ui.courier.hitsTotalLabel": "ヒット数 (合計)", - "common.ui.courier.indexPatternDescription": "Elasticsearch インデックスに接続したインデックスパターンです。", - "common.ui.courier.indexPatternIdDescription": "{kibanaIndexPattern} インデックス内の ID です。", - "common.ui.courier.indexPatternIdLabel": "インデックスパターン ID", - "common.ui.courier.indexPatternLabel": "インデックスパターン", - "common.ui.courier.noSearchStrategyRegisteredErrorMessageDescription": "検索リクエストの検索方法が見つかりませんでした", - "common.ui.courier.noSearchStrategyRegisteredErrorMessageTitle": "検索方法が登録されていません", - "common.ui.courier.queryTimeDescription": "クエリの処理の所要時間です。リクエストの送信やブラウザでのパースの時間は含まれません。", - "common.ui.courier.queryTimeLabel": "クエリ時間", - "common.ui.courier.queryTimeValue": "{queryTime}ms", - "common.ui.courier.requestTimeDescription": "ブラウザから Elasticsearch にリクエストが送信され返されるまでの所要時間です。リクエストがキューで待機していた時間は含まれません。", - "common.ui.courier.requestTimeLabel": "リクエスト時間", - "common.ui.courier.requestTimeValue": "{requestTime}ms", "common.ui.directives.fieldNameIcons.booleanAriaLabel": "ブールフィールド", "common.ui.directives.fieldNameIcons.conflictFieldAriaLabel": "矛盾フィールド", "common.ui.directives.fieldNameIcons.dateFieldAriaLabel": "日付フィールド", @@ -541,20 +523,6 @@ "common.ui.visualize.queryGeohashBounds.unableToGetBoundErrorTitle": "バウンドを取得できませんでした", "common.ui.welcomeErrorMessage": "Kibana が正常に読み込まれませんでした。詳細はサーバーアウトプットを確認してください。", "common.ui.welcomeMessage": "Kibana を読み込み中", - "common.ui.courier.fetch.shardsFailedModal.close": "閉じる", - "common.ui.courier.fetch.shardsFailedModal.copyToClipboard": "応答をクリップボードにコピー", - "common.ui.courier.fetch.shardsFailedModal.failureHeader": "{failureName} で {failureDetails}", - "common.ui.courier.fetch.shardsFailedModal.showDetails": "詳細を表示", - "common.ui.courier.fetch.shardsFailedModal.tabHeaderRequest": "リクエスト", - "common.ui.courier.fetch.shardsFailedModal.tabHeaderResponse": "応答", - "common.ui.courier.fetch.shardsFailedModal.tabHeaderShardFailures": "シャードエラー", - "common.ui.courier.fetch.shardsFailedModal.tableColIndex": "インデックス", - "common.ui.courier.fetch.shardsFailedModal.tableColNode": "ノード", - "common.ui.courier.fetch.shardsFailedModal.tableColReason": "理由", - "common.ui.courier.fetch.shardsFailedModal.tableColShard": "シャード", - "common.ui.courier.fetch.shardsFailedModal.tableRowCollapse": "{rowDescription} を折りたたむ", - "common.ui.courier.fetch.shardsFailedModal.tableRowExpand": "{rowDescription} を展開する", - "common.ui.courier.fetch.shardsFailedNotificationDescription": "表示されているデータは不完全か誤りの可能性があります。", "common.ui.directives.fieldNameIcons.geoShapeFieldAriaLabel": "地理情報図形", "common.ui.vis.editors.agg.errorsAriaLabel": "集約にエラーがあります", "common.ui.vislib.heatmap.maxBucketsText": "定義された数列が多すぎます ({nr}).構成されている最高値は {max} です。", @@ -873,6 +841,38 @@ "data.search.searchBar.savedQueryPopoverSavedQueryListItemDescriptionAriaLabel": "{savedQueryName} の説明", "data.search.searchBar.savedQueryPopoverSavedQueryListItemSelectedButtonAriaLabel": "選択されたクエリボタン {savedQueryName} を保存しました。変更を破棄するには押してください。", "data.search.searchBar.savedQueryPopoverTitleText": "保存されたクエリ", + "data.search.searchSource.fetch.shardsFailedModal.close": "閉じる", + "data.search.searchSource.fetch.shardsFailedModal.copyToClipboard": "応答をクリップボードにコピー", + "data.search.searchSource.fetch.shardsFailedModal.failureHeader": "{failureName} で {failureDetails}", + "data.search.searchSource.fetch.shardsFailedModal.showDetails": "詳細を表示", + "data.search.searchSource.fetch.shardsFailedModal.tabHeaderRequest": "リクエスト", + "data.search.searchSource.fetch.shardsFailedModal.tabHeaderResponse": "応答", + "data.search.searchSource.fetch.shardsFailedModal.tabHeaderShardFailures": "シャードエラー", + "data.search.searchSource.fetch.shardsFailedModal.tableColIndex": "インデックス", + "data.search.searchSource.fetch.shardsFailedModal.tableColNode": "ノード", + "data.search.searchSource.fetch.shardsFailedModal.tableColReason": "理由", + "data.search.searchSource.fetch.shardsFailedModal.tableColShard": "シャード", + "data.search.searchSource.fetch.shardsFailedModal.tableRowCollapse": "{rowDescription} を折りたたむ", + "data.search.searchSource.fetch.shardsFailedModal.tableRowExpand": "{rowDescription} を展開する", + "data.search.searchSource.fetch.shardsFailedNotificationDescription": "表示されているデータは不完全か誤りの可能性があります。", + "data.search.searchSource.fetch.requestTimedOutNotificationMessage": "リクエストがタイムアウトしたため、データが不完全な可能性があります", + "data.search.searchSource.fetch.shardsFailedNotificationMessage": "{shardsTotal} 件中 {shardsFailed} 件のシャードでエラーが発生しました", + "data.search.searchSource.hitsDescription": "クエリにより返されたドキュメントの数です。", + "data.search.searchSource.hitsLabel": "ヒット数", + "data.search.searchSource.hitsTotalDescription": "クエリに一致するドキュメントの数です。", + "data.search.searchSource.hitsTotalLabel": "ヒット数 (合計)", + "data.search.searchSource.indexPatternDescription": "Elasticsearch インデックスに接続したインデックスパターンです。", + "data.search.searchSource.indexPatternIdDescription": "{kibanaIndexPattern} インデックス内の ID です。", + "data.search.searchSource.indexPatternIdLabel": "インデックスパターン ID", + "data.search.searchSource.indexPatternLabel": "インデックスパターン", + "data.search.searchSource.noSearchStrategyRegisteredErrorMessageDescription": "検索リクエストの検索方法が見つかりませんでした", + "data.search.searchSource.noSearchStrategyRegisteredErrorMessageTitle": "検索方法が登録されていません", + "data.search.searchSource.queryTimeDescription": "クエリの処理の所要時間です。リクエストの送信やブラウザでのパースの時間は含まれません。", + "data.search.searchSource.queryTimeLabel": "クエリ時間", + "data.search.searchSource.queryTimeValue": "{queryTime}ms", + "data.search.searchSource.requestTimeDescription": "ブラウザから Elasticsearch にリクエストが送信され返されるまでの所要時間です。リクエストがキューで待機していた時間は含まれません。", + "data.search.searchSource.requestTimeLabel": "リクエスト時間", + "data.search.searchSource.requestTimeValue": "{requestTime}ms", "data.filter.filterEditor.operatorSelectPlaceholderSelect": "選択してください", "data.filter.filterEditor.operatorSelectPlaceholderWaiting": "待機中", "data.filter.filterEditor.rangeInputLabel": "範囲", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index 7ade936ba1044..34559ba9f95be 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -261,24 +261,6 @@ "common.ui.aggTypes.timeInterval.scaledHelpText": "当前缩放至 {bucketDescription}", "common.ui.aggTypes.timeInterval.selectIntervalPlaceholder": "选择时间间隔", "common.ui.aggTypes.timeInterval.selectOptionHelpText": "选择选项或创建定制值示例:30s、20m、24h、2d、1w、1M", - "common.ui.courier.fetch.requestTimedOutNotificationMessage": "由于您的请求超时,因此数据可能不完整", - "common.ui.courier.fetch.shardsFailedNotificationMessage": "{shardsTotal} 个分片有 {shardsFailed} 个失败", - "common.ui.courier.hitsDescription": "查询返回的文档数目。", - "common.ui.courier.hitsLabel": "命中", - "common.ui.courier.hitsTotalDescription": "匹配查询的文档数目。", - "common.ui.courier.hitsTotalLabel": "命中(总计)", - "common.ui.courier.indexPatternDescription": "连接到 Elasticsearch 索引的索引模式。", - "common.ui.courier.indexPatternIdDescription": "{kibanaIndexPattern} 索引中的 ID。", - "common.ui.courier.indexPatternIdLabel": "索引模式 ID", - "common.ui.courier.indexPatternLabel": "索引模式", - "common.ui.courier.noSearchStrategyRegisteredErrorMessageDescription": "无法为该搜索请求找到搜索策略", - "common.ui.courier.noSearchStrategyRegisteredErrorMessageTitle": "未注册任何搜索策略", - "common.ui.courier.queryTimeDescription": "处理查询所花费的时间。不包括发送请求或在浏览器中解析它的时间。", - "common.ui.courier.queryTimeLabel": "查询时间", - "common.ui.courier.queryTimeValue": "{queryTime}ms", - "common.ui.courier.requestTimeDescription": "请求从浏览器到 Elasticsearch 以及返回的时间。不包括请求在队列中等候的时间。", - "common.ui.courier.requestTimeLabel": "请求时间", - "common.ui.courier.requestTimeValue": "{requestTime}ms", "common.ui.directives.fieldNameIcons.booleanAriaLabel": "布尔字段", "common.ui.directives.fieldNameIcons.conflictFieldAriaLabel": "冲突字段", "common.ui.directives.fieldNameIcons.dateFieldAriaLabel": "日期字段", @@ -542,20 +524,6 @@ "common.ui.visualize.queryGeohashBounds.unableToGetBoundErrorTitle": "无法获取边界", "common.ui.welcomeErrorMessage": "Kibana 未正确加载。检查服务器输出以了解详情。", "common.ui.welcomeMessage": "正在加载 Kibana", - "common.ui.courier.fetch.shardsFailedModal.close": "关闭", - "common.ui.courier.fetch.shardsFailedModal.copyToClipboard": "将响应复制到剪贴板", - "common.ui.courier.fetch.shardsFailedModal.failureHeader": "{failureDetails} 时为 {failureName}", - "common.ui.courier.fetch.shardsFailedModal.showDetails": "显示详情", - "common.ui.courier.fetch.shardsFailedModal.tabHeaderRequest": "请求", - "common.ui.courier.fetch.shardsFailedModal.tabHeaderResponse": "响应", - "common.ui.courier.fetch.shardsFailedModal.tabHeaderShardFailures": "分片错误", - "common.ui.courier.fetch.shardsFailedModal.tableColIndex": "索引", - "common.ui.courier.fetch.shardsFailedModal.tableColNode": "节点", - "common.ui.courier.fetch.shardsFailedModal.tableColReason": "原因", - "common.ui.courier.fetch.shardsFailedModal.tableColShard": "分片", - "common.ui.courier.fetch.shardsFailedModal.tableRowCollapse": "折叠 {rowDescription}", - "common.ui.courier.fetch.shardsFailedModal.tableRowExpand": "展开 {rowDescription}", - "common.ui.courier.fetch.shardsFailedNotificationDescription": "您正在查看的数据可能不完整或有错误。", "common.ui.directives.fieldNameIcons.geoShapeFieldAriaLabel": "几何形状字段", "common.ui.vis.editors.agg.errorsAriaLabel": "聚合有错误", "common.ui.vislib.heatmap.maxBucketsText": "定义了过多的序列 ({nr})。配置的最大值为 {max}。", @@ -874,6 +842,38 @@ "data.search.searchBar.savedQueryPopoverSavedQueryListItemDescriptionAriaLabel": "{savedQueryName} 描述", "data.search.searchBar.savedQueryPopoverSavedQueryListItemSelectedButtonAriaLabel": "已保存查询按钮已选择 {savedQueryName}。按下可清除任何更改。", "data.search.searchBar.savedQueryPopoverTitleText": "已保存查询", + "data.search.searchSource.fetch.shardsFailedModal.close": "关闭", + "data.search.searchSource.fetch.shardsFailedModal.copyToClipboard": "将响应复制到剪贴板", + "data.search.searchSource.fetch.shardsFailedModal.failureHeader": "{failureDetails} 时为 {failureName}", + "data.search.searchSource.fetch.shardsFailedModal.showDetails": "显示详情", + "data.search.searchSource.fetch.shardsFailedModal.tabHeaderRequest": "请求", + "data.search.searchSource.fetch.shardsFailedModal.tabHeaderResponse": "响应", + "data.search.searchSource.fetch.shardsFailedModal.tabHeaderShardFailures": "分片错误", + "data.search.searchSource.fetch.shardsFailedModal.tableColIndex": "索引", + "data.search.searchSource.fetch.shardsFailedModal.tableColNode": "节点", + "data.search.searchSource.fetch.shardsFailedModal.tableColReason": "原因", + "data.search.searchSource.fetch.shardsFailedModal.tableColShard": "分片", + "data.search.searchSource.fetch.shardsFailedModal.tableRowCollapse": "折叠 {rowDescription}", + "data.search.searchSource.fetch.shardsFailedModal.tableRowExpand": "展开 {rowDescription}", + "data.search.searchSource.fetch.shardsFailedNotificationDescription": "您正在查看的数据可能不完整或有错误。", + "data.search.searchSource.fetch.requestTimedOutNotificationMessage": "由于您的请求超时,因此数据可能不完整", + "data.search.searchSource.fetch.shardsFailedNotificationMessage": "{shardsTotal} 个分片有 {shardsFailed} 个失败", + "data.search.searchSource.hitsDescription": "查询返回的文档数目。", + "data.search.searchSource.hitsLabel": "命中", + "data.search.searchSource.hitsTotalDescription": "匹配查询的文档数目。", + "data.search.searchSource.hitsTotalLabel": "命中(总计)", + "data.search.searchSource.indexPatternDescription": "连接到 Elasticsearch 索引的索引模式。", + "data.search.searchSource.indexPatternIdDescription": "{kibanaIndexPattern} 索引中的 ID。", + "data.search.searchSource.indexPatternIdLabel": "索引模式 ID", + "data.search.searchSource.indexPatternLabel": "索引模式", + "data.search.searchSource.noSearchStrategyRegisteredErrorMessageDescription": "无法为该搜索请求找到搜索策略", + "data.search.searchSource.noSearchStrategyRegisteredErrorMessageTitle": "未注册任何搜索策略", + "data.search.searchSource.queryTimeDescription": "处理查询所花费的时间。不包括发送请求或在浏览器中解析它的时间。", + "data.search.searchSource.queryTimeLabel": "查询时间", + "data.search.searchSource.queryTimeValue": "{queryTime}ms", + "data.search.searchSource.requestTimeDescription": "请求从浏览器到 Elasticsearch 以及返回的时间。不包括请求在队列中等候的时间。", + "data.search.searchSource.requestTimeLabel": "请求时间", + "data.search.searchSource.requestTimeValue": "{requestTime}ms", "data.filter.filterEditor.operatorSelectPlaceholderSelect": "选择", "data.filter.filterEditor.operatorSelectPlaceholderWaiting": "正在等候", "data.filter.filterEditor.rangeInputLabel": "范围", From b921987f1a8a3eab718616da4acefeb7d41942e8 Mon Sep 17 00:00:00 2001 From: Matthias Wilhelm Date: Sat, 21 Dec 2019 10:38:03 +0100 Subject: [PATCH 14/14] Remove SavedObjectRegistryProvider from codebase (#53455) --- .../kibana-plugin-server.basepath.get.md | 26 ++-- .../kibana-plugin-server.basepath.set.md | 26 ++-- ...lugin-server.irouter.handlelegacyerrors.md | 26 ++-- ...bana-plugin-server.routeconfig.validate.md | 124 +++++++++--------- ...rver.routevalidationerror._constructor_.md | 42 +++--- ...routevalidationresultfactory.badrequest.md | 26 ++-- ...-server.routevalidationresultfactory.ok.md | 26 ++-- ...gin-server.routevalidatoroptions.unsafe.md | 35 ++--- .../kibana/public/dashboard/index.ts | 16 +-- .../kibana/public/dashboard/legacy_imports.ts | 2 +- .../public/dashboard/np_ready/application.ts | 4 +- .../public/dashboard/np_ready/legacy_app.js | 7 +- .../kibana/public/dashboard/plugin.ts | 11 +- .../saved_dashboard_register.ts | 29 +++- .../saved_dashboard/saved_dashboards.ts | 33 +---- .../kibana/public/discover/index.ts | 5 - .../saved_searches/saved_searches_register.ts | 18 +-- .../kibana/public/visualize/index.ts | 6 +- .../public/visualize/kibana_services.ts | 1 - .../kibana/public/visualize/legacy_imports.ts | 1 - .../np_ready/listing/visualize_listing.js | 8 +- .../kibana/public/visualize/plugin.ts | 11 +- .../saved_visualization_register.ts | 19 ++- .../saved_visualizations.ts | 21 +-- .../core_plugins/timelion/public/app.js | 14 +- .../directives}/saved_object_finder.html | 16 +-- .../public/directives/saved_object_finder.js | 17 +-- .../public/services/saved_sheet_register.ts | 5 - .../timelion/public/services/saved_sheets.ts | 47 ++++--- src/legacy/ui/public/saved_objects/index.ts | 1 - .../saved_objects/saved_object_registry.ts | 26 ---- .../translations/translations/ja-JP.json | 16 +-- .../translations/translations/zh-CN.json | 16 +-- 33 files changed, 316 insertions(+), 365 deletions(-) rename src/legacy/{ui/public/directives/partials => core_plugins/timelion/public/directives}/saved_object_finder.html (86%) rename src/legacy/{ui => core_plugins/timelion}/public/directives/saved_object_finder.js (95%) delete mode 100644 src/legacy/ui/public/saved_objects/saved_object_registry.ts diff --git a/docs/development/core/server/kibana-plugin-server.basepath.get.md b/docs/development/core/server/kibana-plugin-server.basepath.get.md index 6ef7022f10e62..3f7895dd72799 100644 --- a/docs/development/core/server/kibana-plugin-server.basepath.get.md +++ b/docs/development/core/server/kibana-plugin-server.basepath.get.md @@ -1,13 +1,13 @@ - - -[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [BasePath](./kibana-plugin-server.basepath.md) > [get](./kibana-plugin-server.basepath.get.md) - -## BasePath.get property - -returns `basePath` value, specific for an incoming request. - -Signature: - -```typescript -get: (request: KibanaRequest | LegacyRequest) => string; -``` + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [BasePath](./kibana-plugin-server.basepath.md) > [get](./kibana-plugin-server.basepath.get.md) + +## BasePath.get property + +returns `basePath` value, specific for an incoming request. + +Signature: + +```typescript +(request: KibanaRequest | LegacyRequest) => string; +``` diff --git a/docs/development/core/server/kibana-plugin-server.basepath.set.md b/docs/development/core/server/kibana-plugin-server.basepath.set.md index 56a7f644d34cc..633765389e649 100644 --- a/docs/development/core/server/kibana-plugin-server.basepath.set.md +++ b/docs/development/core/server/kibana-plugin-server.basepath.set.md @@ -1,13 +1,13 @@ - - -[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [BasePath](./kibana-plugin-server.basepath.md) > [set](./kibana-plugin-server.basepath.set.md) - -## BasePath.set property - -sets `basePath` value, specific for an incoming request. - -Signature: - -```typescript -set: (request: KibanaRequest | LegacyRequest, requestSpecificBasePath: string) => void; -``` + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [BasePath](./kibana-plugin-server.basepath.md) > [set](./kibana-plugin-server.basepath.set.md) + +## BasePath.set property + +sets `basePath` value, specific for an incoming request. + +Signature: + +```typescript +(request: KibanaRequest | LegacyRequest, requestSpecificBasePath: string) => void; +``` diff --git a/docs/development/core/server/kibana-plugin-server.irouter.handlelegacyerrors.md b/docs/development/core/server/kibana-plugin-server.irouter.handlelegacyerrors.md index ff71f13466cf8..238424b1df1d5 100644 --- a/docs/development/core/server/kibana-plugin-server.irouter.handlelegacyerrors.md +++ b/docs/development/core/server/kibana-plugin-server.irouter.handlelegacyerrors.md @@ -1,13 +1,13 @@ - - -[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [IRouter](./kibana-plugin-server.irouter.md) > [handleLegacyErrors](./kibana-plugin-server.irouter.handlelegacyerrors.md) - -## IRouter.handleLegacyErrors property - -Wrap a router handler to catch and converts legacy boom errors to proper custom errors. - -Signature: - -```typescript -handleLegacyErrors: (handler: RequestHandler) => RequestHandler; -``` + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [IRouter](./kibana-plugin-server.irouter.md) > [handleLegacyErrors](./kibana-plugin-server.irouter.handlelegacyerrors.md) + +## IRouter.handleLegacyErrors property + +Wrap a router handler to catch and converts legacy boom errors to proper custom errors. + +Signature: + +```typescript +(handler: RequestHandler) => RequestHandler; +``` diff --git a/docs/development/core/server/kibana-plugin-server.routeconfig.validate.md b/docs/development/core/server/kibana-plugin-server.routeconfig.validate.md index 23a72fc3c68b3..4fbcf0981f114 100644 --- a/docs/development/core/server/kibana-plugin-server.routeconfig.validate.md +++ b/docs/development/core/server/kibana-plugin-server.routeconfig.validate.md @@ -1,62 +1,62 @@ - - -[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [RouteConfig](./kibana-plugin-server.routeconfig.md) > [validate](./kibana-plugin-server.routeconfig.validate.md) - -## RouteConfig.validate property - -A schema created with `@kbn/config-schema` that every request will be validated against. - -Signature: - -```typescript -validate: RouteValidatorFullConfig | false; -``` - -## Remarks - -You \*must\* specify a validation schema to be able to read: - url path segments - request query - request body To opt out of validating the request, specify `validate: false`. In this case request params, query, and body will be \*\*empty\*\* objects and have no access to raw values. In some cases you may want to use another validation library. To do this, you need to instruct the `@kbn/config-schema` library to output \*\*non-validated values\*\* with setting schema as `schema.object({}, { allowUnknowns: true })`; - -## Example - - -```ts - import { schema } from '@kbn/config-schema'; - router.get({ - path: 'path/{id}', - validate: { - params: schema.object({ - id: schema.string(), - }), - query: schema.object({...}), - body: schema.object({...}), - }, -}, -(context, req, res,) { - req.params; // type Readonly<{id: string}> - console.log(req.params.id); // value -}); - -router.get({ - path: 'path/{id}', - validate: false, // handler has no access to params, query, body values. -}, -(context, req, res,) { - req.params; // type Readonly<{}>; - console.log(req.params.id); // undefined -}); - -router.get({ - path: 'path/{id}', - validate: { - // handler has access to raw non-validated params in runtime - params: schema.object({}, { allowUnknowns: true }) - }, -}, -(context, req, res,) { - req.params; // type Readonly<{}>; - console.log(req.params.id); // value - myValidationLibrary.validate({ params: req.params }); -}); - -``` - + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [RouteConfig](./kibana-plugin-server.routeconfig.md) > [validate](./kibana-plugin-server.routeconfig.validate.md) + +## RouteConfig.validate property + +A schema created with `@kbn/config-schema` that every request will be validated against. + +Signature: + +```typescript +RouteValidatorFullConfig | false; +``` + +## Remarks + +You \*must\* specify a validation schema to be able to read: - url path segments - request query - request body To opt out of validating the request, specify `validate: false`. In this case request params, query, and body will be \*\*empty\*\* objects and have no access to raw values. In some cases you may want to use another validation library. To do this, you need to instruct the `@kbn/config-schema` library to output \*\*non-validated values\*\* with setting schema as `schema.object({}, { allowUnknowns: true })`; + +## Example + + +```ts + import { schema } from '@kbn/config-schema'; + router.get({ + path: 'path/{id}', + validate: { + params: schema.object({ + id: schema.string(), + }), + query: schema.object({...}), + body: schema.object({...}), + }, +}, +(context, req, res,) { + req.params; // type Readonly<{id: string}> + console.log(req.params.id); // value +}); + +router.get({ + path: 'path/{id}', + validate: false, // handler has no access to params, query, body values. +}, +(context, req, res,) { + req.params; // type Readonly<{}>; + console.log(req.params.id); // undefined +}); + +router.get({ + path: 'path/{id}', + validate: { + // handler has access to raw non-validated params in runtime + params: schema.object({}, { allowUnknowns: true }) + }, +}, +(context, req, res,) { + req.params; // type Readonly<{}>; + console.log(req.params.id); // value + myValidationLibrary.validate({ params: req.params }); +}); + +``` + diff --git a/docs/development/core/server/kibana-plugin-server.routevalidationerror._constructor_.md b/docs/development/core/server/kibana-plugin-server.routevalidationerror._constructor_.md index 551e13faaf154..31dc6ceb91995 100644 --- a/docs/development/core/server/kibana-plugin-server.routevalidationerror._constructor_.md +++ b/docs/development/core/server/kibana-plugin-server.routevalidationerror._constructor_.md @@ -1,21 +1,21 @@ - - -[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [RouteValidationError](./kibana-plugin-server.routevalidationerror.md) > [(constructor)](./kibana-plugin-server.routevalidationerror._constructor_.md) - -## RouteValidationError.(constructor) - -Constructs a new instance of the `RouteValidationError` class - -Signature: - -```typescript -constructor(error: Error | string, path?: string[]); -``` - -## Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| error | Error | string | | -| path | string[] | | - + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [RouteValidationError](./kibana-plugin-server.routevalidationerror.md) > [(constructor)](./kibana-plugin-server.routevalidationerror._constructor_.md) + +## RouteValidationError.(constructor) + +Constructs a new instance of the `RouteValidationError` class + +Signature: + +```typescript +constructor(error;: Error | string, path?: string[];) +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| error | Error | string | | +| path | string[] | | + diff --git a/docs/development/core/server/kibana-plugin-server.routevalidationresultfactory.badrequest.md b/docs/development/core/server/kibana-plugin-server.routevalidationresultfactory.badrequest.md index 36ea6103fb352..2462ae17943be 100644 --- a/docs/development/core/server/kibana-plugin-server.routevalidationresultfactory.badrequest.md +++ b/docs/development/core/server/kibana-plugin-server.routevalidationresultfactory.badrequest.md @@ -1,13 +1,13 @@ - - -[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [RouteValidationResultFactory](./kibana-plugin-server.routevalidationresultfactory.md) > [badRequest](./kibana-plugin-server.routevalidationresultfactory.badrequest.md) - -## RouteValidationResultFactory.badRequest property - -Signature: - -```typescript -badRequest: (error: Error | string, path?: string[]) => { - error: RouteValidationError; - }; -``` + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [RouteValidationResultFactory](./kibana-plugin-server.routevalidationresultfactory.md) > [badRequest](./kibana-plugin-server.routevalidationresultfactory.badrequest.md) + +## RouteValidationResultFactory.badRequest property + +Signature: + +```typescript +(error: Error | string, path?: string[]) => { + RouteValidationError; + }; +``` diff --git a/docs/development/core/server/kibana-plugin-server.routevalidationresultfactory.ok.md b/docs/development/core/server/kibana-plugin-server.routevalidationresultfactory.ok.md index eca6a31bd547f..c86ef616de103 100644 --- a/docs/development/core/server/kibana-plugin-server.routevalidationresultfactory.ok.md +++ b/docs/development/core/server/kibana-plugin-server.routevalidationresultfactory.ok.md @@ -1,13 +1,13 @@ - - -[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [RouteValidationResultFactory](./kibana-plugin-server.routevalidationresultfactory.md) > [ok](./kibana-plugin-server.routevalidationresultfactory.ok.md) - -## RouteValidationResultFactory.ok property - -Signature: - -```typescript -ok: (value: T) => { - value: T; - }; -``` + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [RouteValidationResultFactory](./kibana-plugin-server.routevalidationresultfactory.md) > [ok](./kibana-plugin-server.routevalidationresultfactory.ok.md) + +## RouteValidationResultFactory.ok property + +Signature: + +```typescript +(value: T) => { + T; + }; +``` diff --git a/docs/development/core/server/kibana-plugin-server.routevalidatoroptions.unsafe.md b/docs/development/core/server/kibana-plugin-server.routevalidatoroptions.unsafe.md index 0406a372c4e9d..b1c75e6dbdf67 100644 --- a/docs/development/core/server/kibana-plugin-server.routevalidatoroptions.unsafe.md +++ b/docs/development/core/server/kibana-plugin-server.routevalidatoroptions.unsafe.md @@ -1,17 +1,18 @@ - - -[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [RouteValidatorOptions](./kibana-plugin-server.routevalidatoroptions.md) > [unsafe](./kibana-plugin-server.routevalidatoroptions.unsafe.md) - -## RouteValidatorOptions.unsafe property - -Set the `unsafe` config to avoid running some additional internal \*safe\* validations on top of your custom validation - -Signature: - -```typescript -unsafe?: { - params?: boolean; - query?: boolean; - body?: boolean; - }; -``` + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [RouteValidatorOptions](./kibana-plugin-server.routevalidatoroptions.md) > [unsafe](./kibana-plugin-server.routevalidatoroptions.unsafe.md) + +## RouteValidatorOptions.unsafe property + +Set the `unsafe` config to avoid running some additional internal \*safe\* validations on top of your custom validation + +Signature: + +```typescript +unsafe?: { + params?: boolean; + query?: boolean; + body?: boolean; + } + +``` diff --git a/src/legacy/core_plugins/kibana/public/dashboard/index.ts b/src/legacy/core_plugins/kibana/public/dashboard/index.ts index 76d9933a3d567..fd39f28a7673a 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/index.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/index.ts @@ -17,17 +17,11 @@ * under the License. */ -import { - npSetup, - npStart, - SavedObjectRegistryProvider, - legacyChrome, - IPrivate, -} from './legacy_imports'; +import { npSetup, npStart, legacyChrome } from './legacy_imports'; import { DashboardPlugin, LegacyAngularInjectedDependencies } from './plugin'; import { start as data } from '../../../data/public/legacy'; import { start as embeddables } from '../../../embeddable_api/public/np_ready/public/legacy'; -import './saved_dashboard/saved_dashboards'; +import './saved_dashboard/saved_dashboard_register'; import './dashboard_config'; export * from './np_ready/dashboard_constants'; @@ -39,14 +33,8 @@ export * from './np_ready/dashboard_constants'; async function getAngularDependencies(): Promise { const injector = await legacyChrome.dangerouslyGetActiveInjector(); - const Private = injector.get('Private'); - - const savedObjectRegistry = Private(SavedObjectRegistryProvider); - return { dashboardConfig: injector.get('dashboardConfig'), - savedObjectRegistry, - savedDashboards: injector.get('savedDashboards'), }; } diff --git a/src/legacy/core_plugins/kibana/public/dashboard/legacy_imports.ts b/src/legacy/core_plugins/kibana/public/dashboard/legacy_imports.ts index d3c17d1176c10..ec0913e5fb3e7 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/legacy_imports.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/legacy_imports.ts @@ -32,7 +32,6 @@ export { AppState } from 'ui/state_management/app_state'; export { AppStateClass } from 'ui/state_management/app_state'; export { SavedObjectSaveOpts } from 'ui/saved_objects/types'; export { npSetup, npStart } from 'ui/new_platform'; -export { SavedObjectRegistryProvider } from 'ui/saved_objects'; export { IPrivate } from 'ui/private'; export { SavedObjectSaveModal } from 'ui/saved_objects/components/saved_object_save_modal'; export { subscribeWithScope } from 'ui/utils/subscribe_with_scope'; @@ -65,5 +64,6 @@ export { stateMonitorFactory, StateMonitor } from 'ui/state_management/state_mon export { ensureDefaultIndexPattern } from 'ui/legacy_compat'; export { unhashUrl } from '../../../../../plugins/kibana_utils/public'; export { IInjector } from 'ui/chrome'; +export { SavedObjectLoader } from 'ui/saved_objects'; export { VISUALIZE_EMBEDDABLE_TYPE } from '../visualize_embeddable'; export { registerTimefilterWithGlobalStateFactory } from 'ui/timefilter/setup_router'; diff --git a/src/legacy/core_plugins/kibana/public/dashboard/np_ready/application.ts b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/application.ts index 298dcee12dc35..2a5dedab98151 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/np_ready/application.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/application.ts @@ -42,6 +42,7 @@ import { RedirectWhenMissingProvider, confirmModalFactory, configureAppAngularModule, + SavedObjectLoader, IPrivate, } from '../legacy_imports'; @@ -57,9 +58,8 @@ export interface RenderDeps { npDataStart: NpDataStart; navigation: NavigationStart; savedObjectsClient: SavedObjectsClientContract; - savedObjectRegistry: any; + savedDashboards: SavedObjectLoader; dashboardConfig: any; - savedDashboards: any; dashboardCapabilities: any; uiSettings: IUiSettingsClient; chrome: ChromeStart; diff --git a/src/legacy/core_plugins/kibana/public/dashboard/np_ready/legacy_app.js b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/legacy_app.js index a4fda5eda8a32..540bfcf5aa684 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/np_ready/legacy_app.js +++ b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/legacy_app.js @@ -98,7 +98,8 @@ export function initDashboardApp(app, deps) { ...defaults, template: dashboardListingTemplate, controller($injector, $location, $scope) { - const services = deps.savedObjectRegistry.byLoaderPropertiesName; + const service = deps.savedDashboards; + const kbnUrl = $injector.get('kbnUrl'); const dashboardConfig = deps.dashboardConfig; @@ -107,7 +108,7 @@ export function initDashboardApp(app, deps) { kbnUrl.redirect(DashboardConstants.CREATE_NEW_DASHBOARD_URL); }; $scope.find = search => { - return services.dashboards.find(search, $scope.listingLimit); + return service.find(search, $scope.listingLimit); }; $scope.editItem = ({ id }) => { kbnUrl.redirect(`${createDashboardEditUrl(id)}?_a=(viewMode:edit)`); @@ -116,7 +117,7 @@ export function initDashboardApp(app, deps) { return deps.addBasePath(`#${createDashboardEditUrl(id)}`); }; $scope.delete = dashboards => { - return services.dashboards.delete(dashboards.map(d => d.id)); + return service.delete(dashboards.map(d => d.id)); }; $scope.hideWriteControls = dashboardConfig.getHideWriteControls(); $scope.initialFilter = $location.search().filter || EMPTY_FILTER; diff --git a/src/legacy/core_plugins/kibana/public/dashboard/plugin.ts b/src/legacy/core_plugins/kibana/public/dashboard/plugin.ts index 76deff201e5ee..ca4b18a37504c 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/plugin.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/plugin.ts @@ -39,11 +39,10 @@ import { } from '../../../../../plugins/home/public'; import { SharePluginStart } from '../../../../../plugins/share/public'; import { KibanaLegacySetup } from '../../../../../plugins/kibana_legacy/public'; +import { createSavedDashboardLoader } from './saved_dashboard/saved_dashboards'; export interface LegacyAngularInjectedDependencies { dashboardConfig: any; - savedObjectRegistry: any; - savedDashboards: any; } export interface DashboardPluginStartDependencies { @@ -90,6 +89,13 @@ export class DashboardPlugin implements Plugin { npDataStart, } = this.startDependencies; const angularDependencies = await getAngularDependencies(); + const savedDashboards = createSavedDashboardLoader({ + savedObjectsClient, + indexPatterns: npDataStart.indexPatterns, + chrome: contextCore.chrome, + overlays: contextCore.overlays, + }); + const deps: RenderDeps = { core: contextCore as LegacyCoreStart, ...angularDependencies, @@ -97,6 +103,7 @@ export class DashboardPlugin implements Plugin { share, npDataStart, savedObjectsClient, + savedDashboards, chrome: contextCore.chrome, addBasePath: contextCore.http.basePath.prepend, uiSettings: contextCore.uiSettings, diff --git a/src/legacy/core_plugins/kibana/public/dashboard/saved_dashboard/saved_dashboard_register.ts b/src/legacy/core_plugins/kibana/public/dashboard/saved_dashboard/saved_dashboard_register.ts index 31ee7299e1ff1..b9ea49ca4fd44 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/saved_dashboard/saved_dashboard_register.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/saved_dashboard/saved_dashboard_register.ts @@ -16,10 +16,31 @@ * specific language governing permissions and limitations * under the License. */ +import { i18n } from '@kbn/i18n'; +import { npStart } from 'ui/new_platform'; +// @ts-ignore +import { uiModules } from 'ui/modules'; +// @ts-ignore +import { savedObjectManagementRegistry } from '../../management/saved_object_registry'; +import { createSavedDashboardLoader } from './saved_dashboards'; -import { SavedObjectRegistryProvider } from 'ui/saved_objects/saved_object_registry'; -import './saved_dashboards'; +const module = uiModules.get('app/dashboard'); -SavedObjectRegistryProvider.register((savedDashboards: any) => { - return savedDashboards; +// Register this service with the saved object registry so it can be +// edited by the object editor. +savedObjectManagementRegistry.register({ + service: 'savedDashboards', + title: i18n.translate('kbn.dashboard.savedDashboardsTitle', { + defaultMessage: 'dashboards', + }), }); + +// this is no longer used in the conroller, but just here for savedObjectManagementRegistry +module.service('savedDashboards', () => + createSavedDashboardLoader({ + savedObjectsClient: npStart.core.savedObjects.client, + indexPatterns: npStart.plugins.data.indexPatterns, + chrome: npStart.core.chrome, + overlays: npStart.core.overlays, + }) +); diff --git a/src/legacy/core_plugins/kibana/public/dashboard/saved_dashboard/saved_dashboards.ts b/src/legacy/core_plugins/kibana/public/dashboard/saved_dashboard/saved_dashboards.ts index 768dc6650595f..4ece5d46358ba 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/saved_dashboard/saved_dashboards.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/saved_dashboard/saved_dashboards.ts @@ -17,36 +17,11 @@ * under the License. */ -import { i18n } from '@kbn/i18n'; -import { npStart } from 'ui/new_platform'; -// @ts-ignore -import { uiModules } from 'ui/modules'; import { SavedObjectLoader } from 'ui/saved_objects'; -// @ts-ignore -import { savedObjectManagementRegistry } from '../../management/saved_object_registry'; +import { SavedObjectKibanaServices } from 'ui/saved_objects/types'; import { createSavedDashboardClass } from './saved_dashboard'; -const module = uiModules.get('app/dashboard'); - -// Register this service with the saved object registry so it can be -// edited by the object editor. -savedObjectManagementRegistry.register({ - service: 'savedDashboards', - title: i18n.translate('kbn.dashboard.savedDashboardsTitle', { - defaultMessage: 'dashboards', - }), -}); - -// This is the only thing that gets injected into controllers -module.service('savedDashboards', function() { - const savedObjectsClient = npStart.core.savedObjects.client; - const services = { - savedObjectsClient, - indexPatterns: npStart.plugins.data.indexPatterns, - chrome: npStart.core.chrome, - overlays: npStart.core.overlays, - }; - +export function createSavedDashboardLoader(services: SavedObjectKibanaServices) { const SavedDashboard = createSavedDashboardClass(services); - return new SavedObjectLoader(SavedDashboard, savedObjectsClient, npStart.core.chrome); -}); + return new SavedObjectLoader(SavedDashboard, services.savedObjectsClient, services.chrome); +} diff --git a/src/legacy/core_plugins/kibana/public/discover/index.ts b/src/legacy/core_plugins/kibana/public/discover/index.ts index e85408dc9bf6b..347f545dea4c9 100644 --- a/src/legacy/core_plugins/kibana/public/discover/index.ts +++ b/src/legacy/core_plugins/kibana/public/discover/index.ts @@ -18,7 +18,6 @@ */ import { PluginInitializer, PluginInitializerContext } from 'kibana/public'; import { npSetup, npStart } from 'ui/new_platform'; -import { SavedObjectRegistryProvider } from 'ui/saved_objects'; import { DiscoverPlugin, DiscoverSetup, DiscoverStart } from './plugin'; // Core will be looking for this when loading our plugin in the new platform @@ -33,8 +32,4 @@ export const pluginInstance = plugin({} as PluginInitializerContext); pluginInstance.start(npStart.core, npStart.plugins); })(); -SavedObjectRegistryProvider.register((savedSearches: any) => { - return savedSearches; -}); - export { createSavedSearchesService } from './saved_searches/saved_searches'; diff --git a/src/legacy/core_plugins/kibana/public/discover/saved_searches/saved_searches_register.ts b/src/legacy/core_plugins/kibana/public/discover/saved_searches/saved_searches_register.ts index bdb1495a33925..ab7894fd5e730 100644 --- a/src/legacy/core_plugins/kibana/public/discover/saved_searches/saved_searches_register.ts +++ b/src/legacy/core_plugins/kibana/public/discover/saved_searches/saved_searches_register.ts @@ -31,13 +31,13 @@ savedObjectManagementRegistry.register({ service: 'savedSearches', title: 'searches', }); +const services = { + savedObjectsClient: npStart.core.savedObjects.client, + indexPatterns: npStart.plugins.data.indexPatterns, + chrome: npStart.core.chrome, + overlays: npStart.core.overlays, +}; +const savedSearches = createSavedSearchesService(services); + const module = uiModules.get('discover/saved_searches'); -module.service('savedSearches', () => { - const services = { - savedObjectsClient: npStart.core.savedObjects.client, - indexPatterns: npStart.plugins.data.indexPatterns, - chrome: npStart.core.chrome, - overlays: npStart.core.overlays, - }; - return createSavedSearchesService(services); -}); +module.service('savedSearches', () => savedSearches); diff --git a/src/legacy/core_plugins/kibana/public/visualize/index.ts b/src/legacy/core_plugins/kibana/public/visualize/index.ts index bd605c5393d21..a389a44197baf 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/index.ts +++ b/src/legacy/core_plugins/kibana/public/visualize/index.ts @@ -25,7 +25,6 @@ import { legacyChrome, npSetup, npStart, - SavedObjectRegistryProvider, VisEditorTypesRegistryProvider, } from './legacy_imports'; import { VisualizePlugin, LegacyAngularInjectedDependencies } from './plugin'; @@ -45,13 +44,10 @@ async function getAngularDependencies(): Promise('Private'); const editorTypes = Private(VisEditorTypesRegistryProvider); - const savedObjectRegistry = Private(SavedObjectRegistryProvider); return { legacyChrome, editorTypes, - savedObjectRegistry, - savedVisualizations: injector.get('savedVisualizations'), }; } @@ -69,3 +65,5 @@ async function getAngularDependencies(): Promise { const isLabsEnabled = uiSettings.get('visualize:enableLabs'); - return visualizationService + return savedVisualizations .findListItems(filter, uiSettings.get('savedObjects:listingLimit')) .then(result => { this.totalItems = result.total; diff --git a/src/legacy/core_plugins/kibana/public/visualize/plugin.ts b/src/legacy/core_plugins/kibana/public/visualize/plugin.ts index d1afa2d065194..9ea26f129895c 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/plugin.ts +++ b/src/legacy/core_plugins/kibana/public/visualize/plugin.ts @@ -46,14 +46,12 @@ import { VisualizeEmbeddableFactory, VISUALIZE_EMBEDDABLE_TYPE, } from './legacy_imports'; -import { SavedVisualizations } from './np_ready/types'; import { UsageCollectionSetup } from '../../../../../plugins/usage_collection/public'; +import { createSavedVisLoader } from './saved_visualizations/saved_visualizations'; export interface LegacyAngularInjectedDependencies { legacyChrome: any; editorTypes: any; - savedObjectRegistry: any; - savedVisualizations: SavedVisualizations; } export interface VisualizePluginStartDependencies { @@ -110,6 +108,12 @@ export class VisualizePlugin implements Plugin { } = this.startDependencies; const angularDependencies = await getAngularDependencies(); + const savedVisualizations = createSavedVisLoader({ + savedObjectsClient, + indexPatterns: data.indexPatterns, + chrome: contextCore.chrome, + overlays: contextCore.overlays, + }); const deps: VisualizeKibanaServices = { ...angularDependencies, addBasePath: contextCore.http.basePath.prepend, @@ -122,6 +126,7 @@ export class VisualizePlugin implements Plugin { localStorage: new Storage(localStorage), navigation, savedObjectsClient, + savedVisualizations, savedQueryService: data.query.savedQueries, share, toastNotifications: contextCore.notifications.toasts, diff --git a/src/legacy/core_plugins/kibana/public/visualize/saved_visualizations/saved_visualization_register.ts b/src/legacy/core_plugins/kibana/public/visualize/saved_visualizations/saved_visualization_register.ts index 803474b1f7b3f..cbf72339804ce 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/saved_visualizations/saved_visualization_register.ts +++ b/src/legacy/core_plugins/kibana/public/visualize/saved_visualizations/saved_visualization_register.ts @@ -16,15 +16,22 @@ * specific language governing permissions and limitations * under the License. */ - -import { SavedObjectRegistryProvider } from 'ui/saved_objects/saved_object_registry'; +import { npStart } from 'ui/new_platform'; +// @ts-ignore +import { uiModules } from 'ui/modules'; // @ts-ignore import { savedObjectManagementRegistry } from '../../management/saved_object_registry'; import './saved_visualizations'; +import { createSavedVisLoader } from './saved_visualizations'; -SavedObjectRegistryProvider.register((savedVisualizations: any) => { - return savedVisualizations; -}); +const services = { + savedObjectsClient: npStart.core.savedObjects.client, + indexPatterns: npStart.plugins.data.indexPatterns, + chrome: npStart.core.chrome, + overlays: npStart.core.overlays, +}; + +const savedObjectLoaderVisualize = createSavedVisLoader(services); // Register this service with the saved object registry so it can be // edited by the object editor. @@ -32,3 +39,5 @@ savedObjectManagementRegistry.register({ service: 'savedVisualizations', title: 'visualizations', }); + +uiModules.get('app/visualize').service('savedVisualizations', () => savedObjectLoaderVisualize); diff --git a/src/legacy/core_plugins/kibana/public/visualize/saved_visualizations/saved_visualizations.ts b/src/legacy/core_plugins/kibana/public/visualize/saved_visualizations/saved_visualizations.ts index aa8d20fed4828..c19c7818c1fbd 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/saved_visualizations/saved_visualizations.ts +++ b/src/legacy/core_plugins/kibana/public/visualize/saved_visualizations/saved_visualizations.ts @@ -16,26 +16,18 @@ * specific language governing permissions and limitations * under the License. */ -import { npStart } from 'ui/new_platform'; -// @ts-ignore -import { uiModules } from 'ui/modules'; import { SavedObjectLoader } from 'ui/saved_objects'; +import { SavedObjectKibanaServices } from 'ui/saved_objects/types'; import { start as visualizations } from '../../../../visualizations/public/np_ready/public/legacy'; // @ts-ignore import { findListItems } from './find_list_items'; import { createSavedVisClass } from './_saved_vis'; import { createVisualizeEditUrl } from '..'; -const app = uiModules.get('app/visualize'); -app.service('savedVisualizations', function() { - const savedObjectsClient = npStart.core.savedObjects.client; - const services = { - savedObjectsClient, - indexPatterns: npStart.plugins.data.indexPatterns, - chrome: npStart.core.chrome, - overlays: npStart.core.overlays, - }; +export function createSavedVisLoader(services: SavedObjectKibanaServices) { + const { savedObjectsClient } = services; + class SavedObjectLoaderVisualize extends SavedObjectLoader { mapHitSource = (source: Record, id: string) => { const visTypes = visualizations.types; @@ -81,6 +73,5 @@ app.service('savedVisualizations', function() { } } const SavedVis = createSavedVisClass(services); - - return new SavedObjectLoaderVisualize(SavedVis, savedObjectsClient, npStart.core.chrome); -}); + return new SavedObjectLoaderVisualize(SavedVis, savedObjectsClient, services.chrome); +} diff --git a/src/legacy/core_plugins/timelion/public/app.js b/src/legacy/core_plugins/timelion/public/app.js index 365e74e93c4ad..7ef722ee3a277 100644 --- a/src/legacy/core_plugins/timelion/public/app.js +++ b/src/legacy/core_plugins/timelion/public/app.js @@ -23,7 +23,6 @@ import { i18n } from '@kbn/i18n'; import { capabilities } from 'ui/capabilities'; import { docTitle } from 'ui/doc_title'; -import { SavedObjectRegistryProvider } from 'ui/saved_objects/saved_object_registry'; import { fatalError, toastNotifications } from 'ui/notify'; import { timezoneProvider } from 'ui/vis/lib/timezone'; import { timefilter } from 'ui/timefilter'; @@ -36,16 +35,15 @@ require('ui/autoload/all'); // TODO: remove ui imports completely (move to plugins) import 'ui/directives/input_focus'; -import 'ui/directives/saved_object_finder'; +import './directives/saved_object_finder'; import 'ui/directives/listen'; import 'ui/kbn_top_nav'; import 'ui/saved_objects/ui/saved_object_save_as_checkbox'; import '../../data/public/legacy'; -import './services/saved_sheets'; -import './services/_saved_sheet'; import './services/saved_sheet_register'; import rootTemplate from 'plugins/timelion/index.html'; +import { createSavedVisLoader } from '../../kibana/public/visualize'; require('plugins/timelion/directives/cells/cells'); require('plugins/timelion/directives/fixed_element'); @@ -130,8 +128,12 @@ app.controller('timelion', function( timefilter.enableAutoRefreshSelector(); timefilter.enableTimeRangeSelector(); - const savedVisualizations = Private(SavedObjectRegistryProvider).byLoaderPropertiesName - .visualizations; + const savedVisualizations = createSavedVisLoader({ + savedObjectsClient: npStart.core.savedObjects.client, + indexPatterns: npStart.plugins.data.indexPatterns, + chrome: npStart.core.chrome, + overlays: npStart.core.overlays, + }); const timezone = Private(timezoneProvider)(); const defaultExpression = '.es(*)'; diff --git a/src/legacy/ui/public/directives/partials/saved_object_finder.html b/src/legacy/core_plugins/timelion/public/directives/saved_object_finder.html similarity index 86% rename from src/legacy/ui/public/directives/partials/saved_object_finder.html rename to src/legacy/core_plugins/timelion/public/directives/saved_object_finder.html index adf7f5dacae9a..ad148801c03a4 100644 --- a/src/legacy/ui/public/directives/partials/saved_object_finder.html +++ b/src/legacy/core_plugins/timelion/public/directives/saved_object_finder.html @@ -23,7 +23,7 @@

@@ -33,7 +33,7 @@ ng-if="onAddNew" ng-click="onAddNew()" data-test-subj="addNewSavedObjectLink" - i18n-id="common.ui.savedObjectFinder.addNewItemButtonLabel" + i18n-id="timelion.savedObjectFinder.addNewItemButtonLabel" i18n-default-message="Add new {item}" i18n-values="{item: finder.properties.noun}" i18n-description="{item} can be a type of object in Kibana, like 'visualization', 'dashboard', etc" @@ -43,7 +43,7 @@ class="kuiButton kuiButton--secondary" ng-if="!useLocalManagement" ng-click="finder.manageObjects(finder.properties.name)" - i18n-id="common.ui.savedObjectFinder.manageItemsButtonLabel" + i18n-id="timelion.savedObjectFinder.manageItemsButtonLabel" i18n-default-message="Manage {items}" i18n-values="{items: finder.properties.nouns}" i18n-description="{items} can be a type of object in Kibana, like 'visualizations', 'dashboards', etc" @@ -64,11 +64,11 @@ aria-live="assertive" > @@ -108,7 +108,7 @@ class="list-group-item list-group-no-results" ng-if="finder.hits.length === 0" > -

{ - return savedSheets; -}); diff --git a/src/legacy/core_plugins/timelion/public/services/saved_sheets.ts b/src/legacy/core_plugins/timelion/public/services/saved_sheets.ts index d851b5a863658..df3898e3410dd 100644 --- a/src/legacy/core_plugins/timelion/public/services/saved_sheets.ts +++ b/src/legacy/core_plugins/timelion/public/services/saved_sheets.ts @@ -33,29 +33,28 @@ savedObjectManagementRegistry.register({ title: 'sheets', }); -// This is the only thing that gets injected into controllers -module.service('savedSheets', function() { - const savedObjectsClient = npStart.core.savedObjects.client; - const services = { - savedObjectsClient, - indexPatterns: npStart.plugins.data.indexPatterns, - chrome: npStart.core.chrome, - overlays: npStart.core.overlays, - }; +const savedObjectsClient = npStart.core.savedObjects.client; +const services = { + savedObjectsClient, + indexPatterns: npStart.plugins.data.indexPatterns, + chrome: npStart.core.chrome, + overlays: npStart.core.overlays, +}; - const SavedSheet = createSavedSheetClass(services, npStart.core.uiSettings); +const SavedSheet = createSavedSheetClass(services, npStart.core.uiSettings); - const savedSheetLoader = new SavedObjectLoader( - SavedSheet, - savedObjectsClient, - npStart.core.chrome - ); - savedSheetLoader.urlFor = id => `#/${encodeURIComponent(id)}`; - // Customize loader properties since adding an 's' on type doesn't work for type 'timelion-sheet'. - savedSheetLoader.loaderProperties = { - name: 'timelion-sheet', - noun: 'Saved Sheets', - nouns: 'saved sheets', - }; - return savedSheetLoader; -}); +export const savedSheetLoader = new SavedObjectLoader( + SavedSheet, + savedObjectsClient, + npStart.core.chrome +); +savedSheetLoader.urlFor = id => `#/${encodeURIComponent(id)}`; +// Customize loader properties since adding an 's' on type doesn't work for type 'timelion-sheet'. +savedSheetLoader.loaderProperties = { + name: 'timelion-sheet', + noun: 'Saved Sheets', + nouns: 'saved sheets', +}; + +// This is the only thing that gets injected into controllers +module.service('savedSheets', () => savedSheetLoader); diff --git a/src/legacy/ui/public/saved_objects/index.ts b/src/legacy/ui/public/saved_objects/index.ts index 3c77a02c608c6..129938ebe0509 100644 --- a/src/legacy/ui/public/saved_objects/index.ts +++ b/src/legacy/ui/public/saved_objects/index.ts @@ -17,7 +17,6 @@ * under the License. */ -export { SavedObjectRegistryProvider } from './saved_object_registry'; export { SavedObjectsClientProvider } from './saved_objects_client_provider'; export { SavedObjectLoader } from './saved_object_loader'; export { findObjectByTitle } from './helpers/find_object_by_title'; diff --git a/src/legacy/ui/public/saved_objects/saved_object_registry.ts b/src/legacy/ui/public/saved_objects/saved_object_registry.ts deleted file mode 100644 index 34b91267bfb32..0000000000000 --- a/src/legacy/ui/public/saved_objects/saved_object_registry.ts +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import { uiRegistry } from '../registry/_registry'; - -export const SavedObjectRegistryProvider = uiRegistry({ - name: 'savedObjects', - index: ['loaderProperties.name'], - order: ['loaderProperties.name'], -}); diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index c79969154d05c..54ae975849c29 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -454,14 +454,14 @@ "common.ui.notify.toaster.unavailableServerErrorMessage": "HTTP リクエストが接続に失敗しました。Kibana サーバーが実行されていて、ご使用のブラウザの接続が正常に動作していることを確認するか、システム管理者にお問い合わせください。", "common.ui.paginateControls.pageSizeLabel": "ページサイズ", "common.ui.paginateControls.scrollTopButtonLabel": "最上部に移動", - "common.ui.savedObjectFinder.addNewItemButtonLabel": "新規 {item} を追加", - "common.ui.savedObjectFinder.manageItemsButtonLabel": "{items} の管理", - "common.ui.savedObjectFinder.noMatchesFoundDescription": "一致する {items} が見つかりません。", - "common.ui.savedObjectFinder.pageItemsFromHitCountDescription": "{hitCount} 件中 {pageFirstItem}-{pageLastItem} 件目", - "common.ui.savedObjectFinder.sortByButtonLabeAscendingScreenReaderOnly": "昇順", - "common.ui.savedObjectFinder.sortByButtonLabeDescendingScreenReaderOnly": "降順", - "common.ui.savedObjectFinder.sortByButtonLabel": "名前", - "common.ui.savedObjectFinder.sortByButtonLabelScreenReaderOnly": "並べ替え基準", + "timelion.savedObjectFinder.addNewItemButtonLabel": "新規 {item} を追加", + "timelion.savedObjectFinder.manageItemsButtonLabel": "{items} の管理", + "timelion.savedObjectFinder.noMatchesFoundDescription": "一致する {items} が見つかりません。", + "timelion.savedObjectFinder.pageItemsFromHitCountDescription": "{hitCount} 件中 {pageFirstItem}-{pageLastItem} 件目", + "timelion.savedObjectFinder.sortByButtonLabeAscendingScreenReaderOnly": "昇順", + "timelion.savedObjectFinder.sortByButtonLabeDescendingScreenReaderOnly": "降順", + "timelion.savedObjectFinder.sortByButtonLabel": "名前", + "timelion.savedObjectFinder.sortByButtonLabelScreenReaderOnly": "並べ替え基準", "common.ui.savedObjects.confirmModal.overwriteButtonLabel": "上書き", "common.ui.savedObjects.confirmModal.overwriteConfirmationMessage": "{title} を上書きしてよろしいですか?", "common.ui.savedObjects.confirmModal.overwriteTitle": "{name} を上書きしますか?", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index 34559ba9f95be..b63a8feeae02b 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -454,14 +454,14 @@ "common.ui.notify.toaster.unavailableServerErrorMessage": "HTTP 请求无法连接。请检查 Kibana 服务器是否正在运行以及您的浏览器是否具有有效的连接,或请联系您的系统管理员。", "common.ui.paginateControls.pageSizeLabel": "页面大小", "common.ui.paginateControls.scrollTopButtonLabel": "滚动至顶部", - "common.ui.savedObjectFinder.addNewItemButtonLabel": "添加新的 {item}", - "common.ui.savedObjectFinder.manageItemsButtonLabel": "管理 {items}", - "common.ui.savedObjectFinder.noMatchesFoundDescription": "未找到任何匹配的 {items}。", - "common.ui.savedObjectFinder.pageItemsFromHitCountDescription": "{pageFirstItem}-{pageLastItem} 页,共 {hitCount} 页", - "common.ui.savedObjectFinder.sortByButtonLabeAscendingScreenReaderOnly": "升序", - "common.ui.savedObjectFinder.sortByButtonLabeDescendingScreenReaderOnly": "降序", - "common.ui.savedObjectFinder.sortByButtonLabel": "名称", - "common.ui.savedObjectFinder.sortByButtonLabelScreenReaderOnly": "排序依据", + "timelion.savedObjectFinder.addNewItemButtonLabel": "添加新的 {item}", + "timelion.savedObjectFinder.manageItemsButtonLabel": "管理 {items}", + "timelion.savedObjectFinder.noMatchesFoundDescription": "未找到任何匹配的 {items}。", + "timelion.savedObjectFinder.pageItemsFromHitCountDescription": "{pageFirstItem}-{pageLastItem} 页,共 {hitCount} 页", + "timelion.savedObjectFinder.sortByButtonLabeAscendingScreenReaderOnly": "升序", + "timelion.savedObjectFinder.sortByButtonLabeDescendingScreenReaderOnly": "降序", + "timelion.savedObjectFinder.sortByButtonLabel": "名称", + "timelion.savedObjectFinder.sortByButtonLabelScreenReaderOnly": "排序依据", "common.ui.savedObjects.confirmModal.overwriteButtonLabel": "覆盖", "common.ui.savedObjects.confirmModal.overwriteConfirmationMessage": "确定要覆盖 “{title}”?", "common.ui.savedObjects.confirmModal.overwriteTitle": "覆盖“{name}”?",