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 b9957534d8c69..163152b52e80b 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 e587ada6695cb..6d37e8f13d6b3 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,34 @@ const indexPattern = ({
getFormatterForFieldNoDefault: () => ({ params: () => ({}) }),
} as unknown) as IndexPattern;
+const rollupIndexPattern = ({
+ type: IndexPatternType.ROLLUP,
+ typeMeta: {
+ params: {
+ '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 +81,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 +146,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 ee1147997079f..4e9aeb1874c89 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 e13f8c1c06241..4be27fc47d0db 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 bdb2d47057f1f..d9cefbd8001a5 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 9a80d5fd0d622..bb9da0d461701 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);
};
}