Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Lens] Use index pattern service instead saved object client #74654

Merged
merged 17 commits into from
Aug 21, 2020
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -87,36 +87,42 @@ const initialState: IndexPatternPrivateState = {
fields: [
{
name: 'timestamp',
displayName: 'timestampLabel',
type: 'date',
aggregatable: true,
searchable: true,
},
{
name: 'bytes',
displayName: 'bytes',
type: 'number',
aggregatable: true,
searchable: true,
},
{
name: 'memory',
displayName: 'amemory',
type: 'number',
aggregatable: true,
searchable: true,
},
{
name: 'unsupported',
displayName: 'unsupported',
type: 'geo',
aggregatable: true,
searchable: true,
},
{
name: 'source',
displayName: 'source',
type: 'string',
aggregatable: true,
searchable: true,
},
{
name: 'client',
displayName: 'client',
type: 'ip',
aggregatable: true,
searchable: true,
Expand All @@ -131,6 +137,7 @@ const initialState: IndexPatternPrivateState = {
fields: [
{
name: 'timestamp',
displayName: 'timestampLabel',
type: 'date',
aggregatable: true,
searchable: true,
Expand All @@ -145,6 +152,7 @@ const initialState: IndexPatternPrivateState = {
},
{
name: 'bytes',
displayName: 'bytes',
type: 'number',
aggregatable: true,
searchable: true,
Expand All @@ -166,6 +174,7 @@ const initialState: IndexPatternPrivateState = {
},
{
name: 'source',
displayName: 'source',
type: 'string',
aggregatable: true,
searchable: true,
Expand All @@ -185,18 +194,21 @@ const initialState: IndexPatternPrivateState = {
fields: [
{
name: 'timestamp',
displayName: 'timestampLabel',
type: 'date',
aggregatable: true,
searchable: true,
},
{
name: 'bytes',
displayName: 'bytes',
type: 'number',
aggregatable: true,
searchable: true,
},
{
name: 'source',
displayName: 'source',
type: 'string',
aggregatable: true,
searchable: true,
Expand Down Expand Up @@ -581,18 +593,19 @@ describe('IndexPattern Data Panel', () => {
.find('[data-test-subj="lnsIndexPatternAvailableFields"]')
.find(FieldItem)
.map((fieldItem) => fieldItem.prop('field').name)
).toEqual(['bytes', 'memory']);
).toEqual(['memory', 'bytes']);
wrapper
.find('[data-test-subj="lnsIndexPatternEmptyFields"]')
.find('button')
.first()
.simulate('click');
const emptyAccordion = wrapper.find('[data-test-subj="lnsIndexPatternEmptyFields"]');
expect(
wrapper
.find('[data-test-subj="lnsIndexPatternEmptyFields"]')
.find(FieldItem)
.map((fieldItem) => fieldItem.prop('field').name)
emptyAccordion.find(FieldItem).map((fieldItem) => fieldItem.prop('field').name)
).toEqual(['client', 'source', 'timestamp']);
expect(
emptyAccordion.find(FieldItem).map((fieldItem) => fieldItem.prop('field').displayName)
).toEqual(['client', 'source', 'timestampLabel']);
});

it('should display NoFieldsCallout when all fields are empty', async () => {
Expand All @@ -615,8 +628,8 @@ describe('IndexPattern Data Panel', () => {
wrapper
.find('[data-test-subj="lnsIndexPatternEmptyFields"]')
.find(FieldItem)
.map((fieldItem) => fieldItem.prop('field').name)
).toEqual(['bytes', 'client', 'memory', 'source', 'timestamp']);
.map((fieldItem) => fieldItem.prop('field').displayName)
).toEqual(['amemory', 'bytes', 'client', 'source', 'timestampLabel']);
});

it('should display spinner for available fields accordion if existing fields are not loaded yet', async () => {
Expand Down Expand Up @@ -656,10 +669,9 @@ describe('IndexPattern Data Panel', () => {

wrapper.find('[data-test-subj="typeFilter-number"]').first().simulate('click');

expect(wrapper.find(FieldItem).map((fieldItem) => fieldItem.prop('field').name)).toEqual([
'bytes',
'memory',
]);
expect(
wrapper.find(FieldItem).map((fieldItem) => fieldItem.prop('field').displayName)
).toEqual(['amemory', 'bytes']);
});

it('should display no fields in groups when filtered by type Record', () => {
Expand All @@ -686,14 +698,9 @@ describe('IndexPattern Data Panel', () => {
.find('button')
.first()
.simulate('click');
expect(wrapper.find(FieldItem).map((fieldItem) => fieldItem.prop('field').name)).toEqual([
'Records',
'bytes',
'memory',
'client',
'source',
'timestamp',
]);
expect(
wrapper.find(FieldItem).map((fieldItem) => fieldItem.prop('field').displayName)
).toEqual(['Records', 'amemory', 'bytes', 'client', 'source', 'timestampLabel']);
});

it('should filter down by type and by name', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const FixedEuiContextMenuPanel = (EuiContextMenuPanel as unknown) as React.Funct
>;

function sortFields(fieldA: IndexPatternField, fieldB: IndexPatternField) {
return fieldA.name.localeCompare(fieldB.name, undefined, { sensitivity: 'base' });
return fieldA.displayName.localeCompare(fieldB.displayName, undefined, { sensitivity: 'base' });
}

const supportedFieldTypes = new Set(['string', 'number', 'boolean', 'date', 'ip', 'document']);
Expand Down Expand Up @@ -323,7 +323,8 @@ export const InnerIndexPatternDataPanel = function InnerIndexPatternDataPanel({
fieldGroup.filter((field) => {
if (
localState.nameFilter.length &&
!field.name.toLowerCase().includes(localState.nameFilter.toLowerCase())
!field.name.toLowerCase().includes(localState.nameFilter.toLowerCase()) &&
!field.displayName.toLowerCase().includes(localState.nameFilter.toLowerCase())
) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ import { mount } from 'enzyme';
import React from 'react';
import { BucketNestingEditor } from './bucket_nesting_editor';
import { IndexPatternColumn } from '../indexpattern';
import { IndexPatternField } from '../types';

const fieldMap = {
a: { displayName: 'a' } as IndexPatternField,
b: { displayName: 'b' } as IndexPatternField,
c: { displayName: 'c' } as IndexPatternField,
};

describe('BucketNestingEditor', () => {
function mockCol(col: Partial<IndexPatternColumn> = {}): IndexPatternColumn {
Expand All @@ -32,6 +39,7 @@ describe('BucketNestingEditor', () => {
it('should display the top level grouping when at the root', () => {
const component = mount(
<BucketNestingEditor
fieldMap={fieldMap}
columnId="a"
layer={{
columnOrder: ['a', 'b', 'c'],
Expand All @@ -56,6 +64,7 @@ describe('BucketNestingEditor', () => {
const component = mount(
<BucketNestingEditor
columnId="a"
fieldMap={fieldMap}
layer={{
columnOrder: ['b', 'a', 'c'],
columns: {
Expand All @@ -81,6 +90,7 @@ describe('BucketNestingEditor', () => {
const component = mount(
<BucketNestingEditor
columnId="a"
fieldMap={fieldMap}
layer={{
columnOrder: ['b', 'a', 'c'],
columns: {
Expand Down Expand Up @@ -124,6 +134,7 @@ describe('BucketNestingEditor', () => {
const component = mount(
<BucketNestingEditor
columnId="a"
fieldMap={fieldMap}
layer={{
columnOrder: ['a', 'b', 'c'],
columns: {
Expand All @@ -144,6 +155,7 @@ describe('BucketNestingEditor', () => {
const component = mount(
<BucketNestingEditor
columnId="a"
fieldMap={fieldMap}
layer={{
columnOrder: ['a', 'b', 'c'],
columns: {
Expand All @@ -164,6 +176,7 @@ describe('BucketNestingEditor', () => {
const component = mount(
<BucketNestingEditor
columnId="a"
fieldMap={fieldMap}
layer={{
columnOrder: ['c', 'a', 'b'],
columns: {
Expand All @@ -187,6 +200,7 @@ describe('BucketNestingEditor', () => {
const component = mount(
<BucketNestingEditor
columnId="a"
fieldMap={fieldMap}
layer={{
columnOrder: ['c', 'a', 'b'],
columns: {
Expand All @@ -213,6 +227,7 @@ describe('BucketNestingEditor', () => {
const component = mount(
<BucketNestingEditor
columnId="a"
fieldMap={fieldMap}
layer={{
columnOrder: ['c', 'a', 'b'],
columns: {
Expand All @@ -238,6 +253,7 @@ describe('BucketNestingEditor', () => {
const setColumns = jest.fn();
const component = mount(
<BucketNestingEditor
fieldMap={fieldMap}
columnId="b"
layer={{
columnOrder: ['c', 'a', 'b'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import React from 'react';
import { i18n } from '@kbn/i18n';
import { EuiFormRow, EuiHorizontalRule, EuiRadio, EuiSelect, htmlIdGenerator } from '@elastic/eui';
import { IndexPatternLayer } from '../types';
import { IndexPatternLayer, IndexPatternField } from '../types';
import { hasField } from '../utils';

const generator = htmlIdGenerator('lens-nesting');
Expand All @@ -25,10 +25,12 @@ export function BucketNestingEditor({
columnId,
layer,
setColumns,
fieldMap,
}: {
columnId: string;
layer: IndexPatternLayer;
setColumns: (columns: string[]) => void;
fieldMap: Record<string, IndexPatternField>;
}) {
const column = layer.columns[columnId];
const columns = Object.entries(layer.columns);
Expand All @@ -37,14 +39,14 @@ export function BucketNestingEditor({
.map(([value, c]) => ({
value,
text: c.label,
fieldName: hasField(c) ? c.sourceField : '',
fieldName: hasField(c) ? fieldMap[c.sourceField].displayName : '',
}));

if (!column || !column.isBucketed || !aggColumns.length) {
return null;
}

const fieldName = hasField(column) ? column.sourceField : '';
const fieldName = hasField(column) ? fieldMap[column.sourceField].displayName : '';

const prevColumn = layer.columnOrder[layer.columnOrder.indexOf(columnId) - 1];

Expand Down
Loading