From ed5946c5d457fe87b0c000d2aeca6e5007fe2f8c Mon Sep 17 00:00:00 2001 From: Gidi Meir Morris Date: Tue, 3 Mar 2020 12:24:21 +1300 Subject: [PATCH] cleaned up types --- .../alert_navigation_registry.ts | 19 ++---------- .../server/alert_navigation_registry/index.ts | 8 +++++ .../server/alert_navigation_registry/types.ts | 30 +++++++++++++++++++ x-pack/plugins/alerting/server/plugin.ts | 5 +--- .../alerting/server/routes/navigation.ts | 2 +- 5 files changed, 42 insertions(+), 22 deletions(-) create mode 100644 x-pack/plugins/alerting/server/alert_navigation_registry/index.ts create mode 100644 x-pack/plugins/alerting/server/alert_navigation_registry/types.ts diff --git a/x-pack/plugins/alerting/server/alert_navigation_registry/alert_navigation_registry.ts b/x-pack/plugins/alerting/server/alert_navigation_registry/alert_navigation_registry.ts index ba069d8834d3c..70253773f7c17 100644 --- a/x-pack/plugins/alerting/server/alert_navigation_registry/alert_navigation_registry.ts +++ b/x-pack/plugins/alerting/server/alert_navigation_registry/alert_navigation_registry.ts @@ -6,23 +6,8 @@ import Boom from 'boom'; import { i18n } from '@kbn/i18n'; -import { AlertType, SanitizedAlert } from '../types'; -import { AlertInstances } from '../alert_instance/alert_instance'; - -interface AlertNavigationContext { - filter?: string; - dateRange?: { - start: Date; - end: Date; - }; -} - -export type AlertNavigationHandler = ( - alert: SanitizedAlert, - alertType: AlertType, - alertInstances?: AlertInstances[], - context?: AlertNavigationContext -) => Record | string; +import { AlertType } from '../types'; +import { AlertNavigationHandler } from './types'; export class AlertNavigationRegistry { private readonly alertNavigations: Map> = new Map(); diff --git a/x-pack/plugins/alerting/server/alert_navigation_registry/index.ts b/x-pack/plugins/alerting/server/alert_navigation_registry/index.ts new file mode 100644 index 0000000000000..1d8b3ffce6bcf --- /dev/null +++ b/x-pack/plugins/alerting/server/alert_navigation_registry/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; + * you may not use this file except in compliance with the Elastic License. + */ + +export * from './types'; +export * from './alert_navigation_registry'; diff --git a/x-pack/plugins/alerting/server/alert_navigation_registry/types.ts b/x-pack/plugins/alerting/server/alert_navigation_registry/types.ts new file mode 100644 index 0000000000000..e20500c891f4b --- /dev/null +++ b/x-pack/plugins/alerting/server/alert_navigation_registry/types.ts @@ -0,0 +1,30 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import * as t from 'io-ts'; +import { JsonObject } from '../../../infra/common/typed_json'; +import { DateFromString } from '../../common/date_from_string'; +import { AlertType, SanitizedAlert } from '../types'; +import { AlertInstance } from '../alert_instance/alert_instance'; + +const dateRangechema = t.type({ + start: DateFromString, + end: DateFromString, +}); + +export const alertNavigationContextSchema = t.type({ + filter: t.string, + dateRange: dateRangechema, +}); + +export type AlertNavigationContext = t.TypeOf; + +export type AlertNavigationHandler = ( + alert: SanitizedAlert, + alertType: AlertType, + alertInstances?: AlertInstance[], + context?: AlertNavigationContext +) => JsonObject | string; diff --git a/x-pack/plugins/alerting/server/plugin.ts b/x-pack/plugins/alerting/server/plugin.ts index 1b2a8cd805aad..049090d058e50 100644 --- a/x-pack/plugins/alerting/server/plugin.ts +++ b/x-pack/plugins/alerting/server/plugin.ts @@ -51,10 +51,7 @@ import { PluginStartContract as ActionsPluginStartContract, } from '../../../plugins/actions/server'; import { Services } from './types'; -import { - AlertNavigationRegistry, - AlertNavigationHandler, -} from './alert_navigation_registry/alert_navigation_registry'; +import { AlertNavigationRegistry, AlertNavigationHandler } from './alert_navigation_registry'; export interface PluginSetupContract { registerType: AlertTypeRegistry['register']; diff --git a/x-pack/plugins/alerting/server/routes/navigation.ts b/x-pack/plugins/alerting/server/routes/navigation.ts index 5b02b96004b8d..9462a6db9a502 100644 --- a/x-pack/plugins/alerting/server/routes/navigation.ts +++ b/x-pack/plugins/alerting/server/routes/navigation.ts @@ -14,7 +14,7 @@ import { } from 'kibana/server'; import { LicenseState } from '../lib/license_state'; import { verifyApiAccess } from '../lib/license_api_access'; -import { AlertNavigationRegistry } from '../alert_navigation_registry/alert_navigation_registry'; +import { AlertNavigationRegistry } from '../alert_navigation_registry'; import { AlertTypeRegistry } from '../alert_type_registry'; const paramSchema = schema.object({