From b324ca3115e45e2890b3f4914d6d4635c8e63860 Mon Sep 17 00:00:00 2001 From: Dzmitry Lemechko Date: Thu, 9 Sep 2021 08:14:56 +0200 Subject: [PATCH 1/6] [jest] update config files to get coverage per plugin (#111299) * [jest] update config files to get coverage per plugin * [docs] add details about plugin coverage collection * fix path for newsfeed jest config * fix lint error * update documentation * fix lint errors again * update doc * fix another lint error * Update src/plugins/telemetry_management_section/jest.config.js Co-authored-by: Luke Elmers * Update src/plugins/telemetry_management_section/jest.config.js Co-authored-by: Luke Elmers * [kibana_legacy] fix path Co-authored-by: Luke Elmers Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- dev_docs/key_concepts/anatomy_of_a_plugin.mdx | 24 +++++++++++++++++++ dev_docs/tutorials/testing_plugins.mdx | 11 +++++++++ .../contributing/development-tests.asciidoc | 8 +++++++ packages/kbn-ui-framework/README.md | 3 +++ src/plugins/advanced_settings/jest.config.js | 3 +++ src/plugins/bfetch/jest.config.js | 3 +++ .../expression_tagcloud/jest.config.js | 6 +++++ src/plugins/charts/jest.config.js | 3 +++ src/plugins/console/jest.config.js | 3 +++ src/plugins/dashboard/jest.config.js | 3 +++ src/plugins/data/jest.config.js | 3 +++ src/plugins/discover/jest.config.js | 3 +++ src/plugins/embeddable/jest.config.js | 3 +++ src/plugins/es_ui_shared/jest.config.js | 5 ++++ src/plugins/expression_error/jest.config.js | 3 +++ src/plugins/expression_image/jest.config.js | 5 ++++ src/plugins/expression_metric/jest.config.js | 5 ++++ .../expression_repeat_image/jest.config.js | 5 ++++ .../expression_reveal_image/jest.config.js | 5 ++++ src/plugins/expression_shape/jest.config.js | 5 ++++ src/plugins/expressions/jest.config.js | 3 +++ src/plugins/field_formats/jest.config.js | 3 +++ src/plugins/home/jest.config.js | 3 +++ .../index_pattern_editor/jest.config.js | 3 +++ .../index_pattern_field_editor/jest.config.js | 5 ++++ .../index_pattern_management/jest.config.js | 5 ++++ src/plugins/input_control_vis/jest.config.js | 3 +++ src/plugins/inspector/jest.config.js | 3 +++ src/plugins/interactive_setup/jest.config.js | 5 ++++ src/plugins/kibana_legacy/jest.config.js | 3 +++ src/plugins/kibana_overview/jest.config.js | 3 +++ src/plugins/kibana_react/jest.config.js | 3 +++ .../kibana_usage_collection/jest.config.js | 5 ++++ src/plugins/kibana_utils/jest.config.js | 5 ++++ src/plugins/management/jest.config.js | 3 +++ src/plugins/maps_ems/jest.config.js | 3 +++ src/plugins/navigation/jest.config.js | 3 +++ src/plugins/newsfeed/jest.config.js | 3 +++ src/plugins/presentation_util/jest.config.js | 5 ++++ src/plugins/saved_objects/jest.config.js | 3 +++ .../saved_objects_management/jest.config.js | 5 ++++ .../saved_objects_tagging_oss/jest.config.js | 5 ++++ src/plugins/screenshot_mode/jest.config.js | 5 ++++ src/plugins/security_oss/jest.config.js | 3 +++ src/plugins/share/jest.config.js | 3 +++ src/plugins/telemetry/jest.config.js | 3 +++ .../jest.config.js | 6 +++++ .../jest.config.js | 4 ++++ src/plugins/ui_actions/jest.config.js | 3 +++ src/plugins/url_forwarding/jest.config.js | 3 +++ src/plugins/usage_collection/jest.config.js | 5 ++++ src/plugins/vis_default_editor/jest.config.js | 3 +++ src/plugins/vis_type_markdown/jest.config.js | 3 +++ src/plugins/vis_type_table/jest.config.js | 6 ++++- src/plugins/vis_type_timelion/jest.config.js | 5 ++++ .../vis_type_timeseries/jest.config.js | 5 ++++ src/plugins/vis_types/metric/jest.config.js | 3 +++ src/plugins/vis_types/pie/jest.config.js | 3 +++ src/plugins/vis_types/tagcloud/jest.config.js | 3 +++ src/plugins/vis_types/vega/jest.config.js | 3 +++ src/plugins/vis_types/vislib/jest.config.js | 5 ++++ src/plugins/vis_types/xy/jest.config.js | 3 +++ src/plugins/visualizations/jest.config.js | 5 ++++ src/plugins/visualize/jest.config.js | 3 +++ x-pack/plugins/actions/jest.config.js | 3 +++ x-pack/plugins/alerting/jest.config.js | 3 +++ x-pack/plugins/apm/jest.config.js | 5 ++++ x-pack/plugins/banners/jest.config.js | 3 +++ x-pack/plugins/canvas/jest.config.js | 5 ++++ x-pack/plugins/cases/jest.config.js | 3 +++ x-pack/plugins/cloud/jest.config.js | 3 +++ .../cross_cluster_replication/jest.config.js | 6 +++++ .../plugins/dashboard_enhanced/jest.config.js | 5 ++++ x-pack/plugins/data_enhanced/jest.config.js | 5 ++++ x-pack/plugins/data_visualizer/jest.config.js | 5 ++++ .../plugins/discover_enhanced/jest.config.js | 5 ++++ x-pack/plugins/drilldowns/jest.config.js | 3 +++ .../embeddable_enhanced/jest.config.js | 3 +++ .../encrypted_saved_objects/jest.config.js | 3 +++ .../plugins/enterprise_search/jest.config.js | 3 ++- x-pack/plugins/event_log/jest.config.js | 3 +++ x-pack/plugins/features/jest.config.js | 3 +++ x-pack/plugins/file_upload/jest.config.js | 5 ++++ x-pack/plugins/fleet/jest.config.js | 3 +++ x-pack/plugins/global_search/jest.config.js | 5 ++++ .../plugins/global_search_bar/jest.config.js | 3 +++ .../global_search_providers/jest.config.js | 5 ++++ x-pack/plugins/graph/jest.config.js | 3 +++ x-pack/plugins/grokdebugger/jest.config.js | 5 ++++ .../index_lifecycle_management/jest.config.js | 6 +++++ .../plugins/index_management/jest.config.js | 5 ++++ x-pack/plugins/infra/jest.config.js | 3 +++ .../plugins/ingest_pipelines/jest.config.js | 5 ++++ x-pack/plugins/lens/jest.config.js | 3 +++ .../plugins/license_api_guard/jest.config.js | 3 +++ .../plugins/license_management/jest.config.js | 5 ++++ x-pack/plugins/licensing/jest.config.js | 3 +++ x-pack/plugins/lists/jest.config.js | 3 +++ x-pack/plugins/logstash/jest.config.js | 5 ++++ x-pack/plugins/maps/jest.config.js | 3 +++ .../plugins/metrics_entities/jest.config.js | 3 +++ x-pack/plugins/ml/jest.config.js | 3 +++ x-pack/plugins/monitoring/jest.config.js | 5 ++++ x-pack/plugins/observability/jest.config.js | 5 ++++ x-pack/plugins/osquery/jest.config.js | 3 +++ x-pack/plugins/painless_lab/jest.config.js | 5 ++++ x-pack/plugins/remote_clusters/jest.config.js | 5 ++++ x-pack/plugins/reporting/jest.config.js | 5 ++++ x-pack/plugins/rollup/jest.config.js | 3 +++ x-pack/plugins/rule_registry/jest.config.js | 3 +++ x-pack/plugins/runtime_fields/jest.config.js | 3 +++ .../saved_objects_tagging/jest.config.js | 5 ++++ x-pack/plugins/searchprofiler/jest.config.js | 5 ++++ x-pack/plugins/security/jest.config.js | 3 +++ .../plugins/security_solution/jest.config.js | 5 ++++ .../plugins/snapshot_restore/jest.config.js | 5 ++++ x-pack/plugins/spaces/jest.config.js | 3 +++ x-pack/plugins/stack_alerts/jest.config.js | 5 ++++ x-pack/plugins/task_manager/jest.config.js | 3 +++ .../telemetry_collection_xpack/jest.config.js | 4 ++++ x-pack/plugins/timelines/jest.config.js | 3 +++ x-pack/plugins/transform/jest.config.js | 3 +++ .../triggers_actions_ui/jest.config.js | 5 ++++ .../ui_actions_enhanced/jest.config.js | 5 ++++ .../plugins/upgrade_assistant/jest.config.js | 5 ++++ x-pack/plugins/uptime/jest.config.js | 3 +++ x-pack/plugins/watcher/jest.config.js | 3 +++ x-pack/plugins/xpack_legacy/jest.config.js | 3 +++ 128 files changed, 527 insertions(+), 2 deletions(-) diff --git a/dev_docs/key_concepts/anatomy_of_a_plugin.mdx b/dev_docs/key_concepts/anatomy_of_a_plugin.mdx index b22bc6f101998..3739f907c3d87 100644 --- a/dev_docs/key_concepts/anatomy_of_a_plugin.mdx +++ b/dev_docs/key_concepts/anatomy_of_a_plugin.mdx @@ -32,6 +32,7 @@ plugins/ plugin.ts common index.ts + jest.config.js ``` ### kibana.json @@ -209,6 +210,29 @@ considerations related to how plugins integrate with core APIs and APIs exposed `common/index.ts` is the entry-point into code that can be used both server-side or client side. +### jest.config.js + +If you are adding unit tests (which we recommend), you will need to add a `jest.config.js` file. Here is an example file that you would use if adding a plugin into the `examples` directory. + +```js +module.exports = { + // Default Jest settings, defined in kbn-test package + preset: '@kbn/test', + // The root of the directory containing package.json + rootDir: '../../..', + // The directory which Jest should use to search for files in + roots: ['/src/plugins/demo'], + // The directory where Jest should output plugin coverage details, e.g. html report + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/demo', + // A list of reporter names that Jest uses when writing coverage reports, default: ["json"] + // "text" is available in console and is good for quick check + // "html" helps to dig into specific files and fix coverage + coverageReporters: ['text', 'html'], + // An array of regexp pattern strings that matched files to include/exclude for code coverage + collectCoverageFrom: ['/src/plugins/demo/{common,public,server}/**/*.{ts,tsx}'], +}; +``` + ## How plugin's interact with each other, and Core The lifecycle-specific contracts exposed by core services are always passed as the first argument to the equivalent lifecycle function in a plugin. diff --git a/dev_docs/tutorials/testing_plugins.mdx b/dev_docs/tutorials/testing_plugins.mdx index 55b662421cbd0..bc92af33d3493 100644 --- a/dev_docs/tutorials/testing_plugins.mdx +++ b/dev_docs/tutorials/testing_plugins.mdx @@ -928,6 +928,17 @@ describe('Case migrations v7.7.0 -> v7.8.0', () => { }); ``` +You can generate code coverage report for a single plugin. + +```bash +yarn jest --coverage --config src/plugins/console/jest.config.js +``` + +Html report should be available in `target/kibana-coverage/jest/src/plugins/console` path + +We run code coverage daily on CI and ["Kibana Stats cluster"](https://kibana-stats.elastic.dev/s/code-coverage/app/home) +can be used to view statistics. The report combines code coverage for all jest tests within Kibana repository. + #### Integration testing With more complicated migrations, the behavior of the migration may be dependent on values from other plugins which may be difficult or even impossible to test with unit tests. You need to actually bootstrap Kibana, load the plugins, and diff --git a/docs/developer/contributing/development-tests.asciidoc b/docs/developer/contributing/development-tests.asciidoc index e7a36d2866728..340e122b44c1b 100644 --- a/docs/developer/contributing/development-tests.asciidoc +++ b/docs/developer/contributing/development-tests.asciidoc @@ -56,6 +56,14 @@ kibana/src/plugins/dashboard/server$ yarn test:jest --coverage yarn jest --coverage --verbose --config /home/tyler/elastic/kibana/src/plugins/dashboard/jest.config.js server ---- +You can generate code coverage report for a single plugin. + +[source,bash] +---- +yarn jest --coverage --config src/plugins/console/jest.config.js +---- + +Html report is available in target/kibana-coverage/jest/path/to/plugin [discrete] === Running browser automation tests diff --git a/packages/kbn-ui-framework/README.md b/packages/kbn-ui-framework/README.md index fe36d202c5fbe..820b272cd65cb 100644 --- a/packages/kbn-ui-framework/README.md +++ b/packages/kbn-ui-framework/README.md @@ -21,4 +21,7 @@ You can run `node scripts/jest --watch` to watch for changes and run the tests a You can run `node scripts/jest --coverage` to generate a code coverage report to see how fully-tested the code is. +You can run `node scripts/jest --config path/to/plugin/jest.config.js --coverage` to generate +a code coverage report for a single plugin. + See the documentation in [`scripts/jest.js`](../scripts/jest.js) for more options. \ No newline at end of file diff --git a/src/plugins/advanced_settings/jest.config.js b/src/plugins/advanced_settings/jest.config.js index 61909cd432df4..7900d7f39b6c6 100644 --- a/src/plugins/advanced_settings/jest.config.js +++ b/src/plugins/advanced_settings/jest.config.js @@ -10,4 +10,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/advanced_settings'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/advanced_settings', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/src/plugins/advanced_settings/{public,server}/**/*.{ts,tsx}'], }; diff --git a/src/plugins/bfetch/jest.config.js b/src/plugins/bfetch/jest.config.js index 544328ed4baf3..d01c81c8f1d82 100644 --- a/src/plugins/bfetch/jest.config.js +++ b/src/plugins/bfetch/jest.config.js @@ -10,4 +10,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/bfetch'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/bfetch', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/src/plugins/bfetch/{common,public,server}/**/*.{ts,tsx}'], }; diff --git a/src/plugins/chart_expressions/expression_tagcloud/jest.config.js b/src/plugins/chart_expressions/expression_tagcloud/jest.config.js index c88c150d6f649..412a133b0d292 100644 --- a/src/plugins/chart_expressions/expression_tagcloud/jest.config.js +++ b/src/plugins/chart_expressions/expression_tagcloud/jest.config.js @@ -10,4 +10,10 @@ module.exports = { preset: '@kbn/test', rootDir: '../../../../', roots: ['/src/plugins/chart_expressions/expression_tagcloud'], + coverageDirectory: + '/target/kibana-coverage/jest/src/plugins/chart_expressions/expression_tagcloud', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/src/plugins/chart_expressions/expression_tagcloud/{common,public,server}/**/*.{ts,tsx}', + ], }; diff --git a/src/plugins/charts/jest.config.js b/src/plugins/charts/jest.config.js index b6516c520ecf6..a4469b78b3306 100644 --- a/src/plugins/charts/jest.config.js +++ b/src/plugins/charts/jest.config.js @@ -10,4 +10,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/charts'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/charts', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/src/plugins/charts/{common,public,server}/**/*.{ts,tsx}'], }; diff --git a/src/plugins/console/jest.config.js b/src/plugins/console/jest.config.js index 0fc1bcbcfb201..08dbc96e0136c 100644 --- a/src/plugins/console/jest.config.js +++ b/src/plugins/console/jest.config.js @@ -11,4 +11,7 @@ module.exports = { rootDir: '../../..', roots: ['/src/plugins/console'], testRunner: 'jasmine2', + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/console', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/src/plugins/console/{common,public,server}/**/*.{js,ts,tsx}'], }; diff --git a/src/plugins/dashboard/jest.config.js b/src/plugins/dashboard/jest.config.js index 0b9ac0428c3af..d99cfe57fcd37 100644 --- a/src/plugins/dashboard/jest.config.js +++ b/src/plugins/dashboard/jest.config.js @@ -11,4 +11,7 @@ module.exports = { rootDir: '../../..', roots: ['/src/plugins/dashboard'], testRunner: 'jasmine2', + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/dashboard', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/src/plugins/dashboard/{common,public,server}/**/*.{ts,tsx}'], }; diff --git a/src/plugins/data/jest.config.js b/src/plugins/data/jest.config.js index eba30c6cfd674..f8ab0e348376e 100644 --- a/src/plugins/data/jest.config.js +++ b/src/plugins/data/jest.config.js @@ -11,4 +11,7 @@ module.exports = { rootDir: '../../..', roots: ['/src/plugins/data'], testRunner: 'jasmine2', + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/data', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/src/plugins/data/{common,public,server}/**/*.{ts,tsx}'], }; diff --git a/src/plugins/discover/jest.config.js b/src/plugins/discover/jest.config.js index 4c0f09b2cc242..00f5d8016e3c4 100644 --- a/src/plugins/discover/jest.config.js +++ b/src/plugins/discover/jest.config.js @@ -11,4 +11,7 @@ module.exports = { rootDir: '../../..', roots: ['/src/plugins/discover'], testRunner: 'jasmine2', + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/discover', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/src/plugins/discover/{common,public,server}/**/*.{js,ts,tsx}'], }; diff --git a/src/plugins/embeddable/jest.config.js b/src/plugins/embeddable/jest.config.js index 6ac4e4486fcfd..37080a605e3d5 100644 --- a/src/plugins/embeddable/jest.config.js +++ b/src/plugins/embeddable/jest.config.js @@ -11,4 +11,7 @@ module.exports = { rootDir: '../../..', roots: ['/src/plugins/embeddable'], testRunner: 'jasmine2', + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/embeddable', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/src/plugins/embeddable/{common,public,server}/**/*.{ts,tsx}'], }; diff --git a/src/plugins/es_ui_shared/jest.config.js b/src/plugins/es_ui_shared/jest.config.js index cf525397bd75c..c311f5d9df2ed 100644 --- a/src/plugins/es_ui_shared/jest.config.js +++ b/src/plugins/es_ui_shared/jest.config.js @@ -10,4 +10,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/es_ui_shared'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/es_ui_shared', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/src/plugins/es_ui_shared/{__packages_do_not_import__,common,public,server,static}/**/*.{ts,tsx}', + ], }; diff --git a/src/plugins/expression_error/jest.config.js b/src/plugins/expression_error/jest.config.js index 64f3e9292ff07..27774f4003f9e 100644 --- a/src/plugins/expression_error/jest.config.js +++ b/src/plugins/expression_error/jest.config.js @@ -10,4 +10,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/expression_error'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/expression_error', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/src/plugins/expression_error/{common,public}/**/*.{ts,tsx}'], }; diff --git a/src/plugins/expression_image/jest.config.js b/src/plugins/expression_image/jest.config.js index 3d5bc9f184c6a..ccefa3c20699e 100644 --- a/src/plugins/expression_image/jest.config.js +++ b/src/plugins/expression_image/jest.config.js @@ -10,4 +10,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/expression_image'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/expression_image', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/src/plugins/expression_image/{common,public,server}/**/*.{ts,tsx}', + ], }; diff --git a/src/plugins/expression_metric/jest.config.js b/src/plugins/expression_metric/jest.config.js index 517409460895e..23546fc334816 100644 --- a/src/plugins/expression_metric/jest.config.js +++ b/src/plugins/expression_metric/jest.config.js @@ -10,4 +10,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/expression_metric'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/expression_metric', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/src/plugins/expression_metric/{common,public,server}/**/*.{ts,tsx}', + ], }; diff --git a/src/plugins/expression_repeat_image/jest.config.js b/src/plugins/expression_repeat_image/jest.config.js index cf1039263840b..b30d782ef6e0e 100644 --- a/src/plugins/expression_repeat_image/jest.config.js +++ b/src/plugins/expression_repeat_image/jest.config.js @@ -10,4 +10,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/expression_repeat_image'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/expression_repeat_image', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/src/plugins/expression_repeat_image/{common,public,server}/**/*.{ts,tsx}', + ], }; diff --git a/src/plugins/expression_reveal_image/jest.config.js b/src/plugins/expression_reveal_image/jest.config.js index aac5fad293846..c1d7fead721f5 100644 --- a/src/plugins/expression_reveal_image/jest.config.js +++ b/src/plugins/expression_reveal_image/jest.config.js @@ -10,4 +10,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/expression_reveal_image'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/expression_reveal_image', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/src/plugins/expression_reveal_image/{common,public,server}/**/*.{ts,tsx}', + ], }; diff --git a/src/plugins/expression_shape/jest.config.js b/src/plugins/expression_shape/jest.config.js index a390c0154bbd0..bb2603cb012eb 100644 --- a/src/plugins/expression_shape/jest.config.js +++ b/src/plugins/expression_shape/jest.config.js @@ -10,4 +10,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/expression_shape'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/expression_shape', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/src/plugins/expression_shape/{common,public,server}/**/*.{ts,tsx}', + ], }; diff --git a/src/plugins/expressions/jest.config.js b/src/plugins/expressions/jest.config.js index 721312f7d886c..24f27aadedd7b 100644 --- a/src/plugins/expressions/jest.config.js +++ b/src/plugins/expressions/jest.config.js @@ -10,4 +10,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/expressions'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/expressions', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/src/plugins/expressions/{common,public,server}/**/*.{ts,tsx}'], }; diff --git a/src/plugins/field_formats/jest.config.js b/src/plugins/field_formats/jest.config.js index ea20fcfec6d09..6fc68ab97526e 100644 --- a/src/plugins/field_formats/jest.config.js +++ b/src/plugins/field_formats/jest.config.js @@ -10,4 +10,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/field_formats'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/field_formats', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/src/plugins/field_formats/{common,public,server}/**/*.{ts,tsx}'], }; diff --git a/src/plugins/home/jest.config.js b/src/plugins/home/jest.config.js index 5107cc001d32f..c7450ebbf3104 100644 --- a/src/plugins/home/jest.config.js +++ b/src/plugins/home/jest.config.js @@ -10,4 +10,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/home'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/home', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/src/plugins/home/{common,public,server}/**/*.{js,ts,tsx}'], }; diff --git a/src/plugins/index_pattern_editor/jest.config.js b/src/plugins/index_pattern_editor/jest.config.js index 0a018a42d06e6..bdf5fd8a0e9e2 100644 --- a/src/plugins/index_pattern_editor/jest.config.js +++ b/src/plugins/index_pattern_editor/jest.config.js @@ -10,4 +10,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/index_pattern_editor'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/index_pattern_editor', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/src/plugins/index_pattern_editor/public/**/*.{ts,tsx}'], }; diff --git a/src/plugins/index_pattern_field_editor/jest.config.js b/src/plugins/index_pattern_field_editor/jest.config.js index fc358c37116c9..e1f8f57038e26 100644 --- a/src/plugins/index_pattern_field_editor/jest.config.js +++ b/src/plugins/index_pattern_field_editor/jest.config.js @@ -10,4 +10,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/index_pattern_field_editor'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/index_pattern_field_editor', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/src/plugins/index_pattern_field_editor/{common,public,server}/**/*.{ts,tsx}', + ], }; diff --git a/src/plugins/index_pattern_management/jest.config.js b/src/plugins/index_pattern_management/jest.config.js index 8383d3bb6110d..6249d44e6b31f 100644 --- a/src/plugins/index_pattern_management/jest.config.js +++ b/src/plugins/index_pattern_management/jest.config.js @@ -11,4 +11,9 @@ module.exports = { rootDir: '../../..', roots: ['/src/plugins/index_pattern_management'], testRunner: 'jasmine2', + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/index_pattern_management', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/src/plugins/index_pattern_management/{public,server}/**/*.{ts,tsx}', + ], }; diff --git a/src/plugins/input_control_vis/jest.config.js b/src/plugins/input_control_vis/jest.config.js index 060ab9ff1a126..207a0b5265417 100644 --- a/src/plugins/input_control_vis/jest.config.js +++ b/src/plugins/input_control_vis/jest.config.js @@ -10,4 +10,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/input_control_vis'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/input_control_vis', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/src/plugins/input_control_vis/public/**/*.{ts,tsx}'], }; diff --git a/src/plugins/inspector/jest.config.js b/src/plugins/inspector/jest.config.js index 67e90f449fa76..3583a69a94bd9 100644 --- a/src/plugins/inspector/jest.config.js +++ b/src/plugins/inspector/jest.config.js @@ -10,4 +10,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/inspector'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/inspector', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/src/plugins/inspector/{common,public}/**/*.{ts,tsx}'], }; diff --git a/src/plugins/interactive_setup/jest.config.js b/src/plugins/interactive_setup/jest.config.js index e9f1f479d66aa..e187f7b31e2fc 100644 --- a/src/plugins/interactive_setup/jest.config.js +++ b/src/plugins/interactive_setup/jest.config.js @@ -10,4 +10,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/interactive_setup'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/interactive_setup', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/src/plugins/interactive_setup/{common,public,server}/**/*.{ts,tsx}', + ], }; diff --git a/src/plugins/kibana_legacy/jest.config.js b/src/plugins/kibana_legacy/jest.config.js index c9b571b13f13f..a2bdf5649f900 100644 --- a/src/plugins/kibana_legacy/jest.config.js +++ b/src/plugins/kibana_legacy/jest.config.js @@ -10,4 +10,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/kibana_legacy'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/kibana_legacy', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/src/plugins/kibana_legacy/public/**/*.{js,ts,tsx}'], }; diff --git a/src/plugins/kibana_overview/jest.config.js b/src/plugins/kibana_overview/jest.config.js index 4862a4967a3ca..00cf46dfe2f80 100644 --- a/src/plugins/kibana_overview/jest.config.js +++ b/src/plugins/kibana_overview/jest.config.js @@ -10,4 +10,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/kibana_overview'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/kibana_overview', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/src/plugins/kibana_overview/{common,public}/**/*.{js,ts,tsx}'], }; diff --git a/src/plugins/kibana_react/jest.config.js b/src/plugins/kibana_react/jest.config.js index 159f7b01795dc..35bf9df51d615 100644 --- a/src/plugins/kibana_react/jest.config.js +++ b/src/plugins/kibana_react/jest.config.js @@ -10,4 +10,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/kibana_react'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/kibana_react', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/src/plugins/kibana_react/{common,public}/**/*.{ts,tsx}'], }; diff --git a/src/plugins/kibana_usage_collection/jest.config.js b/src/plugins/kibana_usage_collection/jest.config.js index f199984a6ad6d..a52c3eb8cc06c 100644 --- a/src/plugins/kibana_usage_collection/jest.config.js +++ b/src/plugins/kibana_usage_collection/jest.config.js @@ -10,4 +10,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/kibana_usage_collection'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/kibana_usage_collection', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/src/plugins/kibana_usage_collection/{common,server}/**/*.{ts,tsx}', + ], }; diff --git a/src/plugins/kibana_utils/jest.config.js b/src/plugins/kibana_utils/jest.config.js index 48b7bb62a8e68..a01ededd1e7c0 100644 --- a/src/plugins/kibana_utils/jest.config.js +++ b/src/plugins/kibana_utils/jest.config.js @@ -10,4 +10,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/kibana_utils'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/kibana_utils', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/src/plugins/kibana_utils/{common,demos,public,server}/**/*.{ts,tsx}', + ], }; diff --git a/src/plugins/management/jest.config.js b/src/plugins/management/jest.config.js index e821012e9dc2e..ee5e50a753693 100644 --- a/src/plugins/management/jest.config.js +++ b/src/plugins/management/jest.config.js @@ -10,4 +10,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/management'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/management', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/src/plugins/management/{common,public,server}/**/*.{ts,tsx}'], }; diff --git a/src/plugins/maps_ems/jest.config.js b/src/plugins/maps_ems/jest.config.js index b7021c9119deb..4e2b09bb66305 100644 --- a/src/plugins/maps_ems/jest.config.js +++ b/src/plugins/maps_ems/jest.config.js @@ -10,4 +10,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/maps_ems'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/maps_ems', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/src/plugins/maps_ems/{common,public,server}/**/*.{ts,tsx}'], }; diff --git a/src/plugins/navigation/jest.config.js b/src/plugins/navigation/jest.config.js index 98cd0e3760a17..e31374a542563 100644 --- a/src/plugins/navigation/jest.config.js +++ b/src/plugins/navigation/jest.config.js @@ -10,4 +10,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/navigation'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/navigation', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/src/plugins/navigation/public/**/*.{ts,tsx}'], }; diff --git a/src/plugins/newsfeed/jest.config.js b/src/plugins/newsfeed/jest.config.js index 580185836c978..43caa9227b9f6 100644 --- a/src/plugins/newsfeed/jest.config.js +++ b/src/plugins/newsfeed/jest.config.js @@ -10,4 +10,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/newsfeed'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/newsfeed', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/src/plugins/newsfeed/{common,public,server}/**/*.{ts,tsx}'], }; diff --git a/src/plugins/presentation_util/jest.config.js b/src/plugins/presentation_util/jest.config.js index 2250d70acb475..cb1e18fd6d736 100644 --- a/src/plugins/presentation_util/jest.config.js +++ b/src/plugins/presentation_util/jest.config.js @@ -10,4 +10,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/presentation_util'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/presentation_util', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/src/plugins/presentation_util/{common,public,server}/**/*.{ts,tsx}', + ], }; diff --git a/src/plugins/saved_objects/jest.config.js b/src/plugins/saved_objects/jest.config.js index 77848e0dc6ed5..416385af2d214 100644 --- a/src/plugins/saved_objects/jest.config.js +++ b/src/plugins/saved_objects/jest.config.js @@ -10,4 +10,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/saved_objects'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/saved_objects', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/src/plugins/saved_objects/{common,public,server}/**/*.{ts,tsx}'], }; diff --git a/src/plugins/saved_objects_management/jest.config.js b/src/plugins/saved_objects_management/jest.config.js index a8fd7db1b7b45..e986e5a310eae 100644 --- a/src/plugins/saved_objects_management/jest.config.js +++ b/src/plugins/saved_objects_management/jest.config.js @@ -10,4 +10,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/saved_objects_management'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/saved_objects_management', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/src/plugins/saved_objects_management/{common,public,server}/**/*.{ts,tsx}', + ], }; diff --git a/src/plugins/saved_objects_tagging_oss/jest.config.js b/src/plugins/saved_objects_tagging_oss/jest.config.js index adb5b1e426180..e7b571e955ef1 100644 --- a/src/plugins/saved_objects_tagging_oss/jest.config.js +++ b/src/plugins/saved_objects_tagging_oss/jest.config.js @@ -10,4 +10,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/saved_objects_tagging_oss'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/saved_objects_tagging_oss', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/src/plugins/saved_objects_tagging_oss/{common,public}/**/*.{ts,tsx}', + ], }; diff --git a/src/plugins/screenshot_mode/jest.config.js b/src/plugins/screenshot_mode/jest.config.js index e84f3742f8c1d..e108ab786739f 100644 --- a/src/plugins/screenshot_mode/jest.config.js +++ b/src/plugins/screenshot_mode/jest.config.js @@ -10,4 +10,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/screenshot_mode'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/screenshot_mode', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/src/plugins/screenshot_mode/{common,public,server}/**/*.{ts,tsx}', + ], }; diff --git a/src/plugins/security_oss/jest.config.js b/src/plugins/security_oss/jest.config.js index c62cad7e72cec..692d85f69a740 100644 --- a/src/plugins/security_oss/jest.config.js +++ b/src/plugins/security_oss/jest.config.js @@ -10,4 +10,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/security_oss'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/security_oss', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/src/plugins/security_oss/{common,public,server}/**/*.{ts,tsx}'], }; diff --git a/src/plugins/share/jest.config.js b/src/plugins/share/jest.config.js index f347067849f71..aae58e3c57d1f 100644 --- a/src/plugins/share/jest.config.js +++ b/src/plugins/share/jest.config.js @@ -10,4 +10,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/share'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/share', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/src/plugins/share/{common,public,server}/**/*.{ts,tsx}'], }; diff --git a/src/plugins/telemetry/jest.config.js b/src/plugins/telemetry/jest.config.js index 61e042b40b5d4..932c3c2851382 100644 --- a/src/plugins/telemetry/jest.config.js +++ b/src/plugins/telemetry/jest.config.js @@ -10,4 +10,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/telemetry'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/telemetry', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/src/plugins/telemetry/{common,public,server}/**/*.{ts,tsx}'], }; diff --git a/src/plugins/telemetry_collection_manager/jest.config.js b/src/plugins/telemetry_collection_manager/jest.config.js index f9615de4ab60a..7f58aa46cabf2 100644 --- a/src/plugins/telemetry_collection_manager/jest.config.js +++ b/src/plugins/telemetry_collection_manager/jest.config.js @@ -10,4 +10,10 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/telemetry_collection_manager'], + coverageDirectory: + '/target/kibana-coverage/jest/src/plugins/telemetry_collection_manager', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/src/plugins/telemetry_collection_manager/{common,server}/**/*.{ts,tsx}', + ], }; diff --git a/src/plugins/telemetry_management_section/jest.config.js b/src/plugins/telemetry_management_section/jest.config.js index e1001bc787589..722496905de9e 100644 --- a/src/plugins/telemetry_management_section/jest.config.js +++ b/src/plugins/telemetry_management_section/jest.config.js @@ -10,4 +10,8 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/telemetry_management_section'], + coverageDirectory: + '/target/kibana-coverage/jest/src/plugins/telemetry_management_section', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/src/plugins/telemetry_management_section/public/**/*.{ts,tsx}'], }; diff --git a/src/plugins/ui_actions/jest.config.js b/src/plugins/ui_actions/jest.config.js index 8ee6a40e19541..f482574316632 100644 --- a/src/plugins/ui_actions/jest.config.js +++ b/src/plugins/ui_actions/jest.config.js @@ -10,4 +10,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/ui_actions'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/ui_actions', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/src/plugins/ui_actions/public/**/*.{ts,tsx}'], }; diff --git a/src/plugins/url_forwarding/jest.config.js b/src/plugins/url_forwarding/jest.config.js index 5e452d70753d5..24a72465626f6 100644 --- a/src/plugins/url_forwarding/jest.config.js +++ b/src/plugins/url_forwarding/jest.config.js @@ -10,4 +10,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/url_forwarding'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/url_forwarding', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/src/plugins/url_forwarding/public/**/*.{ts,tsx}'], }; diff --git a/src/plugins/usage_collection/jest.config.js b/src/plugins/usage_collection/jest.config.js index 25994eeec9820..f93d12327cc1b 100644 --- a/src/plugins/usage_collection/jest.config.js +++ b/src/plugins/usage_collection/jest.config.js @@ -10,4 +10,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/usage_collection'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/usage_collection', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/src/plugins/usage_collection/{common,public,server}/**/*.{ts,tsx}', + ], }; diff --git a/src/plugins/vis_default_editor/jest.config.js b/src/plugins/vis_default_editor/jest.config.js index 52276e29c46c4..c921db167c1e9 100644 --- a/src/plugins/vis_default_editor/jest.config.js +++ b/src/plugins/vis_default_editor/jest.config.js @@ -10,4 +10,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/vis_default_editor'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/vis_default_editor', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/src/plugins/vis_default_editor/public/**/*.{ts,tsx}'], }; diff --git a/src/plugins/vis_type_markdown/jest.config.js b/src/plugins/vis_type_markdown/jest.config.js index 8c73fde8d6618..835d37312eadd 100644 --- a/src/plugins/vis_type_markdown/jest.config.js +++ b/src/plugins/vis_type_markdown/jest.config.js @@ -10,4 +10,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/vis_type_markdown'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/vis_type_markdown', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/src/plugins/vis_type_markdown/{public,server}/**/*.{ts,tsx}'], }; diff --git a/src/plugins/vis_type_table/jest.config.js b/src/plugins/vis_type_table/jest.config.js index 9c91b1b813e52..a5a925eada3f1 100644 --- a/src/plugins/vis_type_table/jest.config.js +++ b/src/plugins/vis_type_table/jest.config.js @@ -11,5 +11,9 @@ module.exports = { rootDir: '../../..', roots: ['/src/plugins/vis_type_table'], testRunner: 'jasmine2', - collectCoverageFrom: ['/src/plugins/vis_type_table/**/*.{js,ts,tsx}'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/vis_type_table', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/src/plugins/vis_type_table/{common,public,server}/**/*.{js,ts,tsx}', + ], }; diff --git a/src/plugins/vis_type_timelion/jest.config.js b/src/plugins/vis_type_timelion/jest.config.js index ed4eedaee2fbf..5da416935adb9 100644 --- a/src/plugins/vis_type_timelion/jest.config.js +++ b/src/plugins/vis_type_timelion/jest.config.js @@ -10,4 +10,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/vis_type_timelion'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/vis_type_timelion', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/src/plugins/vis_type_timelion/{common,public,server}/**/*.{js,ts,tsx}', + ], }; diff --git a/src/plugins/vis_type_timeseries/jest.config.js b/src/plugins/vis_type_timeseries/jest.config.js index 5007d995edc44..3d4333675f7d7 100644 --- a/src/plugins/vis_type_timeseries/jest.config.js +++ b/src/plugins/vis_type_timeseries/jest.config.js @@ -10,4 +10,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/vis_type_timeseries'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/vis_type_timeseries', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/src/plugins/vis_type_timeseries/{common,public,server}/**/*.{js,ts,tsx}', + ], }; diff --git a/src/plugins/vis_types/metric/jest.config.js b/src/plugins/vis_types/metric/jest.config.js index a84929a3805b8..e6de1dd63b34d 100644 --- a/src/plugins/vis_types/metric/jest.config.js +++ b/src/plugins/vis_types/metric/jest.config.js @@ -10,4 +10,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../../..', roots: ['/src/plugins/vis_types/metric'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/vis_types/metric', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/src/plugins/vis_types/metric/{public,server}/**/*.{ts,tsx}'], }; diff --git a/src/plugins/vis_types/pie/jest.config.js b/src/plugins/vis_types/pie/jest.config.js index 505ea97f489f7..d9afd1d718c85 100644 --- a/src/plugins/vis_types/pie/jest.config.js +++ b/src/plugins/vis_types/pie/jest.config.js @@ -10,4 +10,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../../..', roots: ['/src/plugins/vis_types/pie'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/vis_types/pie', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/src/plugins/vis_types/pie/{common,public,server}/**/*.{ts,tsx}'], }; diff --git a/src/plugins/vis_types/tagcloud/jest.config.js b/src/plugins/vis_types/tagcloud/jest.config.js index 20dfd8ad0d11c..9785690d5e8b4 100644 --- a/src/plugins/vis_types/tagcloud/jest.config.js +++ b/src/plugins/vis_types/tagcloud/jest.config.js @@ -11,4 +11,7 @@ module.exports = { rootDir: '../../../..', roots: ['/src/plugins/vis_types/tagcloud'], testRunner: 'jasmine2', + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/vis_types/tagcloud', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/src/plugins/vis_types/tagcloud/{public,server}/**/*.{ts,tsx}'], }; diff --git a/src/plugins/vis_types/vega/jest.config.js b/src/plugins/vis_types/vega/jest.config.js index d7e1653e891a5..33c2d8e7aa1ed 100644 --- a/src/plugins/vis_types/vega/jest.config.js +++ b/src/plugins/vis_types/vega/jest.config.js @@ -10,4 +10,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../../..', roots: ['/src/plugins/vis_types/vega'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/vis_types/vega', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/src/plugins/vis_types/vega/{public,server}/**/*.{js,ts,tsx}'], }; diff --git a/src/plugins/vis_types/vislib/jest.config.js b/src/plugins/vis_types/vislib/jest.config.js index 6b6d7c3361ecf..cc80a320765d8 100644 --- a/src/plugins/vis_types/vislib/jest.config.js +++ b/src/plugins/vis_types/vislib/jest.config.js @@ -10,4 +10,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../../..', roots: ['/src/plugins/vis_types/vislib'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/vis_types/vislib', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/src/plugins/vis_types/vislib/{common,public,server}/**/*.{js,ts,tsx}', + ], }; diff --git a/src/plugins/vis_types/xy/jest.config.js b/src/plugins/vis_types/xy/jest.config.js index 57b041b575e3f..4cdb8f44012c7 100644 --- a/src/plugins/vis_types/xy/jest.config.js +++ b/src/plugins/vis_types/xy/jest.config.js @@ -10,4 +10,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../../..', roots: ['/src/plugins/vis_types/xy'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/vis_types/xy', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/src/plugins/vis_types/xy/{common,public,server}/**/*.{ts,tsx}'], }; diff --git a/src/plugins/visualizations/jest.config.js b/src/plugins/visualizations/jest.config.js index 250bdc44e4de5..450e30a1de24d 100644 --- a/src/plugins/visualizations/jest.config.js +++ b/src/plugins/visualizations/jest.config.js @@ -10,4 +10,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/visualizations'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/visualizations', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/src/plugins/visualizations/{common,public,server}/**/*.{js,ts,tsx}', + ], }; diff --git a/src/plugins/visualize/jest.config.js b/src/plugins/visualize/jest.config.js index 22a9ffa161253..11ea368f57d25 100644 --- a/src/plugins/visualize/jest.config.js +++ b/src/plugins/visualize/jest.config.js @@ -10,4 +10,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/visualize'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/visualize', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/src/plugins/visualize/{common,public,server}/**/*.{ts,tsx}'], }; diff --git a/x-pack/plugins/actions/jest.config.js b/x-pack/plugins/actions/jest.config.js index 3a9fb5019494a..2d3372a91890a 100644 --- a/x-pack/plugins/actions/jest.config.js +++ b/x-pack/plugins/actions/jest.config.js @@ -9,4 +9,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/actions'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/actions', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/x-pack/plugins/actions/{common,server}/**/*.{js,ts,tsx}'], }; diff --git a/x-pack/plugins/alerting/jest.config.js b/x-pack/plugins/alerting/jest.config.js index 1f34005415cca..05db974299b40 100644 --- a/x-pack/plugins/alerting/jest.config.js +++ b/x-pack/plugins/alerting/jest.config.js @@ -9,4 +9,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/alerting'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/alerting', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/x-pack/plugins/alerting/{common,public,server}/**/*.{ts,tsx}'], }; diff --git a/x-pack/plugins/apm/jest.config.js b/x-pack/plugins/apm/jest.config.js index 5bce9bbfb5b1b..77639cb58d497 100644 --- a/x-pack/plugins/apm/jest.config.js +++ b/x-pack/plugins/apm/jest.config.js @@ -13,4 +13,9 @@ module.exports = { roots: ['/x-pack/plugins/apm'], setupFiles: ['/x-pack/plugins/apm/.storybook/jest_setup.js'], testPathIgnorePatterns: ['/x-pack/plugins/apm/e2e/'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/apm', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/x-pack/plugins/apm/{common,public,server}/**/*.{js,ts,tsx}', + ], }; diff --git a/x-pack/plugins/banners/jest.config.js b/x-pack/plugins/banners/jest.config.js index e2d103c8e4a28..291bdb3436295 100644 --- a/x-pack/plugins/banners/jest.config.js +++ b/x-pack/plugins/banners/jest.config.js @@ -9,4 +9,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/banners'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/banners', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/x-pack/plugins/banners/{common,public,server}/**/*.{ts,tsx}'], }; diff --git a/x-pack/plugins/canvas/jest.config.js b/x-pack/plugins/canvas/jest.config.js index 7524e06159a41..2bff284e94ad8 100644 --- a/x-pack/plugins/canvas/jest.config.js +++ b/x-pack/plugins/canvas/jest.config.js @@ -12,4 +12,9 @@ module.exports = { transform: { '^.+\\.stories\\.tsx?$': '@storybook/addon-storyshots/injectFileName', }, + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/canvas', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/x-pack/plugins/canvas/{canvas_plugin_src,common,i18n,public,server,shareable_runtime}/**/*.{js,ts,tsx}', + ], }; diff --git a/x-pack/plugins/cases/jest.config.js b/x-pack/plugins/cases/jest.config.js index 6368eb8895ad1..3b1b0b1223191 100644 --- a/x-pack/plugins/cases/jest.config.js +++ b/x-pack/plugins/cases/jest.config.js @@ -9,4 +9,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/cases'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/cases', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/x-pack/plugins/cases/{common,public,server}/**/*.{ts,tsx}'], }; diff --git a/x-pack/plugins/cloud/jest.config.js b/x-pack/plugins/cloud/jest.config.js index 68f63b4d8b5ac..4235e79e79268 100644 --- a/x-pack/plugins/cloud/jest.config.js +++ b/x-pack/plugins/cloud/jest.config.js @@ -9,4 +9,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/cloud'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/cloud', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/x-pack/plugins/cloud/{common,public,server}/**/*.{ts,tsx}'], }; diff --git a/x-pack/plugins/cross_cluster_replication/jest.config.js b/x-pack/plugins/cross_cluster_replication/jest.config.js index 8d39781213dbd..87d557b57a6a7 100644 --- a/x-pack/plugins/cross_cluster_replication/jest.config.js +++ b/x-pack/plugins/cross_cluster_replication/jest.config.js @@ -9,4 +9,10 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/cross_cluster_replication'], + coverageDirectory: + '/target/kibana-coverage/jest/x-pack/plugins/cross_cluster_replication', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/x-pack/plugins/cross_cluster_replication/{common,public,server}/**/*.{js,ts,tsx}', + ], }; diff --git a/x-pack/plugins/dashboard_enhanced/jest.config.js b/x-pack/plugins/dashboard_enhanced/jest.config.js index 8ade9e0a09f5e..86ae949431e69 100644 --- a/x-pack/plugins/dashboard_enhanced/jest.config.js +++ b/x-pack/plugins/dashboard_enhanced/jest.config.js @@ -9,4 +9,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/dashboard_enhanced'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/dashboard_enhanced', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/x-pack/plugins/dashboard_enhanced/{common,public,server}/**/*.{ts,tsx}', + ], }; diff --git a/x-pack/plugins/data_enhanced/jest.config.js b/x-pack/plugins/data_enhanced/jest.config.js index 62b54b1ba36bc..e48de352c2075 100644 --- a/x-pack/plugins/data_enhanced/jest.config.js +++ b/x-pack/plugins/data_enhanced/jest.config.js @@ -9,4 +9,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/data_enhanced'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/data_enhanced', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/x-pack/plugins/data_enhanced/{common,public,server}/**/*.{ts,tsx}', + ], }; diff --git a/x-pack/plugins/data_visualizer/jest.config.js b/x-pack/plugins/data_visualizer/jest.config.js index 1c4974471bd79..46de590b709bb 100644 --- a/x-pack/plugins/data_visualizer/jest.config.js +++ b/x-pack/plugins/data_visualizer/jest.config.js @@ -9,4 +9,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/data_visualizer'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/data_visualizer', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/x-pack/plugins/data_visualizer/{common,public,server}/**/*.{js,ts,tsx}', + ], }; diff --git a/x-pack/plugins/discover_enhanced/jest.config.js b/x-pack/plugins/discover_enhanced/jest.config.js index 7ef1b0e858ef1..603298832dd61 100644 --- a/x-pack/plugins/discover_enhanced/jest.config.js +++ b/x-pack/plugins/discover_enhanced/jest.config.js @@ -9,4 +9,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/discover_enhanced'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/discover_enhanced', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/x-pack/plugins/discover_enhanced/{common,public,server}/**/*.{ts,tsx}', + ], }; diff --git a/x-pack/plugins/drilldowns/jest.config.js b/x-pack/plugins/drilldowns/jest.config.js index 39259ca43b3b8..a5db93a916ebb 100644 --- a/x-pack/plugins/drilldowns/jest.config.js +++ b/x-pack/plugins/drilldowns/jest.config.js @@ -9,4 +9,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/drilldowns'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/drilldowns', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/x-pack/plugins/drilldowns/url_drilldown/public/**/*.{ts,tsx}'], }; diff --git a/x-pack/plugins/embeddable_enhanced/jest.config.js b/x-pack/plugins/embeddable_enhanced/jest.config.js index 47b539ca226cd..fc9eaec5c972c 100644 --- a/x-pack/plugins/embeddable_enhanced/jest.config.js +++ b/x-pack/plugins/embeddable_enhanced/jest.config.js @@ -9,4 +9,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/embeddable_enhanced'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/embeddable_enhanced', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/x-pack/plugins/embeddable_enhanced/public/**/*.{ts,tsx}'], }; diff --git a/x-pack/plugins/encrypted_saved_objects/jest.config.js b/x-pack/plugins/encrypted_saved_objects/jest.config.js index 213484c8e159d..78bfae78227db 100644 --- a/x-pack/plugins/encrypted_saved_objects/jest.config.js +++ b/x-pack/plugins/encrypted_saved_objects/jest.config.js @@ -9,4 +9,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/encrypted_saved_objects'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/encrypted_saved_objects', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/x-pack/plugins/encrypted_saved_objects/server/**/*.{ts,tsx}'], }; diff --git a/x-pack/plugins/enterprise_search/jest.config.js b/x-pack/plugins/enterprise_search/jest.config.js index 7d10d7aa87bf2..263713697b7e0 100644 --- a/x-pack/plugins/enterprise_search/jest.config.js +++ b/x-pack/plugins/enterprise_search/jest.config.js @@ -10,11 +10,12 @@ module.exports = { rootDir: '../../..', roots: ['/x-pack/plugins/enterprise_search'], collectCoverage: true, - coverageReporters: ['text'], + coverageReporters: ['text', 'html'], collectCoverageFrom: [ '/x-pack/plugins/enterprise_search/**/*.{ts,tsx}', '!/x-pack/plugins/enterprise_search/public/*.ts', '!/x-pack/plugins/enterprise_search/server/*.ts', '!/x-pack/plugins/enterprise_search/public/applications/test_helpers/**/*.{ts,tsx}', ], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/enterprise_search', }; diff --git a/x-pack/plugins/event_log/jest.config.js b/x-pack/plugins/event_log/jest.config.js index de892b297deb9..c8bf86db09e0f 100644 --- a/x-pack/plugins/event_log/jest.config.js +++ b/x-pack/plugins/event_log/jest.config.js @@ -9,4 +9,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/event_log'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/event_log', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/x-pack/plugins/event_log/{common,server}/**/*.{ts,tsx}'], }; diff --git a/x-pack/plugins/features/jest.config.js b/x-pack/plugins/features/jest.config.js index c39da2a15d2a2..7d333047c491f 100644 --- a/x-pack/plugins/features/jest.config.js +++ b/x-pack/plugins/features/jest.config.js @@ -9,4 +9,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/features'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/features', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/x-pack/plugins/features/{common,public,server}/**/*.{ts,tsx}'], }; diff --git a/x-pack/plugins/file_upload/jest.config.js b/x-pack/plugins/file_upload/jest.config.js index b9a58c259b317..92b3c27c74f11 100644 --- a/x-pack/plugins/file_upload/jest.config.js +++ b/x-pack/plugins/file_upload/jest.config.js @@ -9,4 +9,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/file_upload'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/file_upload', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/x-pack/plugins/file_upload/{common,public,server}/**/*.{js,ts,tsx}', + ], }; diff --git a/x-pack/plugins/fleet/jest.config.js b/x-pack/plugins/fleet/jest.config.js index f55b9b45140bf..5443318d52c8d 100644 --- a/x-pack/plugins/fleet/jest.config.js +++ b/x-pack/plugins/fleet/jest.config.js @@ -9,4 +9,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/fleet'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/fleet', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/x-pack/plugins/fleet/{common,public,server}/**/*.{ts,tsx}'], }; diff --git a/x-pack/plugins/global_search/jest.config.js b/x-pack/plugins/global_search/jest.config.js index ed945fcb8e605..ba4c8130c375c 100644 --- a/x-pack/plugins/global_search/jest.config.js +++ b/x-pack/plugins/global_search/jest.config.js @@ -9,4 +9,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/global_search'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/global_search', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/x-pack/plugins/global_search/{common,public,server}/**/*.{ts,tsx}', + ], }; diff --git a/x-pack/plugins/global_search_bar/jest.config.js b/x-pack/plugins/global_search_bar/jest.config.js index 73cf5402a83a9..e00903df125c9 100644 --- a/x-pack/plugins/global_search_bar/jest.config.js +++ b/x-pack/plugins/global_search_bar/jest.config.js @@ -9,4 +9,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/global_search_bar'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/global_search_bar', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/x-pack/plugins/global_search_bar/public/**/*.{ts,tsx}'], }; diff --git a/x-pack/plugins/global_search_providers/jest.config.js b/x-pack/plugins/global_search_providers/jest.config.js index b45fb5cdaa401..231b444585b03 100644 --- a/x-pack/plugins/global_search_providers/jest.config.js +++ b/x-pack/plugins/global_search_providers/jest.config.js @@ -9,4 +9,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/global_search_providers'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/global_search_providers', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/x-pack/plugins/global_search_providers/{public,server}/**/*.{ts,tsx}', + ], }; diff --git a/x-pack/plugins/graph/jest.config.js b/x-pack/plugins/graph/jest.config.js index 8a4f3db30b04a..bd9c9d0938686 100644 --- a/x-pack/plugins/graph/jest.config.js +++ b/x-pack/plugins/graph/jest.config.js @@ -9,4 +9,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/graph'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/graph', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/x-pack/plugins/graph/{common,public,server}/**/*.{js,ts,tsx}'], }; diff --git a/x-pack/plugins/grokdebugger/jest.config.js b/x-pack/plugins/grokdebugger/jest.config.js index 3785cec03b410..56cd0339a7afd 100644 --- a/x-pack/plugins/grokdebugger/jest.config.js +++ b/x-pack/plugins/grokdebugger/jest.config.js @@ -9,4 +9,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/grokdebugger'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/grokdebugger', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/x-pack/plugins/grokdebugger/{common,public,server}/**/*.{js,ts,tsx}', + ], }; diff --git a/x-pack/plugins/index_lifecycle_management/jest.config.js b/x-pack/plugins/index_lifecycle_management/jest.config.js index 94bbdbdc71e74..ec594e214106d 100644 --- a/x-pack/plugins/index_lifecycle_management/jest.config.js +++ b/x-pack/plugins/index_lifecycle_management/jest.config.js @@ -9,4 +9,10 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/index_lifecycle_management'], + coverageDirectory: + '/target/kibana-coverage/jest/x-pack/plugins/index_lifecycle_management', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/x-pack/plugins/index_lifecycle_management/{common,public,server}/**/*.{ts,tsx}', + ], }; diff --git a/x-pack/plugins/index_management/jest.config.js b/x-pack/plugins/index_management/jest.config.js index 8c7eef134d9bf..8cd0af1f81147 100644 --- a/x-pack/plugins/index_management/jest.config.js +++ b/x-pack/plugins/index_management/jest.config.js @@ -9,4 +9,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/index_management'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/index_management', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/x-pack/plugins/index_management/{common,public,server}/**/*.{js,ts,tsx}', + ], }; diff --git a/x-pack/plugins/infra/jest.config.js b/x-pack/plugins/infra/jest.config.js index ccc2f5b693a20..5631bc25a1452 100644 --- a/x-pack/plugins/infra/jest.config.js +++ b/x-pack/plugins/infra/jest.config.js @@ -9,4 +9,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/infra'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/infra', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/x-pack/plugins/infra/{common,public,server}/**/*.{ts,tsx}'], }; diff --git a/x-pack/plugins/ingest_pipelines/jest.config.js b/x-pack/plugins/ingest_pipelines/jest.config.js index ba22288685801..e3e76e54a610d 100644 --- a/x-pack/plugins/ingest_pipelines/jest.config.js +++ b/x-pack/plugins/ingest_pipelines/jest.config.js @@ -9,4 +9,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/ingest_pipelines'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/ingest_pipelines', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/x-pack/plugins/ingest_pipelines/{common,public,server}/**/*.{ts,tsx}', + ], }; diff --git a/x-pack/plugins/lens/jest.config.js b/x-pack/plugins/lens/jest.config.js index 615e540eaedce..f1164df4eab86 100644 --- a/x-pack/plugins/lens/jest.config.js +++ b/x-pack/plugins/lens/jest.config.js @@ -9,4 +9,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/lens'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/lens', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/x-pack/plugins/lens/{common,public,server}/**/*.{ts,tsx}'], }; diff --git a/x-pack/plugins/license_api_guard/jest.config.js b/x-pack/plugins/license_api_guard/jest.config.js index e0f348ceabd85..c6c1bc1bd501a 100644 --- a/x-pack/plugins/license_api_guard/jest.config.js +++ b/x-pack/plugins/license_api_guard/jest.config.js @@ -9,4 +9,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/license_api_guard'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/license_api_guard', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/x-pack/plugins/license_api_guard/server/**/*.{ts,tsx}'], }; diff --git a/x-pack/plugins/license_management/jest.config.js b/x-pack/plugins/license_management/jest.config.js index b0ce5947f3cec..59634448ee26c 100644 --- a/x-pack/plugins/license_management/jest.config.js +++ b/x-pack/plugins/license_management/jest.config.js @@ -9,4 +9,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/license_management'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/license_management', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/x-pack/plugins/license_management/{common,public,server}/**/*.{js,ts,tsx}', + ], }; diff --git a/x-pack/plugins/licensing/jest.config.js b/x-pack/plugins/licensing/jest.config.js index d497f6c7fb05b..5c5276534ebed 100644 --- a/x-pack/plugins/licensing/jest.config.js +++ b/x-pack/plugins/licensing/jest.config.js @@ -9,4 +9,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/licensing'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/licensing', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/x-pack/plugins/licensing/{common,public,server}/**/*.{ts,tsx}'], }; diff --git a/x-pack/plugins/lists/jest.config.js b/x-pack/plugins/lists/jest.config.js index c05b17f57cf7e..cb9832920183f 100644 --- a/x-pack/plugins/lists/jest.config.js +++ b/x-pack/plugins/lists/jest.config.js @@ -6,6 +6,9 @@ */ module.exports = { + collectCoverageFrom: ['/x-pack/plugins/lists/{common,public,server}/**/*.{ts,tsx}'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/lists', + coverageReporters: ['text', 'html'], preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/lists'], diff --git a/x-pack/plugins/logstash/jest.config.js b/x-pack/plugins/logstash/jest.config.js index 98d7f8ccae9c7..7296aa46adbb0 100644 --- a/x-pack/plugins/logstash/jest.config.js +++ b/x-pack/plugins/logstash/jest.config.js @@ -9,4 +9,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/logstash'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/logstash', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/x-pack/plugins/logstash/{common,public,server}/**/*.{js,ts,tsx}', + ], }; diff --git a/x-pack/plugins/maps/jest.config.js b/x-pack/plugins/maps/jest.config.js index 9e620095af880..c9bd7bf4cd0d4 100644 --- a/x-pack/plugins/maps/jest.config.js +++ b/x-pack/plugins/maps/jest.config.js @@ -9,4 +9,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/maps'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/maps', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/x-pack/plugins/maps/{common,public,server}/**/*.{js,ts,tsx}'], }; diff --git a/x-pack/plugins/metrics_entities/jest.config.js b/x-pack/plugins/metrics_entities/jest.config.js index 402532aa44c41..98a391223cc0f 100644 --- a/x-pack/plugins/metrics_entities/jest.config.js +++ b/x-pack/plugins/metrics_entities/jest.config.js @@ -6,6 +6,9 @@ */ module.exports = { + collectCoverageFrom: ['/x-pack/plugins/metrics_entities/{common,server}/**/*.{ts,tsx}'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/metrics_entities', + coverageReporters: ['text', 'html'], preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/metrics_entities'], diff --git a/x-pack/plugins/ml/jest.config.js b/x-pack/plugins/ml/jest.config.js index 2d162c1bdcb93..463fb9fb856cb 100644 --- a/x-pack/plugins/ml/jest.config.js +++ b/x-pack/plugins/ml/jest.config.js @@ -9,4 +9,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/ml'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/ml', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/x-pack/plugins/ml/{common,public,server}/**/*.{js,ts,tsx}'], }; diff --git a/x-pack/plugins/monitoring/jest.config.js b/x-pack/plugins/monitoring/jest.config.js index 76b32a2409d3a..772b1ff1e5810 100644 --- a/x-pack/plugins/monitoring/jest.config.js +++ b/x-pack/plugins/monitoring/jest.config.js @@ -9,4 +9,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/monitoring'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/monitoring', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/x-pack/plugins/monitoring/{common,public,server}/**/*.{js,ts,tsx}', + ], }; diff --git a/x-pack/plugins/observability/jest.config.js b/x-pack/plugins/observability/jest.config.js index 6fdeab06df053..39d8067d0efe4 100644 --- a/x-pack/plugins/observability/jest.config.js +++ b/x-pack/plugins/observability/jest.config.js @@ -10,4 +10,9 @@ module.exports = { rootDir: '../../..', roots: ['/x-pack/plugins/observability'], setupFiles: ['/x-pack/plugins/observability/.storybook/jest_setup.js'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/observability', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/x-pack/plugins/observability/{common,public,server}/**/*.{js,ts,tsx}', + ], }; diff --git a/x-pack/plugins/osquery/jest.config.js b/x-pack/plugins/osquery/jest.config.js index 7158ccc51aaf9..ea070e615b6bc 100644 --- a/x-pack/plugins/osquery/jest.config.js +++ b/x-pack/plugins/osquery/jest.config.js @@ -9,4 +9,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/osquery'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/osquery', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/x-pack/plugins/osquery/{common,public,server}/**/*.{ts,tsx}'], }; diff --git a/x-pack/plugins/painless_lab/jest.config.js b/x-pack/plugins/painless_lab/jest.config.js index 2ca58ad18fc2d..364e9e5a08fa4 100644 --- a/x-pack/plugins/painless_lab/jest.config.js +++ b/x-pack/plugins/painless_lab/jest.config.js @@ -9,4 +9,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/painless_lab'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/painless_lab', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/x-pack/plugins/painless_lab/{common,public,server}/**/*.{ts,tsx}', + ], }; diff --git a/x-pack/plugins/remote_clusters/jest.config.js b/x-pack/plugins/remote_clusters/jest.config.js index 50c5195cdc16a..3467ea1d5b405 100644 --- a/x-pack/plugins/remote_clusters/jest.config.js +++ b/x-pack/plugins/remote_clusters/jest.config.js @@ -9,4 +9,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/remote_clusters'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/remote_clusters', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/x-pack/plugins/remote_clusters/{common,public,server}/**/*.{js,ts,tsx}', + ], }; diff --git a/x-pack/plugins/reporting/jest.config.js b/x-pack/plugins/reporting/jest.config.js index 1968c565934a9..4354377fc26cd 100644 --- a/x-pack/plugins/reporting/jest.config.js +++ b/x-pack/plugins/reporting/jest.config.js @@ -9,4 +9,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/reporting'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/reporting', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/x-pack/plugins/reporting/{common,public,server}/**/*.{js,ts,tsx}', + ], }; diff --git a/x-pack/plugins/rollup/jest.config.js b/x-pack/plugins/rollup/jest.config.js index 5566868f65952..937ff3524f9d6 100644 --- a/x-pack/plugins/rollup/jest.config.js +++ b/x-pack/plugins/rollup/jest.config.js @@ -9,4 +9,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/rollup'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/rollup', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/x-pack/plugins/rollup/{common,public,server}/**/*.{js,ts,tsx}'], }; diff --git a/x-pack/plugins/rule_registry/jest.config.js b/x-pack/plugins/rule_registry/jest.config.js index df8ac522e4b5d..463204b32e29f 100644 --- a/x-pack/plugins/rule_registry/jest.config.js +++ b/x-pack/plugins/rule_registry/jest.config.js @@ -9,4 +9,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/rule_registry'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/rule_registry', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/x-pack/plugins/rule_registry/{common,server}/**/*.{ts,tsx}'], }; diff --git a/x-pack/plugins/runtime_fields/jest.config.js b/x-pack/plugins/runtime_fields/jest.config.js index 5c4b71d99224b..3af90818280cf 100644 --- a/x-pack/plugins/runtime_fields/jest.config.js +++ b/x-pack/plugins/runtime_fields/jest.config.js @@ -9,4 +9,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/runtime_fields'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/runtime_fields', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/x-pack/plugins/runtime_fields/public/**/*.{ts,tsx}'], }; diff --git a/x-pack/plugins/saved_objects_tagging/jest.config.js b/x-pack/plugins/saved_objects_tagging/jest.config.js index a2bf58c4c3002..2a2d0371267e3 100644 --- a/x-pack/plugins/saved_objects_tagging/jest.config.js +++ b/x-pack/plugins/saved_objects_tagging/jest.config.js @@ -9,4 +9,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/saved_objects_tagging'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/saved_objects_tagging', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/x-pack/plugins/saved_objects_tagging/{common,public,server}/**/*.{ts,tsx}', + ], }; diff --git a/x-pack/plugins/searchprofiler/jest.config.js b/x-pack/plugins/searchprofiler/jest.config.js index e6f3cd3744f18..3071f75c18d96 100644 --- a/x-pack/plugins/searchprofiler/jest.config.js +++ b/x-pack/plugins/searchprofiler/jest.config.js @@ -9,4 +9,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/searchprofiler'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/searchprofiler', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/x-pack/plugins/searchprofiler/{common,public,server}/**/*.{ts,tsx}', + ], }; diff --git a/x-pack/plugins/security/jest.config.js b/x-pack/plugins/security/jest.config.js index e31b17583ffca..bc9a651eb78bf 100644 --- a/x-pack/plugins/security/jest.config.js +++ b/x-pack/plugins/security/jest.config.js @@ -9,4 +9,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/security'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/security', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/x-pack/plugins/security/{common,public,server}/**/*.{ts,tsx}'], }; diff --git a/x-pack/plugins/security_solution/jest.config.js b/x-pack/plugins/security_solution/jest.config.js index 700eaebf6c202..6cfcb65bb5d68 100644 --- a/x-pack/plugins/security_solution/jest.config.js +++ b/x-pack/plugins/security_solution/jest.config.js @@ -9,4 +9,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/security_solution'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/security_solution', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/x-pack/plugins/security_solution/{common,public,server}/**/*.{ts,tsx}', + ], }; diff --git a/x-pack/plugins/snapshot_restore/jest.config.js b/x-pack/plugins/snapshot_restore/jest.config.js index f1c9213047ad5..b7dbd6f6c5786 100644 --- a/x-pack/plugins/snapshot_restore/jest.config.js +++ b/x-pack/plugins/snapshot_restore/jest.config.js @@ -9,4 +9,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/snapshot_restore'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/snapshot_restore', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/x-pack/plugins/snapshot_restore/{common,public,server}/**/*.{ts,tsx}', + ], }; diff --git a/x-pack/plugins/spaces/jest.config.js b/x-pack/plugins/spaces/jest.config.js index 4629d714d6d69..791f82af86ce0 100644 --- a/x-pack/plugins/spaces/jest.config.js +++ b/x-pack/plugins/spaces/jest.config.js @@ -9,4 +9,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/spaces'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/spaces', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/x-pack/plugins/spaces/{common,public,server}/**/*.{ts,tsx}'], }; diff --git a/x-pack/plugins/stack_alerts/jest.config.js b/x-pack/plugins/stack_alerts/jest.config.js index 3d03438e02c09..f2f53fd9e0050 100644 --- a/x-pack/plugins/stack_alerts/jest.config.js +++ b/x-pack/plugins/stack_alerts/jest.config.js @@ -9,4 +9,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/stack_alerts'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/stack_alerts', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/x-pack/plugins/stack_alerts/{common,public,server}/**/*.{ts,tsx}', + ], }; diff --git a/x-pack/plugins/task_manager/jest.config.js b/x-pack/plugins/task_manager/jest.config.js index 49293eb21153a..416709552bd37 100644 --- a/x-pack/plugins/task_manager/jest.config.js +++ b/x-pack/plugins/task_manager/jest.config.js @@ -9,4 +9,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/task_manager'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/task_manager', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/x-pack/plugins/task_manager/server/**/*.{ts,tsx}'], }; diff --git a/x-pack/plugins/telemetry_collection_xpack/jest.config.js b/x-pack/plugins/telemetry_collection_xpack/jest.config.js index 1f8e83ab2d86e..94f0906c2149e 100644 --- a/x-pack/plugins/telemetry_collection_xpack/jest.config.js +++ b/x-pack/plugins/telemetry_collection_xpack/jest.config.js @@ -9,4 +9,8 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/telemetry_collection_xpack'], + coverageDirectory: + '/target/kibana-coverage/jest/x-pack/plugins/telemetry_collection_xpack', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/x-pack/plugins/telemetry_collection_xpack/server/**/*.{ts,tsx}'], }; diff --git a/x-pack/plugins/timelines/jest.config.js b/x-pack/plugins/timelines/jest.config.js index 12bc67dbb2f07..d26134d924e1d 100644 --- a/x-pack/plugins/timelines/jest.config.js +++ b/x-pack/plugins/timelines/jest.config.js @@ -9,4 +9,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/timelines'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/timelines', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/x-pack/plugins/timelines/{common,public,server}/**/*.{ts,tsx}'], }; diff --git a/x-pack/plugins/transform/jest.config.js b/x-pack/plugins/transform/jest.config.js index 6b6a57d433392..2732cd66e2c94 100644 --- a/x-pack/plugins/transform/jest.config.js +++ b/x-pack/plugins/transform/jest.config.js @@ -9,4 +9,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/transform'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/transform', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/x-pack/plugins/transform/{common,public,server}/**/*.{ts,tsx}'], }; diff --git a/x-pack/plugins/triggers_actions_ui/jest.config.js b/x-pack/plugins/triggers_actions_ui/jest.config.js index 38bced1dafb43..f6369b6b2b97e 100644 --- a/x-pack/plugins/triggers_actions_ui/jest.config.js +++ b/x-pack/plugins/triggers_actions_ui/jest.config.js @@ -9,4 +9,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/triggers_actions_ui'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/triggers_actions_ui', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/x-pack/plugins/triggers_actions_ui/{common,public,server}/**/*.{ts,tsx}', + ], }; diff --git a/x-pack/plugins/ui_actions_enhanced/jest.config.js b/x-pack/plugins/ui_actions_enhanced/jest.config.js index dd27310084e0d..8182b23b2ebe9 100644 --- a/x-pack/plugins/ui_actions_enhanced/jest.config.js +++ b/x-pack/plugins/ui_actions_enhanced/jest.config.js @@ -9,4 +9,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/ui_actions_enhanced'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/ui_actions_enhanced', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/x-pack/plugins/ui_actions_enhanced/{common,public,server}/**/*.{ts,tsx}', + ], }; diff --git a/x-pack/plugins/upgrade_assistant/jest.config.js b/x-pack/plugins/upgrade_assistant/jest.config.js index 65043acd878da..024cb4a49ab3d 100644 --- a/x-pack/plugins/upgrade_assistant/jest.config.js +++ b/x-pack/plugins/upgrade_assistant/jest.config.js @@ -9,4 +9,9 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/upgrade_assistant'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/upgrade_assistant', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/x-pack/plugins/upgrade_assistant/{common,public,server}/**/*.{ts,tsx}', + ], }; diff --git a/x-pack/plugins/uptime/jest.config.js b/x-pack/plugins/uptime/jest.config.js index 9e97154843770..baafb5ce133e6 100644 --- a/x-pack/plugins/uptime/jest.config.js +++ b/x-pack/plugins/uptime/jest.config.js @@ -9,4 +9,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/uptime'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/uptime', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/x-pack/plugins/uptime/{common,public,server}/**/*.{ts,tsx}'], }; diff --git a/x-pack/plugins/watcher/jest.config.js b/x-pack/plugins/watcher/jest.config.js index d5189ae920637..b078f2ab665d7 100644 --- a/x-pack/plugins/watcher/jest.config.js +++ b/x-pack/plugins/watcher/jest.config.js @@ -9,4 +9,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/watcher'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/watcher', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/x-pack/plugins/watcher/{common,public,server}/**/*.{js,ts,tsx}'], }; diff --git a/x-pack/plugins/xpack_legacy/jest.config.js b/x-pack/plugins/xpack_legacy/jest.config.js index 98d2dd0aa824c..5ad0fa36264d1 100644 --- a/x-pack/plugins/xpack_legacy/jest.config.js +++ b/x-pack/plugins/xpack_legacy/jest.config.js @@ -9,4 +9,7 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/x-pack/plugins/xpack_legacy'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/xpack_legacy', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/x-pack/plugins/xpack_legacy/server/**/*.{ts,tsx}'], }; From 96bffbfaf85e7d96b37823764bbc70cd50d33bcf Mon Sep 17 00:00:00 2001 From: Dario Gieselaar Date: Thu, 9 Sep 2021 08:30:26 +0200 Subject: [PATCH 2/6] [APM] Use full path in route definition (#111501) --- .../src/create_router.test.tsx | 30 +- .../src/create_router.ts | 23 +- .../src/types/index.ts | 259 +++++++++++------- .../apm/dev_docs/routing_and_linking.md | 4 +- .../public/components/app/TraceLink/index.tsx | 2 +- .../backend_detail_dependencies_table.tsx | 2 +- .../backend_error_rate_chart.tsx | 2 +- .../backend_latency_chart.tsx | 2 +- .../backend_throughput_chart.tsx | 2 +- .../app/backend_detail_overview/index.tsx | 4 +- .../app/error_group_details/index.tsx | 4 +- .../app/error_group_overview/index.tsx | 2 +- .../service_dependencies_breakdown_chart.tsx | 2 +- .../app/service_inventory/index.tsx | 2 +- .../components/app/service_logs/index.tsx | 2 +- .../components/app/service_map/Controls.tsx | 2 +- .../service_map/Popover/backend_contents.tsx | 6 +- .../service_map/Popover/service_contents.tsx | 4 +- .../components/app/service_map/index.tsx | 2 +- .../components/app/service_metrics/index.tsx | 2 +- .../app/service_node_metrics/index.tsx | 4 +- .../app/service_node_overview/index.tsx | 2 +- .../components/app/service_overview/index.tsx | 4 +- .../index.tsx | 2 +- .../service_overview_errors_table/index.tsx | 2 +- ...ice_overview_instances_chart_and_table.tsx | 2 +- .../index.tsx | 2 +- .../use_instance_details_fetcher.tsx | 2 +- .../service_overview_throughput_chart.tsx | 2 +- .../app/service_profiling/index.tsx | 2 +- .../app/transaction_details/index.tsx | 4 +- .../transaction_details_tabs.tsx | 2 +- .../use_waterfall_fetcher.ts | 2 +- .../waterfall_with_summary/index.tsx | 2 +- .../Waterfall/FlyoutTopLevelProperties.tsx | 2 +- .../span_flyout/sticky_span_properties.tsx | 2 +- .../components/app/transaction_link/index.tsx | 2 +- .../app/transaction_overview/index.tsx | 2 +- .../components/routing/apm_route_config.tsx | 4 +- .../public/components/routing/home/index.tsx | 4 +- .../service_detail/apm_service_wrapper.tsx | 4 +- .../routing/service_detail/index.tsx | 34 +-- ...redirect_to_default_service_route_view.tsx | 2 +- .../components/routing/settings/index.tsx | 16 +- .../analyze_data_button.tsx | 2 +- .../templates/apm_service_template/index.tsx | 24 +- .../public/components/shared/backend_link.tsx | 4 +- .../shared/charts/breakdown_chart/index.tsx | 2 +- .../latency_chart/latency_chart.stories.tsx | 2 +- .../use_transaction_breakdown.ts | 2 +- .../charts/transaction_charts/ml_header.tsx | 2 +- .../transaction_error_rate_chart/index.tsx | 2 +- .../public/components/shared/service_link.tsx | 4 +- .../shared/time_comparison/index.tsx | 2 +- .../apm_backend/apm_backend_context.tsx | 2 +- .../apm_service/apm_service_context.tsx | 2 +- .../use_service_transaction_types_fetcher.tsx | 2 +- .../use_error_group_distribution_fetcher.tsx | 2 +- .../apm/public/hooks/use_search_strategy.ts | 2 +- .../use_service_metric_charts_fetcher.ts | 2 +- .../use_transaction_latency_chart_fetcher.ts | 2 +- .../use_transaction_trace_samples_fetcher.ts | 2 +- 62 files changed, 304 insertions(+), 222 deletions(-) diff --git a/packages/kbn-typed-react-router-config/src/create_router.test.tsx b/packages/kbn-typed-react-router-config/src/create_router.test.tsx index 3fb37f813e2e1..61ba8eb157ee3 100644 --- a/packages/kbn-typed-react-router-config/src/create_router.test.tsx +++ b/packages/kbn-typed-react-router-config/src/create_router.test.tsx @@ -43,17 +43,23 @@ describe('createRouter', () => { }), }, { - path: '/services/:serviceName', + path: '/services', element: <>, - params: t.type({ - path: t.type({ - serviceName: t.string, - }), - query: t.type({ - transactionType: t.string, - environment: t.string, - }), - }), + children: [ + { + element: <>, + path: '/services/{serviceName}', + params: t.type({ + path: t.type({ + serviceName: t.string, + }), + query: t.type({ + transactionType: t.string, + environment: t.string, + }), + }), + }, + ], }, { path: '/traces', @@ -131,7 +137,7 @@ describe('createRouter', () => { '/services/opbeans-java?rangeFrom=now-15m&rangeTo=now&environment=production&transactionType=request' ); - const serviceOverviewParams = router.getParams('/services/:serviceName', history.location); + const serviceOverviewParams = router.getParams('/services/{serviceName}', history.location); expect(serviceOverviewParams).toEqual({ path: { @@ -250,7 +256,7 @@ describe('createRouter', () => { describe('link', () => { it('returns a link for the given route', () => { - const serviceOverviewLink = router.link('/services/:serviceName', { + const serviceOverviewLink = router.link('/services/{serviceName}', { path: { serviceName: 'opbeans-java' }, query: { rangeFrom: 'now-15m', diff --git a/packages/kbn-typed-react-router-config/src/create_router.ts b/packages/kbn-typed-react-router-config/src/create_router.ts index 370d8b48e53b4..7f2ac818fc9b9 100644 --- a/packages/kbn-typed-react-router-config/src/create_router.ts +++ b/packages/kbn-typed-react-router-config/src/create_router.ts @@ -25,22 +25,24 @@ import { Route, Router } from './types'; const deepExactRt: typeof deepExactRtTyped = deepExactRtNonTyped; const mergeRt: typeof mergeRtTyped = mergeRtNonTyped; +function toReactRouterPath(path: string) { + return path.replace(/(?:{([^\/]+)})/, ':$1'); +} + export function createRouter(routes: TRoutes): Router { const routesByReactRouterConfig = new Map(); const reactRouterConfigsByRoute = new Map(); const reactRouterConfigs = routes.map((route) => toReactRouterConfigRoute(route)); - function toReactRouterConfigRoute(route: Route, prefix: string = ''): ReactRouterConfig { - const path = `${prefix}${route.path}`.replace(/\/{2,}/g, '/').replace(/\/$/, '') || '/'; + function toReactRouterConfigRoute(route: Route): ReactRouterConfig { const reactRouterConfig: ReactRouterConfig = { component: () => route.element, routes: - (route.children as Route[] | undefined)?.map((child) => - toReactRouterConfigRoute(child, path) - ) ?? [], + (route.children as Route[] | undefined)?.map((child) => toReactRouterConfigRoute(child)) ?? + [], exact: !route.children?.length, - path, + path: toReactRouterPath(route.path), }; routesByReactRouterConfig.set(reactRouterConfig, route); @@ -71,11 +73,11 @@ export function createRouter(routes: TRoutes): Router match.route.path === path); + : findLastIndex(matches, (match) => match.route.path === toReactRouterPath(path)); if (matchIndex !== -1) { break; @@ -135,11 +137,12 @@ export function createRouter(routes: TRoutes): Router { - return part.startsWith(':') ? paramsWithBuiltInDefaults.path[part.split(':')[1]] : part; + const match = part.match(/(?:{([a-zA-Z]+)})/); + return match ? paramsWithBuiltInDefaults.path[match[1]] : part; }) .join('/'); - const matches = matchRoutesConfig(reactRouterConfigs, path); + const matches = matchRoutesConfig(reactRouterConfigs, toReactRouterPath(path)); if (!matches.length) { throw new Error(`No matching route found for ${path}`); diff --git a/packages/kbn-typed-react-router-config/src/types/index.ts b/packages/kbn-typed-react-router-config/src/types/index.ts index 4d26d2879d5e7..e6c70001ef4b6 100644 --- a/packages/kbn-typed-react-router-config/src/types/index.ts +++ b/packages/kbn-typed-react-router-config/src/types/index.ts @@ -13,7 +13,97 @@ import { RequiredKeys, ValuesType } from 'utility-types'; // import { unconst } from '../unconst'; import { NormalizePath } from './utils'; -export type PathsOf = keyof MapRoutes & string; +type PathsOfRoute = + | TRoute['path'] + | (TRoute extends { children: Route[] } + ? AppendPath | PathsOf + : never); + +export type PathsOf = TRoutes extends [] + ? never + : TRoutes extends [Route] + ? PathsOfRoute + : TRoutes extends [Route, Route] + ? PathsOfRoute | PathsOfRoute + : TRoutes extends [Route, Route, Route] + ? PathsOfRoute | PathsOfRoute | PathsOfRoute + : TRoutes extends [Route, Route, Route, Route] + ? + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + : TRoutes extends [Route, Route, Route, Route, Route] + ? + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + : TRoutes extends [Route, Route, Route, Route, Route, Route] + ? + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + : TRoutes extends [Route, Route, Route, Route, Route, Route, Route] + ? + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + : TRoutes extends [Route, Route, Route, Route, Route, Route, Route, Route] + ? + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + : TRoutes extends [Route, Route, Route, Route, Route, Route, Route, Route, Route] + ? + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + : TRoutes extends [Route, Route, Route, Route, Route, Route, Route, Route, Route, Route] + ? + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + : TRoutes extends [Route, Route, Route, Route, Route, Route, Route, Route, Route, Route, Route] + ? + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + | PathsOfRoute + : string; export interface RouteMatch { route: TRoute; @@ -167,29 +257,17 @@ type MaybeUnion, U extends Record> = [key in keyof U]: key extends keyof T ? T[key] | U[key] : U[key]; }; -type MapRoute< - TRoute extends Route, - TPrefix extends string, - TParents extends Route[] = [] -> = TRoute extends Route +type MapRoute = TRoute extends Route ? MaybeUnion< { - [key in AppendPath]: TRoute & { parents: TParents }; + [key in TRoute['path']]: TRoute & { parents: TParents }; }, TRoute extends { children: Route[] } ? MaybeUnion< - MapRoutes< - TRoute['children'], - AppendPath, - [...TParents, TRoute] - >, + MapRoutes, { - [key in AppendPath>]: ValuesType< - MapRoutes< - TRoute['children'], - AppendPath, - [...TParents, TRoute] - > + [key in AppendPath]: ValuesType< + MapRoutes >; } > @@ -197,74 +275,68 @@ type MapRoute< > : {}; -type MapRoutes< - TRoutes, - TPrefix extends string = '', - TParents extends Route[] = [] -> = TRoutes extends [Route] - ? MapRoute +type MapRoutes = TRoutes extends [Route] + ? MapRoute : TRoutes extends [Route, Route] - ? MapRoute & MapRoute + ? MapRoute & MapRoute : TRoutes extends [Route, Route, Route] - ? MapRoute & - MapRoute & - MapRoute + ? MapRoute & MapRoute & MapRoute : TRoutes extends [Route, Route, Route, Route] - ? MapRoute & - MapRoute & - MapRoute & - MapRoute + ? MapRoute & + MapRoute & + MapRoute & + MapRoute : TRoutes extends [Route, Route, Route, Route, Route] - ? MapRoute & - MapRoute & - MapRoute & - MapRoute & - MapRoute + ? MapRoute & + MapRoute & + MapRoute & + MapRoute & + MapRoute : TRoutes extends [Route, Route, Route, Route, Route, Route] - ? MapRoute & - MapRoute & - MapRoute & - MapRoute & - MapRoute & - MapRoute + ? MapRoute & + MapRoute & + MapRoute & + MapRoute & + MapRoute & + MapRoute : TRoutes extends [Route, Route, Route, Route, Route, Route, Route] - ? MapRoute & - MapRoute & - MapRoute & - MapRoute & - MapRoute & - MapRoute & - MapRoute + ? MapRoute & + MapRoute & + MapRoute & + MapRoute & + MapRoute & + MapRoute & + MapRoute : TRoutes extends [Route, Route, Route, Route, Route, Route, Route, Route] - ? MapRoute & - MapRoute & - MapRoute & - MapRoute & - MapRoute & - MapRoute & - MapRoute & - MapRoute + ? MapRoute & + MapRoute & + MapRoute & + MapRoute & + MapRoute & + MapRoute & + MapRoute & + MapRoute : TRoutes extends [Route, Route, Route, Route, Route, Route, Route, Route, Route] - ? MapRoute & - MapRoute & - MapRoute & - MapRoute & - MapRoute & - MapRoute & - MapRoute & - MapRoute & - MapRoute + ? MapRoute & + MapRoute & + MapRoute & + MapRoute & + MapRoute & + MapRoute & + MapRoute & + MapRoute & + MapRoute : TRoutes extends [Route, Route, Route, Route, Route, Route, Route, Route, Route, Route] - ? MapRoute & - MapRoute & - MapRoute & - MapRoute & - MapRoute & - MapRoute & - MapRoute & - MapRoute & - MapRoute & - MapRoute + ? MapRoute & + MapRoute & + MapRoute & + MapRoute & + MapRoute & + MapRoute & + MapRoute & + MapRoute & + MapRoute & + MapRoute : {}; // const element = null as any; @@ -279,11 +351,11 @@ type MapRoutes< // element, // children: [ // { -// path: '/agent-configuration', +// path: '/settings/agent-configuration', // element, // }, // { -// path: '/agent-configuration/create', +// path: '/settings/agent-configuration/create', // element, // params: t.partial({ // query: t.partial({ @@ -292,7 +364,7 @@ type MapRoutes< // }), // }, // { -// path: '/agent-configuration/edit', +// path: '/settings/agent-configuration/edit', // element, // params: t.partial({ // query: t.partial({ @@ -301,23 +373,23 @@ type MapRoutes< // }), // }, // { -// path: '/apm-indices', +// path: '/settings/apm-indices', // element, // }, // { -// path: '/customize-ui', +// path: '/settings/customize-ui', // element, // }, // { -// path: '/schema', +// path: '/settings/schema', // element, // }, // { -// path: '/anomaly-detection', +// path: '/settings/anomaly-detection', // element, // }, // { -// path: '/', +// path: '/settings', // element, // }, // ], @@ -346,15 +418,15 @@ type MapRoutes< // ]), // children: [ // { -// path: '/overview', +// path: '/services/:serviceName/overview', // element, // }, // { -// path: '/transactions', +// path: '/services/:serviceName/transactions', // element, // }, // { -// path: '/errors', +// path: '/services/:serviceName/errors', // element, // children: [ // { @@ -367,7 +439,7 @@ type MapRoutes< // }), // }, // { -// path: '/', +// path: '/services/:serviceName', // element, // params: t.partial({ // query: t.partial({ @@ -381,19 +453,19 @@ type MapRoutes< // ], // }, // { -// path: '/foo', +// path: '/services/:serviceName/foo', // element, // }, // { -// path: '/bar', +// path: '/services/:serviceName/bar', // element, // }, // { -// path: '/baz', +// path: '/services/:serviceName/baz', // element, // }, // { -// path: '/', +// path: '/services/:serviceName', // element, // }, // ], @@ -436,6 +508,7 @@ type MapRoutes< // type Bar = ValuesType>['route']['path']; // type Foo = OutputOf; +// type Baz = OutputOf; // const { path }: Foo = {} as any; diff --git a/x-pack/plugins/apm/dev_docs/routing_and_linking.md b/x-pack/plugins/apm/dev_docs/routing_and_linking.md index 7c5a00f43fe4b..478de0081fca4 100644 --- a/x-pack/plugins/apm/dev_docs/routing_and_linking.md +++ b/x-pack/plugins/apm/dev_docs/routing_and_linking.md @@ -18,13 +18,13 @@ Routes (and their parameters) are defined in [public/components/routing/apm_conf #### Parameter handling -Path (like `serviceName` in '/services/:serviceName/transactions') and query parameters are defined in the route definitions. +Path (like `serviceName` in '/services/{serviceName}/transactions') and query parameters are defined in the route definitions. For each parameter, an io-ts runtime type needs to be present: ```tsx { - route: '/services/:serviceName', + route: '/services/{serviceName}', element: , params: t.intersection([ t.type({ diff --git a/x-pack/plugins/apm/public/components/app/TraceLink/index.tsx b/x-pack/plugins/apm/public/components/app/TraceLink/index.tsx index 36ebb239fd7dd..2733ee0ddbdba 100644 --- a/x-pack/plugins/apm/public/components/app/TraceLink/index.tsx +++ b/x-pack/plugins/apm/public/components/app/TraceLink/index.tsx @@ -23,7 +23,7 @@ export function TraceLink() { const { path: { traceId }, query: { rangeFrom, rangeTo }, - } = useApmParams('/link-to/trace/:traceId'); + } = useApmParams('/link-to/trace/{traceId}'); const { data = { transaction: null }, status } = useFetcher( (callApmApi) => { diff --git a/x-pack/plugins/apm/public/components/app/backend_detail_overview/backend_detail_dependencies_table.tsx b/x-pack/plugins/apm/public/components/app/backend_detail_overview/backend_detail_dependencies_table.tsx index 4812d17183c5f..f98358e3a9c27 100644 --- a/x-pack/plugins/apm/public/components/app/backend_detail_overview/backend_detail_dependencies_table.tsx +++ b/x-pack/plugins/apm/public/components/app/backend_detail_overview/backend_detail_dependencies_table.tsx @@ -24,7 +24,7 @@ export function BackendDetailDependenciesTable() { const { query: { rangeFrom, rangeTo, kuery, environment }, - } = useApmParams('/backends/:backendName/overview'); + } = useApmParams('/backends/{backendName}/overview'); const { start, end } = useTimeRange({ rangeFrom, rangeTo }); diff --git a/x-pack/plugins/apm/public/components/app/backend_detail_overview/backend_error_rate_chart.tsx b/x-pack/plugins/apm/public/components/app/backend_detail_overview/backend_error_rate_chart.tsx index 16ab5cefdc658..d48178a8522be 100644 --- a/x-pack/plugins/apm/public/components/app/backend_detail_overview/backend_error_rate_chart.tsx +++ b/x-pack/plugins/apm/public/components/app/backend_detail_overview/backend_error_rate_chart.tsx @@ -31,7 +31,7 @@ export function BackendFailedTransactionRateChart({ const { query: { kuery, environment, rangeFrom, rangeTo }, - } = useApmParams('/backends/:backendName/overview'); + } = useApmParams('/backends/{backendName}/overview'); const { start, end } = useTimeRange({ rangeFrom, rangeTo }); diff --git a/x-pack/plugins/apm/public/components/app/backend_detail_overview/backend_latency_chart.tsx b/x-pack/plugins/apm/public/components/app/backend_detail_overview/backend_latency_chart.tsx index 99f46e77b60f1..759d153988875 100644 --- a/x-pack/plugins/apm/public/components/app/backend_detail_overview/backend_latency_chart.tsx +++ b/x-pack/plugins/apm/public/components/app/backend_detail_overview/backend_latency_chart.tsx @@ -27,7 +27,7 @@ export function BackendLatencyChart({ height }: { height: number }) { const { query: { rangeFrom, rangeTo, kuery, environment }, - } = useApmParams('/backends/:backendName/overview'); + } = useApmParams('/backends/{backendName}/overview'); const { start, end } = useTimeRange({ rangeFrom, rangeTo }); diff --git a/x-pack/plugins/apm/public/components/app/backend_detail_overview/backend_throughput_chart.tsx b/x-pack/plugins/apm/public/components/app/backend_detail_overview/backend_throughput_chart.tsx index ba4bdafe94bdf..2cfc7ea317628 100644 --- a/x-pack/plugins/apm/public/components/app/backend_detail_overview/backend_throughput_chart.tsx +++ b/x-pack/plugins/apm/public/components/app/backend_detail_overview/backend_throughput_chart.tsx @@ -23,7 +23,7 @@ export function BackendThroughputChart({ height }: { height: number }) { const { query: { rangeFrom, rangeTo, kuery, environment }, - } = useApmParams('/backends/:backendName/overview'); + } = useApmParams('/backends/{backendName}/overview'); const { start, end } = useTimeRange({ rangeFrom, rangeTo }); diff --git a/x-pack/plugins/apm/public/components/app/backend_detail_overview/index.tsx b/x-pack/plugins/apm/public/components/app/backend_detail_overview/index.tsx index 1060e20e9c595..16120a6f5b429 100644 --- a/x-pack/plugins/apm/public/components/app/backend_detail_overview/index.tsx +++ b/x-pack/plugins/apm/public/components/app/backend_detail_overview/index.tsx @@ -33,7 +33,7 @@ export function BackendDetailOverview() { const { path: { backendName }, query: { rangeFrom, rangeTo, environment, kuery }, - } = useApmParams('/backends/:backendName/overview'); + } = useApmParams('/backends/{backendName}/overview'); const apmRouter = useApmRouter(); @@ -46,7 +46,7 @@ export function BackendDetailOverview() { }, { title: backendName, - href: apmRouter.link('/backends/:backendName/overview', { + href: apmRouter.link('/backends/{backendName}/overview', { path: { backendName }, query: { rangeFrom, diff --git a/x-pack/plugins/apm/public/components/app/error_group_details/index.tsx b/x-pack/plugins/apm/public/components/app/error_group_details/index.tsx index 3929a055bd77b..9145e019c37ea 100644 --- a/x-pack/plugins/apm/public/components/app/error_group_details/index.tsx +++ b/x-pack/plugins/apm/public/components/app/error_group_details/index.tsx @@ -103,13 +103,13 @@ export function ErrorGroupDetails() { const { path: { groupId }, query: { rangeFrom, rangeTo, environment, kuery }, - } = useApmParams('/services/:serviceName/errors/:groupId'); + } = useApmParams('/services/{serviceName}/errors/{groupId}'); const { start, end } = useTimeRange({ rangeFrom, rangeTo }); useBreadcrumb({ title: groupId, - href: apmRouter.link('/services/:serviceName/errors/:groupId', { + href: apmRouter.link('/services/{serviceName}/errors/{groupId}', { path: { serviceName, groupId, diff --git a/x-pack/plugins/apm/public/components/app/error_group_overview/index.tsx b/x-pack/plugins/apm/public/components/app/error_group_overview/index.tsx index 7fdedb8f7e7b9..97a3c38b65986 100644 --- a/x-pack/plugins/apm/public/components/app/error_group_overview/index.tsx +++ b/x-pack/plugins/apm/public/components/app/error_group_overview/index.tsx @@ -27,7 +27,7 @@ export function ErrorGroupOverview() { const { query: { environment, kuery, sortField, sortDirection, rangeFrom, rangeTo }, - } = useApmParams('/services/:serviceName/errors'); + } = useApmParams('/services/{serviceName}/errors'); const { start, end } = useTimeRange({ rangeFrom, rangeTo }); diff --git a/x-pack/plugins/apm/public/components/app/service_dependencies/service_dependencies_breakdown_chart.tsx b/x-pack/plugins/apm/public/components/app/service_dependencies/service_dependencies_breakdown_chart.tsx index 1ce6d54754719..426328a8ce9f0 100644 --- a/x-pack/plugins/apm/public/components/app/service_dependencies/service_dependencies_breakdown_chart.tsx +++ b/x-pack/plugins/apm/public/components/app/service_dependencies/service_dependencies_breakdown_chart.tsx @@ -22,7 +22,7 @@ export function ServiceDependenciesBreakdownChart({ const { query: { kuery, environment, rangeFrom, rangeTo }, - } = useApmParams('/services/:serviceName/dependencies'); + } = useApmParams('/services/{serviceName}/dependencies'); const { start, end } = useTimeRange({ rangeFrom, rangeTo }); diff --git a/x-pack/plugins/apm/public/components/app/service_inventory/index.tsx b/x-pack/plugins/apm/public/components/app/service_inventory/index.tsx index c822e32ea1fc6..c72c0cfbbceed 100644 --- a/x-pack/plugins/apm/public/components/app/service_inventory/index.tsx +++ b/x-pack/plugins/apm/public/components/app/service_inventory/index.tsx @@ -42,7 +42,7 @@ function useServicesFetcher() { const { query: { rangeFrom, rangeTo, environment, kuery }, - } = useApmParams('/services/:serviceName', '/services'); + } = useApmParams('/services/{serviceName}', '/services'); const { start, end } = useTimeRange({ rangeFrom, rangeTo }); diff --git a/x-pack/plugins/apm/public/components/app/service_logs/index.tsx b/x-pack/plugins/apm/public/components/app/service_logs/index.tsx index ac4a4fb51ce8a..79818473d26b1 100644 --- a/x-pack/plugins/apm/public/components/app/service_logs/index.tsx +++ b/x-pack/plugins/apm/public/components/app/service_logs/index.tsx @@ -27,7 +27,7 @@ export function ServiceLogs() { const { query: { environment, kuery, rangeFrom, rangeTo }, - } = useApmParams('/services/:serviceName/logs'); + } = useApmParams('/services/{serviceName}/logs'); const { start, end } = useTimeRange({ rangeFrom, rangeTo }); diff --git a/x-pack/plugins/apm/public/components/app/service_map/Controls.tsx b/x-pack/plugins/apm/public/components/app/service_map/Controls.tsx index f46b1232b00fd..dd34110a8ffc6 100644 --- a/x-pack/plugins/apm/public/components/app/service_map/Controls.tsx +++ b/x-pack/plugins/apm/public/components/app/service_map/Controls.tsx @@ -107,7 +107,7 @@ export function Controls() { const { query: { kuery }, - } = useApmParams('/service-map', '/services/:serviceName/service-map'); + } = useApmParams('/service-map', '/services/{serviceName}/service-map'); const [zoom, setZoom] = useState((cy && cy.zoom()) || 1); const duration = parseInt(theme.eui.euiAnimSpeedFast, 10); diff --git a/x-pack/plugins/apm/public/components/app/service_map/Popover/backend_contents.tsx b/x-pack/plugins/apm/public/components/app/service_map/Popover/backend_contents.tsx index 9bc30ee67d2c7..c01cf4579fdbd 100644 --- a/x-pack/plugins/apm/public/components/app/service_map/Popover/backend_contents.tsx +++ b/x-pack/plugins/apm/public/components/app/service_map/Popover/backend_contents.tsx @@ -27,7 +27,7 @@ export function BackendContents({ }: ContentsProps) { const { query } = useApmParams( '/service-map', - '/services/:serviceName/service-map' + '/services/{serviceName}/service-map' ); const apmRouter = useApmRouter(); @@ -57,11 +57,11 @@ export function BackendContents({ ); const isLoading = status === FETCH_STATUS.LOADING; - const detailsUrl = apmRouter.link('/backends/:backendName/overview', { + const detailsUrl = apmRouter.link('/backends/{backendName}/overview', { path: { backendName }, query: query as TypeOf< ApmRoutes, - '/backends/:backendName/overview' + '/backends/{backendName}/overview' >['query'], }); diff --git a/x-pack/plugins/apm/public/components/app/service_map/Popover/service_contents.tsx b/x-pack/plugins/apm/public/components/app/service_map/Popover/service_contents.tsx index eb13a854925c4..5eef580793d10 100644 --- a/x-pack/plugins/apm/public/components/app/service_map/Popover/service_contents.tsx +++ b/x-pack/plugins/apm/public/components/app/service_map/Popover/service_contents.tsx @@ -63,12 +63,12 @@ export function ServiceContents({ const isLoading = status === FETCH_STATUS.LOADING; - const detailsUrl = apmRouter.link('/services/:serviceName', { + const detailsUrl = apmRouter.link('/services/{serviceName}', { path: { serviceName }, query: { rangeFrom, rangeTo, environment, kuery }, }); - const focusUrl = apmRouter.link('/services/:serviceName/service-map', { + const focusUrl = apmRouter.link('/services/{serviceName}/service-map', { path: { serviceName }, query: { rangeFrom, rangeTo, environment, kuery }, }); diff --git a/x-pack/plugins/apm/public/components/app/service_map/index.tsx b/x-pack/plugins/apm/public/components/app/service_map/index.tsx index c3a6dca165131..97b4f548f4bf9 100644 --- a/x-pack/plugins/apm/public/components/app/service_map/index.tsx +++ b/x-pack/plugins/apm/public/components/app/service_map/index.tsx @@ -83,7 +83,7 @@ export function ServiceMapHome() { export function ServiceMapServiceDetail() { const { query: { environment, kuery, rangeFrom, rangeTo }, - } = useApmParams('/services/:serviceName/service-map'); + } = useApmParams('/services/{serviceName}/service-map'); const { start, end } = useTimeRange({ rangeFrom, rangeTo }); return ( { setSampleActivePage(0); diff --git a/x-pack/plugins/apm/public/components/app/transaction_details/waterfall_with_summary/waterfall_container/Waterfall/FlyoutTopLevelProperties.tsx b/x-pack/plugins/apm/public/components/app/transaction_details/waterfall_with_summary/waterfall_container/Waterfall/FlyoutTopLevelProperties.tsx index 6bbcfcf545ee1..8954081f9ab47 100644 --- a/x-pack/plugins/apm/public/components/app/transaction_details/waterfall_with_summary/waterfall_container/Waterfall/FlyoutTopLevelProperties.tsx +++ b/x-pack/plugins/apm/public/components/app/transaction_details/waterfall_with_summary/waterfall_container/Waterfall/FlyoutTopLevelProperties.tsx @@ -27,7 +27,7 @@ export function FlyoutTopLevelProperties({ transaction }: Props) { const { urlParams: { latencyAggregationType }, } = useUrlParams(); - const { query } = useApmParams('/services/:serviceName/transactions/view'); + const { query } = useApmParams('/services/{serviceName}/transactions/view'); if (!transaction) { return null; diff --git a/x-pack/plugins/apm/public/components/app/transaction_details/waterfall_with_summary/waterfall_container/Waterfall/span_flyout/sticky_span_properties.tsx b/x-pack/plugins/apm/public/components/app/transaction_details/waterfall_with_summary/waterfall_container/Waterfall/span_flyout/sticky_span_properties.tsx index 97e353d22ccf6..2e02dcee95371 100644 --- a/x-pack/plugins/apm/public/components/app/transaction_details/waterfall_with_summary/waterfall_container/Waterfall/span_flyout/sticky_span_properties.tsx +++ b/x-pack/plugins/apm/public/components/app/transaction_details/waterfall_with_summary/waterfall_container/Waterfall/span_flyout/sticky_span_properties.tsx @@ -33,7 +33,7 @@ interface Props { } export function StickySpanProperties({ span, transaction }: Props) { - const { query } = useApmParams('/services/:serviceName/transactions/view'); + const { query } = useApmParams('/services/{serviceName}/transactions/view'); const { environment, latencyAggregationType } = query; const trackEvent = useUiTracker(); diff --git a/x-pack/plugins/apm/public/components/app/transaction_link/index.tsx b/x-pack/plugins/apm/public/components/app/transaction_link/index.tsx index 25cbf2d319587..468a90f6b17de 100644 --- a/x-pack/plugins/apm/public/components/app/transaction_link/index.tsx +++ b/x-pack/plugins/apm/public/components/app/transaction_link/index.tsx @@ -22,7 +22,7 @@ export function TransactionLink() { const { path: { transactionId }, query: { rangeFrom, rangeTo }, - } = useApmParams('/link-to/transaction/:transactionId'); + } = useApmParams('/link-to/transaction/{transactionId}'); const { data = { transaction: null }, status } = useFetcher( (callApmApi) => { diff --git a/x-pack/plugins/apm/public/components/app/transaction_overview/index.tsx b/x-pack/plugins/apm/public/components/app/transaction_overview/index.tsx index 571ba99d9bf08..a1362f7373e2a 100644 --- a/x-pack/plugins/apm/public/components/app/transaction_overview/index.tsx +++ b/x-pack/plugins/apm/public/components/app/transaction_overview/index.tsx @@ -26,7 +26,7 @@ export function TransactionOverview() { rangeTo, transactionType: transactionTypeFromUrl, }, - } = useApmParams('/services/:serviceName/transactions'); + } = useApmParams('/services/{serviceName}/transactions'); const { start, end } = useTimeRange({ rangeFrom, rangeTo }); diff --git a/x-pack/plugins/apm/public/components/routing/apm_route_config.tsx b/x-pack/plugins/apm/public/components/routing/apm_route_config.tsx index b751ef3f71190..5377cb81b372e 100644 --- a/x-pack/plugins/apm/public/components/routing/apm_route_config.tsx +++ b/x-pack/plugins/apm/public/components/routing/apm_route_config.tsx @@ -21,7 +21,7 @@ import { settings } from './settings'; */ const apmRoutes = route([ { - path: '/link-to/transaction/:transactionId', + path: '/link-to/transaction/{transactionId}', element: , params: t.intersection([ t.type({ @@ -38,7 +38,7 @@ const apmRoutes = route([ ]), }, { - path: '/link-to/trace/:traceId', + path: '/link-to/trace/{traceId}', element: , params: t.intersection([ t.type({ diff --git a/x-pack/plugins/apm/public/components/routing/home/index.tsx b/x-pack/plugins/apm/public/components/routing/home/index.tsx index 1430f5d8e4756..1736a22e9b540 100644 --- a/x-pack/plugins/apm/public/components/routing/home/index.tsx +++ b/x-pack/plugins/apm/public/components/routing/home/index.tsx @@ -104,7 +104,7 @@ export const home = { }), children: [ { - path: '/:backendName/overview', + path: '/backends/{backendName}/overview', element: , params: t.type({ path: t.type({ @@ -113,7 +113,7 @@ export const home = { }), }, page({ - path: '/', + path: '/backends', title: DependenciesInventoryTitle, element: , }), diff --git a/x-pack/plugins/apm/public/components/routing/service_detail/apm_service_wrapper.tsx b/x-pack/plugins/apm/public/components/routing/service_detail/apm_service_wrapper.tsx index aa69aa4fa7965..ef929331f3c1c 100644 --- a/x-pack/plugins/apm/public/components/routing/service_detail/apm_service_wrapper.tsx +++ b/x-pack/plugins/apm/public/components/routing/service_detail/apm_service_wrapper.tsx @@ -15,7 +15,7 @@ export function ApmServiceWrapper() { const { path: { serviceName }, query, - } = useApmParams('/services/:serviceName'); + } = useApmParams('/services/{serviceName}'); const router = useApmRouter(); @@ -26,7 +26,7 @@ export function ApmServiceWrapper() { }, { title: serviceName, - href: router.link('/services/:serviceName', { + href: router.link('/services/{serviceName}', { query, path: { serviceName }, }), diff --git a/x-pack/plugins/apm/public/components/routing/service_detail/index.tsx b/x-pack/plugins/apm/public/components/routing/service_detail/index.tsx index 5124087369ee4..9b87cc338bb9b 100644 --- a/x-pack/plugins/apm/public/components/routing/service_detail/index.tsx +++ b/x-pack/plugins/apm/public/components/routing/service_detail/index.tsx @@ -62,7 +62,7 @@ function page({ } export const serviceDetail = { - path: '/services/:serviceName', + path: '/services/{serviceName}', element: , params: t.intersection([ t.type({ @@ -97,7 +97,7 @@ export const serviceDetail = { }, children: [ page({ - path: '/overview', + path: '/services/{serviceName}/overview', element: , tab: 'overview', title: i18n.translate('xpack.apm.views.overview.title', { @@ -110,7 +110,7 @@ export const serviceDetail = { }), { ...page({ - path: '/transactions', + path: '/services/{serviceName}/transactions', tab: 'transactions', title: i18n.translate('xpack.apm.views.transactions.title', { defaultMessage: 'Transactions', @@ -123,7 +123,7 @@ export const serviceDetail = { }), children: [ { - path: '/view', + path: '/services/{serviceName}/transactions/view', element: , params: t.type({ query: t.intersection([ @@ -138,13 +138,13 @@ export const serviceDetail = { }), }, { - path: '/', + path: '/services/{serviceName}/transactions', element: , }, ], }, page({ - path: '/dependencies', + path: '/services/{serviceName}/dependencies', element: , tab: 'dependencies', title: i18n.translate('xpack.apm.views.dependencies.title', { @@ -156,7 +156,7 @@ export const serviceDetail = { }), { ...page({ - path: '/errors', + path: '/services/{serviceName}/errors', tab: 'errors', title: i18n.translate('xpack.apm.views.errors.title', { defaultMessage: 'Errors', @@ -173,7 +173,7 @@ export const serviceDetail = { }), children: [ { - path: '/:groupId', + path: '/services/{serviceName}/errors/{groupId}', element: , params: t.type({ path: t.type({ @@ -182,13 +182,13 @@ export const serviceDetail = { }), }, { - path: '/', + path: '/services/{serviceName}/errors', element: , }, ], }, page({ - path: '/metrics', + path: '/services/{serviceName}/metrics', tab: 'metrics', title: i18n.translate('xpack.apm.views.metrics.title', { defaultMessage: 'Metrics', @@ -197,7 +197,7 @@ export const serviceDetail = { }), { ...page({ - path: '/nodes', + path: '/services/{serviceName}/nodes', tab: 'nodes', title: i18n.translate('xpack.apm.views.nodes.title', { defaultMessage: 'JVMs', @@ -206,7 +206,7 @@ export const serviceDetail = { }), children: [ { - path: '/:serviceNodeName/metrics', + path: '/services/{serviceName}/nodes/{serviceNodeName}/metrics', element: , params: t.type({ path: t.type({ @@ -215,7 +215,7 @@ export const serviceDetail = { }), }, { - path: '/', + path: '/services/{serviceName}/nodes', element: , params: t.partial({ query: t.partial({ @@ -229,7 +229,7 @@ export const serviceDetail = { ], }, page({ - path: '/service-map', + path: '/services/{serviceName}/service-map', tab: 'service-map', title: i18n.translate('xpack.apm.views.serviceMap.title', { defaultMessage: 'Service Map', @@ -240,7 +240,7 @@ export const serviceDetail = { }, }), page({ - path: '/logs', + path: '/services/{serviceName}/logs', tab: 'logs', title: i18n.translate('xpack.apm.views.logs.title', { defaultMessage: 'Logs', @@ -251,7 +251,7 @@ export const serviceDetail = { }, }), page({ - path: '/profiling', + path: '/services/{serviceName}/profiling', tab: 'profiling', title: i18n.translate('xpack.apm.views.serviceProfiling.title', { defaultMessage: 'Profiling', @@ -259,7 +259,7 @@ export const serviceDetail = { element: , }), { - path: '/', + path: '/services/{serviceName}/', element: , }, ], diff --git a/x-pack/plugins/apm/public/components/routing/service_detail/redirect_to_default_service_route_view.tsx b/x-pack/plugins/apm/public/components/routing/service_detail/redirect_to_default_service_route_view.tsx index 66595430f618d..1cd61ef6e9243 100644 --- a/x-pack/plugins/apm/public/components/routing/service_detail/redirect_to_default_service_route_view.tsx +++ b/x-pack/plugins/apm/public/components/routing/service_detail/redirect_to_default_service_route_view.tsx @@ -13,7 +13,7 @@ export function RedirectToDefaultServiceRouteView() { const { path: { serviceName }, query, - } = useApmParams('/services/:serviceName/*'); + } = useApmParams('/services/{serviceName}/*'); const search = qs.stringify(query); diff --git a/x-pack/plugins/apm/public/components/routing/settings/index.tsx b/x-pack/plugins/apm/public/components/routing/settings/index.tsx index e844f05050d17..e33f60e5593b0 100644 --- a/x-pack/plugins/apm/public/components/routing/settings/index.tsx +++ b/x-pack/plugins/apm/public/components/routing/settings/index.tsx @@ -58,7 +58,7 @@ export const settings = { ), children: [ page({ - path: '/agent-configuration', + path: '/settings/agent-configuration', tab: 'agent-configurations', title: i18n.translate( 'xpack.apm.views.settings.agentConfiguration.title', @@ -68,7 +68,7 @@ export const settings = { }), { ...page({ - path: '/agent-configuration/create', + path: '/settings/agent-configuration/create', title: i18n.translate( 'xpack.apm.views.settings.createAgentConfiguration.title', { defaultMessage: 'Create Agent Configuration' } @@ -84,7 +84,7 @@ export const settings = { }, { ...page({ - path: '/agent-configuration/edit', + path: '/settings/agent-configuration/edit', title: i18n.translate( 'xpack.apm.views.settings.editAgentConfiguration.title', { defaultMessage: 'Edit Agent Configuration' } @@ -101,7 +101,7 @@ export const settings = { }), }, page({ - path: '/apm-indices', + path: '/settings/apm-indices', title: i18n.translate('xpack.apm.views.settings.indices.title', { defaultMessage: 'Indices', }), @@ -109,7 +109,7 @@ export const settings = { element: , }), page({ - path: '/customize-ui', + path: '/settings/customize-ui', title: i18n.translate('xpack.apm.views.settings.customizeUI.title', { defaultMessage: 'Customize app', }), @@ -117,7 +117,7 @@ export const settings = { element: , }), page({ - path: '/schema', + path: '/settings/schema', title: i18n.translate('xpack.apm.views.settings.schema.title', { defaultMessage: 'Schema', }), @@ -125,7 +125,7 @@ export const settings = { tab: 'schema', }), page({ - path: '/anomaly-detection', + path: '/settings/anomaly-detection', title: i18n.translate('xpack.apm.views.settings.anomalyDetection.title', { defaultMessage: 'Anomaly detection', }), @@ -133,7 +133,7 @@ export const settings = { tab: 'anomaly-detection', }), { - path: '/', + path: '/settings', element: , }, ], diff --git a/x-pack/plugins/apm/public/components/routing/templates/apm_service_template/analyze_data_button.tsx b/x-pack/plugins/apm/public/components/routing/templates/apm_service_template/analyze_data_button.tsx index 03fe39e818eaa..068d7bb1c242f 100644 --- a/x-pack/plugins/apm/public/components/routing/templates/apm_service_template/analyze_data_button.tsx +++ b/x-pack/plugins/apm/public/components/routing/templates/apm_service_template/analyze_data_button.tsx @@ -47,7 +47,7 @@ export function AnalyzeDataButton() { const { query: { rangeFrom, rangeTo, environment }, - } = useApmParams('/services/:serviceName'); + } = useApmParams('/services/{serviceName}'); const basepath = services.http?.basePath.get(); const canShowDashboard = services.application?.capabilities.dashboard.show; diff --git a/x-pack/plugins/apm/public/components/routing/templates/apm_service_template/index.tsx b/x-pack/plugins/apm/public/components/routing/templates/apm_service_template/index.tsx index bb00c631fe171..0ae718c79cf39 100644 --- a/x-pack/plugins/apm/public/components/routing/templates/apm_service_template/index.tsx +++ b/x-pack/plugins/apm/public/components/routing/templates/apm_service_template/index.tsx @@ -72,7 +72,7 @@ function TemplateWithContext({ path: { serviceName }, query, query: { rangeFrom, rangeTo }, - } = useApmParams('/services/:serviceName/*'); + } = useApmParams('/services/{serviceName}/*'); const { start, end } = useTimeRange({ rangeFrom, rangeTo }); @@ -82,7 +82,7 @@ function TemplateWithContext({ useBreadcrumb({ title, - href: router.link(`/services/:serviceName/${selectedTab}` as const, { + href: router.link(`/services/{serviceName}/${selectedTab}` as const, { path: { serviceName }, query, }), @@ -162,7 +162,7 @@ function useTabs({ selectedTab }: { selectedTab: Tab['key'] }) { const { path: { serviceName }, query: queryFromUrl, - } = useApmParams(`/services/:serviceName/${selectedTab}` as const); + } = useApmParams(`/services/{serviceName}/${selectedTab}` as const); const query = omit( queryFromUrl, @@ -175,7 +175,7 @@ function useTabs({ selectedTab }: { selectedTab: Tab['key'] }) { const tabs: Tab[] = [ { key: 'overview', - href: router.link('/services/:serviceName/overview', { + href: router.link('/services/{serviceName}/overview', { path: { serviceName }, query, }), @@ -185,7 +185,7 @@ function useTabs({ selectedTab }: { selectedTab: Tab['key'] }) { }, { key: 'transactions', - href: router.link('/services/:serviceName/transactions', { + href: router.link('/services/{serviceName}/transactions', { path: { serviceName }, query, }), @@ -195,7 +195,7 @@ function useTabs({ selectedTab }: { selectedTab: Tab['key'] }) { }, { key: 'dependencies', - href: router.link('/services/:serviceName/dependencies', { + href: router.link('/services/{serviceName}/dependencies', { path: { serviceName }, query, }), @@ -207,7 +207,7 @@ function useTabs({ selectedTab }: { selectedTab: Tab['key'] }) { }, { key: 'errors', - href: router.link('/services/:serviceName/errors', { + href: router.link('/services/{serviceName}/errors', { path: { serviceName }, query, }), @@ -217,7 +217,7 @@ function useTabs({ selectedTab }: { selectedTab: Tab['key'] }) { }, { key: 'metrics', - href: router.link('/services/:serviceName/metrics', { + href: router.link('/services/{serviceName}/metrics', { path: { serviceName }, query, }), @@ -228,7 +228,7 @@ function useTabs({ selectedTab }: { selectedTab: Tab['key'] }) { }, { key: 'nodes', - href: router.link('/services/:serviceName/nodes', { + href: router.link('/services/{serviceName}/nodes', { path: { serviceName }, query, }), @@ -239,7 +239,7 @@ function useTabs({ selectedTab }: { selectedTab: Tab['key'] }) { }, { key: 'service-map', - href: router.link('/services/:serviceName/service-map', { + href: router.link('/services/{serviceName}/service-map', { path: { serviceName }, query, }), @@ -249,7 +249,7 @@ function useTabs({ selectedTab }: { selectedTab: Tab['key'] }) { }, { key: 'logs', - href: router.link('/services/:serviceName/logs', { + href: router.link('/services/{serviceName}/logs', { path: { serviceName }, query, }), @@ -261,7 +261,7 @@ function useTabs({ selectedTab }: { selectedTab: Tab['key'] }) { }, { key: 'profiling', - href: router.link('/services/:serviceName/profiling', { + href: router.link('/services/{serviceName}/profiling', { path: { serviceName, }, diff --git a/x-pack/plugins/apm/public/components/shared/backend_link.tsx b/x-pack/plugins/apm/public/components/shared/backend_link.tsx index caae47184510a..342c668d2efdb 100644 --- a/x-pack/plugins/apm/public/components/shared/backend_link.tsx +++ b/x-pack/plugins/apm/public/components/shared/backend_link.tsx @@ -18,7 +18,7 @@ const StyledLink = euiStyled(EuiLink)`${truncate('100%')};`; interface BackendLinkProps { backendName: string; - query: TypeOf['query']; + query: TypeOf['query']; subtype?: string; type?: string; onClick?: React.ComponentProps['onClick']; @@ -35,7 +35,7 @@ export function BackendLink({ return ( - + diff --git a/x-pack/plugins/apm/public/components/shared/charts/transaction_breakdown_chart/use_transaction_breakdown.ts b/x-pack/plugins/apm/public/components/shared/charts/transaction_breakdown_chart/use_transaction_breakdown.ts index bb56338531df3..789461379d044 100644 --- a/x-pack/plugins/apm/public/components/shared/charts/transaction_breakdown_chart/use_transaction_breakdown.ts +++ b/x-pack/plugins/apm/public/components/shared/charts/transaction_breakdown_chart/use_transaction_breakdown.ts @@ -24,7 +24,7 @@ export function useTransactionBreakdown({ const { query: { rangeFrom, rangeTo }, - } = useApmParams('/services/:serviceName'); + } = useApmParams('/services/{serviceName}'); const { start, end } = useTimeRange({ rangeFrom, rangeTo }); diff --git a/x-pack/plugins/apm/public/components/shared/charts/transaction_charts/ml_header.tsx b/x-pack/plugins/apm/public/components/shared/charts/transaction_charts/ml_header.tsx index f69b7e7004510..76e85b1d9998d 100644 --- a/x-pack/plugins/apm/public/components/shared/charts/transaction_charts/ml_header.tsx +++ b/x-pack/plugins/apm/public/components/shared/charts/transaction_charts/ml_header.tsx @@ -36,7 +36,7 @@ export function MLHeader({ hasValidMlLicense, mlJobId }: Props) { const { query: { kuery }, - } = useApmParams('/services/:serviceName'); + } = useApmParams('/services/{serviceName}'); if (!hasValidMlLicense || !mlJobId) { return null; diff --git a/x-pack/plugins/apm/public/components/shared/charts/transaction_error_rate_chart/index.tsx b/x-pack/plugins/apm/public/components/shared/charts/transaction_error_rate_chart/index.tsx index 2e8578e29297c..ae24a5e53444e 100644 --- a/x-pack/plugins/apm/public/components/shared/charts/transaction_error_rate_chart/index.tsx +++ b/x-pack/plugins/apm/public/components/shared/charts/transaction_error_rate_chart/index.tsx @@ -63,7 +63,7 @@ export function TransactionErrorRateChart({ const { query: { rangeFrom, rangeTo }, - } = useApmParams('/services/:serviceName'); + } = useApmParams('/services/{serviceName}'); const { start, end } = useTimeRange({ rangeFrom, rangeTo }); diff --git a/x-pack/plugins/apm/public/components/shared/service_link.tsx b/x-pack/plugins/apm/public/components/shared/service_link.tsx index a09ce958fdcab..d8f346f63b2ae 100644 --- a/x-pack/plugins/apm/public/components/shared/service_link.tsx +++ b/x-pack/plugins/apm/public/components/shared/service_link.tsx @@ -19,7 +19,7 @@ const StyledLink = euiStyled(EuiLink)`${truncate('100%')};`; interface ServiceLinkProps { agentName?: AgentName; - query: TypeOf['query']; + query: TypeOf['query']; serviceName: string; } @@ -33,7 +33,7 @@ export function ServiceLink({ return ( Date: Thu, 9 Sep 2021 08:47:36 +0200 Subject: [PATCH 3/6] [Integrations] Fixed wording (#111519) for integration upgrade --- .../fleet/public/components/package_policy_actions_menu.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/fleet/public/components/package_policy_actions_menu.tsx b/x-pack/plugins/fleet/public/components/package_policy_actions_menu.tsx index a87cd7e39bfb2..2030f57764756 100644 --- a/x-pack/plugins/fleet/public/components/package_policy_actions_menu.tsx +++ b/x-pack/plugins/fleet/public/components/package_policy_actions_menu.tsx @@ -87,7 +87,7 @@ export const PackagePolicyActionsMenu: React.FunctionComponent<{ > , // FIXME: implement Copy package policy action From db0714709138e9fb415fd8bf73e5830a83968926 Mon Sep 17 00:00:00 2001 From: Pablo Machado Date: Thu, 9 Sep 2021 10:35:47 +0200 Subject: [PATCH 4/6] Fix focus jumps from Case description box back to Alerts table with first keystroke (#111273) Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../public/components/create/form_context.tsx | 15 ++++++++++++++- .../cases/public/components/create/title.tsx | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/cases/public/components/create/form_context.tsx b/x-pack/plugins/cases/public/components/create/form_context.tsx index 65c102583455a..f59e1822c70be 100644 --- a/x-pack/plugins/cases/public/components/create/form_context.tsx +++ b/x-pack/plugins/cases/public/components/create/form_context.tsx @@ -113,7 +113,20 @@ export const FormContext: React.FC = ({ : null, [children, connectors, isLoadingConnectors] ); - return
{childrenWithExtraProp}
; + return ( +
{ + // It avoids the focus scaping from the flyout when enter is pressed. + // https://github.com/elastic/kibana/issues/111120 + if (e.key === 'Enter') { + e.stopPropagation(); + } + }} + form={form} + > + {childrenWithExtraProp} +
+ ); }; FormContext.displayName = 'FormContext'; diff --git a/x-pack/plugins/cases/public/components/create/title.tsx b/x-pack/plugins/cases/public/components/create/title.tsx index cc51a805b5c38..ae8f517173132 100644 --- a/x-pack/plugins/cases/public/components/create/title.tsx +++ b/x-pack/plugins/cases/public/components/create/title.tsx @@ -21,6 +21,7 @@ const TitleComponent: React.FC = ({ isLoading }) => ( idAria: 'caseTitle', 'data-test-subj': 'caseTitle', euiFieldProps: { + autoFocus: true, fullWidth: true, disabled: isLoading, }, From 2c7d13b7b985013a918461b99640f3e64b04bba4 Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Thu, 9 Sep 2021 11:37:18 +0300 Subject: [PATCH 5/6] [Canvas] `Expression types` and `Function form` refactor. (#107516) * Refactored `FormFunction` to ts. * Converted components to ts and added types for expression_types. * Fixed types and refactored `function_component`. * Added types to base_form, function_form, transform, etc. * Arg types added. * Moved model to ts and fixed all types. Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../arg_add_popover/arg_add_popover.tsx | 7 +- .../datasource_component.stories.tsx | 1 - .../components/function_form/function_form.js | 38 ----- .../function_form/function_form.tsx | 60 +++++++ ...mponent.js => function_form_component.tsx} | 30 +--- .../function_form_context_error.tsx | 18 +-- .../function_form_context_pending.js | 46 ------ .../function_form_context_pending.tsx | 47 ++++++ .../public/components/function_form/index.js | 115 -------------- .../public/components/function_form/index.tsx | 150 ++++++++++++++++++ .../canvas/public/expression_types/arg.js | 75 --------- .../canvas/public/expression_types/arg.ts | 145 +++++++++++++++++ .../public/expression_types/arg_type.ts | 33 ++++ .../{arg_type.js => arg_type_registry.ts} | 18 +-- .../{base_form.js => base_form.ts} | 12 +- .../public/expression_types/datasource.js | 76 --------- .../public/expression_types/datasource.tsx | 99 ++++++++++++ .../expression_types/datasource_registry.ts | 18 +++ .../{function_form.js => function_form.tsx} | 106 ++++++++++--- .../canvas/public/expression_types/index.js | 13 -- .../canvas/public/expression_types/index.ts | 23 +++ .../canvas/public/expression_types/model.js | 72 --------- .../canvas/public/expression_types/model.ts | 80 ++++++++++ .../public/expression_types/model_registry.ts | 18 +++ .../public/expression_types/transform.js | 31 ---- .../public/expression_types/transform.ts | 24 +++ .../expression_types/transform_registry.ts | 18 +++ .../canvas/public/expression_types/types.ts | 22 +++ .../canvas/public/expression_types/view.js | 38 ----- .../canvas/public/expression_types/view.ts | 39 +++++ .../public/expression_types/view_registry.ts | 18 +++ ...ession_type.js => find_expression_type.ts} | 14 +- x-pack/plugins/canvas/public/registries.ts | 1 - x-pack/plugins/canvas/types/state.ts | 11 +- 34 files changed, 923 insertions(+), 593 deletions(-) delete mode 100644 x-pack/plugins/canvas/public/components/function_form/function_form.js create mode 100644 x-pack/plugins/canvas/public/components/function_form/function_form.tsx rename x-pack/plugins/canvas/public/components/function_form/{function_form_component.js => function_form_component.tsx} (50%) delete mode 100644 x-pack/plugins/canvas/public/components/function_form/function_form_context_pending.js create mode 100644 x-pack/plugins/canvas/public/components/function_form/function_form_context_pending.tsx delete mode 100644 x-pack/plugins/canvas/public/components/function_form/index.js create mode 100644 x-pack/plugins/canvas/public/components/function_form/index.tsx delete mode 100644 x-pack/plugins/canvas/public/expression_types/arg.js create mode 100644 x-pack/plugins/canvas/public/expression_types/arg.ts create mode 100644 x-pack/plugins/canvas/public/expression_types/arg_type.ts rename x-pack/plugins/canvas/public/expression_types/{arg_type.js => arg_type_registry.ts} (52%) rename x-pack/plugins/canvas/public/expression_types/{base_form.js => base_form.ts} (72%) delete mode 100644 x-pack/plugins/canvas/public/expression_types/datasource.js create mode 100644 x-pack/plugins/canvas/public/expression_types/datasource.tsx create mode 100644 x-pack/plugins/canvas/public/expression_types/datasource_registry.ts rename x-pack/plugins/canvas/public/expression_types/{function_form.js => function_form.tsx} (57%) delete mode 100644 x-pack/plugins/canvas/public/expression_types/index.js create mode 100644 x-pack/plugins/canvas/public/expression_types/index.ts delete mode 100644 x-pack/plugins/canvas/public/expression_types/model.js create mode 100644 x-pack/plugins/canvas/public/expression_types/model.ts create mode 100644 x-pack/plugins/canvas/public/expression_types/model_registry.ts delete mode 100644 x-pack/plugins/canvas/public/expression_types/transform.js create mode 100644 x-pack/plugins/canvas/public/expression_types/transform.ts create mode 100644 x-pack/plugins/canvas/public/expression_types/transform_registry.ts create mode 100644 x-pack/plugins/canvas/public/expression_types/types.ts delete mode 100644 x-pack/plugins/canvas/public/expression_types/view.js create mode 100644 x-pack/plugins/canvas/public/expression_types/view.ts create mode 100644 x-pack/plugins/canvas/public/expression_types/view_registry.ts rename x-pack/plugins/canvas/public/lib/{find_expression_type.js => find_expression_type.ts} (70%) diff --git a/x-pack/plugins/canvas/public/components/arg_add_popover/arg_add_popover.tsx b/x-pack/plugins/canvas/public/components/arg_add_popover/arg_add_popover.tsx index e1cd5c55393fb..0368cd3d9facf 100644 --- a/x-pack/plugins/canvas/public/components/arg_add_popover/arg_add_popover.tsx +++ b/x-pack/plugins/canvas/public/components/arg_add_popover/arg_add_popover.tsx @@ -11,8 +11,7 @@ import { EuiButtonIcon } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { Popover } from '../popover'; import { ArgAdd } from '../arg_add'; -// @ts-expect-error untyped local -import { Arg } from '../../expression_types/arg'; +import type { Arg } from '../../expression_types/arg'; const strings = { getAddAriaLabel: () => @@ -51,8 +50,8 @@ export const ArgAddPopover: FC = ({ options }) => { options.map((opt) => ( { opt.onValueAdd(); closePopover(); diff --git a/x-pack/plugins/canvas/public/components/datasource/__stories__/datasource_component.stories.tsx b/x-pack/plugins/canvas/public/components/datasource/__stories__/datasource_component.stories.tsx index 27fc9e8871c1f..157b612afbb23 100644 --- a/x-pack/plugins/canvas/public/components/datasource/__stories__/datasource_component.stories.tsx +++ b/x-pack/plugins/canvas/public/components/datasource/__stories__/datasource_component.stories.tsx @@ -12,7 +12,6 @@ import React from 'react'; // @ts-expect-error untyped local import { DatasourceComponent } from '../datasource_component'; import { templateFromReactComponent } from '../../../../public/lib/template_from_react_component'; -// @ts-expect-error untyped local import { Datasource } from '../../../../public/expression_types/datasource'; const TestDatasource = ({ args }: any) => ( diff --git a/x-pack/plugins/canvas/public/components/function_form/function_form.js b/x-pack/plugins/canvas/public/components/function_form/function_form.js deleted file mode 100644 index 3f1bd094286b4..0000000000000 --- a/x-pack/plugins/canvas/public/components/function_form/function_form.js +++ /dev/null @@ -1,38 +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 - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import PropTypes from 'prop-types'; -import { compose, branch, renderComponent } from 'recompose'; -import { FunctionFormComponent } from './function_form_component'; -import { FunctionUnknown } from './function_unknown'; -import { FunctionFormContextPending } from './function_form_context_pending'; -import { FunctionFormContextError } from './function_form_context_error'; - -// helper to check the state of the passed in expression type -function checkState(state) { - return ({ context, expressionType }) => { - const matchState = !context || context.state === state; - return expressionType && expressionType.requiresContext && matchState; - }; -} - -// alternate render paths based on expression state -const branches = [ - // if no expressionType was provided, render the ArgTypeUnknown component - branch((props) => !props.expressionType, renderComponent(FunctionUnknown)), - // if the expressionType is in a pending state, render ArgTypeContextPending - branch(checkState('pending'), renderComponent(FunctionFormContextPending)), - // if the expressionType is in an error state, render ArgTypeContextError - branch(checkState('error'), renderComponent(FunctionFormContextError)), -]; - -export const FunctionForm = compose(...branches)(FunctionFormComponent); - -FunctionForm.propTypes = { - context: PropTypes.object, - expressionType: PropTypes.object, -}; diff --git a/x-pack/plugins/canvas/public/components/function_form/function_form.tsx b/x-pack/plugins/canvas/public/components/function_form/function_form.tsx new file mode 100644 index 0000000000000..abe31f0105108 --- /dev/null +++ b/x-pack/plugins/canvas/public/components/function_form/function_form.tsx @@ -0,0 +1,60 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import React from 'react'; +import { FunctionFormComponent } from './function_form_component'; +import { FunctionUnknown } from './function_unknown'; +import { FunctionFormContextPending } from './function_form_context_pending'; +import { FunctionFormContextError } from './function_form_context_error'; +import { ExpressionContext } from '../../../types'; +import { RenderArgData, ExpressionType } from '../../expression_types/types'; + +type FunctionFormProps = RenderArgData; + +// helper to check the state of the passed in expression type +function is( + state: ExpressionContext['state'], + expressionType: ExpressionType, + context?: ExpressionContext +) { + const matchState = !context || context.state === state; + return expressionType && expressionType.requiresContext && matchState; +} + +export const FunctionForm: React.FunctionComponent = (props) => { + const { expressionType, context } = props; + + if (!expressionType) { + return ; + } + + if (is('pending', expressionType, context)) { + return ( + + ); + } + + if (is('error', expressionType, context)) { + return ( + + ); + } + + return ; +}; diff --git a/x-pack/plugins/canvas/public/components/function_form/function_form_component.js b/x-pack/plugins/canvas/public/components/function_form/function_form_component.tsx similarity index 50% rename from x-pack/plugins/canvas/public/components/function_form/function_form_component.js rename to x-pack/plugins/canvas/public/components/function_form/function_form_component.tsx index fc953c8dde352..8e625db94b498 100644 --- a/x-pack/plugins/canvas/public/components/function_form/function_form_component.js +++ b/x-pack/plugins/canvas/public/components/function_form/function_form_component.tsx @@ -5,11 +5,14 @@ * 2.0. */ -import React from 'react'; -import PropTypes from 'prop-types'; +import React, { FunctionComponent } from 'react'; +import { RenderArgData } from '../../expression_types/types'; -export const FunctionFormComponent = (props) => { +type FunctionFormComponentProps = RenderArgData; + +export const FunctionFormComponent: FunctionComponent = (props) => { const passedProps = { + name: props.name, argResolver: props.argResolver, args: props.args, argType: props.argType, @@ -24,27 +27,8 @@ export const FunctionFormComponent = (props) => { onValueAdd: props.onValueAdd, onValueChange: props.onValueChange, onValueRemove: props.onValueRemove, + updateContext: props.updateContext, }; return
{props.expressionType.render(passedProps)}
; }; - -FunctionFormComponent.propTypes = { - // props passed into expression type render functions - argResolver: PropTypes.func.isRequired, - args: PropTypes.object.isRequired, - argType: PropTypes.string.isRequired, - argTypeDef: PropTypes.object.isRequired, - filterGroups: PropTypes.array.isRequired, - context: PropTypes.object, - expressionIndex: PropTypes.number.isRequired, - expressionType: PropTypes.object.isRequired, - nextArgType: PropTypes.string, - nextExpressionType: PropTypes.object, - onAssetAdd: PropTypes.func.isRequired, - onValueAdd: PropTypes.func.isRequired, - onValueChange: PropTypes.func.isRequired, - onValueChange: PropTypes.func.isRequired, - onValueRemove: PropTypes.func.isRequired, - onValueRemove: PropTypes.func.isRequired, -}; diff --git a/x-pack/plugins/canvas/public/components/function_form/function_form_context_error.tsx b/x-pack/plugins/canvas/public/components/function_form/function_form_context_error.tsx index 2ee709edbf91c..88ad97c52a68f 100644 --- a/x-pack/plugins/canvas/public/components/function_form/function_form_context_error.tsx +++ b/x-pack/plugins/canvas/public/components/function_form/function_form_context_error.tsx @@ -6,11 +6,11 @@ */ import React, { FunctionComponent } from 'react'; -import PropTypes from 'prop-types'; import { i18n } from '@kbn/i18n'; +import { ExpressionContext } from '../../../types'; const strings = { - getContextErrorMessage: (errorMessage: string) => + getContextErrorMessage: (errorMessage: string | null = '') => i18n.translate('xpack.canvas.functionForm.contextError', { defaultMessage: 'ERROR: {errorMessage}', values: { @@ -18,18 +18,14 @@ const strings = { }, }), }; -interface Props { - context: { - error: string; - }; +interface FunctionFormContextErrorProps { + context: ExpressionContext; } -export const FunctionFormContextError: FunctionComponent = ({ context }) => ( +export const FunctionFormContextError: FunctionComponent = ({ + context, +}) => (
{strings.getContextErrorMessage(context.error)}
); - -FunctionFormContextError.propTypes = { - context: PropTypes.shape({ error: PropTypes.string }).isRequired, -}; diff --git a/x-pack/plugins/canvas/public/components/function_form/function_form_context_pending.js b/x-pack/plugins/canvas/public/components/function_form/function_form_context_pending.js deleted file mode 100644 index f4a2a71bb03e8..0000000000000 --- a/x-pack/plugins/canvas/public/components/function_form/function_form_context_pending.js +++ /dev/null @@ -1,46 +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 - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import React from 'react'; -import PropTypes from 'prop-types'; -import { Loading } from '../loading'; - -export class FunctionFormContextPending extends React.PureComponent { - static propTypes = { - context: PropTypes.object, - contextExpression: PropTypes.string, - expressionType: PropTypes.object.isRequired, - updateContext: PropTypes.func.isRequired, - }; - - componentDidMount() { - this.fetchContext(this.props); - } - - UNSAFE_componentWillReceiveProps(newProps) { - const oldContext = this.props.contextExpression; - const newContext = newProps.contextExpression; - const forceUpdate = newProps.expressionType.requiresContext && oldContext !== newContext; - this.fetchContext(newProps, forceUpdate); - } - - fetchContext = (props, force = false) => { - // dispatch context update if none is provided - const { expressionType, context, updateContext } = props; - if (force || (context == null && expressionType.requiresContext)) { - updateContext(); - } - }; - - render() { - return ( -
- -
- ); - } -} diff --git a/x-pack/plugins/canvas/public/components/function_form/function_form_context_pending.tsx b/x-pack/plugins/canvas/public/components/function_form/function_form_context_pending.tsx new file mode 100644 index 0000000000000..6cd7b59a2d214 --- /dev/null +++ b/x-pack/plugins/canvas/public/components/function_form/function_form_context_pending.tsx @@ -0,0 +1,47 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import React, { useCallback, useEffect } from 'react'; +import usePrevious from 'react-use/lib/usePrevious'; +import { Loading } from '../loading'; +import { CanvasElement, ExpressionContext } from '../../../types'; +import { ExpressionType } from '../../expression_types/types'; + +interface FunctionFormContextPendingProps { + context?: ExpressionContext; + contextExpression?: string; + expressionType: ExpressionType; + updateContext: (element?: CanvasElement) => void; +} + +export const FunctionFormContextPending: React.FunctionComponent = ( + props +) => { + const { contextExpression, expressionType, context, updateContext } = props; + const prevContextExpression = usePrevious(contextExpression); + const fetchContext = useCallback( + (force = false) => { + // dispatch context update if none is provided + if (force || (context == null && expressionType.requiresContext)) { + updateContext(); + } + }, + [context, expressionType.requiresContext, updateContext] + ); + + useEffect(() => { + const forceUpdate = + expressionType.requiresContext && prevContextExpression !== contextExpression; + fetchContext(forceUpdate); + }, [contextExpression, expressionType, fetchContext, prevContextExpression]); + + return ( +
+ +
+ ); +}; diff --git a/x-pack/plugins/canvas/public/components/function_form/index.js b/x-pack/plugins/canvas/public/components/function_form/index.js deleted file mode 100644 index 76eb23d800b00..0000000000000 --- a/x-pack/plugins/canvas/public/components/function_form/index.js +++ /dev/null @@ -1,115 +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 - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import PropTypes from 'prop-types'; -import { connect } from 'react-redux'; -import { findExpressionType } from '../../lib/find_expression_type'; -import { getId } from '../../lib/get_id'; -import { createAsset } from '../../state/actions/assets'; -import { - fetchContext, - setArgumentAtIndex, - addArgumentValueAtIndex, - deleteArgumentAtIndex, -} from '../../state/actions/elements'; -import { - getSelectedElement, - getSelectedPage, - getContextForIndex, - getGlobalFilterGroups, -} from '../../state/selectors/workpad'; -import { getAssets } from '../../state/selectors/assets'; -import { findExistingAsset } from '../../lib/find_existing_asset'; -import { FunctionForm as Component } from './function_form'; - -const mapStateToProps = (state, { expressionIndex }) => ({ - context: getContextForIndex(state, expressionIndex), - element: getSelectedElement(state), - pageId: getSelectedPage(state), - assets: getAssets(state), - filterGroups: getGlobalFilterGroups(state), -}); - -const mapDispatchToProps = (dispatch, { expressionIndex }) => ({ - addArgument: (element, pageId) => (argName, argValue) => () => { - dispatch( - addArgumentValueAtIndex({ index: expressionIndex, element, pageId, argName, value: argValue }) - ); - }, - updateContext: (element) => () => dispatch(fetchContext(expressionIndex, element)), - setArgument: (element, pageId) => (argName, valueIndex) => (value) => { - dispatch( - setArgumentAtIndex({ - index: expressionIndex, - element, - pageId, - argName, - value, - valueIndex, - }) - ); - }, - deleteArgument: (element, pageId) => (argName, argIndex) => () => { - dispatch( - deleteArgumentAtIndex({ - index: expressionIndex, - element, - pageId, - argName, - argIndex, - }) - ); - }, - onAssetAdd: (type, content) => { - // make the ID here and pass it into the action - const assetId = getId('asset'); - dispatch(createAsset(type, content, assetId)); - - // then return the id, so the caller knows the id that will be created - return assetId; - }, -}); - -const mergeProps = (stateProps, dispatchProps, ownProps) => { - const { element, pageId, assets } = stateProps; - const { argType, nextArgType } = ownProps; - const { - updateContext, - setArgument, - addArgument, - deleteArgument, - onAssetAdd, - ...dispatchers - } = dispatchProps; - - return { - ...stateProps, - ...dispatchers, - ...ownProps, - updateContext: updateContext(element), - expressionType: findExpressionType(argType), - nextExpressionType: nextArgType ? findExpressionType(nextArgType) : nextArgType, - onValueChange: setArgument(element, pageId), - onValueAdd: addArgument(element, pageId), - onValueRemove: deleteArgument(element, pageId), - onAssetAdd: (type, content) => { - const existingId = findExistingAsset(type, content, assets); - if (existingId) { - return existingId; - } - return onAssetAdd(type, content); - }, - }; -}; - -export const FunctionForm = connect(mapStateToProps, mapDispatchToProps, mergeProps)(Component); - -FunctionForm.propTypes = { - expressionIndex: PropTypes.number, - argType: PropTypes.string, - nextArgType: PropTypes.string, -}; diff --git a/x-pack/plugins/canvas/public/components/function_form/index.tsx b/x-pack/plugins/canvas/public/components/function_form/index.tsx new file mode 100644 index 0000000000000..9caf18e9e8b4e --- /dev/null +++ b/x-pack/plugins/canvas/public/components/function_form/index.tsx @@ -0,0 +1,150 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import React, { useCallback } from 'react'; +import { useDispatch, useSelector } from 'react-redux'; +import { Ast } from '@kbn/interpreter/common'; +import { + ExpressionAstExpression, + ExpressionValue, +} from '../../../../../../src/plugins/expressions'; +import { findExpressionType } from '../../lib/find_expression_type'; +import { getId } from '../../lib/get_id'; +// @ts-expect-error unconverted action function +import { createAsset } from '../../state/actions/assets'; +import { + fetchContext, + setArgumentAtIndex, + addArgumentValueAtIndex, + deleteArgumentAtIndex, + // @ts-expect-error untyped local +} from '../../state/actions/elements'; +import { + getSelectedElement, + getSelectedPage, + getContextForIndex, + getGlobalFilterGroups, +} from '../../state/selectors/workpad'; +import { getAssets } from '../../state/selectors/assets'; +// @ts-expect-error unconverted lib +import { findExistingAsset } from '../../lib/find_existing_asset'; +import { FunctionForm as Component } from './function_form'; +import { ArgType, ArgTypeDef } from '../../expression_types/types'; +import { State, ExpressionContext, CanvasElement, AssetType } from '../../../types'; + +interface FunctionFormProps { + name: string; + argResolver: (ast: ExpressionAstExpression) => Promise; + args: Record> | null; + argType: ArgType; + argTypeDef: ArgTypeDef; + expressionIndex: number; + nextArgType?: ArgType; +} + +export const FunctionForm: React.FunctionComponent = (props) => { + const { expressionIndex, argType, nextArgType } = props; + const dispatch = useDispatch(); + const context = useSelector((state) => + getContextForIndex(state, expressionIndex) + ); + const element = useSelector((state) => + getSelectedElement(state) + ); + const pageId = useSelector((state) => getSelectedPage(state)); + const assets = useSelector((state) => getAssets(state)); + const filterGroups = useSelector((state) => getGlobalFilterGroups(state)); + const addArgument = useCallback( + (argName: string, argValue: string | Ast | null) => () => { + dispatch( + addArgumentValueAtIndex({ + index: expressionIndex, + element, + pageId, + argName, + value: argValue, + }) + ); + }, + [dispatch, element, expressionIndex, pageId] + ); + + const updateContext = useCallback(() => dispatch(fetchContext(expressionIndex, element)), [ + dispatch, + element, + expressionIndex, + ]); + + const setArgument = useCallback( + (argName: string, valueIndex: number) => (value: string | Ast | null) => { + dispatch( + setArgumentAtIndex({ + index: expressionIndex, + element, + pageId, + argName, + value, + valueIndex, + }) + ); + }, + [dispatch, element, expressionIndex, pageId] + ); + + const deleteArgument = useCallback( + (argName: string, argIndex: number) => () => { + dispatch( + deleteArgumentAtIndex({ + index: expressionIndex, + element, + pageId, + argName, + argIndex, + }) + ); + }, + [dispatch, element, expressionIndex, pageId] + ); + + const onAssetAddDispatch = useCallback( + (type: AssetType['type'], content: AssetType['value']) => { + // make the ID here and pass it into the action + const assetId = getId('asset'); + dispatch(createAsset(type, content, assetId)); + + // then return the id, so the caller knows the id that will be created + return assetId; + }, + [dispatch] + ); + + const onAssetAdd = useCallback( + (type: AssetType['type'], content: AssetType['value']) => { + const existingId = findExistingAsset(type, content, assets); + if (existingId) { + return existingId; + } + return onAssetAddDispatch(type, content); + }, + [assets, onAssetAddDispatch] + ); + + return ( + + ); +}; diff --git a/x-pack/plugins/canvas/public/expression_types/arg.js b/x-pack/plugins/canvas/public/expression_types/arg.js deleted file mode 100644 index c3b351e5634ec..0000000000000 --- a/x-pack/plugins/canvas/public/expression_types/arg.js +++ /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 - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { createElement } from 'react'; -import { pick } from 'lodash'; -import { ArgForm } from '../components/arg_form'; -import { argTypeRegistry } from './arg_type'; - -export class Arg { - constructor(props) { - const argType = argTypeRegistry.get(props.argType); - if (!argType) { - throw new Error(`Invalid arg type: ${props.argType}`); - } - if (!props.name) { - throw new Error('Args must have a name property'); - } - - // properties that can be overridden - const defaultProps = { - multi: false, - required: false, - types: [], - default: argType.default != null ? argType.default : null, - options: {}, - resolve: () => ({}), - }; - - const viewOverrides = { - argType, - ...pick(props, [ - 'name', - 'displayName', - 'help', - 'multi', - 'required', - 'types', - 'default', - 'resolve', - 'options', - ]), - }; - - Object.assign(this, defaultProps, argType, viewOverrides); - } - - // TODO: Document what these otherProps are. Maybe make them named arguments? - render({ onValueChange, onValueRemove, argValue, key, label, ...otherProps }) { - // This is everything the arg_type template needs to render - const templateProps = { - ...otherProps, - ...this.resolve(otherProps), - onValueChange, - argValue, - typeInstance: this, - }; - - const formProps = { - key, - argTypeInstance: this, - valueMissing: this.required && argValue == null, - label, - onValueChange, - onValueRemove, - templateProps, - argId: key, - }; - - return createElement(ArgForm, formProps); - } -} diff --git a/x-pack/plugins/canvas/public/expression_types/arg.ts b/x-pack/plugins/canvas/public/expression_types/arg.ts new file mode 100644 index 0000000000000..0fc1c996f327c --- /dev/null +++ b/x-pack/plugins/canvas/public/expression_types/arg.ts @@ -0,0 +1,145 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { merge } from 'lodash'; +import { createElement } from 'react'; +import { Ast } from '@kbn/interpreter/common'; +// @ts-expect-error unconverted components +import { ArgForm } from '../components/arg_form'; +import { argTypeRegistry } from './arg_type_registry'; +import type { ArgType, ArgTypeDef, ExpressionType } from './types'; +import { + AssetType, + CanvasElement, + ExpressionAstExpression, + ExpressionValue, + ExpressionContext, +} from '../../types'; +import { BaseFormProps } from './base_form'; + +interface ArtOwnProps { + argType: ArgType; + multi?: boolean; + required?: boolean; + types?: string[]; + default?: string | null; + resolve?: (...args: any[]) => any; + options?: { + include?: string[]; + confirm?: string; + labelValue?: string; + choices?: Array<{ name: string; value: string }>; + min?: number; + max?: number; + shapes?: string[]; + }; +} +export type ArgProps = ArtOwnProps & BaseFormProps; + +export interface DataArg { + argValue?: string | Ast | null; + skipRender?: boolean; + label?: string; + valueIndex: number; + key?: string; + labels?: string[]; + contextExpression?: string; + name: string; + argResolver: (ast: ExpressionAstExpression) => Promise; + args: Record> | null; + argType: ArgType; + argTypeDef?: ArgTypeDef; + filterGroups: string[]; + context?: ExpressionContext; + expressionIndex: number; + expressionType: ExpressionType; + nextArgType?: ArgType; + nextExpressionType?: ExpressionType; + onValueAdd: (argName: string, argValue: string | Ast | null) => () => void; + onAssetAdd: (type: AssetType['type'], content: AssetType['value']) => string; + onValueChange: (value: Ast | string) => void; + onValueRemove: () => void; + updateContext: (element?: CanvasElement) => void; + typeInstance?: ExpressionType; +} + +export class Arg { + argType?: ArgType; + multi?: boolean; + required?: boolean; + types?: string[]; + default?: string | null; + resolve?: (...args: any[]) => any; + options?: { + include: string[]; + }; + name: string = ''; + displayName?: string; + help?: string; + + constructor(props: ArgProps) { + const argType = argTypeRegistry.get(props.argType); + if (!argType) { + throw new Error(`Invalid arg type: ${props.argType}`); + } + if (!props.name) { + throw new Error('Args must have a name property'); + } + + // properties that can be overridden + const defaultProps = { + multi: false, + required: false, + types: [], + default: argType.default != null ? argType.default : null, + options: {}, + resolve: () => ({}), + }; + + const { name, displayName, help, multi, types, options } = props; + + merge(this, defaultProps, argType, { + argType, + name, + displayName, + help, + multi, + types, + default: props.default, + resolve: props.resolve, + required: props.required, + options, + }); + } + + // TODO: Document what these otherProps are. Maybe make them named arguments? + render(data: DataArg) { + const { onValueChange, onValueRemove, argValue, key, label, ...otherProps } = data; + // This is everything the arg_type template needs to render + const templateProps = { + ...otherProps, + ...this.resolve?.(otherProps), + onValueChange, + argValue, + typeInstance: this, + }; + + const formProps = { + key, + argTypeInstance: this, + valueMissing: this.required && argValue == null, + label, + onValueChange, + onValueRemove, + templateProps, + argId: key, + options: this.options, + }; + + return createElement(ArgForm, formProps); + } +} diff --git a/x-pack/plugins/canvas/public/expression_types/arg_type.ts b/x-pack/plugins/canvas/public/expression_types/arg_type.ts new file mode 100644 index 0000000000000..2345b07d79807 --- /dev/null +++ b/x-pack/plugins/canvas/public/expression_types/arg_type.ts @@ -0,0 +1,33 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { templateFromReactComponent } from '../lib/template_from_react_component'; +import { BaseForm, BaseFormProps } from './base_form'; + +interface ArgTypeOwnProps { + simpleTemplate: ReturnType; + template?: ReturnType; + default?: string; + resolveArgValue?: boolean; +} + +export type ArgTypeProps = ArgTypeOwnProps & BaseFormProps; + +export class ArgType extends BaseForm { + simpleTemplate: ReturnType; + template?: ReturnType; + default?: string; + resolveArgValue: boolean; + + constructor(props: ArgTypeProps) { + super(props); + this.simpleTemplate = props.simpleTemplate; + this.template = props.template; + this.default = props.default; + this.resolveArgValue = Boolean(props.resolveArgValue); + } +} diff --git a/x-pack/plugins/canvas/public/expression_types/arg_type.js b/x-pack/plugins/canvas/public/expression_types/arg_type_registry.ts similarity index 52% rename from x-pack/plugins/canvas/public/expression_types/arg_type.js rename to x-pack/plugins/canvas/public/expression_types/arg_type_registry.ts index 30273cedd818c..579245d0d312b 100644 --- a/x-pack/plugins/canvas/public/expression_types/arg_type.js +++ b/x-pack/plugins/canvas/public/expression_types/arg_type_registry.ts @@ -4,23 +4,11 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ - import { Registry } from '@kbn/interpreter/common'; -import { BaseForm } from './base_form'; - -export class ArgType extends BaseForm { - constructor(props) { - super(props); - - this.simpleTemplate = props.simpleTemplate; - this.template = props.template; - this.default = props.default; - this.resolveArgValue = Boolean(props.resolveArgValue); - } -} +import { ArgType, ArgTypeProps } from './arg_type'; -class ArgTypeRegistry extends Registry { - wrapper(obj) { +class ArgTypeRegistry extends Registry { + wrapper(obj: ArgTypeProps) { return new ArgType(obj); } } diff --git a/x-pack/plugins/canvas/public/expression_types/base_form.js b/x-pack/plugins/canvas/public/expression_types/base_form.ts similarity index 72% rename from x-pack/plugins/canvas/public/expression_types/base_form.js rename to x-pack/plugins/canvas/public/expression_types/base_form.ts index 7ca2d6a78b656..11d6b24ee3e86 100644 --- a/x-pack/plugins/canvas/public/expression_types/base_form.js +++ b/x-pack/plugins/canvas/public/expression_types/base_form.ts @@ -5,8 +5,18 @@ * 2.0. */ +export interface BaseFormProps { + name: string; + displayName?: string; + help?: string; +} + export class BaseForm { - constructor(props) { + name: string; + displayName: string; + help: string; + + constructor(props: BaseFormProps) { if (!props.name) { throw new Error('Expression specs require a name property'); } diff --git a/x-pack/plugins/canvas/public/expression_types/datasource.js b/x-pack/plugins/canvas/public/expression_types/datasource.js deleted file mode 100644 index f8bbff702a4e9..0000000000000 --- a/x-pack/plugins/canvas/public/expression_types/datasource.js +++ /dev/null @@ -1,76 +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 - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import React from 'react'; -import PropTypes from 'prop-types'; -import { Registry } from '@kbn/interpreter/common'; -import { RenderToDom } from '../components/render_to_dom'; -import { ExpressionFormHandlers } from '../../common/lib/expression_form_handlers'; -import { BaseForm } from './base_form'; - -const defaultTemplate = () => ( -
-

This datasource has no interface. Use the expression editor to make changes.

-
-); - -class DatasourceWrapper extends React.PureComponent { - static propTypes = { - spec: PropTypes.object.isRequired, - datasourceProps: PropTypes.object.isRequired, - handlers: PropTypes.object.isRequired, - }; - - componentDidUpdate() { - this.callRenderFn(); - } - - componentWillUnmount() { - this.props.handlers.destroy(); - } - - callRenderFn = () => { - const { spec, datasourceProps, handlers } = this.props; - const { template } = spec; - template(this.domNode, datasourceProps, handlers); - }; - - render() { - return ( - { - this.domNode = domNode; - this.callRenderFn(); - }} - /> - ); - } -} - -export class Datasource extends BaseForm { - constructor(props) { - super(props); - - this.template = props.template || defaultTemplate; - this.image = props.image; - } - - render(props = {}) { - const expressionFormHandlers = new ExpressionFormHandlers(); - return ( - - ); - } -} - -class DatasourceRegistry extends Registry { - wrapper(obj) { - return new Datasource(obj); - } -} - -export const datasourceRegistry = new DatasourceRegistry(); diff --git a/x-pack/plugins/canvas/public/expression_types/datasource.tsx b/x-pack/plugins/canvas/public/expression_types/datasource.tsx new file mode 100644 index 0000000000000..0afb9bdd2f96a --- /dev/null +++ b/x-pack/plugins/canvas/public/expression_types/datasource.tsx @@ -0,0 +1,99 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import React, { useEffect, useRef, useCallback } from 'react'; +import { Ast } from '@kbn/interpreter/common'; +import { RenderToDom } from '../components/render_to_dom'; +import { BaseForm, BaseFormProps } from './base_form'; +import { ExpressionFormHandlers } from '../../common/lib'; +import { ExpressionFunction } from '../../types'; + +const defaultTemplate = () => ( +
+

This datasource has no interface. Use the expression editor to make changes.

+
+); + +type TemplateFn = ( + domNode: HTMLElement, + config: DatasourceRenderProps, + handlers: ExpressionFormHandlers +) => void; + +export type DatasourceProps = { + template?: TemplateFn; + image?: string; + requiresContext?: boolean; +} & BaseFormProps; + +export interface DatasourceRenderProps { + args: Record> | null; + updateArgs: (...args: any[]) => void; + datasourceDef: ExpressionFunction; + isInvalid: boolean; + setInvalid: (invalid: boolean) => void; + defaultIndex: string; + renderError: (...args: any[]) => void; +} + +interface DatasourceWrapperProps { + handlers: ExpressionFormHandlers; + spec: Datasource; + datasourceProps: DatasourceRenderProps; +} + +const DatasourceWrapper: React.FunctionComponent = (props) => { + const domNodeRef = useRef(); + const { spec, datasourceProps, handlers } = props; + + const callRenderFn = useCallback(() => { + const { template } = spec; + + if (!domNodeRef.current) { + return; + } + + template(domNodeRef.current, datasourceProps, handlers); + }, [datasourceProps, handlers, spec]); + + useEffect(() => { + callRenderFn(); + return () => { + handlers.destroy(); + }; + }, [callRenderFn, handlers, props]); + + return ( + { + domNodeRef.current = domNode; + callRenderFn(); + }} + /> + ); +}; + +export class Datasource extends BaseForm { + template: TemplateFn | React.FC; + image?: string; + requiresContext?: boolean; + + constructor(props: DatasourceProps) { + super(props); + + this.template = props.template ?? defaultTemplate; + this.image = props.image; + this.requiresContext = props.requiresContext; + } + + render(props: DatasourceRenderProps) { + const expressionFormHandlers = new ExpressionFormHandlers(); + return ( + + ); + } +} diff --git a/x-pack/plugins/canvas/public/expression_types/datasource_registry.ts b/x-pack/plugins/canvas/public/expression_types/datasource_registry.ts new file mode 100644 index 0000000000000..b6427fac9d4a0 --- /dev/null +++ b/x-pack/plugins/canvas/public/expression_types/datasource_registry.ts @@ -0,0 +1,18 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { Registry } from '@kbn/interpreter/common'; +import { Datasource } from './datasource'; +import type { Datasource as DatasourceType, DatasourceProps } from './datasource'; + +class DatasourceRegistry extends Registry { + wrapper(obj: DatasourceProps): DatasourceType { + return new Datasource(obj); + } +} + +export const datasourceRegistry = new DatasourceRegistry(); diff --git a/x-pack/plugins/canvas/public/expression_types/function_form.js b/x-pack/plugins/canvas/public/expression_types/function_form.tsx similarity index 57% rename from x-pack/plugins/canvas/public/expression_types/function_form.js rename to x-pack/plugins/canvas/public/expression_types/function_form.tsx index 2f4e983e9fd4e..70279453ac658 100644 --- a/x-pack/plugins/canvas/public/expression_types/function_form.js +++ b/x-pack/plugins/canvas/public/expression_types/function_form.tsx @@ -5,25 +5,76 @@ * 2.0. */ +import React, { ReactElement } from 'react'; import { EuiCallOut } from '@elastic/eui'; -import React from 'react'; import { isPlainObject, uniq, last, compact } from 'lodash'; -import { fromExpression } from '@kbn/interpreter/common'; +import { Ast, fromExpression } from '@kbn/interpreter/common'; import { ArgAddPopover } from '../components/arg_add_popover'; +// @ts-expect-error unconverted components import { SidebarSection } from '../components/sidebar/sidebar_section'; +// @ts-expect-error unconverted components import { SidebarSectionTitle } from '../components/sidebar/sidebar_section_title'; -import { BaseForm } from './base_form'; -import { Arg } from './arg'; +import { BaseForm, BaseFormProps } from './base_form'; +import { Arg, ArgProps } from './arg'; +import { ArgType, ArgTypeDef, ExpressionType } from './types'; +import { + AssetType, + CanvasElement, + DatatableColumn, + ExpressionAstExpression, + ExpressionContext, + ExpressionValue, +} from '../../types'; + +export interface DataArg { + arg: Arg | undefined; + argValues?: Array; + skipRender?: boolean; + label?: 'string'; +} + +export type RenderArgData = BaseFormProps & { + argType: ArgType; + argTypeDef?: ArgTypeDef; + args: Record> | null; + argResolver: (ast: ExpressionAstExpression) => Promise; + context?: ExpressionContext; + contextExpression?: string; + expressionIndex: number; + expressionType: ExpressionType; + filterGroups: string[]; + nextArgType?: ArgType; + nextExpressionType?: ExpressionType; + onValueAdd: (argName: string, argValue: string | Ast | null) => () => void; + onValueChange: (argName: string, argIndex: number) => (value: string | Ast) => void; + onValueRemove: (argName: string, argIndex: number) => () => void; + onAssetAdd: (type: AssetType['type'], content: AssetType['value']) => string; + updateContext: (element?: CanvasElement) => void; + typeInstance?: ExpressionType; + columns?: DatatableColumn[]; +}; + +export type RenderArgProps = { + typeInstance: FunctionForm; +} & RenderArgData; + +export type FunctionFormProps = { + args?: ArgProps[]; + resolve?: (...args: any[]) => any; +} & BaseFormProps; export class FunctionForm extends BaseForm { - constructor(props) { + args: ArgProps[]; + resolve: (...args: any[]) => any; + + constructor(props: FunctionFormProps) { super({ ...props }); this.args = props.args || []; this.resolve = props.resolve || (() => ({})); } - renderArg(props, dataArg) { + renderArg(props: RenderArgProps, dataArg: DataArg) { const { onValueRemove, onValueChange, ...passedProps } = props; const { arg, argValues, skipRender, label } = dataArg; const { argType, expressionIndex } = passedProps; @@ -32,22 +83,24 @@ export class FunctionForm extends BaseForm { if (!arg || skipRender) { return null; } - - const renderArgWithProps = (argValue, valueIndex) => + const renderArgWithProps = ( + argValue: string | Ast | null, + valueIndex: number + ): ReactElement | null => arg.render({ key: `${argType}-${expressionIndex}-${arg.name}-${valueIndex}`, ...passedProps, label, valueIndex, - argValue, onValueChange: onValueChange(arg.name, valueIndex), onValueRemove: onValueRemove(arg.name, valueIndex), + argValue: argValue ?? null, }); // render the argument's template, wrapped in a remove control // if the argument is required but not included, render the control anyway if (!argValues && arg.required) { - return renderArgWithProps({ type: undefined, value: '' }, 0); + return renderArgWithProps(null, 0); } // render all included argument controls @@ -55,7 +108,7 @@ export class FunctionForm extends BaseForm { } // TODO: Argument adding isn't very good, we should improve this UI - getAddableArg(props, dataArg) { + getAddableArg(props: RenderArgProps, dataArg: DataArg) { const { onValueAdd } = props; const { arg, argValues, skipRender } = dataArg; @@ -68,47 +121,54 @@ export class FunctionForm extends BaseForm { } const value = arg.default == null ? null : fromExpression(arg.default, 'argument'); - return { arg, onValueAdd: onValueAdd(arg.name, value) }; } - resolveArg() { + resolveArg(...args: unknown[]) { // basically a no-op placeholder return {}; } - render(data = {}) { + render(data: RenderArgData) { + if (!data) { + data = { + args: null, + argTypeDef: undefined, + } as RenderArgData; + } const { args, argTypeDef } = data; // Don't instaniate these until render time, to give the registries a chance to populate. const argInstances = this.args.map((argSpec) => new Arg(argSpec)); - if (!isPlainObject(args)) { + if (args === null || !isPlainObject(args)) { throw new Error(`Form "${this.name}" expects "args" object`); } // get a mapping of arg values from the expression and from the renderable's schema const argNames = uniq(argInstances.map((arg) => arg.name).concat(Object.keys(args))); const dataArgs = argNames.map((argName) => { - const arg = argInstances.find((arg) => arg.name === argName); - + const arg = argInstances.find((argument) => argument.name === argName); // if arg is not multi, only preserve the last value found // otherwise, leave the value alone (including if the arg is not defined) const isMulti = arg && arg.multi; - const argValues = args[argName] && !isMulti ? [last(args[argName])] : args[argName]; + const argValues = args[argName] && !isMulti ? [last(args[argName]) ?? null] : args[argName]; return { arg, argValues }; }); // props are passed to resolve and the returned object is mixed into the template props const props = { ...data, ...this.resolve(data), typeInstance: this }; - try { // allow a hook to override the data args const resolvedDataArgs = dataArgs.map((d) => ({ ...d, ...this.resolveArg(d, props) })); - const argumentForms = compact(resolvedDataArgs.map((d) => this.renderArg(props, d))); - const addableArgs = compact(resolvedDataArgs.map((d) => this.getAddableArg(props, d))); + const argumentForms = compact( + resolvedDataArgs.map((dataArg) => this.renderArg(props, dataArg)) + ); + const addableArgs = compact( + resolvedDataArgs.map((dataArg) => this.getAddableArg(props, dataArg)) + ); if (!addableArgs.length && !argumentForms.length) { return null; @@ -116,13 +176,13 @@ export class FunctionForm extends BaseForm { return ( - + {addableArgs.length === 0 ? null : } {argumentForms} ); - } catch (e) { + } catch (e: any) { return (

{e.message}

diff --git a/x-pack/plugins/canvas/public/expression_types/index.js b/x-pack/plugins/canvas/public/expression_types/index.js deleted file mode 100644 index ce1af41669086..0000000000000 --- a/x-pack/plugins/canvas/public/expression_types/index.js +++ /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 - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -export { Datasource, datasourceRegistry } from './datasource'; -export { Transform, transformRegistry } from './transform'; -export { Model, modelRegistry } from './model'; -export { View, viewRegistry } from './view'; -export { ArgType, argTypeRegistry } from './arg_type'; -export { Arg } from './arg'; diff --git a/x-pack/plugins/canvas/public/expression_types/index.ts b/x-pack/plugins/canvas/public/expression_types/index.ts new file mode 100644 index 0000000000000..88cb9aa1548a2 --- /dev/null +++ b/x-pack/plugins/canvas/public/expression_types/index.ts @@ -0,0 +1,23 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +export { Datasource } from './datasource'; +export { datasourceRegistry } from './datasource_registry'; + +export { Transform } from './transform'; +export { transformRegistry } from './transform_registry'; + +export { Model } from './model'; +export { modelRegistry } from './model_registry'; + +export { View } from './view'; +export { viewRegistry } from './view_registry'; + +export { ArgType } from './arg_type'; +export { argTypeRegistry } from './arg_type_registry'; + +export { Arg } from './arg'; diff --git a/x-pack/plugins/canvas/public/expression_types/model.js b/x-pack/plugins/canvas/public/expression_types/model.js deleted file mode 100644 index 1ba4f74a0ba5a..0000000000000 --- a/x-pack/plugins/canvas/public/expression_types/model.js +++ /dev/null @@ -1,72 +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 - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { get, pick } from 'lodash'; -import { Registry } from '@kbn/interpreter/common'; -import { FunctionForm } from './function_form'; - -const NO_NEXT_EXP = 'no next expression'; -const MISSING_MODEL_ARGS = 'missing model args'; - -function getModelArgs(expressionType) { - if (!expressionType) { - return NO_NEXT_EXP; - } - - if (!expressionType.modelArgs) { - return MISSING_MODEL_ARGS; - } - - return expressionType.modelArgs.length > 0 ? expressionType.modelArgs : MISSING_MODEL_ARGS; -} - -export class Model extends FunctionForm { - constructor(props) { - super(props); - - const propNames = ['requiresContext']; - const defaultProps = { - requiresContext: true, - }; - - Object.assign(this, defaultProps, pick(props, propNames)); - } - - resolveArg(dataArg, props) { - // custom argument resolver - // uses `modelArgs` from following expression to control which arguments get rendered - const { nextExpressionType } = props; - const modelArgs = getModelArgs(nextExpressionType); - - // if there is no following expression, or no modelArgs, argument is shown by default - if (modelArgs === NO_NEXT_EXP || modelArgs === MISSING_MODEL_ARGS) { - return { skipRender: false }; - } - - // if argument is missing from modelArgs, mark it as skipped - const argName = get(dataArg, 'arg.name'); - const modelArg = modelArgs.find((modelArg) => { - if (Array.isArray(modelArg)) { - return modelArg[0] === argName; - } - return modelArg === argName; - }); - - return { - label: Array.isArray(modelArg) ? get(modelArg[1], 'label') : null, - skipRender: !modelArg, - }; - } -} - -class ModelRegistry extends Registry { - wrapper(obj) { - return new Model(obj); - } -} - -export const modelRegistry = new ModelRegistry(); diff --git a/x-pack/plugins/canvas/public/expression_types/model.ts b/x-pack/plugins/canvas/public/expression_types/model.ts new file mode 100644 index 0000000000000..49f8346212f96 --- /dev/null +++ b/x-pack/plugins/canvas/public/expression_types/model.ts @@ -0,0 +1,80 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { merge } from 'lodash'; +import { FunctionForm, FunctionFormProps } from './function_form'; +import { Arg, View } from './types'; + +const NO_NEXT_EXP = 'no next expression'; +const MISSING_MODEL_ARGS = 'missing model args'; + +interface ModelOwnProps { + nextExpressionType?: View; + requiresContext?: boolean; + default?: string; + resolveArgValue?: boolean; + modelArgs: string[] | Arg[]; +} + +interface DataArg { + arg: Arg; +} + +export type ModelProps = ModelOwnProps & FunctionFormProps; + +function getModelArgs(expressionType?: View) { + if (!expressionType) { + return NO_NEXT_EXP; + } + + if (!expressionType?.modelArgs) { + return MISSING_MODEL_ARGS; + } + + return expressionType?.modelArgs.length > 0 ? expressionType?.modelArgs : MISSING_MODEL_ARGS; +} + +export class Model extends FunctionForm { + requiresContext?: boolean; + + constructor(props: ModelProps) { + super(props); + + const defaultProps = { requiresContext: true }; + const { requiresContext } = props; + + merge(this, defaultProps, { requiresContext }); + } + + resolveArg(dataArg: DataArg, props: ModelProps) { + // custom argument resolver + // uses `modelArgs` from following expression to control which arguments get rendered + const { nextExpressionType } = props; + const modelArgs: Array | string = getModelArgs(nextExpressionType); + + // if there is no following expression, or no modelArgs, argument is shown by default + if (modelArgs === NO_NEXT_EXP || modelArgs === MISSING_MODEL_ARGS) { + return { skipRender: false }; + } + + // if argument is missing from modelArgs, mark it as skipped + const argName = dataArg?.arg?.name; + const modelArg = + typeof modelArgs !== 'string' && + modelArgs.find((arg) => { + if (Array.isArray(arg)) { + return arg[0] === argName; + } + return arg === argName; + }); + + return { + label: Array.isArray(modelArg) ? modelArg[1]?.label : null, + skipRender: !modelArg, + }; + } +} diff --git a/x-pack/plugins/canvas/public/expression_types/model_registry.ts b/x-pack/plugins/canvas/public/expression_types/model_registry.ts new file mode 100644 index 0000000000000..f5c290f2fe2e9 --- /dev/null +++ b/x-pack/plugins/canvas/public/expression_types/model_registry.ts @@ -0,0 +1,18 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { Registry } from '@kbn/interpreter/common'; +import { Model } from './model'; +import type { ModelProps, Model as ModelType } from './model'; + +class ModelRegistry extends Registry { + wrapper(obj: ModelProps): ModelType { + return new Model(obj); + } +} + +export const modelRegistry = new ModelRegistry(); diff --git a/x-pack/plugins/canvas/public/expression_types/transform.js b/x-pack/plugins/canvas/public/expression_types/transform.js deleted file mode 100644 index 6a190e72aded7..0000000000000 --- a/x-pack/plugins/canvas/public/expression_types/transform.js +++ /dev/null @@ -1,31 +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 - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { pick } from 'lodash'; -import { Registry } from '@kbn/interpreter/common'; -import { FunctionForm } from './function_form'; - -export class Transform extends FunctionForm { - constructor(props) { - super(props); - - const propNames = ['requiresContext']; - const defaultProps = { - requiresContext: true, - }; - - Object.assign(this, defaultProps, pick(props, propNames)); - } -} - -class TransformRegistry extends Registry { - wrapper(obj) { - return new Transform(obj); - } -} - -export const transformRegistry = new TransformRegistry(); diff --git a/x-pack/plugins/canvas/public/expression_types/transform.ts b/x-pack/plugins/canvas/public/expression_types/transform.ts new file mode 100644 index 0000000000000..6b901b5ae7126 --- /dev/null +++ b/x-pack/plugins/canvas/public/expression_types/transform.ts @@ -0,0 +1,24 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ +import { merge } from 'lodash'; +import { FunctionForm, FunctionFormProps } from './function_form'; + +export type TransformProps = { requiresContext: boolean } & FunctionFormProps; + +export class Transform extends FunctionForm { + requiresContext?: boolean; + + constructor(props: TransformProps) { + super(props); + const { requiresContext } = props; + const defaultProps = { + requiresContext: true, + }; + + merge(this, defaultProps, { requiresContext }); + } +} diff --git a/x-pack/plugins/canvas/public/expression_types/transform_registry.ts b/x-pack/plugins/canvas/public/expression_types/transform_registry.ts new file mode 100644 index 0000000000000..a69f5fcf554fe --- /dev/null +++ b/x-pack/plugins/canvas/public/expression_types/transform_registry.ts @@ -0,0 +1,18 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { Registry } from '@kbn/interpreter/common'; +import { Transform } from './transform'; +import type { Transform as TransformType, TransformProps } from './transform'; + +class TransformRegistry extends Registry { + wrapper(obj: TransformProps): TransformType { + return new Transform(obj); + } +} + +export const transformRegistry = new TransformRegistry(); diff --git a/x-pack/plugins/canvas/public/expression_types/types.ts b/x-pack/plugins/canvas/public/expression_types/types.ts new file mode 100644 index 0000000000000..704dae83c8a55 --- /dev/null +++ b/x-pack/plugins/canvas/public/expression_types/types.ts @@ -0,0 +1,22 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import type { Transform } from './transform'; +import type { View } from './view'; +import type { Datasource } from './datasource'; +import type { Model } from './model'; + +export type ArgType = string; + +export type ArgTypeDef = View | Model | Transform | Datasource; + +export { Transform, View, Datasource, Model }; +export type { Arg } from './arg'; + +export type ExpressionType = View | Model | Transform; + +export type { RenderArgData } from './function_form'; diff --git a/x-pack/plugins/canvas/public/expression_types/view.js b/x-pack/plugins/canvas/public/expression_types/view.js deleted file mode 100644 index a4613e51ecbee..0000000000000 --- a/x-pack/plugins/canvas/public/expression_types/view.js +++ /dev/null @@ -1,38 +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 - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { pick } from 'lodash'; -import { Registry } from '@kbn/interpreter/common'; -import { FunctionForm } from './function_form'; - -export class View extends FunctionForm { - constructor(props) { - super(props); - - const propNames = ['help', 'modelArgs', 'requiresContext']; - const defaultProps = { - help: `Element: ${props.name}`, - requiresContext: true, - }; - - Object.assign(this, defaultProps, pick(props, propNames)); - - this.modelArgs = this.modelArgs || []; - - if (!Array.isArray(this.modelArgs)) { - throw new Error(`${this.name} element is invalid, modelArgs must be an array`); - } - } -} - -class ViewRegistry extends Registry { - wrapper(obj) { - return new View(obj); - } -} - -export const viewRegistry = new ViewRegistry(); diff --git a/x-pack/plugins/canvas/public/expression_types/view.ts b/x-pack/plugins/canvas/public/expression_types/view.ts new file mode 100644 index 0000000000000..ae9c37678c396 --- /dev/null +++ b/x-pack/plugins/canvas/public/expression_types/view.ts @@ -0,0 +1,39 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { merge } from 'lodash'; +import { FunctionForm, FunctionFormProps } from './function_form'; +import { Arg } from './types'; + +interface ViewOwnProps { + modelArgs: string[] | Arg[]; + requiresContext?: boolean; + default?: string; + resolveArgValue?: boolean; +} + +export type ViewProps = ViewOwnProps & FunctionFormProps; + +export class View extends FunctionForm { + modelArgs: string[] | Arg[] = []; + requiresContext?: boolean; + + constructor(props: ViewProps) { + super(props); + const { help, modelArgs, requiresContext } = props; + const defaultProps = { + help: `Element: ${props.name}`, + requiresContext: true, + }; + + merge(this, defaultProps, { help, modelArgs: modelArgs || [], requiresContext }); + + if (!Array.isArray(this.modelArgs)) { + throw new Error(`${this.name} element is invalid, modelArgs must be an array`); + } + } +} diff --git a/x-pack/plugins/canvas/public/expression_types/view_registry.ts b/x-pack/plugins/canvas/public/expression_types/view_registry.ts new file mode 100644 index 0000000000000..108a65c73ec60 --- /dev/null +++ b/x-pack/plugins/canvas/public/expression_types/view_registry.ts @@ -0,0 +1,18 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { Registry } from '@kbn/interpreter/common'; +import { View } from './view'; +import type { View as ViewType, ViewProps } from './view'; + +class ViewRegistry extends Registry { + wrapper(obj: ViewProps): ViewType { + return new View(obj); + } +} + +export const viewRegistry = new ViewRegistry(); diff --git a/x-pack/plugins/canvas/public/lib/find_expression_type.js b/x-pack/plugins/canvas/public/lib/find_expression_type.ts similarity index 70% rename from x-pack/plugins/canvas/public/lib/find_expression_type.js rename to x-pack/plugins/canvas/public/lib/find_expression_type.ts index 037b64b334fd6..cb054414b8725 100644 --- a/x-pack/plugins/canvas/public/lib/find_expression_type.js +++ b/x-pack/plugins/canvas/public/lib/find_expression_type.ts @@ -5,19 +5,19 @@ * 2.0. */ -//import { datasourceRegistry } from '../expression_types/datasource'; -import { transformRegistry } from '../expression_types/transform'; -import { modelRegistry } from '../expression_types/model'; -import { viewRegistry } from '../expression_types/view'; +import { transformRegistry } from '../expression_types/transform_registry'; +import { modelRegistry } from '../expression_types/model_registry'; +import { viewRegistry } from '../expression_types/view_registry'; +import { ArgType, ExpressionType } from '../expression_types/types'; -const expressionTypes = ['view', 'model', 'transform', 'datasource']; +const expressionTypes: ArgType[] = ['view', 'model', 'transform', 'datasource']; -export function findExpressionType(name, type) { +export function findExpressionType(name: string, type?: ArgType | null) { const checkTypes = expressionTypes.filter( (expressionType) => type == null || expressionType === type ); - const matches = checkTypes.reduce((acc, checkType) => { + const matches = checkTypes.reduce((acc: ExpressionType[], checkType) => { let expression; switch (checkType) { case 'view': diff --git a/x-pack/plugins/canvas/public/registries.ts b/x-pack/plugins/canvas/public/registries.ts index 1ad7fa6905c22..56d89affce5ea 100644 --- a/x-pack/plugins/canvas/public/registries.ts +++ b/x-pack/plugins/canvas/public/registries.ts @@ -20,7 +20,6 @@ import { modelRegistry, transformRegistry, viewRegistry, - // @ts-expect-error untyped local } from './expression_types'; import { SetupRegistries } from './plugin_api'; diff --git a/x-pack/plugins/canvas/types/state.ts b/x-pack/plugins/canvas/types/state.ts index cc42839ddfac7..30ded5f2a9c7e 100644 --- a/x-pack/plugins/canvas/types/state.ts +++ b/x-pack/plugins/canvas/types/state.ts @@ -16,6 +16,7 @@ import { Style, Range, } from 'src/plugins/expressions'; +import { Datasource, Model, Transform, View } from '../public/expression_types'; import { AssetType } from './assets'; import { CanvasWorkpad } from './canvas'; @@ -51,7 +52,11 @@ type ExpressionType = | KibanaContext | PointSeries | Style - | Range; + | Range + | View + | Model + | Datasource + | Transform; export interface ExpressionRenderable { state: 'ready' | 'pending'; @@ -60,9 +65,9 @@ export interface ExpressionRenderable { } export interface ExpressionContext { - state: 'ready' | 'pending'; + state: 'ready' | 'pending' | 'error'; value: ExpressionType; - error: null; + error: null | string; } export interface ResolvedArgType { From c1697a1163f41f96c8869f2790a85d66b76e6c68 Mon Sep 17 00:00:00 2001 From: Dario Gieselaar Date: Thu, 9 Sep 2021 12:40:07 +0200 Subject: [PATCH 6/6] [APM] Use new path syntax in waterfall (#111689) --- .../waterfall_container/Waterfall/waterfall_item.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/apm/public/components/app/transaction_details/waterfall_with_summary/waterfall_container/Waterfall/waterfall_item.tsx b/x-pack/plugins/apm/public/components/app/transaction_details/waterfall_with_summary/waterfall_container/Waterfall/waterfall_item.tsx index 1a4fa4f5fe836..4001a0624a809 100644 --- a/x-pack/plugins/apm/public/components/app/transaction_details/waterfall_with_summary/waterfall_container/Waterfall/waterfall_item.tsx +++ b/x-pack/plugins/apm/public/components/app/transaction_details/waterfall_with_summary/waterfall_container/Waterfall/waterfall_item.tsx @@ -230,9 +230,9 @@ function RelatedErrors({ }) { const apmRouter = useApmRouter(); const theme = useTheme(); - const { query } = useApmParams('/services/:serviceName/transactions/view'); + const { query } = useApmParams('/services/{serviceName}/transactions/view'); - const href = apmRouter.link(`/services/:serviceName/errors`, { + const href = apmRouter.link(`/services/{serviceName}/errors`, { path: { serviceName: item.doc.service.name }, query: { ...query,