Skip to content

Commit

Permalink
Replace IndexPatternField with FieldSpec, revert terms.test and updat…
Browse files Browse the repository at this point in the history
…e other tests
  • Loading branch information
DianaDerevyankina committed Aug 26, 2021
1 parent 4dd300f commit a38a8f8
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 40 deletions.
20 changes: 10 additions & 10 deletions x-pack/plugins/lens/public/app_plugin/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import {
esFilters,
FilterManager,
IndexPattern,
IndexPatternField,
Query,
} from '../../../../../src/plugins/data/public';
import type { FieldSpec } from '../../../../../src/plugins/data/common';
import { TopNavMenuData } from '../../../../../src/plugins/navigation/public';
import { LensByValueInput } from '../embeddable/embeddable';
import { SavedObjectReference } from '../../../../../src/core/types';
Expand Down Expand Up @@ -155,7 +155,7 @@ describe('Lens App', () => {
it('updates global filters with store state', async () => {
const services = makeDefaultServices(sessionIdSubject);
const indexPattern = ({ id: 'index1' } as unknown) as IndexPattern;
const pinnedField = ({ name: 'pinnedField' } as unknown) as IndexPatternField;
const pinnedField = ({ name: 'pinnedField' } as unknown) as FieldSpec;
const pinnedFilter = esFilters.buildExistsFilter(pinnedField, indexPattern);
services.data.query.filterManager.getFilters = jest.fn().mockImplementation(() => {
return [];
Expand Down Expand Up @@ -653,8 +653,8 @@ describe('Lens App', () => {

it('saves app filters and does not save pinned filters', async () => {
const indexPattern = ({ id: 'index1' } as unknown) as IndexPattern;
const field = ({ name: 'myfield' } as unknown) as IndexPatternField;
const pinnedField = ({ name: 'pinnedField' } as unknown) as IndexPatternField;
const field = ({ name: 'myfield' } as unknown) as FieldSpec;
const pinnedField = ({ name: 'pinnedField' } as unknown) as FieldSpec;
const unpinned = esFilters.buildExistsFilter(field, indexPattern);
const pinned = esFilters.buildExistsFilter(pinnedField, indexPattern);
await act(async () => {
Expand Down Expand Up @@ -835,7 +835,7 @@ describe('Lens App', () => {
it('updates the filters when the user changes them', async () => {
const { instance, services, lensStore } = await mountWith({});
const indexPattern = ({ id: 'index1' } as unknown) as IndexPattern;
const field = ({ name: 'myfield' } as unknown) as IndexPatternField;
const field = ({ name: 'myfield' } as unknown) as FieldSpec;
expect(lensStore.getState()).toEqual({
lens: expect.objectContaining({
filters: [],
Expand Down Expand Up @@ -890,7 +890,7 @@ describe('Lens App', () => {
}),
});
const indexPattern = ({ id: 'index1' } as unknown) as IndexPattern;
const field = ({ name: 'myfield' } as unknown) as IndexPatternField;
const field = ({ name: 'myfield' } as unknown) as FieldSpec;
act(() =>
services.data.query.filterManager.setFilters([
esFilters.buildExistsFilter(field, indexPattern),
Expand Down Expand Up @@ -1025,8 +1025,8 @@ describe('Lens App', () => {
})
);
const indexPattern = ({ id: 'index1' } as unknown) as IndexPattern;
const field = ({ name: 'myfield' } as unknown) as IndexPatternField;
const pinnedField = ({ name: 'pinnedField' } as unknown) as IndexPatternField;
const field = ({ name: 'myfield' } as unknown) as FieldSpec;
const pinnedField = ({ name: 'pinnedField' } as unknown) as FieldSpec;
const unpinned = esFilters.buildExistsFilter(field, indexPattern);
const pinned = esFilters.buildExistsFilter(pinnedField, indexPattern);
FilterManager.setFiltersStore([pinned], esFilters.FilterStateStore.GLOBAL_STATE);
Expand Down Expand Up @@ -1082,8 +1082,8 @@ describe('Lens App', () => {
})
);
const indexPattern = ({ id: 'index1' } as unknown) as IndexPattern;
const field = ({ name: 'myfield' } as unknown) as IndexPatternField;
const pinnedField = ({ name: 'pinnedField' } as unknown) as IndexPatternField;
const field = ({ name: 'myfield' } as unknown) as FieldSpec;
const pinnedField = ({ name: 'pinnedField' } as unknown) as FieldSpec;
const unpinned = esFilters.buildExistsFilter(field, indexPattern);
const pinned = esFilters.buildExistsFilter(pinnedField, indexPattern);
FilterManager.setFiltersStore([pinned], esFilters.FilterStateStore.GLOBAL_STATE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@ import { ReactWrapper } from 'enzyme';
import { DragDrop, ChildDragDropProvider } from '../../../drag_drop';
import { fromExpression } from '@kbn/interpreter/common';
import { coreMock } from 'src/core/public/mocks';
import {
esFilters,
IndexPattern,
IndexPatternField,
} from '../../../../../../../src/plugins/data/public';
import { esFilters, IndexPattern } from '../../../../../../../src/plugins/data/public';
import type { FieldSpec } from '../../../../../../../src/plugins/data/common';
import { UiActionsStart } from '../../../../../../../src/plugins/ui_actions/public';
import { uiActionsPluginMock } from '../../../../../../../src/plugins/ui_actions/public/mocks';
import { TriggerContract } from '../../../../../../../src/plugins/ui_actions/public/triggers';
Expand Down Expand Up @@ -420,7 +417,7 @@ describe('workspace_panel', () => {
expect(expressionRendererMock).toHaveBeenCalledTimes(1);

const indexPattern = ({ id: 'index1' } as unknown) as IndexPattern;
const field = ({ name: 'myfield' } as unknown) as IndexPatternField;
const field = ({ name: 'myfield' } as unknown) as FieldSpec;

await act(async () => {
instance.setProps({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,14 @@ describe('IndexPattern Data Panel', () => {
...props.indexPatterns['1'],
fields: [
...props.indexPatterns['1'].fields,
{ name: '_id', displayName: '_id', meta: true, type: 'string' },
{
name: '_id',
displayName: '_id',
meta: true,
type: 'string',
searchable: true,
aggregatable: true,
},
],
},
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ describe('percentile', () => {
displayName: 'bytes',
type: 'number',
esTypes: ['long'],
searchable: true,
aggregatable: true,
})
).toEqual({
Expand All @@ -97,6 +98,7 @@ describe('percentile', () => {
displayName: 'response_time',
type: 'histogram',
esTypes: ['histogram'],
searchable: true,
aggregatable: true,
})
).toEqual({
Expand All @@ -113,6 +115,7 @@ describe('percentile', () => {
displayName: 'origin',
type: 'string',
esTypes: ['keyword'],
searchable: true,
aggregatable: true,
})
).toBeUndefined();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,23 @@ const defaultOptions = {
id: '1',
title: 'my_index_pattern',
hasRestrictions: false,
fields: [{ name: sourceField, type: 'number', displayName: sourceField }],
fields: [
{
name: sourceField,
type: 'number',
displayName: sourceField,
searchable: true,
aggregatable: true,
},
],
getFieldByName: getFieldByNameFactory([
{ name: sourceField, type: 'number', displayName: sourceField },
{
name: sourceField,
type: 'number',
displayName: sourceField,
searchable: true,
aggregatable: true,
},
]),
},
operationDefinitionMap: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { createMockedIndexPattern } from '../../../mocks';
import { ValuesInput } from './values_input';
import type { TermsIndexPatternColumn } from '.';
import { termsOperation } from '../index';
import type { IndexPattern, IndexPatternField, IndexPatternLayer } from '../../../types';
import { IndexPattern, IndexPatternLayer } from '../../../types';
import { FrameDatasourceAPI } from '../../../../types';

const uiSettingsMock = {} as IUiSettingsClient;
Expand Down Expand Up @@ -177,7 +177,7 @@ describe('terms', () => {
describe('getPossibleOperationForField', () => {
it('should return operation with the right type', () => {
expect(
termsOperation.getPossibleOperationForField(({
termsOperation.getPossibleOperationForField({
aggregatable: true,
searchable: true,
name: 'test',
Expand All @@ -188,15 +188,15 @@ describe('terms', () => {
agg: 'terms',
},
},
} as unknown) as IndexPatternField)
})
).toEqual({
dataType: 'string',
isBucketed: true,
scale: 'ordinal',
});

expect(
termsOperation.getPossibleOperationForField(({
termsOperation.getPossibleOperationForField({
aggregatable: true,
searchable: true,
name: 'test',
Expand All @@ -207,7 +207,7 @@ describe('terms', () => {
agg: 'terms',
},
},
} as unknown) as IndexPatternField)
})
).toEqual({
dataType: 'number',
isBucketed: true,
Expand All @@ -221,7 +221,7 @@ describe('terms', () => {
name: 'test',
displayName: 'test',
type: 'boolean',
} as IndexPatternField)
})
).toEqual({
dataType: 'boolean',
isBucketed: true,
Expand All @@ -235,7 +235,7 @@ describe('terms', () => {
name: 'test',
displayName: 'test',
type: 'ip',
} as IndexPatternField)
})
).toEqual({
dataType: 'ip',
isBucketed: true,
Expand All @@ -251,7 +251,7 @@ describe('terms', () => {
name: 'test',
displayName: 'test',
type: 'string',
} as IndexPatternField)
})
).toEqual(undefined);

expect(
Expand All @@ -262,7 +262,7 @@ describe('terms', () => {
name: 'test',
displayName: 'test',
type: 'string',
} as IndexPatternField)
})
).toEqual(undefined);
});
});
Expand All @@ -277,7 +277,7 @@ describe('terms', () => {
type: 'boolean',
name: 'test',
displayName: 'test',
} as IndexPatternField,
},
layer: { columns: {}, columnOrder: [], indexPatternId: '' },
});
expect(termsColumn.dataType).toEqual('boolean');
Expand All @@ -292,7 +292,7 @@ describe('terms', () => {
type: 'boolean',
name: 'test',
displayName: 'test',
} as IndexPatternField,
},
layer: { columns: {}, columnOrder: [], indexPatternId: '' },
});
expect(termsColumn.params.otherBucket).toEqual(true);
Expand All @@ -307,7 +307,7 @@ describe('terms', () => {
type: 'boolean',
name: 'test',
displayName: 'test',
} as IndexPatternField,
},
layer: { columns: {}, columnOrder: [], indexPatternId: '' },
});
expect(termsColumn.params.otherBucket).toEqual(false);
Expand Down Expand Up @@ -335,7 +335,7 @@ describe('terms', () => {
type: 'boolean',
name: 'test',
displayName: 'test',
} as IndexPatternField,
},
});
expect(termsColumn.params).toEqual(
expect.objectContaining({
Expand Down Expand Up @@ -368,7 +368,7 @@ describe('terms', () => {
type: 'boolean',
name: 'test',
displayName: 'test',
} as IndexPatternField,
},
});
expect(termsColumn.params).toEqual(
expect.objectContaining({ orderBy: { type: 'alphabetical', fallback: true } })
Expand All @@ -385,7 +385,7 @@ describe('terms', () => {
type: 'boolean',
name: 'test',
displayName: 'test',
} as IndexPatternField,
},
});
expect(termsColumn.params).toEqual(expect.objectContaining({ size: 3 }));
});
Expand All @@ -400,7 +400,7 @@ describe('terms', () => {
type: 'boolean',
name: 'test',
displayName: 'test',
} as IndexPatternField,
},
});
expect(termsColumn.params).toEqual(expect.objectContaining({ size: 5 }));
});
Expand Down
8 changes: 3 additions & 5 deletions x-pack/plugins/lens/public/indexpattern_datasource/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
*/

import type { IndexPatternColumn, IncompleteColumn } from './operations';
import type {
IndexPatternField as BaseIndexPatternField,
IndexPatternAggRestrictions,
} from '../../../../../src/plugins/data/public';
import type { IndexPatternAggRestrictions } from '../../../../../src/plugins/data/public';
import type { FieldSpec } from '../../../../../src/plugins/data/common';
import type { DragDropIdentifier } from '../drag_drop/providers';

export {
Expand Down Expand Up @@ -59,7 +57,7 @@ export interface IndexPattern {
hasRestrictions: boolean;
}

export type IndexPatternField = BaseIndexPatternField & {
export type IndexPatternField = FieldSpec & {
displayName: string;
aggregationRestrictions?: Partial<IndexPatternAggRestrictions>;
meta?: boolean;
Expand Down

0 comments on commit a38a8f8

Please sign in to comment.