diff --git a/src/plugins/discover/public/application/components/sidebar/discover_field.test.tsx b/src/plugins/discover/public/application/components/sidebar/discover_field.test.tsx
index 6211d302e7d20..8ab296bf1af4f 100644
--- a/src/plugins/discover/public/application/components/sidebar/discover_field.test.tsx
+++ b/src/plugins/discover/public/application/components/sidebar/discover_field.test.tsx
@@ -51,7 +51,17 @@ jest.mock('../../../kibana_services', () => ({
}),
}));
-function getComponent(selected = false, showDetails = false, useShortDots = false) {
+function getComponent({
+ selected = false,
+ showDetails = false,
+ useShortDots = false,
+ field,
+}: {
+ selected?: boolean;
+ showDetails?: boolean;
+ useShortDots?: boolean;
+ field?: IndexPatternField;
+}) {
const indexPattern = getStubIndexPattern(
'logstash-*',
(cfg: any) => cfg,
@@ -60,23 +70,25 @@ function getComponent(selected = false, showDetails = false, useShortDots = fals
coreMock.createSetup()
);
- const field = new IndexPatternField(
- {
- name: 'bytes',
- type: 'number',
- esTypes: ['long'],
- count: 10,
- scripted: false,
- searchable: true,
- aggregatable: true,
- readFromDocValues: true,
- },
- 'bytes'
- );
+ const finalField =
+ field ??
+ new IndexPatternField(
+ {
+ name: 'bytes',
+ type: 'number',
+ esTypes: ['long'],
+ count: 10,
+ scripted: false,
+ searchable: true,
+ aggregatable: true,
+ readFromDocValues: true,
+ },
+ 'bytes'
+ );
const props = {
indexPattern,
- field,
+ field: finalField,
getDetails: jest.fn(() => ({ buckets: [], error: '', exists: 1, total: true, columns: [] })),
onAddFilter: jest.fn(),
onAddField: jest.fn(),
@@ -91,18 +103,37 @@ function getComponent(selected = false, showDetails = false, useShortDots = fals
describe('discover sidebar field', function () {
it('should allow selecting fields', function () {
- const { comp, props } = getComponent();
+ const { comp, props } = getComponent({});
findTestSubject(comp, 'fieldToggle-bytes').simulate('click');
expect(props.onAddField).toHaveBeenCalledWith('bytes');
});
it('should allow deselecting fields', function () {
- const { comp, props } = getComponent(true);
+ const { comp, props } = getComponent({ selected: true });
findTestSubject(comp, 'fieldToggle-bytes').simulate('click');
expect(props.onRemoveField).toHaveBeenCalledWith('bytes');
});
it('should trigger getDetails', function () {
- const { comp, props } = getComponent(true);
+ const { comp, props } = getComponent({ selected: true });
findTestSubject(comp, 'field-bytes-showDetails').simulate('click');
expect(props.getDetails).toHaveBeenCalledWith(props.field);
});
+ it('should not allow clicking on _source', function () {
+ const field = new IndexPatternField(
+ {
+ name: '_source',
+ type: '_source',
+ esTypes: ['_source'],
+ searchable: true,
+ aggregatable: true,
+ readFromDocValues: true,
+ },
+ '_source'
+ );
+ const { comp, props } = getComponent({
+ selected: true,
+ field,
+ });
+ findTestSubject(comp, 'field-_source-showDetails').simulate('click');
+ expect(props.getDetails).not.toHaveBeenCalled();
+ });
});
diff --git a/src/plugins/discover/public/application/components/sidebar/discover_field.tsx b/src/plugins/discover/public/application/components/sidebar/discover_field.tsx
index bb330cba68e2e..8ff603884239e 100644
--- a/src/plugins/discover/public/application/components/sidebar/discover_field.tsx
+++ b/src/plugins/discover/public/application/components/sidebar/discover_field.tsx
@@ -172,6 +172,19 @@ export function DiscoverField({
);
}
+ if (field.type === '_source') {
+ return (
+
+ );
+ }
+
return (
{
togglePopover();
}}
- buttonProps={{ 'data-test-subj': `field-${field.name}-showDetails` }}
+ dataTestSubj={`field-${field.name}-showDetails`}
fieldIcon={dscFieldIcon}
fieldAction={actionButton}
fieldName={fieldName}
diff --git a/src/plugins/kibana_react/public/field_button/field_button.tsx b/src/plugins/kibana_react/public/field_button/field_button.tsx
index 26e6453e4c48b..97d1b32746120 100644
--- a/src/plugins/kibana_react/public/field_button/field_button.tsx
+++ b/src/plugins/kibana_react/public/field_button/field_button.tsx
@@ -19,8 +19,7 @@
import './field_button.scss';
import classNames from 'classnames';
-import React, { ReactNode, HTMLAttributes, ButtonHTMLAttributes } from 'react';
-import { CommonProps } from '@elastic/eui';
+import React, { ReactNode, HTMLAttributes } from 'react';
export interface FieldButtonProps extends HTMLAttributes {
/**
@@ -54,13 +53,10 @@ export interface FieldButtonProps extends HTMLAttributes {
size?: ButtonSize;
className?: string;
/**
- * The component always renders a `