Skip to content

Commit

Permalink
cleaned up types
Browse files Browse the repository at this point in the history
  • Loading branch information
gmmorris committed Mar 2, 2020
1 parent 62036f3 commit ed5946c
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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, any> | string;
import { AlertType } from '../types';
import { AlertNavigationHandler } from './types';

export class AlertNavigationRegistry {
private readonly alertNavigations: Map<string, Map<string, AlertNavigationHandler>> = new Map();
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
30 changes: 30 additions & 0 deletions x-pack/plugins/alerting/server/alert_navigation_registry/types.ts
Original file line number Diff line number Diff line change
@@ -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<typeof alertNavigationContextSchema>;

export type AlertNavigationHandler = (
alert: SanitizedAlert,
alertType: AlertType,
alertInstances?: AlertInstance[],
context?: AlertNavigationContext
) => JsonObject | string;
5 changes: 1 addition & 4 deletions x-pack/plugins/alerting/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/alerting/server/routes/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit ed5946c

Please sign in to comment.