diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 82568b47a78098..ba468c5a2d9896 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -52,6 +52,7 @@ /x-pack/test/functional/apps/apm/ @elastic/apm-ui /src/legacy/core_plugins/apm_oss/ @elastic/apm-ui /src/plugins/apm_oss/ @elastic/apm-ui +/src/apm.js @watson # Beats /x-pack/legacy/plugins/beats_management/ @elastic/beats diff --git a/.i18nrc.json b/.i18nrc.json index 907310b32e35cc..f03ced2b85093a 100644 --- a/.i18nrc.json +++ b/.i18nrc.json @@ -32,7 +32,7 @@ "statusPage": "src/legacy/core_plugins/status_page", "telemetry": "src/legacy/core_plugins/telemetry", "tileMap": "src/legacy/core_plugins/tile_map", - "timelion": ["src/legacy/core_plugins/timelion", "src/legacy/core_plugins/vis_type_timelion"], + "timelion": ["src/legacy/core_plugins/timelion", "src/legacy/core_plugins/vis_type_timelion", "src/plugins/timelion"], "uiActions": "src/plugins/ui_actions", "visTypeMarkdown": "src/legacy/core_plugins/vis_type_markdown", "visTypeMetric": "src/legacy/core_plugins/vis_type_metric", diff --git a/docs/development/core/public/kibana-plugin-public.doclinksstart.links.md b/docs/development/core/public/kibana-plugin-public.doclinksstart.links.md index 9e662c543eb56d..2a21f00c57461a 100644 --- a/docs/development/core/public/kibana-plugin-public.doclinksstart.links.md +++ b/docs/development/core/public/kibana-plugin-public.doclinksstart.links.md @@ -91,5 +91,6 @@ readonly links: { readonly date: { readonly dateMath: string; }; + readonly management: Record; }; ``` diff --git a/docs/development/core/public/kibana-plugin-public.doclinksstart.md b/docs/development/core/public/kibana-plugin-public.doclinksstart.md index cefac180d88c5b..13c701a8b47dbd 100644 --- a/docs/development/core/public/kibana-plugin-public.doclinksstart.md +++ b/docs/development/core/public/kibana-plugin-public.doclinksstart.md @@ -17,5 +17,5 @@ export interface DocLinksStart | --- | --- | --- | | [DOC\_LINK\_VERSION](./kibana-plugin-public.doclinksstart.doc_link_version.md) | string | | | [ELASTIC\_WEBSITE\_URL](./kibana-plugin-public.doclinksstart.elastic_website_url.md) | string | | -| [links](./kibana-plugin-public.doclinksstart.links.md) | {
readonly filebeat: {
readonly base: string;
readonly installation: string;
readonly configuration: string;
readonly elasticsearchOutput: string;
readonly startup: string;
readonly exportedFields: string;
};
readonly auditbeat: {
readonly base: string;
};
readonly metricbeat: {
readonly base: string;
};
readonly heartbeat: {
readonly base: string;
};
readonly logstash: {
readonly base: string;
};
readonly functionbeat: {
readonly base: string;
};
readonly winlogbeat: {
readonly base: string;
};
readonly aggs: {
readonly date_histogram: string;
readonly date_range: string;
readonly filter: string;
readonly filters: string;
readonly geohash_grid: string;
readonly histogram: string;
readonly ip_range: string;
readonly range: string;
readonly significant_terms: string;
readonly terms: string;
readonly avg: string;
readonly avg_bucket: string;
readonly max_bucket: string;
readonly min_bucket: string;
readonly sum_bucket: string;
readonly cardinality: string;
readonly count: string;
readonly cumulative_sum: string;
readonly derivative: string;
readonly geo_bounds: string;
readonly geo_centroid: string;
readonly max: string;
readonly median: string;
readonly min: string;
readonly moving_avg: string;
readonly percentile_ranks: string;
readonly serial_diff: string;
readonly std_dev: string;
readonly sum: string;
readonly top_hits: string;
};
readonly scriptedFields: {
readonly scriptFields: string;
readonly scriptAggs: string;
readonly painless: string;
readonly painlessApi: string;
readonly painlessSyntax: string;
readonly luceneExpressions: string;
};
readonly indexPatterns: {
readonly loadingData: string;
readonly introduction: string;
};
readonly kibana: string;
readonly siem: {
readonly guide: string;
readonly gettingStarted: string;
};
readonly query: {
readonly luceneQuerySyntax: string;
readonly queryDsl: string;
readonly kueryQuerySyntax: string;
};
readonly date: {
readonly dateMath: string;
};
} | | +| [links](./kibana-plugin-public.doclinksstart.links.md) | {
readonly filebeat: {
readonly base: string;
readonly installation: string;
readonly configuration: string;
readonly elasticsearchOutput: string;
readonly startup: string;
readonly exportedFields: string;
};
readonly auditbeat: {
readonly base: string;
};
readonly metricbeat: {
readonly base: string;
};
readonly heartbeat: {
readonly base: string;
};
readonly logstash: {
readonly base: string;
};
readonly functionbeat: {
readonly base: string;
};
readonly winlogbeat: {
readonly base: string;
};
readonly aggs: {
readonly date_histogram: string;
readonly date_range: string;
readonly filter: string;
readonly filters: string;
readonly geohash_grid: string;
readonly histogram: string;
readonly ip_range: string;
readonly range: string;
readonly significant_terms: string;
readonly terms: string;
readonly avg: string;
readonly avg_bucket: string;
readonly max_bucket: string;
readonly min_bucket: string;
readonly sum_bucket: string;
readonly cardinality: string;
readonly count: string;
readonly cumulative_sum: string;
readonly derivative: string;
readonly geo_bounds: string;
readonly geo_centroid: string;
readonly max: string;
readonly median: string;
readonly min: string;
readonly moving_avg: string;
readonly percentile_ranks: string;
readonly serial_diff: string;
readonly std_dev: string;
readonly sum: string;
readonly top_hits: string;
};
readonly scriptedFields: {
readonly scriptFields: string;
readonly scriptAggs: string;
readonly painless: string;
readonly painlessApi: string;
readonly painlessSyntax: string;
readonly luceneExpressions: string;
};
readonly indexPatterns: {
readonly loadingData: string;
readonly introduction: string;
};
readonly kibana: string;
readonly siem: {
readonly guide: string;
readonly gettingStarted: string;
};
readonly query: {
readonly luceneQuerySyntax: string;
readonly queryDsl: string;
readonly kueryQuerySyntax: string;
};
readonly date: {
readonly dateMath: string;
};
readonly management: Record<string, string>;
} | | diff --git a/docs/development/core/public/kibana-plugin-public.imagevalidation.maxsize.md b/docs/development/core/public/kibana-plugin-public.imagevalidation.maxsize.md new file mode 100644 index 00000000000000..07c4588ff2c8e0 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.imagevalidation.maxsize.md @@ -0,0 +1,14 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [ImageValidation](./kibana-plugin-public.imagevalidation.md) > [maxSize](./kibana-plugin-public.imagevalidation.maxsize.md) + +## ImageValidation.maxSize property + +Signature: + +```typescript +maxSize: { + length: number; + description: string; + }; +``` diff --git a/docs/development/core/public/kibana-plugin-public.imagevalidation.md b/docs/development/core/public/kibana-plugin-public.imagevalidation.md new file mode 100644 index 00000000000000..783f417d0fb4d0 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.imagevalidation.md @@ -0,0 +1,19 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [ImageValidation](./kibana-plugin-public.imagevalidation.md) + +## ImageValidation interface + + +Signature: + +```typescript +export interface ImageValidation +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [maxSize](./kibana-plugin-public.imagevalidation.maxsize.md) | {
length: number;
description: string;
} | | + diff --git a/docs/development/core/public/kibana-plugin-public.md b/docs/development/core/public/kibana-plugin-public.md index 52aca7501e64dd..ad23bfce4f78c2 100644 --- a/docs/development/core/public/kibana-plugin-public.md +++ b/docs/development/core/public/kibana-plugin-public.md @@ -76,6 +76,7 @@ The plugin integrates with the core system via lifecycle events: `setup` | [IHttpInterceptController](./kibana-plugin-public.ihttpinterceptcontroller.md) | Used to halt a request Promise chain in a [HttpInterceptor](./kibana-plugin-public.httpinterceptor.md). | | [IHttpResponse](./kibana-plugin-public.ihttpresponse.md) | | | [IHttpResponseInterceptorOverrides](./kibana-plugin-public.ihttpresponseinterceptoroverrides.md) | Properties that can be returned by HttpInterceptor.request to override the response. | +| [ImageValidation](./kibana-plugin-public.imagevalidation.md) | | | [IUiSettingsClient](./kibana-plugin-public.iuisettingsclient.md) | Client-side client that provides access to the advanced settings stored in elasticsearch. The settings provide control over the behavior of the Kibana application. For example, a user can specify how to display numeric or date fields. Users can adjust the settings via Management UI. [IUiSettingsClient](./kibana-plugin-public.iuisettingsclient.md) | | [LegacyCoreSetup](./kibana-plugin-public.legacycoresetup.md) | Setup interface exposed to the legacy platform via the ui/new_platform module. | | [LegacyCoreStart](./kibana-plugin-public.legacycorestart.md) | Start interface exposed to the legacy platform via the ui/new_platform module. | @@ -110,7 +111,11 @@ The plugin integrates with the core system via lifecycle events: `setup` | [SavedObjectsMigrationVersion](./kibana-plugin-public.savedobjectsmigrationversion.md) | Information about the migrations that have been applied to this SavedObject. When Kibana starts up, KibanaMigrator detects outdated documents and migrates them based on this value. For each migration that has been applied, the plugin's name is used as a key and the latest migration version as the value. | | [SavedObjectsStart](./kibana-plugin-public.savedobjectsstart.md) | | | [SavedObjectsUpdateOptions](./kibana-plugin-public.savedobjectsupdateoptions.md) | | +| [StringValidationRegex](./kibana-plugin-public.stringvalidationregex.md) | StringValidation with regex object | +| [StringValidationRegexString](./kibana-plugin-public.stringvalidationregexstring.md) | StringValidation as regex string | +| [UiSettingsParams](./kibana-plugin-public.uisettingsparams.md) | UiSettings parameters defined by the plugins. | | [UiSettingsState](./kibana-plugin-public.uisettingsstate.md) | | +| [UserProvidedValues](./kibana-plugin-public.userprovidedvalues.md) | Describes the values explicitly set by user. | ## Type Aliases @@ -144,10 +149,12 @@ The plugin integrates with the core system via lifecycle events: `setup` | [SavedObjectAttribute](./kibana-plugin-public.savedobjectattribute.md) | Type definition for a Saved Object attribute value | | [SavedObjectAttributeSingle](./kibana-plugin-public.savedobjectattributesingle.md) | Don't use this type, it's simply a helper type for [SavedObjectAttribute](./kibana-plugin-public.savedobjectattribute.md) | | [SavedObjectsClientContract](./kibana-plugin-public.savedobjectsclientcontract.md) | SavedObjectsClientContract as implemented by the [SavedObjectsClient](./kibana-plugin-public.savedobjectsclient.md) | +| [StringValidation](./kibana-plugin-public.stringvalidation.md) | Allows regex objects or a regex string | | [Toast](./kibana-plugin-public.toast.md) | | | [ToastInput](./kibana-plugin-public.toastinput.md) | Inputs for [IToasts](./kibana-plugin-public.itoasts.md) APIs. | | [ToastInputFields](./kibana-plugin-public.toastinputfields.md) | Allowed fields for [ToastInput](./kibana-plugin-public.toastinput.md). | | [ToastsSetup](./kibana-plugin-public.toastssetup.md) | [IToasts](./kibana-plugin-public.itoasts.md) | | [ToastsStart](./kibana-plugin-public.toastsstart.md) | [IToasts](./kibana-plugin-public.itoasts.md) | +| [UiSettingsType](./kibana-plugin-public.uisettingstype.md) | UI element type to represent the settings. | | [UnmountCallback](./kibana-plugin-public.unmountcallback.md) | A function that will unmount the element previously mounted by the associated [MountPoint](./kibana-plugin-public.mountpoint.md) | diff --git a/docs/development/core/public/kibana-plugin-public.stringvalidation.md b/docs/development/core/public/kibana-plugin-public.stringvalidation.md new file mode 100644 index 00000000000000..bf01e857d262ae --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.stringvalidation.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [StringValidation](./kibana-plugin-public.stringvalidation.md) + +## StringValidation type + +Allows regex objects or a regex string + +Signature: + +```typescript +export declare type StringValidation = StringValidationRegex | StringValidationRegexString; +``` diff --git a/docs/development/core/public/kibana-plugin-public.stringvalidationregex.md b/docs/development/core/public/kibana-plugin-public.stringvalidationregex.md new file mode 100644 index 00000000000000..a60a7bbf742c85 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.stringvalidationregex.md @@ -0,0 +1,21 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [StringValidationRegex](./kibana-plugin-public.stringvalidationregex.md) + +## StringValidationRegex interface + +StringValidation with regex object + +Signature: + +```typescript +export interface StringValidationRegex +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [message](./kibana-plugin-public.stringvalidationregex.message.md) | string | | +| [regex](./kibana-plugin-public.stringvalidationregex.regex.md) | RegExp | | + diff --git a/docs/development/core/public/kibana-plugin-public.stringvalidationregex.message.md b/docs/development/core/public/kibana-plugin-public.stringvalidationregex.message.md new file mode 100644 index 00000000000000..dae94ae08bde5d --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.stringvalidationregex.message.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [StringValidationRegex](./kibana-plugin-public.stringvalidationregex.md) > [message](./kibana-plugin-public.stringvalidationregex.message.md) + +## StringValidationRegex.message property + +Signature: + +```typescript +message: string; +``` diff --git a/docs/development/core/public/kibana-plugin-public.stringvalidationregex.regex.md b/docs/development/core/public/kibana-plugin-public.stringvalidationregex.regex.md new file mode 100644 index 00000000000000..db7a1fca75aae2 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.stringvalidationregex.regex.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [StringValidationRegex](./kibana-plugin-public.stringvalidationregex.md) > [regex](./kibana-plugin-public.stringvalidationregex.regex.md) + +## StringValidationRegex.regex property + +Signature: + +```typescript +regex: RegExp; +``` diff --git a/docs/development/core/public/kibana-plugin-public.stringvalidationregexstring.md b/docs/development/core/public/kibana-plugin-public.stringvalidationregexstring.md new file mode 100644 index 00000000000000..f64e65122d9d15 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.stringvalidationregexstring.md @@ -0,0 +1,21 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [StringValidationRegexString](./kibana-plugin-public.stringvalidationregexstring.md) + +## StringValidationRegexString interface + +StringValidation as regex string + +Signature: + +```typescript +export interface StringValidationRegexString +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [message](./kibana-plugin-public.stringvalidationregexstring.message.md) | string | | +| [regexString](./kibana-plugin-public.stringvalidationregexstring.regexstring.md) | string | | + diff --git a/docs/development/core/public/kibana-plugin-public.stringvalidationregexstring.message.md b/docs/development/core/public/kibana-plugin-public.stringvalidationregexstring.message.md new file mode 100644 index 00000000000000..6d844e8dd970ff --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.stringvalidationregexstring.message.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [StringValidationRegexString](./kibana-plugin-public.stringvalidationregexstring.md) > [message](./kibana-plugin-public.stringvalidationregexstring.message.md) + +## StringValidationRegexString.message property + +Signature: + +```typescript +message: string; +``` diff --git a/docs/development/core/public/kibana-plugin-public.stringvalidationregexstring.regexstring.md b/docs/development/core/public/kibana-plugin-public.stringvalidationregexstring.regexstring.md new file mode 100644 index 00000000000000..b779f113f3bbc4 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.stringvalidationregexstring.regexstring.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [StringValidationRegexString](./kibana-plugin-public.stringvalidationregexstring.md) > [regexString](./kibana-plugin-public.stringvalidationregexstring.regexstring.md) + +## StringValidationRegexString.regexString property + +Signature: + +```typescript +regexString: string; +``` diff --git a/docs/development/core/public/kibana-plugin-public.uisettingsparams.category.md b/docs/development/core/public/kibana-plugin-public.uisettingsparams.category.md new file mode 100644 index 00000000000000..859b25cab4be8a --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.uisettingsparams.category.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [UiSettingsParams](./kibana-plugin-public.uisettingsparams.md) > [category](./kibana-plugin-public.uisettingsparams.category.md) + +## UiSettingsParams.category property + +used to group the configured setting in the UI + +Signature: + +```typescript +category?: string[]; +``` diff --git a/docs/development/core/public/kibana-plugin-public.uisettingsparams.deprecation.md b/docs/development/core/public/kibana-plugin-public.uisettingsparams.deprecation.md new file mode 100644 index 00000000000000..2364d34bdb8a31 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.uisettingsparams.deprecation.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [UiSettingsParams](./kibana-plugin-public.uisettingsparams.md) > [deprecation](./kibana-plugin-public.uisettingsparams.deprecation.md) + +## UiSettingsParams.deprecation property + +optional deprecation information. Used to generate a deprecation warning. + +Signature: + +```typescript +deprecation?: DeprecationSettings; +``` diff --git a/docs/development/core/public/kibana-plugin-public.uisettingsparams.description.md b/docs/development/core/public/kibana-plugin-public.uisettingsparams.description.md new file mode 100644 index 00000000000000..2707c0a456d961 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.uisettingsparams.description.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [UiSettingsParams](./kibana-plugin-public.uisettingsparams.md) > [description](./kibana-plugin-public.uisettingsparams.description.md) + +## UiSettingsParams.description property + +description provided to a user in UI + +Signature: + +```typescript +description?: string; +``` diff --git a/docs/development/core/public/kibana-plugin-public.uisettingsparams.md b/docs/development/core/public/kibana-plugin-public.uisettingsparams.md new file mode 100644 index 00000000000000..d8a966d3e69bfa --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.uisettingsparams.md @@ -0,0 +1,30 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [UiSettingsParams](./kibana-plugin-public.uisettingsparams.md) + +## UiSettingsParams interface + +UiSettings parameters defined by the plugins. + +Signature: + +```typescript +export interface UiSettingsParams +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [category](./kibana-plugin-public.uisettingsparams.category.md) | string[] | used to group the configured setting in the UI | +| [deprecation](./kibana-plugin-public.uisettingsparams.deprecation.md) | DeprecationSettings | optional deprecation information. Used to generate a deprecation warning. | +| [description](./kibana-plugin-public.uisettingsparams.description.md) | string | description provided to a user in UI | +| [name](./kibana-plugin-public.uisettingsparams.name.md) | string | title in the UI | +| [optionLabels](./kibana-plugin-public.uisettingsparams.optionlabels.md) | Record<string, string> | text labels for 'select' type UI element | +| [options](./kibana-plugin-public.uisettingsparams.options.md) | string[] | array of permitted values for this setting | +| [readonly](./kibana-plugin-public.uisettingsparams.readonly.md) | boolean | a flag indicating that value cannot be changed | +| [requiresPageReload](./kibana-plugin-public.uisettingsparams.requirespagereload.md) | boolean | a flag indicating whether new value applying requires page reloading | +| [type](./kibana-plugin-public.uisettingsparams.type.md) | UiSettingsType | defines a type of UI element [UiSettingsType](./kibana-plugin-public.uisettingstype.md) | +| [validation](./kibana-plugin-public.uisettingsparams.validation.md) | ImageValidation | StringValidation | | +| [value](./kibana-plugin-public.uisettingsparams.value.md) | SavedObjectAttribute | default value to fall back to if a user doesn't provide any | + diff --git a/docs/development/core/public/kibana-plugin-public.uisettingsparams.name.md b/docs/development/core/public/kibana-plugin-public.uisettingsparams.name.md new file mode 100644 index 00000000000000..4397c06c02c3d2 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.uisettingsparams.name.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [UiSettingsParams](./kibana-plugin-public.uisettingsparams.md) > [name](./kibana-plugin-public.uisettingsparams.name.md) + +## UiSettingsParams.name property + +title in the UI + +Signature: + +```typescript +name?: string; +``` diff --git a/docs/development/core/public/kibana-plugin-public.uisettingsparams.optionlabels.md b/docs/development/core/public/kibana-plugin-public.uisettingsparams.optionlabels.md new file mode 100644 index 00000000000000..e6e320ae8b09f6 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.uisettingsparams.optionlabels.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [UiSettingsParams](./kibana-plugin-public.uisettingsparams.md) > [optionLabels](./kibana-plugin-public.uisettingsparams.optionlabels.md) + +## UiSettingsParams.optionLabels property + +text labels for 'select' type UI element + +Signature: + +```typescript +optionLabels?: Record; +``` diff --git a/docs/development/core/public/kibana-plugin-public.uisettingsparams.options.md b/docs/development/core/public/kibana-plugin-public.uisettingsparams.options.md new file mode 100644 index 00000000000000..e1a637281b44ec --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.uisettingsparams.options.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [UiSettingsParams](./kibana-plugin-public.uisettingsparams.md) > [options](./kibana-plugin-public.uisettingsparams.options.md) + +## UiSettingsParams.options property + +array of permitted values for this setting + +Signature: + +```typescript +options?: string[]; +``` diff --git a/docs/development/core/public/kibana-plugin-public.uisettingsparams.readonly.md b/docs/development/core/public/kibana-plugin-public.uisettingsparams.readonly.md new file mode 100644 index 00000000000000..92fcb5eae5232d --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.uisettingsparams.readonly.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [UiSettingsParams](./kibana-plugin-public.uisettingsparams.md) > [readonly](./kibana-plugin-public.uisettingsparams.readonly.md) + +## UiSettingsParams.readonly property + +a flag indicating that value cannot be changed + +Signature: + +```typescript +readonly?: boolean; +``` diff --git a/docs/development/core/public/kibana-plugin-public.uisettingsparams.requirespagereload.md b/docs/development/core/public/kibana-plugin-public.uisettingsparams.requirespagereload.md new file mode 100644 index 00000000000000..7d4994208ff1f4 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.uisettingsparams.requirespagereload.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [UiSettingsParams](./kibana-plugin-public.uisettingsparams.md) > [requiresPageReload](./kibana-plugin-public.uisettingsparams.requirespagereload.md) + +## UiSettingsParams.requiresPageReload property + +a flag indicating whether new value applying requires page reloading + +Signature: + +```typescript +requiresPageReload?: boolean; +``` diff --git a/docs/development/core/public/kibana-plugin-public.uisettingsparams.type.md b/docs/development/core/public/kibana-plugin-public.uisettingsparams.type.md new file mode 100644 index 00000000000000..e75dbce413ecef --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.uisettingsparams.type.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [UiSettingsParams](./kibana-plugin-public.uisettingsparams.md) > [type](./kibana-plugin-public.uisettingsparams.type.md) + +## UiSettingsParams.type property + +defines a type of UI element [UiSettingsType](./kibana-plugin-public.uisettingstype.md) + +Signature: + +```typescript +type?: UiSettingsType; +``` diff --git a/docs/development/core/public/kibana-plugin-public.uisettingsparams.validation.md b/docs/development/core/public/kibana-plugin-public.uisettingsparams.validation.md new file mode 100644 index 00000000000000..21b1de399a332d --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.uisettingsparams.validation.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [UiSettingsParams](./kibana-plugin-public.uisettingsparams.md) > [validation](./kibana-plugin-public.uisettingsparams.validation.md) + +## UiSettingsParams.validation property + +Signature: + +```typescript +validation?: ImageValidation | StringValidation; +``` diff --git a/docs/development/core/public/kibana-plugin-public.uisettingsparams.value.md b/docs/development/core/public/kibana-plugin-public.uisettingsparams.value.md new file mode 100644 index 00000000000000..d489b4567ded0a --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.uisettingsparams.value.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [UiSettingsParams](./kibana-plugin-public.uisettingsparams.md) > [value](./kibana-plugin-public.uisettingsparams.value.md) + +## UiSettingsParams.value property + +default value to fall back to if a user doesn't provide any + +Signature: + +```typescript +value?: SavedObjectAttribute; +``` diff --git a/docs/development/core/public/kibana-plugin-public.uisettingstype.md b/docs/development/core/public/kibana-plugin-public.uisettingstype.md new file mode 100644 index 00000000000000..cb58152bd093e1 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.uisettingstype.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [UiSettingsType](./kibana-plugin-public.uisettingstype.md) + +## UiSettingsType type + +UI element type to represent the settings. + +Signature: + +```typescript +export declare type UiSettingsType = 'undefined' | 'json' | 'markdown' | 'number' | 'select' | 'boolean' | 'string' | 'array' | 'image'; +``` diff --git a/docs/development/core/public/kibana-plugin-public.userprovidedvalues.isoverridden.md b/docs/development/core/public/kibana-plugin-public.userprovidedvalues.isoverridden.md new file mode 100644 index 00000000000000..f62ca61ba91429 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.userprovidedvalues.isoverridden.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [UserProvidedValues](./kibana-plugin-public.userprovidedvalues.md) > [isOverridden](./kibana-plugin-public.userprovidedvalues.isoverridden.md) + +## UserProvidedValues.isOverridden property + +Signature: + +```typescript +isOverridden?: boolean; +``` diff --git a/docs/development/core/public/kibana-plugin-public.userprovidedvalues.md b/docs/development/core/public/kibana-plugin-public.userprovidedvalues.md new file mode 100644 index 00000000000000..481bd36dd0ea69 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.userprovidedvalues.md @@ -0,0 +1,21 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [UserProvidedValues](./kibana-plugin-public.userprovidedvalues.md) + +## UserProvidedValues interface + +Describes the values explicitly set by user. + +Signature: + +```typescript +export interface UserProvidedValues +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [isOverridden](./kibana-plugin-public.userprovidedvalues.isoverridden.md) | boolean | | +| [userValue](./kibana-plugin-public.userprovidedvalues.uservalue.md) | T | | + diff --git a/docs/development/core/public/kibana-plugin-public.userprovidedvalues.uservalue.md b/docs/development/core/public/kibana-plugin-public.userprovidedvalues.uservalue.md new file mode 100644 index 00000000000000..132409ad989b1a --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.userprovidedvalues.uservalue.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [UserProvidedValues](./kibana-plugin-public.userprovidedvalues.md) > [userValue](./kibana-plugin-public.userprovidedvalues.uservalue.md) + +## UserProvidedValues.userValue property + +Signature: + +```typescript +userValue?: T; +``` diff --git a/docs/development/core/server/kibana-plugin-server.imagevalidation.md b/docs/development/core/server/kibana-plugin-server.imagevalidation.md index 8d81a7eae19156..0c3e59cc783f95 100644 --- a/docs/development/core/server/kibana-plugin-server.imagevalidation.md +++ b/docs/development/core/server/kibana-plugin-server.imagevalidation.md @@ -4,6 +4,7 @@ ## ImageValidation interface + Signature: ```typescript diff --git a/docs/development/core/server/kibana-plugin-server.md b/docs/development/core/server/kibana-plugin-server.md deleted file mode 100644 index 15f5329d494c22..00000000000000 --- a/docs/development/core/server/kibana-plugin-server.md +++ /dev/null @@ -1,226 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) - -## kibana-plugin-server package - -The Kibana Core APIs for server-side plugins. - -A plugin requires a `kibana.json` file at it's root directory that follows [the manfiest schema](./kibana-plugin-server.pluginmanifest.md) to define static plugin information required to load the plugin. - -A plugin's `server/index` file must contain a named import, `plugin`, that implements [PluginInitializer](./kibana-plugin-server.plugininitializer.md) which returns an object that implements [Plugin](./kibana-plugin-server.plugin.md). - -The plugin integrates with the core system via lifecycle events: `setup`, `start`, and `stop`. In each lifecycle method, the plugin will receive the corresponding core services available (either [CoreSetup](./kibana-plugin-server.coresetup.md) or [CoreStart](./kibana-plugin-server.corestart.md)) and any interfaces returned by dependency plugins' lifecycle method. Anything returned by the plugin's lifecycle method will be exposed to downstream dependencies when their corresponding lifecycle methods are invoked. - -## Classes - -| Class | Description | -| --- | --- | -| [BasePath](./kibana-plugin-server.basepath.md) | Access or manipulate the Kibana base path | -| [ClusterClient](./kibana-plugin-server.clusterclient.md) | Represents an Elasticsearch cluster API client created by the platform. It allows to call API on behalf of the internal Kibana user and the actual user that is derived from the request headers (via asScoped(...)).See [ClusterClient](./kibana-plugin-server.clusterclient.md). | -| [CspConfig](./kibana-plugin-server.cspconfig.md) | CSP configuration for use in Kibana. | -| [ElasticsearchErrorHelpers](./kibana-plugin-server.elasticsearcherrorhelpers.md) | Helpers for working with errors returned from the Elasticsearch service.Since the internal data of errors are subject to change, consumers of the Elasticsearch service should always use these helpers to classify errors instead of checking error internals such as body.error.header[WWW-Authenticate] | -| [KibanaRequest](./kibana-plugin-server.kibanarequest.md) | Kibana specific abstraction for an incoming request. | -| [RouteValidationError](./kibana-plugin-server.routevalidationerror.md) | Error to return when the validation is not successful. | -| [SavedObjectsClient](./kibana-plugin-server.savedobjectsclient.md) | | -| [SavedObjectsErrorHelpers](./kibana-plugin-server.savedobjectserrorhelpers.md) | | -| [SavedObjectsRepository](./kibana-plugin-server.savedobjectsrepository.md) | | -| [ScopedClusterClient](./kibana-plugin-server.scopedclusterclient.md) | Serves the same purpose as "normal" ClusterClient but exposes additional callAsCurrentUser method that doesn't use credentials of the Kibana internal user (as callAsInternalUser does) to request Elasticsearch API, but rather passes HTTP headers extracted from the current user request to the API.See [ScopedClusterClient](./kibana-plugin-server.scopedclusterclient.md). | - -## Enumerations - -| Enumeration | Description | -| --- | --- | -| [AuthResultType](./kibana-plugin-server.authresulttype.md) | | -| [AuthStatus](./kibana-plugin-server.authstatus.md) | Status indicating an outcome of the authentication. | - -## Interfaces - -| Interface | Description | -| --- | --- | -| [APICaller](./kibana-plugin-server.apicaller.md) | | -| [AssistanceAPIResponse](./kibana-plugin-server.assistanceapiresponse.md) | | -| [AssistantAPIClientParams](./kibana-plugin-server.assistantapiclientparams.md) | | -| [Authenticated](./kibana-plugin-server.authenticated.md) | | -| [AuthResultParams](./kibana-plugin-server.authresultparams.md) | Result of an incoming request authentication. | -| [AuthToolkit](./kibana-plugin-server.authtoolkit.md) | A tool set defining an outcome of Auth interceptor for incoming request. | -| [CallAPIOptions](./kibana-plugin-server.callapioptions.md) | The set of options that defines how API call should be made and result be processed. | -| [Capabilities](./kibana-plugin-server.capabilities.md) | The read-only set of capabilities available for the current UI session. Capabilities are simple key-value pairs of (string, boolean), where the string denotes the capability ID, and the boolean is a flag indicating if the capability is enabled or disabled. | -| [CapabilitiesSetup](./kibana-plugin-server.capabilitiessetup.md) | APIs to manage the [Capabilities](./kibana-plugin-server.capabilities.md) that will be used by the application.Plugins relying on capabilities to toggle some of their features should register them during the setup phase using the registerProvider method.Plugins having the responsibility to restrict capabilities depending on a given context should register their capabilities switcher using the registerSwitcher method.Refers to the methods documentation for complete description and examples. | -| [CapabilitiesStart](./kibana-plugin-server.capabilitiesstart.md) | APIs to access the application [Capabilities](./kibana-plugin-server.capabilities.md). | -| [ConfigDeprecationFactory](./kibana-plugin-server.configdeprecationfactory.md) | Provides helpers to generates the most commonly used [ConfigDeprecation](./kibana-plugin-server.configdeprecation.md) when invoking a [ConfigDeprecationProvider](./kibana-plugin-server.configdeprecationprovider.md).See methods documentation for more detailed examples. | -| [ContextSetup](./kibana-plugin-server.contextsetup.md) | An object that handles registration of context providers and configuring handlers with context. | -| [CoreSetup](./kibana-plugin-server.coresetup.md) | Context passed to the plugins setup method. | -| [CoreStart](./kibana-plugin-server.corestart.md) | Context passed to the plugins start method. | -| [CustomHttpResponseOptions](./kibana-plugin-server.customhttpresponseoptions.md) | HTTP response parameters for a response with adjustable status code. | -| [DeprecationAPIClientParams](./kibana-plugin-server.deprecationapiclientparams.md) | | -| [DeprecationAPIResponse](./kibana-plugin-server.deprecationapiresponse.md) | | -| [DeprecationInfo](./kibana-plugin-server.deprecationinfo.md) | | -| [DeprecationSettings](./kibana-plugin-server.deprecationsettings.md) | UiSettings deprecation field options. | -| [DiscoveredPlugin](./kibana-plugin-server.discoveredplugin.md) | Small container object used to expose information about discovered plugins that may or may not have been started. | -| [ElasticsearchError](./kibana-plugin-server.elasticsearcherror.md) | | -| [ElasticsearchServiceSetup](./kibana-plugin-server.elasticsearchservicesetup.md) | | -| [EnvironmentMode](./kibana-plugin-server.environmentmode.md) | | -| [ErrorHttpResponseOptions](./kibana-plugin-server.errorhttpresponseoptions.md) | HTTP response parameters | -| [FakeRequest](./kibana-plugin-server.fakerequest.md) | Fake request object created manually by Kibana plugins. | -| [HttpResponseOptions](./kibana-plugin-server.httpresponseoptions.md) | HTTP response parameters | -| [HttpServiceSetup](./kibana-plugin-server.httpservicesetup.md) | Kibana HTTP Service provides own abstraction for work with HTTP stack. Plugins don't have direct access to hapi server and its primitives anymore. Moreover, plugins shouldn't rely on the fact that HTTP Service uses one or another library under the hood. This gives the platform flexibility to upgrade or changing our internal HTTP stack without breaking plugins. If the HTTP Service lacks functionality you need, we are happy to discuss and support your needs. | -| [HttpServiceStart](./kibana-plugin-server.httpservicestart.md) | | -| [IContextContainer](./kibana-plugin-server.icontextcontainer.md) | An object that handles registration of context providers and configuring handlers with context. | -| [ICspConfig](./kibana-plugin-server.icspconfig.md) | CSP configuration for use in Kibana. | -| [IKibanaResponse](./kibana-plugin-server.ikibanaresponse.md) | A response data object, expected to returned as a result of [RequestHandler](./kibana-plugin-server.requesthandler.md) execution | -| [IKibanaSocket](./kibana-plugin-server.ikibanasocket.md) | A tiny abstraction for TCP socket. | -| [ImageValidation](./kibana-plugin-server.imagevalidation.md) | | -| [IndexSettingsDeprecationInfo](./kibana-plugin-server.indexsettingsdeprecationinfo.md) | | -| [IRenderOptions](./kibana-plugin-server.irenderoptions.md) | | -| [IRouter](./kibana-plugin-server.irouter.md) | Registers route handlers for specified resource path and method. See [RouteConfig](./kibana-plugin-server.routeconfig.md) and [RequestHandler](./kibana-plugin-server.requesthandler.md) for more information about arguments to route registrations. | -| [IScopedRenderingClient](./kibana-plugin-server.iscopedrenderingclient.md) | | -| [IUiSettingsClient](./kibana-plugin-server.iuisettingsclient.md) | Server-side client that provides access to the advanced settings stored in elasticsearch. The settings provide control over the behavior of the Kibana application. For example, a user can specify how to display numeric or date fields. Users can adjust the settings via Management UI. | -| [KibanaRequestEvents](./kibana-plugin-server.kibanarequestevents.md) | Request events. | -| [KibanaRequestRoute](./kibana-plugin-server.kibanarequestroute.md) | Request specific route information exposed to a handler. | -| [LegacyRequest](./kibana-plugin-server.legacyrequest.md) | | -| [LegacyServiceSetupDeps](./kibana-plugin-server.legacyservicesetupdeps.md) | | -| [LegacyServiceStartDeps](./kibana-plugin-server.legacyservicestartdeps.md) | | -| [Logger](./kibana-plugin-server.logger.md) | Logger exposes all the necessary methods to log any type of information and this is the interface used by the logging consumers including plugins. | -| [LoggerFactory](./kibana-plugin-server.loggerfactory.md) | The single purpose of LoggerFactory interface is to define a way to retrieve a context-based logger instance. | -| [LogMeta](./kibana-plugin-server.logmeta.md) | Contextual metadata | -| [OnPostAuthToolkit](./kibana-plugin-server.onpostauthtoolkit.md) | A tool set defining an outcome of OnPostAuth interceptor for incoming request. | -| [OnPreAuthToolkit](./kibana-plugin-server.onpreauthtoolkit.md) | A tool set defining an outcome of OnPreAuth interceptor for incoming request. | -| [OnPreResponseExtensions](./kibana-plugin-server.onpreresponseextensions.md) | Additional data to extend a response. | -| [OnPreResponseInfo](./kibana-plugin-server.onpreresponseinfo.md) | Response status code. | -| [OnPreResponseToolkit](./kibana-plugin-server.onpreresponsetoolkit.md) | A tool set defining an outcome of OnPreAuth interceptor for incoming request. | -| [PackageInfo](./kibana-plugin-server.packageinfo.md) | | -| [Plugin](./kibana-plugin-server.plugin.md) | The interface that should be returned by a PluginInitializer. | -| [PluginConfigDescriptor](./kibana-plugin-server.pluginconfigdescriptor.md) | Describes a plugin configuration properties. | -| [PluginInitializerContext](./kibana-plugin-server.plugininitializercontext.md) | Context that's available to plugins during initialization stage. | -| [PluginManifest](./kibana-plugin-server.pluginmanifest.md) | Describes the set of required and optional properties plugin can define in its mandatory JSON manifest file. | -| [PluginsServiceSetup](./kibana-plugin-server.pluginsservicesetup.md) | | -| [PluginsServiceStart](./kibana-plugin-server.pluginsservicestart.md) | | -| [RequestHandlerContext](./kibana-plugin-server.requesthandlercontext.md) | Plugin specific context passed to a route handler.Provides the following clients: - [rendering](./kibana-plugin-server.iscopedrenderingclient.md) - Rendering client which uses the data of the incoming request - [savedObjects.client](./kibana-plugin-server.savedobjectsclient.md) - Saved Objects client which uses the credentials of the incoming request - [elasticsearch.dataClient](./kibana-plugin-server.scopedclusterclient.md) - Elasticsearch data client which uses the credentials of the incoming request - [elasticsearch.adminClient](./kibana-plugin-server.scopedclusterclient.md) - Elasticsearch admin client which uses the credentials of the incoming request - [uiSettings.client](./kibana-plugin-server.iuisettingsclient.md) - uiSettings client which uses the credentials of the incoming request | -| [RouteConfig](./kibana-plugin-server.routeconfig.md) | Route specific configuration. | -| [RouteConfigOptions](./kibana-plugin-server.routeconfigoptions.md) | Additional route options. | -| [RouteConfigOptionsBody](./kibana-plugin-server.routeconfigoptionsbody.md) | Additional body options for a route | -| [RouteValidationResultFactory](./kibana-plugin-server.routevalidationresultfactory.md) | Validation result factory to be used in the custom validation function to return the valid data or validation errorsSee [RouteValidationFunction](./kibana-plugin-server.routevalidationfunction.md). | -| [RouteValidatorConfig](./kibana-plugin-server.routevalidatorconfig.md) | The configuration object to the RouteValidator class. Set params, query and/or body to specify the validation logic to follow for that property. | -| [RouteValidatorOptions](./kibana-plugin-server.routevalidatoroptions.md) | Additional options for the RouteValidator class to modify its default behaviour. | -| [SavedObject](./kibana-plugin-server.savedobject.md) | | -| [SavedObjectAttributes](./kibana-plugin-server.savedobjectattributes.md) | The data for a Saved Object is stored as an object in the attributes property. | -| [SavedObjectReference](./kibana-plugin-server.savedobjectreference.md) | A reference to another saved object. | -| [SavedObjectsBaseOptions](./kibana-plugin-server.savedobjectsbaseoptions.md) | | -| [SavedObjectsBulkCreateObject](./kibana-plugin-server.savedobjectsbulkcreateobject.md) | | -| [SavedObjectsBulkGetObject](./kibana-plugin-server.savedobjectsbulkgetobject.md) | | -| [SavedObjectsBulkResponse](./kibana-plugin-server.savedobjectsbulkresponse.md) | | -| [SavedObjectsBulkUpdateObject](./kibana-plugin-server.savedobjectsbulkupdateobject.md) | | -| [SavedObjectsBulkUpdateOptions](./kibana-plugin-server.savedobjectsbulkupdateoptions.md) | | -| [SavedObjectsBulkUpdateResponse](./kibana-plugin-server.savedobjectsbulkupdateresponse.md) | | -| [SavedObjectsClientProviderOptions](./kibana-plugin-server.savedobjectsclientprovideroptions.md) | Options to control the creation of the Saved Objects Client. | -| [SavedObjectsClientWrapperOptions](./kibana-plugin-server.savedobjectsclientwrapperoptions.md) | Options passed to each SavedObjectsClientWrapperFactory to aid in creating the wrapper instance. | -| [SavedObjectsCreateOptions](./kibana-plugin-server.savedobjectscreateoptions.md) | | -| [SavedObjectsDeleteByNamespaceOptions](./kibana-plugin-server.savedobjectsdeletebynamespaceoptions.md) | | -| [SavedObjectsDeleteOptions](./kibana-plugin-server.savedobjectsdeleteoptions.md) | | -| [SavedObjectsExportOptions](./kibana-plugin-server.savedobjectsexportoptions.md) | Options controlling the export operation. | -| [SavedObjectsExportResultDetails](./kibana-plugin-server.savedobjectsexportresultdetails.md) | Structure of the export result details entry | -| [SavedObjectsFindOptions](./kibana-plugin-server.savedobjectsfindoptions.md) | | -| [SavedObjectsFindResponse](./kibana-plugin-server.savedobjectsfindresponse.md) | Return type of the Saved Objects find() method.\*Note\*: this type is different between the Public and Server Saved Objects clients. | -| [SavedObjectsImportConflictError](./kibana-plugin-server.savedobjectsimportconflicterror.md) | Represents a failure to import due to a conflict. | -| [SavedObjectsImportError](./kibana-plugin-server.savedobjectsimporterror.md) | Represents a failure to import. | -| [SavedObjectsImportMissingReferencesError](./kibana-plugin-server.savedobjectsimportmissingreferenceserror.md) | Represents a failure to import due to missing references. | -| [SavedObjectsImportOptions](./kibana-plugin-server.savedobjectsimportoptions.md) | Options to control the import operation. | -| [SavedObjectsImportResponse](./kibana-plugin-server.savedobjectsimportresponse.md) | The response describing the result of an import. | -| [SavedObjectsImportRetry](./kibana-plugin-server.savedobjectsimportretry.md) | Describes a retry operation for importing a saved object. | -| [SavedObjectsImportUnknownError](./kibana-plugin-server.savedobjectsimportunknownerror.md) | Represents a failure to import due to an unknown reason. | -| [SavedObjectsImportUnsupportedTypeError](./kibana-plugin-server.savedobjectsimportunsupportedtypeerror.md) | Represents a failure to import due to having an unsupported saved object type. | -| [SavedObjectsIncrementCounterOptions](./kibana-plugin-server.savedobjectsincrementcounteroptions.md) | | -| [SavedObjectsMigrationLogger](./kibana-plugin-server.savedobjectsmigrationlogger.md) | | -| [SavedObjectsMigrationVersion](./kibana-plugin-server.savedobjectsmigrationversion.md) | Information about the migrations that have been applied to this SavedObject. When Kibana starts up, KibanaMigrator detects outdated documents and migrates them based on this value. For each migration that has been applied, the plugin's name is used as a key and the latest migration version as the value. | -| [SavedObjectsRawDoc](./kibana-plugin-server.savedobjectsrawdoc.md) | A raw document as represented directly in the saved object index. | -| [SavedObjectsRepositoryFactory](./kibana-plugin-server.savedobjectsrepositoryfactory.md) | Factory provided when invoking a [client factory provider](./kibana-plugin-server.savedobjectsclientfactoryprovider.md) See [SavedObjectsServiceSetup.setClientFactoryProvider](./kibana-plugin-server.savedobjectsservicesetup.setclientfactoryprovider.md) | -| [SavedObjectsResolveImportErrorsOptions](./kibana-plugin-server.savedobjectsresolveimporterrorsoptions.md) | Options to control the "resolve import" operation. | -| [SavedObjectsServiceSetup](./kibana-plugin-server.savedobjectsservicesetup.md) | Saved Objects is Kibana's data persistence mechanism allowing plugins to use Elasticsearch for storing and querying state. The SavedObjectsServiceSetup API exposes methods for creating and registering Saved Object client wrappers. | -| [SavedObjectsServiceStart](./kibana-plugin-server.savedobjectsservicestart.md) | Saved Objects is Kibana's data persisentence mechanism allowing plugins to use Elasticsearch for storing and querying state. The SavedObjectsServiceStart API provides a scoped Saved Objects client for interacting with Saved Objects. | -| [SavedObjectsUpdateOptions](./kibana-plugin-server.savedobjectsupdateoptions.md) | | -| [SavedObjectsUpdateResponse](./kibana-plugin-server.savedobjectsupdateresponse.md) | | -| [SessionCookieValidationResult](./kibana-plugin-server.sessioncookievalidationresult.md) | Return type from a function to validate cookie contents. | -| [SessionStorage](./kibana-plugin-server.sessionstorage.md) | Provides an interface to store and retrieve data across requests. | -| [SessionStorageCookieOptions](./kibana-plugin-server.sessionstoragecookieoptions.md) | Configuration used to create HTTP session storage based on top of cookie mechanism. | -| [SessionStorageFactory](./kibana-plugin-server.sessionstoragefactory.md) | SessionStorage factory to bind one to an incoming request | -| [StringValidation](./kibana-plugin-server.stringvalidation.md) | | -| [UiSettingsParams](./kibana-plugin-server.uisettingsparams.md) | UiSettings parameters defined by the plugins. | -| [UiSettingsServiceSetup](./kibana-plugin-server.uisettingsservicesetup.md) | | -| [UiSettingsServiceStart](./kibana-plugin-server.uisettingsservicestart.md) | | -| [UserProvidedValues](./kibana-plugin-server.userprovidedvalues.md) | Describes the values explicitly set by user. | -| [UuidServiceSetup](./kibana-plugin-server.uuidservicesetup.md) | APIs to access the application's instance uuid. | - -## Variables - -| Variable | Description | -| --- | --- | -| [kibanaResponseFactory](./kibana-plugin-server.kibanaresponsefactory.md) | Set of helpers used to create KibanaResponse to form HTTP response on an incoming request. Should be returned as a result of [RequestHandler](./kibana-plugin-server.requesthandler.md) execution. | -| [validBodyOutput](./kibana-plugin-server.validbodyoutput.md) | The set of valid body.output | - -## Type Aliases - -| Type Alias | Description | -| --- | --- | -| [AuthenticationHandler](./kibana-plugin-server.authenticationhandler.md) | See [AuthToolkit](./kibana-plugin-server.authtoolkit.md). | -| [AuthHeaders](./kibana-plugin-server.authheaders.md) | Auth Headers map | -| [AuthResult](./kibana-plugin-server.authresult.md) | | -| [CapabilitiesProvider](./kibana-plugin-server.capabilitiesprovider.md) | See [CapabilitiesSetup](./kibana-plugin-server.capabilitiessetup.md) | -| [CapabilitiesSwitcher](./kibana-plugin-server.capabilitiesswitcher.md) | See [CapabilitiesSetup](./kibana-plugin-server.capabilitiessetup.md) | -| [ConfigDeprecation](./kibana-plugin-server.configdeprecation.md) | Configuration deprecation returned from [ConfigDeprecationProvider](./kibana-plugin-server.configdeprecationprovider.md) that handles a single deprecation from the configuration. | -| [ConfigDeprecationLogger](./kibana-plugin-server.configdeprecationlogger.md) | Logger interface used when invoking a [ConfigDeprecation](./kibana-plugin-server.configdeprecation.md) | -| [ConfigDeprecationProvider](./kibana-plugin-server.configdeprecationprovider.md) | A provider that should returns a list of [ConfigDeprecation](./kibana-plugin-server.configdeprecation.md).See [ConfigDeprecationFactory](./kibana-plugin-server.configdeprecationfactory.md) for more usage examples. | -| [ConfigPath](./kibana-plugin-server.configpath.md) | | -| [ElasticsearchClientConfig](./kibana-plugin-server.elasticsearchclientconfig.md) | | -| [GetAuthHeaders](./kibana-plugin-server.getauthheaders.md) | Get headers to authenticate a user against Elasticsearch. | -| [GetAuthState](./kibana-plugin-server.getauthstate.md) | Get authentication state for a request. Returned by auth interceptor. | -| [HandlerContextType](./kibana-plugin-server.handlercontexttype.md) | Extracts the type of the first argument of a [HandlerFunction](./kibana-plugin-server.handlerfunction.md) to represent the type of the context. | -| [HandlerFunction](./kibana-plugin-server.handlerfunction.md) | A function that accepts a context object and an optional number of additional arguments. Used for the generic types in [IContextContainer](./kibana-plugin-server.icontextcontainer.md) | -| [HandlerParameters](./kibana-plugin-server.handlerparameters.md) | Extracts the types of the additional arguments of a [HandlerFunction](./kibana-plugin-server.handlerfunction.md), excluding the [HandlerContextType](./kibana-plugin-server.handlercontexttype.md). | -| [Headers](./kibana-plugin-server.headers.md) | Http request headers to read. | -| [HttpResponsePayload](./kibana-plugin-server.httpresponsepayload.md) | Data send to the client as a response payload. | -| [IBasePath](./kibana-plugin-server.ibasepath.md) | Access or manipulate the Kibana base path[BasePath](./kibana-plugin-server.basepath.md) | -| [IClusterClient](./kibana-plugin-server.iclusterclient.md) | Represents an Elasticsearch cluster API client created by the platform. It allows to call API on behalf of the internal Kibana user and the actual user that is derived from the request headers (via asScoped(...)).See [ClusterClient](./kibana-plugin-server.clusterclient.md). | -| [IContextProvider](./kibana-plugin-server.icontextprovider.md) | A function that returns a context value for a specific key of given context type. | -| [ICustomClusterClient](./kibana-plugin-server.icustomclusterclient.md) | Represents an Elasticsearch cluster API client created by a plugin. It allows to call API on behalf of the internal Kibana user and the actual user that is derived from the request headers (via asScoped(...)).See [ClusterClient](./kibana-plugin-server.clusterclient.md). | -| [IsAuthenticated](./kibana-plugin-server.isauthenticated.md) | Return authentication status for a request. | -| [ISavedObjectsRepository](./kibana-plugin-server.isavedobjectsrepository.md) | See [SavedObjectsRepository](./kibana-plugin-server.savedobjectsrepository.md) | -| [IScopedClusterClient](./kibana-plugin-server.iscopedclusterclient.md) | Serves the same purpose as "normal" ClusterClient but exposes additional callAsCurrentUser method that doesn't use credentials of the Kibana internal user (as callAsInternalUser does) to request Elasticsearch API, but rather passes HTTP headers extracted from the current user request to the API.See [ScopedClusterClient](./kibana-plugin-server.scopedclusterclient.md). | -| [KibanaRequestRouteOptions](./kibana-plugin-server.kibanarequestrouteoptions.md) | Route options: If 'GET' or 'OPTIONS' method, body options won't be returned. | -| [KibanaResponseFactory](./kibana-plugin-server.kibanaresponsefactory.md) | Creates an object containing request response payload, HTTP headers, error details, and other data transmitted to the client. | -| [KnownHeaders](./kibana-plugin-server.knownheaders.md) | Set of well-known HTTP headers. | -| [LifecycleResponseFactory](./kibana-plugin-server.lifecycleresponsefactory.md) | Creates an object containing redirection or error response with error details, HTTP headers, and other data transmitted to the client. | -| [MIGRATION\_ASSISTANCE\_INDEX\_ACTION](./kibana-plugin-server.migration_assistance_index_action.md) | | -| [MIGRATION\_DEPRECATION\_LEVEL](./kibana-plugin-server.migration_deprecation_level.md) | | -| [MutatingOperationRefreshSetting](./kibana-plugin-server.mutatingoperationrefreshsetting.md) | Elasticsearch Refresh setting for mutating operation | -| [OnPostAuthHandler](./kibana-plugin-server.onpostauthhandler.md) | See [OnPostAuthToolkit](./kibana-plugin-server.onpostauthtoolkit.md). | -| [OnPreAuthHandler](./kibana-plugin-server.onpreauthhandler.md) | See [OnPreAuthToolkit](./kibana-plugin-server.onpreauthtoolkit.md). | -| [OnPreResponseHandler](./kibana-plugin-server.onpreresponsehandler.md) | See [OnPreAuthToolkit](./kibana-plugin-server.onpreauthtoolkit.md). | -| [PluginConfigSchema](./kibana-plugin-server.pluginconfigschema.md) | Dedicated type for plugin configuration schema. | -| [PluginInitializer](./kibana-plugin-server.plugininitializer.md) | The plugin export at the root of a plugin's server directory should conform to this interface. | -| [PluginName](./kibana-plugin-server.pluginname.md) | Dedicated type for plugin name/id that is supposed to make Map/Set/Arrays that use it as a key or value more obvious. | -| [PluginOpaqueId](./kibana-plugin-server.pluginopaqueid.md) | | -| [RecursiveReadonly](./kibana-plugin-server.recursivereadonly.md) | | -| [RedirectResponseOptions](./kibana-plugin-server.redirectresponseoptions.md) | HTTP response parameters for redirection response | -| [RequestHandler](./kibana-plugin-server.requesthandler.md) | A function executed when route path matched requested resource path. Request handler is expected to return a result of one of [KibanaResponseFactory](./kibana-plugin-server.kibanaresponsefactory.md) functions. | -| [RequestHandlerContextContainer](./kibana-plugin-server.requesthandlercontextcontainer.md) | An object that handles registration of http request context providers. | -| [RequestHandlerContextProvider](./kibana-plugin-server.requesthandlercontextprovider.md) | Context provider for request handler. Extends request context object with provided functionality or data. | -| [ResponseError](./kibana-plugin-server.responseerror.md) | Error message and optional data send to the client in case of error. | -| [ResponseErrorAttributes](./kibana-plugin-server.responseerrorattributes.md) | Additional data to provide error details. | -| [ResponseHeaders](./kibana-plugin-server.responseheaders.md) | Http response headers to set. | -| [RouteContentType](./kibana-plugin-server.routecontenttype.md) | The set of supported parseable Content-Types | -| [RouteMethod](./kibana-plugin-server.routemethod.md) | The set of common HTTP methods supported by Kibana routing. | -| [RouteRegistrar](./kibana-plugin-server.routeregistrar.md) | Route handler common definition | -| [RouteValidationFunction](./kibana-plugin-server.routevalidationfunction.md) | The custom validation function if @kbn/config-schema is not a valid solution for your specific plugin requirements. | -| [RouteValidationSpec](./kibana-plugin-server.routevalidationspec.md) | Allowed property validation options: either @kbn/config-schema validations or custom validation functionsSee [RouteValidationFunction](./kibana-plugin-server.routevalidationfunction.md) for custom validation. | -| [RouteValidatorFullConfig](./kibana-plugin-server.routevalidatorfullconfig.md) | Route validations config and options merged into one object | -| [SavedObjectAttribute](./kibana-plugin-server.savedobjectattribute.md) | Type definition for a Saved Object attribute value | -| [SavedObjectAttributeSingle](./kibana-plugin-server.savedobjectattributesingle.md) | Don't use this type, it's simply a helper type for [SavedObjectAttribute](./kibana-plugin-server.savedobjectattribute.md) | -| [SavedObjectsClientContract](./kibana-plugin-server.savedobjectsclientcontract.md) | Saved Objects is Kibana's data persisentence mechanism allowing plugins to use Elasticsearch for storing plugin state.\#\# SavedObjectsClient errorsSince the SavedObjectsClient has its hands in everything we are a little paranoid about the way we present errors back to to application code. Ideally, all errors will be either:1. Caused by bad implementation (ie. undefined is not a function) and as such unpredictable 2. An error that has been classified and decorated appropriately by the decorators in [SavedObjectsErrorHelpers](./kibana-plugin-server.savedobjectserrorhelpers.md)Type 1 errors are inevitable, but since all expected/handle-able errors should be Type 2 the isXYZError() helpers exposed at SavedObjectsErrorHelpers should be used to understand and manage error responses from the SavedObjectsClient.Type 2 errors are decorated versions of the source error, so if the elasticsearch client threw an error it will be decorated based on its type. That means that rather than looking for error.body.error.type or doing substring checks on error.body.error.reason, just use the helpers to understand the meaning of the error:\`\`\`js if (SavedObjectsErrorHelpers.isNotFoundError(error)) { // handle 404 }if (SavedObjectsErrorHelpers.isNotAuthorizedError(error)) { // 401 handling should be automatic, but in case you wanted to know }// always rethrow the error unless you handle it throw error; \`\`\`\#\#\# 404s from missing indexFrom the perspective of application code and APIs the SavedObjectsClient is a black box that persists objects. One of the internal details that users have no control over is that we use an elasticsearch index for persistance and that index might be missing.At the time of writing we are in the process of transitioning away from the operating assumption that the SavedObjects index is always available. Part of this transition is handling errors resulting from an index missing. These used to trigger a 500 error in most cases, and in others cause 404s with different error messages.From my (Spencer) perspective, a 404 from the SavedObjectsApi is a 404; The object the request/call was targeting could not be found. This is why \#14141 takes special care to ensure that 404 errors are generic and don't distinguish between index missing or document missing.\#\#\# 503s from missing indexUnlike all other methods, create requests are supposed to succeed even when the Kibana index does not exist because it will be automatically created by elasticsearch. When that is not the case it is because Elasticsearch's action.auto_create_index setting prevents it from being created automatically so we throw a special 503 with the intention of informing the user that their Elasticsearch settings need to be updated.See [SavedObjectsClient](./kibana-plugin-server.savedobjectsclient.md) See [SavedObjectsErrorHelpers](./kibana-plugin-server.savedobjectserrorhelpers.md) | -| [SavedObjectsClientFactory](./kibana-plugin-server.savedobjectsclientfactory.md) | Describes the factory used to create instances of the Saved Objects Client. | -| [SavedObjectsClientFactoryProvider](./kibana-plugin-server.savedobjectsclientfactoryprovider.md) | Provider to invoke to retrieve a [SavedObjectsClientFactory](./kibana-plugin-server.savedobjectsclientfactory.md). | -| [SavedObjectsClientWrapperFactory](./kibana-plugin-server.savedobjectsclientwrapperfactory.md) | Describes the factory used to create instances of Saved Objects Client Wrappers. | -| [ScopeableRequest](./kibana-plugin-server.scopeablerequest.md) | A user credentials container. It accommodates the necessary auth credentials to impersonate the current user.See [KibanaRequest](./kibana-plugin-server.kibanarequest.md). | -| [SharedGlobalConfig](./kibana-plugin-server.sharedglobalconfig.md) | | -| [UiSettingsType](./kibana-plugin-server.uisettingstype.md) | UI element type to represent the settings. | - diff --git a/docs/development/core/server/kibana-plugin-server.stringvalidation.md b/docs/development/core/server/kibana-plugin-server.stringvalidation.md index cc52c853ce2489..0e396f2972c44f 100644 --- a/docs/development/core/server/kibana-plugin-server.stringvalidation.md +++ b/docs/development/core/server/kibana-plugin-server.stringvalidation.md @@ -2,18 +2,12 @@ [Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [StringValidation](./kibana-plugin-server.stringvalidation.md) -## StringValidation interface +## StringValidation type + +Allows regex objects or a regex string Signature: ```typescript -export interface StringValidation +export declare type StringValidation = StringValidationRegex | StringValidationRegexString; ``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [message](./kibana-plugin-server.stringvalidation.message.md) | string | | -| [regexString](./kibana-plugin-server.stringvalidation.regexstring.md) | string | | - diff --git a/docs/development/core/server/kibana-plugin-server.stringvalidation.message.md b/docs/development/core/server/kibana-plugin-server.stringvalidation.message.md deleted file mode 100644 index a15fe8b9314039..00000000000000 --- a/docs/development/core/server/kibana-plugin-server.stringvalidation.message.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [StringValidation](./kibana-plugin-server.stringvalidation.md) > [message](./kibana-plugin-server.stringvalidation.message.md) - -## StringValidation.message property - -Signature: - -```typescript -message: string; -``` diff --git a/docs/development/core/server/kibana-plugin-server.stringvalidation.regexstring.md b/docs/development/core/server/kibana-plugin-server.stringvalidation.regexstring.md deleted file mode 100644 index e19560237f77de..00000000000000 --- a/docs/development/core/server/kibana-plugin-server.stringvalidation.regexstring.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [StringValidation](./kibana-plugin-server.stringvalidation.md) > [regexString](./kibana-plugin-server.stringvalidation.regexstring.md) - -## StringValidation.regexString property - -Signature: - -```typescript -regexString: string; -``` diff --git a/docs/development/core/server/kibana-plugin-server.stringvalidationregex.md b/docs/development/core/server/kibana-plugin-server.stringvalidationregex.md new file mode 100644 index 00000000000000..46d196ea8e03fe --- /dev/null +++ b/docs/development/core/server/kibana-plugin-server.stringvalidationregex.md @@ -0,0 +1,21 @@ + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [StringValidationRegex](./kibana-plugin-server.stringvalidationregex.md) + +## StringValidationRegex interface + +StringValidation with regex object + +Signature: + +```typescript +export interface StringValidationRegex +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [message](./kibana-plugin-server.stringvalidationregex.message.md) | string | | +| [regex](./kibana-plugin-server.stringvalidationregex.regex.md) | RegExp | | + diff --git a/docs/development/core/server/kibana-plugin-server.stringvalidationregex.message.md b/docs/development/core/server/kibana-plugin-server.stringvalidationregex.message.md new file mode 100644 index 00000000000000..383b1f6d8873c2 --- /dev/null +++ b/docs/development/core/server/kibana-plugin-server.stringvalidationregex.message.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [StringValidationRegex](./kibana-plugin-server.stringvalidationregex.md) > [message](./kibana-plugin-server.stringvalidationregex.message.md) + +## StringValidationRegex.message property + +Signature: + +```typescript +message: string; +``` diff --git a/docs/development/core/server/kibana-plugin-server.stringvalidationregex.regex.md b/docs/development/core/server/kibana-plugin-server.stringvalidationregex.regex.md new file mode 100644 index 00000000000000..69a96a04895039 --- /dev/null +++ b/docs/development/core/server/kibana-plugin-server.stringvalidationregex.regex.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [StringValidationRegex](./kibana-plugin-server.stringvalidationregex.md) > [regex](./kibana-plugin-server.stringvalidationregex.regex.md) + +## StringValidationRegex.regex property + +Signature: + +```typescript +regex: RegExp; +``` diff --git a/docs/development/core/server/kibana-plugin-server.stringvalidationregexstring.md b/docs/development/core/server/kibana-plugin-server.stringvalidationregexstring.md new file mode 100644 index 00000000000000..d76cb94fdd1a1c --- /dev/null +++ b/docs/development/core/server/kibana-plugin-server.stringvalidationregexstring.md @@ -0,0 +1,21 @@ + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [StringValidationRegexString](./kibana-plugin-server.stringvalidationregexstring.md) + +## StringValidationRegexString interface + +StringValidation as regex string + +Signature: + +```typescript +export interface StringValidationRegexString +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [message](./kibana-plugin-server.stringvalidationregexstring.message.md) | string | | +| [regexString](./kibana-plugin-server.stringvalidationregexstring.regexstring.md) | string | | + diff --git a/docs/development/core/server/kibana-plugin-server.stringvalidationregexstring.message.md b/docs/development/core/server/kibana-plugin-server.stringvalidationregexstring.message.md new file mode 100644 index 00000000000000..361dfe788b852e --- /dev/null +++ b/docs/development/core/server/kibana-plugin-server.stringvalidationregexstring.message.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [StringValidationRegexString](./kibana-plugin-server.stringvalidationregexstring.md) > [message](./kibana-plugin-server.stringvalidationregexstring.message.md) + +## StringValidationRegexString.message property + +Signature: + +```typescript +message: string; +``` diff --git a/docs/development/core/server/kibana-plugin-server.stringvalidationregexstring.regexstring.md b/docs/development/core/server/kibana-plugin-server.stringvalidationregexstring.regexstring.md new file mode 100644 index 00000000000000..203cc7e7a0aadd --- /dev/null +++ b/docs/development/core/server/kibana-plugin-server.stringvalidationregexstring.regexstring.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [StringValidationRegexString](./kibana-plugin-server.stringvalidationregexstring.md) > [regexString](./kibana-plugin-server.stringvalidationregexstring.regexstring.md) + +## StringValidationRegexString.regexString property + +Signature: + +```typescript +regexString: string; +``` diff --git a/docs/development/core/server/kibana-plugin-server.uisettingstype.md b/docs/development/core/server/kibana-plugin-server.uisettingstype.md index 789d4d5788468e..b78932aecc7245 100644 --- a/docs/development/core/server/kibana-plugin-server.uisettingstype.md +++ b/docs/development/core/server/kibana-plugin-server.uisettingstype.md @@ -9,5 +9,5 @@ UI element type to represent the settings. Signature: ```typescript -export declare type UiSettingsType = 'json' | 'markdown' | 'number' | 'select' | 'boolean' | 'string'; +export declare type UiSettingsType = 'undefined' | 'json' | 'markdown' | 'number' | 'select' | 'boolean' | 'string' | 'array' | 'image'; ``` diff --git a/src/core/public/doc_links/doc_links_service.ts b/src/core/public/doc_links/doc_links_service.ts index 1046f7a17dc518..3521d7ef9c66eb 100644 --- a/src/core/public/doc_links/doc_links_service.ts +++ b/src/core/public/doc_links/doc_links_service.ts @@ -214,5 +214,6 @@ export interface DocLinksStart { readonly date: { readonly dateMath: string; }; + readonly management: Record; }; } diff --git a/src/core/public/index.ts b/src/core/public/index.ts index bf8cab9a3c7787..c57d35343087ae 100644 --- a/src/core/public/index.ts +++ b/src/core/public/index.ts @@ -78,7 +78,16 @@ import { export { CoreContext, CoreSystem } from './core_system'; export { RecursiveReadonly, DEFAULT_APP_CATEGORIES } from '../utils'; -export { AppCategory } from '../types'; +export { + AppCategory, + UiSettingsParams, + UserProvidedValues, + UiSettingsType, + ImageValidation, + StringValidation, + StringValidationRegex, + StringValidationRegexString, +} from '../types'; export { ApplicationSetup, diff --git a/src/core/public/public.api.md b/src/core/public/public.api.md index 0da6e0d422f2d7..a9cea7ae97998d 100644 --- a/src/core/public/public.api.md +++ b/src/core/public/public.api.md @@ -531,6 +531,7 @@ export interface DocLinksStart { readonly date: { readonly dateMath: string; }; + readonly management: Record; }; } @@ -730,6 +731,15 @@ export interface IHttpResponseInterceptorOverrides { readonly response?: Readonly; } +// @public (undocumented) +export interface ImageValidation { + // (undocumented) + maxSize: { + length: number; + description: string; + }; +} + // @public export type IToasts = Pick; @@ -1166,6 +1176,25 @@ export class SimpleSavedObject { _version?: SavedObject['version']; } +// @public +export type StringValidation = StringValidationRegex | StringValidationRegexString; + +// @public +export interface StringValidationRegex { + // (undocumented) + message: string; + // (undocumented) + regex: RegExp; +} + +// @public +export interface StringValidationRegexString { + // (undocumented) + message: string; + // (undocumented) + regexString: string; +} + // Warning: (ae-missing-release-tag) "Toast" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) @@ -1207,14 +1236,42 @@ export type ToastsSetup = IToasts; // @public (undocumented) export type ToastsStart = IToasts; +// @public +export interface UiSettingsParams { + category?: string[]; + // Warning: (ae-forgotten-export) The symbol "DeprecationSettings" needs to be exported by the entry point index.d.ts + deprecation?: DeprecationSettings; + description?: string; + name?: string; + optionLabels?: Record; + options?: string[]; + readonly?: boolean; + requiresPageReload?: boolean; + type?: UiSettingsType; + // (undocumented) + validation?: ImageValidation | StringValidation; + value?: SavedObjectAttribute; +} + // @public (undocumented) export interface UiSettingsState { // (undocumented) [key: string]: UiSettingsParams_2 & UserProvidedValues_2; } +// @public +export type UiSettingsType = 'undefined' | 'json' | 'markdown' | 'number' | 'select' | 'boolean' | 'string' | 'array' | 'image'; + // @public export type UnmountCallback = () => void; +// @public +export interface UserProvidedValues { + // (undocumented) + isOverridden?: boolean; + // (undocumented) + userValue?: T; +} + ``` diff --git a/src/core/public/types.ts b/src/core/public/types.ts index 5abbb3c55813ac..267a9e9f7e0145 100644 --- a/src/core/public/types.ts +++ b/src/core/public/types.ts @@ -17,6 +17,14 @@ * under the License. */ +export { + UiSettingsParams, + UserProvidedValues, + UiSettingsType, + ImageValidation, + StringValidationRegex, +} from '../../core/types'; + /** * A function that should mount DOM content inside the provided container element * and return a handler to unmount it. diff --git a/src/core/server/index.ts b/src/core/server/index.ts index cdc2ec91134ed1..91f38c9f2ddbe9 100644 --- a/src/core/server/index.ts +++ b/src/core/server/index.ts @@ -222,6 +222,8 @@ export { ImageValidation, DeprecationSettings, StringValidation, + StringValidationRegex, + StringValidationRegexString, } from './ui_settings'; export { RecursiveReadonly } from '../utils'; diff --git a/src/core/server/saved_objects/types.ts b/src/core/server/saved_objects/types.ts index dfce4a4c8ab189..a3fe2b937635bf 100644 --- a/src/core/server/saved_objects/types.ts +++ b/src/core/server/saved_objects/types.ts @@ -33,6 +33,13 @@ export { SavedObjectsImportRetry, } from './import/types'; +import { SavedObjectAttributes } from '../../types'; +export { + SavedObjectAttributes, + SavedObjectAttribute, + SavedObjectAttributeSingle, +} from '../../types'; + /** * Information about the migrations that have been applied to this SavedObject. * When Kibana starts up, KibanaMigrator detects outdated documents and @@ -52,36 +59,6 @@ export interface SavedObjectsMigrationVersion { [pluginName: string]: string; } -/** - * Don't use this type, it's simply a helper type for {@link SavedObjectAttribute} - * - * @public - */ -export type SavedObjectAttributeSingle = - | string - | number - | boolean - | null - | undefined - | SavedObjectAttributes; - -/** - * Type definition for a Saved Object attribute value - * - * @public - */ -export type SavedObjectAttribute = SavedObjectAttributeSingle | SavedObjectAttributeSingle[]; - -/** - * The data for a Saved Object is stored as an object in the `attributes` - * property. - * - * @public - */ -export interface SavedObjectAttributes { - [key: string]: SavedObjectAttribute; -} - /** * * @public diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md index 060587448642fd..629e6a881199be 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -803,8 +803,6 @@ export interface IKibanaSocket { getPeerCertificate(detailed?: boolean): PeerCertificate | DetailedPeerCertificate | null; } -// Warning: (ae-missing-release-tag) "ImageValidation" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// // @public (undocumented) export interface ImageValidation { // (undocumented) @@ -1957,10 +1955,19 @@ export type SharedGlobalConfig = RecursiveReadonly_2<{ path: Pick; }>; -// Warning: (ae-missing-release-tag) "StringValidation" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// -// @public (undocumented) -export interface StringValidation { +// @public +export type StringValidation = StringValidationRegex | StringValidationRegexString; + +// @public +export interface StringValidationRegex { + // (undocumented) + message: string; + // (undocumented) + regex: RegExp; +} + +// @public +export interface StringValidationRegexString { // (undocumented) message: string; // (undocumented) @@ -1994,7 +2001,7 @@ export interface UiSettingsServiceStart { } // @public -export type UiSettingsType = 'json' | 'markdown' | 'number' | 'select' | 'boolean' | 'string'; +export type UiSettingsType = 'undefined' | 'json' | 'markdown' | 'number' | 'select' | 'boolean' | 'string' | 'array' | 'image'; // @public export interface UserProvidedValues { diff --git a/src/core/server/ui_settings/index.ts b/src/core/server/ui_settings/index.ts index 39eb0046010b38..ddb66df3ffcbe1 100644 --- a/src/core/server/ui_settings/index.ts +++ b/src/core/server/ui_settings/index.ts @@ -34,4 +34,6 @@ export { ImageValidation, DeprecationSettings, StringValidation, + StringValidationRegex, + StringValidationRegexString, } from './types'; diff --git a/src/core/server/ui_settings/types.ts b/src/core/server/ui_settings/types.ts index a74a31bbbd671a..f3eb1f5a6859cc 100644 --- a/src/core/server/ui_settings/types.ts +++ b/src/core/server/ui_settings/types.ts @@ -16,7 +16,19 @@ * specific language governing permissions and limitations * under the License. */ -import { SavedObjectsClientContract, SavedObjectAttribute } from '../saved_objects/types'; +import { SavedObjectsClientContract } from '../saved_objects/types'; +import { UiSettingsParams, UserProvidedValues } from '../../types'; +export { + UiSettingsParams, + StringValidationRegexString, + StringValidationRegex, + StringValidation, + DeprecationSettings, + ImageValidation, + UiSettingsType, + UserProvidedValues, +} from '../../types'; + /** * Server-side client that provides access to the advanced settings stored in elasticsearch. * The settings provide control over the behavior of the Kibana application. @@ -64,76 +76,6 @@ export interface IUiSettingsClient { isOverridden: (key: string) => boolean; } -/** - * Describes the values explicitly set by user. - * @public - * */ -export interface UserProvidedValues { - userValue?: T; - isOverridden?: boolean; -} - -/** - * UiSettings deprecation field options. - * @public - * */ -export interface DeprecationSettings { - /** Deprecation message */ - message: string; - /** Key to documentation links */ - docLinksKey: string; -} - -/** - * UI element type to represent the settings. - * @public - * */ -export type UiSettingsType = 'json' | 'markdown' | 'number' | 'select' | 'boolean' | 'string'; - -/** - * UiSettings parameters defined by the plugins. - * @public - * */ -export interface UiSettingsParams { - /** title in the UI */ - name?: string; - /** default value to fall back to if a user doesn't provide any */ - value?: SavedObjectAttribute; - /** description provided to a user in UI */ - description?: string; - /** used to group the configured setting in the UI */ - category?: string[]; - /** array of permitted values for this setting */ - options?: string[]; - /** text labels for 'select' type UI element */ - optionLabels?: Record; - /** a flag indicating whether new value applying requires page reloading */ - requiresPageReload?: boolean; - /** a flag indicating that value cannot be changed */ - readonly?: boolean; - /** defines a type of UI element {@link UiSettingsType} */ - type?: UiSettingsType; - /** optional deprecation information. Used to generate a deprecation warning. */ - deprecation?: DeprecationSettings; - /* - * Allows defining a custom validation applicable to value change on the client. - * @deprecated - */ - validation?: ImageValidation | StringValidation; -} - -export interface StringValidation { - regexString: string; - message: string; -} - -export interface ImageValidation { - maxSize: { - length: number; - description: string; - }; -} - /** @internal */ export interface InternalUiSettingsServiceSetup { /** diff --git a/src/core/types/index.ts b/src/core/types/index.ts index 7ddb6b0d8dfbbc..346b4cfce70c1a 100644 --- a/src/core/types/index.ts +++ b/src/core/types/index.ts @@ -24,3 +24,5 @@ export * from './core_service'; export * from './capabilities'; export * from './app_category'; +export * from './ui_settings'; +export * from './saved_objects'; diff --git a/src/core/types/saved_objects.ts b/src/core/types/saved_objects.ts new file mode 100644 index 00000000000000..73eb2db11d62fb --- /dev/null +++ b/src/core/types/saved_objects.ts @@ -0,0 +1,48 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * Don't use this type, it's simply a helper type for {@link SavedObjectAttribute} + * + * @public + */ +export type SavedObjectAttributeSingle = + | string + | number + | boolean + | null + | undefined + | SavedObjectAttributes; + +/** + * Type definition for a Saved Object attribute value + * + * @public + */ +export type SavedObjectAttribute = SavedObjectAttributeSingle | SavedObjectAttributeSingle[]; + +/** + * The data for a Saved Object is stored as an object in the `attributes` + * property. + * + * @public + */ +export interface SavedObjectAttributes { + [key: string]: SavedObjectAttribute; +} diff --git a/src/core/types/ui_settings.ts b/src/core/types/ui_settings.ts new file mode 100644 index 00000000000000..eccd3f9616af07 --- /dev/null +++ b/src/core/types/ui_settings.ts @@ -0,0 +1,121 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { SavedObjectAttribute } from './saved_objects'; + +/** + * UI element type to represent the settings. + * @public + * */ +export type UiSettingsType = + | 'undefined' // I don't know why malformed UiSettings objects exist + | 'json' + | 'markdown' + | 'number' + | 'select' + | 'boolean' + | 'string' + | 'array' + | 'image'; + +/** + * UiSettings deprecation field options. + * @public + * */ +export interface DeprecationSettings { + /** Deprecation message */ + message: string; + /** Key to documentation links */ + docLinksKey: string; +} + +/** + * UiSettings parameters defined by the plugins. + * @public + * */ +export interface UiSettingsParams { + /** title in the UI */ + name?: string; + /** default value to fall back to if a user doesn't provide any */ + value?: SavedObjectAttribute; + /** description provided to a user in UI */ + description?: string; + /** used to group the configured setting in the UI */ + category?: string[]; + /** array of permitted values for this setting */ + options?: string[]; + /** text labels for 'select' type UI element */ + optionLabels?: Record; + /** a flag indicating whether new value applying requires page reloading */ + requiresPageReload?: boolean; + /** a flag indicating that value cannot be changed */ + readonly?: boolean; + /** defines a type of UI element {@link UiSettingsType} */ + type?: UiSettingsType; + /** optional deprecation information. Used to generate a deprecation warning. */ + deprecation?: DeprecationSettings; + /* + * Allows defining a custom validation applicable to value change on the client. + * @deprecated + */ + validation?: ImageValidation | StringValidation; +} + +/** + * Allows regex objects or a regex string + * @public + * */ +export type StringValidation = StringValidationRegex | StringValidationRegexString; + +/** + * StringValidation with regex object + * @public + * */ +export interface StringValidationRegex { + regex: RegExp; + message: string; +} + +/** + * StringValidation as regex string + * @public + * */ +export interface StringValidationRegexString { + regexString: string; + message: string; +} + +/** + * @public + * */ +export interface ImageValidation { + maxSize: { + length: number; + description: string; + }; +} + +/** + * Describes the values explicitly set by user. + * @public + * */ +export interface UserProvidedValues { + userValue?: T; + isOverridden?: boolean; +} diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/__snapshots__/advanced_settings.test.js.snap b/src/legacy/core_plugins/kibana/public/management/sections/settings/__snapshots__/advanced_settings.test.js.snap deleted file mode 100644 index eef8f3fc93d90f..00000000000000 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/__snapshots__/advanced_settings.test.js.snap +++ /dev/null @@ -1,1022 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`AdvancedSettings should render normally 1`] = ` -
- - - - - - - - - - - - - -
- -
-`; - -exports[`AdvancedSettings should render read-only when saving is disabled 1`] = ` -
- - - - - - - - - - - - - - - -
-`; - -exports[`AdvancedSettings should render specific setting if given setting key 1`] = ` -
- - - - - - - - - - - - - - - -
-`; diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/__snapshots__/advanced_settings.test.tsx.snap b/src/legacy/core_plugins/kibana/public/management/sections/settings/__snapshots__/advanced_settings.test.tsx.snap new file mode 100644 index 00000000000000..4814432c832e2f --- /dev/null +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/__snapshots__/advanced_settings.test.tsx.snap @@ -0,0 +1,367 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AdvancedSettings should render read-only when saving is disabled 1`] = ` +
+ + + + + + + + + + + + + + + +
+`; + +exports[`AdvancedSettings should render specific setting if given setting key 1`] = ` +
+ + + + + + + + + + + + + + + +
+`; diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/advanced_settings.test.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/advanced_settings.test.js deleted file mode 100644 index 94128dc5271de1..00000000000000 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/advanced_settings.test.js +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import React from 'react'; -import { shallow } from 'enzyme'; -import dedent from 'dedent'; - -import { AdvancedSettings } from './advanced_settings'; - -jest.mock('./components/field', () => ({ - Field: () => { - return 'field'; - }, -})); - -jest.mock('./components/call_outs', () => ({ - CallOuts: () => { - return 'callOuts'; - }, -})); - -jest.mock('./components/search', () => ({ - Search: () => { - return 'search'; - }, -})); - -const config = { - set: () => {}, - remove: () => {}, - isCustom: setting => setting.isCustom, - isOverridden: key => Boolean(config.getAll()[key].isOverridden), - getAll: () => { - return { - 'test:array:setting': { - value: ['default_value'], - name: 'Test array setting', - description: 'Description for Test array setting', - category: ['elasticsearch'], - }, - 'test:boolean:setting': { - value: true, - name: 'Test boolean setting', - description: 'Description for Test boolean setting', - category: ['elasticsearch'], - }, - 'test:image:setting': { - value: null, - name: 'Test image setting', - description: 'Description for Test image setting', - type: 'image', - }, - 'test:json:setting': { - value: '{"foo": "bar"}', - name: 'Test json setting', - description: 'Description for Test json setting', - type: 'json', - }, - 'test:markdown:setting': { - value: '', - name: 'Test markdown setting', - description: 'Description for Test markdown setting', - type: 'markdown', - }, - 'test:number:setting': { - value: 5, - name: 'Test number setting', - description: 'Description for Test number setting', - }, - 'test:select:setting': { - value: 'orange', - name: 'Test select setting', - description: 'Description for Test select setting', - type: 'select', - options: ['apple', 'orange', 'banana'], - }, - 'test:string:setting': { - value: null, - name: 'Test string setting', - description: 'Description for Test string setting', - type: 'string', - isCustom: true, - }, - 'test:readonlystring:setting': { - value: null, - name: 'Test readonly string setting', - description: 'Description for Test readonly string setting', - type: 'string', - readonly: true, - }, - 'test:customstring:setting': { - value: null, - name: 'Test custom string setting', - description: 'Description for Test custom string setting', - type: 'string', - isCustom: true, - }, - 'test:isOverridden:string': { - isOverridden: true, - value: 'foo', - name: 'An overridden string', - description: 'Description for overridden string', - type: 'string', - }, - 'test:isOverridden:number': { - isOverridden: true, - value: 1234, - name: 'An overridden number', - description: 'Description for overridden number', - type: 'number', - }, - 'test:isOverridden:json': { - isOverridden: true, - value: dedent` - { - "foo": "bar" - } - `, - name: 'An overridden json', - description: 'Description for overridden json', - type: 'json', - }, - 'test:isOverridden:select': { - isOverridden: true, - value: 'orange', - name: 'Test overridden select setting', - description: 'Description for overridden select setting', - type: 'select', - options: ['apple', 'orange', 'banana'], - }, - }; - }, -}; - -describe('AdvancedSettings', () => { - it('should render normally', async () => { - const component = shallow(); - - expect(component).toMatchSnapshot(); - }); - - it('should render specific setting if given setting key', async () => { - const component = shallow( - - ); - - expect(component).toMatchSnapshot(); - }); - - it('should render read-only when saving is disabled', async () => { - const component = shallow( - - ); - - expect(component).toMatchSnapshot(); - }); -}); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/advanced_settings.test.tsx b/src/legacy/core_plugins/kibana/public/management/sections/settings/advanced_settings.test.tsx new file mode 100644 index 00000000000000..2a75c98b721bca --- /dev/null +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/advanced_settings.test.tsx @@ -0,0 +1,237 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import React from 'react'; +import { Observable } from 'rxjs'; +import { shallow } from 'enzyme'; +import dedent from 'dedent'; +import { + UiSettingsParams, + UserProvidedValues, + UiSettingsType, +} from '../../../../../../../core/public'; +import { FieldSetting } from './types'; +import { AdvancedSettings } from './advanced_settings'; + +jest.mock('ui/new_platform', () => ({ + npStart: mockConfig(), +})); + +jest.mock('./components/field', () => ({ + Field: () => { + return 'field'; + }, +})); + +jest.mock('./components/call_outs', () => ({ + CallOuts: () => { + return 'callOuts'; + }, +})); + +jest.mock('./components/search', () => ({ + Search: () => { + return 'search'; + }, +})); + +function mockConfig() { + const defaultConfig: Partial = { + displayName: 'defaultName', + requiresPageReload: false, + isOverridden: false, + ariaName: 'ariaName', + readOnly: false, + isCustom: false, + defVal: 'defVal', + type: 'string' as UiSettingsType, + category: ['category'], + }; + + const config = { + set: (key: string, value: any) => Promise.resolve(true), + remove: (key: string) => Promise.resolve(true), + isCustom: (key: string) => false, + isOverridden: (key: string) => Boolean(config.getAll()[key].isOverridden), + getRegistered: () => ({} as Readonly>), + overrideLocalDefault: (key: string, value: any) => {}, + getUpdate$: () => + new Observable<{ + key: string; + newValue: any; + oldValue: any; + }>(), + isDeclared: (key: string) => true, + isDefault: (key: string) => true, + + getSaved$: () => + new Observable<{ + key: string; + newValue: any; + oldValue: any; + }>(), + + getUpdateErrors$: () => new Observable(), + get: (key: string, defaultOverride?: any): any => config.getAll()[key] || defaultOverride, + get$: (key: string) => new Observable(config.get(key)), + getAll: (): Readonly> => { + return { + 'test:array:setting': { + ...defaultConfig, + value: ['default_value'], + name: 'Test array setting', + description: 'Description for Test array setting', + category: ['elasticsearch'], + }, + 'test:boolean:setting': { + ...defaultConfig, + value: true, + name: 'Test boolean setting', + description: 'Description for Test boolean setting', + category: ['elasticsearch'], + }, + 'test:image:setting': { + ...defaultConfig, + value: null, + name: 'Test image setting', + description: 'Description for Test image setting', + type: 'image', + }, + 'test:json:setting': { + ...defaultConfig, + value: '{"foo": "bar"}', + name: 'Test json setting', + description: 'Description for Test json setting', + type: 'json', + }, + 'test:markdown:setting': { + ...defaultConfig, + value: '', + name: 'Test markdown setting', + description: 'Description for Test markdown setting', + type: 'markdown', + }, + 'test:number:setting': { + ...defaultConfig, + value: 5, + name: 'Test number setting', + description: 'Description for Test number setting', + }, + 'test:select:setting': { + ...defaultConfig, + value: 'orange', + name: 'Test select setting', + description: 'Description for Test select setting', + type: 'select', + options: ['apple', 'orange', 'banana'], + }, + 'test:string:setting': { + ...defaultConfig, + ...{ + value: null, + name: 'Test string setting', + description: 'Description for Test string setting', + type: 'string', + isCustom: true, + }, + }, + 'test:readonlystring:setting': { + ...defaultConfig, + ...{ + value: null, + name: 'Test readonly string setting', + description: 'Description for Test readonly string setting', + type: 'string', + readOnly: true, + }, + }, + 'test:customstring:setting': { + ...defaultConfig, + ...{ + value: null, + name: 'Test custom string setting', + description: 'Description for Test custom string setting', + type: 'string', + isCustom: true, + }, + }, + 'test:isOverridden:string': { + ...defaultConfig, + isOverridden: true, + value: 'foo', + name: 'An overridden string', + description: 'Description for overridden string', + type: 'string', + }, + 'test:isOverridden:number': { + ...defaultConfig, + isOverridden: true, + value: 1234, + name: 'An overridden number', + description: 'Description for overridden number', + type: 'number', + }, + 'test:isOverridden:json': { + ...defaultConfig, + isOverridden: true, + value: dedent` + { + "foo": "bar" + } + `, + name: 'An overridden json', + description: 'Description for overridden json', + type: 'json', + }, + 'test:isOverridden:select': { + ...defaultConfig, + isOverridden: true, + value: 'orange', + name: 'Test overridden select setting', + description: 'Description for overridden select setting', + type: 'select', + options: ['apple', 'orange', 'banana'], + }, + }; + }, + }; + return { + core: { + uiSettings: config, + }, + }; +} + +describe('AdvancedSettings', () => { + it('should render specific setting if given setting key', async () => { + const component = shallow( + + ); + + expect(component).toMatchSnapshot(); + }); + + it('should render read-only when saving is disabled', async () => { + const component = shallow( + + ); + + expect(component).toMatchSnapshot(); + }); +}); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/advanced_settings.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/advanced_settings.tsx similarity index 62% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/advanced_settings.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/advanced_settings.tsx index 508e05bbf9bb40..569ef73f2b4536 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/advanced_settings.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/advanced_settings.tsx @@ -18,17 +18,19 @@ */ import React, { Component } from 'react'; -import PropTypes from 'prop-types'; - import { Comparators, EuiFlexGroup, EuiFlexItem, EuiSpacer, Query } from '@elastic/eui'; +import { npStart } from 'ui/new_platform'; import { CallOuts } from './components/call_outs'; import { Search } from './components/search'; import { Form } from './components/form'; import { AdvancedSettingsVoiceAnnouncement } from './components/advanced_settings_voice_announcement'; +import { IUiSettingsClient } from '../../../../../../../core/public/'; import { getAriaName, toEditableConfig, DEFAULT_CATEGORY } from './lib'; +import { FieldSetting, IQuery } from './types'; + import { registerDefaultComponents, PAGE_TITLE_COMPONENT, @@ -37,18 +39,37 @@ import { } from './components/default_component_registry'; import { getSettingsComponent } from './components/component_registry'; -export class AdvancedSettings extends Component { - static propTypes = { - config: PropTypes.object.isRequired, - query: PropTypes.string, - enableSaving: PropTypes.bool.isRequired, - }; +interface AdvancedSettingsProps { + queryText: string; + enableSaving: boolean; +} + +interface AdvancedSettingsState { + footerQueryMatched: boolean; + query: IQuery; + filteredSettings: Record; +} - constructor(props) { +type GroupedSettings = Record; + +export class AdvancedSettings extends Component { + private config: IUiSettingsClient; + private settings: FieldSetting[]; + private groupedSettings: GroupedSettings; + private categoryCounts: Record; + private categories: string[] = []; + + constructor(props: AdvancedSettingsProps) { super(props); - const { config, query } = this.props; - const parsedQuery = Query.parse(query ? `ariaName:"${getAriaName(query)}"` : ''); - this.init(config); + const { queryText } = this.props; + const parsedQuery = Query.parse(queryText ? `ariaName:"${getAriaName(queryText)}"` : ''); + + this.config = npStart.core.uiSettings; + this.settings = this.initSettings(this.config); + this.groupedSettings = this.initGroupedSettings(this.settings); + this.categories = this.initCategories(this.groupedSettings); + this.categoryCounts = this.initCategoryCounts(this.groupedSettings); + this.state = { query: parsedQuery, footerQueryMatched: false, @@ -58,34 +79,44 @@ export class AdvancedSettings extends Component { registerDefaultComponents(); } - init(config) { - this.settings = this.mapConfig(config); - this.groupedSettings = this.mapSettings(this.settings); + init(config: IUiSettingsClient) { + this.settings = this.initSettings(config); + this.groupedSettings = this.initGroupedSettings(this.settings); + this.categories = this.initCategories(this.groupedSettings); + this.categoryCounts = this.initCategoryCounts(this.groupedSettings); + } - this.categories = Object.keys(this.groupedSettings).sort((a, b) => { + initSettings = this.mapConfig; + initGroupedSettings = this.mapSettings; + initCategories(groupedSettings: GroupedSettings) { + return Object.keys(groupedSettings).sort((a, b) => { if (a === DEFAULT_CATEGORY) return -1; if (b === DEFAULT_CATEGORY) return 1; if (a > b) return 1; return a === b ? 0 : -1; }); - - this.categoryCounts = Object.keys(this.groupedSettings).reduce((counts, category) => { - counts[category] = this.groupedSettings[category].length; - return counts; - }, {}); + } + initCategoryCounts(groupedSettings: GroupedSettings) { + return Object.keys(groupedSettings).reduce( + (counts: Record, category: string) => { + counts[category] = groupedSettings[category].length; + return counts; + }, + {} + ); } - UNSAFE_componentWillReceiveProps(nextProps) { - const { config } = nextProps; - const { query } = this.state; - - this.init(config); - this.setState({ - filteredSettings: this.mapSettings(Query.execute(query, this.settings)), + componentDidMount() { + this.config.getUpdate$().subscribe(() => { + const { query } = this.state; + this.init(this.config); + this.setState({ + filteredSettings: this.mapSettings(Query.execute(query, this.settings)), + }); }); } - mapConfig(config) { + mapConfig(config: IUiSettingsClient) { const all = config.getAll(); return Object.entries(all) .map(setting => { @@ -101,9 +132,9 @@ export class AdvancedSettings extends Component { .sort(Comparators.property('name', Comparators.default('asc'))); } - mapSettings(settings) { + mapSettings(settings: FieldSetting[]) { // Group settings by category - return settings.reduce((groupedSettings, setting) => { + return settings.reduce((groupedSettings: GroupedSettings, setting) => { // We will want to change this logic when we put each category on its // own page aka allowing a setting to be included in multiple categories. const category = setting.category[0]; @@ -112,15 +143,7 @@ export class AdvancedSettings extends Component { }, {}); } - saveConfig = (name, value) => { - return this.props.config.set(name, value); - }; - - clearConfig = name => { - return this.props.config.remove(name); - }; - - onQueryChange = ({ query }) => { + onQueryChange = ({ query }: { query: IQuery }) => { this.setState({ query, filteredSettings: this.mapSettings(Query.execute(query, this.settings)), @@ -135,7 +158,7 @@ export class AdvancedSettings extends Component { }); }; - onFooterQueryMatchChange = matched => { + onFooterQueryMatchChange = (matched: boolean) => { this.setState({ footerQueryMatched: matched, }); @@ -170,8 +193,8 @@ export class AdvancedSettings extends Component { categories={this.categories} categoryCounts={this.categoryCounts} clearQuery={this.clearQuery} - save={this.saveConfig} - clear={this.clearConfig} + save={this.config.set.bind(this.config)} + clear={this.config.remove.bind(this.config)} showNoResultsMessage={!footerQueryMatched} enableSaving={this.props.enableSaving} /> diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/breadcrumbs.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/breadcrumbs.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/breadcrumbs.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/breadcrumbs.ts diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/__snapshots__/component_registry.test.js.snap b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/__snapshots__/component_registry.test.tsx.snap similarity index 100% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/__snapshots__/component_registry.test.js.snap rename to src/legacy/core_plugins/kibana/public/management/sections/settings/components/__snapshots__/component_registry.test.tsx.snap diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/advanced_settings_voice_announcement/__snapshots__/advanced_settings_voice_announcement.test.js.snap b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/advanced_settings_voice_announcement/__snapshots__/advanced_settings_voice_announcement.test.tsx.snap similarity index 95% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/advanced_settings_voice_announcement/__snapshots__/advanced_settings_voice_announcement.test.js.snap rename to src/legacy/core_plugins/kibana/public/management/sections/settings/components/advanced_settings_voice_announcement/__snapshots__/advanced_settings_voice_announcement.test.tsx.snap index 049e4530b795f9..e8c8184cf7e57c 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/advanced_settings_voice_announcement/__snapshots__/advanced_settings_voice_announcement.test.js.snap +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/advanced_settings_voice_announcement/__snapshots__/advanced_settings_voice_announcement.test.tsx.snap @@ -15,7 +15,7 @@ exports[`Advanced Settings: Voice Announcement should render announcement 1`] = values={ Object { "optionLenght": 1, - "query": undefined, + "query": "dark theme", "sectionLenght": 1, } } @@ -40,7 +40,7 @@ exports[`Advanced Settings: Voice Announcement should render nothing 1`] = ` values={ Object { "optionLenght": 1, - "query": undefined, + "query": "", "sectionLenght": 1, } } diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/advanced_settings_voice_announcement/advanced_settings_voice_announcement.test.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/advanced_settings_voice_announcement/advanced_settings_voice_announcement.test.tsx similarity index 66% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/advanced_settings_voice_announcement/advanced_settings_voice_announcement.test.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/components/advanced_settings_voice_announcement/advanced_settings_voice_announcement.test.tsx index 41b16c5cbda711..66f2d4e784630f 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/advanced_settings_voice_announcement/advanced_settings_voice_announcement.test.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/advanced_settings_voice_announcement/advanced_settings_voice_announcement.test.tsx @@ -19,28 +19,44 @@ import React from 'react'; import { shallow } from 'enzyme'; +import { UiSettingsType } from '../../../../../../../../../core/public'; import { AdvancedSettingsVoiceAnnouncement } from './advanced_settings_voice_announcement'; +const settingPartial = { + name: 'name', + isOverridden: false, + type: 'string' as UiSettingsType, + value: 'value', + defVal: 'defVal', + optionLabels: { label: 'label' }, + description: 'description', + displayName: 'displayName', + isCustom: false, + requiresPageReload: false, + options: [], + validation: { regex: /a/, message: 'message' }, + category: ['category'], + readOnly: false, +}; + const testProps = { nothing: { query: '', filteredSettings: [ - [ - { - ariaName: 'General', - }, - ], + { + ariaName: 'General', + ...settingPartial, + }, ], }, searchResult: { query: 'dark theme', filteredSettings: [ - [ - { - ariaName: 'General', - }, - ], + { + ariaName: 'General', + ...settingPartial, + }, ], }, }; @@ -50,7 +66,7 @@ describe('Advanced Settings: Voice Announcement', () => { const { query, filteredSettings } = testProps.nothing; const component = shallow( - + ); expect(component).toMatchSnapshot(); @@ -60,7 +76,7 @@ describe('Advanced Settings: Voice Announcement', () => { const { query, filteredSettings } = testProps.searchResult; const component = shallow( - + ); expect(component).toMatchSnapshot(); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/advanced_settings_voice_announcement/advanced_settings_voice_announcement.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/advanced_settings_voice_announcement/advanced_settings_voice_announcement.tsx similarity index 92% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/advanced_settings_voice_announcement/advanced_settings_voice_announcement.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/components/advanced_settings_voice_announcement/advanced_settings_voice_announcement.tsx index 34625e1ce5114f..01f1388ba1eef5 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/advanced_settings_voice_announcement/advanced_settings_voice_announcement.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/advanced_settings_voice_announcement/advanced_settings_voice_announcement.tsx @@ -40,9 +40,15 @@ import React, { Component } from 'react'; import { FormattedMessage } from '@kbn/i18n/react'; import { EuiScreenReaderOnly, EuiDelayRender } from '@elastic/eui'; +import { FieldSetting } from '../../types'; -export class AdvancedSettingsVoiceAnnouncement extends Component { - shouldComponentUpdate = nextProps => { +interface Props { + queryText: string; + settings: Record; +} + +export class AdvancedSettingsVoiceAnnouncement extends Component { + shouldComponentUpdate = (nextProps: Props) => { /* If a user typed smth new, we should clear the previous timer and start another one + block component rendering. @@ -57,7 +63,7 @@ export class AdvancedSettingsVoiceAnnouncement extends Component { const filteredSections = Object.values(this.props.settings).map(setting => setting.map(option => option.ariaName) ); - const filteredOptions = [].concat(...filteredSections); + const filteredOptions = [...filteredSections]; return (
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/advanced_settings_voice_announcement/index.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/advanced_settings_voice_announcement/index.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/advanced_settings_voice_announcement/index.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/components/advanced_settings_voice_announcement/index.ts diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/call_outs/__snapshots__/call_outs.test.js.snap b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/call_outs/__snapshots__/call_outs.test.tsx.snap similarity index 100% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/call_outs/__snapshots__/call_outs.test.js.snap rename to src/legacy/core_plugins/kibana/public/management/sections/settings/components/call_outs/__snapshots__/call_outs.test.tsx.snap diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/call_outs/call_outs.test.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/call_outs/call_outs.test.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/call_outs/call_outs.test.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/components/call_outs/call_outs.test.tsx diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/call_outs/call_outs.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/call_outs/call_outs.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/call_outs/call_outs.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/components/call_outs/call_outs.tsx diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/call_outs/index.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/call_outs/index.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/call_outs/index.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/components/call_outs/index.ts diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/component_registry.test.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/component_registry.test.tsx similarity index 74% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/component_registry.test.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/components/component_registry.test.tsx index fb3365a102fde6..24e9e5dd3809c8 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/component_registry.test.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/component_registry.test.tsx @@ -17,6 +17,7 @@ * under the License. */ +import React, { FunctionComponent } from 'react'; import { tryRegisterSettingsComponent, registerSettingsComponent, @@ -25,15 +26,15 @@ import { describe('tryRegisterSettingsComponent', () => { it('should allow a component to be registered', () => { - const component = {}; + const component = () =>
; expect(tryRegisterSettingsComponent('tryTest1', component)).toEqual(true); }); it('should return false if the component is already registered, and not allow an override', () => { - const component = {}; + const component = () =>
; expect(tryRegisterSettingsComponent('tryTest2', component)).toEqual(true); - const updatedComponent = { updated: 'yay' }; + const updatedComponent = () =>
; expect(tryRegisterSettingsComponent('tryTest2', updatedComponent)).toEqual(false); expect(getSettingsComponent('tryTest2')).toBe(component); }); @@ -41,49 +42,36 @@ describe('tryRegisterSettingsComponent', () => { describe('registerSettingsComponent', () => { it('should allow a component to be registered', () => { - const component = {}; + const component = () =>
; registerSettingsComponent('test', component); }); it('should disallow registering a component with a duplicate id', () => { - const component = {}; + const component = () =>
; registerSettingsComponent('test2', component); - expect(() => - registerSettingsComponent('test2', 'some other component') - ).toThrowErrorMatchingSnapshot(); + expect(() => registerSettingsComponent('test2', () => )).toThrowErrorMatchingSnapshot(); }); it('should allow a component to be overriden', () => { - const component = {}; + const component = () =>
; registerSettingsComponent('test3', component); - const anotherComponent = { anotherComponent: 'ok' }; + const anotherComponent = () => ; registerSettingsComponent('test3', anotherComponent, true); expect(getSettingsComponent('test3')).toBe(anotherComponent); }); - it('should set a displayName for the component if one does not exist', () => { - const component = {}; + it('should set a displayName for the component', () => { + const component = () =>
; registerSettingsComponent('display_name_component', component); - - expect(component.displayName).toEqual('display_name_component'); - }); - - it('should not set a displayName for the component if one already exists', () => { - const component = { - displayName: '', - }; - - registerSettingsComponent('another_display_name_component', component); - - expect(component.displayName).toEqual(''); + expect((component as FunctionComponent).displayName).toEqual('display_name_component'); }); }); describe('getSettingsComponent', () => { it('should allow a component to be retrieved', () => { - const component = {}; + const component = () =>
; registerSettingsComponent('test4', component); expect(getSettingsComponent('test4')).toBe(component); }); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/component_registry.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/component_registry.ts similarity index 81% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/component_registry.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/components/component_registry.ts index 4b81b74d20aa48..b58180c498edfe 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/component_registry.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/component_registry.ts @@ -17,7 +17,10 @@ * under the License. */ -const registry = {}; +import { ComponentType } from 'react'; + +type Id = string; +const registry: Record | undefined>> = {}; /** * Attempts to register the provided component. @@ -26,7 +29,10 @@ const registry = {}; * @param {*} id the id of the component to register * @param {*} component the component */ -export function tryRegisterSettingsComponent(id, component) { +export function tryRegisterSettingsComponent( + id: Id, + component: ComponentType | undefined> +) { if (id in registry) { return false; } @@ -45,7 +51,11 @@ export function tryRegisterSettingsComponent(id, component) { * @param {*} component the component * @param {*} allowOverride (default: false) - optional flag to allow this component to override a previously registered component */ -export function registerSettingsComponent(id, component, allowOverride = false) { +export function registerSettingsComponent( + id: Id, + component: ComponentType | undefined>, + allowOverride = false +) { if (!allowOverride && id in registry) { throw new Error(`Component with id ${id} is already registered.`); } @@ -65,7 +75,7 @@ export function registerSettingsComponent(id, component, allowOverride = false) * * @param {*} id the ID of the component to retrieve */ -export function getSettingsComponent(id) { +export function getSettingsComponent(id: Id): ComponentType | undefined> { if (!(id in registry)) { throw new Error(`Component not found with id ${id}`); } diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/default_component_registry.test.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/default_component_registry.test.tsx similarity index 96% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/default_component_registry.test.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/components/default_component_registry.test.tsx index 4fc6dc710f8669..ff3f75b79baefc 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/default_component_registry.test.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/default_component_registry.test.tsx @@ -17,6 +17,7 @@ * under the License. */ +import React from 'react'; import { registerDefaultComponents, PAGE_TITLE_COMPONENT } from './default_component_registry'; import { getSettingsComponent, registerSettingsComponent } from './component_registry'; import { PageTitle } from './page_title'; @@ -34,7 +35,7 @@ describe('default_component_registry', () => { }); it('should not override components if they are already registered', () => { - const newComponent = {}; + const newComponent = () =>
; registerSettingsComponent(PAGE_TITLE_COMPONENT, newComponent, true); registerDefaultComponents(); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/default_component_registry.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/default_component_registry.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/default_component_registry.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/components/default_component_registry.ts diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/__snapshots__/field.test.js.snap b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/__snapshots__/field.test.tsx.snap similarity index 99% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/__snapshots__/field.test.js.snap rename to src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/__snapshots__/field.test.tsx.snap index f4d20b45658802..915ee021e9b607 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/__snapshots__/field.test.js.snap +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/__snapshots__/field.test.tsx.snap @@ -1309,7 +1309,6 @@ exports[`Field for json setting should render as read only if saving is disabled Object { "value": {} @@ -1420,7 +1419,6 @@ exports[`Field for json setting should render as read only with help text if ove Object { "value": {} @@ -1637,7 +1635,6 @@ exports[`Field for json setting should render default value if there is no user Object { "value": {} @@ -1765,7 +1762,6 @@ exports[`Field for json setting should render user value if there is user value Object { "value": {} diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.test.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.test.tsx similarity index 84% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.test.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.test.tsx index 07ce6f84d2bb64..bd2ba8ac0ebcc6 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.test.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.test.tsx @@ -21,7 +21,10 @@ import React from 'react'; import { I18nProvider } from '@kbn/i18n/react'; import { shallowWithI18nProvider, mountWithI18nProvider } from 'test_utils/enzyme_helpers'; import { mount } from 'enzyme'; +import { FieldSetting } from '../../types'; +import { UiSettingsType, StringValidation } from '../../../../../../../../../core/public'; +// @ts-ignore import { findTestSubject } from '@elastic/eui/lib/test'; import { Field } from './field'; @@ -37,7 +40,13 @@ import { toastNotifications } from 'ui/notify'; jest.mock('brace/theme/textmate', () => 'brace/theme/textmate'); jest.mock('brace/mode/markdown', () => 'brace/mode/markdown'); -const settings = { +const defaults = { + requiresPageReload: false, + readOnly: false, + category: ['category'], +}; + +const settings: Record = { array: { name: 'array:test:setting', ariaName: 'array test setting', @@ -48,7 +57,7 @@ const settings = { defVal: ['default_value'], isCustom: false, isOverridden: false, - options: null, + ...defaults, }, boolean: { name: 'boolean:test:setting', @@ -60,7 +69,7 @@ const settings = { defVal: true, isCustom: false, isOverridden: false, - options: null, + ...defaults, }, image: { name: 'image:test:setting', @@ -78,6 +87,7 @@ const settings = { description: 'Description for 1 kB', }, }, + ...defaults, }, json: { name: 'json:test:setting', @@ -89,7 +99,7 @@ const settings = { defVal: '{}', isCustom: false, isOverridden: false, - options: null, + ...defaults, }, markdown: { name: 'markdown:test:setting', @@ -101,7 +111,7 @@ const settings = { defVal: '', isCustom: false, isOverridden: false, - options: null, + ...defaults, }, number: { name: 'number:test:setting', @@ -113,7 +123,7 @@ const settings = { defVal: 5, isCustom: false, isOverridden: false, - options: null, + ...defaults, }, select: { name: 'select:test:setting', @@ -131,6 +141,7 @@ const settings = { orange: 'Orange', // Deliberately left out `banana` to test if it also works with missing labels }, + ...defaults, }, string: { name: 'string:test:setting', @@ -142,7 +153,7 @@ const settings = { defVal: null, isCustom: false, isOverridden: false, - options: null, + ...defaults, }, stringWithValidation: { name: 'string:test-validation:setting', @@ -158,7 +169,7 @@ const settings = { defVal: 'foo-default', isCustom: false, isOverridden: false, - options: null, + ...defaults, }, }; const userValues = { @@ -175,8 +186,8 @@ const userValues = { const invalidUserValues = { stringWithValidation: 'invalidUserValue', }; -const save = jest.fn(() => Promise.resolve()); -const clear = jest.fn(() => Promise.resolve()); +const save = jest.fn(() => Promise.resolve(true)); +const clear = jest.fn(() => Promise.resolve(true)); describe('Field', () => { Object.keys(settings).forEach(type => { @@ -196,6 +207,7 @@ describe('Field', () => { { { /> ); const select = findTestSubject(component, `advancedSetting-editField-${setting.name}`); + // @ts-ignore const labels = select.find('option').map(option => option.prop('value')); expect(labels).toEqual(['apple', 'orange', 'banana']); }); @@ -280,13 +294,14 @@ describe('Field', () => { /> ); const select = findTestSubject(component, `advancedSetting-editField-${setting.name}`); + // @ts-ignore const labels = select.find('option').map(option => option.text()); expect(labels).toEqual(['Apple', 'Orange', 'banana']); }); } const setup = () => { - const Wrapper = props => ( + const Wrapper = (props: Record) => ( @@ -304,21 +319,22 @@ describe('Field', () => { describe(`for changing ${type} setting`, () => { const { wrapper, component } = setup(); const userValue = userValues[type]; - component.instance().getImageAsBase64 = file => Promise.resolve(file); + (component.instance() as Field).getImageAsBase64 = ({}: Blob) => Promise.resolve(''); it('should be able to change value from no value and cancel', async () => { - await component.instance().onImageChange([userValue]); + await (component.instance() as Field).onImageChange([userValue]); const updated = wrapper.update(); findTestSubject(updated, `advancedSetting-cancelEditField-${setting.name}`).simulate( 'click' ); expect( - component.instance().state.unsavedValue === component.instance().state.savedValue + (component.instance() as Field).state.unsavedValue === + (component.instance() as Field).state.savedValue ).toBe(true); }); it('should be able to change value and save', async () => { - await component.instance().onImageChange([userValue]); + await (component.instance() as Field).onImageChange([userValue]); const updated = wrapper.update(); findTestSubject(updated, `advancedSetting-saveEditField-${setting.name}`).simulate( 'click' @@ -327,12 +343,12 @@ describe('Field', () => { component.setState({ savedValue: userValue }); await wrapper.setProps({ setting: { - ...component.instance().props.setting, + ...(component.instance() as Field).props.setting, value: userValue, }, }); - await component.instance().cancelChangeImage(); + await (component.instance() as Field).cancelChangeImage(); wrapper.update(); }); @@ -341,7 +357,7 @@ describe('Field', () => { findTestSubject(updated, `advancedSetting-changeImage-${setting.name}`).simulate('click'); const newUserValue = `${userValue}=`; - await component.instance().onImageChange([newUserValue]); + await (component.instance() as Field).onImageChange([newUserValue]); const updated2 = wrapper.update(); findTestSubject(updated2, `advancedSetting-saveEditField-${setting.name}`).simulate( 'click' @@ -350,7 +366,7 @@ describe('Field', () => { component.setState({ savedValue: newUserValue }); await wrapper.setProps({ setting: { - ...component.instance().props.setting, + ...(component.instance() as Field).props.setting, value: newUserValue, }, }); @@ -370,18 +386,19 @@ describe('Field', () => { const fieldUserValue = userValue; it('should be able to change value and cancel', async () => { - component.instance().onCodeEditorChange(fieldUserValue); + (component.instance() as Field).onCodeEditorChange(fieldUserValue as UiSettingsType); const updated = wrapper.update(); findTestSubject(updated, `advancedSetting-cancelEditField-${setting.name}`).simulate( 'click' ); expect( - component.instance().state.unsavedValue === component.instance().state.savedValue + (component.instance() as Field).state.unsavedValue === + (component.instance() as Field).state.savedValue ).toBe(true); }); it('should be able to change value and save', async () => { - component.instance().onCodeEditorChange(fieldUserValue); + (component.instance() as Field).onCodeEditorChange(fieldUserValue as UiSettingsType); const updated = wrapper.update(); findTestSubject(updated, `advancedSetting-saveEditField-${setting.name}`).simulate( 'click' @@ -390,7 +407,7 @@ describe('Field', () => { component.setState({ savedValue: fieldUserValue }); await wrapper.setProps({ setting: { - ...component.instance().props.setting, + ...(component.instance() as Field).props.setting, value: userValue, }, }); @@ -399,9 +416,9 @@ describe('Field', () => { if (type === 'json') { it('should be able to clear value and have empty object populate', async () => { - component.instance().onCodeEditorChange(''); + (component.instance() as Field).onCodeEditorChange('' as UiSettingsType); wrapper.update(); - expect(component.instance().state.unsavedValue).toEqual('{}'); + expect((component.instance() as Field).state.unsavedValue).toEqual('{}'); }); } @@ -414,32 +431,35 @@ describe('Field', () => { } else { describe(`for changing ${type} setting`, () => { const { wrapper, component } = setup(); + // @ts-ignore const userValue = userValues[type]; const fieldUserValue = type === 'array' ? userValue.join(', ') : userValue; if (setting.validation) { + // @ts-ignore const invalidUserValue = invalidUserValues[type]; it('should display an error when validation fails', async () => { - component.instance().onFieldChange({ target: { value: invalidUserValue } }); + (component.instance() as Field).onFieldChange(invalidUserValue); const updated = wrapper.update(); const errorMessage = updated.find('.euiFormErrorText').text(); - expect(errorMessage).toEqual(setting.validation.message); + expect(errorMessage).toEqual((setting.validation as StringValidation).message); }); } it('should be able to change value and cancel', async () => { - component.instance().onFieldChange({ target: { value: fieldUserValue } }); + (component.instance() as Field).onFieldChange(fieldUserValue); const updated = wrapper.update(); findTestSubject(updated, `advancedSetting-cancelEditField-${setting.name}`).simulate( 'click' ); expect( - component.instance().state.unsavedValue === component.instance().state.savedValue + (component.instance() as Field).state.unsavedValue === + (component.instance() as Field).state.savedValue ).toBe(true); }); it('should be able to change value and save', async () => { - component.instance().onFieldChange({ target: { value: fieldUserValue } }); + (component.instance() as Field).onFieldChange(fieldUserValue); const updated = wrapper.update(); findTestSubject(updated, `advancedSetting-saveEditField-${setting.name}`).simulate( 'click' @@ -448,7 +468,7 @@ describe('Field', () => { component.setState({ savedValue: fieldUserValue }); await wrapper.setProps({ setting: { - ...component.instance().props.setting, + ...(component.instance() as Field).props.setting, value: userValue, }, }); @@ -472,7 +492,7 @@ describe('Field', () => { const wrapper = mountWithI18nProvider( ); - wrapper.instance().onFieldChange({ target: { value: 'a new value' } }); + (wrapper.instance() as Field).onFieldChange({ target: { value: 'a new value' } }); const updated = wrapper.update(); findTestSubject(updated, `advancedSetting-saveEditField-${setting.name}`).simulate('click'); expect(save).toHaveBeenCalled(); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.tsx similarity index 81% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.tsx index a2f201cf757f52..524160191d8f08 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.tsx @@ -18,7 +18,7 @@ */ import React, { PureComponent, Fragment } from 'react'; -import PropTypes from 'prop-types'; +import ReactDOM from 'react-dom'; import { npStart } from 'ui/new_platform'; import 'brace/theme/textmate'; @@ -35,6 +35,7 @@ import { EuiDescribedFormGroup, EuiFieldNumber, EuiFieldText, + // @ts-ignore EuiFilePicker, EuiFlexGroup, EuiFlexItem, @@ -47,22 +48,39 @@ import { EuiText, EuiSelect, EuiSwitch, + EuiSwitchEvent, keyCodes, } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; - +import { FieldSetting } from '../../types'; import { isDefaultValue } from '../../lib'; +import { + UiSettingsType, + ImageValidation, + StringValidationRegex, +} from '../../../../../../../../../core/public'; + +interface FieldProps { + setting: FieldSetting; + save: (name: string, value: string) => Promise; + clear: (name: string) => Promise; + enableSaving: boolean; +} -export class Field extends PureComponent { - static propTypes = { - setting: PropTypes.object.isRequired, - save: PropTypes.func.isRequired, - clear: PropTypes.func.isRequired, - enableSaving: PropTypes.bool.isRequired, - }; +interface FieldState { + unsavedValue: any; + savedValue: any; + loading: boolean; + isInvalid: boolean; + error: string | null; + changeImage: boolean; + isJsonArray: boolean; +} - constructor(props) { +export class Field extends PureComponent { + private changeImageForm: EuiFilePicker | undefined; + constructor(props: FieldProps) { super(props); const { type, value, defVal } = this.props.setting; const editableValue = this.getEditableValue(type, value, defVal); @@ -74,12 +92,11 @@ export class Field extends PureComponent { changeImage: false, savedValue: editableValue, unsavedValue: editableValue, - isJsonArray: type === 'json' ? Array.isArray(JSON.parse(defVal || '{}')) : false, + isJsonArray: type === 'json' ? Array.isArray(JSON.parse(String(defVal) || '{}')) : false, }; - this.changeImageForm = null; } - UNSAFE_componentWillReceiveProps(nextProps) { + UNSAFE_componentWillReceiveProps(nextProps: FieldProps) { const { unsavedValue } = this.state; const { type, value, defVal } = nextProps.setting; const editableValue = this.getEditableValue(type, value, defVal); @@ -90,11 +107,15 @@ export class Field extends PureComponent { }); } - getEditableValue(type, value, defVal) { + getEditableValue( + type: UiSettingsType, + value: FieldSetting['value'], + defVal: FieldSetting['defVal'] + ) { const val = value === null || value === undefined ? defVal : value; switch (type) { case 'array': - return val.join(', '); + return (val as string[]).join(', '); case 'boolean': return !!val; case 'number': @@ -106,21 +127,27 @@ export class Field extends PureComponent { } } - getDisplayedDefaultValue(type, defVal, optionLabels = {}) { + getDisplayedDefaultValue( + type: UiSettingsType, + defVal: FieldSetting['defVal'], + optionLabels: Record = {} + ) { if (defVal === undefined || defVal === null || defVal === '') { return 'null'; } switch (type) { case 'array': - return defVal.join(', '); + return (defVal as string[]).join(', '); case 'select': - return optionLabels.hasOwnProperty(defVal) ? optionLabels[defVal] : String(defVal); + return optionLabels.hasOwnProperty(String(defVal)) + ? optionLabels[String(defVal)] + : String(defVal); default: return String(defVal); } } - setLoading(loading) { + setLoading(loading: boolean) { this.setState({ loading, }); @@ -133,11 +160,11 @@ export class Field extends PureComponent { }); } - onCodeEditorChange = value => { + onCodeEditorChange = (value: UiSettingsType) => { const { type } = this.props.setting; const { isJsonArray } = this.state; - let newUnsavedValue = undefined; + let newUnsavedValue; let isInvalid = false; let error = null; @@ -148,12 +175,9 @@ export class Field extends PureComponent { JSON.parse(newUnsavedValue); } catch (e) { isInvalid = true; - error = ( - - ); + error = i18n.translate('kbn.management.settings.field.codeEditorSyntaxErrorMessage', { + defaultMessage: 'Invalid JSON syntax', + }); } break; default: @@ -167,12 +191,18 @@ export class Field extends PureComponent { }); }; - onFieldChange = e => { - const value = e.target.value; + onFieldChangeSwitch = (e: EuiSwitchEvent) => { + return this.onFieldChange(e.target.checked); + }; + + onFieldChangeEvent = (e: React.ChangeEvent) => + this.onFieldChange(e.target.value); + + onFieldChange = (value: any) => { const { type, validation } = this.props.setting; const { unsavedValue } = this.state; - let newUnsavedValue = undefined; + let newUnsavedValue; switch (type) { case 'boolean': @@ -186,11 +216,11 @@ export class Field extends PureComponent { } let isInvalid = false; - let error = undefined; + let error = null; - if (validation && validation.regex) { - if (!validation.regex.test(newUnsavedValue)) { - error = validation.message; + if (validation && (validation as StringValidationRegex).regex) { + if (!(validation as StringValidationRegex).regex!.test(newUnsavedValue.toString())) { + error = (validation as StringValidationRegex).message; isInvalid = true; } } @@ -202,7 +232,7 @@ export class Field extends PureComponent { }); }; - onFieldKeyDown = ({ keyCode }) => { + onFieldKeyDown = ({ keyCode }: { keyCode: number }) => { if (keyCode === keyCodes.ENTER) { this.saveEdit(); } @@ -211,13 +241,13 @@ export class Field extends PureComponent { } }; - onFieldEscape = ({ keyCode }) => { + onFieldEscape = ({ keyCode }: { keyCode: number }) => { if (keyCode === keyCodes.ESCAPE) { this.cancelEdit(); } }; - onImageChange = async files => { + onImageChange = async (files: any[]) => { if (!files.length) { this.clearError(); this.setState({ @@ -227,9 +257,12 @@ export class Field extends PureComponent { } const file = files[0]; - const { maxSize } = this.props.setting.validation; + const { maxSize } = this.props.setting.validation as ImageValidation; try { - const base64Image = await this.getImageAsBase64(file); + let base64Image = ''; + if (file instanceof File) { + base64Image = (await this.getImageAsBase64(file)) as string; + } const isInvalid = !!(maxSize && maxSize.length && base64Image.length > maxSize.length); this.setState({ isInvalid, @@ -254,17 +287,13 @@ export class Field extends PureComponent { } }; - getImageAsBase64(file) { - if (!file instanceof File) { - return null; - } - + async getImageAsBase64(file: Blob): Promise { const reader = new FileReader(); reader.readAsDataURL(file); return new Promise((resolve, reject) => { reader.onload = () => { - resolve(reader.result); + resolve(reader.result || undefined); }; reader.onerror = err => { reject(err); @@ -309,20 +338,24 @@ export class Field extends PureComponent { settingName: this.props.setting.displayName || this.props.setting.name, }, }), - text: ( - <> - - - window.location.reload()}> - {i18n.translate( - 'kbn.management.settings.field.requiresPageReloadToastButtonLabel', - { defaultMessage: 'Reload page' } - )} - - - - - ), + text: element => { + const content = ( + <> + + + window.location.reload()}> + {i18n.translate( + 'kbn.management.settings.field.requiresPageReloadToastButtonLabel', + { defaultMessage: 'Reload page' } + )} + + + + + ); + ReactDOM.render(content, element); + return () => ReactDOM.unmountComponentAtNode(element); + }, color: 'success', }); } @@ -341,8 +374,8 @@ export class Field extends PureComponent { switch (type) { case 'array': - valueToSave = valueToSave.split(',').map(val => val.trim()); - isSameValue = valueToSave.join(',') === defVal.join(','); + valueToSave = valueToSave.split(',').map((val: string) => val.trim()); + isSameValue = valueToSave.join(',') === (defVal as string[]).join(','); break; case 'json': valueToSave = valueToSave.trim(); @@ -394,7 +427,7 @@ export class Field extends PureComponent { this.setLoading(false); }; - renderField(setting) { + renderField(setting: FieldSetting) { const { enableSaving } = this.props; const { loading, changeImage, unsavedValue } = this.state; const { name, value, type, options, optionLabels = {}, isOverridden, ariaName } = setting; @@ -414,7 +447,7 @@ export class Field extends PureComponent { ) } checked={!!unsavedValue} - onChange={this.onFieldChange} + onChange={this.onFieldChangeSwitch} disabled={loading || isOverridden || !enableSaving} onKeyDown={this.onFieldKeyDown} data-test-subj={`advancedSetting-editField-${name}`} @@ -449,14 +482,16 @@ export class Field extends PureComponent { ); case 'image': if (!isDefaultValue(setting) && !changeImage) { - return ; + return ( + + ); } else { return ( { + ref={(input: HTMLInputElement) => { this.changeImageForm = input; }} onKeyDown={this.onFieldEscape} @@ -469,13 +504,13 @@ export class Field extends PureComponent { { + options={(options as string[]).map(option => { return { text: optionLabels.hasOwnProperty(option) ? optionLabels[option] : option, value: option, }; })} - onChange={this.onFieldChange} + onChange={this.onFieldChangeEvent} isLoading={loading} disabled={loading || isOverridden || !enableSaving} onKeyDown={this.onFieldKeyDown} @@ -487,7 +522,7 @@ export class Field extends PureComponent { @@ -541,7 +576,7 @@ export class Field extends PureComponent { return null; } - renderTitle(setting) { + renderTitle(setting: FieldSetting) { return (

{setting.displayName || setting.name} @@ -566,7 +601,7 @@ export class Field extends PureComponent { ); } - renderDescription(setting) { + renderDescription(setting: FieldSetting) { let description; let deprecation; @@ -579,7 +614,7 @@ export class Field extends PureComponent { { - window.open(links.management[setting.deprecation.docLinksKey], '_blank'); + window.open(links.management[setting.deprecation!.docLinksKey], '_blank'); }} onClickAriaLabel={i18n.translate( 'kbn.management.settings.field.deprecationClickAreaLabel', @@ -608,7 +643,7 @@ export class Field extends PureComponent { * Justification for dangerouslySetInnerHTML: * Setting description may contain formatting and links to documentation. */ - dangerouslySetInnerHTML={{ __html: setting.description }} //eslint-disable-line react/no-danger + dangerouslySetInnerHTML={{ __html: setting.description || '' }} // eslint-disable-line react/no-danger /> ); } @@ -622,7 +657,7 @@ export class Field extends PureComponent { ); } - renderDefaultValue(setting) { + renderDefaultValue(setting: FieldSetting) { const { type, defVal, optionLabels } = setting; if (isDefaultValue(setting)) { return; @@ -641,7 +676,7 @@ export class Field extends PureComponent { = 500 ? 300 : null} + overflowHeight={(defVal as string).length >= 500 ? 300 : undefined} > {this.getDisplayedDefaultValue(type, defVal)} @@ -667,7 +702,7 @@ export class Field extends PureComponent { ); } - renderResetToDefaultLink(setting) { + renderResetToDefaultLink(setting: FieldSetting) { const { ariaName, name } = setting; if (isDefaultValue(setting)) { return; @@ -694,7 +729,7 @@ export class Field extends PureComponent { ); } - renderChangeImageLink(setting) { + renderChangeImageLink(setting: FieldSetting) { const { changeImage } = this.state; const { type, value, ariaName, name } = setting; if (type !== 'image' || !value || changeImage) { @@ -721,7 +756,7 @@ export class Field extends PureComponent { ); } - renderActions(setting) { + renderActions(setting: FieldSetting) { const { ariaName, name } = setting; const { loading, isInvalid, changeImage, savedValue, unsavedValue } = this.state; const isDisabled = loading || setting.isOverridden; @@ -798,6 +833,7 @@ export class Field extends PureComponent { helpText={this.renderHelpText(setting)} describedByIds={[`${setting.name}-aria`]} className="mgtAdvancedSettings__fieldRow" + // @ts-ignore hasChildLabel={setting.type !== 'boolean'} > {this.renderField(setting)} diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/index.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/index.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/index.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/index.ts diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/form/__snapshots__/form.test.js.snap b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/form/__snapshots__/form.test.tsx.snap similarity index 79% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/form/__snapshots__/form.test.js.snap rename to src/legacy/core_plugins/kibana/public/management/sections/settings/components/form/__snapshots__/form.test.tsx.snap index 4111b3d5fa2d3f..b43c17c2a88656 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/form/__snapshots__/form.test.js.snap +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/form/__snapshots__/form.test.tsx.snap @@ -61,9 +61,16 @@ exports[`Form should render normally 1`] = ` "category": Array [ "general", ], - "description": "bar", + "defVal": "defVal", + "description": "description", "displayName": "Test date", + "isCustom": false, + "isOverridden": false, "name": "general:test:date", + "readOnly": false, + "requiresPageReload": false, + "type": "string", + "value": "value", } } /> @@ -78,9 +85,16 @@ exports[`Form should render normally 1`] = ` "category": Array [ "general", ], - "description": "foo", + "defVal": "defVal", + "description": "description", "displayName": "Test setting", + "isCustom": false, + "isOverridden": false, "name": "setting:test", + "readOnly": false, + "requiresPageReload": false, + "type": "string", + "value": "value", } } /> @@ -120,8 +134,16 @@ exports[`Form should render normally 1`] = ` "category": Array [ "dashboard", ], + "defVal": "defVal", + "description": "description", "displayName": "Dashboard test setting", + "isCustom": false, + "isOverridden": false, "name": "dashboard:test:setting", + "readOnly": false, + "requiresPageReload": false, + "type": "string", + "value": "value", } } /> @@ -187,9 +209,16 @@ exports[`Form should render normally 1`] = ` "category": Array [ "x-pack", ], - "description": "bar", + "defVal": "defVal", + "description": "description", "displayName": "X-Pack test setting", + "isCustom": false, + "isOverridden": false, "name": "xpack:test:setting", + "readOnly": false, + "requiresPageReload": false, + "type": "string", + "value": "value", } } /> @@ -234,9 +263,16 @@ exports[`Form should render read-only when saving is disabled 1`] = ` "category": Array [ "general", ], - "description": "bar", + "defVal": "defVal", + "description": "description", "displayName": "Test date", + "isCustom": false, + "isOverridden": false, "name": "general:test:date", + "readOnly": false, + "requiresPageReload": false, + "type": "string", + "value": "value", } } /> @@ -251,9 +287,16 @@ exports[`Form should render read-only when saving is disabled 1`] = ` "category": Array [ "general", ], - "description": "foo", + "defVal": "defVal", + "description": "description", "displayName": "Test setting", + "isCustom": false, + "isOverridden": false, "name": "setting:test", + "readOnly": false, + "requiresPageReload": false, + "type": "string", + "value": "value", } } /> @@ -293,8 +336,16 @@ exports[`Form should render read-only when saving is disabled 1`] = ` "category": Array [ "dashboard", ], + "defVal": "defVal", + "description": "description", "displayName": "Dashboard test setting", + "isCustom": false, + "isOverridden": false, "name": "dashboard:test:setting", + "readOnly": false, + "requiresPageReload": false, + "type": "string", + "value": "value", } } /> @@ -360,9 +411,16 @@ exports[`Form should render read-only when saving is disabled 1`] = ` "category": Array [ "x-pack", ], - "description": "bar", + "defVal": "defVal", + "description": "description", "displayName": "X-Pack test setting", + "isCustom": false, + "isOverridden": false, "name": "xpack:test:setting", + "readOnly": false, + "requiresPageReload": false, + "type": "string", + "value": "value", } } /> diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/form/form.test.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/form/form.test.tsx similarity index 88% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/form/form.test.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/components/form/form.test.tsx index 7befed814e5d0a..6bbcfd543a6290 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/form/form.test.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/form/form.test.tsx @@ -19,6 +19,7 @@ import React from 'react'; import { shallowWithI18nProvider } from 'test_utils/enzyme_helpers'; +import { UiSettingsType } from '../../../../../../../../../core/public'; import { Form } from './form'; @@ -28,6 +29,17 @@ jest.mock('../field', () => ({ }, })); +const defaults = { + requiresPageReload: false, + readOnly: false, + value: 'value', + description: 'description', + isOverridden: false, + type: 'string' as UiSettingsType, + isCustom: false, + defVal: 'defVal', +}; + const settings = { dashboard: [ { @@ -35,6 +47,7 @@ const settings = { ariaName: 'dashboard test setting', displayName: 'Dashboard test setting', category: ['dashboard'], + ...defaults, }, ], general: [ @@ -44,6 +57,7 @@ const settings = { displayName: 'Test date', description: 'bar', category: ['general'], + ...defaults, }, { name: 'setting:test', @@ -51,6 +65,7 @@ const settings = { displayName: 'Test setting', description: 'foo', category: ['general'], + ...defaults, }, ], 'x-pack': [ @@ -60,6 +75,7 @@ const settings = { displayName: 'X-Pack test setting', category: ['x-pack'], description: 'bar', + ...defaults, }, ], }; @@ -69,8 +85,8 @@ const categoryCounts = { dashboard: 1, 'x-pack': 10, }; -const save = () => {}; -const clear = () => {}; +const save = (key: string, value: any) => Promise.resolve(true); +const clear = (key: string) => Promise.resolve(true); const clearQuery = () => {}; describe('Form', () => { diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/form/form.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/form/form.tsx similarity index 84% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/form/form.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/components/form/form.tsx index 19d8b9da446c76..113e0b2db5f308 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/form/form.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/form/form.tsx @@ -18,7 +18,6 @@ */ import React, { PureComponent, Fragment } from 'react'; -import PropTypes from 'prop-types'; import { EuiFlexGroup, @@ -33,20 +32,23 @@ import { FormattedMessage } from '@kbn/i18n/react'; import { getCategoryName } from '../../lib'; import { Field } from '../field'; +import { FieldSetting } from '../../types'; -export class Form extends PureComponent { - static propTypes = { - settings: PropTypes.object.isRequired, - categories: PropTypes.array.isRequired, - categoryCounts: PropTypes.object.isRequired, - clearQuery: PropTypes.func.isRequired, - save: PropTypes.func.isRequired, - clear: PropTypes.func.isRequired, - showNoResultsMessage: PropTypes.bool.isRequired, - enableSaving: PropTypes.bool.isRequired, - }; +type Category = string; - renderClearQueryLink(totalSettings, currentSettings) { +interface FormProps { + settings: Record; + categories: Category[]; + categoryCounts: Record; + clearQuery: () => void; + save: (key: string, value: any) => Promise; + clear: (key: string) => Promise; + showNoResultsMessage: boolean; + enableSaving: boolean; +} + +export class Form extends PureComponent { + renderClearQueryLink(totalSettings: number, currentSettings: number) { const { clearQuery } = this.props; if (totalSettings !== currentSettings) { @@ -78,7 +80,7 @@ export class Form extends PureComponent { return null; } - renderCategory(category, settings, totalSettings) { + renderCategory(category: Category, settings: FieldSetting[], totalSettings: number) { return ( @@ -110,7 +112,7 @@ export class Form extends PureComponent { ); } - maybeRenderNoSettings(clearQuery) { + maybeRenderNoSettings(clearQuery: FormProps['clearQuery']) { if (this.props.showNoResultsMessage) { return ( @@ -136,7 +138,7 @@ export class Form extends PureComponent { render() { const { settings, categories, categoryCounts, clearQuery } = this.props; - const currentCategories = []; + const currentCategories: Category[] = []; categories.forEach(category => { if (settings[category] && settings[category].length) { @@ -148,7 +150,7 @@ export class Form extends PureComponent { {currentCategories.length ? currentCategories.map(category => { - return this.renderCategory(category, settings[category], categoryCounts[category]); // fix this + return this.renderCategory(category, settings[category], categoryCounts[category]); }) : this.maybeRenderNoSettings(clearQuery)} diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/form/index.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/form/index.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/form/index.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/components/form/index.ts diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_footer/__snapshots__/page_footer.test.js.snap b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_footer/__snapshots__/page_footer.test.tsx.snap similarity index 100% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_footer/__snapshots__/page_footer.test.js.snap rename to src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_footer/__snapshots__/page_footer.test.tsx.snap diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_footer/index.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_footer/index.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_footer/index.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_footer/index.ts diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_footer/page_footer.test.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_footer/page_footer.test.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_footer/page_footer.test.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_footer/page_footer.test.tsx diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_footer/page_footer.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_footer/page_footer.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_footer/page_footer.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_footer/page_footer.ts diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_subtitle/__snapshots__/page_subtitle.test.js.snap b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_subtitle/__snapshots__/page_subtitle.test.tsx.snap similarity index 100% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_subtitle/__snapshots__/page_subtitle.test.js.snap rename to src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_subtitle/__snapshots__/page_subtitle.test.tsx.snap diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_subtitle/index.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_subtitle/index.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_subtitle/index.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_subtitle/index.ts diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_subtitle/page_subtitle.test.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_subtitle/page_subtitle.test.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_subtitle/page_subtitle.test.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_subtitle/page_subtitle.test.tsx diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_subtitle/page_subtitle.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_subtitle/page_subtitle.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_subtitle/page_subtitle.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_subtitle/page_subtitle.ts diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_title/__snapshots__/page_title.test.js.snap b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_title/__snapshots__/page_title.test.tsx.snap similarity index 100% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_title/__snapshots__/page_title.test.js.snap rename to src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_title/__snapshots__/page_title.test.tsx.snap diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_title/index.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_title/index.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_title/index.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_title/index.ts diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_title/page_title.test.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_title/page_title.test.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_title/page_title.test.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_title/page_title.test.tsx diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_title/page_title.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_title/page_title.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_title/page_title.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_title/page_title.tsx diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/__snapshots__/search.test.js.snap b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/__snapshots__/search.test.tsx.snap similarity index 100% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/__snapshots__/search.test.js.snap rename to src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/__snapshots__/search.test.tsx.snap diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/index.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/index.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/index.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/index.ts diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/search.test.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/search.test.tsx similarity index 97% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/search.test.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/search.test.tsx index 3cd2de6ddccaa7..8e7bac5129ae94 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/search.test.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/search.test.tsx @@ -19,6 +19,7 @@ import React from 'react'; import { shallowWithI18nProvider, mountWithI18nProvider } from 'test_utils/enzyme_helpers'; +// @ts-ignore import { findTestSubject } from '@elastic/eui/lib/test'; import { Query } from '@elastic/eui'; @@ -38,7 +39,7 @@ describe('Search', () => { }); it('should call parent function when query is changed', async () => { - //This test is brittle as it knows about implementation details + // This test is brittle as it knows about implementation details // (EuiFieldSearch uses onKeyup instead of onChange to handle input) const onQueryChange = jest.fn(); const component = mountWithI18nProvider( diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/search.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/search.tsx similarity index 84% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/search.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/search.tsx index 02315e73cc11b8..471f2ba28005ca 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/search.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/search.tsx @@ -18,21 +18,26 @@ */ import React, { Fragment, PureComponent } from 'react'; -import PropTypes from 'prop-types'; import { i18n } from '@kbn/i18n'; - -import { EuiSearchBar, EuiFormErrorText } from '@elastic/eui'; +import { + // @ts-ignore + EuiSearchBar, + EuiFormErrorText, +} from '@elastic/eui'; +import { IQuery } from '../../types'; import { getCategoryName } from '../../lib'; -export class Search extends PureComponent { - static propTypes = { - categories: PropTypes.array.isRequired, - query: PropTypes.object.isRequired, - onQueryChange: PropTypes.func.isRequired, - }; +interface SearchProps { + categories: string[]; + query: IQuery; + onQueryChange: ({ query }: { query: IQuery }) => void; +} + +export class Search extends PureComponent { + private categories: Array<{ value: string; name: string }> = []; - constructor(props) { + constructor(props: SearchProps) { super(props); const { categories } = props; this.categories = categories.map(category => { @@ -48,7 +53,7 @@ export class Search extends PureComponent { parseErrorMessage: null, }; - onChange = ({ query, error }) => { + onChange = ({ query, error }: { query: IQuery; error: { message: string } }) => { if (error) { this.setState({ isSearchTextValid: false, diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/index.html b/src/legacy/core_plugins/kibana/public/management/sections/settings/index.html index e1b901a9669606..2fe8fce08b4abc 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/index.html +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/index.html @@ -1,5 +1,5 @@ -
+
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/index.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/index.js index f03dcd195092aa..6d8987b1a928e5 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/index.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/index.js @@ -29,38 +29,10 @@ import { } from 'ui/registry/feature_catalogue'; import React from 'react'; -import { render, unmountComponentAtNode } from 'react-dom'; import { AdvancedSettings } from './advanced_settings'; import { i18n } from '@kbn/i18n'; import { getBreadcrumbs } from './breadcrumbs'; -const REACT_ADVANCED_SETTINGS_DOM_ELEMENT_ID = 'reactAdvancedSettings'; - -function updateAdvancedSettings($scope, config, query) { - $scope.$$postDigest(() => { - const node = document.getElementById(REACT_ADVANCED_SETTINGS_DOM_ELEMENT_ID); - if (!node) { - return; - } - - render( - - - , - node - ); - }); -} - -function destroyAdvancedSettings() { - const node = document.getElementById(REACT_ADVANCED_SETTINGS_DOM_ELEMENT_ID); - node && unmountComponentAtNode(node); -} - uiRoutes.when('/management/kibana/settings/:setting?', { template: indexTemplate, k7Breadcrumbs: getBreadcrumbs, @@ -82,23 +54,28 @@ uiRoutes.when('/management/kibana/settings/:setting?', { }, }); -uiModules.get('apps/management').directive('kbnManagementAdvanced', function(config, $route) { +uiModules.get('apps/management').directive('kbnManagementAdvanced', function($route) { return { restrict: 'E', link: function($scope) { - config.watchAll(() => { - updateAdvancedSettings($scope, config, $route.current.params.setting || ''); - }, $scope); - - $scope.$on('$destroy', () => { - destroyAdvancedSettings(); - }); - + $scope.query = $route.current.params.setting || ''; $route.updateParams({ setting: null }); }, }; }); +const AdvancedSettingsApp = ({ query = '' }) => { + return ( + + + + ); +}; + +uiModules.get('apps/management').directive('kbnManagementAdvancedReact', function(reactDirective) { + return reactDirective(AdvancedSettingsApp, [['query', { watchDepth: 'reference' }]]); +}); + management.getSection('kibana').register('settings', { display: i18n.translate('kbn.management.settings.sectionLabel', { defaultMessage: 'Advanced Settings', diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/__tests__/get_category_name.test.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/__tests__/get_category_name.test.js deleted file mode 100644 index 731281933161b3..00000000000000 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/__tests__/get_category_name.test.js +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import expect from '@kbn/expect'; -import { getCategoryName } from '../get_category_name'; - -describe('Settings', function() { - describe('Advanced', function() { - describe('getCategoryName(category)', function() { - it('should be a function', function() { - expect(getCategoryName).to.be.a(Function); - }); - - it('should return correct name for known categories', function() { - expect(getCategoryName('general')).to.be('General'); - expect(getCategoryName('timelion')).to.be('Timelion'); - expect(getCategoryName('notifications')).to.be('Notifications'); - expect(getCategoryName('visualizations')).to.be('Visualizations'); - expect(getCategoryName('discover')).to.be('Discover'); - expect(getCategoryName('dashboard')).to.be('Dashboard'); - expect(getCategoryName('reporting')).to.be('Reporting'); - expect(getCategoryName('search')).to.be('Search'); - }); - - it('should capitalize unknown category', function() { - expect(getCategoryName('elasticsearch')).to.be('Elasticsearch'); - }); - - it('should return empty string for no category', function() { - expect(getCategoryName()).to.be(''); - expect(getCategoryName('')).to.be(''); - expect(getCategoryName(false)).to.be(''); - }); - }); - }); -}); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/default_category.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/default_category.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/lib/default_category.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/lib/default_category.ts diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/__tests__/get_aria_name.test.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_aria_name.test.ts similarity index 88% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/lib/__tests__/get_aria_name.test.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_aria_name.test.ts index 0e54480813e3fb..e129481a397c16 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/__tests__/get_aria_name.test.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_aria_name.test.ts @@ -18,15 +18,11 @@ */ import expect from '@kbn/expect'; -import { getAriaName } from '../get_aria_name'; +import { getAriaName } from './get_aria_name'; describe('Settings', function() { describe('Advanced', function() { describe('getAriaName(name)', function() { - it('should be a function', function() { - expect(getAriaName).to.be.a(Function); - }); - it('should return a space delimited lower-case string with no special characters', function() { expect(getAriaName('xPack:defaultAdminEmail')).to.be('x pack default admin email'); expect(getAriaName('doc_table:highlight')).to.be('doc table highlight'); @@ -36,7 +32,6 @@ describe('Settings', function() { it('should return an empty string if passed undefined or null', function() { expect(getAriaName()).to.be(''); expect(getAriaName(undefined)).to.be(''); - expect(getAriaName(null)).to.be(''); }); }); }); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_aria_name.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_aria_name.ts similarity index 93% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_aria_name.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_aria_name.ts index c75c761328370d..d5c2be752a278a 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_aria_name.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_aria_name.ts @@ -26,8 +26,8 @@ import { words } from 'lodash'; * * Example: 'xPack:fooBar:foo_bar_baz' -> 'x pack foo bar foo bar baz' */ -export function getAriaName(name) { - return words(name) +export function getAriaName(name?: string) { + return words(name || '') .map(word => word.toLowerCase()) .join(' '); } diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/__tests__/default_category.test.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_category_name.test.ts similarity index 69% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/lib/__tests__/default_category.test.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_category_name.test.ts index 1172542dbce3d0..73e303e20c64d7 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/__tests__/default_category.test.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_category_name.test.ts @@ -18,13 +18,18 @@ */ import expect from '@kbn/expect'; -import { DEFAULT_CATEGORY } from '../default_category'; +import { getCategoryName } from './get_category_name'; describe('Settings', function() { describe('Advanced', function() { - describe('DEFAULT_CATEGORY', function() { - it('should be general', function() { - expect(DEFAULT_CATEGORY).to.be('general'); + describe('getCategoryName(category)', function() { + it('should capitalize unknown category', function() { + expect(getCategoryName('elasticsearch')).to.be('Elasticsearch'); + }); + + it('should return empty string for no category', function() { + expect(getCategoryName()).to.be(''); + expect(getCategoryName('')).to.be(''); }); }); }); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_category_name.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_category_name.ts similarity index 92% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_category_name.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_category_name.ts index c64b332e8ebee3..d0361ba698eebf 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_category_name.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_category_name.ts @@ -19,9 +19,9 @@ import { i18n } from '@kbn/i18n'; -const upperFirst = (str = '') => str.replace(/^./, str => str.toUpperCase()); +const upperFirst = (str = '') => str.replace(/^./, strng => strng.toUpperCase()); -const names = { +const names: Record = { general: i18n.translate('kbn.management.settings.categoryNames.generalLabel', { defaultMessage: 'General', }), @@ -51,6 +51,6 @@ const names = { }), }; -export function getCategoryName(category) { +export function getCategoryName(category?: string) { return category ? names[category] || upperFirst(category) : ''; } diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/__tests__/get_val_type.test.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_val_type.test.ts similarity index 93% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/lib/__tests__/get_val_type.test.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_val_type.test.ts index 0a6cce972e518b..ec59dcaa1ea290 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/__tests__/get_val_type.test.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_val_type.test.ts @@ -18,15 +18,11 @@ */ import expect from '@kbn/expect'; -import { getValType } from '../get_val_type'; +import { getValType } from './get_val_type'; describe('Settings', function() { describe('Advanced', function() { describe('getValType(def, val)', function() { - it('should be a function', function() { - expect(getValType).to.be.a(Function); - }); - it('should return the explicitly defined type of a setting', function() { expect(getValType({ type: 'string' })).to.be('string'); expect(getValType({ type: 'json' })).to.be('json'); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_val_type.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_val_type.ts similarity index 67% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_val_type.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_val_type.ts index 35ed1f14332ede..e0aafb6710b7b4 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_val_type.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_val_type.ts @@ -22,7 +22,11 @@ * @param {?} current value of the setting * @returns {string} the type to use for determining the display and editor */ -export function getValType(def, value) { + +import { UiSettingsType } from 'src/core/public'; +import { FieldSetting } from '../types'; + +export function getValType(def: Partial, value?: any): UiSettingsType { if (def.type) { return def.type; } @@ -31,5 +35,17 @@ export function getValType(def, value) { return 'array'; } - return def.value != null ? typeof def.value : typeof value; + const typeofVal = def.value != null ? typeof def.value : typeof value; + + if (typeofVal === 'bigint') { + return 'number'; + } + + if (typeofVal === 'symbol' || typeofVal === 'object' || typeofVal === 'function') { + throw new Error( + `incompatible UiSettingsType: '${def.name}' type ${typeofVal} | ${JSON.stringify(def)}` + ); + } + + return typeofVal; } diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/index.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/index.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/lib/index.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/lib/index.ts diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/__tests__/is_default_value.test.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/is_default_value.test.ts similarity index 84% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/lib/__tests__/is_default_value.test.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/lib/is_default_value.test.ts index 58ffd0597a34a9..30531ca89b0b58 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/__tests__/is_default_value.test.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/is_default_value.test.ts @@ -18,20 +18,29 @@ */ import expect from '@kbn/expect'; -import { isDefaultValue } from '../is_default_value'; +import { isDefaultValue } from './is_default_value'; +import { UiSettingsType } from '../../../../../../../../core/public'; describe('Settings', function() { describe('Advanced', function() { describe('getCategoryName(category)', function() { - it('should be a function', function() { - expect(isDefaultValue).to.be.a(Function); - }); - describe('when given a setting definition object', function() { const setting = { isCustom: false, value: 'value', defVal: 'defaultValue', + displayName: 'displayName', + name: 'name', + ariaName: 'ariaName', + description: 'description', + requiresPageReload: false, + type: 'string' as UiSettingsType, + isOverridden: false, + readOnly: false, + options: [], + optionLabels: { option: 'label' }, + category: ['category'], + validation: { regex: /regexString/, message: 'validation description' }, }; describe('that is custom', function() { diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/is_default_value.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/is_default_value.ts similarity index 90% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/lib/is_default_value.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/lib/is_default_value.ts index 166aed6aeb5130..53c2ef3187f091 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/is_default_value.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/is_default_value.ts @@ -16,8 +16,9 @@ * specific language governing permissions and limitations * under the License. */ +import { FieldSetting } from '../types'; -export function isDefaultValue(setting) { +export function isDefaultValue(setting: FieldSetting) { return ( setting.isCustom || setting.value === undefined || diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/__tests__/to_editable_config.test.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/to_editable_config.test.ts similarity index 75% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/lib/__tests__/to_editable_config.test.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/lib/to_editable_config.test.ts index 4896b4516dd1da..881a2eb003cc81 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/__tests__/to_editable_config.test.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/to_editable_config.test.ts @@ -17,8 +17,25 @@ * under the License. */ +import { UiSettingsParams, StringValidationRegex } from 'src/core/public'; import expect from '@kbn/expect'; -import { toEditableConfig } from '../to_editable_config'; +import { toEditableConfig } from './to_editable_config'; + +const defDefault = { + isOverridden: true, +}; + +function invoke({ + def = defDefault, + name = 'woah', + value = 'forreal', +}: { + def?: UiSettingsParams & { isOverridden?: boolean }; + name?: string; + value?: any; +}) { + return toEditableConfig({ def, name, value, isCustom: def === defDefault, isOverridden: true }); +} describe('Settings', function() { describe('Advanced', function() { @@ -38,17 +55,17 @@ describe('Settings', function() { }); describe('when given a setting definition object', function() { - let def; + let def: UiSettingsParams & { isOverridden?: boolean }; beforeEach(function() { def = { value: 'the original', description: 'the one and only', - options: 'all the options', + options: ['all the options'], }; }); it('is not marked as custom', function() { - expect(invoke({ def }).isCustom).to.be.false; + expect(invoke({ def }).isCustom).to.be(false); }); it('sets a default value', function() { @@ -65,7 +82,7 @@ describe('Settings', function() { describe('that contains a type', function() { it('sets that type', function() { - def.type = 'something'; + def.type = 'string'; expect(invoke({ def }).type).to.equal(def.type); }); }); @@ -84,37 +101,34 @@ describe('Settings', function() { message: 'must start with "foo"', }; const result = invoke({ def }); - expect(result.validation.regex).to.be.a(RegExp); - expect(result.validation.message).to.equal('must start with "foo"'); + const validationTyped = result.validation as StringValidationRegex; + expect(validationTyped.regex).to.be.a(RegExp); + expect(validationTyped.message).to.equal('must start with "foo"'); }); }); }); describe('when not given a setting definition object', function() { it('is marked as custom', function() { - expect(invoke().isCustom).to.be.true; + expect(invoke({}).isCustom).to.be(true); }); it('sets defVal to undefined', function() { - expect(invoke().defVal).to.be.undefined; + expect(invoke({}).defVal).to.be(undefined); }); it('sets description to undefined', function() { - expect(invoke().description).to.be.undefined; + expect(invoke({}).description).to.be(undefined); }); it('sets options to undefined', function() { - expect(invoke().options).to.be.undefined; + expect(invoke({}).options).to.be(undefined); }); it('sets validation to undefined', function() { - expect(invoke().validation).to.be.undefined; + expect(invoke({}).validation).to.be(undefined); }); }); }); }); }); - -function invoke({ def = false, name = 'woah', value = 'forreal' } = {}) { - return toEditableConfig({ def, name, value, isCustom: def === false }); -} diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/to_editable_config.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/to_editable_config.ts similarity index 74% rename from src/legacy/core_plugins/kibana/public/management/sections/settings/lib/to_editable_config.js rename to src/legacy/core_plugins/kibana/public/management/sections/settings/lib/to_editable_config.ts index 6efb89cfba2b25..2c27d72f7f645a 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/to_editable_config.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/lib/to_editable_config.ts @@ -17,6 +17,12 @@ * under the License. */ +import { + UiSettingsParams, + UserProvidedValues, + StringValidationRegexString, + SavedObjectAttribute, +} from 'src/core/public'; import { getValType } from './get_val_type'; import { getAriaName } from './get_aria_name'; import { DEFAULT_CATEGORY } from './default_category'; @@ -27,10 +33,25 @@ import { DEFAULT_CATEGORY } from './default_category'; * @param {object} current value of setting * @returns {object} the editable config object */ -export function toEditableConfig({ def, name, value, isCustom, isOverridden }) { +export function toEditableConfig({ + def, + name, + value, + isCustom, + isOverridden, +}: { + def: UiSettingsParams & UserProvidedValues; + name: string; + value: SavedObjectAttribute; + isCustom: boolean; + isOverridden: boolean; +}) { if (!def) { def = {}; } + + const validationTyped = def.validation as StringValidationRegexString; + const conf = { name, displayName: def.name || name, @@ -45,10 +66,10 @@ export function toEditableConfig({ def, name, value, isCustom, isOverridden }) { description: def.description, deprecation: def.deprecation, validation: - def.validation && def.validation.regexString + validationTyped && validationTyped.regexString ? { - regex: new RegExp(def.validation.regexString), - message: def.validation.message, + regex: new RegExp(validationTyped.regexString), + message: validationTyped.message, } : def.validation, options: def.options, diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/types.ts b/src/legacy/core_plugins/kibana/public/management/sections/settings/types.ts new file mode 100644 index 00000000000000..fea70110f60711 --- /dev/null +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/types.ts @@ -0,0 +1,54 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { + UiSettingsType, + StringValidation, + ImageValidation, + SavedObjectAttribute, +} from '../../../../../../../core/public'; + +export interface FieldSetting { + displayName: string; + name: string; + value: SavedObjectAttribute; + description?: string; + options?: string[]; + optionLabels?: Record; + requiresPageReload: boolean; + type: UiSettingsType; + category: string[]; + ariaName: string; + isOverridden: boolean; + defVal: SavedObjectAttribute; + isCustom: boolean; + validation?: StringValidation | ImageValidation; + readOnly?: boolean; + deprecation?: { + message: string; + docLinksKey: string; + }; +} + +// until eui searchbar and query are typed +export interface IQuery { + ast: any; // incomplete + text: string; + syntax: any; // incomplete +} diff --git a/src/legacy/core_plugins/kibana/ui_setting_defaults.js b/src/legacy/core_plugins/kibana/ui_setting_defaults.js index 9b848666541ce7..02a4f10a543c4a 100644 --- a/src/legacy/core_plugins/kibana/ui_setting_defaults.js +++ b/src/legacy/core_plugins/kibana/ui_setting_defaults.js @@ -257,6 +257,7 @@ export function getUiSettingDefaults() { defaultMessage: 'Default index', }), value: null, + type: 'string', description: i18n.translate('kbn.advancedSettings.defaultIndexText', { defaultMessage: 'The index to access if no index is set', }), diff --git a/src/legacy/core_plugins/timelion/index.ts b/src/legacy/core_plugins/timelion/index.ts index d725327e2365b5..42d4e04184a257 100644 --- a/src/legacy/core_plugins/timelion/index.ts +++ b/src/legacy/core_plugins/timelion/index.ts @@ -21,10 +21,7 @@ import { resolve } from 'path'; import { i18n } from '@kbn/i18n'; import { Legacy } from 'kibana'; import { LegacyPluginApi, LegacyPluginInitializer } from 'src/legacy/plugin_discovery/types'; -import { CoreSetup, PluginInitializerContext } from 'src/core/server'; import { DEFAULT_APP_CATEGORIES } from '../../../core/utils'; -import { plugin } from './server'; -import { CustomCoreSetup } from './server/plugin'; const experimentalLabel = i18n.translate('timelion.uiSettings.experimentalLabel', { defaultMessage: 'experimental', @@ -195,12 +192,6 @@ const timelionPluginInitializer: LegacyPluginInitializer = ({ Plugin }: LegacyPl }, }, }, - init: (server: Legacy.Server) => { - const initializerContext = {} as PluginInitializerContext; - const core = { http: { server } } as CoreSetup & CustomCoreSetup; - - plugin(initializerContext).setup(core); - }, }); // eslint-disable-next-line import/no-default-export diff --git a/src/legacy/core_plugins/timelion/public/directives/timelion_expression_input.js b/src/legacy/core_plugins/timelion/public/directives/timelion_expression_input.js index 1fec243a277f85..57262fda55e48a 100644 --- a/src/legacy/core_plugins/timelion/public/directives/timelion_expression_input.js +++ b/src/legacy/core_plugins/timelion/public/directives/timelion_expression_input.js @@ -43,7 +43,7 @@ import _ from 'lodash'; import $ from 'jquery'; import PEG from 'pegjs'; -import grammar from 'raw-loader!../../../vis_type_timelion/public/chain.peg'; +import grammar from 'raw-loader!../../../../../plugins/timelion/common/chain.peg'; import timelionExpressionInputTemplate from './timelion_expression_input.html'; import { SUGGESTION_TYPE, diff --git a/src/legacy/core_plugins/timelion/public/lib/_tests_/calculate_interval.js b/src/legacy/core_plugins/timelion/public/lib/_tests_/calculate_interval.js deleted file mode 100644 index 77472dc89cd734..00000000000000 --- a/src/legacy/core_plugins/timelion/public/lib/_tests_/calculate_interval.js +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -const filename = require('path').basename(__filename); -const fn = require(`../calculate_interval`); -const moment = require('moment'); -const expect = require('chai').expect; - -const from = (count, unit) => - moment() - .subtract(count, unit) - .valueOf(); -const to = moment().valueOf(); -const size = 200; -const min = '1ms'; - -describe(filename, () => { - it('Exports a function', () => { - expect(fn).to.be.a('function'); - }); - - it('Only calculates when interval = auto', () => { - const partialFn = interval => fn(from(1, 'y'), to, size, interval, min); - expect(partialFn('1ms')).to.equal('1ms'); - expect(partialFn('bag_of_beans')).to.equal('bag_of_beans'); - expect(partialFn('auto')).to.not.equal('auto'); - }); - - it('Calculates nice round intervals', () => { - const partialFn = (count, unit) => fn(from(count, unit), to, size, 'auto', min); - expect(partialFn(15, 'm')).to.equal('1s'); - expect(partialFn(1, 'h')).to.equal('30s'); - expect(partialFn(3, 'd')).to.equal('30m'); - expect(partialFn(1, 'w')).to.equal('1h'); - expect(partialFn(1, 'y')).to.equal('24h'); - expect(partialFn(100, 'y')).to.equal('1y'); - }); - - it('Does not calculate an interval lower than the minimum', () => { - const partialFn = (count, unit) => fn(from(count, unit), to, size, 'auto', '1m'); - expect(partialFn(5, 's')).to.equal('1m'); - expect(partialFn(15, 'm')).to.equal('1m'); - expect(partialFn(1, 'h')).to.equal('1m'); - expect(partialFn(3, 'd')).to.equal('30m'); - expect(partialFn(1, 'w')).to.equal('1h'); - expect(partialFn(1, 'y')).to.equal('24h'); - expect(partialFn(100, 'y')).to.equal('1y'); - }); -}); diff --git a/src/legacy/core_plugins/timelion/public/panels/timechart/schema.ts b/src/legacy/core_plugins/timelion/public/panels/timechart/schema.ts index 57ee99f5268b08..cd40cbfa89ffed 100644 --- a/src/legacy/core_plugins/timelion/public/panels/timechart/schema.ts +++ b/src/legacy/core_plugins/timelion/public/panels/timechart/schema.ts @@ -24,7 +24,11 @@ import moment from 'moment-timezone'; import { timefilter } from 'ui/timefilter'; // @ts-ignore import observeResize from '../../lib/observe_resize'; -import { calculateInterval, DEFAULT_TIME_FORMAT } from '../../../../vis_type_timelion/common/lib'; +import { + calculateInterval, + DEFAULT_TIME_FORMAT, + // @ts-ignore +} from '../../../../../../plugins/timelion/common/lib'; import { tickFormatters } from '../../../../vis_type_timelion/public/helpers/tick_formatters'; import { TimelionVisualizationDependencies } from '../../plugin'; import { xaxisFormatterProvider } from '../../../../vis_type_timelion/public/helpers/xaxis_formatter'; diff --git a/src/legacy/core_plugins/timelion/server/plugin.ts b/src/legacy/core_plugins/timelion/server/plugin.ts deleted file mode 100644 index c94277ebc7adcf..00000000000000 --- a/src/legacy/core_plugins/timelion/server/plugin.ts +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -import { Legacy } from 'kibana'; -import { i18n } from '@kbn/i18n'; -import { PluginInitializerContext, CoreSetup } from 'kibana/server'; - -import loadFunctions, { LoadFunctions } from './lib/load_functions'; -import { initRoutes } from './routes'; - -function getFunction(functions: LoadFunctions, name: string) { - if (functions[name]) { - return functions[name]; - } - - throw new Error( - i18n.translate('timelion.noFunctionErrorMessage', { - defaultMessage: 'No such function: {name}', - values: { name }, - }) - ); -} - -// TODO: Remove as CoreSetup is completed. -export interface CustomCoreSetup { - http: { - server: Legacy.Server; - }; -} - -export class TimelionServerPlugin { - public initializerContext: PluginInitializerContext; - - constructor(initializerContext: PluginInitializerContext) { - this.initializerContext = initializerContext; - } - - public setup(core: CoreSetup & CustomCoreSetup) { - const { server } = core.http; - const functions = loadFunctions('series_functions'); - - server.expose('functions', functions); - server.expose('getFunction', (name: string) => getFunction(functions, name)); - - initRoutes(server); - } -} diff --git a/src/legacy/core_plugins/timelion/server/routes/index.ts b/src/legacy/core_plugins/timelion/server/routes/index.ts deleted file mode 100644 index b6438c81ef002c..00000000000000 --- a/src/legacy/core_plugins/timelion/server/routes/index.ts +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -import { Legacy } from 'kibana'; - -// @ts-ignore -import { runRoute } from './run'; -// @ts-ignore -import { functionsRoute } from './functions'; -// @ts-ignore -import { validateEsRoute } from './validate_es'; - -export function initRoutes(server: Legacy.Server) { - runRoute(server); - functionsRoute(server); - validateEsRoute(server); -} diff --git a/src/legacy/core_plugins/timelion/server/routes/run.ts b/src/legacy/core_plugins/timelion/server/routes/run.ts deleted file mode 100644 index 17f87825cd8b04..00000000000000 --- a/src/legacy/core_plugins/timelion/server/routes/run.ts +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -import Joi from 'joi'; -import Bluebird from 'bluebird'; -import _ from 'lodash'; -import { Legacy } from 'kibana'; -// @ts-ignore -import chainRunnerFn from '../handlers/chain_runner.js'; -// @ts-ignore -import getNamespacesSettings from '../lib/get_namespaced_settings'; -// @ts-ignore -import getTlConfig from '../handlers/lib/tl_config'; - -const timelionDefaults = getNamespacesSettings(); - -export interface TimelionRequestQuery { - payload: { - sheet: string[]; - extended?: { - es: { - filter: { - bool: { - filter: string[] | object; - must: string[]; - should: string[]; - must_not: string[]; - }; - }; - }; - }; - }; - time?: { - from?: string; - interval: string; - timezone: string; - to?: string; - }; -} - -function formatErrorResponse(e: Error, h: Legacy.ResponseToolkit) { - return h - .response({ - title: e.toString(), - message: e.toString(), - }) - .code(500); -} - -const requestPayload = { - payload: Joi.object({ - sheet: Joi.array() - .items(Joi.string()) - .required(), - extended: Joi.object({ - es: Joi.object({ - filter: Joi.object({ - bool: Joi.object({ - filter: Joi.array().allow(null), - must: Joi.array().allow(null), - should: Joi.array().allow(null), - must_not: Joi.array().allow(null), - }), - }), - }), - }).optional(), - time: Joi.object({ - from: Joi.string(), - interval: Joi.string().required(), - timezone: Joi.string().required(), - to: Joi.string(), - }).required(), - }), -}; - -export function runRoute(server: Legacy.Server) { - server.route({ - method: 'POST', - path: '/api/timelion/run', - options: { - validate: requestPayload, - }, - handler: async (request: Legacy.Request & TimelionRequestQuery, h: Legacy.ResponseToolkit) => { - try { - const uiSettings = await request.getUiSettingsService().getAll(); - - const tlConfig = getTlConfig({ - server, - request, - settings: _.defaults(uiSettings, timelionDefaults), // Just in case they delete some setting. - }); - const chainRunner = chainRunnerFn(tlConfig); - const sheet = await Bluebird.all(chainRunner.processRequest(request.payload)); - - return { - sheet, - stats: chainRunner.getStats(), - }; - } catch (err) { - server.log(['timelion', 'error'], `${err.toString()}: ${err.stack}`); - // TODO Maybe we should just replace everywhere we throw with Boom? Probably. - if (err.isBoom) { - return err; - } else { - return formatErrorResponse(err, h); - } - } - }, - }); -} diff --git a/src/legacy/core_plugins/vis_type_timelion/public/components/panel.tsx b/src/legacy/core_plugins/vis_type_timelion/public/components/panel.tsx index 6095ba28443b8d..3b42fa7dfcbb88 100644 --- a/src/legacy/core_plugins/vis_type_timelion/public/components/panel.tsx +++ b/src/legacy/core_plugins/vis_type_timelion/public/components/panel.tsx @@ -24,7 +24,7 @@ import { debounce, compact, get, each, cloneDeep, last, map } from 'lodash'; import { useKibana } from '../../../../../plugins/kibana_react/public'; import '../flot'; -import { DEFAULT_TIME_FORMAT } from '../../common/lib'; +import { DEFAULT_TIME_FORMAT } from '../../../../../plugins/timelion/common/lib'; import { buildSeriesData, diff --git a/src/legacy/core_plugins/vis_type_timelion/public/components/timelion_expression_input.tsx b/src/legacy/core_plugins/vis_type_timelion/public/components/timelion_expression_input.tsx index fa79e4eb6871a9..620bc26d9184d1 100644 --- a/src/legacy/core_plugins/vis_type_timelion/public/components/timelion_expression_input.tsx +++ b/src/legacy/core_plugins/vis_type_timelion/public/components/timelion_expression_input.tsx @@ -24,8 +24,11 @@ import * as monacoEditor from 'monaco-editor/esm/vs/editor/editor.api'; import { CodeEditor, useKibana } from '../../../../../plugins/kibana_react/public'; import { suggest, getSuggestion } from './timelion_expression_input_helpers'; -import { ITimelionFunction, TimelionFunctionArgs } from '../../common/types'; import { getArgValueSuggestions } from '../helpers/arg_value_suggestions'; +import { + ITimelionFunction, + TimelionFunctionArgs, +} from '../../../../../plugins/timelion/common/types'; const LANGUAGE_ID = 'timelion_expression'; monacoEditor.languages.register({ id: LANGUAGE_ID }); diff --git a/src/legacy/core_plugins/vis_type_timelion/public/components/timelion_expression_input_helpers.test.ts b/src/legacy/core_plugins/vis_type_timelion/public/components/timelion_expression_input_helpers.test.ts index 18a0c0872dc031..cf40d2f791fc28 100644 --- a/src/legacy/core_plugins/vis_type_timelion/public/components/timelion_expression_input_helpers.test.ts +++ b/src/legacy/core_plugins/vis_type_timelion/public/components/timelion_expression_input_helpers.test.ts @@ -22,7 +22,7 @@ import { getArgValueSuggestions } from '../helpers/arg_value_suggestions'; import { setIndexPatterns, setSavedObjectsClient } from '../helpers/plugin_services'; import { IndexPatterns } from 'src/plugins/data/public'; import { SavedObjectsClient } from 'kibana/public'; -import { ITimelionFunction } from '../../common/types'; +import { ITimelionFunction } from '../../../../../plugins/timelion/common/types'; describe('Timelion expression suggestions', () => { setIndexPatterns({} as IndexPatterns); diff --git a/src/legacy/core_plugins/vis_type_timelion/public/components/timelion_expression_input_helpers.ts b/src/legacy/core_plugins/vis_type_timelion/public/components/timelion_expression_input_helpers.ts index d7818680c9543e..93b6a0d463c01b 100644 --- a/src/legacy/core_plugins/vis_type_timelion/public/components/timelion_expression_input_helpers.ts +++ b/src/legacy/core_plugins/vis_type_timelion/public/components/timelion_expression_input_helpers.ts @@ -18,16 +18,19 @@ */ import { get, startsWith } from 'lodash'; +import { i18n } from '@kbn/i18n'; import * as monacoEditor from 'monaco-editor/esm/vs/editor/editor.api'; -import { i18n } from '@kbn/i18n'; import { Parser } from 'pegjs'; // @ts-ignore import { parse } from '../_generated_/chain'; -import { ITimelionFunction, TimelionFunctionArgs } from '../../common/types'; import { ArgValueSuggestions, FunctionArg, Location } from '../helpers/arg_value_suggestions'; +import { + ITimelionFunction, + TimelionFunctionArgs, +} from '../../../../../plugins/timelion/common/types'; export enum SUGGESTION_TYPE { ARGUMENTS = 'arguments', diff --git a/src/legacy/core_plugins/vis_type_timelion/public/helpers/arg_value_suggestions.ts b/src/legacy/core_plugins/vis_type_timelion/public/helpers/arg_value_suggestions.ts index 8d133de51f6d9a..e293a662a4ed7f 100644 --- a/src/legacy/core_plugins/vis_type_timelion/public/helpers/arg_value_suggestions.ts +++ b/src/legacy/core_plugins/vis_type_timelion/public/helpers/arg_value_suggestions.ts @@ -18,8 +18,8 @@ */ import { get } from 'lodash'; -import { TimelionFunctionArgs } from '../../common/types'; import { getIndexPatterns, getSavedObjectsClient } from './plugin_services'; +import { TimelionFunctionArgs } from '../../../../../plugins/timelion/common/types'; export interface Location { min: number; diff --git a/src/legacy/core_plugins/vis_type_timelion/public/helpers/panel_utils.ts b/src/legacy/core_plugins/vis_type_timelion/public/helpers/panel_utils.ts index db29d9112be8e8..f932e5ee4b2f46 100644 --- a/src/legacy/core_plugins/vis_type_timelion/public/helpers/panel_utils.ts +++ b/src/legacy/core_plugins/vis_type_timelion/public/helpers/panel_utils.ts @@ -23,7 +23,7 @@ import moment, { Moment } from 'moment-timezone'; import { TimefilterContract } from 'src/plugins/data/public'; import { IUiSettingsClient } from 'kibana/public'; -import { calculateInterval } from '../../common/lib'; +import { calculateInterval } from '../../../../../plugins/timelion/common/lib'; import { xaxisFormatterProvider } from './xaxis_formatter'; import { Series } from './timelion_request_handler'; diff --git a/src/legacy/core_plugins/vis_type_timelion/public/chain.peg b/src/plugins/timelion/common/chain.peg similarity index 100% rename from src/legacy/core_plugins/vis_type_timelion/public/chain.peg rename to src/plugins/timelion/common/chain.peg diff --git a/src/plugins/timelion/common/lib/calculate_interval.test.ts b/src/plugins/timelion/common/lib/calculate_interval.test.ts new file mode 100644 index 00000000000000..17e8a019110714 --- /dev/null +++ b/src/plugins/timelion/common/lib/calculate_interval.test.ts @@ -0,0 +1,66 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { calculateInterval as fn } from './calculate_interval'; + +import moment, { unitOfTime } from 'moment'; + +const from = (count: number, unit: unitOfTime.DurationConstructor) => + moment() + .subtract(count, unit) + .valueOf(); +const to = moment().valueOf(); +const size = 200; +const min = '1ms'; + +describe('calculate_interval', () => { + it('Exports a function', () => { + expect(typeof fn).toBe('function'); + }); + + it('Only calculates when interval = auto', () => { + const partialFn = (interval: string) => fn(from(1, 'y'), to, size, interval, min); + expect(partialFn('1ms')).toEqual('1ms'); + expect(partialFn('bag_of_beans')).toEqual('bag_of_beans'); + expect(partialFn('auto')).not.toEqual('auto'); + }); + + it('Calculates nice round intervals', () => { + const partialFn = (count: number, unit: unitOfTime.DurationConstructor) => + fn(from(count, unit), to, size, 'auto', min); + expect(partialFn(15, 'm')).toEqual('1s'); + expect(partialFn(1, 'h')).toEqual('30s'); + expect(partialFn(3, 'd')).toEqual('30m'); + expect(partialFn(1, 'w')).toEqual('1h'); + expect(partialFn(1, 'y')).toEqual('24h'); + expect(partialFn(100, 'y')).toEqual('1y'); + }); + + it('Does not calculate an interval lower than the minimum', () => { + const partialFn = (count: number, unit: unitOfTime.DurationConstructor) => + fn(from(count, unit), to, size, 'auto', '1m'); + expect(partialFn(5, 's')).toEqual('1m'); + expect(partialFn(15, 'm')).toEqual('1m'); + expect(partialFn(1, 'h')).toEqual('1m'); + expect(partialFn(3, 'd')).toEqual('30m'); + expect(partialFn(1, 'w')).toEqual('1h'); + expect(partialFn(1, 'y')).toEqual('24h'); + expect(partialFn(100, 'y')).toEqual('1y'); + }); +}); diff --git a/src/legacy/core_plugins/vis_type_timelion/common/lib/calculate_interval.ts b/src/plugins/timelion/common/lib/calculate_interval.ts similarity index 100% rename from src/legacy/core_plugins/vis_type_timelion/common/lib/calculate_interval.ts rename to src/plugins/timelion/common/lib/calculate_interval.ts index 328c634ea51537..f724f4723a9290 100644 --- a/src/legacy/core_plugins/vis_type_timelion/common/lib/calculate_interval.ts +++ b/src/plugins/timelion/common/lib/calculate_interval.ts @@ -17,10 +17,10 @@ * under the License. */ -import { toMS } from './to_milliseconds'; - // Totally cribbed this from Kibana 3. // I bet there's something similar in the Kibana 4 code. Somewhere. Somehow. +import { toMS } from './to_milliseconds'; + function roundInterval(interval: number) { switch (true) { case interval <= 500: // <= 0.5s diff --git a/src/legacy/core_plugins/vis_type_timelion/common/lib/index.ts b/src/plugins/timelion/common/lib/index.ts similarity index 100% rename from src/legacy/core_plugins/vis_type_timelion/common/lib/index.ts rename to src/plugins/timelion/common/lib/index.ts diff --git a/src/legacy/core_plugins/vis_type_timelion/common/lib/to_milliseconds.ts b/src/plugins/timelion/common/lib/to_milliseconds.ts similarity index 100% rename from src/legacy/core_plugins/vis_type_timelion/common/lib/to_milliseconds.ts rename to src/plugins/timelion/common/lib/to_milliseconds.ts diff --git a/src/legacy/core_plugins/vis_type_timelion/common/types.ts b/src/plugins/timelion/common/types.ts similarity index 100% rename from src/legacy/core_plugins/vis_type_timelion/common/types.ts rename to src/plugins/timelion/common/types.ts diff --git a/src/plugins/timelion/server/config.ts b/src/plugins/timelion/server/config.ts index a47d39beb7555b..e76c878c0c6b1f 100644 --- a/src/plugins/timelion/server/config.ts +++ b/src/plugins/timelion/server/config.ts @@ -22,6 +22,7 @@ import { schema } from '@kbn/config-schema'; export const ConfigSchema = schema.object( { ui: schema.object({ enabled: schema.boolean({ defaultValue: false }) }), + graphiteUrls: schema.maybe(schema.arrayOf(schema.string())), }, // This option should be removed as soon as we entirely migrate config from legacy Timelion plugin. { allowUnknowns: true } diff --git a/src/legacy/core_plugins/timelion/server/fit_functions/average.js b/src/plugins/timelion/server/fit_functions/average.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/fit_functions/average.js rename to src/plugins/timelion/server/fit_functions/average.js diff --git a/src/legacy/core_plugins/timelion/server/fit_functions/__tests__/average.js b/src/plugins/timelion/server/fit_functions/average.test.js similarity index 99% rename from src/legacy/core_plugins/timelion/server/fit_functions/__tests__/average.js rename to src/plugins/timelion/server/fit_functions/average.test.js index d30244610a1248..2f61a29bc25b23 100644 --- a/src/legacy/core_plugins/timelion/server/fit_functions/__tests__/average.js +++ b/src/plugins/timelion/server/fit_functions/average.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../average`); +import fn from './average'; import moment from 'moment'; const expect = require('chai').expect; import _ from 'lodash'; diff --git a/src/legacy/core_plugins/timelion/server/fit_functions/carry.js b/src/plugins/timelion/server/fit_functions/carry.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/fit_functions/carry.js rename to src/plugins/timelion/server/fit_functions/carry.js diff --git a/src/legacy/core_plugins/timelion/server/fit_functions/__tests__/carry.js b/src/plugins/timelion/server/fit_functions/carry.test.js similarity index 98% rename from src/legacy/core_plugins/timelion/server/fit_functions/__tests__/carry.js rename to src/plugins/timelion/server/fit_functions/carry.test.js index 8e35d63618ae4b..22608e0bf49888 100644 --- a/src/legacy/core_plugins/timelion/server/fit_functions/__tests__/carry.js +++ b/src/plugins/timelion/server/fit_functions/carry.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../carry`); +import fn from './carry'; import moment from 'moment'; const expect = require('chai').expect; import _ from 'lodash'; diff --git a/src/legacy/core_plugins/timelion/server/fit_functions/nearest.js b/src/plugins/timelion/server/fit_functions/nearest.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/fit_functions/nearest.js rename to src/plugins/timelion/server/fit_functions/nearest.js diff --git a/src/legacy/core_plugins/timelion/server/fit_functions/none.js b/src/plugins/timelion/server/fit_functions/none.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/fit_functions/none.js rename to src/plugins/timelion/server/fit_functions/none.js diff --git a/src/legacy/core_plugins/timelion/server/fit_functions/scale.js b/src/plugins/timelion/server/fit_functions/scale.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/fit_functions/scale.js rename to src/plugins/timelion/server/fit_functions/scale.js diff --git a/src/legacy/core_plugins/timelion/server/handlers/chain_runner.js b/src/plugins/timelion/server/handlers/chain_runner.js similarity index 95% rename from src/legacy/core_plugins/timelion/server/handlers/chain_runner.js rename to src/plugins/timelion/server/handlers/chain_runner.js index 9056362cb723a2..9a87909b0a857e 100644 --- a/src/legacy/core_plugins/timelion/server/handlers/chain_runner.js +++ b/src/plugins/timelion/server/handlers/chain_runner.js @@ -26,7 +26,7 @@ import parseSheet from './lib/parse_sheet.js'; import repositionArguments from './lib/reposition_arguments.js'; import indexArguments from './lib/index_arguments.js'; import validateTime from './lib/validate_time.js'; -import { calculateInterval } from '../../../vis_type_timelion/common/lib'; +import { calculateInterval } from '../../common/lib'; export default function chainRunner(tlConfig) { const preprocessChain = require('./lib/preprocess_chain')(tlConfig); @@ -41,7 +41,7 @@ export default function chainRunner(tlConfig) { // Invokes a modifier function, resolving arguments into series as needed function invoke(fnName, args) { - const functionDef = tlConfig.server.plugins.timelion.getFunction(fnName); + const functionDef = tlConfig.getFunction(fnName); function resolveArgument(item) { if (Array.isArray(item)) { @@ -51,7 +51,7 @@ export default function chainRunner(tlConfig) { if (_.isObject(item)) { switch (item.type) { case 'function': { - const itemFunctionDef = tlConfig.server.plugins.timelion.getFunction(item.function); + const itemFunctionDef = tlConfig.getFunction(item.function); if (itemFunctionDef.cacheKey && queryCache[itemFunctionDef.cacheKey(item)]) { stats.queryCount++; return Bluebird.resolve(_.cloneDeep(queryCache[itemFunctionDef.cacheKey(item)])); @@ -168,7 +168,7 @@ export default function chainRunner(tlConfig) { stats.queryTime = new Date().getTime(); _.each(queries, function(query, i) { - const functionDef = tlConfig.server.plugins.timelion.getFunction(query.function); + const functionDef = tlConfig.getFunction(query.function); const resolvedDatasource = resolvedDatasources[i]; if (resolvedDatasource.isRejected()) { diff --git a/src/legacy/core_plugins/timelion/server/handlers/lib/arg_type.js b/src/plugins/timelion/server/handlers/lib/arg_type.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/handlers/lib/arg_type.js rename to src/plugins/timelion/server/handlers/lib/arg_type.js diff --git a/src/legacy/core_plugins/timelion/server/handlers/lib/index_arguments.js b/src/plugins/timelion/server/handlers/lib/index_arguments.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/handlers/lib/index_arguments.js rename to src/plugins/timelion/server/handlers/lib/index_arguments.js diff --git a/src/legacy/core_plugins/timelion/server/handlers/lib/parse_sheet.js b/src/plugins/timelion/server/handlers/lib/parse_sheet.js similarity index 93% rename from src/legacy/core_plugins/timelion/server/handlers/lib/parse_sheet.js rename to src/plugins/timelion/server/handlers/lib/parse_sheet.js index 4957d3cb78b85e..4880c73f42bb2e 100644 --- a/src/legacy/core_plugins/timelion/server/handlers/lib/parse_sheet.js +++ b/src/plugins/timelion/server/handlers/lib/parse_sheet.js @@ -21,10 +21,7 @@ import { i18n } from '@kbn/i18n'; import fs from 'fs'; import path from 'path'; import _ from 'lodash'; -const grammar = fs.readFileSync( - path.resolve(__dirname, '../../../../vis_type_timelion/public/chain.peg'), - 'utf8' -); +const grammar = fs.readFileSync(path.resolve(__dirname, '../../../common/chain.peg'), 'utf8'); import PEG from 'pegjs'; const Parser = PEG.generate(grammar); diff --git a/src/legacy/core_plugins/timelion/server/handlers/__tests__/parse_sheet.js b/src/plugins/timelion/server/handlers/lib/parse_sheet.test.js similarity index 97% rename from src/legacy/core_plugins/timelion/server/handlers/__tests__/parse_sheet.js rename to src/plugins/timelion/server/handlers/lib/parse_sheet.test.js index 4ec2a88d3e68b0..16d5f8b4a02bb9 100644 --- a/src/legacy/core_plugins/timelion/server/handlers/__tests__/parse_sheet.js +++ b/src/plugins/timelion/server/handlers/lib/parse_sheet.test.js @@ -17,7 +17,7 @@ * under the License. */ -const parseSheet = require('../lib/parse_sheet'); +const parseSheet = require('./parse_sheet'); const expect = require('chai').expect; diff --git a/src/legacy/core_plugins/timelion/server/handlers/lib/preprocess_chain.js b/src/plugins/timelion/server/handlers/lib/preprocess_chain.js similarity index 95% rename from src/legacy/core_plugins/timelion/server/handlers/lib/preprocess_chain.js rename to src/plugins/timelion/server/handlers/lib/preprocess_chain.js index 5e5f274115ee21..6a667e36054ce3 100644 --- a/src/legacy/core_plugins/timelion/server/handlers/lib/preprocess_chain.js +++ b/src/plugins/timelion/server/handlers/lib/preprocess_chain.js @@ -24,7 +24,7 @@ export default function preProcessChainFn(tlConfig) { queries = queries || {}; function validateAndStore(item) { if (_.isObject(item) && item.type === 'function') { - const functionDef = tlConfig.server.plugins.timelion.getFunction(item.function); + const functionDef = tlConfig.getFunction(item.function); if (functionDef.datasource) { queries[functionDef.cacheKey(item)] = item; diff --git a/src/legacy/core_plugins/timelion/server/handlers/lib/reposition_arguments.js b/src/plugins/timelion/server/handlers/lib/reposition_arguments.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/handlers/lib/reposition_arguments.js rename to src/plugins/timelion/server/handlers/lib/reposition_arguments.js diff --git a/src/legacy/core_plugins/timelion/server/handlers/lib/tl_config.js b/src/plugins/timelion/server/handlers/lib/tl_config.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/handlers/lib/tl_config.js rename to src/plugins/timelion/server/handlers/lib/tl_config.js diff --git a/src/legacy/core_plugins/timelion/server/handlers/lib/validate_arg.js b/src/plugins/timelion/server/handlers/lib/validate_arg.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/handlers/lib/validate_arg.js rename to src/plugins/timelion/server/handlers/lib/validate_arg.js diff --git a/src/legacy/core_plugins/timelion/server/handlers/lib/validate_time.js b/src/plugins/timelion/server/handlers/lib/validate_time.js similarity index 96% rename from src/legacy/core_plugins/timelion/server/handlers/lib/validate_time.js rename to src/plugins/timelion/server/handlers/lib/validate_time.js index db924e33be5e9b..07157a9a8c6d9c 100644 --- a/src/legacy/core_plugins/timelion/server/handlers/lib/validate_time.js +++ b/src/plugins/timelion/server/handlers/lib/validate_time.js @@ -20,7 +20,7 @@ import { i18n } from '@kbn/i18n'; import moment from 'moment'; -import { toMS } from '../../../../vis_type_timelion/common/lib'; +import { toMS } from '../../../common/lib/to_milliseconds'; export default function validateTime(time, tlConfig) { const span = moment.duration(moment(time.to).diff(moment(time.from))).asMilliseconds(); diff --git a/src/legacy/core_plugins/timelion/server/lib/alter.js b/src/plugins/timelion/server/lib/alter.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/lib/alter.js rename to src/plugins/timelion/server/lib/alter.js diff --git a/src/legacy/core_plugins/timelion/server/lib/asSorted.js b/src/plugins/timelion/server/lib/as_sorted.js similarity index 95% rename from src/legacy/core_plugins/timelion/server/lib/asSorted.js rename to src/plugins/timelion/server/lib/as_sorted.js index ff20af78b43623..536145a6b8dcda 100644 --- a/src/legacy/core_plugins/timelion/server/lib/asSorted.js +++ b/src/plugins/timelion/server/lib/as_sorted.js @@ -18,7 +18,7 @@ */ import _ from 'lodash'; -import unzipPairs from './unzipPairs.js'; +import unzipPairs from './unzip_pairs.js'; export default function asSorted(timeValObject, fn) { const data = unzipPairs(timeValObject); diff --git a/src/legacy/core_plugins/timelion/server/lib/build_target.js b/src/plugins/timelion/server/lib/build_target.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/lib/build_target.js rename to src/plugins/timelion/server/lib/build_target.js diff --git a/src/legacy/core_plugins/timelion/server/lib/classes/chainable.js b/src/plugins/timelion/server/lib/classes/chainable.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/lib/classes/chainable.js rename to src/plugins/timelion/server/lib/classes/chainable.js diff --git a/src/legacy/core_plugins/timelion/server/lib/classes/datasource.js b/src/plugins/timelion/server/lib/classes/datasource.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/lib/classes/datasource.js rename to src/plugins/timelion/server/lib/classes/datasource.js diff --git a/src/legacy/core_plugins/timelion/server/lib/classes/timelion_function.d.ts b/src/plugins/timelion/server/lib/classes/timelion_function.d.ts similarity index 93% rename from src/legacy/core_plugins/timelion/server/lib/classes/timelion_function.d.ts rename to src/plugins/timelion/server/lib/classes/timelion_function.d.ts index 08358b9d81f781..798902aa133dee 100644 --- a/src/legacy/core_plugins/timelion/server/lib/classes/timelion_function.d.ts +++ b/src/plugins/timelion/server/lib/classes/timelion_function.d.ts @@ -17,7 +17,7 @@ * under the License. */ -import { TimelionFunctionArgs } from '../../../../vis_type_timelion/common/types'; +import { TimelionFunctionArgs } from '../../../common/types'; export interface TimelionFunctionInterface extends TimelionFunctionConfig { chainable: boolean; diff --git a/src/legacy/core_plugins/timelion/server/lib/classes/timelion_function.js b/src/plugins/timelion/server/lib/classes/timelion_function.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/lib/classes/timelion_function.js rename to src/plugins/timelion/server/lib/classes/timelion_function.js diff --git a/src/legacy/core_plugins/timelion/server/index.ts b/src/plugins/timelion/server/lib/config_manager.ts similarity index 56% rename from src/legacy/core_plugins/timelion/server/index.ts rename to src/plugins/timelion/server/lib/config_manager.ts index 36af9ce7b85dff..60d89f34a4c085 100644 --- a/src/legacy/core_plugins/timelion/server/index.ts +++ b/src/plugins/timelion/server/lib/config_manager.ts @@ -18,8 +18,28 @@ */ import { PluginInitializerContext } from 'kibana/server'; -import { TimelionServerPlugin as Plugin } from './plugin'; +import { TypeOf } from '@kbn/config-schema'; +import { ConfigSchema } from '../config'; -export function plugin(initializerContext: PluginInitializerContext) { - return new Plugin(initializerContext); +export class ConfigManager { + private esShardTimeout: number = 0; + private graphiteUrls: string[] = []; + + constructor(config: PluginInitializerContext['config']) { + config.create>().subscribe(configUpdate => { + this.graphiteUrls = configUpdate.graphiteUrls || []; + }); + + config.legacy.globalConfig$.subscribe(configUpdate => { + this.esShardTimeout = configUpdate.elasticsearch.shardTimeout.asMilliseconds(); + }); + } + + getEsShardTimeout() { + return this.esShardTimeout; + } + + getGraphiteUrls() { + return this.graphiteUrls; + } } diff --git a/src/legacy/core_plugins/timelion/server/lib/functions_md.js b/src/plugins/timelion/server/lib/functions_md.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/lib/functions_md.js rename to src/plugins/timelion/server/lib/functions_md.js diff --git a/src/legacy/core_plugins/timelion/server/lib/get_namespaced_settings.js b/src/plugins/timelion/server/lib/get_namespaced_settings.js similarity index 97% rename from src/legacy/core_plugins/timelion/server/lib/get_namespaced_settings.js rename to src/plugins/timelion/server/lib/get_namespaced_settings.js index 5d18d87e8e054b..31bd6b440f9b86 100644 --- a/src/legacy/core_plugins/timelion/server/lib/get_namespaced_settings.js +++ b/src/plugins/timelion/server/lib/get_namespaced_settings.js @@ -18,7 +18,7 @@ */ import _ from 'lodash'; -import configFile from '../../timelion.json'; +import configFile from '../timelion.json'; export default function() { function flattenWith(dot, nestedObj, flattenArrays) { diff --git a/src/legacy/core_plugins/timelion/server/lib/load_functions.d.ts b/src/plugins/timelion/server/lib/load_functions.d.ts similarity index 100% rename from src/legacy/core_plugins/timelion/server/lib/load_functions.d.ts rename to src/plugins/timelion/server/lib/load_functions.d.ts diff --git a/src/legacy/core_plugins/timelion/server/lib/load_functions.js b/src/plugins/timelion/server/lib/load_functions.js similarity index 84% rename from src/legacy/core_plugins/timelion/server/lib/load_functions.js rename to src/plugins/timelion/server/lib/load_functions.js index 11501ce3f102b8..b7cec8f68faf22 100644 --- a/src/legacy/core_plugins/timelion/server/lib/load_functions.js +++ b/src/plugins/timelion/server/lib/load_functions.js @@ -28,18 +28,18 @@ export default function(directory) { } // Get a list of all files and use the filename as the object key - const files = _.map(glob.sync(path.resolve(__dirname, '../' + directory + '/*.js')), function( - file - ) { - const name = file.substring(file.lastIndexOf('/') + 1, file.lastIndexOf('.')); - return getTuple(directory, name); - }); + const files = _.map( + glob + .sync(path.resolve(__dirname, '../' + directory + '/*.js')) + .filter(filename => !filename.includes('.test')), + function(file) { + const name = file.substring(file.lastIndexOf('/') + 1, file.lastIndexOf('.')); + return getTuple(directory, name); + } + ); // Get a list of all directories with an index.js, use the directory name as the key in the object const directories = _.chain(glob.sync(path.resolve(__dirname, '../' + directory + '/*/index.js'))) - .filter(function(file) { - return file.match(/__test__/) == null; - }) .map(function(file) { const parts = file.split('/'); const name = parts[parts.length - 2]; diff --git a/src/legacy/core_plugins/timelion/server/lib/__tests__/load_functions.js b/src/plugins/timelion/server/lib/load_functions.test.js similarity index 95% rename from src/legacy/core_plugins/timelion/server/lib/__tests__/load_functions.js rename to src/plugins/timelion/server/lib/load_functions.test.js index 45dd436be6943a..ebe1a04532e050 100644 --- a/src/legacy/core_plugins/timelion/server/lib/__tests__/load_functions.js +++ b/src/plugins/timelion/server/lib/load_functions.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../load_functions`); +const fn = require(`src/plugins/timelion/server/lib/load_functions`); const expect = require('chai').expect; diff --git a/src/legacy/core_plugins/timelion/server/lib/offset_time.js b/src/plugins/timelion/server/lib/offset_time.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/lib/offset_time.js rename to src/plugins/timelion/server/lib/offset_time.js diff --git a/src/legacy/core_plugins/timelion/server/lib/offset_time.test.js b/src/plugins/timelion/server/lib/offset_time.test.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/lib/offset_time.test.js rename to src/plugins/timelion/server/lib/offset_time.test.js diff --git a/src/legacy/core_plugins/timelion/server/lib/process_function_definition.js b/src/plugins/timelion/server/lib/process_function_definition.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/lib/process_function_definition.js rename to src/plugins/timelion/server/lib/process_function_definition.js diff --git a/src/legacy/core_plugins/timelion/server/lib/reduce.js b/src/plugins/timelion/server/lib/reduce.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/lib/reduce.js rename to src/plugins/timelion/server/lib/reduce.js diff --git a/src/legacy/core_plugins/timelion/server/lib/split_interval.js b/src/plugins/timelion/server/lib/split_interval.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/lib/split_interval.js rename to src/plugins/timelion/server/lib/split_interval.js diff --git a/src/legacy/core_plugins/timelion/server/lib/unzipPairs.js b/src/plugins/timelion/server/lib/unzip_pairs.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/lib/unzipPairs.js rename to src/plugins/timelion/server/lib/unzip_pairs.js diff --git a/src/plugins/timelion/server/plugin.ts b/src/plugins/timelion/server/plugin.ts index 4436c1539fc5bc..4330bc0ffb357c 100644 --- a/src/plugins/timelion/server/plugin.ts +++ b/src/plugins/timelion/server/plugin.ts @@ -17,11 +17,21 @@ * under the License. */ +import { i18n } from '@kbn/i18n'; import { first } from 'rxjs/operators'; import { TypeOf } from '@kbn/config-schema'; -import { PluginInitializerContext, RecursiveReadonly } from '../../../../src/core/server'; +import { + CoreSetup, + PluginInitializerContext, + RecursiveReadonly, +} from '../../../../src/core/server'; import { deepFreeze } from '../../../../src/core/utils'; import { ConfigSchema } from './config'; +import loadFunctions from './lib/load_functions'; +import { functionsRoute } from './routes/functions'; +import { validateEsRoute } from './routes/validate_es'; +import { runRoute } from './routes/run'; +import { ConfigManager } from './lib/config_manager'; /** * Describes public Timelion plugin contract returned at the `setup` stage. @@ -36,12 +46,44 @@ export interface PluginSetupContract { export class Plugin { constructor(private readonly initializerContext: PluginInitializerContext) {} - public async setup(): Promise> { + public async setup(core: CoreSetup): Promise> { const config = await this.initializerContext.config .create>() .pipe(first()) .toPromise(); + const configManager = new ConfigManager(this.initializerContext.config); + + const functions = loadFunctions('series_functions'); + + const getFunction = (name: string) => { + if (functions[name]) { + return functions[name]; + } + + throw new Error( + i18n.translate('timelion.noFunctionErrorMessage', { + defaultMessage: 'No such function: {name}', + values: { name }, + }) + ); + }; + + const logger = this.initializerContext.logger.get('timelion'); + + const router = core.http.createRouter(); + + const deps = { + configManager, + functions, + getFunction, + logger, + }; + + functionsRoute(router, deps); + runRoute(router, deps); + validateEsRoute(router); + return deepFreeze({ uiEnabled: config.ui.enabled }); } diff --git a/src/legacy/core_plugins/timelion/server/routes/functions.js b/src/plugins/timelion/server/routes/functions.ts similarity index 68% rename from src/legacy/core_plugins/timelion/server/routes/functions.js rename to src/plugins/timelion/server/routes/functions.ts index 813d006225f43d..a908fefa377eb9 100644 --- a/src/legacy/core_plugins/timelion/server/routes/functions.js +++ b/src/plugins/timelion/server/routes/functions.ts @@ -18,18 +18,22 @@ */ import _ from 'lodash'; +import { IRouter } from 'kibana/server'; +import { LoadFunctions } from '../lib/load_functions'; -export function functionsRoute(server) { - server.route({ - method: 'GET', - path: '/api/timelion/functions', - handler: () => { - const functionArray = _.map(server.plugins.timelion.functions, function(val, key) { +export function functionsRoute(router: IRouter, { functions }: { functions: LoadFunctions }) { + router.get( + { + path: '/api/timelion/functions', + validate: false, + }, + async (context, request, response) => { + const functionArray = _.map(functions, function(val, key) { // TODO: This won't work on frozen objects, it should be removed when everything is converted to datasources and chainables return _.extend({}, val, { name: key }); }); - return _.sortBy(functionArray, 'name'); - }, - }); + return response.ok({ body: _.sortBy(functionArray, 'name') }); + } + ); } diff --git a/src/plugins/timelion/server/routes/run.ts b/src/plugins/timelion/server/routes/run.ts new file mode 100644 index 00000000000000..b7a4179da768ea --- /dev/null +++ b/src/plugins/timelion/server/routes/run.ts @@ -0,0 +1,144 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import { IRouter, Logger } from 'kibana/server'; +import { schema } from '@kbn/config-schema'; +import Bluebird from 'bluebird'; +import _ from 'lodash'; +// @ts-ignore +import chainRunnerFn from '../handlers/chain_runner.js'; +// @ts-ignore +import getNamespacesSettings from '../lib/get_namespaced_settings'; +// @ts-ignore +import getTlConfig from '../handlers/lib/tl_config'; +import { TimelionFunctionInterface } from '../types'; +import { ConfigManager } from '../lib/config_manager'; + +const timelionDefaults = getNamespacesSettings(); + +export interface TimelionRequestQuery { + payload: { + sheet: string[]; + extended?: { + es: { + filter: { + bool: { + filter: string[] | object; + must: string[]; + should: string[]; + must_not: string[]; + }; + }; + }; + }; + }; + time?: { + from?: string; + interval: string; + timezone: string; + to?: string; + }; +} + +export function runRoute( + router: IRouter, + { + logger, + getFunction, + configManager, + }: { + logger: Logger; + getFunction: (name: string) => TimelionFunctionInterface; + configManager: ConfigManager; + } +) { + router.post( + { + path: '/api/timelion/run', + validate: { + body: schema.object({ + sheet: schema.arrayOf(schema.string()), + extended: schema.maybe( + schema.object({ + es: schema.object({ + filter: schema.object({ + bool: schema.object({ + filter: schema.maybe( + schema.arrayOf(schema.object({}, { allowUnknowns: true })) + ), + must: schema.maybe(schema.arrayOf(schema.object({}, { allowUnknowns: true }))), + should: schema.maybe( + schema.arrayOf(schema.object({}, { allowUnknowns: true })) + ), + must_not: schema.maybe( + schema.arrayOf(schema.object({}, { allowUnknowns: true })) + ), + }), + }), + }), + }) + ), + time: schema.maybe( + schema.object({ + from: schema.maybe(schema.string()), + interval: schema.string(), + timezone: schema.string(), + to: schema.maybe(schema.string()), + }) + ), + }), + }, + }, + router.handleLegacyErrors(async (context, request, response) => { + try { + const uiSettings = await context.core.uiSettings.client.getAll(); + + const tlConfig = getTlConfig({ + request, + settings: _.defaults(uiSettings, timelionDefaults), // Just in case they delete some setting. + getFunction, + allowedGraphiteUrls: configManager.getGraphiteUrls(), + esShardTimeout: configManager.getEsShardTimeout(), + savedObjectsClient: context.core.savedObjects.client, + esDataClient: () => context.core.elasticsearch.dataClient, + }); + const chainRunner = chainRunnerFn(tlConfig); + const sheet = await Bluebird.all(chainRunner.processRequest(request.body)); + + return response.ok({ + body: { + sheet, + stats: chainRunner.getStats(), + }, + }); + } catch (err) { + logger.error(`${err.toString()}: ${err.stack}`); + // TODO Maybe we should just replace everywhere we throw with Boom? Probably. + if (err.isBoom) { + throw err; + } else { + return response.internalError({ + body: { + message: err.toString(), + }, + }); + } + } + }) + ); +} diff --git a/src/legacy/core_plugins/timelion/server/routes/validate_es.js b/src/plugins/timelion/server/routes/validate_es.ts similarity index 65% rename from src/legacy/core_plugins/timelion/server/routes/validate_es.js rename to src/plugins/timelion/server/routes/validate_es.ts index 5e39069f2a698e..70d53b6b2c5e3c 100644 --- a/src/legacy/core_plugins/timelion/server/routes/validate_es.js +++ b/src/plugins/timelion/server/routes/validate_es.ts @@ -18,15 +18,18 @@ */ import _ from 'lodash'; +import { IRouter } from 'kibana/server'; -export function validateEsRoute(server) { - server.route({ - method: 'GET', - path: '/api/timelion/validate/es', - handler: async function(request) { - const uiSettings = await request.getUiSettingsService().getAll(); +export function validateEsRoute(router: IRouter) { + router.get( + { + path: '/api/timelion/validate/es', + validate: false, + }, + async function(context, request, response) { + const uiSettings = await context.core.uiSettings.client.getAll(); - const { callWithRequest } = server.plugins.elasticsearch.getCluster('data'); + const { callAsCurrentUser } = context.core.elasticsearch.dataClient; const timefield = uiSettings['timelion:es.timefield']; @@ -51,24 +54,28 @@ export function validateEsRoute(server) { let resp = {}; try { - resp = await callWithRequest(request, 'search', body); + resp = await callAsCurrentUser('search', body); } catch (errResp) { resp = errResp; } if (_.has(resp, 'aggregations.maxAgg.value') && _.has(resp, 'aggregations.minAgg.value')) { - return { - ok: true, - field: timefield, - min: _.get(resp, 'aggregations.minAgg.value'), - max: _.get(resp, 'aggregations.maxAgg.value'), - }; + return response.ok({ + body: { + ok: true, + field: timefield, + min: _.get(resp, 'aggregations.minAgg.value'), + max: _.get(resp, 'aggregations.maxAgg.value'), + }, + }); } - return { - ok: false, - resp: resp, - }; - }, - }); + return response.ok({ + body: { + ok: false, + resp, + }, + }); + } + ); } diff --git a/src/legacy/core_plugins/timelion/server/series_functions/abs.js b/src/plugins/timelion/server/series_functions/abs.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/abs.js rename to src/plugins/timelion/server/series_functions/abs.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/abs.js b/src/plugins/timelion/server/series_functions/abs.test.js similarity index 94% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/abs.js rename to src/plugins/timelion/server/series_functions/abs.test.js index 28538d4da2f79f..385fad7db739ca 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/abs.js +++ b/src/plugins/timelion/server/series_functions/abs.test.js @@ -17,11 +17,11 @@ * under the License. */ -const fn = require(`../abs`); +import fn from './abs'; import _ from 'lodash'; const expect = require('chai').expect; -const seriesList = require('./fixtures/seriesList.js')(); +const seriesList = require('./fixtures/series_list.js')(); import invoke from './helpers/invoke_series_fn.js'; describe('abs.js', function() { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/aggregate.js b/src/plugins/timelion/server/series_functions/aggregate/aggregate.test.js similarity index 89% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/aggregate.js rename to src/plugins/timelion/server/series_functions/aggregate/aggregate.test.js index 6177f7cb7bac4d..d2708a525b9c6c 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/aggregate.js +++ b/src/plugins/timelion/server/series_functions/aggregate/aggregate.test.js @@ -17,17 +17,16 @@ * under the License. */ -const filename = require('path').basename(__filename); -const fn = require(`../aggregate/index.js`); +import fn from './index'; import _ from 'lodash'; const expect = require('chai').expect; -import invoke from './helpers/invoke_series_fn.js'; +import invoke from '../helpers/invoke_series_fn.js'; -describe(filename, () => { +describe('aggregate', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('../fixtures/series_list.js')(); }); it('first', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/aggregate/avg.js b/src/plugins/timelion/server/series_functions/aggregate/avg.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/aggregate/avg.js rename to src/plugins/timelion/server/series_functions/aggregate/avg.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/aggregate/cardinality.js b/src/plugins/timelion/server/series_functions/aggregate/cardinality.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/aggregate/cardinality.js rename to src/plugins/timelion/server/series_functions/aggregate/cardinality.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/aggregate/first.js b/src/plugins/timelion/server/series_functions/aggregate/first.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/aggregate/first.js rename to src/plugins/timelion/server/series_functions/aggregate/first.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/aggregate/index.js b/src/plugins/timelion/server/series_functions/aggregate/index.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/aggregate/index.js rename to src/plugins/timelion/server/series_functions/aggregate/index.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/aggregate/last.js b/src/plugins/timelion/server/series_functions/aggregate/last.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/aggregate/last.js rename to src/plugins/timelion/server/series_functions/aggregate/last.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/aggregate/max.js b/src/plugins/timelion/server/series_functions/aggregate/max.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/aggregate/max.js rename to src/plugins/timelion/server/series_functions/aggregate/max.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/aggregate/min.js b/src/plugins/timelion/server/series_functions/aggregate/min.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/aggregate/min.js rename to src/plugins/timelion/server/series_functions/aggregate/min.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/aggregate/sum.js b/src/plugins/timelion/server/series_functions/aggregate/sum.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/aggregate/sum.js rename to src/plugins/timelion/server/series_functions/aggregate/sum.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/bars.js b/src/plugins/timelion/server/series_functions/bars.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/bars.js rename to src/plugins/timelion/server/series_functions/bars.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/bars.js b/src/plugins/timelion/server/series_functions/bars.test.js similarity index 95% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/bars.js rename to src/plugins/timelion/server/series_functions/bars.test.js index 90b66759f7341b..74105330e6053d 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/bars.js +++ b/src/plugins/timelion/server/series_functions/bars.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../bars`); +import fn from './bars'; import _ from 'lodash'; const expect = require('chai').expect; @@ -26,7 +26,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('bars.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('creates the bars property, with defaults, on all series', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/color.js b/src/plugins/timelion/server/series_functions/color.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/color.js rename to src/plugins/timelion/server/series_functions/color.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/color.js b/src/plugins/timelion/server/series_functions/color.test.js similarity index 96% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/color.js rename to src/plugins/timelion/server/series_functions/color.test.js index f333a39bec5baf..2dc8c6fbcb8969 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/color.js +++ b/src/plugins/timelion/server/series_functions/color.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../color`); +import fn from './color'; import _ from 'lodash'; const expect = require('chai').expect; @@ -26,7 +26,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('color.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('sets the color, on all series', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/condition.js b/src/plugins/timelion/server/series_functions/condition.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/condition.js rename to src/plugins/timelion/server/series_functions/condition.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/condition.js b/src/plugins/timelion/server/series_functions/condition.test.js similarity index 97% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/condition.js rename to src/plugins/timelion/server/series_functions/condition.test.js index 533c5adfd62aba..469f84344eb4f3 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/condition.js +++ b/src/plugins/timelion/server/series_functions/condition.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../condition`); +import fn from './condition'; import moment from 'moment'; const expect = require('chai').expect; import invoke from './helpers/invoke_series_fn.js'; @@ -28,7 +28,7 @@ describe('condition.js', function() { let comparable; let seriesList; beforeEach(function() { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); comparable = getSeriesList('', [ [moment.utc('1980-01-01T00:00:00.000Z'), 12], [moment.utc('1981-01-01T00:00:00.000Z'), 33], diff --git a/src/legacy/core_plugins/timelion/server/series_functions/cusum.js b/src/plugins/timelion/server/series_functions/cusum.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/cusum.js rename to src/plugins/timelion/server/series_functions/cusum.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/cusum.js b/src/plugins/timelion/server/series_functions/cusum.test.js similarity index 93% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/cusum.js rename to src/plugins/timelion/server/series_functions/cusum.test.js index d9f534555b9d7e..29927a8d0faf21 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/cusum.js +++ b/src/plugins/timelion/server/series_functions/cusum.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../cusum`); +import fn from './cusum'; import _ from 'lodash'; const expect = require('chai').expect; @@ -26,7 +26,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('cusum.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('progressively adds the numbers in the list', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/derivative.js b/src/plugins/timelion/server/series_functions/derivative.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/derivative.js rename to src/plugins/timelion/server/series_functions/derivative.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/derivative.js b/src/plugins/timelion/server/series_functions/derivative.test.js similarity index 92% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/derivative.js rename to src/plugins/timelion/server/series_functions/derivative.test.js index 88ef4778ef2f16..296cf91711d027 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/derivative.js +++ b/src/plugins/timelion/server/series_functions/derivative.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../derivative`); +import fn from './derivative'; import _ from 'lodash'; const expect = require('chai').expect; @@ -26,7 +26,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('derivative.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('gets the change in the set', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/divide.js b/src/plugins/timelion/server/series_functions/divide.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/divide.js rename to src/plugins/timelion/server/series_functions/divide.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/divide.js b/src/plugins/timelion/server/series_functions/divide.test.js similarity index 92% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/divide.js rename to src/plugins/timelion/server/series_functions/divide.test.js index afe531922522fa..e24ec7d60541cb 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/divide.js +++ b/src/plugins/timelion/server/series_functions/divide.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../divide`); +import fn from './divide'; import _ from 'lodash'; const expect = require('chai').expect; @@ -26,7 +26,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('divide.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('divides by a single number', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/es.js b/src/plugins/timelion/server/series_functions/es/es.test.js similarity index 94% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/es.js rename to src/plugins/timelion/server/series_functions/es/es.test.js index f2b364afb723ba..4bd37b03f01fe2 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/es.js +++ b/src/plugins/timelion/server/series_functions/es/es.test.js @@ -17,52 +17,38 @@ * under the License. */ -const filename = require('path').basename(__filename); -import es from '../es'; +import es from './index'; -import tlConfigFn from './fixtures/tlConfig'; -import * as aggResponse from '../es/lib/agg_response_to_series_list'; -import buildRequest from '../es/lib/build_request'; -import createDateAgg from '../es/lib/create_date_agg'; -import esResponse from './fixtures/es_response'; +import tlConfigFn from '../fixtures/tl_config'; +import * as aggResponse from './lib/agg_response_to_series_list'; +import buildRequest from './lib/build_request'; +import createDateAgg from './lib/create_date_agg'; +import esResponse from '../fixtures/es_response'; import Bluebird from 'bluebird'; import _ from 'lodash'; import { expect } from 'chai'; import sinon from 'sinon'; -import invoke from './helpers/invoke_series_fn.js'; +import invoke from '../helpers/invoke_series_fn.js'; function stubRequestAndServer(response, indexPatternSavedObjects = []) { return { - server: { - plugins: { - elasticsearch: { - getCluster: sinon - .stub() - .withArgs('data') - .returns({ - callWithRequest: function() { - return Bluebird.resolve(response); - }, - }), - }, + esDataClient: sinon.stub().returns({ + callAsCurrentUser: function() { + return Bluebird.resolve(response); }, - }, - request: { - getSavedObjectsClient: function() { - return { - find: function() { - return Bluebird.resolve({ - saved_objects: indexPatternSavedObjects, - }); - }, - }; + }), + savedObjectsClient: { + find: function() { + return Bluebird.resolve({ + saved_objects: indexPatternSavedObjects, + }); }, }, }; } -describe(filename, () => { +describe('es', () => { let tlConfig; describe('seriesList processor', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/es/index.js b/src/plugins/timelion/server/series_functions/es/index.js similarity index 91% rename from src/legacy/core_plugins/timelion/server/series_functions/es/index.js rename to src/plugins/timelion/server/series_functions/es/index.js index 4ce2752fbf9be3..eb41663b71cf72 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/es/index.js +++ b/src/plugins/timelion/server/series_functions/es/index.js @@ -17,7 +17,6 @@ * under the License. */ -import { first, map } from 'rxjs/operators'; import { i18n } from '@kbn/i18n'; import _ from 'lodash'; import Datasource from '../../lib/classes/datasource'; @@ -109,7 +108,7 @@ export default new Datasource('es', { fit: 'nearest', }); - const findResp = await tlConfig.request.getSavedObjectsClient().find({ + const findResp = await tlConfig.savedObjectsClient.find({ type: 'index-pattern', fields: ['title', 'fields'], search: `"${config.index}"`, @@ -126,17 +125,12 @@ export default new Datasource('es', { }); } - const esShardTimeout = await tlConfig.server.newPlatform.__internals.elasticsearch.legacy.config$ - .pipe( - first(), - map(config => config.shardTimeout.asMilliseconds()) - ) - .toPromise(); + const esShardTimeout = tlConfig.esShardTimeout; const body = buildRequest(config, tlConfig, scriptedFields, esShardTimeout); - const { callWithRequest } = tlConfig.server.plugins.elasticsearch.getCluster('data'); - const resp = await callWithRequest(tlConfig.request, 'search', body); + const { callAsCurrentUser: callWithRequest } = tlConfig.esDataClient(); + const resp = await callWithRequest('search', body); if (!resp._shards.total) { throw new Error( i18n.translate('timelion.serverSideErrors.esFunction.indexNotFoundErrorMessage', { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/es/lib/agg_body.js b/src/plugins/timelion/server/series_functions/es/lib/agg_body.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/es/lib/agg_body.js rename to src/plugins/timelion/server/series_functions/es/lib/agg_body.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/es/lib/agg_response_to_series_list.js b/src/plugins/timelion/server/series_functions/es/lib/agg_response_to_series_list.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/es/lib/agg_response_to_series_list.js rename to src/plugins/timelion/server/series_functions/es/lib/agg_response_to_series_list.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/es/lib/build_request.js b/src/plugins/timelion/server/series_functions/es/lib/build_request.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/es/lib/build_request.js rename to src/plugins/timelion/server/series_functions/es/lib/build_request.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/es/lib/create_date_agg.js b/src/plugins/timelion/server/series_functions/es/lib/create_date_agg.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/es/lib/create_date_agg.js rename to src/plugins/timelion/server/series_functions/es/lib/create_date_agg.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/first.js b/src/plugins/timelion/server/series_functions/first.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/first.js rename to src/plugins/timelion/server/series_functions/first.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/first.js b/src/plugins/timelion/server/series_functions/first.test.js similarity index 92% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/first.js rename to src/plugins/timelion/server/series_functions/first.test.js index 3e86554e843b0c..96192b2b3903f6 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/first.js +++ b/src/plugins/timelion/server/series_functions/first.test.js @@ -17,10 +17,10 @@ * under the License. */ -const fn = require(`../first`); +import fn from './first'; const expect = require('chai').expect; -const seriesList = require('./fixtures/seriesList.js')(); +const seriesList = require('./fixtures/series_list.js')(); import invoke from './helpers/invoke_series_fn.js'; describe('first.js', function() { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/fit.js b/src/plugins/timelion/server/series_functions/fit.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/fit.js rename to src/plugins/timelion/server/series_functions/fit.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/fit.js b/src/plugins/timelion/server/series_functions/fit.test.js similarity index 98% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/fit.js rename to src/plugins/timelion/server/series_functions/fit.test.js index db9360da3f5921..75eaa2a50ea720 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/fit.js +++ b/src/plugins/timelion/server/series_functions/fit.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../fit`); +const fn = require(`src/plugins/timelion/server/series_functions/fit`); import moment from 'moment'; const expect = require('chai').expect; import invoke from './helpers/invoke_series_fn.js'; diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/fixtures/bucketList.js b/src/plugins/timelion/server/series_functions/fixtures/bucket_list.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/fixtures/bucketList.js rename to src/plugins/timelion/server/series_functions/fixtures/bucket_list.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/fixtures/es_response.js b/src/plugins/timelion/server/series_functions/fixtures/es_response.js similarity index 99% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/fixtures/es_response.js rename to src/plugins/timelion/server/series_functions/fixtures/es_response.js index 65aed311e232b8..22352258b2f518 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/fixtures/es_response.js +++ b/src/plugins/timelion/server/series_functions/fixtures/es_response.js @@ -17,6 +17,8 @@ * under the License. */ +/* eslint-disable quotes */ + /* Really didn't want to do this, but testing the agg flatten logic in units isn't really possible since the functions depend on each other diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/fixtures/seriesList.js b/src/plugins/timelion/server/series_functions/fixtures/series_list.js similarity index 97% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/fixtures/seriesList.js rename to src/plugins/timelion/server/series_functions/fixtures/series_list.js index 29b759af521ed0..90d9bc8417ef7e 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/fixtures/seriesList.js +++ b/src/plugins/timelion/server/series_functions/fixtures/series_list.js @@ -17,7 +17,7 @@ * under the License. */ -import buckets from './bucketList'; +import buckets from './bucket_list'; import getSeries from '../helpers/get_series'; import getSeriesList from '../helpers/get_series_list'; diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/fixtures/tlConfig.js b/src/plugins/timelion/server/series_functions/fixtures/tl_config.js similarity index 52% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/fixtures/tlConfig.js rename to src/plugins/timelion/server/series_functions/fixtures/tl_config.js index 6eea99424c4abe..bf477110be379b 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/fixtures/tlConfig.js +++ b/src/plugins/timelion/server/series_functions/fixtures/tl_config.js @@ -18,48 +18,25 @@ */ import moment from 'moment'; -import { of } from 'rxjs'; import sinon from 'sinon'; -import timelionDefaults from '../../../lib/get_namespaced_settings'; +import timelionDefaults from '../../lib/get_namespaced_settings'; import esResponse from './es_response'; export default function() { - const functions = require('../../../lib/load_functions')('series_functions'); - const kibanaServerConfigs = { - 'timelion.graphiteUrls': ['https://www.hostedgraphite.com/UID/ACCESS_KEY/graphite'], - }; - const server = { - plugins: { - timelion: { - getFunction: name => { - if (!functions[name]) throw new Error('No such function: ' + name); - return functions[name]; - }, - }, - elasticsearch: { - getCluster: sinon - .stub() - .withArgs('data') - .returns({ - callWithRequest: function() { - return Promise.resolve(esResponse); - }, - }), - }, + const functions = require('../../lib/load_functions')('series_functions'); + + const tlConfig = require('../../handlers/lib/tl_config.js')({ + getFunction: name => { + if (!functions[name]) throw new Error('No such function: ' + name); + return functions[name]; }, - newPlatform: { - __internals: { - elasticsearch: { - legacy: { config$: of({ shardTimeout: moment.duration(30000) }) }, - }, + esDataClient: sinon.stub().returns({ + callAsCurrentUser: function() { + return Promise.resolve(esResponse); }, - }, - config: () => ({ get: key => kibanaServerConfigs[key] }), - }; - - const tlConfig = require('../../../handlers/lib/tl_config.js')({ - server, - request: {}, + }), + esShardTimeout: moment.duration(30000), + allowedGraphiteUrls: ['https://www.hostedgraphite.com/UID/ACCESS_KEY/graphite'], }); tlConfig.time = { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/graphite.js b/src/plugins/timelion/server/series_functions/graphite.js similarity index 97% rename from src/legacy/core_plugins/timelion/server/series_functions/graphite.js rename to src/plugins/timelion/server/series_functions/graphite.js index a80dd2f3ff29e7..7b7bb1541bea0a 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/graphite.js +++ b/src/plugins/timelion/server/series_functions/graphite.js @@ -46,7 +46,7 @@ export default new Datasource('graphite', { min: moment(tlConfig.time.from).format('HH:mm[_]YYYYMMDD'), max: moment(tlConfig.time.to).format('HH:mm[_]YYYYMMDD'), }; - const allowedUrls = tlConfig.server.config().get('timelion.graphiteUrls'); + const allowedUrls = tlConfig.allowedGraphiteUrls; const configuredUrl = tlConfig.settings['timelion:graphite.url']; if (!allowedUrls.includes(configuredUrl)) { throw new Error( diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/graphite.js b/src/plugins/timelion/server/series_functions/graphite.test.js similarity index 85% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/graphite.js rename to src/plugins/timelion/server/series_functions/graphite.test.js index b7ee96ef77575f..914e0a7aaa4a11 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/graphite.js +++ b/src/plugins/timelion/server/series_functions/graphite.test.js @@ -17,12 +17,12 @@ * under the License. */ -import proxyquire from 'proxyquire'; -import Bluebird from 'bluebird'; const expect = require('chai').expect; -const graphiteResponse = function() { - return Bluebird.resolve({ +import fn from './graphite'; + +jest.mock('node-fetch', () => () => { + return Promise.resolve({ json: function() { return [ { @@ -37,14 +37,11 @@ const graphiteResponse = function() { ]; }, }); -}; - -const filename = require('path').basename(__filename); -const fn = proxyquire(`../${filename}`, { 'node-fetch': graphiteResponse }); +}); import invoke from './helpers/invoke_series_fn.js'; -describe(filename, function() { +describe('graphite', function() { it('should wrap the graphite response up in a seriesList', function() { return invoke(fn, []).then(function(result) { expect(result.output.list[0].data[0][1]).to.eql(3); diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/helpers/get_series.js b/src/plugins/timelion/server/series_functions/helpers/get_series.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/helpers/get_series.js rename to src/plugins/timelion/server/series_functions/helpers/get_series.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/helpers/get_series_list.js b/src/plugins/timelion/server/series_functions/helpers/get_series_list.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/helpers/get_series_list.js rename to src/plugins/timelion/server/series_functions/helpers/get_series_list.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/helpers/get_single_series_list.js b/src/plugins/timelion/server/series_functions/helpers/get_single_series_list.js similarity index 90% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/helpers/get_single_series_list.js rename to src/plugins/timelion/server/series_functions/helpers/get_single_series_list.js index cef5bed5d32185..c9cd3393e62f06 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/helpers/get_single_series_list.js +++ b/src/plugins/timelion/server/series_functions/helpers/get_single_series_list.js @@ -17,8 +17,8 @@ * under the License. */ -import getSeries from '../helpers/get_series'; -import getSeriesList from '../helpers/get_series_list'; +import getSeries from './get_series'; +import getSeriesList from './get_series_list'; import _ from 'lodash'; export default function(name, data) { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/helpers/invoke_series_fn.js b/src/plugins/timelion/server/series_functions/helpers/invoke_series_fn.js similarity index 89% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/helpers/invoke_series_fn.js rename to src/plugins/timelion/server/series_functions/helpers/invoke_series_fn.js index 51ef4c61a95e83..3a8bb92a883f87 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/helpers/invoke_series_fn.js +++ b/src/plugins/timelion/server/series_functions/helpers/invoke_series_fn.js @@ -20,10 +20,10 @@ // invokes a series_function with the specified arguments import _ from 'lodash'; -import indexArguments from '../../../handlers/lib/index_arguments'; +import indexArguments from '../../handlers/lib/index_arguments'; export default function invokeSeriesFn(fnDef, args, tlConfigOverrides) { - const tlConfig = _.merge(require('../fixtures/tlConfig')(), tlConfigOverrides); + const tlConfig = _.merge(require('../fixtures/tl_config')(), tlConfigOverrides); return Promise.all(args).then(function(args) { args.byName = indexArguments(fnDef, args); diff --git a/src/legacy/core_plugins/timelion/server/series_functions/hide.js b/src/plugins/timelion/server/series_functions/hide.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/hide.js rename to src/plugins/timelion/server/series_functions/hide.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/hide.js b/src/plugins/timelion/server/series_functions/hide.test.js similarity index 93% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/hide.js rename to src/plugins/timelion/server/series_functions/hide.test.js index 5d4b6246708471..5e71c1508e9e07 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/hide.js +++ b/src/plugins/timelion/server/series_functions/hide.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../hide`); +import fn from './hide'; import _ from 'lodash'; const expect = require('chai').expect; @@ -26,7 +26,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('hide.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('hides a series', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/holt/index.js b/src/plugins/timelion/server/series_functions/holt/index.js similarity index 98% rename from src/legacy/core_plugins/timelion/server/series_functions/holt/index.js rename to src/plugins/timelion/server/series_functions/holt/index.js index 0cc41df933e8c8..39cfe0bb3556dc 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/holt/index.js +++ b/src/plugins/timelion/server/series_functions/holt/index.js @@ -23,7 +23,7 @@ import Chainable from '../../lib/classes/chainable'; import ses from './lib/ses'; import des from './lib/des'; import tes from './lib/tes'; -import { toMS } from '../../../../vis_type_timelion/common/lib'; +import { toMS } from '../../../common/lib/to_milliseconds'; export default new Chainable('holt', { args: [ diff --git a/src/legacy/core_plugins/timelion/server/series_functions/holt/lib/des.js b/src/plugins/timelion/server/series_functions/holt/lib/des.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/holt/lib/des.js rename to src/plugins/timelion/server/series_functions/holt/lib/des.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/holt/lib/ses.js b/src/plugins/timelion/server/series_functions/holt/lib/ses.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/holt/lib/ses.js rename to src/plugins/timelion/server/series_functions/holt/lib/ses.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/holt/lib/tes.js b/src/plugins/timelion/server/series_functions/holt/lib/tes.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/holt/lib/tes.js rename to src/plugins/timelion/server/series_functions/holt/lib/tes.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/label.js b/src/plugins/timelion/server/series_functions/label.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/label.js rename to src/plugins/timelion/server/series_functions/label.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/label.js b/src/plugins/timelion/server/series_functions/label.test.js similarity index 94% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/label.js rename to src/plugins/timelion/server/series_functions/label.test.js index 9e0a92b1e40042..8d97083769060b 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/label.js +++ b/src/plugins/timelion/server/series_functions/label.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../label`); +import fn from './label'; import _ from 'lodash'; const expect = require('chai').expect; @@ -26,7 +26,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('label.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('changes the label on the series', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/legend.js b/src/plugins/timelion/server/series_functions/legend.js similarity index 98% rename from src/legacy/core_plugins/timelion/server/series_functions/legend.js rename to src/plugins/timelion/server/series_functions/legend.js index fd9ff53a1391f9..b4673186867296 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/legend.js +++ b/src/plugins/timelion/server/series_functions/legend.js @@ -20,7 +20,7 @@ import { i18n } from '@kbn/i18n'; import alter from '../lib/alter.js'; import Chainable from '../lib/classes/chainable'; -import { DEFAULT_TIME_FORMAT } from '../../../vis_type_timelion/common/lib'; +import { DEFAULT_TIME_FORMAT } from '../../common/lib'; export default new Chainable('legend', { args: [ diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/legend.js b/src/plugins/timelion/server/series_functions/legend.test.js similarity index 96% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/legend.js rename to src/plugins/timelion/server/series_functions/legend.test.js index 205f0c4431fccd..10789555deac83 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/legend.js +++ b/src/plugins/timelion/server/series_functions/legend.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../legend`); +import fn from './legend'; const expect = require('chai').expect; import invoke from './helpers/invoke_series_fn.js'; @@ -25,7 +25,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('legend.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('should create the _global object if it does not exist', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/lines.js b/src/plugins/timelion/server/series_functions/lines.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/lines.js rename to src/plugins/timelion/server/series_functions/lines.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/lines.js b/src/plugins/timelion/server/series_functions/lines.test.js similarity index 95% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/lines.js rename to src/plugins/timelion/server/series_functions/lines.test.js index 32974495b40eb4..c8985cd4791504 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/lines.js +++ b/src/plugins/timelion/server/series_functions/lines.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../lines`); +import fn from './lines'; const expect = require('chai').expect; import invoke from './helpers/invoke_series_fn.js'; @@ -25,7 +25,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('lines.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('should simply set show, steps, stack and lineWidth', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/log.js b/src/plugins/timelion/server/series_functions/log.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/log.js rename to src/plugins/timelion/server/series_functions/log.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/log.js b/src/plugins/timelion/server/series_functions/log.test.js similarity index 93% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/log.js rename to src/plugins/timelion/server/series_functions/log.test.js index 8cd2e2caa2c470..f37553508bc8ad 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/log.js +++ b/src/plugins/timelion/server/series_functions/log.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../log`); +import fn from './log'; import _ from 'lodash'; const expect = require('chai').expect; @@ -26,7 +26,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('log.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('should return the log10 value of every value', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/max.js b/src/plugins/timelion/server/series_functions/max.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/max.js rename to src/plugins/timelion/server/series_functions/max.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/max.js b/src/plugins/timelion/server/series_functions/max.test.js similarity index 93% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/max.js rename to src/plugins/timelion/server/series_functions/max.test.js index 9cc4afffb22ba9..7b3d819d0666b9 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/max.js +++ b/src/plugins/timelion/server/series_functions/max.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../max`); +import fn from './max'; import _ from 'lodash'; const expect = require('chai').expect; @@ -26,7 +26,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('max.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('keeps the max of a series vs a number', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/min.js b/src/plugins/timelion/server/series_functions/min.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/min.js rename to src/plugins/timelion/server/series_functions/min.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/min.js b/src/plugins/timelion/server/series_functions/min.test.js similarity index 93% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/min.js rename to src/plugins/timelion/server/series_functions/min.test.js index a89183ee90c6b6..d30339d6218f8a 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/min.js +++ b/src/plugins/timelion/server/series_functions/min.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../min`); +import fn from './min'; import _ from 'lodash'; const expect = require('chai').expect; @@ -26,7 +26,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('min.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('keeps the min of a series vs a number', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/movingaverage.js b/src/plugins/timelion/server/series_functions/movingaverage.js similarity index 98% rename from src/legacy/core_plugins/timelion/server/series_functions/movingaverage.js rename to src/plugins/timelion/server/series_functions/movingaverage.js index a4b458991c1bc0..be5f9027703476 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/movingaverage.js +++ b/src/plugins/timelion/server/series_functions/movingaverage.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import alter from '../lib/alter.js'; import _ from 'lodash'; import Chainable from '../lib/classes/chainable'; -import { toMS } from '../../../vis_type_timelion/common/lib'; +import { toMS } from '../../common/lib/to_milliseconds'; const validPositions = ['left', 'right', 'center']; const defaultPosition = 'center'; diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/movingaverage.js b/src/plugins/timelion/server/series_functions/movingaverage.test.js similarity index 96% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/movingaverage.js rename to src/plugins/timelion/server/series_functions/movingaverage.test.js index dceef96b1d1664..760d5af92a1eff 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/movingaverage.js +++ b/src/plugins/timelion/server/series_functions/movingaverage.test.js @@ -17,12 +17,12 @@ * under the License. */ -const fn = require(`../movingaverage`); +import fn from './movingaverage'; const expect = require('chai').expect; import moment from 'moment'; import _ from 'lodash'; -import buckets from './fixtures/bucketList'; +import buckets from './fixtures/bucket_list'; import getSeries from './helpers/get_series'; import getSeriesList from './helpers/get_series_list'; import invoke from './helpers/invoke_series_fn.js'; diff --git a/src/legacy/core_plugins/timelion/server/series_functions/movingstd.js b/src/plugins/timelion/server/series_functions/movingstd.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/movingstd.js rename to src/plugins/timelion/server/series_functions/movingstd.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/movingstd.js b/src/plugins/timelion/server/series_functions/movingstd.test.js similarity index 98% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/movingstd.js rename to src/plugins/timelion/server/series_functions/movingstd.test.js index d2ef271293afc6..bd165488687d4a 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/movingstd.js +++ b/src/plugins/timelion/server/series_functions/movingstd.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../movingstd`); +import fn from './movingstd'; import moment from 'moment'; const expect = require('chai').expect; diff --git a/src/legacy/core_plugins/timelion/server/series_functions/multiply.js b/src/plugins/timelion/server/series_functions/multiply.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/multiply.js rename to src/plugins/timelion/server/series_functions/multiply.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/multiply.js b/src/plugins/timelion/server/series_functions/multiply.test.js similarity index 92% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/multiply.js rename to src/plugins/timelion/server/series_functions/multiply.test.js index 0cc5665fb919a0..f460e5dd307310 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/multiply.js +++ b/src/plugins/timelion/server/series_functions/multiply.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../multiply`); +import fn from './multiply'; import _ from 'lodash'; const expect = require('chai').expect; @@ -26,7 +26,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('multiply.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('multiplies by a number', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/points.js b/src/plugins/timelion/server/series_functions/points.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/points.js rename to src/plugins/timelion/server/series_functions/points.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/points.js b/src/plugins/timelion/server/series_functions/points.test.js similarity index 96% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/points.js rename to src/plugins/timelion/server/series_functions/points.test.js index 53831f0f6138de..c45d68a5e45503 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/points.js +++ b/src/plugins/timelion/server/series_functions/points.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../points`); +import fn from './points'; import _ from 'lodash'; import assert from 'chai'; @@ -27,7 +27,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('points.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('should set the point radius', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/precision.js b/src/plugins/timelion/server/series_functions/precision.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/precision.js rename to src/plugins/timelion/server/series_functions/precision.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/precision.js b/src/plugins/timelion/server/series_functions/precision.test.js similarity index 93% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/precision.js rename to src/plugins/timelion/server/series_functions/precision.test.js index 29e3bc1ab66f8f..e8bd2c947c200d 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/precision.js +++ b/src/plugins/timelion/server/series_functions/precision.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../precision`); +import fn from './precision'; import _ from 'lodash'; const expect = require('chai').expect; @@ -26,7 +26,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('precision.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('keeps the min of a series vs a number', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/props.js b/src/plugins/timelion/server/series_functions/props.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/props.js rename to src/plugins/timelion/server/series_functions/props.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/quandl.js b/src/plugins/timelion/server/series_functions/quandl.js similarity index 98% rename from src/legacy/core_plugins/timelion/server/series_functions/quandl.js rename to src/plugins/timelion/server/series_functions/quandl.js index fd7de05464da33..40400ea44c7fc6 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/quandl.js +++ b/src/plugins/timelion/server/series_functions/quandl.js @@ -127,9 +127,6 @@ export default new Datasource('quandl', { }, ], }; - }) - .catch(function(e) { - throw e; }); }, }); diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/quandl.js b/src/plugins/timelion/server/series_functions/quandl.test.js similarity index 55% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/quandl.js rename to src/plugins/timelion/server/series_functions/quandl.test.js index 009c0e4e025cd9..fe5aab512370f9 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/quandl.js +++ b/src/plugins/timelion/server/series_functions/quandl.test.js @@ -17,85 +17,79 @@ * under the License. */ -import proxyquire from 'proxyquire'; -import Bluebird from 'bluebird'; -import assert from 'chai'; -const expect = assert.expect; +import fn from './quandl'; const parseURL = require('url').parse; const parseQueryString = require('querystring').parse; -const tlConfig = require('./fixtures/tlConfig')(); +const tlConfig = require('./fixtures/tl_config')(); import moment from 'moment'; +import fetchMock from 'node-fetch'; + +function parseUrlParams(url) { + return parseQueryString(parseURL(url).query); +} + +jest.mock('node-fetch', () => + jest.fn(() => + Promise.resolve({ + json: function() { + return { + name: '__beer__', + data: [ + ['2015-01-01', 3], + ['2015-01-02', 14], + ['2015-01-03', 15.92], + ['2015-01-04', 65.35], + ], + }; + }, + }) + ) +); -const filename = require('path').basename(__filename); import invoke from './helpers/invoke_series_fn.js'; -let fn; -let response; -let calledWith; -describe(filename, function() { +describe('quandl', function() { beforeEach(function() { - response = function(url) { - calledWith = { - params: parseQueryString(parseURL(url).query), - code: url.match(/datasets\/(.*).json/)[1], - }; - return Bluebird.resolve({ - json: function() { - return { - name: '__beer__', - data: [ - ['2015-01-01', 3], - ['2015-01-02', 14], - ['2015-01-03', 15.92], - ['2015-01-04', 65.35], - ], - }; - }, - }); - }; - fn = proxyquire(`../${filename}`, { 'node-fetch': response }); + jest.clearAllMocks(); }); it('should wrap the quandl response up in a seriesList', function() { return invoke(fn, []).then(function(result) { - expect(result.output.list[0].data[0][1]).to.eql(3); - expect(result.output.list[0].data[1][1]).to.eql(14); + expect(result.output.list[0].data[0][1]).toEqual(3); + expect(result.output.list[0].data[1][1]).toEqual(14); }); }); it('should set the label to that of the quandl name', function() { return invoke(fn, []).then(function(result) { - expect(result.output.list[0].label).to.eql('__beer__'); + expect(result.output.list[0].label).toEqual('__beer__'); }); }); it('should call the quandl API with the quandl code that has been passed', function() { return invoke(fn, ['BEER/IS_GOOD']).then(function() { - expect(calledWith.code).to.eql('BEER/IS_GOOD'); + expect(fetchMock).toHaveBeenCalled(); + expect(fetchMock.mock.calls[0][0].match(/datasets\/(.*).json/)[1]).toEqual('BEER/IS_GOOD'); }); }); it('should limit the time span and interval to the stuff attached to tlConfig', function() { return invoke(fn, []).then(function() { - expect(calledWith.params.trim_start).to.eql( - moment.utc(tlConfig.time.from).format('YYYY-MM-DD') - ); - expect(calledWith.params.trim_end).to.eql(moment.utc(tlConfig.time.to).format('YYYY-MM-DD')); + const params = parseUrlParams(fetchMock.mock.calls[0][0]); + expect(params.trim_start).toEqual(moment.utc(tlConfig.time.from).format('YYYY-MM-DD')); + expect(params.trim_end).toEqual(moment.utc(tlConfig.time.to).format('YYYY-MM-DD')); }); }); it('should throw an error is passed an unsupported interval', function() { - return invoke(fn, [], { time: { interval: '2d' } }) - .then(expect.fail) - .catch(function(r) { - expect(r).to.be.an('error'); - }); + return expect(invoke(fn, [], { time: { interval: '2d' } })).rejects.toThrowError(); }); it('should use the configured API key when talking to quandl', function() { return invoke(fn, [], { settings: { 'timelion:quandl.key': 'bEeR' } }).then(function() { - expect(calledWith.params.auth_token).to.eql('bEeR'); + const params = parseUrlParams(fetchMock.mock.calls[0][0]); + expect(params.auth_token).toEqual('bEeR'); }); }); }); diff --git a/src/legacy/core_plugins/timelion/server/series_functions/range.js b/src/plugins/timelion/server/series_functions/range.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/range.js rename to src/plugins/timelion/server/series_functions/range.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/range.js b/src/plugins/timelion/server/series_functions/range.test.js similarity index 93% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/range.js rename to src/plugins/timelion/server/series_functions/range.test.js index 38bee7d45565e6..f03488a6f2cf2b 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/range.js +++ b/src/plugins/timelion/server/series_functions/range.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../range`); +import fn from './range'; import _ from 'lodash'; const expect = require('chai').expect; @@ -26,7 +26,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('range.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); seriesList.list[0].data = [ [1000, 20], [2000, 10], diff --git a/src/legacy/core_plugins/timelion/server/series_functions/scale_interval.js b/src/plugins/timelion/server/series_functions/scale_interval.js similarity index 96% rename from src/legacy/core_plugins/timelion/server/series_functions/scale_interval.js rename to src/plugins/timelion/server/series_functions/scale_interval.js index b604015624dfd6..821f2714631ccf 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/scale_interval.js +++ b/src/plugins/timelion/server/series_functions/scale_interval.js @@ -19,7 +19,7 @@ import { i18n } from '@kbn/i18n'; import alter from '../lib/alter.js'; -import { toMS } from '../../../vis_type_timelion/common/lib'; +import { toMS } from '../../common/lib/to_milliseconds'; import _ from 'lodash'; import Chainable from '../lib/classes/chainable'; diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/scale_interval.js b/src/plugins/timelion/server/series_functions/scale_interval.test.js similarity index 92% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/scale_interval.js rename to src/plugins/timelion/server/series_functions/scale_interval.test.js index 12ad5503e69bfe..dfd5fd349ea041 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/scale_interval.js +++ b/src/plugins/timelion/server/series_functions/scale_interval.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../scale_interval`); +import fn from './scale_interval'; import _ from 'lodash'; const expect = require('chai').expect; @@ -26,7 +26,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('scale_interval.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('Can multiply to transform one interval to another', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/static.js b/src/plugins/timelion/server/series_functions/static.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/static.js rename to src/plugins/timelion/server/series_functions/static.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/static.js b/src/plugins/timelion/server/series_functions/static.test.js similarity index 97% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/static.js rename to src/plugins/timelion/server/series_functions/static.test.js index cea9525694ab3d..f791009e9e2b49 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/static.js +++ b/src/plugins/timelion/server/series_functions/static.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../static`); +import fn from './static'; import _ from 'lodash'; const expect = require('chai').expect; diff --git a/src/legacy/core_plugins/timelion/server/series_functions/subtract.js b/src/plugins/timelion/server/series_functions/subtract.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/subtract.js rename to src/plugins/timelion/server/series_functions/subtract.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/subtract.js b/src/plugins/timelion/server/series_functions/subtract.test.js similarity index 97% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/subtract.js rename to src/plugins/timelion/server/series_functions/subtract.test.js index 55d661ea95485e..7085e0baed0232 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/subtract.js +++ b/src/plugins/timelion/server/series_functions/subtract.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../subtract`); +import fn from './subtract'; import _ from 'lodash'; const expect = require('chai').expect; @@ -26,7 +26,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('subtract.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('it throws an error if first argument is not seriesList', async () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/sum.js b/src/plugins/timelion/server/series_functions/sum.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/sum.js rename to src/plugins/timelion/server/series_functions/sum.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/sum.js b/src/plugins/timelion/server/series_functions/sum.test.js similarity index 93% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/sum.js rename to src/plugins/timelion/server/series_functions/sum.test.js index 61e3a254d0b5de..d897d1a958460a 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/sum.js +++ b/src/plugins/timelion/server/series_functions/sum.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../sum`); +import fn from './sum'; import _ from 'lodash'; const expect = require('chai').expect; @@ -26,7 +26,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('sum.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('it adds a number', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/title.js b/src/plugins/timelion/server/series_functions/title.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/title.js rename to src/plugins/timelion/server/series_functions/title.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/title.js b/src/plugins/timelion/server/series_functions/title.test.js similarity index 93% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/title.js rename to src/plugins/timelion/server/series_functions/title.test.js index 973bb2ed0ea32d..e2238bb740bcdb 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/title.js +++ b/src/plugins/timelion/server/series_functions/title.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../title`); +import fn from './title'; import _ from 'lodash'; const expect = require('chai').expect; @@ -26,7 +26,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('title.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('sets the title property', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/trend/index.js b/src/plugins/timelion/server/series_functions/trend/index.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/trend/index.js rename to src/plugins/timelion/server/series_functions/trend/index.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/trend/lib/regress.js b/src/plugins/timelion/server/series_functions/trend/lib/regress.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/trend/lib/regress.js rename to src/plugins/timelion/server/series_functions/trend/lib/regress.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/trim.js b/src/plugins/timelion/server/series_functions/trim.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/trim.js rename to src/plugins/timelion/server/series_functions/trim.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/trim.js b/src/plugins/timelion/server/series_functions/trim.test.js similarity index 95% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/trim.js rename to src/plugins/timelion/server/series_functions/trim.test.js index ed7a8999d706a7..e2b88a52f0045e 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/trim.js +++ b/src/plugins/timelion/server/series_functions/trim.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../trim`); +import fn from './trim'; import _ from 'lodash'; const expect = require('chai').expect; @@ -26,7 +26,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('trim.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('Sets the first and last values to null by default', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/worldbank.js b/src/plugins/timelion/server/series_functions/worldbank.js similarity index 96% rename from src/legacy/core_plugins/timelion/server/series_functions/worldbank.js rename to src/plugins/timelion/server/series_functions/worldbank.js index 3630d6c956b681..f19bfab01b0f9e 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/worldbank.js +++ b/src/plugins/timelion/server/series_functions/worldbank.js @@ -45,7 +45,7 @@ export default new Datasource('worldbank', { The worldbank provides mostly yearly data, and often has no data for the current year. Try {offsetQuery} if you get no data for recent time ranges.`, values: { - worldbankUrl: 'http://data.worldbank.org/', + worldbankUrl: 'https://api.worldbank.org/v2/', offsetQuery: 'offset=-1y', }, }), @@ -53,7 +53,7 @@ export default new Datasource('worldbank', { // http://api.worldbank.org/en/countries/ind;chn/indicators/DPANUSSPF?date=2000:2006&MRV=5 const config = _.defaults(args.byName, { - code: 'countries/wld/indicators/SP.POP.TOTL', + code: 'country/all/indicator/SP.POP.TOTL', }); const time = { @@ -62,7 +62,7 @@ export default new Datasource('worldbank', { }; const URL = - 'http://api.worldbank.org/' + + 'https://api.worldbank.org/v2/' + config.code + '?date=' + time.min + diff --git a/src/legacy/core_plugins/timelion/server/series_functions/worldbank_indicators.js b/src/plugins/timelion/server/series_functions/worldbank_indicators.js similarity index 95% rename from src/legacy/core_plugins/timelion/server/series_functions/worldbank_indicators.js rename to src/plugins/timelion/server/series_functions/worldbank_indicators.js index dc9a3b4a67b338..7049eefb8f808d 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/worldbank_indicators.js +++ b/src/plugins/timelion/server/series_functions/worldbank_indicators.js @@ -54,7 +54,7 @@ export default new Datasource('worldbank_indicators', { mostly yearly data, and often has no data for the current year. Try {offsetQuery} if you get no data for recent time ranges.`, values: { - worldbankUrl: 'http://data.worldbank.org/', + worldbankUrl: 'https://api.worldbank.org/v2/', offsetQuery: 'offset=-1y', }, }), @@ -66,7 +66,7 @@ export default new Datasource('worldbank_indicators', { const countries = config.country.split(':'); const seriesLists = _.map(countries, function(country) { - const code = 'countries/' + country + '/indicators/' + config.indicator; + const code = 'country/' + country + '/indicator/' + config.indicator; const wbArgs = [code]; wbArgs.byName = { code: code }; return worldbank.timelionFn(wbArgs, tlConfig); diff --git a/src/legacy/core_plugins/timelion/server/series_functions/yaxis.js b/src/plugins/timelion/server/series_functions/yaxis.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/yaxis.js rename to src/plugins/timelion/server/series_functions/yaxis.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/yaxis.js b/src/plugins/timelion/server/series_functions/yaxis.test.js similarity index 97% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/yaxis.js rename to src/plugins/timelion/server/series_functions/yaxis.test.js index 9210a2cd300b09..87001ce45fd39f 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/yaxis.js +++ b/src/plugins/timelion/server/series_functions/yaxis.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../yaxis`); +import fn from './yaxis'; import Bluebird from 'bluebird'; const expect = require('chai').expect; import invoke from './helpers/invoke_series_fn.js'; @@ -25,7 +25,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('yaxis.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('creates the yaxes array', () => { diff --git a/src/legacy/core_plugins/timelion/timelion.json b/src/plugins/timelion/server/timelion.json similarity index 100% rename from src/legacy/core_plugins/timelion/timelion.json rename to src/plugins/timelion/server/timelion.json diff --git a/src/legacy/core_plugins/timelion/server/types.ts b/src/plugins/timelion/server/types.ts similarity index 100% rename from src/legacy/core_plugins/timelion/server/types.ts rename to src/plugins/timelion/server/types.ts diff --git a/x-pack/legacy/plugins/ml/public/application/routing/routes/timeseriesexplorer.tsx b/x-pack/legacy/plugins/ml/public/application/routing/routes/timeseriesexplorer.tsx index f824faf7845c64..bc457f1a3fe89e 100644 --- a/x-pack/legacy/plugins/ml/public/application/routing/routes/timeseriesexplorer.tsx +++ b/x-pack/legacy/plugins/ml/public/application/routing/routes/timeseriesexplorer.tsx @@ -72,6 +72,11 @@ const PageWrapper: FC = ({ config, deps }) => { ); }; +interface AppStateZoom { + from: string; + to: string; +} + interface TimeSeriesExplorerUrlStateManager { config: any; jobsWithTimeRange: MlJobWithTimeRange[]; @@ -159,10 +164,9 @@ export const TimeSeriesExplorerUrlStateManager: FC( + appState?.mlTimeSeriesExplorer?.forecastId + ); + useEffect(() => { if ( autoZoomDuration !== undefined && @@ -221,6 +231,9 @@ export const TimeSeriesExplorerUrlStateManager: FC { @@ -231,20 +244,6 @@ export const TimeSeriesExplorerUrlStateManager: FC { // eslint-disable-next-line no-console @@ -282,6 +282,11 @@ export const TimeSeriesExplorerUrlStateManager: FC ); diff --git a/x-pack/legacy/plugins/ml/public/application/timeseriesexplorer/components/timeseries_chart/timeseries_chart.js b/x-pack/legacy/plugins/ml/public/application/timeseriesexplorer/components/timeseries_chart/timeseries_chart.js index d8e9e4379395a5..4b2d640b99bb3d 100644 --- a/x-pack/legacy/plugins/ml/public/application/timeseriesexplorer/components/timeseries_chart/timeseries_chart.js +++ b/x-pack/legacy/plugins/ml/public/application/timeseriesexplorer/components/timeseries_chart/timeseries_chart.js @@ -385,6 +385,7 @@ const TimeseriesChartIntl = injectI18n( drawContextElements(context, this.vizWidth, contextChartHeight, swimlaneHeight); } + contextChartInitialized = false; drawContextChartSelection() { const { contextChartData, @@ -446,7 +447,10 @@ const TimeseriesChartIntl = injectI18n( }; if (!_.isEqual(newSelectedBounds, this.selectedBounds)) { this.selectedBounds = newSelectedBounds; - contextChartSelected({ from: contextXScaleDomain[0], to: contextXScaleDomain[1] }); + if (this.contextChartInitialized === false) { + this.contextChartInitialized = true; + contextChartSelected({ from: contextXScaleDomain[0], to: contextXScaleDomain[1] }); + } } } } diff --git a/x-pack/legacy/plugins/ml/public/application/timeseriesexplorer/timeseriesexplorer.d.ts b/x-pack/legacy/plugins/ml/public/application/timeseriesexplorer/timeseriesexplorer.d.ts index 6c1bb01137c917..4253316123f01a 100644 --- a/x-pack/legacy/plugins/ml/public/application/timeseriesexplorer/timeseriesexplorer.d.ts +++ b/x-pack/legacy/plugins/ml/public/application/timeseriesexplorer/timeseriesexplorer.d.ts @@ -19,8 +19,7 @@ declare const TimeSeriesExplorer: FC<{ selectedJobId: string; selectedDetectorIndex: number; selectedEntities: any[]; - selectedForecastId: string; - setGlobalState: (arg: any) => void; + selectedForecastId?: string; tableInterval: string; tableSeverity: number; zoom?: { from: string; to: string }; diff --git a/x-pack/legacy/plugins/ml/public/application/timeseriesexplorer/timeseriesexplorer.js b/x-pack/legacy/plugins/ml/public/application/timeseriesexplorer/timeseriesexplorer.js index 6d918a62d721a3..02cb2e3f4e25a5 100644 --- a/x-pack/legacy/plugins/ml/public/application/timeseriesexplorer/timeseriesexplorer.js +++ b/x-pack/legacy/plugins/ml/public/application/timeseriesexplorer/timeseriesexplorer.js @@ -188,6 +188,24 @@ export class TimeSeriesExplorer extends React.Component { */ contextChart$ = new Subject(); + /** + * Returns field names that don't have a selection yet. + */ + getFieldNamesWithEmptyValues = () => { + const latestEntityControls = this.getControlsForDetector(); + return latestEntityControls + .filter(({ fieldValue }) => !fieldValue) + .map(({ fieldName }) => fieldName); + }; + + /** + * Checks if all entity control dropdowns have a selection. + */ + arePartitioningFieldsProvided = () => { + const fieldNamesWithEmptyValues = this.getFieldNamesWithEmptyValues(); + return fieldNamesWithEmptyValues.length === 0; + }; + detectorIndexChangeHandler = e => { const { appStateHandler } = this.props; const id = e.target.value; @@ -296,7 +314,17 @@ export class TimeSeriesExplorer extends React.Component { } contextChartSelected = selection => { + const zoomState = { + from: selection.from.toISOString(), + to: selection.to.toISOString(), + }; + + if (isEqual(this.props.zoom, zoomState) && this.state.focusChartData !== undefined) { + return; + } + this.contextChart$.next(selection); + this.props.appStateHandler(APP_STATE_ACTION.SET_ZOOM, zoomState); }; entityFieldValueChanged = (entity, fieldValue) => { @@ -509,27 +537,38 @@ export class TimeSeriesExplorer extends React.Component { (Array.isArray(stateUpdate.contextForecastData) && stateUpdate.contextForecastData.length > 0); stateUpdate.loading = false; + // Set zoomFrom/zoomTo attributes in scope which will result in the metric chart automatically // selecting the specified range in the context chart, and so loading that date range in the focus chart. - if (stateUpdate.contextChartData.length) { + // Only touch the zoom range if data for the context chart has been loaded and all necessary + // partition fields have a selection. + if ( + stateUpdate.contextChartData.length && + this.arePartitioningFieldsProvided() === true + ) { // Check for a zoom parameter in the appState (URL). let focusRange = calculateInitialFocusRange( zoom, stateUpdate.contextAggregationInterval, bounds ); - - if (focusRange === undefined) { + if ( + focusRange === undefined || + this.previousSelectedForecastId !== this.props.selectedForecastId + ) { focusRange = calculateDefaultFocusRange( autoZoomDuration, stateUpdate.contextAggregationInterval, stateUpdate.contextChartData, stateUpdate.contextForecastData ); + this.previousSelectedForecastId = this.props.selectedForecastId; } - stateUpdate.zoomFrom = focusRange[0]; - stateUpdate.zoomTo = focusRange[1]; + this.contextChartSelected({ + from: focusRange[0], + to: focusRange[1], + }); } this.setState(stateUpdate); @@ -881,11 +920,6 @@ export class TimeSeriesExplorer extends React.Component { ...refreshFocusData, ...tableData, }); - const zoomState = { - from: selection.from.toISOString(), - to: selection.to.toISOString(), - }; - this.props.appStateHandler(APP_STATE_ACTION.SET_ZOOM, zoomState); }) ); @@ -917,6 +951,11 @@ export class TimeSeriesExplorer extends React.Component { if (this.props.selectedForecastId !== undefined) { // Ensure the forecast data will be shown if hidden previously. this.setState({ showForecast: true }); + // Not best practice but we need the previous value for another comparison + // once all the data was loaded. + if (previousProps !== undefined) { + this.previousSelectedForecastId = previousProps.selectedForecastId; + } } } @@ -927,8 +966,7 @@ export class TimeSeriesExplorer extends React.Component { !isEqual(previousProps.selectedDetectorIndex, this.props.selectedDetectorIndex) || !isEqual(previousProps.selectedEntities, this.props.selectedEntities) || !isEqual(previousProps.selectedForecastId, this.props.selectedForecastId) || - previousProps.selectedJobId !== this.props.selectedJobId || - !isEqual(previousProps.zoom, this.props.zoom) + previousProps.selectedJobId !== this.props.selectedJobId ) { const fullRefresh = previousProps === undefined || @@ -961,41 +999,6 @@ export class TimeSeriesExplorer extends React.Component { ) { tableControlsListener(); } - - if ( - this.props.autoZoomDuration === undefined || - this.props.selectedForecastId !== undefined || - this.state.contextAggregationInterval === undefined || - this.state.contextChartData === undefined || - this.state.contextChartData.length === 0 - ) { - return; - } - - const defaultRange = calculateDefaultFocusRange( - this.props.autoZoomDuration, - this.state.contextAggregationInterval, - this.state.contextChartData, - this.state.contextForecastData - ); - - const selection = { - from: this.state.zoomFrom, - to: this.state.zoomTo, - }; - - if ( - (selection.from.getTime() !== defaultRange[0].getTime() || - selection.to.getTime() !== defaultRange[1].getTime()) && - isNaN(Date.parse(selection.from)) === false && - isNaN(Date.parse(selection.to)) === false - ) { - const zoomState = { - from: selection.from.toISOString(), - to: selection.to.toISOString(), - }; - this.props.appStateHandler(APP_STATE_ACTION.SET_ZOOM, zoomState); - } } componentWillUnmount() { @@ -1070,12 +1073,8 @@ export class TimeSeriesExplorer extends React.Component { const selectedJob = mlJobService.getJob(selectedJobId); const entityControls = this.getControlsForDetector(); - - const fieldNamesWithEmptyValues = entityControls - .filter(({ fieldValue }) => !fieldValue) - .map(({ fieldName }) => fieldName); - - const arePartitioningFieldsProvided = fieldNamesWithEmptyValues.length === 0; + const fieldNamesWithEmptyValues = this.getFieldNamesWithEmptyValues(); + const arePartitioningFieldsProvided = this.arePartitioningFieldsProvided(); const detectorSelectOptions = getViewableDetectors(selectedJob).map(d => ({ value: d.index, diff --git a/x-pack/legacy/plugins/siem/public/components/timeline/body/events/index.tsx b/x-pack/legacy/plugins/siem/public/components/timeline/body/events/index.tsx index 9361a46dddff45..6b2e105ad05664 100644 --- a/x-pack/legacy/plugins/siem/public/components/timeline/body/events/index.tsx +++ b/x-pack/legacy/plugins/siem/public/components/timeline/body/events/index.tsx @@ -31,6 +31,7 @@ interface Props { browserFields: BrowserFields; columnHeaders: ColumnHeader[]; columnRenderers: ColumnRenderer[]; + containerElementRef: HTMLDivElement; data: TimelineItem[]; eventIdToNoteIds: Readonly>; getNotesByIds: (noteIds: string[]) => Note[]; @@ -53,61 +54,62 @@ interface Props { // Passing the styles directly to the component because the width is // being calculated and is recommended by Styled Components for performance // https://github.com/styled-components/styled-components/issues/134#issuecomment-312415291 -export const Events = React.memo( - ({ - actionsColumnWidth, - addNoteToEvent, - browserFields, - columnHeaders, - columnRenderers, - data, - eventIdToNoteIds, - getNotesByIds, - id, - isEventViewer = false, - loadingEventIds, - onColumnResized, - onPinEvent, - onRowSelected, - onUpdateColumns, - onUnPinEvent, - pinnedEventIds, - rowRenderers, - selectedEventIds, - showCheckboxes, - toggleColumn, - updateNote, - }) => ( - - {data.map((event, i) => ( - - ))} - - ) +const EventsComponent: React.FC = ({ + actionsColumnWidth, + addNoteToEvent, + browserFields, + columnHeaders, + columnRenderers, + containerElementRef, + data, + eventIdToNoteIds, + getNotesByIds, + id, + isEventViewer = false, + loadingEventIds, + onColumnResized, + onPinEvent, + onRowSelected, + onUpdateColumns, + onUnPinEvent, + pinnedEventIds, + rowRenderers, + selectedEventIds, + showCheckboxes, + toggleColumn, + updateNote, +}) => ( + + {data.map((event, i) => ( + + ))} + ); -Events.displayName = 'Events'; + +export const Events = React.memo(EventsComponent); diff --git a/x-pack/legacy/plugins/siem/public/components/timeline/body/events/stateful_event.tsx b/x-pack/legacy/plugins/siem/public/components/timeline/body/events/stateful_event.tsx index 6c43d9a63029c2..5704b6030e7d19 100644 --- a/x-pack/legacy/plugins/siem/public/components/timeline/body/events/stateful_event.tsx +++ b/x-pack/legacy/plugins/siem/public/components/timeline/body/events/stateful_event.tsx @@ -35,6 +35,7 @@ import { StatefulEventChild } from './stateful_event_child'; interface Props { actionsColumnWidth: number; + containerElementRef: HTMLDivElement; addNoteToEvent: AddNoteToEvent; browserFields: BrowserFields; columnHeaders: ColumnHeader[]; @@ -115,6 +116,7 @@ const StatefulEventComponent: React.FC = ({ actionsColumnWidth, addNoteToEvent, browserFields, + containerElementRef, columnHeaders, columnRenderers, event, @@ -201,6 +203,7 @@ const StatefulEventComponent: React.FC = ({ {({ isVisible }) => { @@ -279,7 +282,7 @@ const StatefulEventComponent: React.FC = ({ } else { // Height place holder for visibility detection as well as re-rendering sections. const height = - divElement.current != null + divElement.current != null && divElement.current.clientHeight ? `${divElement.current.clientHeight}px` : DEFAULT_ROW_HEIGHT; diff --git a/x-pack/legacy/plugins/siem/public/components/timeline/body/index.tsx b/x-pack/legacy/plugins/siem/public/components/timeline/body/index.tsx index c4ad532f76fc42..f00da482669278 100644 --- a/x-pack/legacy/plugins/siem/public/components/timeline/body/index.tsx +++ b/x-pack/legacy/plugins/siem/public/components/timeline/body/index.tsx @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import React, { useMemo } from 'react'; +import React, { useMemo, useRef } from 'react'; import { BrowserFields } from '../../../containers/source'; import { TimelineItem, TimelineNonEcsData } from '../../../graphql/types'; @@ -95,6 +95,7 @@ export const Body = React.memo( toggleColumn, updateNote, }) => { + const containerElementRef = useRef(null); const timelineTypeContext = useTimelineTypeContext(); const additionalActionWidth = timelineTypeContext.timelineActions?.reduce((acc, v) => acc + v.width, 0) ?? 0; @@ -112,7 +113,7 @@ export const Body = React.memo( return ( <> - + ( />