From 92fb5dbafcaed93d2bb4f4e8a42543019d7c3d19 Mon Sep 17 00:00:00 2001 From: Spencer Date: Mon, 8 Aug 2022 16:12:04 -0500 Subject: [PATCH 1/7] [ci] mark PR stats as usable for metrics (#138297) --- .buildkite/pipeline-utils/ci-stats/client.ts | 12 ++++--- .../pipeline-utils/ci-stats/on_complete.ts | 7 +--- .buildkite/pipelines/pull_request/base.yml | 35 +++++++++++++------ 3 files changed, 32 insertions(+), 22 deletions(-) diff --git a/.buildkite/pipeline-utils/ci-stats/client.ts b/.buildkite/pipeline-utils/ci-stats/client.ts index 9044e0072e1502..6a5c048464c708 100644 --- a/.buildkite/pipeline-utils/ci-stats/client.ts +++ b/.buildkite/pipeline-utils/ci-stats/client.ts @@ -84,6 +84,9 @@ export class CiStatsClient { jenkinsJobId: process.env.BUILDKITE_BUILD_NUMBER, jenkinsUrl: process.env.BUILDKITE_BUILD_URL, prId: process.env.GITHUB_PR_NUMBER || null, + backfillJobIds: process.env.KIBANA_REUSABLE_BUILD_JOB_ID + ? [process.env.KIBANA_REUSABLE_BUILD_JOB_ID] + : [], }, }); @@ -132,13 +135,12 @@ export class CiStatsClient { }); }; - getPrReport = async (buildId: string, backfillJobIds: string[] = []) => { + getPrReport = async (buildId: string) => { const resp = await this.request({ - path: `v3/pr_report`, - method: 'post', - body: { + method: 'GET', + path: `v2/pr_report`, + params: { buildId, - backfillJobIds, }, }); diff --git a/.buildkite/pipeline-utils/ci-stats/on_complete.ts b/.buildkite/pipeline-utils/ci-stats/on_complete.ts index e0ef78a2f61c24..0b93fd6b0673f4 100644 --- a/.buildkite/pipeline-utils/ci-stats/on_complete.ts +++ b/.buildkite/pipeline-utils/ci-stats/on_complete.ts @@ -26,12 +26,7 @@ export async function onComplete() { return; } - const backfillJobIds: string[] = []; - if (process.env.KIBANA_REUSABLE_BUILD_JOB_ID) { - backfillJobIds.push(process.env.KIBANA_REUSABLE_BUILD_JOB_ID); - } - - const report = await ciStats.getPrReport(process.env.CI_STATS_BUILD_ID, backfillJobIds); + const report = await ciStats.getPrReport(process.env.CI_STATS_BUILD_ID); if (report?.md) { buildkite.setMetadata('pr_comment:ci_stats_report:body', report.md); diff --git a/.buildkite/pipelines/pull_request/base.yml b/.buildkite/pipelines/pull_request/base.yml index db42cc4c7293c2..5ce9b5b3246b95 100644 --- a/.buildkite/pipelines/pull_request/base.yml +++ b/.buildkite/pipelines/pull_request/base.yml @@ -15,6 +15,30 @@ steps: if: "build.env('KIBANA_BUILD_ID') == null || build.env('KIBANA_BUILD_ID') == ''" timeout_in_minutes: 60 + - command: .buildkite/scripts/steps/build_api_docs.sh + label: 'Build API Docs' + agents: + queue: n2-4-spot + key: build_api_docs + timeout_in_minutes: 60 + retry: + automatic: + - exit_status: '-1' + limit: 3 + + - command: .buildkite/scripts/steps/ci_stats_ready.sh + label: Mark CI Stats as ready + agents: + queue: kibana-default + timeout_in_minutes: 10 + depends_on: + - build + - build_api_docs + retry: + automatic: + - exit_status: '*' + limit: 1 + - command: .buildkite/scripts/steps/test/pick_test_group_run_order.sh label: 'Pick Test Group Run Order' agents: @@ -61,14 +85,3 @@ steps: agents: queue: c2-8 timeout_in_minutes: 60 - - - command: .buildkite/scripts/steps/build_api_docs.sh - label: 'Build API Docs' - agents: - queue: n2-4-spot - key: build_api_docs - timeout_in_minutes: 60 - retry: - automatic: - - exit_status: '-1' - limit: 3 From 604a18d0c67bef5a16ae21cc2db42a8ae5905fd2 Mon Sep 17 00:00:00 2001 From: Candace Park <56409205+parkiino@users.noreply.github.com> Date: Mon, 8 Aug 2022 17:12:37 -0400 Subject: [PATCH 2/7] [Security Solution][Admin][Responder] Disable responder option when metadata api returns an error (#137923) --- .../responder_context_menu_item.tsx | 13 +++++++++++-- .../components/take_action_dropdown/index.test.tsx | 2 +- .../hooks/endpoint/use_get_endpoint_details.ts | 1 + 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/security_solution/public/detections/components/endpoint_responder/responder_context_menu_item.tsx b/x-pack/plugins/security_solution/public/detections/components/endpoint_responder/responder_context_menu_item.tsx index 85c0c2f31b29c0..6fea341cbc0ee6 100644 --- a/x-pack/plugins/security_solution/public/detections/components/endpoint_responder/responder_context_menu_item.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/endpoint_responder/responder_context_menu_item.tsx @@ -30,6 +30,10 @@ export const LOADING_ENDPOINT_DATA_TOOLTIP = i18n.translate( 'xpack.securitySolution.endpoint.detections.takeAction.responseActionConsole.loadingTooltip', { defaultMessage: 'Loading' } ); +export const METADATA_API_ERROR_TOOLTIP = i18n.translate( + 'xpack.securitySolution.endpoint.detections.takeAction.responseActionConsole.generalMetadataErrorTooltip', + { defaultMessage: 'Failed to retrieve Endpoint metadata' } +); export interface ResponderContextMenuItemProps { endpointId: string; @@ -62,16 +66,21 @@ export const ResponderContextMenuItem = memo( return [true, LOADING_ENDPOINT_DATA_TOOLTIP]; } - // if we got an error and it's a 400 (alerts can exist for endpoint that are no longer around) + // if we got an error and it's a 400 with unenrolled in the error message (alerts can exist for endpoint that are no longer around) // or, // the Host status is `unenrolled` if ( - (error && error.body?.statusCode === 400) || + (error && error.body?.statusCode === 400 && error.body?.message.includes('unenrolled')) || endpointHostInfo?.host_status === HostStatus.UNENROLLED ) { return [true, HOST_ENDPOINT_UNENROLLED_TOOLTIP]; } + // return general error tooltip + if (error) { + return [true, METADATA_API_ERROR_TOOLTIP]; + } + return [false, undefined]; }, [endpointHostInfo, endpointId, error, isFetching, isResponderCapabilitiesEnabled]); diff --git a/x-pack/plugins/security_solution/public/detections/components/take_action_dropdown/index.test.tsx b/x-pack/plugins/security_solution/public/detections/components/take_action_dropdown/index.test.tsx index d47b9f0187e8d0..4481c8a5c93a45 100644 --- a/x-pack/plugins/security_solution/public/detections/components/take_action_dropdown/index.test.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/take_action_dropdown/index.test.tsx @@ -24,8 +24,8 @@ import { initialUserPrivilegesState as mockInitialUserPrivilegesState } from '.. import { useUserPrivileges } from '../../../common/components/user_privileges'; import { useIsExperimentalFeatureEnabled } from '../../../common/hooks/use_experimental_features'; import { - HOST_ENDPOINT_UNENROLLED_TOOLTIP, NOT_FROM_ENDPOINT_HOST_TOOLTIP, + HOST_ENDPOINT_UNENROLLED_TOOLTIP, } from '../endpoint_responder/responder_context_menu_item'; import { endpointMetadataHttpMocks } from '../../../management/pages/endpoint_hosts/mocks'; import type { HttpSetup } from '@kbn/core/public'; diff --git a/x-pack/plugins/security_solution/public/management/hooks/endpoint/use_get_endpoint_details.ts b/x-pack/plugins/security_solution/public/management/hooks/endpoint/use_get_endpoint_details.ts index 7a69aeb6434928..e81e8b716ea9cd 100644 --- a/x-pack/plugins/security_solution/public/management/hooks/endpoint/use_get_endpoint_details.ts +++ b/x-pack/plugins/security_solution/public/management/hooks/endpoint/use_get_endpoint_details.ts @@ -15,6 +15,7 @@ import { HOST_METADATA_GET_ROUTE } from '../../../../common/endpoint/constants'; interface HttpResponse { statusCode: number; + message: string; } /** From e0b4b1baa33ac1c85821510ef8579b169f492db5 Mon Sep 17 00:00:00 2001 From: Marshall Main <55718608+marshallmain@users.noreply.github.com> Date: Mon, 8 Aug 2022 14:22:40 -0700 Subject: [PATCH 3/7] Query relative times around now for preview table (#138067) --- .../components/rules/rule_preview/preview_histogram.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/security_solution/public/detections/components/rules/rule_preview/preview_histogram.tsx b/x-pack/plugins/security_solution/public/detections/components/rules/rule_preview/preview_histogram.tsx index 3c38e6e1a1e172..f374c4b192bf23 100644 --- a/x-pack/plugins/security_solution/public/detections/components/rules/rule_preview/preview_histogram.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/rules/rule_preview/preview_histogram.tsx @@ -91,7 +91,6 @@ export const PreviewHistogram = ({ () => (advancedOptions ? advancedOptions.timeframeEnd.toISOString() : formatDate(to)), [to, advancedOptions] ); - const alertsEndDate = useMemo(() => formatDate(to), [to]); const isEqlRule = useMemo(() => ruleType === 'eql', [ruleType]); const isMlRule = useMemo(() => ruleType === 'machine_learning', [ruleType]); @@ -214,7 +213,12 @@ export const PreviewHistogram = ({ dataProviders, deletedEventIds, disabledCellActions: FIELDS_WITHOUT_CELL_ACTIONS, - end: alertsEndDate, + // Fix for https://github.com/elastic/kibana/issues/135511, until we start writing proper + // simulated @timestamp values to the preview alerts. The preview alerts will have @timestamp values + // close to the server's `now` time, but the client clock could be out of sync with the server. So we + // avoid computing static dates for this time range filter and instead pass in a small relative time window. + end: 'now+5m', + start: 'now-5m', entityType: 'events', filters: [], globalFullScreen, @@ -233,7 +237,6 @@ export const PreviewHistogram = ({ runtimeMappings, setQuery: () => {}, sort, - start: startDate, tGridEventRenderedViewEnabled, type: 'embedded', leadingControlColumns: getPreviewTableControlColumn(1.5), From 4226cbf2e64caac3a4fc14037b42ee0875f84a9d Mon Sep 17 00:00:00 2001 From: Devon Thomson Date: Mon, 8 Aug 2022 17:36:01 -0400 Subject: [PATCH 4/7] Use name for Controls Data View picker (#138313) --- .../public/components/data_view_picker/data_view_picker.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plugins/presentation_util/public/components/data_view_picker/data_view_picker.tsx b/src/plugins/presentation_util/public/components/data_view_picker/data_view_picker.tsx index 47c3625971f188..756fc9c525bb1f 100644 --- a/src/plugins/presentation_util/public/components/data_view_picker/data_view_picker.tsx +++ b/src/plugins/presentation_util/public/components/data_view_picker/data_view_picker.tsx @@ -85,11 +85,11 @@ export function DataViewPicker({ {...selectableProps} searchable singleSelection="always" - options={dataViews.map(({ title, id }) => ({ + options={dataViews.map(({ name, id, title }) => ({ key: id, - label: title, + label: name ?? title, value: id, - 'data-test-subj': `data-view-picker-${title}`, + 'data-test-subj': `data-view-picker-${name ?? title}`, checked: id === selectedDataViewId ? 'on' : undefined, }))} onChange={(choices) => { From 2b2b92e6bfe8fe61a326bffb69727dfe5e2000a8 Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Mon, 8 Aug 2022 14:56:30 -0700 Subject: [PATCH 5/7] Rename ActionStatus and WatchStatus models to ActionStatusModel and WatchStatusModel to differentiate between models, POJOs, and client-side components. (#137631) Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../action_status/action_status.test.js | 360 ------------------ .../action_status_model.js} | 7 +- .../action_status_model.test.js | 359 +++++++++++++++++ .../index.js | 2 +- .../watcher/server/models/watch/base_watch.js | 7 +- .../watch_history_item/watch_history_item.js | 11 +- .../models/watch_status/watch_status.test.js | 314 --------------- .../index.js | 2 +- .../watch_status_model.js} | 13 +- .../watch_status_model.test.js | 313 +++++++++++++++ .../action/register_acknowledge_route.ts | 4 +- .../api/watch/register_activate_route.ts | 4 +- .../api/watch/register_deactivate_route.ts | 4 +- 13 files changed, 703 insertions(+), 697 deletions(-) delete mode 100644 x-pack/plugins/watcher/server/models/action_status/action_status.test.js rename x-pack/plugins/watcher/server/models/{action_status/action_status.js => action_status_model/action_status_model.js} (98%) create mode 100644 x-pack/plugins/watcher/server/models/action_status_model/action_status_model.test.js rename x-pack/plugins/watcher/server/models/{watch_status => action_status_model}/index.js (81%) delete mode 100644 x-pack/plugins/watcher/server/models/watch_status/watch_status.test.js rename x-pack/plugins/watcher/server/models/{action_status => watch_status_model}/index.js (81%) rename x-pack/plugins/watcher/server/models/{watch_status/watch_status.js => watch_status_model/watch_status_model.js} (96%) create mode 100644 x-pack/plugins/watcher/server/models/watch_status_model/watch_status_model.test.js diff --git a/x-pack/plugins/watcher/server/models/action_status/action_status.test.js b/x-pack/plugins/watcher/server/models/action_status/action_status.test.js deleted file mode 100644 index 2bc8ec6ffecafd..00000000000000 --- a/x-pack/plugins/watcher/server/models/action_status/action_status.test.js +++ /dev/null @@ -1,360 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { ActionStatus } from './action_status'; -import { ACTION_STATES } from '../../../common/constants'; -import moment from 'moment'; - -describe('action_status', () => { - describe('ActionStatus', () => { - describe('fromUpstreamJson factory method', () => { - let upstreamJson; - beforeEach(() => { - upstreamJson = { - id: 'my-action', - actionStatusJson: { - ack: { - timestamp: '2017-03-01T20:56:58.442Z', - state: 'acked', - }, - last_execution: { - timestamp: '2017-03-01T20:55:49.679Z', - successful: true, - reason: 'reasons', - }, - last_throttle: { - timestamp: '2017-03-01T20:55:49.679Z', - }, - last_successful_execution: { - timestamp: '2017-03-01T20:55:49.679Z', - successful: true, - }, - }, - }; - }); - - it(`throws an error if no 'id' property in json`, () => { - delete upstreamJson.id; - expect(() => { - ActionStatus.fromUpstreamJson(upstreamJson); - }).toThrow('JSON argument must contain an "id" property'); - }); - - it(`throws an error if no 'actionStatusJson' property in json`, () => { - delete upstreamJson.actionStatusJson; - expect(() => { - ActionStatus.fromUpstreamJson(upstreamJson); - }).toThrow('JSON argument must contain an "actionStatusJson" property'); - }); - - it('returns correct ActionStatus instance', () => { - const actionStatus = ActionStatus.fromUpstreamJson({ - ...upstreamJson, - errors: { foo: 'bar' }, - }); - - expect(actionStatus.id).toBe(upstreamJson.id); - expect(actionStatus.lastAcknowledged).toEqual( - moment(upstreamJson.actionStatusJson.ack.timestamp) - ); - expect(actionStatus.lastExecution).toEqual( - moment(upstreamJson.actionStatusJson.last_execution.timestamp) - ); - expect(actionStatus.lastExecutionSuccessful).toEqual( - upstreamJson.actionStatusJson.last_execution.successful - ); - expect(actionStatus.lastExecutionReason).toBe( - upstreamJson.actionStatusJson.last_execution.reason - ); - expect(actionStatus.lastThrottled).toEqual( - moment(upstreamJson.actionStatusJson.last_throttle.timestamp) - ); - expect(actionStatus.lastSuccessfulExecution).toEqual( - moment(upstreamJson.actionStatusJson.last_successful_execution.timestamp) - ); - expect(actionStatus.errors).toEqual({ foo: 'bar' }); - }); - }); - - describe('state getter method', () => { - let upstreamJson; - beforeEach(() => { - upstreamJson = { - id: 'my-action', - lastCheckedRawFormat: '2017-03-01T20:55:49.679Z', - actionStatusJson: { - ack: { - timestamp: '2017-03-01T20:56:58.442Z', - state: 'acked', - }, - last_execution: { - timestamp: '2017-03-01T20:55:49.679Z', - successful: true, - reason: 'reasons', - }, - last_throttle: { - timestamp: '2017-03-01T20:55:49.679Z', - }, - last_successful_execution: { - timestamp: '2017-03-01T20:55:49.679Z', - successful: true, - }, - }, - }; - }); - - describe(`correctly calculates ACTION_STATES.ERROR`, () => { - it('lastExecutionSuccessful is equal to false and it is the most recent execution', () => { - upstreamJson.actionStatusJson.last_execution.successful = false; - const actionStatus = ActionStatus.fromUpstreamJson(upstreamJson); - expect(actionStatus.state).toBe(ACTION_STATES.ERROR); - }); - - it('action is acked and lastAcknowledged is less than lastExecution', () => { - const actionStatus = ActionStatus.fromUpstreamJson({ - ...upstreamJson, - actionStatusJson: { - ack: { - state: 'acked', - timestamp: '2017-03-01T00:00:00.000Z', - }, - last_execution: { - timestamp: '2017-03-02T00:00:00.000Z', - }, - }, - }); - expect(actionStatus.state).toBe(ACTION_STATES.ERROR); - }); - - it('action is ackable and lastSuccessfulExecution is less than lastExecution', () => { - delete upstreamJson.actionStatusJson.last_throttle; - upstreamJson.actionStatusJson.ack.state = 'ackable'; - upstreamJson.actionStatusJson.last_successful_execution.timestamp = - '2017-03-01T00:00:00.000Z'; - upstreamJson.actionStatusJson.last_execution.timestamp = '2017-03-02T00:00:00.000Z'; - const actionStatus = ActionStatus.fromUpstreamJson(upstreamJson); - - expect(actionStatus.state).toBe(ACTION_STATES.ERROR); - }); - }); - - it('correctly calculates ACTION_STATES.CONFIG_ERROR', () => { - const actionStatus = ActionStatus.fromUpstreamJson({ - ...upstreamJson, - errors: { foo: 'bar' }, - }); - expect(actionStatus.state).toBe(ACTION_STATES.CONFIG_ERROR); - }); - - it(`correctly calculates ACTION_STATES.OK`, () => { - upstreamJson.actionStatusJson.ack.state = 'awaits_successful_execution'; - const actionStatus = ActionStatus.fromUpstreamJson(upstreamJson); - - expect(actionStatus.state).toBe(ACTION_STATES.OK); - }); - - describe(`correctly calculates ACTION_STATES.ACKNOWLEDGED`, () => { - it(`when lastAcknowledged is equal to lastExecution`, () => { - upstreamJson.actionStatusJson.ack.state = 'acked'; - upstreamJson.actionStatusJson.ack.timestamp = '2017-03-01T00:00:00.000Z'; - upstreamJson.actionStatusJson.last_execution.timestamp = '2017-03-01T00:00:00.000Z'; - const actionStatus = ActionStatus.fromUpstreamJson(upstreamJson); - - expect(actionStatus.state).toBe(ACTION_STATES.ACKNOWLEDGED); - }); - - it(`when lastAcknowledged is greater than lastExecution`, () => { - upstreamJson.actionStatusJson.ack.state = 'acked'; - upstreamJson.actionStatusJson.ack.timestamp = '2017-03-02T00:00:00.000Z'; - upstreamJson.actionStatusJson.last_execution.timestamp = '2017-03-01T00:00:00.000Z'; - const actionStatus = ActionStatus.fromUpstreamJson(upstreamJson); - - expect(actionStatus.state).toBe(ACTION_STATES.ACKNOWLEDGED); - }); - }); - - describe(`correctly calculates ACTION_STATES.THROTTLED`, () => { - it(`when lastThrottled is equal to lastExecution`, () => { - upstreamJson.actionStatusJson.ack.state = 'ackable'; - upstreamJson.actionStatusJson.last_throttle.timestamp = '2017-03-01T00:00:00.000Z'; - upstreamJson.actionStatusJson.last_execution.timestamp = '2017-03-01T00:00:00.000Z'; - const actionStatus = ActionStatus.fromUpstreamJson(upstreamJson); - - expect(actionStatus.state).toBe(ACTION_STATES.THROTTLED); - }); - - it(`when lastThrottled is greater than lastExecution`, () => { - upstreamJson.actionStatusJson.ack.state = 'ackable'; - upstreamJson.actionStatusJson.last_throttle.timestamp = '2017-03-02T00:00:00.000Z'; - upstreamJson.actionStatusJson.last_execution.timestamp = '2017-03-01T00:00:00.000Z'; - const actionStatus = ActionStatus.fromUpstreamJson(upstreamJson); - - expect(actionStatus.state).toBe(ACTION_STATES.THROTTLED); - }); - }); - - describe(`correctly calculates ACTION_STATES.FIRING`, () => { - it(`when lastSuccessfulExecution is equal to lastExecution`, () => { - delete upstreamJson.actionStatusJson.last_throttle; - upstreamJson.actionStatusJson.ack.state = 'ackable'; - upstreamJson.actionStatusJson.last_successful_execution.timestamp = - '2017-03-01T00:00:00.000Z'; - upstreamJson.actionStatusJson.last_execution.timestamp = '2017-03-01T00:00:00.000Z'; - const actionStatus = ActionStatus.fromUpstreamJson(upstreamJson); - - expect(actionStatus.state).toBe(ACTION_STATES.FIRING); - }); - - it(`when lastSuccessfulExecution is greater than lastExecution`, () => { - delete upstreamJson.actionStatusJson.last_throttle; - upstreamJson.actionStatusJson.ack.state = 'ackable'; - upstreamJson.actionStatusJson.last_successful_execution.timestamp = - '2017-03-02T00:00:00.000Z'; - upstreamJson.actionStatusJson.last_execution.timestamp = '2017-03-01T00:00:00.000Z'; - const actionStatus = ActionStatus.fromUpstreamJson(upstreamJson); - - expect(actionStatus.state).toBe(ACTION_STATES.FIRING); - }); - }); - - it(`correctly calculates ACTION_STATES.UNKNOWN if it can not determine state`, () => { - upstreamJson = { - id: 'my-action', - actionStatusJson: { - ack: { state: 'foo' }, - last_successful_execution: { successful: true }, - }, - }; - const actionStatus = ActionStatus.fromUpstreamJson(upstreamJson); - - expect(actionStatus.state).toBe(ACTION_STATES.UNKNOWN); - }); - }); - - describe('isAckable getter method', () => { - let upstreamJson; - beforeEach(() => { - upstreamJson = { - id: 'my-action', - actionStatusJson: { - ack: { - timestamp: '2017-03-01T20:56:58.442Z', - state: 'acked', - }, - last_execution: { - timestamp: '2017-03-01T20:55:49.679Z', - successful: true, - reason: 'reasons', - }, - last_throttle: { - timestamp: '2017-03-01T20:55:49.679Z', - }, - last_successful_execution: { - timestamp: '2017-03-01T20:55:49.679Z', - successful: true, - }, - }, - }; - }); - - it(`correctly calculated isAckable when in ACTION_STATES.OK`, () => { - upstreamJson.actionStatusJson.ack.state = 'awaits_successful_execution'; - const actionStatus = ActionStatus.fromUpstreamJson(upstreamJson); - - expect(actionStatus.state).toBe(ACTION_STATES.OK); - expect(actionStatus.isAckable).toBe(false); - }); - - it(`correctly calculated isAckable when in ACTION_STATES.ACKNOWLEDGED`, () => { - upstreamJson.actionStatusJson.ack.state = 'acked'; - upstreamJson.actionStatusJson.ack.timestamp = '2017-03-01T00:00:00.000Z'; - upstreamJson.actionStatusJson.last_execution.timestamp = '2017-03-01T00:00:00.000Z'; - const actionStatus = ActionStatus.fromUpstreamJson(upstreamJson); - - expect(actionStatus.state).toBe(ACTION_STATES.ACKNOWLEDGED); - expect(actionStatus.isAckable).toBe(false); - }); - - it(`correctly calculated isAckable when in ACTION_STATES.THROTTLED`, () => { - upstreamJson.actionStatusJson.ack.state = 'ackable'; - upstreamJson.actionStatusJson.last_throttle.timestamp = '2017-03-01T00:00:00.000Z'; - upstreamJson.actionStatusJson.last_execution.timestamp = '2017-03-01T00:00:00.000Z'; - const actionStatus = ActionStatus.fromUpstreamJson(upstreamJson); - - expect(actionStatus.state).toBe(ACTION_STATES.THROTTLED); - expect(actionStatus.isAckable).toBe(true); - }); - - it(`correctly calculated isAckable when in ACTION_STATES.FIRING`, () => { - delete upstreamJson.actionStatusJson.last_throttle; - upstreamJson.actionStatusJson.ack.state = 'ackable'; - upstreamJson.actionStatusJson.last_successful_execution.timestamp = - '2017-03-01T00:00:00.000Z'; - upstreamJson.actionStatusJson.last_execution.timestamp = '2017-03-01T00:00:00.000Z'; - const actionStatus = ActionStatus.fromUpstreamJson(upstreamJson); - - expect(actionStatus.state).toBe(ACTION_STATES.FIRING); - expect(actionStatus.isAckable).toBe(true); - }); - - it(`correctly calculated isAckable when in ACTION_STATES.ERROR`, () => { - delete upstreamJson.actionStatusJson.last_throttle; - upstreamJson.actionStatusJson.ack.state = 'ackable'; - upstreamJson.actionStatusJson.last_successful_execution.timestamp = - '2017-03-01T00:00:00.000Z'; - upstreamJson.actionStatusJson.last_execution.timestamp = '2017-03-02T00:00:00.000Z'; - const actionStatus = ActionStatus.fromUpstreamJson(upstreamJson); - - expect(actionStatus.state).toBe(ACTION_STATES.ERROR); - expect(actionStatus.isAckable).toBe(false); - }); - }); - - describe('downstreamJson getter method', () => { - let upstreamJson; - beforeEach(() => { - upstreamJson = { - id: 'my-action', - actionStatusJson: { - ack: { - timestamp: '2017-03-01T20:56:58.442Z', - state: 'acked', - }, - last_execution: { - timestamp: '2017-03-01T20:55:49.679Z', - successful: true, - reason: 'reasons', - }, - last_throttle: { - timestamp: '2017-03-01T20:55:49.679Z', - }, - last_successful_execution: { - timestamp: '2017-03-01T20:55:49.679Z', - successful: true, - }, - }, - }; - }); - - it('returns correct JSON for client', () => { - const actionStatus = ActionStatus.fromUpstreamJson(upstreamJson); - - const json = actionStatus.downstreamJson; - - expect(json.id).toBe(actionStatus.id); - expect(json.state).toBe(actionStatus.state); - expect(json.isAckable).toBe(actionStatus.isAckable); - expect(json.lastAcknowledged).toBe(actionStatus.lastAcknowledged); - expect(json.lastThrottled).toBe(actionStatus.lastThrottled); - expect(json.lastExecution).toBe(actionStatus.lastExecution); - expect(json.lastExecutionSuccessful).toBe(actionStatus.lastExecutionSuccessful); - expect(json.lastExecutionReason).toBe(actionStatus.lastExecutionReason); - expect(json.lastSuccessfulExecution).toBe(actionStatus.lastSuccessfulExecution); - }); - }); - }); -}); diff --git a/x-pack/plugins/watcher/server/models/action_status/action_status.js b/x-pack/plugins/watcher/server/models/action_status_model/action_status_model.js similarity index 98% rename from x-pack/plugins/watcher/server/models/action_status/action_status.js rename to x-pack/plugins/watcher/server/models/action_status_model/action_status_model.js index 1aef503ea2c0cb..e4ef87ab07dd66 100644 --- a/x-pack/plugins/watcher/server/models/action_status/action_status.js +++ b/x-pack/plugins/watcher/server/models/action_status_model/action_status_model.js @@ -7,11 +7,12 @@ import { get } from 'lodash'; import { badRequest } from '@hapi/boom'; +import { i18n } from '@kbn/i18n'; + import { getMoment } from '../../../common/lib/get_moment'; import { ACTION_STATES } from '../../../common/constants'; -import { i18n } from '@kbn/i18n'; -export class ActionStatus { +export class ActionStatusModel { constructor(props) { this.id = props.id; this.actionStatusJson = props.actionStatusJson; @@ -119,7 +120,7 @@ export class ActionStatus { throw badRequest(missingPropertyError('actionStatusJson')); } - return new ActionStatus(json); + return new ActionStatusModel(json); } /* diff --git a/x-pack/plugins/watcher/server/models/action_status_model/action_status_model.test.js b/x-pack/plugins/watcher/server/models/action_status_model/action_status_model.test.js new file mode 100644 index 00000000000000..08cd9e62093a87 --- /dev/null +++ b/x-pack/plugins/watcher/server/models/action_status_model/action_status_model.test.js @@ -0,0 +1,359 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import moment from 'moment'; + +import { ACTION_STATES } from '../../../common/constants'; +import { ActionStatusModel } from './action_status_model'; + +describe('ActionStatusModel', () => { + describe('fromUpstreamJson factory method', () => { + let upstreamJson; + beforeEach(() => { + upstreamJson = { + id: 'my-action', + actionStatusJson: { + ack: { + timestamp: '2017-03-01T20:56:58.442Z', + state: 'acked', + }, + last_execution: { + timestamp: '2017-03-01T20:55:49.679Z', + successful: true, + reason: 'reasons', + }, + last_throttle: { + timestamp: '2017-03-01T20:55:49.679Z', + }, + last_successful_execution: { + timestamp: '2017-03-01T20:55:49.679Z', + successful: true, + }, + }, + }; + }); + + it(`throws an error if no 'id' property in json`, () => { + delete upstreamJson.id; + expect(() => { + ActionStatusModel.fromUpstreamJson(upstreamJson); + }).toThrow('JSON argument must contain an "id" property'); + }); + + it(`throws an error if no 'actionStatusJson' property in json`, () => { + delete upstreamJson.actionStatusJson; + expect(() => { + ActionStatusModel.fromUpstreamJson(upstreamJson); + }).toThrow('JSON argument must contain an "actionStatusJson" property'); + }); + + it('returns correct ActionStatus instance', () => { + const actionStatus = ActionStatusModel.fromUpstreamJson({ + ...upstreamJson, + errors: { foo: 'bar' }, + }); + + expect(actionStatus.id).toBe(upstreamJson.id); + expect(actionStatus.lastAcknowledged).toEqual( + moment(upstreamJson.actionStatusJson.ack.timestamp) + ); + expect(actionStatus.lastExecution).toEqual( + moment(upstreamJson.actionStatusJson.last_execution.timestamp) + ); + expect(actionStatus.lastExecutionSuccessful).toEqual( + upstreamJson.actionStatusJson.last_execution.successful + ); + expect(actionStatus.lastExecutionReason).toBe( + upstreamJson.actionStatusJson.last_execution.reason + ); + expect(actionStatus.lastThrottled).toEqual( + moment(upstreamJson.actionStatusJson.last_throttle.timestamp) + ); + expect(actionStatus.lastSuccessfulExecution).toEqual( + moment(upstreamJson.actionStatusJson.last_successful_execution.timestamp) + ); + expect(actionStatus.errors).toEqual({ foo: 'bar' }); + }); + }); + + describe('state getter method', () => { + let upstreamJson; + beforeEach(() => { + upstreamJson = { + id: 'my-action', + lastCheckedRawFormat: '2017-03-01T20:55:49.679Z', + actionStatusJson: { + ack: { + timestamp: '2017-03-01T20:56:58.442Z', + state: 'acked', + }, + last_execution: { + timestamp: '2017-03-01T20:55:49.679Z', + successful: true, + reason: 'reasons', + }, + last_throttle: { + timestamp: '2017-03-01T20:55:49.679Z', + }, + last_successful_execution: { + timestamp: '2017-03-01T20:55:49.679Z', + successful: true, + }, + }, + }; + }); + + describe(`correctly calculates ACTION_STATES.ERROR`, () => { + it('lastExecutionSuccessful is equal to false and it is the most recent execution', () => { + upstreamJson.actionStatusJson.last_execution.successful = false; + const actionStatus = ActionStatusModel.fromUpstreamJson(upstreamJson); + expect(actionStatus.state).toBe(ACTION_STATES.ERROR); + }); + + it('action is acked and lastAcknowledged is less than lastExecution', () => { + const actionStatus = ActionStatusModel.fromUpstreamJson({ + ...upstreamJson, + actionStatusJson: { + ack: { + state: 'acked', + timestamp: '2017-03-01T00:00:00.000Z', + }, + last_execution: { + timestamp: '2017-03-02T00:00:00.000Z', + }, + }, + }); + expect(actionStatus.state).toBe(ACTION_STATES.ERROR); + }); + + it('action is ackable and lastSuccessfulExecution is less than lastExecution', () => { + delete upstreamJson.actionStatusJson.last_throttle; + upstreamJson.actionStatusJson.ack.state = 'ackable'; + upstreamJson.actionStatusJson.last_successful_execution.timestamp = + '2017-03-01T00:00:00.000Z'; + upstreamJson.actionStatusJson.last_execution.timestamp = '2017-03-02T00:00:00.000Z'; + const actionStatus = ActionStatusModel.fromUpstreamJson(upstreamJson); + + expect(actionStatus.state).toBe(ACTION_STATES.ERROR); + }); + }); + + it('correctly calculates ACTION_STATES.CONFIG_ERROR', () => { + const actionStatus = ActionStatusModel.fromUpstreamJson({ + ...upstreamJson, + errors: { foo: 'bar' }, + }); + expect(actionStatus.state).toBe(ACTION_STATES.CONFIG_ERROR); + }); + + it(`correctly calculates ACTION_STATES.OK`, () => { + upstreamJson.actionStatusJson.ack.state = 'awaits_successful_execution'; + const actionStatus = ActionStatusModel.fromUpstreamJson(upstreamJson); + + expect(actionStatus.state).toBe(ACTION_STATES.OK); + }); + + describe(`correctly calculates ACTION_STATES.ACKNOWLEDGED`, () => { + it(`when lastAcknowledged is equal to lastExecution`, () => { + upstreamJson.actionStatusJson.ack.state = 'acked'; + upstreamJson.actionStatusJson.ack.timestamp = '2017-03-01T00:00:00.000Z'; + upstreamJson.actionStatusJson.last_execution.timestamp = '2017-03-01T00:00:00.000Z'; + const actionStatus = ActionStatusModel.fromUpstreamJson(upstreamJson); + + expect(actionStatus.state).toBe(ACTION_STATES.ACKNOWLEDGED); + }); + + it(`when lastAcknowledged is greater than lastExecution`, () => { + upstreamJson.actionStatusJson.ack.state = 'acked'; + upstreamJson.actionStatusJson.ack.timestamp = '2017-03-02T00:00:00.000Z'; + upstreamJson.actionStatusJson.last_execution.timestamp = '2017-03-01T00:00:00.000Z'; + const actionStatus = ActionStatusModel.fromUpstreamJson(upstreamJson); + + expect(actionStatus.state).toBe(ACTION_STATES.ACKNOWLEDGED); + }); + }); + + describe(`correctly calculates ACTION_STATES.THROTTLED`, () => { + it(`when lastThrottled is equal to lastExecution`, () => { + upstreamJson.actionStatusJson.ack.state = 'ackable'; + upstreamJson.actionStatusJson.last_throttle.timestamp = '2017-03-01T00:00:00.000Z'; + upstreamJson.actionStatusJson.last_execution.timestamp = '2017-03-01T00:00:00.000Z'; + const actionStatus = ActionStatusModel.fromUpstreamJson(upstreamJson); + + expect(actionStatus.state).toBe(ACTION_STATES.THROTTLED); + }); + + it(`when lastThrottled is greater than lastExecution`, () => { + upstreamJson.actionStatusJson.ack.state = 'ackable'; + upstreamJson.actionStatusJson.last_throttle.timestamp = '2017-03-02T00:00:00.000Z'; + upstreamJson.actionStatusJson.last_execution.timestamp = '2017-03-01T00:00:00.000Z'; + const actionStatus = ActionStatusModel.fromUpstreamJson(upstreamJson); + + expect(actionStatus.state).toBe(ACTION_STATES.THROTTLED); + }); + }); + + describe(`correctly calculates ACTION_STATES.FIRING`, () => { + it(`when lastSuccessfulExecution is equal to lastExecution`, () => { + delete upstreamJson.actionStatusJson.last_throttle; + upstreamJson.actionStatusJson.ack.state = 'ackable'; + upstreamJson.actionStatusJson.last_successful_execution.timestamp = + '2017-03-01T00:00:00.000Z'; + upstreamJson.actionStatusJson.last_execution.timestamp = '2017-03-01T00:00:00.000Z'; + const actionStatus = ActionStatusModel.fromUpstreamJson(upstreamJson); + + expect(actionStatus.state).toBe(ACTION_STATES.FIRING); + }); + + it(`when lastSuccessfulExecution is greater than lastExecution`, () => { + delete upstreamJson.actionStatusJson.last_throttle; + upstreamJson.actionStatusJson.ack.state = 'ackable'; + upstreamJson.actionStatusJson.last_successful_execution.timestamp = + '2017-03-02T00:00:00.000Z'; + upstreamJson.actionStatusJson.last_execution.timestamp = '2017-03-01T00:00:00.000Z'; + const actionStatus = ActionStatusModel.fromUpstreamJson(upstreamJson); + + expect(actionStatus.state).toBe(ACTION_STATES.FIRING); + }); + }); + + it(`correctly calculates ACTION_STATES.UNKNOWN if it can not determine state`, () => { + upstreamJson = { + id: 'my-action', + actionStatusJson: { + ack: { state: 'foo' }, + last_successful_execution: { successful: true }, + }, + }; + const actionStatus = ActionStatusModel.fromUpstreamJson(upstreamJson); + + expect(actionStatus.state).toBe(ACTION_STATES.UNKNOWN); + }); + }); + + describe('isAckable getter method', () => { + let upstreamJson; + beforeEach(() => { + upstreamJson = { + id: 'my-action', + actionStatusJson: { + ack: { + timestamp: '2017-03-01T20:56:58.442Z', + state: 'acked', + }, + last_execution: { + timestamp: '2017-03-01T20:55:49.679Z', + successful: true, + reason: 'reasons', + }, + last_throttle: { + timestamp: '2017-03-01T20:55:49.679Z', + }, + last_successful_execution: { + timestamp: '2017-03-01T20:55:49.679Z', + successful: true, + }, + }, + }; + }); + + it(`correctly calculated isAckable when in ACTION_STATES.OK`, () => { + upstreamJson.actionStatusJson.ack.state = 'awaits_successful_execution'; + const actionStatus = ActionStatusModel.fromUpstreamJson(upstreamJson); + + expect(actionStatus.state).toBe(ACTION_STATES.OK); + expect(actionStatus.isAckable).toBe(false); + }); + + it(`correctly calculated isAckable when in ACTION_STATES.ACKNOWLEDGED`, () => { + upstreamJson.actionStatusJson.ack.state = 'acked'; + upstreamJson.actionStatusJson.ack.timestamp = '2017-03-01T00:00:00.000Z'; + upstreamJson.actionStatusJson.last_execution.timestamp = '2017-03-01T00:00:00.000Z'; + const actionStatus = ActionStatusModel.fromUpstreamJson(upstreamJson); + + expect(actionStatus.state).toBe(ACTION_STATES.ACKNOWLEDGED); + expect(actionStatus.isAckable).toBe(false); + }); + + it(`correctly calculated isAckable when in ACTION_STATES.THROTTLED`, () => { + upstreamJson.actionStatusJson.ack.state = 'ackable'; + upstreamJson.actionStatusJson.last_throttle.timestamp = '2017-03-01T00:00:00.000Z'; + upstreamJson.actionStatusJson.last_execution.timestamp = '2017-03-01T00:00:00.000Z'; + const actionStatus = ActionStatusModel.fromUpstreamJson(upstreamJson); + + expect(actionStatus.state).toBe(ACTION_STATES.THROTTLED); + expect(actionStatus.isAckable).toBe(true); + }); + + it(`correctly calculated isAckable when in ACTION_STATES.FIRING`, () => { + delete upstreamJson.actionStatusJson.last_throttle; + upstreamJson.actionStatusJson.ack.state = 'ackable'; + upstreamJson.actionStatusJson.last_successful_execution.timestamp = + '2017-03-01T00:00:00.000Z'; + upstreamJson.actionStatusJson.last_execution.timestamp = '2017-03-01T00:00:00.000Z'; + const actionStatus = ActionStatusModel.fromUpstreamJson(upstreamJson); + + expect(actionStatus.state).toBe(ACTION_STATES.FIRING); + expect(actionStatus.isAckable).toBe(true); + }); + + it(`correctly calculated isAckable when in ACTION_STATES.ERROR`, () => { + delete upstreamJson.actionStatusJson.last_throttle; + upstreamJson.actionStatusJson.ack.state = 'ackable'; + upstreamJson.actionStatusJson.last_successful_execution.timestamp = + '2017-03-01T00:00:00.000Z'; + upstreamJson.actionStatusJson.last_execution.timestamp = '2017-03-02T00:00:00.000Z'; + const actionStatus = ActionStatusModel.fromUpstreamJson(upstreamJson); + + expect(actionStatus.state).toBe(ACTION_STATES.ERROR); + expect(actionStatus.isAckable).toBe(false); + }); + }); + + describe('downstreamJson getter method', () => { + let upstreamJson; + beforeEach(() => { + upstreamJson = { + id: 'my-action', + actionStatusJson: { + ack: { + timestamp: '2017-03-01T20:56:58.442Z', + state: 'acked', + }, + last_execution: { + timestamp: '2017-03-01T20:55:49.679Z', + successful: true, + reason: 'reasons', + }, + last_throttle: { + timestamp: '2017-03-01T20:55:49.679Z', + }, + last_successful_execution: { + timestamp: '2017-03-01T20:55:49.679Z', + successful: true, + }, + }, + }; + }); + + it('returns correct JSON for client', () => { + const actionStatus = ActionStatusModel.fromUpstreamJson(upstreamJson); + + const json = actionStatus.downstreamJson; + + expect(json.id).toBe(actionStatus.id); + expect(json.state).toBe(actionStatus.state); + expect(json.isAckable).toBe(actionStatus.isAckable); + expect(json.lastAcknowledged).toBe(actionStatus.lastAcknowledged); + expect(json.lastThrottled).toBe(actionStatus.lastThrottled); + expect(json.lastExecution).toBe(actionStatus.lastExecution); + expect(json.lastExecutionSuccessful).toBe(actionStatus.lastExecutionSuccessful); + expect(json.lastExecutionReason).toBe(actionStatus.lastExecutionReason); + expect(json.lastSuccessfulExecution).toBe(actionStatus.lastSuccessfulExecution); + }); + }); +}); diff --git a/x-pack/plugins/watcher/server/models/watch_status/index.js b/x-pack/plugins/watcher/server/models/action_status_model/index.js similarity index 81% rename from x-pack/plugins/watcher/server/models/watch_status/index.js rename to x-pack/plugins/watcher/server/models/action_status_model/index.js index 43ac78260def90..18ceabb0c1dc8f 100644 --- a/x-pack/plugins/watcher/server/models/watch_status/index.js +++ b/x-pack/plugins/watcher/server/models/action_status_model/index.js @@ -5,4 +5,4 @@ * 2.0. */ -export { WatchStatus } from './watch_status'; +export { ActionStatusModel } from './action_status_model'; diff --git a/x-pack/plugins/watcher/server/models/watch/base_watch.js b/x-pack/plugins/watcher/server/models/watch/base_watch.js index 0222f2f241621e..053b03e7f39316 100644 --- a/x-pack/plugins/watcher/server/models/watch/base_watch.js +++ b/x-pack/plugins/watcher/server/models/watch/base_watch.js @@ -7,9 +7,10 @@ import { get, map, pick } from 'lodash'; import { badRequest } from '@hapi/boom'; -import { Action } from '../../../common/models/action'; -import { WatchStatus } from '../watch_status'; import { i18n } from '@kbn/i18n'; + +import { Action } from '../../../common/models/action'; +import { WatchStatusModel } from '../watch_status_model'; import { WatchErrors } from '../watch_errors'; export class BaseWatch { @@ -137,7 +138,7 @@ export class BaseWatch { const watchErrors = WatchErrors.fromUpstreamJson(this.getWatchErrors(actions)); - const watchStatus = WatchStatus.fromUpstreamJson({ + const watchStatus = WatchStatusModel.fromUpstreamJson({ id, watchStatusJson, watchErrors, diff --git a/x-pack/plugins/watcher/server/models/watch_history_item/watch_history_item.js b/x-pack/plugins/watcher/server/models/watch_history_item/watch_history_item.js index b59c5e3b1a61f0..a343dcfe729079 100644 --- a/x-pack/plugins/watcher/server/models/watch_history_item/watch_history_item.js +++ b/x-pack/plugins/watcher/server/models/watch_history_item/watch_history_item.js @@ -6,11 +6,12 @@ */ import { badRequest } from '@hapi/boom'; -import { getMoment } from '../../../common/lib/get_moment'; import { get, cloneDeep } from 'lodash'; -import { WatchStatus } from '../watch_status'; import { i18n } from '@kbn/i18n'; +import { getMoment } from '../../../common/lib/get_moment'; +import { WatchStatusModel } from '../watch_status_model'; + export class WatchHistoryItem { constructor(props) { this.id = props.id; @@ -23,7 +24,11 @@ export class WatchHistoryItem { const watchStatusJson = get(this.watchHistoryItemJson, 'status'); const state = get(this.watchHistoryItemJson, 'state'); - this.watchStatus = WatchStatus.fromUpstreamJson({ id: this.watchId, watchStatusJson, state }); + this.watchStatus = WatchStatusModel.fromUpstreamJson({ + id: this.watchId, + watchStatusJson, + state, + }); } get downstreamJson() { diff --git a/x-pack/plugins/watcher/server/models/watch_status/watch_status.test.js b/x-pack/plugins/watcher/server/models/watch_status/watch_status.test.js deleted file mode 100644 index ce949de1b5a502..00000000000000 --- a/x-pack/plugins/watcher/server/models/watch_status/watch_status.test.js +++ /dev/null @@ -1,314 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { WatchStatus } from './watch_status'; -import { ACTION_STATES, WATCH_STATES, WATCH_STATE_COMMENTS } from '../../../common/constants'; -import moment from 'moment'; - -describe('watch_status', () => { - describe('WatchStatus', () => { - describe('fromUpstreamJson factory method', () => { - let upstreamJson; - beforeEach(() => { - upstreamJson = { - id: 'my-watch', - watchStatusJson: { - state: { - active: true, - }, - last_checked: '2017-03-02T14:25:31.139Z', - last_met_condition: '2017-07-05T14:25:31.139Z', - actions: { - foo: {}, - bar: {}, - }, - }, - }; - }); - - it(`throws an error if no 'id' property in json`, () => { - delete upstreamJson.id; - expect(() => { - WatchStatus.fromUpstreamJson(upstreamJson); - }).toThrow(/must contain an id property/i); - }); - - it(`throws an error if no 'watchStatusJson' property in json`, () => { - delete upstreamJson.watchStatusJson; - expect(() => { - WatchStatus.fromUpstreamJson(upstreamJson); - }).toThrow(/must contain a watchStatusJson property/i); - }); - - it('returns correct WatchStatus instance', () => { - const watchStatus = WatchStatus.fromUpstreamJson(upstreamJson); - - expect(watchStatus.id).toBe(upstreamJson.id); - expect(watchStatus.watchStatusJson).toEqual(upstreamJson.watchStatusJson); - expect(watchStatus.isActive).toEqual(true); - expect(watchStatus.lastChecked).toEqual(moment(upstreamJson.watchStatusJson.last_checked)); - expect(watchStatus.lastMetCondition).toEqual( - moment(upstreamJson.watchStatusJson.last_met_condition) - ); - expect(watchStatus.actionStatuses.length).toBe(2); - - expect(watchStatus.actionStatuses[0].constructor.name).toBe('ActionStatus'); - expect(watchStatus.actionStatuses[1].constructor.name).toBe('ActionStatus'); - }); - }); - - describe('lastFired getter method', () => { - let upstreamJson; - beforeEach(() => { - upstreamJson = { - id: 'my-watch', - watchStatusJson: { - actions: { - foo: { - last_execution: { - timestamp: '2017-07-05T00:00:00.000Z', - }, - }, - bar: { - last_execution: { - timestamp: '2025-07-05T00:00:00.000Z', - }, - }, - baz: {}, - }, - }, - }; - }); - - it(`returns the latest lastExecution from it's actions`, () => { - const watchStatus = WatchStatus.fromUpstreamJson(upstreamJson); - expect(watchStatus.lastFired).toEqual( - moment(upstreamJson.watchStatusJson.actions.bar.last_execution.timestamp) - ); - }); - }); - - describe('comment getter method', () => { - let upstreamJson; - beforeEach(() => { - upstreamJson = { - id: 'my-watch', - watchStatusJson: { - state: { - active: true, - }, - }, - }; - }); - - it(`correctly calculates WATCH_STATE_COMMENTS.OK there are no actions`, () => { - const watchStatus = WatchStatus.fromUpstreamJson(upstreamJson); - watchStatus.isActive = true; - expect(watchStatus.comment).toBe(WATCH_STATE_COMMENTS.OK); - }); - - it(`correctly calculates WATCH_STATE_COMMENTS.PARTIALLY_THROTTLED`, () => { - const watchStatus = WatchStatus.fromUpstreamJson(upstreamJson); - - watchStatus.actionStatuses = [ - { state: ACTION_STATES.THROTTLED }, - { state: ACTION_STATES.FIRING }, - { state: ACTION_STATES.OK }, - ]; - - expect(watchStatus.comment).toBe(WATCH_STATE_COMMENTS.PARTIALLY_THROTTLED); - }); - - it(`correctly calculates WATCH_STATE_COMMENTS.THROTTLED`, () => { - const watchStatus = WatchStatus.fromUpstreamJson(upstreamJson); - - watchStatus.actionStatuses = [ - { state: ACTION_STATES.THROTTLED }, - { state: ACTION_STATES.THROTTLED }, - { state: ACTION_STATES.THROTTLED }, - ]; - - expect(watchStatus.comment).toBe(WATCH_STATE_COMMENTS.THROTTLED); - }); - - it(`correctly calculates WATCH_STATE_COMMENTS.PARTIALLY_ACKNOWLEDGED`, () => { - const watchStatus = WatchStatus.fromUpstreamJson(upstreamJson); - - watchStatus.actionStatuses = [ - { state: ACTION_STATES.ACKNOWLEDGED }, - { state: ACTION_STATES.OK }, - { state: ACTION_STATES.THROTTLED }, - { state: ACTION_STATES.FIRING }, - ]; - - expect(watchStatus.comment).toBe(WATCH_STATE_COMMENTS.PARTIALLY_ACKNOWLEDGED); - }); - - it(`correctly calculates WATCH_STATE_COMMENTS.ACKNOWLEDGED`, () => { - const watchStatus = WatchStatus.fromUpstreamJson(upstreamJson); - - watchStatus.actionStatuses = [ - { state: ACTION_STATES.ACKNOWLEDGED }, - { state: ACTION_STATES.ACKNOWLEDGED }, - { state: ACTION_STATES.ACKNOWLEDGED }, - ]; - - expect(watchStatus.comment).toBe(WATCH_STATE_COMMENTS.ACKNOWLEDGED); - }); - - it(`correctly calculates WATCH_STATE_COMMENTS.FAILING`, () => { - const watchStatus = WatchStatus.fromUpstreamJson(upstreamJson); - - watchStatus.actionStatuses = [ - { state: ACTION_STATES.OK }, - { state: ACTION_STATES.ACKNOWLEDGED }, - { state: ACTION_STATES.THROTTLED }, - { state: ACTION_STATES.FIRING }, - { state: ACTION_STATES.ERROR }, - ]; - - expect(watchStatus.comment).toBe(WATCH_STATE_COMMENTS.FAILING); - }); - - it(`correctly calculates WATCH_STATE_COMMENTS.OK when watch is inactive`, () => { - const watchStatus = WatchStatus.fromUpstreamJson(upstreamJson); - watchStatus.isActive = false; - - watchStatus.actionStatuses = [ - { state: ACTION_STATES.OK }, - { state: ACTION_STATES.ACKNOWLEDGED }, - { state: ACTION_STATES.THROTTLED }, - { state: ACTION_STATES.FIRING }, - { state: ACTION_STATES.ERROR }, - ]; - - expect(watchStatus.comment).toBe(WATCH_STATE_COMMENTS.OK); - }); - }); - - describe('state getter method', () => { - let upstreamJson; - beforeEach(() => { - upstreamJson = { - id: 'my-watch', - watchStatusJson: { - state: { - active: true, - }, - }, - }; - }); - - it(`correctly calculates WATCH_STATES.OK there are no actions`, () => { - const watchStatus = WatchStatus.fromUpstreamJson(upstreamJson); - watchStatus.isActive = true; - expect(watchStatus.state).toBe(WATCH_STATES.OK); - }); - - it(`correctly calculates WATCH_STATES.FIRING`, () => { - const watchStatus = WatchStatus.fromUpstreamJson(upstreamJson); - - watchStatus.actionStatuses = [{ state: ACTION_STATES.OK }, { state: ACTION_STATES.FIRING }]; - expect(watchStatus.state).toBe(WATCH_STATES.FIRING); - - watchStatus.actionStatuses = [ - { state: ACTION_STATES.OK }, - { state: ACTION_STATES.FIRING }, - { state: ACTION_STATES.THROTTLED }, - ]; - expect(watchStatus.state).toBe(WATCH_STATES.FIRING); - - watchStatus.actionStatuses = [ - { state: ACTION_STATES.OK }, - { state: ACTION_STATES.FIRING }, - { state: ACTION_STATES.THROTTLED }, - { state: ACTION_STATES.ACKNOWLEDGED }, - ]; - expect(watchStatus.state).toBe(WATCH_STATES.FIRING); - }); - - it(`correctly calculates WATCH_STATES.ERROR`, () => { - const watchStatus = WatchStatus.fromUpstreamJson(upstreamJson); - - watchStatus.actionStatuses = [ - { state: ACTION_STATES.OK }, - { state: ACTION_STATES.FIRING }, - { state: ACTION_STATES.THROTTLED }, - { state: ACTION_STATES.ACKNOWLEDGED }, - { state: ACTION_STATES.ERROR }, - ]; - - expect(watchStatus.state).toBe(WATCH_STATES.ERROR); - }); - - it('correctly calculates WATCH_STATE.CONFIG_ERROR', () => { - const watchStatus = WatchStatus.fromUpstreamJson(upstreamJson); - - watchStatus.actionStatuses = [ - { state: ACTION_STATES.OK }, - { state: ACTION_STATES.CONFIG_ERROR }, - ]; - - expect(watchStatus.state).toBe(WATCH_STATES.CONFIG_ERROR); - }); - - it(`correctly calculates WATCH_STATES.DISABLED when watch is inactive`, () => { - const watchStatus = WatchStatus.fromUpstreamJson(upstreamJson); - watchStatus.isActive = false; - - watchStatus.actionStatuses = [ - { state: ACTION_STATES.OK }, - { state: ACTION_STATES.FIRING }, - { state: ACTION_STATES.THROTTLED }, - { state: ACTION_STATES.ACKNOWLEDGED }, - { state: ACTION_STATES.ERROR }, - ]; - - expect(watchStatus.state).toBe(WATCH_STATES.DISABLED); - }); - }); - - describe('downstreamJson getter method', () => { - let upstreamJson; - beforeEach(() => { - upstreamJson = { - id: 'my-watch', - watchStatusJson: { - state: { - active: true, - }, - last_checked: '2017-03-02T14:25:31.139Z', - last_met_condition: '2017-07-05T14:25:31.139Z', - actions: { - foo: {}, - bar: {}, - }, - }, - }; - }); - - it('returns correct downstream JSON object', () => { - const watchStatus = WatchStatus.fromUpstreamJson(upstreamJson); - watchStatus.actionStatuses = [ - { id: 'foo', state: ACTION_STATES.OK }, - { id: 'bar', state: ACTION_STATES.OK }, - ]; - - const actual = watchStatus.downstreamJson; - - expect(actual.id).toBe(watchStatus.id); - expect(actual.state).toBe(watchStatus.state); - expect(actual.comment).toBe(watchStatus.comment); - expect(actual.isActive).toBe(watchStatus.isActive); - expect(actual.lastChecked).toBe(watchStatus.lastChecked); - expect(actual.lastMetCondition).toBe(watchStatus.lastMetCondition); - expect(actual.lastFired).toBe(watchStatus.lastFired); - expect(actual.actionStatuses.length).toBe(2); - }); - }); - }); -}); diff --git a/x-pack/plugins/watcher/server/models/action_status/index.js b/x-pack/plugins/watcher/server/models/watch_status_model/index.js similarity index 81% rename from x-pack/plugins/watcher/server/models/action_status/index.js rename to x-pack/plugins/watcher/server/models/watch_status_model/index.js index 6078ffd5323e7f..8c5b9e305794bf 100644 --- a/x-pack/plugins/watcher/server/models/action_status/index.js +++ b/x-pack/plugins/watcher/server/models/watch_status_model/index.js @@ -5,4 +5,4 @@ * 2.0. */ -export { ActionStatus } from './action_status'; +export { WatchStatusModel } from './watch_status_model'; diff --git a/x-pack/plugins/watcher/server/models/watch_status/watch_status.js b/x-pack/plugins/watcher/server/models/watch_status_model/watch_status_model.js similarity index 96% rename from x-pack/plugins/watcher/server/models/watch_status/watch_status.js rename to x-pack/plugins/watcher/server/models/watch_status_model/watch_status_model.js index 312b7ff11915e3..c0b38c429a1f6a 100644 --- a/x-pack/plugins/watcher/server/models/watch_status/watch_status.js +++ b/x-pack/plugins/watcher/server/models/watch_status_model/watch_status_model.js @@ -7,11 +7,12 @@ import { get, map, forEach, maxBy } from 'lodash'; import { badRequest } from '@hapi/boom'; -import { getMoment } from '../../../common/lib/get_moment'; -import { ActionStatus } from '../action_status'; -import { ACTION_STATES, WATCH_STATES, WATCH_STATE_COMMENTS } from '../../../common/constants'; import { i18n } from '@kbn/i18n'; +import { ACTION_STATES, WATCH_STATES, WATCH_STATE_COMMENTS } from '../../../common/constants'; +import { getMoment } from '../../../common/lib/get_moment'; +import { ActionStatusModel } from '../action_status_model'; + function getActionStatusTotals(watchStatus) { const result = {}; @@ -27,7 +28,7 @@ function getActionStatusTotals(watchStatus) { const WATCH_STATE_FAILED = 'failed'; -export class WatchStatus { +export class WatchStatusModel { constructor(props) { this.id = props.id; this.watchState = props.state; @@ -46,7 +47,7 @@ export class WatchStatus { errors: this.watchErrors.actions && this.watchErrors.actions[id], lastCheckedRawFormat: get(this.watchStatusJson, 'last_checked'), }; - return ActionStatus.fromUpstreamJson(json); + return ActionStatusModel.fromUpstreamJson(json); }); } @@ -168,7 +169,7 @@ export class WatchStatus { ); } - return new WatchStatus(json); + return new WatchStatusModel(json); } /* diff --git a/x-pack/plugins/watcher/server/models/watch_status_model/watch_status_model.test.js b/x-pack/plugins/watcher/server/models/watch_status_model/watch_status_model.test.js new file mode 100644 index 00000000000000..5dbb3a58d27408 --- /dev/null +++ b/x-pack/plugins/watcher/server/models/watch_status_model/watch_status_model.test.js @@ -0,0 +1,313 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import moment from 'moment'; + +import { ACTION_STATES, WATCH_STATES, WATCH_STATE_COMMENTS } from '../../../common/constants'; +import { WatchStatusModel } from './watch_status_model'; + +describe('WatchStatusModel', () => { + describe('fromUpstreamJson factory method', () => { + let upstreamJson; + beforeEach(() => { + upstreamJson = { + id: 'my-watch', + watchStatusJson: { + state: { + active: true, + }, + last_checked: '2017-03-02T14:25:31.139Z', + last_met_condition: '2017-07-05T14:25:31.139Z', + actions: { + foo: {}, + bar: {}, + }, + }, + }; + }); + + it(`throws an error if no 'id' property in json`, () => { + delete upstreamJson.id; + expect(() => { + WatchStatusModel.fromUpstreamJson(upstreamJson); + }).toThrow(/must contain an id property/i); + }); + + it(`throws an error if no 'watchStatusJson' property in json`, () => { + delete upstreamJson.watchStatusJson; + expect(() => { + WatchStatusModel.fromUpstreamJson(upstreamJson); + }).toThrow(/must contain a watchStatusJson property/i); + }); + + it('returns correct WatchStatus instance', () => { + const watchStatus = WatchStatusModel.fromUpstreamJson(upstreamJson); + + expect(watchStatus.id).toBe(upstreamJson.id); + expect(watchStatus.watchStatusJson).toEqual(upstreamJson.watchStatusJson); + expect(watchStatus.isActive).toEqual(true); + expect(watchStatus.lastChecked).toEqual(moment(upstreamJson.watchStatusJson.last_checked)); + expect(watchStatus.lastMetCondition).toEqual( + moment(upstreamJson.watchStatusJson.last_met_condition) + ); + expect(watchStatus.actionStatuses.length).toBe(2); + + expect(watchStatus.actionStatuses[0].constructor.name).toBe('ActionStatusModel'); + expect(watchStatus.actionStatuses[1].constructor.name).toBe('ActionStatusModel'); + }); + }); + + describe('lastFired getter method', () => { + let upstreamJson; + beforeEach(() => { + upstreamJson = { + id: 'my-watch', + watchStatusJson: { + actions: { + foo: { + last_execution: { + timestamp: '2017-07-05T00:00:00.000Z', + }, + }, + bar: { + last_execution: { + timestamp: '2025-07-05T00:00:00.000Z', + }, + }, + baz: {}, + }, + }, + }; + }); + + it(`returns the latest lastExecution from it's actions`, () => { + const watchStatus = WatchStatusModel.fromUpstreamJson(upstreamJson); + expect(watchStatus.lastFired).toEqual( + moment(upstreamJson.watchStatusJson.actions.bar.last_execution.timestamp) + ); + }); + }); + + describe('comment getter method', () => { + let upstreamJson; + beforeEach(() => { + upstreamJson = { + id: 'my-watch', + watchStatusJson: { + state: { + active: true, + }, + }, + }; + }); + + it(`correctly calculates WATCH_STATE_COMMENTS.OK there are no actions`, () => { + const watchStatus = WatchStatusModel.fromUpstreamJson(upstreamJson); + watchStatus.isActive = true; + expect(watchStatus.comment).toBe(WATCH_STATE_COMMENTS.OK); + }); + + it(`correctly calculates WATCH_STATE_COMMENTS.PARTIALLY_THROTTLED`, () => { + const watchStatus = WatchStatusModel.fromUpstreamJson(upstreamJson); + + watchStatus.actionStatuses = [ + { state: ACTION_STATES.THROTTLED }, + { state: ACTION_STATES.FIRING }, + { state: ACTION_STATES.OK }, + ]; + + expect(watchStatus.comment).toBe(WATCH_STATE_COMMENTS.PARTIALLY_THROTTLED); + }); + + it(`correctly calculates WATCH_STATE_COMMENTS.THROTTLED`, () => { + const watchStatus = WatchStatusModel.fromUpstreamJson(upstreamJson); + + watchStatus.actionStatuses = [ + { state: ACTION_STATES.THROTTLED }, + { state: ACTION_STATES.THROTTLED }, + { state: ACTION_STATES.THROTTLED }, + ]; + + expect(watchStatus.comment).toBe(WATCH_STATE_COMMENTS.THROTTLED); + }); + + it(`correctly calculates WATCH_STATE_COMMENTS.PARTIALLY_ACKNOWLEDGED`, () => { + const watchStatus = WatchStatusModel.fromUpstreamJson(upstreamJson); + + watchStatus.actionStatuses = [ + { state: ACTION_STATES.ACKNOWLEDGED }, + { state: ACTION_STATES.OK }, + { state: ACTION_STATES.THROTTLED }, + { state: ACTION_STATES.FIRING }, + ]; + + expect(watchStatus.comment).toBe(WATCH_STATE_COMMENTS.PARTIALLY_ACKNOWLEDGED); + }); + + it(`correctly calculates WATCH_STATE_COMMENTS.ACKNOWLEDGED`, () => { + const watchStatus = WatchStatusModel.fromUpstreamJson(upstreamJson); + + watchStatus.actionStatuses = [ + { state: ACTION_STATES.ACKNOWLEDGED }, + { state: ACTION_STATES.ACKNOWLEDGED }, + { state: ACTION_STATES.ACKNOWLEDGED }, + ]; + + expect(watchStatus.comment).toBe(WATCH_STATE_COMMENTS.ACKNOWLEDGED); + }); + + it(`correctly calculates WATCH_STATE_COMMENTS.FAILING`, () => { + const watchStatus = WatchStatusModel.fromUpstreamJson(upstreamJson); + + watchStatus.actionStatuses = [ + { state: ACTION_STATES.OK }, + { state: ACTION_STATES.ACKNOWLEDGED }, + { state: ACTION_STATES.THROTTLED }, + { state: ACTION_STATES.FIRING }, + { state: ACTION_STATES.ERROR }, + ]; + + expect(watchStatus.comment).toBe(WATCH_STATE_COMMENTS.FAILING); + }); + + it(`correctly calculates WATCH_STATE_COMMENTS.OK when watch is inactive`, () => { + const watchStatus = WatchStatusModel.fromUpstreamJson(upstreamJson); + watchStatus.isActive = false; + + watchStatus.actionStatuses = [ + { state: ACTION_STATES.OK }, + { state: ACTION_STATES.ACKNOWLEDGED }, + { state: ACTION_STATES.THROTTLED }, + { state: ACTION_STATES.FIRING }, + { state: ACTION_STATES.ERROR }, + ]; + + expect(watchStatus.comment).toBe(WATCH_STATE_COMMENTS.OK); + }); + }); + + describe('state getter method', () => { + let upstreamJson; + beforeEach(() => { + upstreamJson = { + id: 'my-watch', + watchStatusJson: { + state: { + active: true, + }, + }, + }; + }); + + it(`correctly calculates WATCH_STATES.OK there are no actions`, () => { + const watchStatus = WatchStatusModel.fromUpstreamJson(upstreamJson); + watchStatus.isActive = true; + expect(watchStatus.state).toBe(WATCH_STATES.OK); + }); + + it(`correctly calculates WATCH_STATES.FIRING`, () => { + const watchStatus = WatchStatusModel.fromUpstreamJson(upstreamJson); + + watchStatus.actionStatuses = [{ state: ACTION_STATES.OK }, { state: ACTION_STATES.FIRING }]; + expect(watchStatus.state).toBe(WATCH_STATES.FIRING); + + watchStatus.actionStatuses = [ + { state: ACTION_STATES.OK }, + { state: ACTION_STATES.FIRING }, + { state: ACTION_STATES.THROTTLED }, + ]; + expect(watchStatus.state).toBe(WATCH_STATES.FIRING); + + watchStatus.actionStatuses = [ + { state: ACTION_STATES.OK }, + { state: ACTION_STATES.FIRING }, + { state: ACTION_STATES.THROTTLED }, + { state: ACTION_STATES.ACKNOWLEDGED }, + ]; + expect(watchStatus.state).toBe(WATCH_STATES.FIRING); + }); + + it(`correctly calculates WATCH_STATES.ERROR`, () => { + const watchStatus = WatchStatusModel.fromUpstreamJson(upstreamJson); + + watchStatus.actionStatuses = [ + { state: ACTION_STATES.OK }, + { state: ACTION_STATES.FIRING }, + { state: ACTION_STATES.THROTTLED }, + { state: ACTION_STATES.ACKNOWLEDGED }, + { state: ACTION_STATES.ERROR }, + ]; + + expect(watchStatus.state).toBe(WATCH_STATES.ERROR); + }); + + it('correctly calculates WATCH_STATE.CONFIG_ERROR', () => { + const watchStatus = WatchStatusModel.fromUpstreamJson(upstreamJson); + + watchStatus.actionStatuses = [ + { state: ACTION_STATES.OK }, + { state: ACTION_STATES.CONFIG_ERROR }, + ]; + + expect(watchStatus.state).toBe(WATCH_STATES.CONFIG_ERROR); + }); + + it(`correctly calculates WATCH_STATES.DISABLED when watch is inactive`, () => { + const watchStatus = WatchStatusModel.fromUpstreamJson(upstreamJson); + watchStatus.isActive = false; + + watchStatus.actionStatuses = [ + { state: ACTION_STATES.OK }, + { state: ACTION_STATES.FIRING }, + { state: ACTION_STATES.THROTTLED }, + { state: ACTION_STATES.ACKNOWLEDGED }, + { state: ACTION_STATES.ERROR }, + ]; + + expect(watchStatus.state).toBe(WATCH_STATES.DISABLED); + }); + }); + + describe('downstreamJson getter method', () => { + let upstreamJson; + beforeEach(() => { + upstreamJson = { + id: 'my-watch', + watchStatusJson: { + state: { + active: true, + }, + last_checked: '2017-03-02T14:25:31.139Z', + last_met_condition: '2017-07-05T14:25:31.139Z', + actions: { + foo: {}, + bar: {}, + }, + }, + }; + }); + + it('returns correct downstream JSON object', () => { + const watchStatus = WatchStatusModel.fromUpstreamJson(upstreamJson); + watchStatus.actionStatuses = [ + { id: 'foo', state: ACTION_STATES.OK }, + { id: 'bar', state: ACTION_STATES.OK }, + ]; + + const actual = watchStatus.downstreamJson; + + expect(actual.id).toBe(watchStatus.id); + expect(actual.state).toBe(watchStatus.state); + expect(actual.comment).toBe(watchStatus.comment); + expect(actual.isActive).toBe(watchStatus.isActive); + expect(actual.lastChecked).toBe(watchStatus.lastChecked); + expect(actual.lastMetCondition).toBe(watchStatus.lastMetCondition); + expect(actual.lastFired).toBe(watchStatus.lastFired); + expect(actual.actionStatuses.length).toBe(2); + }); + }); +}); diff --git a/x-pack/plugins/watcher/server/routes/api/watch/action/register_acknowledge_route.ts b/x-pack/plugins/watcher/server/routes/api/watch/action/register_acknowledge_route.ts index 31b6d9ec15995c..2facea38a43179 100644 --- a/x-pack/plugins/watcher/server/routes/api/watch/action/register_acknowledge_route.ts +++ b/x-pack/plugins/watcher/server/routes/api/watch/action/register_acknowledge_route.ts @@ -9,7 +9,7 @@ import { schema } from '@kbn/config-schema'; import { get } from 'lodash'; import { IScopedClusterClient } from '@kbn/core/server'; // @ts-ignore -import { WatchStatus } from '../../../../models/watch_status'; +import { WatchStatusModel } from '../../../../models/watch_status_model'; import { RouteDependencies } from '../../../../types'; const paramsSchema = schema.object({ @@ -48,7 +48,7 @@ export function registerAcknowledgeRoute({ watchStatusJson, }; - const watchStatus = WatchStatus.fromUpstreamJson(json); + const watchStatus = WatchStatusModel.fromUpstreamJson(json); return response.ok({ body: { watchStatus: watchStatus.downstreamJson }, }); diff --git a/x-pack/plugins/watcher/server/routes/api/watch/register_activate_route.ts b/x-pack/plugins/watcher/server/routes/api/watch/register_activate_route.ts index 213567aef26a3a..bde5e1f88a68be 100644 --- a/x-pack/plugins/watcher/server/routes/api/watch/register_activate_route.ts +++ b/x-pack/plugins/watcher/server/routes/api/watch/register_activate_route.ts @@ -10,7 +10,7 @@ import { IScopedClusterClient } from '@kbn/core/server'; import { get } from 'lodash'; import { RouteDependencies } from '../../../types'; // @ts-ignore -import { WatchStatus } from '../../../models/watch_status'; +import { WatchStatusModel } from '../../../models/watch_status_model'; function activateWatch(dataClient: IScopedClusterClient, watchId: string) { return dataClient.asCurrentUser.watcher.activateWatch({ @@ -46,7 +46,7 @@ export function registerActivateRoute({ watchStatusJson, }; - const watchStatus = WatchStatus.fromUpstreamJson(json); + const watchStatus = WatchStatusModel.fromUpstreamJson(json); return response.ok({ body: { watchStatus: watchStatus.downstreamJson, diff --git a/x-pack/plugins/watcher/server/routes/api/watch/register_deactivate_route.ts b/x-pack/plugins/watcher/server/routes/api/watch/register_deactivate_route.ts index 2d929965468b1a..21bb73e2b6067d 100644 --- a/x-pack/plugins/watcher/server/routes/api/watch/register_deactivate_route.ts +++ b/x-pack/plugins/watcher/server/routes/api/watch/register_deactivate_route.ts @@ -10,7 +10,7 @@ import { IScopedClusterClient } from '@kbn/core/server'; import { get } from 'lodash'; import { RouteDependencies } from '../../../types'; // @ts-ignore -import { WatchStatus } from '../../../models/watch_status'; +import { WatchStatusModel } from '../../../models/watch_status_model'; const paramsSchema = schema.object({ watchId: schema.string(), @@ -46,7 +46,7 @@ export function registerDeactivateRoute({ watchStatusJson, }; - const watchStatus = WatchStatus.fromUpstreamJson(json); + const watchStatus = WatchStatusModel.fromUpstreamJson(json); return response.ok({ body: { watchStatus: watchStatus.downstreamJson, From 47dc9878b6f6f06f7afd83e1d122924e49d9d42e Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Mon, 8 Aug 2022 16:33:09 -0700 Subject: [PATCH 6/7] Refactor Watcher UI sections and components for clarity (#137601) * Refactor Watch Status page and its panels for clarity. * Refactor Watch List Page for clarity. * Refactor Simulate Watch Results Flyout for clarity. * Refactor Watch Edit Page for clarity. * Add barrel file for sections and refine tab selection on Watch Status Page. * Update test and test helper files, description names, and variable names to match. --- .../client_integration/helpers/index.ts | 20 ++++---- ...s.ts => watch_create_json_page.helpers.ts} | 4 +- ...=> watch_create_threshold_page.helpers.ts} | 4 +- ....helpers.ts => watch_edit_page.helpers.ts} | 4 +- ....helpers.ts => watch_list_page.helpers.ts} | 4 +- ...elpers.ts => watch_status_page.helpers.ts} | 7 ++- ...test.ts => watch_create_json_page.test.ts} | 6 +-- ...x => watch_create_threshold_page.test.tsx} | 6 +-- ...h_edit.test.ts => watch_edit_page.test.ts} | 6 +-- ...h_list.test.ts => watch_list_page.test.ts} | 6 +-- ...atus.test.ts => watch_status_page.test.ts} | 6 +-- .../watcher/public/application/app.tsx | 12 ++--- .../public/application/sections/index.ts | 10 ++++ .../watch_edit_page/components/index.ts | 10 ++++ .../components/json_watch_edit/index.ts | 0 .../json_watch_edit/json_watch_edit.tsx | 0 .../json_watch_edit/json_watch_edit_form.tsx | 0 .../json_watch_edit_simulate.tsx | 21 ++++---- .../simulate_watch_results_flyout.tsx} | 2 +- .../components/monitoring_watch_edit/index.ts | 0 .../monitoring_watch_edit.tsx | 0 .../components/request_flyout.tsx | 0 .../action_fields/email_action_fields.tsx | 0 .../action_fields/index.ts | 0 .../action_fields/index_action_fields.tsx | 0 .../action_fields/jira_action_fields.tsx | 0 .../action_fields/logging_action_fields.tsx | 0 .../action_fields/pagerduty_action_fields.tsx | 0 .../action_fields/slack_action_fields.tsx | 0 .../action_fields/webhook_action_fields.tsx | 0 .../components/threshold_watch_edit/index.ts | 0 .../threshold_watch_action_accordion.tsx | 0 .../threshold_watch_action_dropdown.tsx | 0 .../threshold_watch_action_panel.tsx | 0 .../threshold_watch_edit.tsx | 0 .../watch_visualization.tsx | 0 .../sections/watch_edit_page/index.ts | 8 ++++ .../watch_context.ts | 0 .../watch_edit_actions.ts | 0 .../watch_edit_page.tsx} | 24 +++++----- .../sections/watch_list_page/index.ts | 8 ++++ .../watch_list_page.tsx} | 16 +++---- .../components/action_statuses_panel.tsx} | 2 +- .../components/execution_history_panel.tsx} | 2 +- .../watch_status_page/components/index.ts | 9 ++++ .../sections/watch_status_page/index.ts | 8 ++++ .../watch_details_context.ts | 0 .../watch_status_page.tsx} | 48 +++++++++---------- 48 files changed, 153 insertions(+), 100 deletions(-) rename x-pack/plugins/watcher/__jest__/client_integration/helpers/{watch_create_json.helpers.ts => watch_create_json_page.helpers.ts} (94%) rename x-pack/plugins/watcher/__jest__/client_integration/helpers/{watch_create_threshold.helpers.ts => watch_create_threshold_page.helpers.ts} (95%) rename x-pack/plugins/watcher/__jest__/client_integration/helpers/{watch_edit.helpers.ts => watch_edit_page.helpers.ts} (92%) rename x-pack/plugins/watcher/__jest__/client_integration/helpers/{watch_list.helpers.ts => watch_list_page.helpers.ts} (95%) rename x-pack/plugins/watcher/__jest__/client_integration/helpers/{watch_status.helpers.ts => watch_status_page.helpers.ts} (95%) rename x-pack/plugins/watcher/__jest__/client_integration/{watch_create_json.test.ts => watch_create_json_page.test.ts} (97%) rename x-pack/plugins/watcher/__jest__/client_integration/{watch_create_threshold.test.tsx => watch_create_threshold_page.test.tsx} (99%) rename x-pack/plugins/watcher/__jest__/client_integration/{watch_edit.test.ts => watch_edit_page.test.ts} (97%) rename x-pack/plugins/watcher/__jest__/client_integration/{watch_list.test.ts => watch_list_page.test.ts} (98%) rename x-pack/plugins/watcher/__jest__/client_integration/{watch_status.test.ts => watch_status_page.test.ts} (98%) create mode 100644 x-pack/plugins/watcher/public/application/sections/index.ts create mode 100644 x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/index.ts rename x-pack/plugins/watcher/public/application/sections/{watch_edit => watch_edit_page}/components/json_watch_edit/index.ts (100%) rename x-pack/plugins/watcher/public/application/sections/{watch_edit => watch_edit_page}/components/json_watch_edit/json_watch_edit.tsx (100%) rename x-pack/plugins/watcher/public/application/sections/{watch_edit => watch_edit_page}/components/json_watch_edit/json_watch_edit_form.tsx (100%) rename x-pack/plugins/watcher/public/application/sections/{watch_edit => watch_edit_page}/components/json_watch_edit/json_watch_edit_simulate.tsx (99%) rename x-pack/plugins/watcher/public/application/sections/{watch_edit/components/json_watch_edit/json_watch_edit_simulate_results.tsx => watch_edit_page/components/json_watch_edit/simulate_watch_results_flyout.tsx} (99%) rename x-pack/plugins/watcher/public/application/sections/{watch_edit => watch_edit_page}/components/monitoring_watch_edit/index.ts (100%) rename x-pack/plugins/watcher/public/application/sections/{watch_edit => watch_edit_page}/components/monitoring_watch_edit/monitoring_watch_edit.tsx (100%) rename x-pack/plugins/watcher/public/application/sections/{watch_edit => watch_edit_page}/components/request_flyout.tsx (100%) rename x-pack/plugins/watcher/public/application/sections/{watch_edit => watch_edit_page}/components/threshold_watch_edit/action_fields/email_action_fields.tsx (100%) rename x-pack/plugins/watcher/public/application/sections/{watch_edit => watch_edit_page}/components/threshold_watch_edit/action_fields/index.ts (100%) rename x-pack/plugins/watcher/public/application/sections/{watch_edit => watch_edit_page}/components/threshold_watch_edit/action_fields/index_action_fields.tsx (100%) rename x-pack/plugins/watcher/public/application/sections/{watch_edit => watch_edit_page}/components/threshold_watch_edit/action_fields/jira_action_fields.tsx (100%) rename x-pack/plugins/watcher/public/application/sections/{watch_edit => watch_edit_page}/components/threshold_watch_edit/action_fields/logging_action_fields.tsx (100%) rename x-pack/plugins/watcher/public/application/sections/{watch_edit => watch_edit_page}/components/threshold_watch_edit/action_fields/pagerduty_action_fields.tsx (100%) rename x-pack/plugins/watcher/public/application/sections/{watch_edit => watch_edit_page}/components/threshold_watch_edit/action_fields/slack_action_fields.tsx (100%) rename x-pack/plugins/watcher/public/application/sections/{watch_edit => watch_edit_page}/components/threshold_watch_edit/action_fields/webhook_action_fields.tsx (100%) rename x-pack/plugins/watcher/public/application/sections/{watch_edit => watch_edit_page}/components/threshold_watch_edit/index.ts (100%) rename x-pack/plugins/watcher/public/application/sections/{watch_edit => watch_edit_page}/components/threshold_watch_edit/threshold_watch_action_accordion.tsx (100%) rename x-pack/plugins/watcher/public/application/sections/{watch_edit => watch_edit_page}/components/threshold_watch_edit/threshold_watch_action_dropdown.tsx (100%) rename x-pack/plugins/watcher/public/application/sections/{watch_edit => watch_edit_page}/components/threshold_watch_edit/threshold_watch_action_panel.tsx (100%) rename x-pack/plugins/watcher/public/application/sections/{watch_edit => watch_edit_page}/components/threshold_watch_edit/threshold_watch_edit.tsx (100%) rename x-pack/plugins/watcher/public/application/sections/{watch_edit => watch_edit_page}/components/threshold_watch_edit/watch_visualization.tsx (100%) create mode 100644 x-pack/plugins/watcher/public/application/sections/watch_edit_page/index.ts rename x-pack/plugins/watcher/public/application/sections/{watch_edit => watch_edit_page}/watch_context.ts (100%) rename x-pack/plugins/watcher/public/application/sections/{watch_edit => watch_edit_page}/watch_edit_actions.ts (100%) rename x-pack/plugins/watcher/public/application/sections/{watch_edit/components/watch_edit.tsx => watch_edit_page/watch_edit_page.tsx} (87%) create mode 100644 x-pack/plugins/watcher/public/application/sections/watch_list_page/index.ts rename x-pack/plugins/watcher/public/application/sections/{watch_list/components/watch_list.tsx => watch_list_page/watch_list_page.tsx} (97%) rename x-pack/plugins/watcher/public/application/sections/{watch_status/components/watch_detail.tsx => watch_status_page/components/action_statuses_panel.tsx} (99%) rename x-pack/plugins/watcher/public/application/sections/{watch_status/components/watch_history.tsx => watch_status_page/components/execution_history_panel.tsx} (99%) create mode 100644 x-pack/plugins/watcher/public/application/sections/watch_status_page/components/index.ts create mode 100644 x-pack/plugins/watcher/public/application/sections/watch_status_page/index.ts rename x-pack/plugins/watcher/public/application/sections/{watch_status => watch_status_page}/watch_details_context.ts (100%) rename x-pack/plugins/watcher/public/application/sections/{watch_status/components/watch_status.tsx => watch_status_page/watch_status_page.tsx} (87%) diff --git a/x-pack/plugins/watcher/__jest__/client_integration/helpers/index.ts b/x-pack/plugins/watcher/__jest__/client_integration/helpers/index.ts index 4fbcb847022e94..eb54a540cb51da 100644 --- a/x-pack/plugins/watcher/__jest__/client_integration/helpers/index.ts +++ b/x-pack/plugins/watcher/__jest__/client_integration/helpers/index.ts @@ -5,20 +5,20 @@ * 2.0. */ -import { setup as watchListSetup } from './watch_list.helpers'; -import { setup as watchStatusSetup } from './watch_status.helpers'; -import { setup as watchCreateJsonSetup } from './watch_create_json.helpers'; -import { setup as watchCreateThresholdSetup } from './watch_create_threshold.helpers'; -import { setup as watchEditSetup } from './watch_edit.helpers'; +import { setup as watchListPageSetup } from './watch_list_page.helpers'; +import { setup as watchStatusPageSetup } from './watch_status_page.helpers'; +import { setup as watchCreateJsonPageSetup } from './watch_create_json_page.helpers'; +import { setup as watchCreateThresholdPageSetup } from './watch_create_threshold_page.helpers'; +import { setup as watchEditPageSetup } from './watch_edit_page.helpers'; export type { TestBed } from '@kbn/test-jest-helpers'; export { getRandomString, findTestSubject } from '@kbn/test-jest-helpers'; export { setupEnvironment } from './setup_environment'; export const pageHelpers = { - watchList: { setup: watchListSetup }, - watchStatus: { setup: watchStatusSetup }, - watchCreateJson: { setup: watchCreateJsonSetup }, - watchCreateThreshold: { setup: watchCreateThresholdSetup }, - watchEdit: { setup: watchEditSetup }, + watchListPage: { setup: watchListPageSetup }, + watchStatusPage: { setup: watchStatusPageSetup }, + watchCreateJsonPage: { setup: watchCreateJsonPageSetup }, + watchCreateThresholdPage: { setup: watchCreateThresholdPageSetup }, + watchEditPage: { setup: watchEditPageSetup }, }; diff --git a/x-pack/plugins/watcher/__jest__/client_integration/helpers/watch_create_json.helpers.ts b/x-pack/plugins/watcher/__jest__/client_integration/helpers/watch_create_json_page.helpers.ts similarity index 94% rename from x-pack/plugins/watcher/__jest__/client_integration/helpers/watch_create_json.helpers.ts rename to x-pack/plugins/watcher/__jest__/client_integration/helpers/watch_create_json_page.helpers.ts index 8af924c807372f..c526ed75beb716 100644 --- a/x-pack/plugins/watcher/__jest__/client_integration/helpers/watch_create_json.helpers.ts +++ b/x-pack/plugins/watcher/__jest__/client_integration/helpers/watch_create_json_page.helpers.ts @@ -8,7 +8,7 @@ import { registerTestBed, TestBed, AsyncTestBedConfig } from '@kbn/test-jest-helpers'; import { HttpSetup } from '@kbn/core/public'; -import { WatchEdit } from '../../../public/application/sections/watch_edit/components/watch_edit'; +import { WatchEditPage } from '../../../public/application/sections/watch_edit_page'; import { registerRouter } from '../../../public/application/lib/navigation'; import { ROUTES, WATCH_TYPES } from '../../../common/constants'; import { WithAppDependencies } from './setup_environment'; @@ -31,7 +31,7 @@ export interface WatchCreateJsonTestBed extends TestBed => { - const initTestBed = registerTestBed(WithAppDependencies(WatchEdit, httpSetup), testBedConfig); + const initTestBed = registerTestBed(WithAppDependencies(WatchEditPage, httpSetup), testBedConfig); const testBed = await initTestBed(); /** diff --git a/x-pack/plugins/watcher/__jest__/client_integration/helpers/watch_create_threshold.helpers.ts b/x-pack/plugins/watcher/__jest__/client_integration/helpers/watch_create_threshold_page.helpers.ts similarity index 95% rename from x-pack/plugins/watcher/__jest__/client_integration/helpers/watch_create_threshold.helpers.ts rename to x-pack/plugins/watcher/__jest__/client_integration/helpers/watch_create_threshold_page.helpers.ts index a4b7cce96ae03a..d2bb49a8611673 100644 --- a/x-pack/plugins/watcher/__jest__/client_integration/helpers/watch_create_threshold.helpers.ts +++ b/x-pack/plugins/watcher/__jest__/client_integration/helpers/watch_create_threshold_page.helpers.ts @@ -8,7 +8,7 @@ import { registerTestBed, TestBed, AsyncTestBedConfig } from '@kbn/test-jest-helpers'; import { HttpSetup } from '@kbn/core/public'; -import { WatchEdit } from '../../../public/application/sections/watch_edit/components/watch_edit'; +import { WatchEditPage } from '../../../public/application/sections/watch_edit_page'; import { registerRouter } from '../../../public/application/lib/navigation'; import { ROUTES, WATCH_TYPES } from '../../../common/constants'; import { WithAppDependencies } from './setup_environment'; @@ -34,7 +34,7 @@ export interface WatchCreateThresholdTestBed extends TestBed => { - const initTestBed = registerTestBed(WithAppDependencies(WatchEdit, httpSetup), testBedConfig); + const initTestBed = registerTestBed(WithAppDependencies(WatchEditPage, httpSetup), testBedConfig); const testBed = await initTestBed(); /** diff --git a/x-pack/plugins/watcher/__jest__/client_integration/helpers/watch_edit.helpers.ts b/x-pack/plugins/watcher/__jest__/client_integration/helpers/watch_edit_page.helpers.ts similarity index 92% rename from x-pack/plugins/watcher/__jest__/client_integration/helpers/watch_edit.helpers.ts rename to x-pack/plugins/watcher/__jest__/client_integration/helpers/watch_edit_page.helpers.ts index 22fc71c8d46365..cbda9eb293a70e 100644 --- a/x-pack/plugins/watcher/__jest__/client_integration/helpers/watch_edit.helpers.ts +++ b/x-pack/plugins/watcher/__jest__/client_integration/helpers/watch_edit_page.helpers.ts @@ -8,7 +8,7 @@ import { registerTestBed, TestBed, AsyncTestBedConfig } from '@kbn/test-jest-helpers'; import { HttpSetup } from '@kbn/core/public'; -import { WatchEdit } from '../../../public/application/sections/watch_edit/components/watch_edit'; +import { WatchEditPage } from '../../../public/application/sections/watch_edit_page'; import { registerRouter } from '../../../public/application/lib/navigation'; import { ROUTES } from '../../../common/constants'; import { WATCH_ID } from './jest_constants'; @@ -30,7 +30,7 @@ export interface WatchEditTestBed extends TestBed { } export const setup = async (httpSetup: HttpSetup): Promise => { - const initTestBed = registerTestBed(WithAppDependencies(WatchEdit, httpSetup), testBedConfig); + const initTestBed = registerTestBed(WithAppDependencies(WatchEditPage, httpSetup), testBedConfig); const testBed = await initTestBed(); /** diff --git a/x-pack/plugins/watcher/__jest__/client_integration/helpers/watch_list.helpers.ts b/x-pack/plugins/watcher/__jest__/client_integration/helpers/watch_list_page.helpers.ts similarity index 95% rename from x-pack/plugins/watcher/__jest__/client_integration/helpers/watch_list.helpers.ts rename to x-pack/plugins/watcher/__jest__/client_integration/helpers/watch_list_page.helpers.ts index 1da9ad7f231569..fad3898d4e6050 100644 --- a/x-pack/plugins/watcher/__jest__/client_integration/helpers/watch_list.helpers.ts +++ b/x-pack/plugins/watcher/__jest__/client_integration/helpers/watch_list_page.helpers.ts @@ -14,7 +14,7 @@ import { AsyncTestBedConfig, } from '@kbn/test-jest-helpers'; import { HttpSetup } from '@kbn/core/public'; -import { WatchList } from '../../../public/application/sections/watch_list/components/watch_list'; +import { WatchListPage } from '../../../public/application/sections/watch_list_page'; import { ROUTES, REFRESH_INTERVALS } from '../../../common/constants'; import { WithAppDependencies } from './setup_environment'; @@ -35,7 +35,7 @@ export interface WatchListTestBed extends TestBed { } export const setup = async (httpSetup: HttpSetup): Promise => { - const initTestBed = registerTestBed(WithAppDependencies(WatchList, httpSetup), testBedConfig); + const initTestBed = registerTestBed(WithAppDependencies(WatchListPage, httpSetup), testBedConfig); const testBed = await initTestBed(); /** diff --git a/x-pack/plugins/watcher/__jest__/client_integration/helpers/watch_status.helpers.ts b/x-pack/plugins/watcher/__jest__/client_integration/helpers/watch_status_page.helpers.ts similarity index 95% rename from x-pack/plugins/watcher/__jest__/client_integration/helpers/watch_status.helpers.ts rename to x-pack/plugins/watcher/__jest__/client_integration/helpers/watch_status_page.helpers.ts index 99e1cf936d1d70..601857ca941f07 100644 --- a/x-pack/plugins/watcher/__jest__/client_integration/helpers/watch_status.helpers.ts +++ b/x-pack/plugins/watcher/__jest__/client_integration/helpers/watch_status_page.helpers.ts @@ -16,7 +16,7 @@ import { import { HttpSetup } from '@kbn/core/public'; import { registerRouter } from '../../../public/application/lib/navigation'; -import { WatchStatus } from '../../../public/application/sections/watch_status/components/watch_status'; +import { WatchStatusPage } from '../../../public/application/sections/watch_status_page'; import { ROUTES } from '../../../common/constants'; import { WATCH_ID } from './jest_constants'; import { WithAppDependencies } from './setup_environment'; @@ -41,7 +41,10 @@ export interface WatchStatusTestBed extends TestBed { } export const setup = async (httpSetup: HttpSetup): Promise => { - const initTestBed = registerTestBed(WithAppDependencies(WatchStatus, httpSetup), testBedConfig); + const initTestBed = registerTestBed( + WithAppDependencies(WatchStatusPage, httpSetup), + testBedConfig + ); const testBed = await initTestBed(); /** diff --git a/x-pack/plugins/watcher/__jest__/client_integration/watch_create_json.test.ts b/x-pack/plugins/watcher/__jest__/client_integration/watch_create_json_page.test.ts similarity index 97% rename from x-pack/plugins/watcher/__jest__/client_integration/watch_create_json.test.ts rename to x-pack/plugins/watcher/__jest__/client_integration/watch_create_json_page.test.ts index fc518bcab882b9..54352e278770b5 100644 --- a/x-pack/plugins/watcher/__jest__/client_integration/watch_create_json.test.ts +++ b/x-pack/plugins/watcher/__jest__/client_integration/watch_create_json_page.test.ts @@ -11,12 +11,12 @@ import { getExecuteDetails } from '../../__fixtures__'; import { API_BASE_PATH } from '../../common/constants'; import { defaultWatch } from '../../public/application/models/watch'; import { setupEnvironment, pageHelpers } from './helpers'; -import { WatchCreateJsonTestBed } from './helpers/watch_create_json.helpers'; +import type { WatchCreateJsonTestBed } from './helpers/watch_create_json_page.helpers'; import { WATCH } from './helpers/jest_constants'; -const { setup } = pageHelpers.watchCreateJson; +const { setup } = pageHelpers.watchCreateJsonPage; -describe(' create route', () => { +describe(' create route', () => { const { httpSetup, httpRequestsMockHelpers } = setupEnvironment(); let testBed: WatchCreateJsonTestBed; diff --git a/x-pack/plugins/watcher/__jest__/client_integration/watch_create_threshold.test.tsx b/x-pack/plugins/watcher/__jest__/client_integration/watch_create_threshold_page.test.tsx similarity index 99% rename from x-pack/plugins/watcher/__jest__/client_integration/watch_create_threshold.test.tsx rename to x-pack/plugins/watcher/__jest__/client_integration/watch_create_threshold_page.test.tsx index 73b51f0ddbb899..4fe5fb3445da86 100644 --- a/x-pack/plugins/watcher/__jest__/client_integration/watch_create_threshold.test.tsx +++ b/x-pack/plugins/watcher/__jest__/client_integration/watch_create_threshold_page.test.tsx @@ -13,7 +13,7 @@ import { WATCH_ID } from './helpers/jest_constants'; import { getExecuteDetails } from '../../__fixtures__'; import { WATCH_TYPES, API_BASE_PATH } from '../../common/constants'; import { setupEnvironment, pageHelpers } from './helpers'; -import { WatchCreateThresholdTestBed } from './helpers/watch_create_threshold.helpers'; +import type { WatchCreateThresholdTestBed } from './helpers/watch_create_threshold_page.helpers'; const WATCH_NAME = 'my_test_watch'; @@ -77,9 +77,9 @@ jest.mock('@elastic/eui', () => { }; }); -const { setup } = pageHelpers.watchCreateThreshold; +const { setup } = pageHelpers.watchCreateThresholdPage; -describe(' create route', () => { +describe(' create route', () => { const { httpSetup, httpRequestsMockHelpers } = setupEnvironment(); let testBed: WatchCreateThresholdTestBed; diff --git a/x-pack/plugins/watcher/__jest__/client_integration/watch_edit.test.ts b/x-pack/plugins/watcher/__jest__/client_integration/watch_edit_page.test.ts similarity index 97% rename from x-pack/plugins/watcher/__jest__/client_integration/watch_edit.test.ts rename to x-pack/plugins/watcher/__jest__/client_integration/watch_edit_page.test.ts index 8b0ee0189695bf..f57dcb6788fe1c 100644 --- a/x-pack/plugins/watcher/__jest__/client_integration/watch_edit.test.ts +++ b/x-pack/plugins/watcher/__jest__/client_integration/watch_edit_page.test.ts @@ -10,13 +10,13 @@ import { act } from 'react-dom/test-utils'; import { getWatch } from '../../__fixtures__'; import { defaultWatch } from '../../public/application/models/watch'; import { setupEnvironment, pageHelpers } from './helpers'; -import { WatchEditTestBed } from './helpers/watch_edit.helpers'; +import type { WatchEditTestBed } from './helpers/watch_edit_page.helpers'; import { WATCH, WATCH_ID } from './helpers/jest_constants'; import { API_BASE_PATH } from '../../common/constants'; -const { setup } = pageHelpers.watchEdit; +const { setup } = pageHelpers.watchEditPage; -describe('', () => { +describe('', () => { const { httpSetup, httpRequestsMockHelpers } = setupEnvironment(); let testBed: WatchEditTestBed; diff --git a/x-pack/plugins/watcher/__jest__/client_integration/watch_list.test.ts b/x-pack/plugins/watcher/__jest__/client_integration/watch_list_page.test.ts similarity index 98% rename from x-pack/plugins/watcher/__jest__/client_integration/watch_list.test.ts rename to x-pack/plugins/watcher/__jest__/client_integration/watch_list_page.test.ts index ac1e7291b187ab..3dda2d81b38004 100644 --- a/x-pack/plugins/watcher/__jest__/client_integration/watch_list.test.ts +++ b/x-pack/plugins/watcher/__jest__/client_integration/watch_list_page.test.ts @@ -8,12 +8,12 @@ import { act } from 'react-dom/test-utils'; import * as fixtures from '../../__fixtures__'; import { setupEnvironment, pageHelpers, getRandomString, findTestSubject } from './helpers'; -import { WatchListTestBed } from './helpers/watch_list.helpers'; +import type { WatchListTestBed } from './helpers/watch_list_page.helpers'; import { API_BASE_PATH } from '../../common/constants'; -const { setup } = pageHelpers.watchList; +const { setup } = pageHelpers.watchListPage; -describe('', () => { +describe('', () => { const { httpSetup, httpRequestsMockHelpers } = setupEnvironment(); let testBed: WatchListTestBed; diff --git a/x-pack/plugins/watcher/__jest__/client_integration/watch_status.test.ts b/x-pack/plugins/watcher/__jest__/client_integration/watch_status_page.test.ts similarity index 98% rename from x-pack/plugins/watcher/__jest__/client_integration/watch_status.test.ts rename to x-pack/plugins/watcher/__jest__/client_integration/watch_status_page.test.ts index 901ebf156911f3..bc7784f912fc12 100644 --- a/x-pack/plugins/watcher/__jest__/client_integration/watch_status.test.ts +++ b/x-pack/plugins/watcher/__jest__/client_integration/watch_status_page.test.ts @@ -10,11 +10,11 @@ import moment from 'moment'; import { getWatchHistory } from '../../__fixtures__'; import { WATCH_STATES, ACTION_STATES } from '../../common/constants'; import { setupEnvironment, pageHelpers } from './helpers'; -import { WatchStatusTestBed } from './helpers/watch_status.helpers'; +import type { WatchStatusTestBed } from './helpers/watch_status_page.helpers'; import { WATCH, WATCH_ID } from './helpers/jest_constants'; import { API_BASE_PATH } from '../../common/constants'; -const { setup } = pageHelpers.watchStatus; +const { setup } = pageHelpers.watchStatusPage; const watchHistory1 = getWatchHistory({ startTime: '2019-06-04T01:11:11.294' }); const watchHistory2 = getWatchHistory({ startTime: '2019-06-04T01:10:10.987Z' }); @@ -38,7 +38,7 @@ const watch = { }, }; -describe('', () => { +describe('', () => { const { httpSetup, httpRequestsMockHelpers } = setupEnvironment(); let testBed: WatchStatusTestBed; diff --git a/x-pack/plugins/watcher/public/application/app.tsx b/x-pack/plugins/watcher/public/application/app.tsx index ab7f1df69f3b7f..36371efc98383e 100644 --- a/x-pack/plugins/watcher/public/application/app.tsx +++ b/x-pack/plugins/watcher/public/application/app.tsx @@ -26,9 +26,7 @@ import { RegisterManagementAppArgs, ManagementAppMountParams } from '@kbn/manage import { ChartsPluginSetup } from '@kbn/charts-plugin/public'; import { LicenseStatus } from '../../common/types/license_status'; -import { WatchStatus } from './sections/watch_status/components/watch_status'; -import { WatchEdit } from './sections/watch_edit/components/watch_edit'; -import { WatchList } from './sections/watch_list/components/watch_list'; +import { WatchListPage, WatchEditPage, WatchStatusPage } from './sections'; import { registerRouter } from './lib/navigation'; import { AppContextProvider } from './app_context'; import { useExecutionContext } from './shared_imports'; @@ -107,10 +105,10 @@ export const App = (deps: AppDeps) => { // Export this so we can test it with a different router. export const AppWithoutRouter = () => ( - - - - + + + + diff --git a/x-pack/plugins/watcher/public/application/sections/index.ts b/x-pack/plugins/watcher/public/application/sections/index.ts new file mode 100644 index 00000000000000..abea90ac6b5a09 --- /dev/null +++ b/x-pack/plugins/watcher/public/application/sections/index.ts @@ -0,0 +1,10 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +export { WatchStatusPage } from './watch_status_page'; +export { WatchEditPage } from './watch_edit_page'; +export { WatchListPage } from './watch_list_page'; diff --git a/x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/index.ts b/x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/index.ts new file mode 100644 index 00000000000000..b8267592014fb9 --- /dev/null +++ b/x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/index.ts @@ -0,0 +1,10 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +export { JsonWatchEdit } from './json_watch_edit'; +export { MonitoringWatchEdit } from './monitoring_watch_edit'; +export { ThresholdWatchEdit } from './threshold_watch_edit'; diff --git a/x-pack/plugins/watcher/public/application/sections/watch_edit/components/json_watch_edit/index.ts b/x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/json_watch_edit/index.ts similarity index 100% rename from x-pack/plugins/watcher/public/application/sections/watch_edit/components/json_watch_edit/index.ts rename to x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/json_watch_edit/index.ts diff --git a/x-pack/plugins/watcher/public/application/sections/watch_edit/components/json_watch_edit/json_watch_edit.tsx b/x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/json_watch_edit/json_watch_edit.tsx similarity index 100% rename from x-pack/plugins/watcher/public/application/sections/watch_edit/components/json_watch_edit/json_watch_edit.tsx rename to x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/json_watch_edit/json_watch_edit.tsx diff --git a/x-pack/plugins/watcher/public/application/sections/watch_edit/components/json_watch_edit/json_watch_edit_form.tsx b/x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/json_watch_edit/json_watch_edit_form.tsx similarity index 100% rename from x-pack/plugins/watcher/public/application/sections/watch_edit/components/json_watch_edit/json_watch_edit_form.tsx rename to x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/json_watch_edit/json_watch_edit_form.tsx diff --git a/x-pack/plugins/watcher/public/application/sections/watch_edit/components/json_watch_edit/json_watch_edit_simulate.tsx b/x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/json_watch_edit/json_watch_edit_simulate.tsx similarity index 99% rename from x-pack/plugins/watcher/public/application/sections/watch_edit/components/json_watch_edit/json_watch_edit_simulate.tsx rename to x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/json_watch_edit/json_watch_edit_simulate.tsx index 788d374df4aba5..9e2fa3f35b50f6 100644 --- a/x-pack/plugins/watcher/public/application/sections/watch_edit/components/json_watch_edit/json_watch_edit_simulate.tsx +++ b/x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/json_watch_edit/json_watch_edit_simulate.tsx @@ -39,7 +39,7 @@ import { import { ErrableFormRow } from '../../../../components'; import { executeWatch } from '../../../../lib/api'; import { WatchContext } from '../../watch_context'; -import { JsonWatchEditSimulateResults } from './json_watch_edit_simulate_results'; +import { SimulateWatchResultsFlyout } from './simulate_watch_results_flyout'; import { getTimeUnitLabel } from '../../../../lib/get_time_unit_label'; import { useAppContext } from '../../../../app_context'; @@ -150,15 +150,6 @@ export const JsonWatchEditSimulate = ({ return ( - { - setExecuteResults(null); - setExecuteResultsError(null); - }} - />

{i18n.translate('xpack.watcher.sections.watchEdit.simulate.pageDescription', { @@ -429,6 +420,16 @@ export const JsonWatchEditSimulate = ({ })} + + { + setExecuteResults(null); + setExecuteResultsError(null); + }} + /> ); }; diff --git a/x-pack/plugins/watcher/public/application/sections/watch_edit/components/json_watch_edit/json_watch_edit_simulate_results.tsx b/x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/json_watch_edit/simulate_watch_results_flyout.tsx similarity index 99% rename from x-pack/plugins/watcher/public/application/sections/watch_edit/components/json_watch_edit/json_watch_edit_simulate_results.tsx rename to x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/json_watch_edit/simulate_watch_results_flyout.tsx index c96070b076e1a2..4383176fb88fcb 100644 --- a/x-pack/plugins/watcher/public/application/sections/watch_edit/components/json_watch_edit/json_watch_edit_simulate_results.tsx +++ b/x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/json_watch_edit/simulate_watch_results_flyout.tsx @@ -27,7 +27,7 @@ import { getTypeFromAction } from '../../watch_edit_actions'; import { WatchContext } from '../../watch_context'; import { WatchStatus, SectionError } from '../../../../components'; -export const JsonWatchEditSimulateResults = ({ +export const SimulateWatchResultsFlyout = ({ executeResults, executeDetails, onCloseFlyout, diff --git a/x-pack/plugins/watcher/public/application/sections/watch_edit/components/monitoring_watch_edit/index.ts b/x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/monitoring_watch_edit/index.ts similarity index 100% rename from x-pack/plugins/watcher/public/application/sections/watch_edit/components/monitoring_watch_edit/index.ts rename to x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/monitoring_watch_edit/index.ts diff --git a/x-pack/plugins/watcher/public/application/sections/watch_edit/components/monitoring_watch_edit/monitoring_watch_edit.tsx b/x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/monitoring_watch_edit/monitoring_watch_edit.tsx similarity index 100% rename from x-pack/plugins/watcher/public/application/sections/watch_edit/components/monitoring_watch_edit/monitoring_watch_edit.tsx rename to x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/monitoring_watch_edit/monitoring_watch_edit.tsx diff --git a/x-pack/plugins/watcher/public/application/sections/watch_edit/components/request_flyout.tsx b/x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/request_flyout.tsx similarity index 100% rename from x-pack/plugins/watcher/public/application/sections/watch_edit/components/request_flyout.tsx rename to x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/request_flyout.tsx diff --git a/x-pack/plugins/watcher/public/application/sections/watch_edit/components/threshold_watch_edit/action_fields/email_action_fields.tsx b/x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/threshold_watch_edit/action_fields/email_action_fields.tsx similarity index 100% rename from x-pack/plugins/watcher/public/application/sections/watch_edit/components/threshold_watch_edit/action_fields/email_action_fields.tsx rename to x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/threshold_watch_edit/action_fields/email_action_fields.tsx diff --git a/x-pack/plugins/watcher/public/application/sections/watch_edit/components/threshold_watch_edit/action_fields/index.ts b/x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/threshold_watch_edit/action_fields/index.ts similarity index 100% rename from x-pack/plugins/watcher/public/application/sections/watch_edit/components/threshold_watch_edit/action_fields/index.ts rename to x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/threshold_watch_edit/action_fields/index.ts diff --git a/x-pack/plugins/watcher/public/application/sections/watch_edit/components/threshold_watch_edit/action_fields/index_action_fields.tsx b/x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/threshold_watch_edit/action_fields/index_action_fields.tsx similarity index 100% rename from x-pack/plugins/watcher/public/application/sections/watch_edit/components/threshold_watch_edit/action_fields/index_action_fields.tsx rename to x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/threshold_watch_edit/action_fields/index_action_fields.tsx diff --git a/x-pack/plugins/watcher/public/application/sections/watch_edit/components/threshold_watch_edit/action_fields/jira_action_fields.tsx b/x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/threshold_watch_edit/action_fields/jira_action_fields.tsx similarity index 100% rename from x-pack/plugins/watcher/public/application/sections/watch_edit/components/threshold_watch_edit/action_fields/jira_action_fields.tsx rename to x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/threshold_watch_edit/action_fields/jira_action_fields.tsx diff --git a/x-pack/plugins/watcher/public/application/sections/watch_edit/components/threshold_watch_edit/action_fields/logging_action_fields.tsx b/x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/threshold_watch_edit/action_fields/logging_action_fields.tsx similarity index 100% rename from x-pack/plugins/watcher/public/application/sections/watch_edit/components/threshold_watch_edit/action_fields/logging_action_fields.tsx rename to x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/threshold_watch_edit/action_fields/logging_action_fields.tsx diff --git a/x-pack/plugins/watcher/public/application/sections/watch_edit/components/threshold_watch_edit/action_fields/pagerduty_action_fields.tsx b/x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/threshold_watch_edit/action_fields/pagerduty_action_fields.tsx similarity index 100% rename from x-pack/plugins/watcher/public/application/sections/watch_edit/components/threshold_watch_edit/action_fields/pagerduty_action_fields.tsx rename to x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/threshold_watch_edit/action_fields/pagerduty_action_fields.tsx diff --git a/x-pack/plugins/watcher/public/application/sections/watch_edit/components/threshold_watch_edit/action_fields/slack_action_fields.tsx b/x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/threshold_watch_edit/action_fields/slack_action_fields.tsx similarity index 100% rename from x-pack/plugins/watcher/public/application/sections/watch_edit/components/threshold_watch_edit/action_fields/slack_action_fields.tsx rename to x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/threshold_watch_edit/action_fields/slack_action_fields.tsx diff --git a/x-pack/plugins/watcher/public/application/sections/watch_edit/components/threshold_watch_edit/action_fields/webhook_action_fields.tsx b/x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/threshold_watch_edit/action_fields/webhook_action_fields.tsx similarity index 100% rename from x-pack/plugins/watcher/public/application/sections/watch_edit/components/threshold_watch_edit/action_fields/webhook_action_fields.tsx rename to x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/threshold_watch_edit/action_fields/webhook_action_fields.tsx diff --git a/x-pack/plugins/watcher/public/application/sections/watch_edit/components/threshold_watch_edit/index.ts b/x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/threshold_watch_edit/index.ts similarity index 100% rename from x-pack/plugins/watcher/public/application/sections/watch_edit/components/threshold_watch_edit/index.ts rename to x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/threshold_watch_edit/index.ts diff --git a/x-pack/plugins/watcher/public/application/sections/watch_edit/components/threshold_watch_edit/threshold_watch_action_accordion.tsx b/x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/threshold_watch_edit/threshold_watch_action_accordion.tsx similarity index 100% rename from x-pack/plugins/watcher/public/application/sections/watch_edit/components/threshold_watch_edit/threshold_watch_action_accordion.tsx rename to x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/threshold_watch_edit/threshold_watch_action_accordion.tsx diff --git a/x-pack/plugins/watcher/public/application/sections/watch_edit/components/threshold_watch_edit/threshold_watch_action_dropdown.tsx b/x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/threshold_watch_edit/threshold_watch_action_dropdown.tsx similarity index 100% rename from x-pack/plugins/watcher/public/application/sections/watch_edit/components/threshold_watch_edit/threshold_watch_action_dropdown.tsx rename to x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/threshold_watch_edit/threshold_watch_action_dropdown.tsx diff --git a/x-pack/plugins/watcher/public/application/sections/watch_edit/components/threshold_watch_edit/threshold_watch_action_panel.tsx b/x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/threshold_watch_edit/threshold_watch_action_panel.tsx similarity index 100% rename from x-pack/plugins/watcher/public/application/sections/watch_edit/components/threshold_watch_edit/threshold_watch_action_panel.tsx rename to x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/threshold_watch_edit/threshold_watch_action_panel.tsx diff --git a/x-pack/plugins/watcher/public/application/sections/watch_edit/components/threshold_watch_edit/threshold_watch_edit.tsx b/x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/threshold_watch_edit/threshold_watch_edit.tsx similarity index 100% rename from x-pack/plugins/watcher/public/application/sections/watch_edit/components/threshold_watch_edit/threshold_watch_edit.tsx rename to x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/threshold_watch_edit/threshold_watch_edit.tsx diff --git a/x-pack/plugins/watcher/public/application/sections/watch_edit/components/threshold_watch_edit/watch_visualization.tsx b/x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/threshold_watch_edit/watch_visualization.tsx similarity index 100% rename from x-pack/plugins/watcher/public/application/sections/watch_edit/components/threshold_watch_edit/watch_visualization.tsx rename to x-pack/plugins/watcher/public/application/sections/watch_edit_page/components/threshold_watch_edit/watch_visualization.tsx diff --git a/x-pack/plugins/watcher/public/application/sections/watch_edit_page/index.ts b/x-pack/plugins/watcher/public/application/sections/watch_edit_page/index.ts new file mode 100644 index 00000000000000..6dd89f80810df3 --- /dev/null +++ b/x-pack/plugins/watcher/public/application/sections/watch_edit_page/index.ts @@ -0,0 +1,8 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +export { WatchEditPage } from './watch_edit_page'; diff --git a/x-pack/plugins/watcher/public/application/sections/watch_edit/watch_context.ts b/x-pack/plugins/watcher/public/application/sections/watch_edit_page/watch_context.ts similarity index 100% rename from x-pack/plugins/watcher/public/application/sections/watch_edit/watch_context.ts rename to x-pack/plugins/watcher/public/application/sections/watch_edit_page/watch_context.ts diff --git a/x-pack/plugins/watcher/public/application/sections/watch_edit/watch_edit_actions.ts b/x-pack/plugins/watcher/public/application/sections/watch_edit_page/watch_edit_actions.ts similarity index 100% rename from x-pack/plugins/watcher/public/application/sections/watch_edit/watch_edit_actions.ts rename to x-pack/plugins/watcher/public/application/sections/watch_edit_page/watch_edit_actions.ts diff --git a/x-pack/plugins/watcher/public/application/sections/watch_edit/components/watch_edit.tsx b/x-pack/plugins/watcher/public/application/sections/watch_edit_page/watch_edit_page.tsx similarity index 87% rename from x-pack/plugins/watcher/public/application/sections/watch_edit/components/watch_edit.tsx rename to x-pack/plugins/watcher/public/application/sections/watch_edit_page/watch_edit_page.tsx index 363060fbfb96c1..75fd085ed72720 100644 --- a/x-pack/plugins/watcher/public/application/sections/watch_edit/components/watch_edit.tsx +++ b/x-pack/plugins/watcher/public/application/sections/watch_edit_page/watch_edit_page.tsx @@ -12,18 +12,16 @@ import { EuiPageContent } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n-react'; -import { WATCH_TYPES } from '../../../../../common/constants'; -import { BaseWatch } from '../../../../../common/types/watch_types'; -import { getPageErrorCode, PageError, SectionLoading } from '../../../components'; -import { loadWatch } from '../../../lib/api'; -import { listBreadcrumb, editBreadcrumb, createBreadcrumb } from '../../../lib/breadcrumbs'; -import { useAppContext } from '../../../app_context'; -import { Watch } from '../../../models/watch'; -import { PageError as GenericPageError } from '../../../shared_imports'; -import { WatchContext } from '../watch_context'; -import { JsonWatchEdit } from './json_watch_edit'; -import { ThresholdWatchEdit } from './threshold_watch_edit'; -import { MonitoringWatchEdit } from './monitoring_watch_edit'; +import { WATCH_TYPES } from '../../../../common/constants'; +import { BaseWatch } from '../../../../common/types/watch_types'; +import { getPageErrorCode, PageError, SectionLoading } from '../../components'; +import { loadWatch } from '../../lib/api'; +import { listBreadcrumb, editBreadcrumb, createBreadcrumb } from '../../lib/breadcrumbs'; +import { useAppContext } from '../../app_context'; +import { Watch } from '../../models/watch'; +import { PageError as GenericPageError } from '../../shared_imports'; +import { WatchContext } from './watch_context'; +import { JsonWatchEdit, ThresholdWatchEdit, MonitoringWatchEdit } from './components'; const getTitle = (watch: BaseWatch) => { if (watch.isNew) { @@ -85,7 +83,7 @@ const watchReducer = (state: any, action: any) => { } }; -export const WatchEdit = ({ +export const WatchEditPage = ({ match: { params: { id, type }, }, diff --git a/x-pack/plugins/watcher/public/application/sections/watch_list_page/index.ts b/x-pack/plugins/watcher/public/application/sections/watch_list_page/index.ts new file mode 100644 index 00000000000000..2301d9428c7953 --- /dev/null +++ b/x-pack/plugins/watcher/public/application/sections/watch_list_page/index.ts @@ -0,0 +1,8 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +export { WatchListPage } from './watch_list_page'; diff --git a/x-pack/plugins/watcher/public/application/sections/watch_list/components/watch_list.tsx b/x-pack/plugins/watcher/public/application/sections/watch_list_page/watch_list_page.tsx similarity index 97% rename from x-pack/plugins/watcher/public/application/sections/watch_list/components/watch_list.tsx rename to x-pack/plugins/watcher/public/application/sections/watch_list_page/watch_list_page.tsx index 542196fb517fbc..19fd1f536125fb 100644 --- a/x-pack/plugins/watcher/public/application/sections/watch_list/components/watch_list.tsx +++ b/x-pack/plugins/watcher/public/application/sections/watch_list_page/watch_list_page.tsx @@ -30,8 +30,8 @@ import { Moment } from 'moment'; import { reactRouterNavigate } from '@kbn/kibana-react-plugin/public'; -import { REFRESH_INTERVALS, PAGINATION, WATCH_TYPES } from '../../../../../common/constants'; -import { listBreadcrumb } from '../../../lib/breadcrumbs'; +import { REFRESH_INTERVALS, PAGINATION, WATCH_TYPES } from '../../../../common/constants'; +import { listBreadcrumb } from '../../lib/breadcrumbs'; import { getPageErrorCode, PageError, @@ -39,13 +39,13 @@ import { WatchStatus, SectionLoading, Error, -} from '../../../components'; -import { useLoadWatches } from '../../../lib/api'; -import { goToCreateThresholdAlert, goToCreateAdvancedWatch } from '../../../lib/navigation'; -import { useAppContext } from '../../../app_context'; -import { PageError as GenericPageError } from '../../../shared_imports'; +} from '../../components'; +import { useLoadWatches } from '../../lib/api'; +import { goToCreateThresholdAlert, goToCreateAdvancedWatch } from '../../lib/navigation'; +import { useAppContext } from '../../app_context'; +import { PageError as GenericPageError } from '../../shared_imports'; -export const WatchList = () => { +export const WatchListPage = () => { // hooks const { setBreadcrumbs, diff --git a/x-pack/plugins/watcher/public/application/sections/watch_status/components/watch_detail.tsx b/x-pack/plugins/watcher/public/application/sections/watch_status_page/components/action_statuses_panel.tsx similarity index 99% rename from x-pack/plugins/watcher/public/application/sections/watch_status/components/watch_detail.tsx rename to x-pack/plugins/watcher/public/application/sections/watch_status_page/components/action_statuses_panel.tsx index 90042ee85ad958..df5ce20f3cdcf4 100644 --- a/x-pack/plugins/watcher/public/application/sections/watch_status/components/watch_detail.tsx +++ b/x-pack/plugins/watcher/public/application/sections/watch_status_page/components/action_statuses_panel.tsx @@ -36,7 +36,7 @@ interface ActionStatus { errors: ActionError[]; } -export const WatchDetail = () => { +export const ActionStatusesPanel = () => { const { toasts } = useAppContext(); const { watchDetail } = useContext(WatchDetailsContext); diff --git a/x-pack/plugins/watcher/public/application/sections/watch_status/components/watch_history.tsx b/x-pack/plugins/watcher/public/application/sections/watch_status_page/components/execution_history_panel.tsx similarity index 99% rename from x-pack/plugins/watcher/public/application/sections/watch_status/components/watch_history.tsx rename to x-pack/plugins/watcher/public/application/sections/watch_status_page/components/execution_history_panel.tsx index ba591b7da5357b..1e618061cce8b7 100644 --- a/x-pack/plugins/watcher/public/application/sections/watch_status/components/watch_history.tsx +++ b/x-pack/plugins/watcher/public/application/sections/watch_status_page/components/execution_history_panel.tsx @@ -68,7 +68,7 @@ const watchHistoryTimeSpanOptions = [ }, ]; -export const WatchHistory = () => { +export const ExecutionHistoryPanel = () => { const { watchDetail: loadedWatch } = useContext(WatchDetailsContext); const [isActivated, setIsActivated] = useState(undefined); diff --git a/x-pack/plugins/watcher/public/application/sections/watch_status_page/components/index.ts b/x-pack/plugins/watcher/public/application/sections/watch_status_page/components/index.ts new file mode 100644 index 00000000000000..8178ac23d94734 --- /dev/null +++ b/x-pack/plugins/watcher/public/application/sections/watch_status_page/components/index.ts @@ -0,0 +1,9 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +export { ActionStatusesPanel } from './action_statuses_panel'; +export { ExecutionHistoryPanel } from './execution_history_panel'; diff --git a/x-pack/plugins/watcher/public/application/sections/watch_status_page/index.ts b/x-pack/plugins/watcher/public/application/sections/watch_status_page/index.ts new file mode 100644 index 00000000000000..7bb821a2bb690d --- /dev/null +++ b/x-pack/plugins/watcher/public/application/sections/watch_status_page/index.ts @@ -0,0 +1,8 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +export { WatchStatusPage } from './watch_status_page'; diff --git a/x-pack/plugins/watcher/public/application/sections/watch_status/watch_details_context.ts b/x-pack/plugins/watcher/public/application/sections/watch_status_page/watch_details_context.ts similarity index 100% rename from x-pack/plugins/watcher/public/application/sections/watch_status/watch_details_context.ts rename to x-pack/plugins/watcher/public/application/sections/watch_status_page/watch_details_context.ts diff --git a/x-pack/plugins/watcher/public/application/sections/watch_status/components/watch_status.tsx b/x-pack/plugins/watcher/public/application/sections/watch_status_page/watch_status_page.tsx similarity index 87% rename from x-pack/plugins/watcher/public/application/sections/watch_status/components/watch_status.tsx rename to x-pack/plugins/watcher/public/application/sections/watch_status_page/watch_status_page.tsx index 0d1c4663ed39fd..e72a2bd82d812f 100644 --- a/x-pack/plugins/watcher/public/application/sections/watch_status/components/watch_status.tsx +++ b/x-pack/plugins/watcher/public/application/sections/watch_status_page/watch_status_page.tsx @@ -16,44 +16,37 @@ import { } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n-react'; -import { WatchDetail } from './watch_detail'; -import { WatchHistory } from './watch_history'; -import { listBreadcrumb, statusBreadcrumb } from '../../../lib/breadcrumbs'; -import { useLoadWatchDetail, deactivateWatch, activateWatch } from '../../../lib/api'; -import { WatchDetailsContext } from '../watch_details_context'; -import { - getPageErrorCode, - PageError, - SectionLoading, - DeleteWatchesModal, -} from '../../../components'; -import { goToWatchList } from '../../../lib/navigation'; -import { useAppContext } from '../../../app_context'; + +import { listBreadcrumb, statusBreadcrumb } from '../../lib/breadcrumbs'; +import { useLoadWatchDetail, deactivateWatch, activateWatch } from '../../lib/api'; +import { goToWatchList } from '../../lib/navigation'; +import { useAppContext } from '../../app_context'; +import { getPageErrorCode, PageError, SectionLoading, DeleteWatchesModal } from '../../components'; + +import { ActionStatusesPanel, ExecutionHistoryPanel } from './components'; +import { WatchDetailsContext } from './watch_details_context'; interface WatchStatusTab { - id: string; + id: 'executionHistoryTab' | 'actionStatusesTab'; name: string; } -const WATCH_EXECUTION_HISTORY_TAB = 'watchExecutionHistoryTab'; -const WATCH_ACTIONS_TAB = 'watchActionsTab'; - -const WATCH_STATUS_TABS: WatchStatusTab[] = [ +const TABS: WatchStatusTab[] = [ { - id: WATCH_EXECUTION_HISTORY_TAB, + id: 'executionHistoryTab', name: i18n.translate('xpack.watcher.sections.watchStatus.executionHistoryTabLabel', { defaultMessage: 'Execution history', }), }, { - id: WATCH_ACTIONS_TAB, + id: 'actionStatusesTab', name: i18n.translate('xpack.watcher.sections.watchStatus.actionsTabLabel', { defaultMessage: 'Action statuses', }), }, ]; -export const WatchStatus = ({ +export const WatchStatusPage = ({ match: { params: { id }, }, @@ -71,7 +64,7 @@ export const WatchStatus = ({ isLoading: isWatchDetailLoading, } = useLoadWatchDetail(id); - const [selectedTab, setSelectedTab] = useState(WATCH_EXECUTION_HISTORY_TAB); + const [selectedTab, setSelectedTab] = useState('executionHistoryTab'); const [isActivated, setIsActivated] = useState(undefined); const [watchesToDelete, setWatchesToDelete] = useState([]); const [isTogglingActivation, setIsTogglingActivation] = useState(false); @@ -152,6 +145,13 @@ export const WatchStatus = ({ setIsActivated(!isActivated); }; + const selectedPanel = + selectedTab === 'executionHistoryTab' ? ( + + ) : selectedTab === 'actionStatusesTab' ? ( + + ) : undefined; + return ( <> @@ -216,7 +216,7 @@ export const WatchStatus = ({ , ] } - tabs={WATCH_STATUS_TABS.map((tab, index) => ({ + tabs={TABS.map((tab, index) => ({ onClick: () => { setSelectedTab(tab.id); }, @@ -229,7 +229,7 @@ export const WatchStatus = ({ - {selectedTab === WATCH_ACTIONS_TAB ? : } + {selectedPanel} { From aa1ce834a62a308f2a506cdc0e58cba7a64eb7d0 Mon Sep 17 00:00:00 2001 From: Najmieh Sadat <98463228+najmiehsa@users.noreply.github.com> Date: Tue, 9 Aug 2022 04:20:05 +0430 Subject: [PATCH 7/7] Modified the kubernetes instruction command (#138306) Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../components/enrollment_instructions/standalone/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/fleet/public/components/enrollment_instructions/standalone/index.tsx b/x-pack/plugins/fleet/public/components/enrollment_instructions/standalone/index.tsx index c40015004db1b6..6994cf2a7ebc2c 100644 --- a/x-pack/plugins/fleet/public/components/enrollment_instructions/standalone/index.tsx +++ b/x-pack/plugins/fleet/public/components/enrollment_instructions/standalone/index.tsx @@ -29,7 +29,7 @@ Expand-Archive .\elastic-agent-${kibanaVersion}-windows-x86_64.zip -DestinationP cd elastic-agent-${kibanaVersion}-windows-x86_64 .\\elastic-agent.exe install`; - const k8sCommand = 'kubectl apply -f elastic-agent-standalone-kubernetes.yaml'; + const k8sCommand = 'kubectl apply -f elastic-agent-standalone-kubernetes.yml'; return { linux: linuxCommand,