diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatterntype.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatterntype.md new file mode 100644 index 00000000000000..46fd3a0725e403 --- /dev/null +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatterntype.md @@ -0,0 +1,19 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [IndexPatternType](./kibana-plugin-plugins-data-public.indexpatterntype.md) + +## IndexPatternType enum + +Signature: + +```typescript +export declare enum IndexPatternType +``` + +## Enumeration Members + +| Member | Value | Description | +| --- | --- | --- | +| DEFAULT | "default" | | +| ROLLUP | "rollup" | | + diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatterntypemeta.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatterntypemeta.md index e6690b244c9ea5..19a884862d4609 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatterntypemeta.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatterntypemeta.md @@ -15,4 +15,5 @@ export interface TypeMeta | Property | Type | Description | | --- | --- | --- | | [aggs](./kibana-plugin-plugins-data-public.indexpatterntypemeta.aggs.md) | Record<string, AggregationRestrictions> | | +| [params](./kibana-plugin-plugins-data-public.indexpatterntypemeta.params.md) | {
rollup_index: string;
} | | diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatterntypemeta.params.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatterntypemeta.params.md new file mode 100644 index 00000000000000..12646a39188a07 --- /dev/null +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatterntypemeta.params.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [IndexPatternTypeMeta](./kibana-plugin-plugins-data-public.indexpatterntypemeta.md) > [params](./kibana-plugin-plugins-data-public.indexpatterntypemeta.params.md) + +## IndexPatternTypeMeta.params property + +Signature: + +```typescript +params?: { + rollup_index: string; + }; +``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md index 65c4601d5faec9..7c2911875ee054 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md @@ -31,6 +31,7 @@ | --- | --- | | [BUCKET\_TYPES](./kibana-plugin-plugins-data-public.bucket_types.md) | | | [ES\_FIELD\_TYPES](./kibana-plugin-plugins-data-public.es_field_types.md) | \* | +| [IndexPatternType](./kibana-plugin-plugins-data-public.indexpatterntype.md) | | | [KBN\_FIELD\_TYPES](./kibana-plugin-plugins-data-public.kbn_field_types.md) | \* | | [METRIC\_TYPES](./kibana-plugin-plugins-data-public.metric_types.md) | | | [QuerySuggestionTypes](./kibana-plugin-plugins-data-public.querysuggestiontypes.md) | | diff --git a/src/plugins/data/common/index_patterns/types.ts b/src/plugins/data/common/index_patterns/types.ts index b03e745df74a6a..58cc6d0478d5e8 100644 --- a/src/plugins/data/common/index_patterns/types.ts +++ b/src/plugins/data/common/index_patterns/types.ts @@ -150,9 +150,17 @@ export type AggregationRestrictions = Record< time_zone?: string; } >; + export interface TypeMeta { aggs?: Record; - [key: string]: any; + params?: { + rollup_index: string; + }; +} + +export enum IndexPatternType { + DEFAULT = 'default', + ROLLUP = 'rollup', } export type FieldSpecConflictDescriptions = Record; diff --git a/src/plugins/data/public/index.ts b/src/plugins/data/public/index.ts index e9e50ebfaf138c..9af1cbf95d94da 100644 --- a/src/plugins/data/public/index.ts +++ b/src/plugins/data/public/index.ts @@ -269,6 +269,7 @@ export { IndexPatternLoadExpressionFunctionDefinition, fieldList, INDEX_PATTERN_SAVED_OBJECT_TYPE, + IndexPatternType, } from '../common'; export { DuplicateIndexPatternError } from '../common/index_patterns/errors'; diff --git a/src/plugins/data/public/public.api.md b/src/plugins/data/public/public.api.md index b8af7c12d57fcc..6c0ddd000f30aa 100644 --- a/src/plugins/data/public/public.api.md +++ b/src/plugins/data/public/public.api.md @@ -1688,14 +1688,26 @@ export class IndexPatternsService { updateSavedObject(indexPattern: IndexPattern, saveAttempts?: number, ignoreErrors?: boolean): Promise; } +// Warning: (ae-missing-release-tag) "IndexPatternType" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export enum IndexPatternType { + // (undocumented) + DEFAULT = "default", + // (undocumented) + ROLLUP = "rollup" +} + // Warning: (ae-missing-release-tag) "TypeMeta" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) export interface IndexPatternTypeMeta { - // (undocumented) - [key: string]: any; // (undocumented) aggs?: Record; + // (undocumented) + params?: { + rollup_index: string; + }; } // Warning: (ae-missing-release-tag) "injectReferences" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) @@ -2766,20 +2778,20 @@ export interface WaitUntilNextSessionCompletesOptions { // src/plugins/data/public/index.ts:238:27 - (ae-forgotten-export) The symbol "validateIndexPattern" needs to be exported by the entry point index.d.ts // src/plugins/data/public/index.ts:238:27 - (ae-forgotten-export) The symbol "flattenHitWrapper" needs to be exported by the entry point index.d.ts // src/plugins/data/public/index.ts:238:27 - (ae-forgotten-export) The symbol "formatHitProvider" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:409:20 - (ae-forgotten-export) The symbol "getResponseInspectorStats" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:409:20 - (ae-forgotten-export) The symbol "tabifyAggResponse" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:409:20 - (ae-forgotten-export) The symbol "tabifyGetColumns" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:411:1 - (ae-forgotten-export) The symbol "CidrMask" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:412:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:421:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:422:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:423:1 - (ae-forgotten-export) The symbol "IpAddress" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:424:1 - (ae-forgotten-export) The symbol "isDateHistogramBucketAggConfig" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:428:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:429:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:432:1 - (ae-forgotten-export) The symbol "parseInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:433:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:436:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:410:20 - (ae-forgotten-export) The symbol "getResponseInspectorStats" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:410:20 - (ae-forgotten-export) The symbol "tabifyAggResponse" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:410:20 - (ae-forgotten-export) The symbol "tabifyGetColumns" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:412:1 - (ae-forgotten-export) The symbol "CidrMask" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:413:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:422:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:423:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:424:1 - (ae-forgotten-export) The symbol "IpAddress" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:425:1 - (ae-forgotten-export) The symbol "isDateHistogramBucketAggConfig" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:429:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:430:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:433:1 - (ae-forgotten-export) The symbol "parseInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:434:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:437:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts // src/plugins/data/public/query/state_sync/connect_to_query_state.ts:34:5 - (ae-forgotten-export) The symbol "FilterStateStore" needs to be exported by the entry point index.d.ts // src/plugins/data/public/search/session/session_service.ts:62:5 - (ae-forgotten-export) The symbol "UrlGeneratorStateMapping" needs to be exported by the entry point index.d.ts diff --git a/src/plugins/index_pattern_management/public/components/edit_index_pattern/indexed_fields_table/__snapshots__/indexed_fields_table.test.tsx.snap b/src/plugins/index_pattern_management/public/components/edit_index_pattern/indexed_fields_table/__snapshots__/indexed_fields_table.test.tsx.snap index 32a2b936edd004..776294a93df185 100644 --- a/src/plugins/index_pattern_management/public/components/edit_index_pattern/indexed_fields_table/__snapshots__/indexed_fields_table.test.tsx.snap +++ b/src/plugins/index_pattern_management/public/components/edit_index_pattern/indexed_fields_table/__snapshots__/indexed_fields_table.test.tsx.snap @@ -1,5 +1,146 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`IndexedFieldsTable IndexedFieldsTable with rollup index pattern should render normally 1`] = ` +
+ + +`; + exports[`IndexedFieldsTable should filter based on the query bar 1`] = `
diff --git a/src/plugins/index_pattern_management/public/components/edit_index_pattern/indexed_fields_table/components/table/table.test.tsx b/src/plugins/index_pattern_management/public/components/edit_index_pattern/indexed_fields_table/components/table/table.test.tsx index b9957534d8c694..163152b52e80b9 100644 --- a/src/plugins/index_pattern_management/public/components/edit_index_pattern/indexed_fields_table/components/table/table.test.tsx +++ b/src/plugins/index_pattern_management/public/components/edit_index_pattern/indexed_fields_table/components/table/table.test.tsx @@ -8,13 +8,13 @@ import React from 'react'; import { shallow } from 'enzyme'; -import { IIndexPattern } from 'src/plugins/data/public'; +import { IndexPattern } from 'src/plugins/data/public'; import { IndexedFieldItem } from '../../types'; import { Table, renderFieldName } from './table'; const indexPattern = { timeFieldName: 'timestamp', -} as IIndexPattern; +} as IndexPattern; const items: IndexedFieldItem[] = [ { diff --git a/src/plugins/index_pattern_management/public/components/edit_index_pattern/indexed_fields_table/indexed_fields_table.test.tsx b/src/plugins/index_pattern_management/public/components/edit_index_pattern/indexed_fields_table/indexed_fields_table.test.tsx index e587ada6695cb4..c819b1d3a33fd9 100644 --- a/src/plugins/index_pattern_management/public/components/edit_index_pattern/indexed_fields_table/indexed_fields_table.test.tsx +++ b/src/plugins/index_pattern_management/public/components/edit_index_pattern/indexed_fields_table/indexed_fields_table.test.tsx @@ -8,8 +8,9 @@ import React from 'react'; import { shallow } from 'enzyme'; -import { IndexPatternField, IndexPattern } from 'src/plugins/data/public'; +import { IndexPatternField, IndexPattern, IndexPatternType } from 'src/plugins/data/public'; import { IndexedFieldsTable } from './indexed_fields_table'; +import { RollupIndexPatternListConfig } from '../../../service/list'; jest.mock('@elastic/eui', () => ({ EuiFlexGroup: 'eui-flex-group', @@ -28,7 +29,8 @@ jest.mock('./components/table', () => ({ const helpers = { editField: (fieldName: string) => {}, deleteField: (fieldName: string) => {}, - getFieldInfo: () => [], + // getFieldInfo handles non rollups as well + getFieldInfo: new RollupIndexPatternListConfig().getFieldInfo, }; const indexPattern = ({ @@ -36,6 +38,32 @@ const indexPattern = ({ getFormatterForFieldNoDefault: () => ({ params: () => ({}) }), } as unknown) as IndexPattern; +const rollupIndexPattern = ({ + type: IndexPatternType.ROLLUP, + typeMeta: { + 'rollup-index': 'rollup', + aggs: { + date_histogram: { + timestamp: { + agg: 'date_histogram', + fixed_interval: '30s', + delay: '30s', + time_zone: 'UTC', + }, + }, + terms: { Elastic: { agg: 'terms' } }, + histogram: { amount: { agg: 'histogram', interval: 5 } }, + avg: { amount: { agg: 'avg' } }, + max: { amount: { agg: 'max' } }, + min: { amount: { agg: 'min' } }, + sum: { amount: { agg: 'sum' } }, + value_count: { amount: { agg: 'value_count' } }, + }, + }, + getNonScriptedFields: () => fields, + getFormatterForFieldNoDefault: () => ({ params: () => ({}) }), +} as unknown) as IndexPattern; + const mockFieldToIndexPatternField = ( spec: Record ) => { @@ -51,6 +79,7 @@ const fields = [ }, { name: 'timestamp', displayName: 'timestamp', esTypes: ['date'] }, { name: 'conflictingField', displayName: 'conflictingField', esTypes: ['keyword', 'long'] }, + { name: 'amount', displayName: 'amount', esTypes: ['long'] }, ].map(mockFieldToIndexPatternField); describe('IndexedFieldsTable', () => { @@ -115,4 +144,26 @@ describe('IndexedFieldsTable', () => { expect(component).toMatchSnapshot(); }); + + describe('IndexedFieldsTable with rollup index pattern', () => { + test('should render normally', async () => { + const component = shallow( + { + return () => false; + }} + indexedFieldTypeFilter="" + fieldFilter="" + /> + ); + + await new Promise((resolve) => process.nextTick(resolve)); + component.update(); + + expect(component).toMatchSnapshot(); + }); + }); }); diff --git a/src/plugins/index_pattern_management/public/components/edit_index_pattern/indexed_fields_table/indexed_fields_table.tsx b/src/plugins/index_pattern_management/public/components/edit_index_pattern/indexed_fields_table/indexed_fields_table.tsx index ee1147997079f4..4e9aeb1874c897 100644 --- a/src/plugins/index_pattern_management/public/components/edit_index_pattern/indexed_fields_table/indexed_fields_table.tsx +++ b/src/plugins/index_pattern_management/public/components/edit_index_pattern/indexed_fields_table/indexed_fields_table.tsx @@ -8,7 +8,7 @@ import React, { Component } from 'react'; import { createSelector } from 'reselect'; -import { IndexPatternField, IndexPattern, IFieldType } from '../../../../../../plugins/data/public'; +import { IndexPatternField, IndexPattern } from '../../../../../../plugins/data/public'; import { Table } from './components/table'; import { IndexedFieldItem } from './types'; @@ -20,7 +20,7 @@ interface IndexedFieldsTableProps { helpers: { editField: (fieldName: string) => void; deleteField: (fieldName: string) => void; - getFieldInfo: (indexPattern: IndexPattern, field: IFieldType) => string[]; + getFieldInfo: (indexPattern: IndexPattern, field: IndexPatternField) => string[]; }; fieldWildcardMatcher: (filters: any[]) => (val: any) => boolean; } diff --git a/src/plugins/index_pattern_management/public/service/list/config.ts b/src/plugins/index_pattern_management/public/service/list/config.ts index e13f8c1c06241e..4be27fc47d0db8 100644 --- a/src/plugins/index_pattern_management/public/service/list/config.ts +++ b/src/plugins/index_pattern_management/public/service/list/config.ts @@ -7,8 +7,7 @@ */ import { i18n } from '@kbn/i18n'; -import { IIndexPattern, IFieldType } from 'src/plugins/data/public'; -import { SimpleSavedObject } from 'src/core/public'; +import { IndexPattern, IndexPatternField, IndexPatternType } from '../../../../data/public'; export interface IndexPatternTag { key: string; @@ -23,12 +22,9 @@ const defaultIndexPatternListName = i18n.translate( ); export class IndexPatternListConfig { - public readonly key = 'default'; + public readonly key: IndexPatternType = IndexPatternType.DEFAULT; - public getIndexPatternTags( - indexPattern: IIndexPattern | SimpleSavedObject, - isDefault: boolean - ): IndexPatternTag[] { + public getIndexPatternTags(indexPattern: IndexPattern, isDefault: boolean): IndexPatternTag[] { return isDefault ? [ { @@ -39,11 +35,11 @@ export class IndexPatternListConfig { : []; } - public getFieldInfo(indexPattern: IIndexPattern, field: IFieldType): string[] { + public getFieldInfo(indexPattern: IndexPattern, field: IndexPatternField): string[] { return []; } - public areScriptedFieldsEnabled(indexPattern: IIndexPattern): boolean { + public areScriptedFieldsEnabled(indexPattern: IndexPattern): boolean { return true; } } diff --git a/src/plugins/index_pattern_management/public/service/list/manager.ts b/src/plugins/index_pattern_management/public/service/list/manager.ts index bdb2d47057f1f2..d9cefbd8001a5d 100644 --- a/src/plugins/index_pattern_management/public/service/list/manager.ts +++ b/src/plugins/index_pattern_management/public/service/list/manager.ts @@ -6,13 +6,11 @@ * Side Public License, v 1. */ -import { IIndexPattern, IFieldType } from 'src/plugins/data/public'; -import { SimpleSavedObject } from 'src/core/public'; +import { IndexPattern, IndexPatternField } from 'src/plugins/data/public'; import { once } from 'lodash'; import { CoreStart } from '../../../../../core/public'; import { IndexPatternListConfig, IndexPatternTag } from './config'; import { CONFIG_ROLLUPS } from '../../constants'; -// @ts-ignore import { RollupIndexPatternListConfig } from './rollup_list_config'; interface IndexPatternListManagerStart { @@ -32,10 +30,7 @@ export class IndexPatternListManager { return configs; }); return { - getIndexPatternTags: ( - indexPattern: IIndexPattern | SimpleSavedObject, - isDefault: boolean - ) => + getIndexPatternTags: (indexPattern: IndexPattern, isDefault: boolean) => getConfigs().reduce( (tags: IndexPatternTag[], config) => config.getIndexPatternTags @@ -44,14 +39,14 @@ export class IndexPatternListManager { [] ), - getFieldInfo: (indexPattern: IIndexPattern, field: IFieldType): string[] => + getFieldInfo: (indexPattern: IndexPattern, field: IndexPatternField): string[] => getConfigs().reduce( (info: string[], config) => config.getFieldInfo ? info.concat(config.getFieldInfo(indexPattern, field)) : info, [] ), - areScriptedFieldsEnabled: (indexPattern: IIndexPattern): boolean => + areScriptedFieldsEnabled: (indexPattern: IndexPattern): boolean => getConfigs().every((config) => config.areScriptedFieldsEnabled ? config.areScriptedFieldsEnabled(indexPattern) : true ), diff --git a/src/plugins/index_pattern_management/public/service/list/rollup_list_config.js b/src/plugins/index_pattern_management/public/service/list/rollup_list_config.ts similarity index 69% rename from src/plugins/index_pattern_management/public/service/list/rollup_list_config.js rename to src/plugins/index_pattern_management/public/service/list/rollup_list_config.ts index 9a80d5fd0d622b..bb9da0d461701d 100644 --- a/src/plugins/index_pattern_management/public/service/list/rollup_list_config.js +++ b/src/plugins/index_pattern_management/public/service/list/rollup_list_config.ts @@ -6,18 +6,17 @@ * Side Public License, v 1. */ +import { IndexPattern, IndexPatternField, IndexPatternType } from '../../../../data/public'; import { IndexPatternListConfig } from '.'; -function isRollup(indexPattern) { - return ( - indexPattern.type === 'rollup' || (indexPattern.get && indexPattern.get('type') === 'rollup') - ); +function isRollup(indexPattern: IndexPattern) { + return indexPattern.type === IndexPatternType.ROLLUP; } export class RollupIndexPatternListConfig extends IndexPatternListConfig { - key = 'rollup'; + key = IndexPatternType.ROLLUP; - getIndexPatternTags = (indexPattern) => { + getIndexPatternTags = (indexPattern: IndexPattern) => { return isRollup(indexPattern) ? [ { @@ -28,13 +27,13 @@ export class RollupIndexPatternListConfig extends IndexPatternListConfig { : []; }; - getFieldInfo = (indexPattern, field) => { + getFieldInfo = (indexPattern: IndexPattern, field: IndexPatternField) => { if (!isRollup(indexPattern)) { return []; } const allAggs = indexPattern.typeMeta && indexPattern.typeMeta.aggs; - const fieldAggs = allAggs && Object.keys(allAggs).filter((agg) => allAggs[agg][field]); + const fieldAggs = allAggs && Object.keys(allAggs).filter((agg) => allAggs[agg][field.name]); if (!fieldAggs || !fieldAggs.length) { return []; @@ -42,13 +41,12 @@ export class RollupIndexPatternListConfig extends IndexPatternListConfig { return ['Rollup aggregations:'].concat( fieldAggs.map((aggName) => { - const agg = allAggs[aggName][field]; + const agg = allAggs![aggName][field.name]; switch (aggName) { case 'date_histogram': - return `${aggName} (interval: ${agg.interval}, ${ + return `${aggName} (interval: ${agg.fixed_interval}, ${ agg.delay ? `delay: ${agg.delay},` : '' } ${agg.time_zone})`; - break; case 'histogram': return `${aggName} (interval: ${agg.interval})`; default: @@ -58,7 +56,7 @@ export class RollupIndexPatternListConfig extends IndexPatternListConfig { ); }; - areScriptedFieldsEnabled = (indexPattern) => { + areScriptedFieldsEnabled = (indexPattern: IndexPattern) => { return !isRollup(indexPattern); }; }