Skip to content

Commit

Permalink
[nit][pre-req] Strongly-type Shipper and Category (#114412)
Browse files Browse the repository at this point in the history
  • Loading branch information
clintandrewhall authored Oct 12, 2021
1 parent c926b14 commit 243c213
Showing 1 changed file with 54 additions and 7 deletions.
61 changes: 54 additions & 7 deletions src/plugins/custom_integrations/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
export const PLUGIN_ID = 'customIntegrations';
export const PLUGIN_NAME = 'customIntegrations';

export interface IntegrationCategoryCount {
count: number;
id: IntegrationCategory;
}

/**
* A map of category names and their corresponding titles.
*/
// TODO: consider i18n
export const INTEGRATION_CATEGORY_DISPLAY = {
// Known EPR
aws: 'AWS',
azure: 'Azure',
cloud: 'Cloud',
Expand Down Expand Up @@ -49,13 +47,62 @@ export const INTEGRATION_CATEGORY_DISPLAY = {
updates_available: 'Updates available',
};

/**
* A category applicable to an Integration.
*/
export type IntegrationCategory = keyof typeof INTEGRATION_CATEGORY_DISPLAY;

/**
* The list of all available categories.
*/
// This `as` is necessary, as Object.keys cannot be strongly typed.
// see: https://github.com/Microsoft/TypeScript/issues/12870
export const category = Object.keys(INTEGRATION_CATEGORY_DISPLAY) as IntegrationCategory[];

/**
* An object containing the id of an `IntegrationCategory` and the count of all Integrations in that category.
*/
export interface IntegrationCategoryCount {
count: number;
id: IntegrationCategory;
}

/**
* A map of shipper names and their corresponding titles.
*/
// TODO: consider i18n
export const SHIPPER_DISPLAY = {
beats: 'Beats',
language_clients: 'Language clients',
other: 'Other',
sample_data: 'Sample data',
tests: 'Tests',
tutorial: 'Tutorials',
};

/**
* A shipper-- an internal or external system capable of storing data in ES/Kibana-- applicable to an Integration.
*/
export type Shipper = keyof typeof SHIPPER_DISPLAY;

/**
* The list of all known shippers.
*/
// This `as` is necessary, as Object.keys cannot be strongly typed.
// see: https://github.com/Microsoft/TypeScript/issues/12870
export const shipper = Object.keys(SHIPPER_DISPLAY) as Shipper[];

/**
* An icon representing an Integration.
*/
export interface CustomIntegrationIcon {
src: string;
type: 'eui' | 'svg';
}

/**
* A definition of a dataintegration, which can be registered with Kibana.
*/
export interface CustomIntegration {
id: string;
title: string;
Expand All @@ -65,7 +112,7 @@ export interface CustomIntegration {
isBeta: boolean;
icons: CustomIntegrationIcon[];
categories: IntegrationCategory[];
shipper: string;
shipper: Shipper;
eprOverlap?: string; // name of the equivalent Elastic Agent integration in EPR. e.g. a beat module can correspond to an EPR-package, or an APM-tutorial. When completed, Integrations-UX can preferentially show the EPR-package, rather than the custom-integration
}

Expand Down

0 comments on commit 243c213

Please sign in to comment.