Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,10 @@ describe('IndexPatternDimensionPanel', () => {
{...defaultProps}
dragDropContext={{
...dragDropContext,
dragging: { indexPatternId: 'foo', field: { type: 'number', name: 'bar' } },
dragging: {
indexPatternId: 'foo',
field: { type: 'number', name: 'bar', aggregatable: true },
},
}}
state={dragDropState()}
filterOperations={() => false}
Expand All @@ -882,7 +885,10 @@ describe('IndexPatternDimensionPanel', () => {
{...defaultProps}
dragDropContext={{
...dragDropContext,
dragging: { field: { type: 'number', name: 'bar' }, indexPatternId: 'foo' },
dragging: {
field: { type: 'number', name: 'bar', aggregatable: true },
indexPatternId: 'foo',
},
}}
state={dragDropState()}
filterOperations={op => op.dataType === 'number'}
Expand All @@ -904,7 +910,10 @@ describe('IndexPatternDimensionPanel', () => {
{...defaultProps}
dragDropContext={{
...dragDropContext,
dragging: { field: { type: 'number', name: 'bar' }, indexPatternId: 'foo2' },
dragging: {
field: { type: 'number', name: 'bar', aggregatable: true },
indexPatternId: 'foo2',
},
}}
state={dragDropState()}
filterOperations={op => op.dataType === 'number'}
Expand All @@ -921,7 +930,10 @@ describe('IndexPatternDimensionPanel', () => {
});

it('appends the dropped column when a field is dropped', () => {
const dragging = { field: { type: 'number', name: 'bar' }, indexPatternId: 'foo' };
const dragging = {
field: { type: 'number', name: 'bar', aggregatable: true },
indexPatternId: 'foo',
};
const testState = dragDropState();
wrapper = shallow(
<IndexPatternDimensionPanel
Expand Down Expand Up @@ -966,7 +978,10 @@ describe('IndexPatternDimensionPanel', () => {
});

it('updates a column when a field is dropped', () => {
const dragging = { field: { type: 'number', name: 'bar' }, indexPatternId: 'foo' };
const dragging = {
field: { type: 'number', name: 'bar', aggregatable: true },
indexPatternId: 'foo',
};
const testState = dragDropState();
wrapper = shallow(
<IndexPatternDimensionPanel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ export const dateHistogramOperation: OperationDefinition<DateHistogramIndexPatte
defaultMessage: 'Date Histogram',
}),
getPossibleOperationsForDocument: () => [],
getPossibleOperationsForField: ({ aggregationRestrictions, type }) => {
if (type === 'date' && (!aggregationRestrictions || aggregationRestrictions.date_histogram)) {
getPossibleOperationsForField: ({ aggregationRestrictions, aggregatable, type }) => {
if (
type === 'date' &&
aggregatable &&
(!aggregationRestrictions || aggregationRestrictions.date_histogram)
) {
return [
{
dataType: 'date',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ function buildMetricOperation<T extends FieldBasedIndexPatternColumn>(
type,
displayName,
getPossibleOperationsForDocument: () => [],
getPossibleOperationsForField: ({ aggregationRestrictions, type: fieldType }) => {
if (fieldType === 'number' && (!aggregationRestrictions || aggregationRestrictions[type])) {
getPossibleOperationsForField: ({ aggregationRestrictions, aggregatable, type: fieldType }) => {
if (
fieldType === 'number' &&
aggregatable &&
(!aggregationRestrictions || aggregationRestrictions[type])
) {
return [
{
dataType: 'number',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,80 @@ describe('terms', () => {
});
});

describe('getPossibleOperationsForField', () => {
it('should return operation with the right type', () => {
expect(
termsOperation.getPossibleOperationsForField({
aggregatable: true,
searchable: true,
name: 'test',
type: 'string',
aggregationRestrictions: {
terms: {
agg: 'terms',
},
},
})
).toEqual([
{
dataType: 'string',
isBucketed: true,
},
]);

expect(
termsOperation.getPossibleOperationsForField({
aggregatable: true,
searchable: true,
name: 'test',
type: 'boolean',
})
).toEqual([
{
dataType: 'boolean',
isBucketed: true,
},
]);
});

it('should not return an operation if restrictions prevent terms', () => {
expect(
termsOperation.getPossibleOperationsForField({
aggregatable: false,
searchable: true,
name: 'test',
type: 'string',
})
).toEqual([]);

expect(
termsOperation.getPossibleOperationsForField({
aggregatable: true,
aggregationRestrictions: {},
searchable: true,
name: 'test',
type: 'string',
})
).toEqual([]);
});
});

describe('buildColumn', () => {
it('should use type from the passed field', () => {
const termsColumn = termsOperation.buildColumn({
layerId: 'first',
suggestedPriority: undefined,
field: {
aggregatable: true,
searchable: true,
type: 'boolean',
name: 'test',
},
columns: {},
});
expect(termsColumn.dataType).toEqual('boolean');
});

it('should use existing metric column as order column', () => {
const termsColumn = termsOperation.buildColumn({
layerId: 'first',
Expand All @@ -85,6 +158,12 @@ describe('terms', () => {
operationType: 'count',
},
},
field: {
aggregatable: true,
searchable: true,
type: 'boolean',
name: 'test',
},
});
expect(termsColumn.params).toEqual(
expect.objectContaining({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { EuiForm, EuiFormRow, EuiRange, EuiSelect } from '@elastic/eui';
import { TermsIndexPatternColumn, IndexPatternColumn } from '../indexpattern';
import { OperationDefinition } from '../operations';
import { updateColumnParam } from '../state_helpers';
import { DataType } from '../../types';

type PropType<C> = C extends React.ComponentType<infer P> ? P : unknown;

Expand Down Expand Up @@ -42,11 +43,15 @@ export const termsOperation: OperationDefinition<TermsIndexPatternColumn> = {
defaultMessage: 'Top Values',
}),
getPossibleOperationsForDocument: () => [],
getPossibleOperationsForField: ({ aggregationRestrictions, type }) => {
if (type === 'string' && (!aggregationRestrictions || aggregationRestrictions.terms)) {
getPossibleOperationsForField: ({ aggregationRestrictions, aggregatable, type }) => {
if (
(type === 'string' || type === 'boolean') &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we going to treat IP addresses as strings as well? I think we want Terms support for those

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I will add this in a separate PR.

aggregatable &&
(!aggregationRestrictions || aggregationRestrictions.terms)
) {
return [
{
dataType: 'string',
dataType: type,
isBucketed: true,
},
];
Expand All @@ -60,7 +65,7 @@ export const termsOperation: OperationDefinition<TermsIndexPatternColumn> = {

return {
label: ofName(field ? field.name : ''),
dataType: 'string',
dataType: field!.type as DataType,
operationType: 'terms',
suggestedPriority,
sourceField: field ? field.name : '',
Expand Down