From c85fc3819a02ca34f3f0503221f77aba17905e8e Mon Sep 17 00:00:00 2001 From: Brian Seeders Date: Mon, 13 Dec 2021 13:22:48 -0500 Subject: [PATCH 1/2] Bump prettier/eslint packages related to Typescript after TS upgrade --- package.json | 8 ++--- yarn.lock | 90 ++++++++++++++++++++++++++-------------------------- 2 files changed, 49 insertions(+), 49 deletions(-) diff --git a/package.json b/package.json index 871e467394e52..d76a63a163ba3 100644 --- a/package.json +++ b/package.json @@ -663,9 +663,9 @@ "@types/yargs": "^15.0.0", "@types/yauzl": "^2.9.1", "@types/zen-observable": "^0.8.0", - "@typescript-eslint/eslint-plugin": "^5.2.0", - "@typescript-eslint/parser": "^5.2.0", - "@typescript-eslint/typescript-estree": "^5.2.0", + "@typescript-eslint/eslint-plugin": "^5.6.0", + "@typescript-eslint/parser": "^5.6.0", + "@typescript-eslint/typescript-estree": "^5.6.0", "@yarnpkg/lockfile": "^1.1.0", "abab": "^2.0.4", "aggregate-error": "^3.1.0", @@ -802,7 +802,7 @@ "postcss": "^7.0.32", "postcss-loader": "^3.0.0", "postcss-prefix-selector": "^1.7.2", - "prettier": "^2.4.0", + "prettier": "^2.5.1", "pretty-ms": "5.0.0", "q": "^1.5.1", "react-test-renderer": "^16.12.0", diff --git a/yarn.lock b/yarn.lock index edfc532366ce4..d5560352616ce 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6785,13 +6785,13 @@ resolved "https://registry.yarnpkg.com/@types/zen-observable/-/zen-observable-0.8.0.tgz#8b63ab7f1aa5321248aad5ac890a485656dcea4d" integrity sha512-te5lMAWii1uEJ4FwLjzdlbw3+n0FZNOvFXHxQDKeT0dilh7HOzdMzV2TrJVUzq8ep7J4Na8OUYPRLSQkJHAlrg== -"@typescript-eslint/eslint-plugin@^5.2.0": - version "5.2.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.2.0.tgz#2bdb247cc2e2afce7efbce09afb9a6f0a8a08434" - integrity sha512-qQwg7sqYkBF4CIQSyRQyqsYvP+g/J0To9ZPVNJpfxfekl5RmdvQnFFTVVwpRtaUDFNvjfe/34TgY/dpc3MgNTw== +"@typescript-eslint/eslint-plugin@^5.6.0": + version "5.7.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.7.0.tgz#12d54709f8ea1da99a01d8a992cd0474ad0f0aa9" + integrity sha512-8RTGBpNn5a9M628wBPrCbJ+v3YTEOE2qeZb7TDkGKTDXSj36KGRg92SpFFaR/0S3rSXQxM0Og/kV9EyadsYSBg== dependencies: - "@typescript-eslint/experimental-utils" "5.2.0" - "@typescript-eslint/scope-manager" "5.2.0" + "@typescript-eslint/experimental-utils" "5.7.0" + "@typescript-eslint/scope-manager" "5.7.0" debug "^4.3.2" functional-red-black-tree "^1.0.1" ignore "^5.1.8" @@ -6799,15 +6799,15 @@ semver "^7.3.5" tsutils "^3.21.0" -"@typescript-eslint/experimental-utils@5.2.0": - version "5.2.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-5.2.0.tgz#e3b2cb9cd0aff9b50f68d9a414c299fd26b067e6" - integrity sha512-fWyT3Agf7n7HuZZRpvUYdFYbPk3iDCq6fgu3ulia4c7yxmPnwVBovdSOX7RL+k8u6hLbrXcdAehlWUVpGh6IEw== +"@typescript-eslint/experimental-utils@5.7.0": + version "5.7.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-5.7.0.tgz#2b1633e6613c3238036156f70c32634843ad034f" + integrity sha512-u57eZ5FbEpzN5kSjmVrSesovWslH2ZyNPnaXQMXWgH57d5+EVHEt76W75vVuI9qKZ5BMDKNfRN+pxcPEjQjb2A== dependencies: "@types/json-schema" "^7.0.9" - "@typescript-eslint/scope-manager" "5.2.0" - "@typescript-eslint/types" "5.2.0" - "@typescript-eslint/typescript-estree" "5.2.0" + "@typescript-eslint/scope-manager" "5.7.0" + "@typescript-eslint/types" "5.7.0" + "@typescript-eslint/typescript-estree" "5.7.0" eslint-scope "^5.1.1" eslint-utils "^3.0.0" @@ -6823,14 +6823,14 @@ eslint-scope "^5.1.1" eslint-utils "^3.0.0" -"@typescript-eslint/parser@^5.2.0": - version "5.2.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-5.2.0.tgz#dc081aa89de16b5676b10215519af3aa7b58fb72" - integrity sha512-Uyy4TjJBlh3NuA8/4yIQptyJb95Qz5PX//6p8n7zG0QnN4o3NF9Je3JHbVU7fxf5ncSXTmnvMtd/LDQWDk0YqA== +"@typescript-eslint/parser@^5.6.0": + version "5.7.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-5.7.0.tgz#4dca6de463d86f02d252e681136a67888ea3b181" + integrity sha512-m/gWCCcS4jXw6vkrPQ1BjZ1vomP01PArgzvauBqzsoZ3urLbsRChexB8/YV8z9HwE3qlJM35FxfKZ1nfP/4x8g== dependencies: - "@typescript-eslint/scope-manager" "5.2.0" - "@typescript-eslint/types" "5.2.0" - "@typescript-eslint/typescript-estree" "5.2.0" + "@typescript-eslint/scope-manager" "5.7.0" + "@typescript-eslint/types" "5.7.0" + "@typescript-eslint/typescript-estree" "5.7.0" debug "^4.3.2" "@typescript-eslint/scope-manager@4.31.2": @@ -6841,23 +6841,23 @@ "@typescript-eslint/types" "4.31.2" "@typescript-eslint/visitor-keys" "4.31.2" -"@typescript-eslint/scope-manager@5.2.0": - version "5.2.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.2.0.tgz#7ce8e4ab2baaa0ad5282913ea8e13ce03ec6a12a" - integrity sha512-RW+wowZqPzQw8MUFltfKYZfKXqA2qgyi6oi/31J1zfXJRpOn6tCaZtd9b5u9ubnDG2n/EMvQLeZrsLNPpaUiFQ== +"@typescript-eslint/scope-manager@5.7.0": + version "5.7.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.7.0.tgz#70adf960e5a58994ad50438ba60d98ecadd79452" + integrity sha512-7mxR520DGq5F7sSSgM0HSSMJ+TFUymOeFRMfUfGFAVBv8BR+Jv1vHgAouYUvWRZeszVBJlLcc9fDdktxb5kmxA== dependencies: - "@typescript-eslint/types" "5.2.0" - "@typescript-eslint/visitor-keys" "5.2.0" + "@typescript-eslint/types" "5.7.0" + "@typescript-eslint/visitor-keys" "5.7.0" "@typescript-eslint/types@4.31.2": version "4.31.2" resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.31.2.tgz#2aea7177d6d744521a168ed4668eddbd912dfadf" integrity sha512-kWiTTBCTKEdBGrZKwFvOlGNcAsKGJSBc8xLvSjSppFO88AqGxGNYtF36EuEYG6XZ9vT0xX8RNiHbQUKglbSi1w== -"@typescript-eslint/types@5.2.0": - version "5.2.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.2.0.tgz#7ad32d15abddb0ee968a330f0ea182ea544ef7cf" - integrity sha512-cTk6x08qqosps6sPyP2j7NxyFPlCNsJwSDasqPNjEQ8JMD5xxj2NHxcLin5AJQ8pAVwpQ8BMI3bTxR0zxmK9qQ== +"@typescript-eslint/types@5.7.0": + version "5.7.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.7.0.tgz#2d4cae0105ba7d08bffa69698197a762483ebcbe" + integrity sha512-5AeYIF5p2kAneIpnLFve8g50VyAjq7udM7ApZZ9JYjdPjkz0LvODfuSHIDUVnIuUoxafoWzpFyU7Sqbxgi79mA== "@typescript-eslint/typescript-estree@4.31.2": version "4.31.2" @@ -6872,13 +6872,13 @@ semver "^7.3.5" tsutils "^3.21.0" -"@typescript-eslint/typescript-estree@5.2.0", "@typescript-eslint/typescript-estree@^5.2.0": - version "5.2.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.2.0.tgz#c22e0ff6f8a4a3f78504a80ebd686fe2870a68ae" - integrity sha512-RsdXq2XmVgKbm9nLsE3mjNUM7BTr/K4DYR9WfFVMUuozHWtH5gMpiNZmtrMG8GR385EOSQ3kC9HiEMJWimxd/g== +"@typescript-eslint/typescript-estree@5.7.0", "@typescript-eslint/typescript-estree@^5.6.0": + version "5.7.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.7.0.tgz#968fad899050ccce4f08a40cd5fabc0798525006" + integrity sha512-aO1Ql+izMrTnPj5aFFlEJkpD4jRqC4Gwhygu2oHK2wfVQpmOPbyDSveJ+r/NQo+PWV43M6uEAeLVbTi09dFLhg== dependencies: - "@typescript-eslint/types" "5.2.0" - "@typescript-eslint/visitor-keys" "5.2.0" + "@typescript-eslint/types" "5.7.0" + "@typescript-eslint/visitor-keys" "5.7.0" debug "^4.3.2" globby "^11.0.4" is-glob "^4.0.3" @@ -6893,12 +6893,12 @@ "@typescript-eslint/types" "4.31.2" eslint-visitor-keys "^2.0.0" -"@typescript-eslint/visitor-keys@5.2.0": - version "5.2.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.2.0.tgz#03522d35df98474f08e0357171a7d1b259a88f55" - integrity sha512-Nk7HizaXWWCUBfLA/rPNKMzXzWS8Wg9qHMuGtT+v2/YpPij4nVXrVJc24N/r5WrrmqK31jCrZxeHqIgqRzs0Xg== +"@typescript-eslint/visitor-keys@5.7.0": + version "5.7.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.7.0.tgz#e05164239eb7cb8aa9fa06c516ede480ce260178" + integrity sha512-hdohahZ4lTFcglZSJ3DGdzxQHBSxsLVqHzkiOmKi7xVAWC4y2c1bIMKmPJSrA4aOEoRUPOKQ87Y/taC7yVHpFg== dependencies: - "@typescript-eslint/types" "5.2.0" + "@typescript-eslint/types" "5.7.0" eslint-visitor-keys "^3.0.0" "@ungap/promise-all-settled@1.1.2": @@ -22407,10 +22407,10 @@ prettier-linter-helpers@^1.0.0: dependencies: fast-diff "^1.1.2" -prettier@^2.4.0: - version "2.4.0" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.4.0.tgz#85bdfe0f70c3e777cf13a4ffff39713ca6f64cba" - integrity sha512-DsEPLY1dE5HF3BxCRBmD4uYZ+5DCbvatnolqTqcxEgKVZnL2kUfyu7b8pPQ5+hTBkdhU9SLUmK0/pHb07RE4WQ== +prettier@^2.5.1: + version "2.5.1" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.5.1.tgz#fff75fa9d519c54cf0fce328c1017d94546bc56a" + integrity sha512-vBZcPRUR5MZJwoyi3ZoyQlc1rXeEck8KgeC9AwwOn+exuxLxq5toTRDTSaVrXHxelDMHy9zlicw8u66yxoSUFg== prettier@~2.2.1: version "2.2.1" From 492496be8d9bab2e2d657e24c3794b92237cf1c0 Mon Sep 17 00:00:00 2001 From: Brian Seeders Date: Mon, 13 Dec 2021 14:39:14 -0500 Subject: [PATCH 2/2] eslint fixes --- .../migrations/actions/create_index.ts | 118 ++--- .../actions/update_and_pickup_mappings.ts | 56 +-- .../solution_nav/solution_nav.tsx | 191 ++++---- .../solution_nav/solution_nav_avatar.tsx | 39 +- .../solution_nav_collapse_button.tsx | 55 +-- .../public/decorator/factory.ts | 15 +- .../plugins/index_patterns/server/index.ts | 6 +- .../function_form_context_pending.tsx | 49 +- .../connectors/resilient/case_fields.tsx | 299 ++++++------ .../cases/public/components/links/index.tsx | 5 +- .../index_data_visualizer.tsx | 255 +++++------ .../fleet_server_cloud_unhealthy_callout.tsx | 93 ++-- ...fleet_server_on_prem_unhealthy_callout.tsx | 77 ++-- .../yaml_code_editor_with_placeholder.tsx | 54 +-- .../sections/epm/screens/detail/index.tsx | 19 +- .../fleet/public/components/package_icon.tsx | 11 +- .../fleet/server/routes/agent/handlers.ts | 74 +-- .../fleet/server/routes/epm/handlers.ts | 194 ++++---- .../fleet/server/routes/output/handler.ts | 82 ++-- .../components/expression_editor/editor.tsx | 319 +++++++------ .../page_results_content.tsx | 429 +++++++++--------- .../page_setup_content.tsx | 69 +-- ...ed_object_save_modal_dashboard_wrapper.tsx | 65 +-- ...saved_object_save_modal_origin_wrapper.tsx | 93 ++-- .../migrations/saved_object_migrations.ts | 16 +- .../common/components/links/helpers.tsx | 5 +- .../observablity_alerts/render_cell_value.tsx | 119 ++--- .../render_cell_value.tsx | 111 ++--- .../render_cell_value.tsx | 81 ++-- .../pages/event_filters/store/middleware.ts | 5 +- .../pages/event_filters/store/reducer.ts | 19 +- .../pages/event_filters/store/selector.ts | 5 +- .../exception_items_summary.test.tsx | 25 +- .../pages/trusted_apps/store/middleware.ts | 5 +- .../pages/trusted_apps/store/reducer.ts | 39 +- .../transform/server/routes/api/transforms.ts | 55 +-- .../servicenow/servicenow_connectors.tsx | 285 ++++++------ .../slack/slack_connectors.tsx | 115 ++--- .../teams/teams_connectors.tsx | 115 ++--- .../lib/requests/get_journey_failed_steps.ts | 78 ++-- .../server/lib/requests/get_journey_steps.ts | 114 ++--- .../lib/requests/get_last_successful_check.ts | 36 +- .../lib/requests/get_monitor_details.ts | 100 ++-- .../server/lib/requests/get_ping_histogram.ts | 158 +++---- .../feature_usage_test/server/index.ts | 6 +- 45 files changed, 2102 insertions(+), 2057 deletions(-) diff --git a/src/core/server/saved_objects/migrations/actions/create_index.ts b/src/core/server/saved_objects/migrations/actions/create_index.ts index 9fa8aebcd7dc1..b687a4ad93b36 100644 --- a/src/core/server/saved_objects/migrations/actions/create_index.ts +++ b/src/core/server/saved_objects/migrations/actions/create_index.ts @@ -55,72 +55,74 @@ export const createIndex = ({ mappings, aliases = [], }: CreateIndexParams): TaskEither.TaskEither => { - const createIndexTask: TaskEither.TaskEither = - () => { - const aliasesObject = aliasArrayToRecord(aliases); + const createIndexTask: TaskEither.TaskEither< + RetryableEsClientError, + AcknowledgeResponse + > = () => { + const aliasesObject = aliasArrayToRecord(aliases); - return client.indices - .create( - { - index: indexName, - // wait until all shards are available before creating the index - // (since number_of_shards=1 this does not have any effect atm) - wait_for_active_shards: WAIT_FOR_ALL_SHARDS_TO_BE_ACTIVE, - // Wait up to 60s for the cluster state to update and all shards to be - // started - timeout: DEFAULT_TIMEOUT, - body: { - mappings, - aliases: aliasesObject, - settings: { - index: { - // ES rule of thumb: shards should be several GB to 10's of GB, so - // Kibana is unlikely to cross that limit. - number_of_shards: 1, - auto_expand_replicas: INDEX_AUTO_EXPAND_REPLICAS, - // Set an explicit refresh interval so that we don't inherit the - // value from incorrectly configured index templates (not required - // after we adopt system indices) - refresh_interval: '1s', - // Bump priority so that recovery happens before newer indices - priority: 10, - }, + return client.indices + .create( + { + index: indexName, + // wait until all shards are available before creating the index + // (since number_of_shards=1 this does not have any effect atm) + wait_for_active_shards: WAIT_FOR_ALL_SHARDS_TO_BE_ACTIVE, + // Wait up to 60s for the cluster state to update and all shards to be + // started + timeout: DEFAULT_TIMEOUT, + body: { + mappings, + aliases: aliasesObject, + settings: { + index: { + // ES rule of thumb: shards should be several GB to 10's of GB, so + // Kibana is unlikely to cross that limit. + number_of_shards: 1, + auto_expand_replicas: INDEX_AUTO_EXPAND_REPLICAS, + // Set an explicit refresh interval so that we don't inherit the + // value from incorrectly configured index templates (not required + // after we adopt system indices) + refresh_interval: '1s', + // Bump priority so that recovery happens before newer indices + priority: 10, }, }, }, - { maxRetries: 0 /** handle retry ourselves for now */ } - ) - .then((res) => { + }, + { maxRetries: 0 /** handle retry ourselves for now */ } + ) + .then((res) => { + /** + * - acknowledged=false, we timed out before the cluster state was + * updated on all nodes with the newly created index, but it + * probably will be created sometime soon. + * - shards_acknowledged=false, we timed out before all shards were + * started + * - acknowledged=true, shards_acknowledged=true, index creation complete + */ + return Either.right({ + acknowledged: Boolean(res.body.acknowledged), + shardsAcknowledged: res.body.shards_acknowledged, + }); + }) + .catch((error) => { + if (error?.body?.error?.type === 'resource_already_exists_exception') { /** - * - acknowledged=false, we timed out before the cluster state was - * updated on all nodes with the newly created index, but it - * probably will be created sometime soon. - * - shards_acknowledged=false, we timed out before all shards were - * started - * - acknowledged=true, shards_acknowledged=true, index creation complete + * If the target index already exists it means a previous create + * operation had already been started. However, we can't be sure + * that all shards were started so return shardsAcknowledged: false */ return Either.right({ - acknowledged: Boolean(res.body.acknowledged), - shardsAcknowledged: res.body.shards_acknowledged, + acknowledged: true, + shardsAcknowledged: false, }); - }) - .catch((error) => { - if (error?.body?.error?.type === 'resource_already_exists_exception') { - /** - * If the target index already exists it means a previous create - * operation had already been started. However, we can't be sure - * that all shards were started so return shardsAcknowledged: false - */ - return Either.right({ - acknowledged: true, - shardsAcknowledged: false, - }); - } else { - throw error; - } - }) - .catch(catchRetryableEsClientErrors); - }; + } else { + throw error; + } + }) + .catch(catchRetryableEsClientErrors); + }; return pipe( createIndexTask, diff --git a/src/core/server/saved_objects/migrations/actions/update_and_pickup_mappings.ts b/src/core/server/saved_objects/migrations/actions/update_and_pickup_mappings.ts index 52065ba60cb84..8c742005a01ce 100644 --- a/src/core/server/saved_objects/migrations/actions/update_and_pickup_mappings.ts +++ b/src/core/server/saved_objects/migrations/actions/update_and_pickup_mappings.ts @@ -41,33 +41,35 @@ export const updateAndPickupMappings = ({ RetryableEsClientError, UpdateAndPickupMappingsResponse > => { - const putMappingTask: TaskEither.TaskEither = - () => { - return client.indices - .putMapping({ - index, - timeout: DEFAULT_TIMEOUT, - body: mappings, - }) - .then((res) => { - // Ignore `acknowledged: false`. When the coordinating node accepts - // the new cluster state update but not all nodes have applied the - // update within the timeout `acknowledged` will be false. However, - // retrying this update will always immediately result in `acknowledged: - // true` even if there are still nodes which are falling behind with - // cluster state updates. - // For updateAndPickupMappings this means that there is the potential - // that some existing document's fields won't be picked up if the node - // on which the Kibana shard is running has fallen behind with cluster - // state updates and the mapping update wasn't applied before we run - // `pickupUpdatedMappings`. ES tries to limit this risk by blocking - // index operations (including update_by_query used by - // updateAndPickupMappings) if there are pending mappings changes. But - // not all mapping changes will prevent this. - return Either.right('update_mappings_succeeded' as const); - }) - .catch(catchRetryableEsClientErrors); - }; + const putMappingTask: TaskEither.TaskEither< + RetryableEsClientError, + 'update_mappings_succeeded' + > = () => { + return client.indices + .putMapping({ + index, + timeout: DEFAULT_TIMEOUT, + body: mappings, + }) + .then((res) => { + // Ignore `acknowledged: false`. When the coordinating node accepts + // the new cluster state update but not all nodes have applied the + // update within the timeout `acknowledged` will be false. However, + // retrying this update will always immediately result in `acknowledged: + // true` even if there are still nodes which are falling behind with + // cluster state updates. + // For updateAndPickupMappings this means that there is the potential + // that some existing document's fields won't be picked up if the node + // on which the Kibana shard is running has fallen behind with cluster + // state updates and the mapping update wasn't applied before we run + // `pickupUpdatedMappings`. ES tries to limit this risk by blocking + // index operations (including update_by_query used by + // updateAndPickupMappings) if there are pending mappings changes. But + // not all mapping changes will prevent this. + return Either.right('update_mappings_succeeded' as const); + }) + .catch(catchRetryableEsClientErrors); + }; return pipe( putMappingTask, diff --git a/src/plugins/kibana_react/public/page_template/solution_nav/solution_nav.tsx b/src/plugins/kibana_react/public/page_template/solution_nav/solution_nav.tsx index 233872e203a52..cbfc74e92dbd6 100644 --- a/src/plugins/kibana_react/public/page_template/solution_nav/solution_nav.tsx +++ b/src/plugins/kibana_react/public/page_template/solution_nav/solution_nav.tsx @@ -53,107 +53,108 @@ const setTabIndex = (items: Array>, isHidden: boolean) => /** * A wrapper around EuiSideNav but also creates the appropriate title with optional solution logo */ -export const KibanaPageTemplateSolutionNav: FunctionComponent = - ({ name, icon, items, isOpenOnDesktop = false, onCollapse, ...rest }) => { - // The EuiShowFor and EuiHideFor components are not in sync with the euiBreakpoint() function :( - const isSmallerBreakpoint = useIsWithinBreakpoints(['xs', 's']); - const isMediumBreakpoint = useIsWithinBreakpoints(['m']); - const isLargerBreakpoint = useIsWithinBreakpoints(['l', 'xl']); +export const KibanaPageTemplateSolutionNav: FunctionComponent< + KibanaPageTemplateSolutionNavProps +> = ({ name, icon, items, isOpenOnDesktop = false, onCollapse, ...rest }) => { + // The EuiShowFor and EuiHideFor components are not in sync with the euiBreakpoint() function :( + const isSmallerBreakpoint = useIsWithinBreakpoints(['xs', 's']); + const isMediumBreakpoint = useIsWithinBreakpoints(['m']); + const isLargerBreakpoint = useIsWithinBreakpoints(['l', 'xl']); - // This is used for both the EuiSideNav and EuiFlyout toggling - const [isSideNavOpenOnMobile, setIsSideNavOpenOnMobile] = useState(false); - const toggleOpenOnMobile = () => { - setIsSideNavOpenOnMobile(!isSideNavOpenOnMobile); - }; - - const isHidden = isLargerBreakpoint && !isOpenOnDesktop; + // This is used for both the EuiSideNav and EuiFlyout toggling + const [isSideNavOpenOnMobile, setIsSideNavOpenOnMobile] = useState(false); + const toggleOpenOnMobile = () => { + setIsSideNavOpenOnMobile(!isSideNavOpenOnMobile); + }; - /** - * Create the avatar - */ - let solutionAvatar; - if (icon) { - solutionAvatar = ; - } + const isHidden = isLargerBreakpoint && !isOpenOnDesktop; - /** - * Create the titles - */ - const titleText = ( - - {solutionAvatar} - {name} - - ); - const mobileTitleText = ( - - ); + /** + * Create the avatar + */ + let solutionAvatar; + if (icon) { + solutionAvatar = ; + } - /** - * Create the side nav component - */ - let sideNav; - if (items) { - const sideNavClasses = classNames('kbnPageTemplateSolutionNav', { - 'kbnPageTemplateSolutionNav--hidden': isHidden, - }); + /** + * Create the titles + */ + const titleText = ( + + {solutionAvatar} + {name} + + ); + const mobileTitleText = ( + + ); - sideNav = ( - - {solutionAvatar} - {mobileTitleText} - - } - toggleOpenOnMobile={toggleOpenOnMobile} - isOpenOnMobile={isSideNavOpenOnMobile} - items={setTabIndex(items, isHidden)} - {...rest} - /> - ); - } + /** + * Create the side nav component + */ + let sideNav; + if (items) { + const sideNavClasses = classNames('kbnPageTemplateSolutionNav', { + 'kbnPageTemplateSolutionNav--hidden': isHidden, + }); - return ( - - {isSmallerBreakpoint && sideNav} - {isMediumBreakpoint && ( - - {isSideNavOpenOnMobile && ( - setIsSideNavOpenOnMobile(false)} - side="left" - size={248} - closeButtonPosition="outside" - className="kbnPageTemplateSolutionNav__flyout" - > - {sideNav} - - )} - - - )} - {isLargerBreakpoint && ( + sideNav = ( + - {sideNav} - + {solutionAvatar} + {mobileTitleText} - )} - + } + toggleOpenOnMobile={toggleOpenOnMobile} + isOpenOnMobile={isSideNavOpenOnMobile} + items={setTabIndex(items, isHidden)} + {...rest} + /> ); - }; + } + + return ( + + {isSmallerBreakpoint && sideNav} + {isMediumBreakpoint && ( + + {isSideNavOpenOnMobile && ( + setIsSideNavOpenOnMobile(false)} + side="left" + size={248} + closeButtonPosition="outside" + className="kbnPageTemplateSolutionNav__flyout" + > + {sideNav} + + )} + + + )} + {isLargerBreakpoint && ( + + {sideNav} + + + )} + + ); +}; diff --git a/src/plugins/kibana_react/public/page_template/solution_nav/solution_nav_avatar.tsx b/src/plugins/kibana_react/public/page_template/solution_nav/solution_nav_avatar.tsx index 6b286edee0ffa..c7233be268fbd 100644 --- a/src/plugins/kibana_react/public/page_template/solution_nav/solution_nav_avatar.tsx +++ b/src/plugins/kibana_react/public/page_template/solution_nav/solution_nav_avatar.tsx @@ -22,22 +22,23 @@ export type KibanaPageTemplateSolutionNavAvatarProps = DistributiveOmit = - ({ className, size, ...rest }) => { - return ( - // @ts-ignore Complains about ExclusiveUnion between `iconSize` and `iconType`, but works fine - - ); - }; +export const KibanaPageTemplateSolutionNavAvatar: FunctionComponent< + KibanaPageTemplateSolutionNavAvatarProps +> = ({ className, size, ...rest }) => { + return ( + // @ts-ignore Complains about ExclusiveUnion between `iconSize` and `iconType`, but works fine + + ); +}; diff --git a/src/plugins/kibana_react/public/page_template/solution_nav/solution_nav_collapse_button.tsx b/src/plugins/kibana_react/public/page_template/solution_nav/solution_nav_collapse_button.tsx index f56f720dcd52e..4ed224212f4af 100644 --- a/src/plugins/kibana_react/public/page_template/solution_nav/solution_nav_collapse_button.tsx +++ b/src/plugins/kibana_react/public/page_template/solution_nav/solution_nav_collapse_button.tsx @@ -24,33 +24,34 @@ export type KibanaPageTemplateSolutionNavCollapseButtonProps = /** * Creates the styled icon button for showing/hiding solution nav */ -export const KibanaPageTemplateSolutionNavCollapseButton: FunctionComponent = - ({ className, isCollapsed, ...rest }) => { - const classes = classNames( - 'kbnPageTemplateSolutionNavCollapseButton', - { - 'kbnPageTemplateSolutionNavCollapseButton-isCollapsed': isCollapsed, - }, - className - ); +export const KibanaPageTemplateSolutionNavCollapseButton: FunctionComponent< + KibanaPageTemplateSolutionNavCollapseButtonProps +> = ({ className, isCollapsed, ...rest }) => { + const classes = classNames( + 'kbnPageTemplateSolutionNavCollapseButton', + { + 'kbnPageTemplateSolutionNavCollapseButton-isCollapsed': isCollapsed, + }, + className + ); - const collapseLabel = i18n.translate('kibana-react.solutionNav.collapsibleLabel', { - defaultMessage: 'Collapse side navigation', - }); + const collapseLabel = i18n.translate('kibana-react.solutionNav.collapsibleLabel', { + defaultMessage: 'Collapse side navigation', + }); - const openLabel = i18n.translate('kibana-react.solutionNav.openLabel', { - defaultMessage: 'Open side navigation', - }); + const openLabel = i18n.translate('kibana-react.solutionNav.openLabel', { + defaultMessage: 'Open side navigation', + }); - return ( - - ); - }; + return ( + + ); +}; diff --git a/src/plugins/saved_objects_tagging_oss/public/decorator/factory.ts b/src/plugins/saved_objects_tagging_oss/public/decorator/factory.ts index ebd490a8761eb..b353c41dbcdde 100644 --- a/src/plugins/saved_objects_tagging_oss/public/decorator/factory.ts +++ b/src/plugins/saved_objects_tagging_oss/public/decorator/factory.ts @@ -13,11 +13,12 @@ import { decorateObject } from './decorate_object'; export const decoratorId = 'tag'; -export const tagDecoratorFactory: SavedObjectDecoratorFactory = - () => { - return { - getId: () => decoratorId, - decorateConfig, - decorateObject, - }; +export const tagDecoratorFactory: SavedObjectDecoratorFactory< + InternalTagDecoratedSavedObject +> = () => { + return { + getId: () => decoratorId, + decorateConfig, + decorateObject, }; +}; diff --git a/test/plugin_functional/plugins/index_patterns/server/index.ts b/test/plugin_functional/plugins/index_patterns/server/index.ts index 10111fafe1b0f..f776ad9a76224 100644 --- a/test/plugin_functional/plugins/index_patterns/server/index.ts +++ b/test/plugin_functional/plugins/index_patterns/server/index.ts @@ -13,5 +13,7 @@ import { IndexPatternsTestPluginStart, } from './plugin'; -export const plugin: PluginInitializer = - () => new IndexPatternsTestPlugin(); +export const plugin: PluginInitializer< + IndexPatternsTestPluginSetup, + IndexPatternsTestPluginStart +> = () => new IndexPatternsTestPlugin(); 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 index c3855b42ec2fb..e633164dda741 100644 --- 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 @@ -18,29 +18,30 @@ interface FunctionFormContextPendingProps { 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] - ); +export const FunctionFormContextPending: React.FunctionComponent< + FunctionFormContextPendingProps +> = (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]); + useEffect(() => { + const forceUpdate = + expressionType.requiresContext && prevContextExpression !== contextExpression; + fetchContext(forceUpdate); + }, [contextExpression, expressionType, fetchContext, prevContextExpression]); - return ( -
- -
- ); - }; + return ( +
+ +
+ ); +}; diff --git a/x-pack/plugins/cases/public/components/connectors/resilient/case_fields.tsx b/x-pack/plugins/cases/public/components/connectors/resilient/case_fields.tsx index 9dc76fb48cf17..1edd0f89fa1a3 100644 --- a/x-pack/plugins/cases/public/components/connectors/resilient/case_fields.tsx +++ b/x-pack/plugins/cases/public/components/connectors/resilient/case_fields.tsx @@ -24,163 +24,164 @@ import * as i18n from './translations'; import { ConnectorTypes, ResilientFieldsType } from '../../../../common/api'; import { ConnectorCard } from '../card'; -const ResilientFieldsComponent: React.FunctionComponent> = - ({ isEdit = true, fields, connector, onChange }) => { - const init = useRef(true); - const { incidentTypes = null, severityCode = null } = fields ?? {}; - - const { http, notifications } = useKibana().services; - - const { isLoading: isLoadingIncidentTypes, incidentTypes: allIncidentTypes } = - useGetIncidentTypes({ - http, - toastNotifications: notifications.toasts, - connector, - }); +const ResilientFieldsComponent: React.FunctionComponent< + ConnectorFieldsProps +> = ({ isEdit = true, fields, connector, onChange }) => { + const init = useRef(true); + const { incidentTypes = null, severityCode = null } = fields ?? {}; + + const { http, notifications } = useKibana().services; - const { isLoading: isLoadingSeverity, severity } = useGetSeverity({ + const { isLoading: isLoadingIncidentTypes, incidentTypes: allIncidentTypes } = + useGetIncidentTypes({ http, toastNotifications: notifications.toasts, connector, }); - const severitySelectOptions: EuiSelectOption[] = useMemo( - () => - severity.map((s) => ({ - value: s.id.toString(), - text: s.name, - })), - [severity] - ); - - const incidentTypesComboBoxOptions: Array> = useMemo( - () => - allIncidentTypes - ? allIncidentTypes.map((type: { id: number; name: string }) => ({ - label: type.name, - value: type.id.toString(), - })) - : [], - [allIncidentTypes] - ); - const listItems = useMemo( - () => [ - ...(incidentTypes != null && incidentTypes.length > 0 - ? [ - { - title: i18n.INCIDENT_TYPES_LABEL, - description: allIncidentTypes - .filter((type) => incidentTypes.includes(type.id.toString())) - .map((type) => type.name) - .join(', '), - }, - ] - : []), - ...(severityCode != null && severityCode.length > 0 - ? [ - { - title: i18n.SEVERITY_LABEL, - description: - severity.find((severityObj) => severityObj.id.toString() === severityCode) - ?.name ?? '', - }, - ] - : []), - ], - [incidentTypes, severityCode, allIncidentTypes, severity] - ); - - const onFieldChange = useCallback( - (key, value) => { - onChange({ - ...fields, - incidentTypes, - severityCode, - [key]: value, - }); - }, - [incidentTypes, severityCode, onChange, fields] + const { isLoading: isLoadingSeverity, severity } = useGetSeverity({ + http, + toastNotifications: notifications.toasts, + connector, + }); + + const severitySelectOptions: EuiSelectOption[] = useMemo( + () => + severity.map((s) => ({ + value: s.id.toString(), + text: s.name, + })), + [severity] + ); + + const incidentTypesComboBoxOptions: Array> = useMemo( + () => + allIncidentTypes + ? allIncidentTypes.map((type: { id: number; name: string }) => ({ + label: type.name, + value: type.id.toString(), + })) + : [], + [allIncidentTypes] + ); + const listItems = useMemo( + () => [ + ...(incidentTypes != null && incidentTypes.length > 0 + ? [ + { + title: i18n.INCIDENT_TYPES_LABEL, + description: allIncidentTypes + .filter((type) => incidentTypes.includes(type.id.toString())) + .map((type) => type.name) + .join(', '), + }, + ] + : []), + ...(severityCode != null && severityCode.length > 0 + ? [ + { + title: i18n.SEVERITY_LABEL, + description: + severity.find((severityObj) => severityObj.id.toString() === severityCode)?.name ?? + '', + }, + ] + : []), + ], + [incidentTypes, severityCode, allIncidentTypes, severity] + ); + + const onFieldChange = useCallback( + (key, value) => { + onChange({ + ...fields, + incidentTypes, + severityCode, + [key]: value, + }); + }, + [incidentTypes, severityCode, onChange, fields] + ); + + const selectedIncidentTypesComboBoxOptionsMemo = useMemo(() => { + const allIncidentTypesAsObject = allIncidentTypes.reduce( + (acc, type) => ({ ...acc, [type.id.toString()]: type.name }), + {} as Record ); - - const selectedIncidentTypesComboBoxOptionsMemo = useMemo(() => { - const allIncidentTypesAsObject = allIncidentTypes.reduce( - (acc, type) => ({ ...acc, [type.id.toString()]: type.name }), - {} as Record + return incidentTypes + ? incidentTypes + .map((type) => ({ + label: allIncidentTypesAsObject[type.toString()], + value: type.toString(), + })) + .filter((type) => type.label != null) + : []; + }, [allIncidentTypes, incidentTypes]); + + const onIncidentChange = useCallback( + (selectedOptions: Array<{ label: string; value?: string }>) => { + onFieldChange( + 'incidentTypes', + selectedOptions.map((selectedOption) => selectedOption.value ?? selectedOption.label) ); - return incidentTypes - ? incidentTypes - .map((type) => ({ - label: allIncidentTypesAsObject[type.toString()], - value: type.toString(), - })) - .filter((type) => type.label != null) - : []; - }, [allIncidentTypes, incidentTypes]); - - const onIncidentChange = useCallback( - (selectedOptions: Array<{ label: string; value?: string }>) => { - onFieldChange( - 'incidentTypes', - selectedOptions.map((selectedOption) => selectedOption.value ?? selectedOption.label) - ); - }, - [onFieldChange] - ); - - const onIncidentBlur = useCallback(() => { - if (!incidentTypes) { - onFieldChange('incidentTypes', []); - } - }, [incidentTypes, onFieldChange]); - - // Set field at initialization - useEffect(() => { - if (init.current) { - init.current = false; - onChange({ incidentTypes, severityCode }); - } - }, [incidentTypes, onChange, severityCode]); - - return isEdit ? ( - - - - - - - onFieldChange('severityCode', e.target.value)} - options={severitySelectOptions} - value={severityCode ?? undefined} - /> - - - - ) : ( - - ); - }; + }, + [onFieldChange] + ); + + const onIncidentBlur = useCallback(() => { + if (!incidentTypes) { + onFieldChange('incidentTypes', []); + } + }, [incidentTypes, onFieldChange]); + + // Set field at initialization + useEffect(() => { + if (init.current) { + init.current = false; + onChange({ incidentTypes, severityCode }); + } + }, [incidentTypes, onChange, severityCode]); + + return isEdit ? ( + + + + + + + onFieldChange('severityCode', e.target.value)} + options={severitySelectOptions} + value={severityCode ?? undefined} + /> + + + + ) : ( + + ); +}; // eslint-disable-next-line import/no-default-export export { ResilientFieldsComponent as default }; diff --git a/x-pack/plugins/cases/public/components/links/index.tsx b/x-pack/plugins/cases/public/components/links/index.tsx index 45c7db3e896f9..015e61a59b21c 100644 --- a/x-pack/plugins/cases/public/components/links/index.tsx +++ b/x-pack/plugins/cases/public/components/links/index.tsx @@ -25,8 +25,9 @@ export interface CasesNavigation Promise | void; } -export const LinkButton: React.FC | PropsForAnchor> = - ({ children, ...props }) => {children}; +export const LinkButton: React.FC< + PropsForButton | PropsForAnchor +> = ({ children, ...props }) => {children}; export const LinkAnchor: React.FC = ({ children, ...props }) => ( {children} diff --git a/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/index_data_visualizer.tsx b/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/index_data_visualizer.tsx index 0970938f8099f..2cd349839cafb 100644 --- a/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/index_data_visualizer.tsx +++ b/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/index_data_visualizer.tsx @@ -38,143 +38,144 @@ export interface DataVisualizerUrlStateContextProviderProps { additionalLinks: ResultLink[]; } -export const DataVisualizerUrlStateContextProvider: FC = - ({ IndexDataVisualizerComponent, additionalLinks }) => { - const { - services: { - data: { indexPatterns }, - savedObjects: { client: savedObjectsClient }, - notifications: { toasts }, - }, - } = useDataVisualizerKibana(); - const history = useHistory(); - const { search: searchString } = useLocation(); - - const [currentIndexPattern, setCurrentIndexPattern] = useState(undefined); - const [currentSavedSearch, setCurrentSavedSearch] = useState | null>( - null - ); - - useEffect(() => { - const prevSearchString = searchString; - const parsedQueryString = parse(prevSearchString, { sort: false }); - - const getIndexPattern = async () => { - if (typeof parsedQueryString?.savedSearchId === 'string') { - const savedSearchId = parsedQueryString.savedSearchId; - try { - const savedSearch = await savedObjectsClient.get('search', savedSearchId); - const indexPatternId = savedSearch.references.find( - (ref) => ref.type === 'index-pattern' - )?.id; - if (indexPatternId !== undefined && savedSearch) { - try { - const indexPattern = await indexPatterns.get(indexPatternId); - setCurrentSavedSearch(savedSearch); - setCurrentIndexPattern(indexPattern); - } catch (e) { - toasts.addError(e, { - title: i18n.translate('xpack.dataVisualizer.index.dataViewErrorMessage', { - defaultMessage: 'Error finding data view', - }), - }); - } - } - } catch (e) { - toasts.addError(e, { - title: i18n.translate('xpack.dataVisualizer.index.savedSearchErrorMessage', { - defaultMessage: 'Error retrieving saved search {savedSearchId}', - values: { savedSearchId }, - }), - }); - } - } +export const DataVisualizerUrlStateContextProvider: FC< + DataVisualizerUrlStateContextProviderProps +> = ({ IndexDataVisualizerComponent, additionalLinks }) => { + const { + services: { + data: { indexPatterns }, + savedObjects: { client: savedObjectsClient }, + notifications: { toasts }, + }, + } = useDataVisualizerKibana(); + const history = useHistory(); + const { search: searchString } = useLocation(); + + const [currentIndexPattern, setCurrentIndexPattern] = useState(undefined); + const [currentSavedSearch, setCurrentSavedSearch] = useState | null>( + null + ); - if (typeof parsedQueryString?.index === 'string') { - const indexPattern = await indexPatterns.get(parsedQueryString.index); - setCurrentIndexPattern(indexPattern); - } - }; - getIndexPattern(); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [savedObjectsClient, toasts, indexPatterns]); - - const setUrlState: SetUrlState = useCallback( - ( - accessor: Accessor, - attribute: string | Dictionary, - value?: any, - replaceState?: boolean - ) => { - const prevSearchString = searchString; - const urlState = parseUrlState(prevSearchString); - const parsedQueryString = parse(prevSearchString, { sort: false }); - - if (!Object.prototype.hasOwnProperty.call(urlState, accessor)) { - urlState[accessor] = {}; - } + useEffect(() => { + const prevSearchString = searchString; + const parsedQueryString = parse(prevSearchString, { sort: false }); - if (typeof attribute === 'string') { - if (isEqual(getNestedProperty(urlState, `${accessor}.${attribute}`), value)) { - return prevSearchString; + const getIndexPattern = async () => { + if (typeof parsedQueryString?.savedSearchId === 'string') { + const savedSearchId = parsedQueryString.savedSearchId; + try { + const savedSearch = await savedObjectsClient.get('search', savedSearchId); + const indexPatternId = savedSearch.references.find( + (ref) => ref.type === 'index-pattern' + )?.id; + if (indexPatternId !== undefined && savedSearch) { + try { + const indexPattern = await indexPatterns.get(indexPatternId); + setCurrentSavedSearch(savedSearch); + setCurrentIndexPattern(indexPattern); + } catch (e) { + toasts.addError(e, { + title: i18n.translate('xpack.dataVisualizer.index.dataViewErrorMessage', { + defaultMessage: 'Error finding data view', + }), + }); + } } - - urlState[accessor][attribute] = value; - } else { - const attributes = attribute; - Object.keys(attributes).forEach((a) => { - urlState[accessor][a] = attributes[a]; + } catch (e) { + toasts.addError(e, { + title: i18n.translate('xpack.dataVisualizer.index.savedSearchErrorMessage', { + defaultMessage: 'Error retrieving saved search {savedSearchId}', + values: { savedSearchId }, + }), }); } + } + + if (typeof parsedQueryString?.index === 'string') { + const indexPattern = await indexPatterns.get(parsedQueryString.index); + setCurrentIndexPattern(indexPattern); + } + }; + getIndexPattern(); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [savedObjectsClient, toasts, indexPatterns]); + + const setUrlState: SetUrlState = useCallback( + ( + accessor: Accessor, + attribute: string | Dictionary, + value?: any, + replaceState?: boolean + ) => { + const prevSearchString = searchString; + const urlState = parseUrlState(prevSearchString); + const parsedQueryString = parse(prevSearchString, { sort: false }); - try { - const oldLocationSearchString = stringify(parsedQueryString, { - sort: false, - encode: false, - }); + if (!Object.prototype.hasOwnProperty.call(urlState, accessor)) { + urlState[accessor] = {}; + } - Object.keys(urlState).forEach((a) => { - if (isRisonSerializationRequired(a)) { - parsedQueryString[a] = encode(urlState[a]); - } else { - parsedQueryString[a] = urlState[a]; - } - }); - const newLocationSearchString = stringify(parsedQueryString, { - sort: false, - encode: false, - }); + if (typeof attribute === 'string') { + if (isEqual(getNestedProperty(urlState, `${accessor}.${attribute}`), value)) { + return prevSearchString; + } - if (oldLocationSearchString !== newLocationSearchString) { - const newSearchString = stringify(parsedQueryString, { sort: false }); - if (replaceState) { - history.replace({ search: newSearchString }); - } else { - history.push({ search: newSearchString }); - } + urlState[accessor][attribute] = value; + } else { + const attributes = attribute; + Object.keys(attributes).forEach((a) => { + urlState[accessor][a] = attributes[a]; + }); + } + + try { + const oldLocationSearchString = stringify(parsedQueryString, { + sort: false, + encode: false, + }); + + Object.keys(urlState).forEach((a) => { + if (isRisonSerializationRequired(a)) { + parsedQueryString[a] = encode(urlState[a]); + } else { + parsedQueryString[a] = urlState[a]; + } + }); + const newLocationSearchString = stringify(parsedQueryString, { + sort: false, + encode: false, + }); + + if (oldLocationSearchString !== newLocationSearchString) { + const newSearchString = stringify(parsedQueryString, { sort: false }); + if (replaceState) { + history.replace({ search: newSearchString }); + } else { + history.push({ search: newSearchString }); } - } catch (error) { - // eslint-disable-next-line no-console - console.error('Could not save url state', error); } - }, - [history, searchString] - ); - - return ( - - {currentIndexPattern ? ( - - ) : ( -
- )} - - ); - }; + } catch (error) { + // eslint-disable-next-line no-console + console.error('Could not save url state', error); + } + }, + [history, searchString] + ); + + return ( + + {currentIndexPattern ? ( + + ) : ( +
+ )} + + ); +}; export const IndexDataVisualizer: FC<{ additionalLinks: ResultLink[] }> = ({ additionalLinks }) => { const coreStart = getCoreStart(); diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/fleet_server_callouts/fleet_server_cloud_unhealthy_callout.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/fleet_server_callouts/fleet_server_cloud_unhealthy_callout.tsx index 073a602dd47e5..865b96acbb860 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/fleet_server_callouts/fleet_server_cloud_unhealthy_callout.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/fleet_server_callouts/fleet_server_cloud_unhealthy_callout.tsx @@ -15,53 +15,50 @@ export interface FleetServerCloudUnhealthyCalloutProps { deploymentUrl: string; } -export const FleetServerCloudUnhealthyCallout: React.FunctionComponent = - ({ deploymentUrl }) => { - const { docLinks } = useStartServices(); - return ( - - } - > +export const FleetServerCloudUnhealthyCallout: React.FunctionComponent< + FleetServerCloudUnhealthyCalloutProps +> = ({ deploymentUrl }) => { + const { docLinks } = useStartServices(); + return ( + - - - ), - guideLink: ( - - - - ), - }} + id="xpack.fleet.fleetServerCloudUnhealthyCallout.calloutTitle" + defaultMessage="Fleet Server is not Healthy" /> - - - - - - ); - }; + } + > + + + + ), + guideLink: ( + + + + ), + }} + /> + + + + + + ); +}; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/fleet_server_callouts/fleet_server_on_prem_unhealthy_callout.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/fleet_server_callouts/fleet_server_on_prem_unhealthy_callout.tsx index 34ca37fda82f2..e7ba51ebf5247 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/fleet_server_callouts/fleet_server_on_prem_unhealthy_callout.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/fleet_server_callouts/fleet_server_on_prem_unhealthy_callout.tsx @@ -14,45 +14,42 @@ import { useStartServices } from '../../../../hooks'; export interface FleetServerOnPremUnhealthyCalloutProps { onClickAddFleetServer: () => void; } -export const FleetServerOnPremUnhealthyCallout: React.FunctionComponent = - ({ onClickAddFleetServer }) => { - const { docLinks } = useStartServices(); - return ( - - } - > +export const FleetServerOnPremUnhealthyCallout: React.FunctionComponent< + FleetServerOnPremUnhealthyCalloutProps +> = ({ onClickAddFleetServer }) => { + const { docLinks } = useStartServices(); + return ( + - - - ), - }} + id="xpack.fleet.fleetServerOnPremUnhealthyCallout.calloutTitle" + defaultMessage="Fleet Server is not Healthy" /> - - - - - - ); - }; + } + > + + + + ), + }} + /> + + + + + + ); +}; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/settings/components/edit_output_flyout/yaml_code_editor_with_placeholder.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/settings/components/edit_output_flyout/yaml_code_editor_with_placeholder.tsx index a59c61262e0b9..21581677e093a 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/settings/components/edit_output_flyout/yaml_code_editor_with_placeholder.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/settings/components/edit_output_flyout/yaml_code_editor_with_placeholder.tsx @@ -60,35 +60,31 @@ export type YamlCodeEditorWithPlaceholderProps = Pick = - (props) => { - const { placeholder, disabled, ...editorProps } = props; - - if (disabled) { - return ( - -
{editorProps.value}
-
- ); - } +export const YamlCodeEditorWithPlaceholder: React.FunctionComponent< + YamlCodeEditorWithPlaceholderProps +> = (props) => { + const { placeholder, disabled, ...editorProps } = props; + if (disabled) { return ( - - - {(!editorProps.value || editorProps.value === '') && ( - {placeholder} - )} - + +
{editorProps.value}
+
); - }; + } + + return ( + + + {(!editorProps.value || editorProps.value === '') && ( + {placeholder} + )} + + ); +}; diff --git a/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/index.tsx b/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/index.tsx index cdebc5f8b3ce1..bc6958e9b4a4f 100644 --- a/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/index.tsx +++ b/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/index.tsx @@ -616,13 +616,14 @@ export function Detail() { type EuiButtonPropsFull = Parameters[0]; -const EuiButtonWithTooltip: React.FC }> = - ({ tooltip: tooltipProps, ...buttonProps }) => { - return tooltipProps ? ( - - - - ) : ( +const EuiButtonWithTooltip: React.FC< + EuiButtonPropsFull & { tooltip?: Partial } +> = ({ tooltip: tooltipProps, ...buttonProps }) => { + return tooltipProps ? ( + - ); - }; + + ) : ( + + ); +}; diff --git a/x-pack/plugins/fleet/public/components/package_icon.tsx b/x-pack/plugins/fleet/public/components/package_icon.tsx index b77a7bd082d9a..9e7b54673c9d9 100644 --- a/x-pack/plugins/fleet/public/components/package_icon.tsx +++ b/x-pack/plugins/fleet/public/components/package_icon.tsx @@ -12,11 +12,12 @@ import { EuiIcon } from '@elastic/eui'; import type { UsePackageIconType } from '../hooks'; import { usePackageIconType } from '../hooks'; -export const PackageIcon: React.FunctionComponent> = - ({ packageName, integrationName, version, icons, tryApi, ...euiIconProps }) => { - const iconType = usePackageIconType({ packageName, integrationName, version, icons, tryApi }); - return ; - }; +export const PackageIcon: React.FunctionComponent< + UsePackageIconType & Omit +> = ({ packageName, integrationName, version, icons, tryApi, ...euiIconProps }) => { + const iconType = usePackageIconType({ packageName, integrationName, version, icons, tryApi }); + return ; +}; export const CardIcon: React.FunctionComponent> = ( props diff --git a/x-pack/plugins/fleet/server/routes/agent/handlers.ts b/x-pack/plugins/fleet/server/routes/agent/handlers.ts index 578d4281cba3b..504e8ed6e0c66 100644 --- a/x-pack/plugins/fleet/server/routes/agent/handlers.ts +++ b/x-pack/plugins/fleet/server/routes/agent/handlers.ts @@ -28,51 +28,53 @@ import { defaultIngestErrorHandler } from '../../errors'; import { licenseService } from '../../services'; import * as AgentService from '../../services/agents'; -export const getAgentHandler: RequestHandler> = - async (context, request, response) => { - const soClient = context.core.savedObjects.client; - const esClient = context.core.elasticsearch.client.asInternalUser; - - try { - const body: GetOneAgentResponse = { - item: await AgentService.getAgentById(esClient, request.params.agentId), - }; +export const getAgentHandler: RequestHandler< + TypeOf +> = async (context, request, response) => { + const soClient = context.core.savedObjects.client; + const esClient = context.core.elasticsearch.client.asInternalUser; - return response.ok({ body }); - } catch (error) { - if (soClient.errors.isNotFoundError(error)) { - return response.notFound({ - body: { message: `Agent ${request.params.agentId} not found` }, - }); - } + try { + const body: GetOneAgentResponse = { + item: await AgentService.getAgentById(esClient, request.params.agentId), + }; - return defaultIngestErrorHandler({ error, response }); + return response.ok({ body }); + } catch (error) { + if (soClient.errors.isNotFoundError(error)) { + return response.notFound({ + body: { message: `Agent ${request.params.agentId} not found` }, + }); } - }; -export const deleteAgentHandler: RequestHandler> = - async (context, request, response) => { - const esClient = context.core.elasticsearch.client.asInternalUser; + return defaultIngestErrorHandler({ error, response }); + } +}; - try { - await AgentService.deleteAgent(esClient, request.params.agentId); +export const deleteAgentHandler: RequestHandler< + TypeOf +> = async (context, request, response) => { + const esClient = context.core.elasticsearch.client.asInternalUser; - const body = { - action: 'deleted', - }; + try { + await AgentService.deleteAgent(esClient, request.params.agentId); - return response.ok({ body }); - } catch (error) { - if (error.isBoom) { - return response.customError({ - statusCode: error.output.statusCode, - body: { message: `Agent ${request.params.agentId} not found` }, - }); - } + const body = { + action: 'deleted', + }; - return defaultIngestErrorHandler({ error, response }); + return response.ok({ body }); + } catch (error) { + if (error.isBoom) { + return response.customError({ + statusCode: error.output.statusCode, + body: { message: `Agent ${request.params.agentId} not found` }, + }); } - }; + + return defaultIngestErrorHandler({ error, response }); + } +}; export const updateAgentHandler: RequestHandler< TypeOf, diff --git a/x-pack/plugins/fleet/server/routes/epm/handlers.ts b/x-pack/plugins/fleet/server/routes/epm/handlers.ts index 4f3f969defd0c..4e43a19b3637e 100644 --- a/x-pack/plugins/fleet/server/routes/epm/handlers.ts +++ b/x-pack/plugins/fleet/server/routes/epm/handlers.ts @@ -116,101 +116,102 @@ export const getLimitedListHandler: FleetRequestHandler = async (context, reques } }; -export const getFileHandler: FleetRequestHandler> = - async (context, request, response) => { - try { - const { pkgName, pkgVersion, filePath } = request.params; - const savedObjectsClient = context.fleet.epm.internalSoClient; - const installation = await getInstallation({ savedObjectsClient, pkgName }); - const useLocalFile = pkgVersion === installation?.version; - - if (useLocalFile) { - const assetPath = `${pkgName}-${pkgVersion}/${filePath}`; - const fileBuffer = getArchiveEntry(assetPath); - // only pull local installation if we don't have it cached - const storedAsset = - !fileBuffer && (await getAsset({ savedObjectsClient, path: assetPath })); - - // error, if neither is available - if (!fileBuffer && !storedAsset) { - return response.custom({ - body: `installed package file not found: ${filePath}`, - statusCode: 404, - }); - } +export const getFileHandler: FleetRequestHandler< + TypeOf +> = async (context, request, response) => { + try { + const { pkgName, pkgVersion, filePath } = request.params; + const savedObjectsClient = context.fleet.epm.internalSoClient; + const installation = await getInstallation({ savedObjectsClient, pkgName }); + const useLocalFile = pkgVersion === installation?.version; - // if storedAsset is not available, fileBuffer *must* be - // b/c we error if we don't have at least one, and storedAsset is the least likely - const { buffer, contentType } = storedAsset - ? { - contentType: storedAsset.media_type, - buffer: storedAsset.data_utf8 - ? Buffer.from(storedAsset.data_utf8, 'utf8') - : Buffer.from(storedAsset.data_base64, 'base64'), - } - : { - contentType: mime.contentType(path.extname(assetPath)), - buffer: fileBuffer, - }; - - if (!contentType) { - return response.custom({ - body: `unknown content type for file: ${filePath}`, - statusCode: 400, - }); - } + if (useLocalFile) { + const assetPath = `${pkgName}-${pkgVersion}/${filePath}`; + const fileBuffer = getArchiveEntry(assetPath); + // only pull local installation if we don't have it cached + const storedAsset = !fileBuffer && (await getAsset({ savedObjectsClient, path: assetPath })); + // error, if neither is available + if (!fileBuffer && !storedAsset) { return response.custom({ - body: buffer, - statusCode: 200, - headers: { - 'cache-control': 'max-age=10, public', - 'content-type': contentType, - }, + body: `installed package file not found: ${filePath}`, + statusCode: 404, }); - } else { - const registryResponse = await getFile(pkgName, pkgVersion, filePath); - const headersToProxy: KnownHeaders[] = ['content-type', 'cache-control']; - const proxiedHeaders = headersToProxy.reduce((headers, knownHeader) => { - const value = registryResponse.headers.get(knownHeader); - if (value !== null) { - headers[knownHeader] = value; + } + + // if storedAsset is not available, fileBuffer *must* be + // b/c we error if we don't have at least one, and storedAsset is the least likely + const { buffer, contentType } = storedAsset + ? { + contentType: storedAsset.media_type, + buffer: storedAsset.data_utf8 + ? Buffer.from(storedAsset.data_utf8, 'utf8') + : Buffer.from(storedAsset.data_base64, 'base64'), } - return headers; - }, {} as ResponseHeaders); + : { + contentType: mime.contentType(path.extname(assetPath)), + buffer: fileBuffer, + }; + if (!contentType) { return response.custom({ - body: registryResponse.body, - statusCode: registryResponse.status, - headers: proxiedHeaders, + body: `unknown content type for file: ${filePath}`, + statusCode: 400, }); } - } catch (error) { - return defaultIngestErrorHandler({ error, response }); - } - }; -export const getInfoHandler: FleetRequestHandler> = - async (context, request, response) => { - try { - const savedObjectsClient = context.fleet.epm.internalSoClient; - const { pkgName, pkgVersion } = request.params; - if (pkgVersion && !semverValid(pkgVersion)) { - throw new IngestManagerError('Package version is not a valid semver'); - } - const res = await getPackageInfo({ - savedObjectsClient, - pkgName, - pkgVersion: pkgVersion || '', + return response.custom({ + body: buffer, + statusCode: 200, + headers: { + 'cache-control': 'max-age=10, public', + 'content-type': contentType, + }, + }); + } else { + const registryResponse = await getFile(pkgName, pkgVersion, filePath); + const headersToProxy: KnownHeaders[] = ['content-type', 'cache-control']; + const proxiedHeaders = headersToProxy.reduce((headers, knownHeader) => { + const value = registryResponse.headers.get(knownHeader); + if (value !== null) { + headers[knownHeader] = value; + } + return headers; + }, {} as ResponseHeaders); + + return response.custom({ + body: registryResponse.body, + statusCode: registryResponse.status, + headers: proxiedHeaders, }); - const body: GetInfoResponse = { - item: res, - }; - return response.ok({ body }); - } catch (error) { - return defaultIngestErrorHandler({ error, response }); } - }; + } catch (error) { + return defaultIngestErrorHandler({ error, response }); + } +}; + +export const getInfoHandler: FleetRequestHandler< + TypeOf +> = async (context, request, response) => { + try { + const savedObjectsClient = context.fleet.epm.internalSoClient; + const { pkgName, pkgVersion } = request.params; + if (pkgVersion && !semverValid(pkgVersion)) { + throw new IngestManagerError('Package version is not a valid semver'); + } + const res = await getPackageInfo({ + savedObjectsClient, + pkgName, + pkgVersion: pkgVersion || '', + }); + const body: GetInfoResponse = { + item: res, + }; + return response.ok({ body }); + } catch (error) { + return defaultIngestErrorHandler({ error, response }); + } +}; export const updatePackageHandler: FleetRequestHandler< TypeOf, @@ -232,19 +233,20 @@ export const updatePackageHandler: FleetRequestHandler< } }; -export const getStatsHandler: FleetRequestHandler> = - async (context, request, response) => { - try { - const { pkgName } = request.params; - const savedObjectsClient = context.fleet.epm.internalSoClient; - const body: GetStatsResponse = { - response: await getPackageUsageStats({ savedObjectsClient, pkgName }), - }; - return response.ok({ body }); - } catch (error) { - return defaultIngestErrorHandler({ error, response }); - } - }; +export const getStatsHandler: FleetRequestHandler< + TypeOf +> = async (context, request, response) => { + try { + const { pkgName } = request.params; + const savedObjectsClient = context.fleet.epm.internalSoClient; + const body: GetStatsResponse = { + response: await getPackageUsageStats({ savedObjectsClient, pkgName }), + }; + return response.ok({ body }); + } catch (error) { + return defaultIngestErrorHandler({ error, response }); + } +}; export const installPackageFromRegistryHandler: FleetRequestHandler< TypeOf, diff --git a/x-pack/plugins/fleet/server/routes/output/handler.ts b/x-pack/plugins/fleet/server/routes/output/handler.ts index 21d337455b1ec..6de9fe1204f1c 100644 --- a/x-pack/plugins/fleet/server/routes/output/handler.ts +++ b/x-pack/plugins/fleet/server/routes/output/handler.ts @@ -41,27 +41,28 @@ export const getOutputsHandler: RequestHandler = async (context, request, respon } }; -export const getOneOuputHandler: RequestHandler> = - async (context, request, response) => { - const soClient = context.core.savedObjects.client; - try { - const output = await outputService.get(soClient, request.params.outputId); - - const body: GetOneOutputResponse = { - item: output, - }; - - return response.ok({ body }); - } catch (error) { - if (error.isBoom && error.output.statusCode === 404) { - return response.notFound({ - body: { message: `Output ${request.params.outputId} not found` }, - }); - } - - return defaultIngestErrorHandler({ error, response }); +export const getOneOuputHandler: RequestHandler< + TypeOf +> = async (context, request, response) => { + const soClient = context.core.savedObjects.client; + try { + const output = await outputService.get(soClient, request.params.outputId); + + const body: GetOneOutputResponse = { + item: output, + }; + + return response.ok({ body }); + } catch (error) { + if (error.isBoom && error.output.statusCode === 404) { + return response.notFound({ + body: { message: `Output ${request.params.outputId} not found` }, + }); } - }; + + return defaultIngestErrorHandler({ error, response }); + } +}; export const putOuputHandler: RequestHandler< TypeOf, @@ -119,24 +120,25 @@ export const postOuputHandler: RequestHandler< } }; -export const deleteOutputHandler: RequestHandler> = - async (context, request, response) => { - const soClient = context.core.savedObjects.client; - try { - await outputService.delete(soClient, request.params.outputId); - - const body: DeleteOutputResponse = { - id: request.params.outputId, - }; - - return response.ok({ body }); - } catch (error) { - if (error.isBoom && error.output.statusCode === 404) { - return response.notFound({ - body: { message: `Output ${request.params.outputId} not found` }, - }); - } - - return defaultIngestErrorHandler({ error, response }); +export const deleteOutputHandler: RequestHandler< + TypeOf +> = async (context, request, response) => { + const soClient = context.core.savedObjects.client; + try { + await outputService.delete(soClient, request.params.outputId); + + const body: DeleteOutputResponse = { + id: request.params.outputId, + }; + + return response.ok({ body }); + } catch (error) { + if (error.isBoom && error.output.statusCode === 404) { + return response.notFound({ + body: { message: `Output ${request.params.outputId} not found` }, + }); } - }; + + return defaultIngestErrorHandler({ error, response }); + } +}; diff --git a/x-pack/plugins/infra/public/alerting/log_threshold/components/expression_editor/editor.tsx b/x-pack/plugins/infra/public/alerting/log_threshold/components/expression_editor/editor.tsx index 312662286595c..a9b74ad62d190 100644 --- a/x-pack/plugins/infra/public/alerting/log_threshold/components/expression_editor/editor.tsx +++ b/x-pack/plugins/infra/public/alerting/log_threshold/components/expression_editor/editor.tsx @@ -159,177 +159,176 @@ export const SourceStatusWrapper: React.FC = ({ children }) => { ); }; -export const Editor: React.FC> = - (props) => { - const { setAlertParams, alertParams, errors } = props; - const [hasSetDefaults, setHasSetDefaults] = useState(false); - const { sourceId, resolvedSourceConfiguration } = useLogSourceContext(); - - const { - criteria: criteriaErrors, - threshold: thresholdErrors, - timeSizeUnit: timeSizeUnitErrors, - timeWindowSize: timeWindowSizeErrors, - } = useMemo(() => decodeOrThrow(errorsRT)(errors), [errors]); - - const supportedFields = useMemo(() => { - if (resolvedSourceConfiguration?.fields) { - return resolvedSourceConfiguration.fields.filter((field) => { - return (field.type === 'string' || field.type === 'number') && field.searchable; - }); - } else { - return []; - } - }, [resolvedSourceConfiguration]); - - const groupByFields = useMemo(() => { - if (resolvedSourceConfiguration?.fields) { - return resolvedSourceConfiguration.fields.filter((field) => { - return field.type === 'string' && field.aggregatable; - }); - } else { - return []; +export const Editor: React.FC< + AlertTypeParamsExpressionProps +> = (props) => { + const { setAlertParams, alertParams, errors } = props; + const [hasSetDefaults, setHasSetDefaults] = useState(false); + const { sourceId, resolvedSourceConfiguration } = useLogSourceContext(); + + const { + criteria: criteriaErrors, + threshold: thresholdErrors, + timeSizeUnit: timeSizeUnitErrors, + timeWindowSize: timeWindowSizeErrors, + } = useMemo(() => decodeOrThrow(errorsRT)(errors), [errors]); + + const supportedFields = useMemo(() => { + if (resolvedSourceConfiguration?.fields) { + return resolvedSourceConfiguration.fields.filter((field) => { + return (field.type === 'string' || field.type === 'number') && field.searchable; + }); + } else { + return []; + } + }, [resolvedSourceConfiguration]); + + const groupByFields = useMemo(() => { + if (resolvedSourceConfiguration?.fields) { + return resolvedSourceConfiguration.fields.filter((field) => { + return field.type === 'string' && field.aggregatable; + }); + } else { + return []; + } + }, [resolvedSourceConfiguration]); + + const updateThreshold = useCallback( + (thresholdParams) => { + const nextThresholdParams = { ...alertParams.count, ...thresholdParams }; + setAlertParams('count', nextThresholdParams); + }, + [alertParams.count, setAlertParams] + ); + + const updateCriteria = useCallback( + (criteria: PartialCriteriaType) => { + setAlertParams('criteria', criteria); + }, + [setAlertParams] + ); + + const updateTimeSize = useCallback( + (ts: number | undefined) => { + setAlertParams('timeSize', ts); + }, + [setAlertParams] + ); + + const updateTimeUnit = useCallback( + (tu: string) => { + if (timeUnitRT.is(tu)) { + setAlertParams('timeUnit', tu); } - }, [resolvedSourceConfiguration]); - - const updateThreshold = useCallback( - (thresholdParams) => { - const nextThresholdParams = { ...alertParams.count, ...thresholdParams }; - setAlertParams('count', nextThresholdParams); - }, - [alertParams.count, setAlertParams] - ); + }, + [setAlertParams] + ); - const updateCriteria = useCallback( - (criteria: PartialCriteriaType) => { - setAlertParams('criteria', criteria); - }, - [setAlertParams] - ); + const updateGroupBy = useCallback( + (groups: string[]) => { + setAlertParams('groupBy', groups); + }, + [setAlertParams] + ); - const updateTimeSize = useCallback( - (ts: number | undefined) => { - setAlertParams('timeSize', ts); - }, - [setAlertParams] - ); + const defaultCountAlertParams = useMemo( + () => createDefaultCountRuleParams(supportedFields), + [supportedFields] + ); - const updateTimeUnit = useCallback( - (tu: string) => { - if (timeUnitRT.is(tu)) { - setAlertParams('timeUnit', tu); - } - }, - [setAlertParams] - ); + const updateType = useCallback( + (type: ThresholdType) => { + const defaults = + type === 'count' ? defaultCountAlertParams : createDefaultRatioRuleParams(supportedFields); + // Reset properties that don't make sense switching from one context to the other + setAlertParams('count', defaults.count); + setAlertParams('criteria', defaults.criteria); + }, + [defaultCountAlertParams, setAlertParams, supportedFields] + ); - const updateGroupBy = useCallback( - (groups: string[]) => { - setAlertParams('groupBy', groups); - }, - [setAlertParams] - ); + useMount(() => { + const newAlertParams = { ...defaultCountAlertParams, ...alertParams }; + for (const [key, value] of Object.entries(newAlertParams) as ObjectEntries< + typeof newAlertParams + >) { + setAlertParams(key, value); + } + setHasSetDefaults(true); + }); - const defaultCountAlertParams = useMemo( - () => createDefaultCountRuleParams(supportedFields), - [supportedFields] + const shouldShowGroupByOptimizationWarning = useMemo(() => { + const hasSetGroupBy = alertParams.groupBy && alertParams.groupBy.length > 0; + return ( + hasSetGroupBy && + alertParams.count && + !isOptimizableGroupedThreshold(alertParams.count.comparator, alertParams.count.value) ); + }, [alertParams]); + + // Wait until the alert param defaults have been set + if (!hasSetDefaults) return null; + + const criteriaComponent = alertParams.criteria ? ( + + ) : null; - const updateType = useCallback( - (type: ThresholdType) => { - const defaults = - type === 'count' - ? defaultCountAlertParams - : createDefaultRatioRuleParams(supportedFields); - // Reset properties that don't make sense switching from one context to the other - setAlertParams('count', defaults.count); - setAlertParams('criteria', defaults.criteria); - }, - [defaultCountAlertParams, setAlertParams, supportedFields] - ); + return ( + <> + - useMount(() => { - const newAlertParams = { ...defaultCountAlertParams, ...alertParams }; - for (const [key, value] of Object.entries(newAlertParams) as ObjectEntries< - typeof newAlertParams - >) { - setAlertParams(key, value); - } - setHasSetDefaults(true); - }); - - const shouldShowGroupByOptimizationWarning = useMemo(() => { - const hasSetGroupBy = alertParams.groupBy && alertParams.groupBy.length > 0; - return ( - hasSetGroupBy && - alertParams.count && - !isOptimizableGroupedThreshold(alertParams.count.comparator, alertParams.count.value) - ); - }, [alertParams]); - - // Wait until the alert param defaults have been set - if (!hasSetDefaults) return null; - - const criteriaComponent = alertParams.criteria ? ( - - ) : null; - return ( - <> - - - {alertParams.criteria && !isRatioRule(alertParams.criteria) && criteriaComponent} - - - - - - - - {alertParams.criteria && isRatioRule(alertParams.criteria) && criteriaComponent} - - {shouldShowGroupByOptimizationWarning && ( - <> - - - {i18n.translate('xpack.infra.logs.alertFlyout.groupByOptimizationWarning', { - defaultMessage: - 'When setting a "group by" we highly recommend using the "{comparator}" comparator for your threshold. This can lead to significant performance improvements.', - values: { - comparator: Comparator.GT, - }, - })} - - - )} - - - - ); - }; + + + + + {alertParams.criteria && isRatioRule(alertParams.criteria) && criteriaComponent} + + {shouldShowGroupByOptimizationWarning && ( + <> + + + {i18n.translate('xpack.infra.logs.alertFlyout.groupByOptimizationWarning', { + defaultMessage: + 'When setting a "group by" we highly recommend using the "{comparator}" comparator for your threshold. This can lead to significant performance improvements.', + values: { + comparator: Comparator.GT, + }, + })} + + + )} + + + + ); +}; // required for dynamic import // eslint-disable-next-line import/no-default-export diff --git a/x-pack/plugins/infra/public/pages/logs/log_entry_categories/page_results_content.tsx b/x-pack/plugins/infra/public/pages/logs/log_entry_categories/page_results_content.tsx index 2cb96f4ab0641..190050b504ee3 100644 --- a/x-pack/plugins/infra/public/pages/logs/log_entry_categories/page_results_content.tsx +++ b/x-pack/plugins/infra/public/pages/logs/log_entry_categories/page_results_content.tsx @@ -42,244 +42,243 @@ interface LogEntryCategoriesResultsContentProps { pageTitle: string; } -export const LogEntryCategoriesResultsContent: React.FunctionComponent = - ({ onOpenSetup, pageTitle }) => { - useTrackPageview({ app: 'infra_logs', path: 'log_entry_categories_results' }); - useTrackPageview({ app: 'infra_logs', path: 'log_entry_categories_results', delay: 15000 }); +export const LogEntryCategoriesResultsContent: React.FunctionComponent< + LogEntryCategoriesResultsContentProps +> = ({ onOpenSetup, pageTitle }) => { + useTrackPageview({ app: 'infra_logs', path: 'log_entry_categories_results' }); + useTrackPageview({ app: 'infra_logs', path: 'log_entry_categories_results', delay: 15000 }); - const { - services: { ml, http }, - } = useKibanaContextForPlugin(); + const { + services: { ml, http }, + } = useKibanaContextForPlugin(); - const { sourceStatus } = useLogSourceContext(); - const { hasLogAnalysisSetupCapabilities } = useLogAnalysisCapabilitiesContext(); + const { sourceStatus } = useLogSourceContext(); + const { hasLogAnalysisSetupCapabilities } = useLogAnalysisCapabilitiesContext(); - const { - fetchJobStatus, - fetchModuleDefinition, - moduleDescriptor, - setupStatus, - hasOutdatedJobConfigurations, - hasOutdatedJobDefinitions, - hasStoppedJobs, - jobIds, - categoryQualityWarnings, - sourceConfiguration: { sourceId }, - } = useLogEntryCategoriesModuleContext(); + const { + fetchJobStatus, + fetchModuleDefinition, + moduleDescriptor, + setupStatus, + hasOutdatedJobConfigurations, + hasOutdatedJobDefinitions, + hasStoppedJobs, + jobIds, + categoryQualityWarnings, + sourceConfiguration: { sourceId }, + } = useLogEntryCategoriesModuleContext(); - const { - timeRange: selectedTimeRange, - setTimeRange: setSelectedTimeRange, - autoRefresh, - setAutoRefresh, - } = useLogEntryCategoriesResultsUrlState(); + const { + timeRange: selectedTimeRange, + setTimeRange: setSelectedTimeRange, + autoRefresh, + setAutoRefresh, + } = useLogEntryCategoriesResultsUrlState(); - const [categoryQueryTimeRange, setCategoryQueryTimeRange] = useState<{ - lastChangedTime: number; - timeRange: TimeRange; - }>(() => ({ - lastChangedTime: Date.now(), - timeRange: stringToNumericTimeRange(selectedTimeRange), - })); + const [categoryQueryTimeRange, setCategoryQueryTimeRange] = useState<{ + lastChangedTime: number; + timeRange: TimeRange; + }>(() => ({ + lastChangedTime: Date.now(), + timeRange: stringToNumericTimeRange(selectedTimeRange), + })); - const [categoryQueryDatasets, setCategoryQueryDatasets] = useState([]); + const [categoryQueryDatasets, setCategoryQueryDatasets] = useState([]); - const { services } = useKibana<{}>(); + const { services } = useKibana<{}>(); - const showLoadDataErrorNotification = useCallback( - (error: Error) => { - services.notifications?.toasts.addError(error, { - title: loadDataErrorTitle, - }); - }, - [services.notifications] - ); + const showLoadDataErrorNotification = useCallback( + (error: Error) => { + services.notifications?.toasts.addError(error, { + title: loadDataErrorTitle, + }); + }, + [services.notifications] + ); - const { - getLogEntryCategoryDatasets, - getTopLogEntryCategories, - isLoadingLogEntryCategoryDatasets, - isLoadingTopLogEntryCategories, - logEntryCategoryDatasets, - topLogEntryCategories, - sortOptions, - changeSortOptions, - } = useLogEntryCategoriesResults({ - categoriesCount: 25, - endTime: categoryQueryTimeRange.timeRange.endTime, - filteredDatasets: categoryQueryDatasets, - onGetTopLogEntryCategoriesError: showLoadDataErrorNotification, - sourceId, - startTime: categoryQueryTimeRange.timeRange.startTime, - }); + const { + getLogEntryCategoryDatasets, + getTopLogEntryCategories, + isLoadingLogEntryCategoryDatasets, + isLoadingTopLogEntryCategories, + logEntryCategoryDatasets, + topLogEntryCategories, + sortOptions, + changeSortOptions, + } = useLogEntryCategoriesResults({ + categoriesCount: 25, + endTime: categoryQueryTimeRange.timeRange.endTime, + filteredDatasets: categoryQueryDatasets, + onGetTopLogEntryCategoriesError: showLoadDataErrorNotification, + sourceId, + startTime: categoryQueryTimeRange.timeRange.startTime, + }); - const handleQueryTimeRangeChange = useCallback( - ({ start: startTime, end: endTime }: { start: string; end: string }) => { - setCategoryQueryTimeRange((previousQueryParameters) => ({ - ...previousQueryParameters, - timeRange: stringToNumericTimeRange({ startTime, endTime }), - lastChangedTime: Date.now(), - })); - }, - [setCategoryQueryTimeRange] - ); + const handleQueryTimeRangeChange = useCallback( + ({ start: startTime, end: endTime }: { start: string; end: string }) => { + setCategoryQueryTimeRange((previousQueryParameters) => ({ + ...previousQueryParameters, + timeRange: stringToNumericTimeRange({ startTime, endTime }), + lastChangedTime: Date.now(), + })); + }, + [setCategoryQueryTimeRange] + ); - const handleSelectedTimeRangeChange = useCallback( - (selectedTime: { start: string; end: string; isInvalid: boolean }) => { - if (selectedTime.isInvalid) { - return; - } - setSelectedTimeRange({ - startTime: selectedTime.start, - endTime: selectedTime.end, - }); - handleQueryTimeRangeChange(selectedTime); - }, - [setSelectedTimeRange, handleQueryTimeRangeChange] - ); + const handleSelectedTimeRangeChange = useCallback( + (selectedTime: { start: string; end: string; isInvalid: boolean }) => { + if (selectedTime.isInvalid) { + return; + } + setSelectedTimeRange({ + startTime: selectedTime.start, + endTime: selectedTime.end, + }); + handleQueryTimeRangeChange(selectedTime); + }, + [setSelectedTimeRange, handleQueryTimeRangeChange] + ); - const handleAutoRefreshChange = useCallback( - ({ isPaused, refreshInterval: interval }: { isPaused: boolean; refreshInterval: number }) => { - setAutoRefresh({ - isPaused, - interval, - }); - }, - [setAutoRefresh] - ); + const handleAutoRefreshChange = useCallback( + ({ isPaused, refreshInterval: interval }: { isPaused: boolean; refreshInterval: number }) => { + setAutoRefresh({ + isPaused, + interval, + }); + }, + [setAutoRefresh] + ); - const hasResults = useMemo( - () => topLogEntryCategories.length > 0, - [topLogEntryCategories.length] - ); + const hasResults = useMemo( + () => topLogEntryCategories.length > 0, + [topLogEntryCategories.length] + ); - const isFirstUse = useMemo( - () => - ((setupStatus.type === 'skipped' && !!setupStatus.newlyCreated) || - setupStatus.type === 'succeeded') && - !hasResults, - [hasResults, setupStatus] - ); + const isFirstUse = useMemo( + () => + ((setupStatus.type === 'skipped' && !!setupStatus.newlyCreated) || + setupStatus.type === 'succeeded') && + !hasResults, + [hasResults, setupStatus] + ); - useEffect(() => { - getTopLogEntryCategories(); - }, [ - getTopLogEntryCategories, - categoryQueryDatasets, - categoryQueryTimeRange.lastChangedTime, - sortOptions, - ]); + useEffect(() => { + getTopLogEntryCategories(); + }, [ + getTopLogEntryCategories, + categoryQueryDatasets, + categoryQueryTimeRange.lastChangedTime, + sortOptions, + ]); - useEffect(() => { - getLogEntryCategoryDatasets(); - }, [getLogEntryCategoryDatasets, categoryQueryTimeRange.lastChangedTime]); + useEffect(() => { + getLogEntryCategoryDatasets(); + }, [getLogEntryCategoryDatasets, categoryQueryTimeRange.lastChangedTime]); - useEffect(() => { - fetchModuleDefinition(); - }, [fetchModuleDefinition]); + useEffect(() => { + fetchModuleDefinition(); + }, [fetchModuleDefinition]); - useInterval(() => { - fetchJobStatus(); - }, JOB_STATUS_POLLING_INTERVAL); + useInterval(() => { + fetchJobStatus(); + }, JOB_STATUS_POLLING_INTERVAL); - useInterval( - () => { - handleQueryTimeRangeChange({ - start: selectedTimeRange.startTime, - end: selectedTimeRange.endTime, - }); - }, - autoRefresh.isPaused ? null : autoRefresh.interval - ); + useInterval( + () => { + handleQueryTimeRangeChange({ + start: selectedTimeRange.startTime, + end: selectedTimeRange.endTime, + }); + }, + autoRefresh.isPaused ? null : autoRefresh.interval + ); - const analyzeInMlLink = useMlHref(ml, http.basePath.get(), { - page: ML_PAGES.ANOMALY_EXPLORER, - pageState: { - jobIds: [jobIds['log-entry-categories-count']], - timeRange: { - from: moment(categoryQueryTimeRange.timeRange.startTime).format( - 'YYYY-MM-DDTHH:mm:ss.SSSZ' - ), - to: moment(categoryQueryTimeRange.timeRange.endTime).format('YYYY-MM-DDTHH:mm:ss.SSSZ'), - mode: 'absolute', - }, + const analyzeInMlLink = useMlHref(ml, http.basePath.get(), { + page: ML_PAGES.ANOMALY_EXPLORER, + pageState: { + jobIds: [jobIds['log-entry-categories-count']], + timeRange: { + from: moment(categoryQueryTimeRange.timeRange.startTime).format('YYYY-MM-DDTHH:mm:ss.SSSZ'), + to: moment(categoryQueryTimeRange.timeRange.endTime).format('YYYY-MM-DDTHH:mm:ss.SSSZ'), + mode: 'absolute', }, - }); + }, + }); - return ( - + , + , + ], + }} > - , - , - ], - }} - > - - - - - - - - - - - - - - - - - - - - - - - ); - }; + + + + + + + + + + + + + + + + + + + + + + + ); +}; const stringToNumericTimeRange = (timeRange: StringTimeRange): TimeRange => ({ startTime: moment( diff --git a/x-pack/plugins/infra/public/pages/logs/log_entry_categories/page_setup_content.tsx b/x-pack/plugins/infra/public/pages/logs/log_entry_categories/page_setup_content.tsx index 6ab8e5d3a264c..ead8590ca3398 100644 --- a/x-pack/plugins/infra/public/pages/logs/log_entry_categories/page_setup_content.tsx +++ b/x-pack/plugins/infra/public/pages/logs/log_entry_categories/page_setup_content.tsx @@ -14,40 +14,41 @@ interface LogEntryCategoriesSetupContentProps { onOpenSetup: () => void; } -export const LogEntryCategoriesSetupContent: React.FunctionComponent = - ({ onOpenSetup }) => { - useTrackPageview({ app: 'infra_logs', path: 'log_entry_categories_setup' }); - useTrackPageview({ app: 'infra_logs', path: 'log_entry_categories_setup', delay: 15000 }); +export const LogEntryCategoriesSetupContent: React.FunctionComponent< + LogEntryCategoriesSetupContentProps +> = ({ onOpenSetup }) => { + useTrackPageview({ app: 'infra_logs', path: 'log_entry_categories_setup' }); + useTrackPageview({ app: 'infra_logs', path: 'log_entry_categories_setup', delay: 15000 }); - return ( - + return ( + + + + } + body={ + +

- - } - body={ - -

- -

-
- } - actions={ - - - - } - /> - ); - }; +

+ + } + actions={ + + + + } + /> + ); +}; diff --git a/x-pack/plugins/lens/public/app_plugin/tags_saved_object_save_modal_dashboard_wrapper.tsx b/x-pack/plugins/lens/public/app_plugin/tags_saved_object_save_modal_dashboard_wrapper.tsx index 37c93bfbabc56..96139799ca210 100644 --- a/x-pack/plugins/lens/public/app_plugin/tags_saved_object_save_modal_dashboard_wrapper.tsx +++ b/x-pack/plugins/lens/public/app_plugin/tags_saved_object_save_modal_dashboard_wrapper.tsx @@ -32,39 +32,40 @@ export type TagEnhancedSavedObjectSaveModalDashboardProps = Omit< const SavedObjectSaveModalDashboard = withSuspense(LazySavedObjectSaveModalDashboard); -export const TagEnhancedSavedObjectSaveModalDashboard: FC = - ({ initialTags, onSave, savedObjectsTagging, ...otherProps }) => { - const [selectedTags, setSelectedTags] = useState(initialTags); +export const TagEnhancedSavedObjectSaveModalDashboard: FC< + TagEnhancedSavedObjectSaveModalDashboardProps +> = ({ initialTags, onSave, savedObjectsTagging, ...otherProps }) => { + const [selectedTags, setSelectedTags] = useState(initialTags); - const tagSelectorOption = useMemo( - () => - savedObjectsTagging ? ( - - ) : undefined, - [savedObjectsTagging, initialTags] - ); + const tagSelectorOption = useMemo( + () => + savedObjectsTagging ? ( + + ) : undefined, + [savedObjectsTagging, initialTags] + ); - const tagEnhancedOptions = <>{tagSelectorOption}; + const tagEnhancedOptions = <>{tagSelectorOption}; - const tagEnhancedOnSave: SaveModalDashboardProps['onSave'] = useCallback( - (saveOptions) => { - onSave({ - ...saveOptions, - returnToOrigin: false, - newTags: selectedTags, - }); - }, - [onSave, selectedTags] - ); + const tagEnhancedOnSave: SaveModalDashboardProps['onSave'] = useCallback( + (saveOptions) => { + onSave({ + ...saveOptions, + returnToOrigin: false, + newTags: selectedTags, + }); + }, + [onSave, selectedTags] + ); - return ( - - ); - }; + return ( + + ); +}; diff --git a/x-pack/plugins/lens/public/app_plugin/tags_saved_object_save_modal_origin_wrapper.tsx b/x-pack/plugins/lens/public/app_plugin/tags_saved_object_save_modal_origin_wrapper.tsx index 7efdc5133349f..4e1bb05ee8515 100644 --- a/x-pack/plugins/lens/public/app_plugin/tags_saved_object_save_modal_origin_wrapper.tsx +++ b/x-pack/plugins/lens/public/app_plugin/tags_saved_object_save_modal_origin_wrapper.tsx @@ -22,53 +22,54 @@ export type TagEnhancedSavedObjectSaveModalOriginProps = Omit void; }; -export const TagEnhancedSavedObjectSaveModalOrigin: FC = - ({ initialTags, onSave, savedObjectsTagging, options, ...otherProps }) => { - const [selectedTags, setSelectedTags] = useState(initialTags); +export const TagEnhancedSavedObjectSaveModalOrigin: FC< + TagEnhancedSavedObjectSaveModalOriginProps +> = ({ initialTags, onSave, savedObjectsTagging, options, ...otherProps }) => { + const [selectedTags, setSelectedTags] = useState(initialTags); - const tagSelectorOption = useMemo( - () => - savedObjectsTagging ? ( - - ) : undefined, - [savedObjectsTagging, initialTags] - ); - - const tagEnhancedOptions = - typeof options === 'function' ? ( - (state: SaveModalState) => { - return ( - <> - {tagSelectorOption} - {options(state)} - - ); - } - ) : ( - <> - {tagSelectorOption} - {options} - - ); + const tagSelectorOption = useMemo( + () => + savedObjectsTagging ? ( + + ) : undefined, + [savedObjectsTagging, initialTags] + ); - const tagEnhancedOnSave: OriginSaveModalProps['onSave'] = useCallback( - (saveOptions) => { - onSave({ - ...saveOptions, - newTags: selectedTags, - }); - }, - [onSave, selectedTags] + const tagEnhancedOptions = + typeof options === 'function' ? ( + (state: SaveModalState) => { + return ( + <> + {tagSelectorOption} + {options(state)} + + ); + } + ) : ( + <> + {tagSelectorOption} + {options} + ); - return ( - - ); - }; + const tagEnhancedOnSave: OriginSaveModalProps['onSave'] = useCallback( + (saveOptions) => { + onSave({ + ...saveOptions, + newTags: selectedTags, + }); + }, + [onSave, selectedTags] + ); + + return ( + + ); +}; diff --git a/x-pack/plugins/lens/server/migrations/saved_object_migrations.ts b/x-pack/plugins/lens/server/migrations/saved_object_migrations.ts index fb3718cf2d213..f4f16f21452fb 100644 --- a/x-pack/plugins/lens/server/migrations/saved_object_migrations.ts +++ b/x-pack/plugins/lens/server/migrations/saved_object_migrations.ts @@ -403,14 +403,16 @@ const transformTableState: SavedObjectMigrationFn< return newDoc; }; -const renameOperationsForFormula: SavedObjectMigrationFn = - (doc) => { - const newDoc = cloneDeep(doc); - return { - ...newDoc, - attributes: commonRenameOperationsForFormula(newDoc.attributes), - }; +const renameOperationsForFormula: SavedObjectMigrationFn< + LensDocShapePre712, + LensDocShapePost712 +> = (doc) => { + const newDoc = cloneDeep(doc); + return { + ...newDoc, + attributes: commonRenameOperationsForFormula(newDoc.attributes), }; +}; const removeTimezoneDateHistogramParam: SavedObjectMigrationFn = ( doc diff --git a/x-pack/plugins/security_solution/public/common/components/links/helpers.tsx b/x-pack/plugins/security_solution/public/common/components/links/helpers.tsx index 0504a17904a75..704f7ea7931fb 100644 --- a/x-pack/plugins/security_solution/public/common/components/links/helpers.tsx +++ b/x-pack/plugins/security_solution/public/common/components/links/helpers.tsx @@ -17,8 +17,9 @@ import { } from '@elastic/eui'; import styled from 'styled-components'; -export const LinkButton: React.FC | PropsForAnchor> = - ({ children, ...props }) => {children}; +export const LinkButton: React.FC< + PropsForButton | PropsForAnchor +> = ({ children, ...props }) => {children}; export const LinkAnchor: React.FC = ({ children, ...props }) => ( {children} diff --git a/x-pack/plugins/security_solution/public/detections/configurations/examples/observablity_alerts/render_cell_value.tsx b/x-pack/plugins/security_solution/public/detections/configurations/examples/observablity_alerts/render_cell_value.tsx index c718d0e642c65..7976ad5dca7f3 100644 --- a/x-pack/plugins/security_solution/public/detections/configurations/examples/observablity_alerts/render_cell_value.tsx +++ b/x-pack/plugins/security_solution/public/detections/configurations/examples/observablity_alerts/render_cell_value.tsx @@ -31,63 +31,64 @@ const reason = * accepts `EuiDataGridCellValueElementProps`, plus `data` * from the TGrid */ -export const RenderCellValue: React.FC = - ({ - columnId, - data, - eventId, - header, - isDetails, - isDraggable, - isExpandable, - isExpanded, - linkValues, - rowIndex, - setCellProps, - timelineId, - }) => { - const value = - getMappedNonEcsValue({ - data, - fieldName: columnId, - })?.reduce((x) => x[0]) ?? ''; +export const RenderCellValue: React.FC< + EuiDataGridCellValueElementProps & CellValueElementProps +> = ({ + columnId, + data, + eventId, + header, + isDetails, + isDraggable, + isExpandable, + isExpanded, + linkValues, + rowIndex, + setCellProps, + timelineId, +}) => { + const value = + getMappedNonEcsValue({ + data, + fieldName: columnId, + })?.reduce((x) => x[0]) ?? ''; - switch (columnId) { - case ALERT_STATUS: - return ( - - ); - case ALERT_DURATION: - case 'signal.duration.us': - return {moment().fromNow(true)}; - case ALERT_RULE_SEVERITY: - case 'signal.rule.severity': - return ; - case ALERT_REASON: - case 'signal.reason': - return ( - - {reason} - - ); - default: - // NOTE: we're using `DefaultCellRenderer` in this example configuration as a fallback, but - // using `DefaultCellRenderer` here is entirely optional - return ( - - ); - } - }; + switch (columnId) { + case ALERT_STATUS: + return ( + + ); + case ALERT_DURATION: + case 'signal.duration.us': + return {moment().fromNow(true)}; + case ALERT_RULE_SEVERITY: + case 'signal.rule.severity': + return ; + case ALERT_REASON: + case 'signal.reason': + return ( + + {reason} + + ); + default: + // NOTE: we're using `DefaultCellRenderer` in this example configuration as a fallback, but + // using `DefaultCellRenderer` here is entirely optional + return ( + + ); + } +}; diff --git a/x-pack/plugins/security_solution/public/detections/configurations/examples/security_solution_rac/render_cell_value.tsx b/x-pack/plugins/security_solution/public/detections/configurations/examples/security_solution_rac/render_cell_value.tsx index 61a5225cdae8c..8d726c1c19213 100644 --- a/x-pack/plugins/security_solution/public/detections/configurations/examples/security_solution_rac/render_cell_value.tsx +++ b/x-pack/plugins/security_solution/public/detections/configurations/examples/security_solution_rac/render_cell_value.tsx @@ -24,59 +24,60 @@ const reason = * accepts `EuiDataGridCellValueElementProps`, plus `data` * from the TGrid */ -export const RenderCellValue: React.FC = - ({ - columnId, - data, - eventId, - header, - isDetails, - isExpandable, - isExpanded, - linkValues, - rowIndex, - setCellProps, - timelineId, - }) => { - const value = - getMappedNonEcsValue({ - data, - fieldName: columnId, - })?.reduce((x) => x[0]) ?? ''; - const draggableId = `${timelineId}-${eventId}-${columnId}-${value}`; +export const RenderCellValue: React.FC< + EuiDataGridCellValueElementProps & CellValueElementProps +> = ({ + columnId, + data, + eventId, + header, + isDetails, + isExpandable, + isExpanded, + linkValues, + rowIndex, + setCellProps, + timelineId, +}) => { + const value = + getMappedNonEcsValue({ + data, + fieldName: columnId, + })?.reduce((x) => x[0]) ?? ''; + const draggableId = `${timelineId}-${eventId}-${columnId}-${value}`; - switch (columnId) { - case 'signal.rule.severity': - case ALERT_RULE_SEVERITY: - return ( - - - - ); - case 'signal.reason': - case ALERT_REASON: - return {reason}; - default: - return ( - - ); - } - }; + switch (columnId) { + case 'signal.rule.severity': + case ALERT_RULE_SEVERITY: + return ( + + + + ); + case 'signal.reason': + case ALERT_REASON: + return {reason}; + default: + return ( + + ); + } +}; diff --git a/x-pack/plugins/security_solution/public/detections/configurations/security_solution_detections/render_cell_value.tsx b/x-pack/plugins/security_solution/public/detections/configurations/security_solution_detections/render_cell_value.tsx index 54cd26e9cdc54..d5f7ed0ee2e1e 100644 --- a/x-pack/plugins/security_solution/public/detections/configurations/security_solution_detections/render_cell_value.tsx +++ b/x-pack/plugins/security_solution/public/detections/configurations/security_solution_detections/render_cell_value.tsx @@ -16,43 +16,44 @@ import { DefaultCellRenderer } from '../../../timelines/components/timeline/cell * accepts `EuiDataGridCellValueElementProps`, plus `data` * from the TGrid */ -export const RenderCellValue: React.FC = - ({ - browserFields, - columnId, - data, - ecsData, - eventId, - globalFilters, - header, - isDetails, - isDraggable, - isExpandable, - isExpanded, - linkValues, - rowIndex, - rowRenderers, - setCellProps, - timelineId, - truncate, - }) => ( - - ); +export const RenderCellValue: React.FC< + EuiDataGridCellValueElementProps & CellValueElementProps +> = ({ + browserFields, + columnId, + data, + ecsData, + eventId, + globalFilters, + header, + isDetails, + isDraggable, + isExpandable, + isExpanded, + linkValues, + rowIndex, + rowRenderers, + setCellProps, + timelineId, + truncate, +}) => ( + +); diff --git a/x-pack/plugins/security_solution/public/management/pages/event_filters/store/middleware.ts b/x-pack/plugins/security_solution/public/management/pages/event_filters/store/middleware.ts index bc59b4d2c3bb3..ac495749eb9a2 100644 --- a/x-pack/plugins/security_solution/public/management/pages/event_filters/store/middleware.ts +++ b/x-pack/plugins/security_solution/public/management/pages/event_filters/store/middleware.ts @@ -346,5 +346,6 @@ export const createEventFiltersPageMiddleware = ( }; }; -export const eventFiltersPageMiddlewareFactory: ImmutableMiddlewareFactory = - (coreStart) => createEventFiltersPageMiddleware(new EventFiltersHttpService(coreStart.http)); +export const eventFiltersPageMiddlewareFactory: ImmutableMiddlewareFactory< + EventFiltersListPageState +> = (coreStart) => createEventFiltersPageMiddleware(new EventFiltersHttpService(coreStart.http)); diff --git a/x-pack/plugins/security_solution/public/management/pages/event_filters/store/reducer.ts b/x-pack/plugins/security_solution/public/management/pages/event_filters/store/reducer.ts index 353484492eb73..3d58f6c9652ce 100644 --- a/x-pack/plugins/security_solution/public/management/pages/event_filters/store/reducer.ts +++ b/x-pack/plugins/security_solution/public/management/pages/event_filters/store/reducer.ts @@ -66,16 +66,17 @@ const handleEventFiltersListPageDataChanges: CaseReducer = - (state, action) => { - return { - ...state, - listPage: { - ...state.listPage, - dataExist: action.payload, - }, - }; +const handleEventFiltersListPageDataExistChanges: CaseReducer< + EventFiltersListPageDataExistsChanged +> = (state, action) => { + return { + ...state, + listPage: { + ...state.listPage, + dataExist: action.payload, + }, }; +}; const eventFiltersInitForm: CaseReducer = (state, action) => { return { diff --git a/x-pack/plugins/security_solution/public/management/pages/event_filters/store/selector.ts b/x-pack/plugins/security_solution/public/management/pages/event_filters/store/selector.ts index 8293c1a0452eb..9e5eb5c531b6e 100644 --- a/x-pack/plugins/security_solution/public/management/pages/event_filters/store/selector.ts +++ b/x-pack/plugins/security_solution/public/management/pages/event_filters/store/selector.ts @@ -93,8 +93,9 @@ export const getListFetchError: EventFiltersSelector | return (isFailedResourceState(listPageDataState) && listPageDataState.error) || undefined; }); -export const getListPageDataExistsState: EventFiltersSelector = - ({ listPage: { dataExist } }) => dataExist; +export const getListPageDataExistsState: EventFiltersSelector< + StoreState['listPage']['dataExist'] +> = ({ listPage: { dataExist } }) => dataExist; export const getListIsLoading: EventFiltersSelector = createSelector( getCurrentListPageDataState, diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/ingest_manager_integration/endpoint_package_custom_extension/components/exception_items_summary.test.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/ingest_manager_integration/endpoint_package_custom_extension/components/exception_items_summary.test.tsx index bc672a3bd00d6..973d0d457756d 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/ingest_manager_integration/endpoint_package_custom_extension/components/exception_items_summary.test.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/ingest_manager_integration/endpoint_package_custom_extension/components/exception_items_summary.test.tsx @@ -24,18 +24,19 @@ const getStatValue = (el: reactTestingLibrary.RenderResult, stat: string) => { }; describe('Fleet event filters card', () => { - const renderComponent: (stats: GetExceptionSummaryResponse) => reactTestingLibrary.RenderResult = - (stats) => { - const Wrapper: React.FC = ({ children }) => ( - - {children} - - ); - const component = reactTestingLibrary.render(, { - wrapper: Wrapper, - }); - return component; - }; + const renderComponent: ( + stats: GetExceptionSummaryResponse + ) => reactTestingLibrary.RenderResult = (stats) => { + const Wrapper: React.FC = ({ children }) => ( + + {children} + + ); + const component = reactTestingLibrary.render(, { + wrapper: Wrapper, + }); + return component; + }; it('should renders correctly', () => { const summary: GetExceptionSummaryResponse = { windows: 3, diff --git a/x-pack/plugins/security_solution/public/management/pages/trusted_apps/store/middleware.ts b/x-pack/plugins/security_solution/public/management/pages/trusted_apps/store/middleware.ts index 55199d703d1ca..97f6661cebadb 100644 --- a/x-pack/plugins/security_solution/public/management/pages/trusted_apps/store/middleware.ts +++ b/x-pack/plugins/security_solution/public/management/pages/trusted_apps/store/middleware.ts @@ -474,5 +474,6 @@ export const createTrustedAppsPageMiddleware = ( }; }; -export const trustedAppsPageMiddlewareFactory: ImmutableMiddlewareFactory = - (coreStart) => createTrustedAppsPageMiddleware(new TrustedAppsHttpService(coreStart.http)); +export const trustedAppsPageMiddlewareFactory: ImmutableMiddlewareFactory< + TrustedAppsListPageState +> = (coreStart) => createTrustedAppsPageMiddleware(new TrustedAppsHttpService(coreStart.http)); diff --git a/x-pack/plugins/security_solution/public/management/pages/trusted_apps/store/reducer.ts b/x-pack/plugins/security_solution/public/management/pages/trusted_apps/store/reducer.ts index 46722d8b9522c..07409a46156db 100644 --- a/x-pack/plugins/security_solution/public/management/pages/trusted_apps/store/reducer.ts +++ b/x-pack/plugins/security_solution/public/management/pages/trusted_apps/store/reducer.ts @@ -68,13 +68,14 @@ const trustedAppsListResourceStateChanged: CaseReducer = - (state, action) => { - return { - ...state, - deletionDialog: { ...state.deletionDialog, submissionResourceState: action.payload.newState }, - }; +const trustedAppDeletionSubmissionResourceStateChanged: CaseReducer< + TrustedAppDeletionSubmissionResourceStateChanged +> = (state, action) => { + return { + ...state, + deletionDialog: { ...state.deletionDialog, submissionResourceState: action.payload.newState }, }; +}; const trustedAppDeletionDialogStarted: CaseReducer = ( state, @@ -93,13 +94,14 @@ const trustedAppDeletionDialogClosed: CaseReducer = - (state, action) => { - return { - ...state, - creationDialog: { ...state.creationDialog, submissionResourceState: action.payload.newState }, - }; +const trustedAppCreationSubmissionResourceStateChanged: CaseReducer< + TrustedAppCreationSubmissionResourceStateChanged +> = (state, action) => { + return { + ...state, + creationDialog: { ...state.creationDialog, submissionResourceState: action.payload.newState }, }; +}; const trustedAppCreationDialogStarted: CaseReducer = ( state, @@ -114,13 +116,14 @@ const trustedAppCreationDialogStarted: CaseReducer = - (state, action) => { - return { - ...state, - creationDialog: { ...state.creationDialog, formState: { ...action.payload } }, - }; +const trustedAppCreationDialogFormStateUpdated: CaseReducer< + TrustedAppCreationDialogFormStateUpdated +> = (state, action) => { + return { + ...state, + creationDialog: { ...state.creationDialog, formState: { ...action.payload } }, }; +}; const handleUpdateToEditItemState: CaseReducer = ( state, diff --git a/x-pack/plugins/transform/server/routes/api/transforms.ts b/x-pack/plugins/transform/server/routes/api/transforms.ts index e19ac2c39c129..deef8898fdc66 100644 --- a/x-pack/plugins/transform/server/routes/api/transforms.ts +++ b/x-pack/plugins/transform/server/routes/api/transforms.ts @@ -590,22 +590,22 @@ const previewTransformHandler: RequestHandler< } }; -const startTransformsHandler: RequestHandler = - async (ctx, req, res) => { - const transformsInfo = req.body; +const startTransformsHandler: RequestHandler< + undefined, + undefined, + StartTransformsRequestSchema +> = async (ctx, req, res) => { + const transformsInfo = req.body; - try { - const body = await startTransforms( - transformsInfo, - ctx.core.elasticsearch.client.asCurrentUser - ); - return res.ok({ - body, - }); - } catch (e) { - return res.customError(wrapError(wrapEsError(e))); - } - }; + try { + const body = await startTransforms(transformsInfo, ctx.core.elasticsearch.client.asCurrentUser); + return res.ok({ + body, + }); + } catch (e) { + return res.customError(wrapError(wrapEsError(e))); + } +}; async function startTransforms( transformsInfo: StartTransformsRequestSchema, @@ -635,18 +635,21 @@ async function startTransforms( return results; } -const stopTransformsHandler: RequestHandler = - async (ctx, req, res) => { - const transformsInfo = req.body; +const stopTransformsHandler: RequestHandler< + undefined, + undefined, + StopTransformsRequestSchema +> = async (ctx, req, res) => { + const transformsInfo = req.body; - try { - return res.ok({ - body: await stopTransforms(transformsInfo, ctx.core.elasticsearch.client.asCurrentUser), - }); - } catch (e) { - return res.customError(wrapError(wrapEsError(e))); - } - }; + try { + return res.ok({ + body: await stopTransforms(transformsInfo, ctx.core.elasticsearch.client.asCurrentUser), + }); + } catch (e) { + return res.customError(wrapError(wrapEsError(e))); + } +}; async function stopTransforms( transformsInfo: StopTransformsRequestSchema, diff --git a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/servicenow/servicenow_connectors.tsx b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/servicenow/servicenow_connectors.tsx index 415e99eee7fdc..556e8cfbca3f0 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/servicenow/servicenow_connectors.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/servicenow/servicenow_connectors.tsx @@ -29,157 +29,158 @@ export { ServiceNowConnectorFields as default }; // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { snExternalServiceConfig } from '../../../../../../actions/server/builtin_action_types/servicenow/config'; -const ServiceNowConnectorFields: React.FC> = - ({ - action, - editActionSecrets, - editActionConfig, - errors, - consumer, - readOnly, - setCallbacks, - isEdit, - }) => { - const { - http, - notifications: { toasts }, - } = useKibana().services; - const { apiUrl, usesTableApi } = action.config; - const { username, password } = action.secrets; - const requiresNewApplication = !checkConnectorIsDeprecated(action); - - const [showUpdateConnector, setShowUpdateConnector] = useState(false); - - const { fetchAppInfo, isLoading } = useGetAppInfo({ - actionTypeId: action.actionTypeId, - }); - - const [showApplicationRequiredCallout, setShowApplicationRequiredCallout] = - useState(false); - const [applicationInfoErrorMsg, setApplicationInfoErrorMsg] = useState(null); - - const getApplicationInfo = useCallback(async () => { - setShowApplicationRequiredCallout(false); - setApplicationInfoErrorMsg(null); - - try { - const res = await fetchAppInfo(action); - if (isRESTApiError(res)) { - throw new Error(res.error?.message ?? i18n.UNKNOWN); - } - - return res; - } catch (e) { - setShowApplicationRequiredCallout(true); - setApplicationInfoErrorMsg(e.message); - // We need to throw here so the connector will be not be saved. - throw e; +const ServiceNowConnectorFields: React.FC< + ActionConnectorFieldsProps +> = ({ + action, + editActionSecrets, + editActionConfig, + errors, + consumer, + readOnly, + setCallbacks, + isEdit, +}) => { + const { + http, + notifications: { toasts }, + } = useKibana().services; + const { apiUrl, usesTableApi } = action.config; + const { username, password } = action.secrets; + const requiresNewApplication = !checkConnectorIsDeprecated(action); + + const [showUpdateConnector, setShowUpdateConnector] = useState(false); + + const { fetchAppInfo, isLoading } = useGetAppInfo({ + actionTypeId: action.actionTypeId, + }); + + const [showApplicationRequiredCallout, setShowApplicationRequiredCallout] = + useState(false); + const [applicationInfoErrorMsg, setApplicationInfoErrorMsg] = useState(null); + + const getApplicationInfo = useCallback(async () => { + setShowApplicationRequiredCallout(false); + setApplicationInfoErrorMsg(null); + + try { + const res = await fetchAppInfo(action); + if (isRESTApiError(res)) { + throw new Error(res.error?.message ?? i18n.UNKNOWN); } - }, [action, fetchAppInfo]); - const beforeActionConnectorSave = useCallback(async () => { - if (requiresNewApplication) { - await getApplicationInfo(); - } - }, [getApplicationInfo, requiresNewApplication]); - - useEffect( - () => setCallbacks({ beforeActionConnectorSave }), - [beforeActionConnectorSave, setCallbacks] - ); - - const onMigrateClick = useCallback(() => setShowUpdateConnector(true), []); - const onModalCancel = useCallback(() => setShowUpdateConnector(false), []); - - const onUpdateConnectorConfirm = useCallback(async () => { - try { - await getApplicationInfo(); - - await updateActionConnector({ - http, - connector: { - name: action.name, - config: { apiUrl, usesTableApi: false }, - secrets: { username, password }, - }, - id: action.id, - }); - - editActionConfig('usesTableApi', false); - setShowUpdateConnector(false); - - toasts.addSuccess({ - title: i18n.UPDATE_SUCCESS_TOAST_TITLE(action.name), - text: i18n.UPDATE_SUCCESS_TOAST_TEXT, - }); - } catch (err) { - /** - * getApplicationInfo may throw an error if the request - * fails or if there is a REST api error. - * - * We silent the errors as a callout will show and inform the user - */ - } - }, [ - getApplicationInfo, - http, - action.name, - action.id, - apiUrl, - username, - password, - editActionConfig, - toasts, - ]); - - /** - * Defaults the usesTableApi attribute to false - * if it is not defined. The usesTableApi attribute - * will be undefined only at the creation of - * the connector. - */ - useEffect(() => { - if (usesTableApi == null) { - editActionConfig('usesTableApi', false); - } - }); - - return ( - <> - {showUpdateConnector && ( - - )} - {requiresNewApplication && ( - - )} - {!requiresNewApplication && } - { + if (requiresNewApplication) { + await getApplicationInfo(); + } + }, [getApplicationInfo, requiresNewApplication]); + + useEffect( + () => setCallbacks({ beforeActionConnectorSave }), + [beforeActionConnectorSave, setCallbacks] + ); + + const onMigrateClick = useCallback(() => setShowUpdateConnector(true), []); + const onModalCancel = useCallback(() => setShowUpdateConnector(false), []); + + const onUpdateConnectorConfirm = useCallback(async () => { + try { + await getApplicationInfo(); + + await updateActionConnector({ + http, + connector: { + name: action.name, + config: { apiUrl, usesTableApi: false }, + secrets: { username, password }, + }, + id: action.id, + }); + + editActionConfig('usesTableApi', false); + setShowUpdateConnector(false); + + toasts.addSuccess({ + title: i18n.UPDATE_SUCCESS_TOAST_TITLE(action.name), + text: i18n.UPDATE_SUCCESS_TOAST_TEXT, + }); + } catch (err) { + /** + * getApplicationInfo may throw an error if the request + * fails or if there is a REST api error. + * + * We silent the errors as a callout will show and inform the user + */ + } + }, [ + getApplicationInfo, + http, + action.name, + action.id, + apiUrl, + username, + password, + editActionConfig, + toasts, + ]); + + /** + * Defaults the usesTableApi attribute to false + * if it is not defined. The usesTableApi attribute + * will be undefined only at the creation of + * the connector. + */ + useEffect(() => { + if (usesTableApi == null) { + editActionConfig('usesTableApi', false); + } + }); + + return ( + <> + {showUpdateConnector && ( + + )} + {requiresNewApplication && ( + + )} + {!requiresNewApplication && } + + {showApplicationRequiredCallout && requiresNewApplication && ( + - {showApplicationRequiredCallout && requiresNewApplication && ( - - )} - - ); - }; + )} + + ); +}; const SpacedDeprecatedCallout = ({ onMigrate }: { onMigrate: () => void }) => ( <> diff --git a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/slack/slack_connectors.tsx b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/slack/slack_connectors.tsx index e93ca46ddc2f7..39e05c2c09c7e 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/slack/slack_connectors.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/slack/slack_connectors.tsx @@ -14,66 +14,67 @@ import { SlackActionConnector } from '../types'; import { useKibana } from '../../../../common/lib/kibana'; import { getEncryptedFieldNotifyLabel } from '../../get_encrypted_field_notify_label'; -const SlackActionFields: React.FunctionComponent> = - ({ action, editActionSecrets, errors, readOnly }) => { - const { docLinks } = useKibana().services; - const { webhookUrl } = action.secrets; - const isWebhookUrlInvalid: boolean = - errors.webhookUrl !== undefined && errors.webhookUrl.length > 0 && webhookUrl !== undefined; +const SlackActionFields: React.FunctionComponent< + ActionConnectorFieldsProps +> = ({ action, editActionSecrets, errors, readOnly }) => { + const { docLinks } = useKibana().services; + const { webhookUrl } = action.secrets; + const isWebhookUrlInvalid: boolean = + errors.webhookUrl !== undefined && errors.webhookUrl.length > 0 && webhookUrl !== undefined; - return ( - <> - - - + return ( + <> + + + + } + error={errors.webhookUrl} + isInvalid={isWebhookUrlInvalid} + label={i18n.translate( + 'xpack.triggersActionsUI.components.builtinActionTypes.slackAction.webhookUrlTextFieldLabel', + { + defaultMessage: 'Webhook URL', } - error={errors.webhookUrl} - isInvalid={isWebhookUrlInvalid} - label={i18n.translate( - 'xpack.triggersActionsUI.components.builtinActionTypes.slackAction.webhookUrlTextFieldLabel', - { - defaultMessage: 'Webhook URL', - } + )} + > + <> + {getEncryptedFieldNotifyLabel( + !action.id, + 1, + action.isMissingSecrets ?? false, + i18n.translate( + 'xpack.triggersActionsUI.components.builtinActionTypes.slackAction.reenterValueLabel', + { defaultMessage: 'This URL is encrypted. Please reenter a value for this field.' } + ) )} - > - <> - {getEncryptedFieldNotifyLabel( - !action.id, - 1, - action.isMissingSecrets ?? false, - i18n.translate( - 'xpack.triggersActionsUI.components.builtinActionTypes.slackAction.reenterValueLabel', - { defaultMessage: 'This URL is encrypted. Please reenter a value for this field.' } - ) - )} - { - editActionSecrets('webhookUrl', e.target.value); - }} - onBlur={() => { - if (!webhookUrl) { - editActionSecrets('webhookUrl', ''); - } - }} - /> - - - - ); - }; + { + editActionSecrets('webhookUrl', e.target.value); + }} + onBlur={() => { + if (!webhookUrl) { + editActionSecrets('webhookUrl', ''); + } + }} + /> + + + + ); +}; // eslint-disable-next-line import/no-default-export export { SlackActionFields as default }; diff --git a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/teams/teams_connectors.tsx b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/teams/teams_connectors.tsx index 586727e0d1965..b6c41cb649dbd 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/teams/teams_connectors.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/teams/teams_connectors.tsx @@ -14,67 +14,68 @@ import { TeamsActionConnector } from '../types'; import { useKibana } from '../../../../common/lib/kibana'; import { getEncryptedFieldNotifyLabel } from '../../get_encrypted_field_notify_label'; -const TeamsActionFields: React.FunctionComponent> = - ({ action, editActionSecrets, errors, readOnly }) => { - const { webhookUrl } = action.secrets; - const { docLinks } = useKibana().services; +const TeamsActionFields: React.FunctionComponent< + ActionConnectorFieldsProps +> = ({ action, editActionSecrets, errors, readOnly }) => { + const { webhookUrl } = action.secrets; + const { docLinks } = useKibana().services; - const isWebhookUrlInvalid: boolean = - errors.webhookUrl !== undefined && errors.webhookUrl.length > 0 && webhookUrl !== undefined; + const isWebhookUrlInvalid: boolean = + errors.webhookUrl !== undefined && errors.webhookUrl.length > 0 && webhookUrl !== undefined; - return ( - <> - - - + return ( + <> + + + + } + error={errors.webhookUrl} + isInvalid={isWebhookUrlInvalid} + label={i18n.translate( + 'xpack.triggersActionsUI.components.builtinActionTypes.teamsAction.webhookUrlTextFieldLabel', + { + defaultMessage: 'Webhook URL', } - error={errors.webhookUrl} - isInvalid={isWebhookUrlInvalid} - label={i18n.translate( - 'xpack.triggersActionsUI.components.builtinActionTypes.teamsAction.webhookUrlTextFieldLabel', - { - defaultMessage: 'Webhook URL', - } + )} + > + <> + {getEncryptedFieldNotifyLabel( + !action.id, + 1, + action.isMissingSecrets ?? false, + i18n.translate( + 'xpack.triggersActionsUI.components.builtinActionTypes.teamsAction.reenterValueLabel', + { defaultMessage: 'This URL is encrypted. Please reenter a value for this field.' } + ) )} - > - <> - {getEncryptedFieldNotifyLabel( - !action.id, - 1, - action.isMissingSecrets ?? false, - i18n.translate( - 'xpack.triggersActionsUI.components.builtinActionTypes.teamsAction.reenterValueLabel', - { defaultMessage: 'This URL is encrypted. Please reenter a value for this field.' } - ) - )} - { - editActionSecrets('webhookUrl', e.target.value); - }} - onBlur={() => { - if (!webhookUrl) { - editActionSecrets('webhookUrl', ''); - } - }} - /> - - - - ); - }; + { + editActionSecrets('webhookUrl', e.target.value); + }} + onBlur={() => { + if (!webhookUrl) { + editActionSecrets('webhookUrl', ''); + } + }} + /> + + + + ); +}; // eslint-disable-next-line import/no-default-export export { TeamsActionFields as default }; diff --git a/x-pack/plugins/uptime/server/lib/requests/get_journey_failed_steps.ts b/x-pack/plugins/uptime/server/lib/requests/get_journey_failed_steps.ts index c53f1b589ef7a..4d94d5f33a897 100644 --- a/x-pack/plugins/uptime/server/lib/requests/get_journey_failed_steps.ts +++ b/x-pack/plugins/uptime/server/lib/requests/get_journey_failed_steps.ts @@ -14,47 +14,49 @@ export interface GetJourneyStepsParams { checkGroups: string[]; } -export const getJourneyFailedSteps: UMElasticsearchQueryFn = - async ({ uptimeEsClient, checkGroups }) => { - const params = { - query: { - bool: { - filter: [ - { - terms: { - 'synthetics.type': ['step/end'], - }, +export const getJourneyFailedSteps: UMElasticsearchQueryFn< + GetJourneyStepsParams, + JourneyStep[] +> = async ({ uptimeEsClient, checkGroups }) => { + const params = { + query: { + bool: { + filter: [ + { + terms: { + 'synthetics.type': ['step/end'], }, - { - exists: { - field: 'synthetics.error', - }, + }, + { + exists: { + field: 'synthetics.error', }, - { - terms: { - 'monitor.check_group': checkGroups, - }, + }, + { + terms: { + 'monitor.check_group': checkGroups, }, - ] as QueryDslQueryContainer[], - }, + }, + ] as QueryDslQueryContainer[], }, - sort: asMutableArray([ - { 'synthetics.step.index': { order: 'asc' } }, - { '@timestamp': { order: 'asc' } }, - ] as const), - _source: { - excludes: ['synthetics.blob'], - }, - size: 500, - }; + }, + sort: asMutableArray([ + { 'synthetics.step.index': { order: 'asc' } }, + { '@timestamp': { order: 'asc' } }, + ] as const), + _source: { + excludes: ['synthetics.blob'], + }, + size: 500, + }; - const { body: result } = await uptimeEsClient.search({ body: params }); + const { body: result } = await uptimeEsClient.search({ body: params }); - return result.hits.hits.map(({ _id, _source }) => { - const step = Object.assign({ _id }, _source) as JourneyStep; - return { - ...step, - timestamp: step['@timestamp'], - }; - }); - }; + return result.hits.hits.map(({ _id, _source }) => { + const step = Object.assign({ _id }, _source) as JourneyStep; + return { + ...step, + timestamp: step['@timestamp'], + }; + }); +}; diff --git a/x-pack/plugins/uptime/server/lib/requests/get_journey_steps.ts b/x-pack/plugins/uptime/server/lib/requests/get_journey_steps.ts index 3e48ae7cccfbc..a7c418c23ae3d 100644 --- a/x-pack/plugins/uptime/server/lib/requests/get_journey_steps.ts +++ b/x-pack/plugins/uptime/server/lib/requests/get_journey_steps.ts @@ -33,67 +33,69 @@ export const formatSyntheticEvents = (eventTypes?: string | string[]) => { type ResultType = JourneyStep & { '@timestamp': string }; -export const getJourneySteps: UMElasticsearchQueryFn = - async ({ uptimeEsClient, checkGroup, syntheticEventTypes }) => { - const params = { - query: { - bool: { - filter: [ - { - terms: { - 'synthetics.type': formatSyntheticEvents(syntheticEventTypes), - }, +export const getJourneySteps: UMElasticsearchQueryFn< + GetJourneyStepsParams, + JourneyStep[] +> = async ({ uptimeEsClient, checkGroup, syntheticEventTypes }) => { + const params = { + query: { + bool: { + filter: [ + { + terms: { + 'synthetics.type': formatSyntheticEvents(syntheticEventTypes), }, - { - term: { - 'monitor.check_group': checkGroup, - }, + }, + { + term: { + 'monitor.check_group': checkGroup, }, - ] as QueryDslQueryContainer, - }, + }, + ] as QueryDslQueryContainer, }, - sort: asMutableArray([ - { 'synthetics.step.index': { order: 'asc' } }, - { '@timestamp': { order: 'asc' } }, - ] as const), - _source: { - excludes: ['synthetics.blob', 'screenshot_ref'], - }, - size: 500, - }; - const { body: result } = await uptimeEsClient.search({ body: params }); + }, + sort: asMutableArray([ + { 'synthetics.step.index': { order: 'asc' } }, + { '@timestamp': { order: 'asc' } }, + ] as const), + _source: { + excludes: ['synthetics.blob', 'screenshot_ref'], + }, + size: 500, + }; + const { body: result } = await uptimeEsClient.search({ body: params }); - const steps = result.hits.hits.map( - ({ _id, _source }) => Object.assign({ _id }, _source) as ResultType - ); + const steps = result.hits.hits.map( + ({ _id, _source }) => Object.assign({ _id }, _source) as ResultType + ); - const screenshotIndexList: number[] = []; - const refIndexList: number[] = []; - const stepsWithoutImages: ResultType[] = []; + const screenshotIndexList: number[] = []; + const refIndexList: number[] = []; + const stepsWithoutImages: ResultType[] = []; - /** - * Store screenshot indexes, we use these to determine if a step has a screenshot below. - * Store steps that are not screenshots, we return these to the client. - */ - for (const step of steps) { - const { synthetics } = step; - if (synthetics.type === 'step/screenshot' && synthetics?.step?.index) { - screenshotIndexList.push(synthetics.step.index); - } else if (synthetics.type === 'step/screenshot_ref' && synthetics?.step?.index) { - refIndexList.push(synthetics.step.index); - } else { - stepsWithoutImages.push(step); - } + /** + * Store screenshot indexes, we use these to determine if a step has a screenshot below. + * Store steps that are not screenshots, we return these to the client. + */ + for (const step of steps) { + const { synthetics } = step; + if (synthetics.type === 'step/screenshot' && synthetics?.step?.index) { + screenshotIndexList.push(synthetics.step.index); + } else if (synthetics.type === 'step/screenshot_ref' && synthetics?.step?.index) { + refIndexList.push(synthetics.step.index); + } else { + stepsWithoutImages.push(step); } + } - return stepsWithoutImages.map(({ _id, ...rest }) => ({ - _id, - ...rest, - timestamp: rest['@timestamp'], - synthetics: { - ...rest.synthetics, - isFullScreenshot: screenshotIndexList.some((i) => i === rest?.synthetics?.step?.index), - isScreenshotRef: refIndexList.some((i) => i === rest?.synthetics?.step?.index), - }, - })); - }; + return stepsWithoutImages.map(({ _id, ...rest }) => ({ + _id, + ...rest, + timestamp: rest['@timestamp'], + synthetics: { + ...rest.synthetics, + isFullScreenshot: screenshotIndexList.some((i) => i === rest?.synthetics?.step?.index), + isScreenshotRef: refIndexList.some((i) => i === rest?.synthetics?.step?.index), + }, + })); +}; diff --git a/x-pack/plugins/uptime/server/lib/requests/get_last_successful_check.ts b/x-pack/plugins/uptime/server/lib/requests/get_last_successful_check.ts index bd61263543cd4..ea1b9ad447a1d 100644 --- a/x-pack/plugins/uptime/server/lib/requests/get_last_successful_check.ts +++ b/x-pack/plugins/uptime/server/lib/requests/get_last_successful_check.ts @@ -80,25 +80,27 @@ export const getLastSuccessfulStepParams = ({ }; }; -export const getLastSuccessfulCheck: UMElasticsearchQueryFn = - async ({ uptimeEsClient, monitorId, timestamp, location }) => { - const lastSuccessCheckParams = getLastSuccessfulStepParams({ - monitorId, - timestamp, - location, - }); +export const getLastSuccessfulCheck: UMElasticsearchQueryFn< + GetStepScreenshotParams, + Ping | null +> = async ({ uptimeEsClient, monitorId, timestamp, location }) => { + const lastSuccessCheckParams = getLastSuccessfulStepParams({ + monitorId, + timestamp, + location, + }); - const { body: result } = await uptimeEsClient.search({ body: lastSuccessCheckParams }); + const { body: result } = await uptimeEsClient.search({ body: lastSuccessCheckParams }); - if (result.hits.total.value < 1) { - return null; - } + if (result.hits.total.value < 1) { + return null; + } - const check = result.hits.hits[0]._source as Ping & { '@timestamp': string }; + const check = result.hits.hits[0]._source as Ping & { '@timestamp': string }; - return { - ...check, - timestamp: check['@timestamp'], - docId: result.hits.hits[0]._id, - }; + return { + ...check, + timestamp: check['@timestamp'], + docId: result.hits.hits[0]._id, }; +}; diff --git a/x-pack/plugins/uptime/server/lib/requests/get_monitor_details.ts b/x-pack/plugins/uptime/server/lib/requests/get_monitor_details.ts index 9f77b0833d8b6..6a4042a8f5fe6 100644 --- a/x-pack/plugins/uptime/server/lib/requests/get_monitor_details.ts +++ b/x-pack/plugins/uptime/server/lib/requests/get_monitor_details.ts @@ -93,63 +93,65 @@ export const getMonitorAlerts = async ({ return monitorAlerts; }; -export const getMonitorDetails: UMElasticsearchQueryFn = - async ({ uptimeEsClient, monitorId, dateStart, dateEnd, rulesClient }) => { - const queryFilters: any = [ - { - range: { - '@timestamp': { - gte: dateStart, - lte: dateEnd, - }, +export const getMonitorDetails: UMElasticsearchQueryFn< + GetMonitorDetailsParams, + MonitorDetails +> = async ({ uptimeEsClient, monitorId, dateStart, dateEnd, rulesClient }) => { + const queryFilters: any = [ + { + range: { + '@timestamp': { + gte: dateStart, + lte: dateEnd, }, }, - { - term: { - 'monitor.id': monitorId, - }, + }, + { + term: { + 'monitor.id': monitorId, }, - ]; - - const params = { - size: 1, - _source: ['error', '@timestamp'], - query: { - bool: { - must: [ - { - exists: { - field: 'error', - }, + }, + ]; + + const params = { + size: 1, + _source: ['error', '@timestamp'], + query: { + bool: { + must: [ + { + exists: { + field: 'error', }, - ], - filter: queryFilters, - }, - }, - sort: [ - { - '@timestamp': { - order: 'desc' as const, }, + ], + filter: queryFilters, + }, + }, + sort: [ + { + '@timestamp': { + order: 'desc' as const, }, - ], - }; + }, + ], + }; - const { body: result } = await uptimeEsClient.search({ body: params }, 'getMonitorDetails'); + const { body: result } = await uptimeEsClient.search({ body: params }, 'getMonitorDetails'); - const data = result.hits.hits[0]?._source as Ping & { '@timestamp': string }; + const data = result.hits.hits[0]?._source as Ping & { '@timestamp': string }; - const errorTimestamp: string | undefined = data?.['@timestamp']; - const monAlerts = await getMonitorAlerts({ - uptimeEsClient, - rulesClient, - monitorId, - }); + const errorTimestamp: string | undefined = data?.['@timestamp']; + const monAlerts = await getMonitorAlerts({ + uptimeEsClient, + rulesClient, + monitorId, + }); - return { - monitorId, - error: data?.error, - timestamp: errorTimestamp, - alerts: monAlerts, - }; + return { + monitorId, + error: data?.error, + timestamp: errorTimestamp, + alerts: monAlerts, }; +}; diff --git a/x-pack/plugins/uptime/server/lib/requests/get_ping_histogram.ts b/x-pack/plugins/uptime/server/lib/requests/get_ping_histogram.ts index 139ac8bad417c..a8d722b4e059d 100644 --- a/x-pack/plugins/uptime/server/lib/requests/get_ping_histogram.ts +++ b/x-pack/plugins/uptime/server/lib/requests/get_ping_histogram.ts @@ -12,97 +12,99 @@ import { UMElasticsearchQueryFn } from '../adapters/framework'; import { createEsQuery } from '../../../common/utils/es_search'; import { getHistogramInterval } from '../../../common/lib/get_histogram_interval'; -export const getPingHistogram: UMElasticsearchQueryFn = - async ({ - uptimeEsClient, - dateStart: from, - dateEnd: to, - filters, - monitorId, - bucketSize, - query, - }) => { - const boolFilters = filters ? JSON.parse(filters) : null; - const additionalFilters = []; - if (monitorId) { - additionalFilters.push({ match: { 'monitor.id': monitorId } }); - } - if (boolFilters) { - additionalFilters.push(boolFilters); - } - const filter = getFilterClause(from, to, additionalFilters); +export const getPingHistogram: UMElasticsearchQueryFn< + GetPingHistogramParams, + HistogramResult +> = async ({ + uptimeEsClient, + dateStart: from, + dateEnd: to, + filters, + monitorId, + bucketSize, + query, +}) => { + const boolFilters = filters ? JSON.parse(filters) : null; + const additionalFilters = []; + if (monitorId) { + additionalFilters.push({ match: { 'monitor.id': monitorId } }); + } + if (boolFilters) { + additionalFilters.push(boolFilters); + } + const filter = getFilterClause(from, to, additionalFilters); - const minInterval = getHistogramInterval(from, to, QUERY.DEFAULT_BUCKET_COUNT); + const minInterval = getHistogramInterval(from, to, QUERY.DEFAULT_BUCKET_COUNT); - const params = createEsQuery({ - body: { - query: { - bool: { - filter: [ - ...filter, - { - exists: { - field: 'summary', - }, + const params = createEsQuery({ + body: { + query: { + bool: { + filter: [ + ...filter, + { + exists: { + field: 'summary', }, - ], - ...(query - ? { - minimum_should_match: 1, - should: [ - { - multi_match: { - query: escape(query), - type: 'phrase_prefix' as const, - fields: ['monitor.id.text', 'monitor.name.text', 'url.full.text'], - }, + }, + ], + ...(query + ? { + minimum_should_match: 1, + should: [ + { + multi_match: { + query: escape(query), + type: 'phrase_prefix' as const, + fields: ['monitor.id.text', 'monitor.name.text', 'url.full.text'], }, - ], - } - : {}), - }, + }, + ], + } + : {}), }, - size: 0, - aggs: { - timeseries: { - date_histogram: { - field: '@timestamp', - fixed_interval: bucketSize || minInterval + 'ms', - missing: '0', - }, - aggs: { - down: { - sum: { - field: 'summary.down', - }, + }, + size: 0, + aggs: { + timeseries: { + date_histogram: { + field: '@timestamp', + fixed_interval: bucketSize || minInterval + 'ms', + missing: '0', + }, + aggs: { + down: { + sum: { + field: 'summary.down', }, - up: { - sum: { - field: 'summary.up', - }, + }, + up: { + sum: { + field: 'summary.up', }, }, }, }, }, - }); + }, + }); - const { body: result } = await uptimeEsClient.search(params, 'getPingsOverTime'); - const buckets = result?.aggregations?.timeseries?.buckets ?? []; + const { body: result } = await uptimeEsClient.search(params, 'getPingsOverTime'); + const buckets = result?.aggregations?.timeseries?.buckets ?? []; - const histogram = buckets.map((bucket: Pick) => { - const x: number = bucket.key; - const downCount = bucket.down.value || 0; - const upCount = bucket.up.value || 0; - return { - x, - downCount, - upCount, - y: 1, - }; - }); + const histogram = buckets.map((bucket: Pick) => { + const x: number = bucket.key; + const downCount = bucket.down.value || 0; + const upCount = bucket.up.value || 0; return { - histogram, - minInterval, + x, + downCount, + upCount, + y: 1, }; + }); + return { + histogram, + minInterval, }; +}; diff --git a/x-pack/test/plugin_api_integration/plugins/feature_usage_test/server/index.ts b/x-pack/test/plugin_api_integration/plugins/feature_usage_test/server/index.ts index b6f4dacbfdd7f..32161d27a4ff0 100644 --- a/x-pack/test/plugin_api_integration/plugins/feature_usage_test/server/index.ts +++ b/x-pack/test/plugin_api_integration/plugins/feature_usage_test/server/index.ts @@ -12,5 +12,7 @@ import { FeatureUsageTestPluginStart, } from './plugin'; -export const plugin: PluginInitializer = - () => new FeatureUsageTestPlugin(); +export const plugin: PluginInitializer< + FeatureUsageTestPluginSetup, + FeatureUsageTestPluginStart +> = () => new FeatureUsageTestPlugin();