Skip to content

Commit

Permalink
Merge branch 'master' into TestUserSampleDataMap
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Apr 14, 2021
2 parents e2b1243 + af9129b commit 8f2c477
Show file tree
Hide file tree
Showing 13 changed files with 149 additions and 27 deletions.
1 change: 1 addition & 0 deletions src/plugins/discover/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ export const CONTEXT_TIE_BREAKER_FIELDS_SETTING = 'context:tieBreakerFields';
export const DOC_TABLE_LEGACY = 'doc_table:legacy';
export const MODIFY_COLUMNS_ON_SWITCH = 'discover:modifyColumnsOnSwitch';
export const SEARCH_FIELDS_FROM_SOURCE = 'discover:searchFieldsFromSource';
export const MAX_DOC_FIELDS_DISPLAYED = 'discover:maxDocFieldsDisplayed';
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { formatRow, formatTopLevelObject } from './row_formatter';
import { stubbedSavedObjectIndexPattern } from '../../../__mocks__/stubbed_saved_object_index_pattern';
import { IndexPattern } from '../../../../../data/common/index_patterns/index_patterns';
import { fieldFormatsMock } from '../../../../../data/common/field_formats/mocks';
import { setServices } from '../../../kibana_services';

describe('Row formatter', () => {
const hit = {
Expand Down Expand Up @@ -58,6 +59,11 @@ describe('Row formatter', () => {
beforeEach(() => {
// @ts-expect-error
indexPattern.formatHit = formatHitMock;
setServices({
uiSettings: {
get: () => 100,
},
});
});

it('formats document properly', () => {
Expand All @@ -66,6 +72,17 @@ describe('Row formatter', () => {
);
});

it('limits number of rendered items', () => {
setServices({
uiSettings: {
get: () => 1,
},
});
expect(formatRow(hit, indexPattern).trim()).toMatchInlineSnapshot(
`"<dl class=\\"source truncate-by-height\\"><dt>also:</dt><dd>with \\\\&quot;quotes\\\\&quot; or &#39;single qoutes&#39;</dd> </dl>"`
);
});

it('formats document with highlighted fields first', () => {
expect(
formatRow({ ...hit, highlight: { number: '42' } }, indexPattern).trim()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
*/

import { template } from 'lodash';
import { IndexPattern } from '../../../kibana_services';
import { MAX_DOC_FIELDS_DISPLAYED } from '../../../../common';
import { getServices, IndexPattern } from '../../../kibana_services';

function noWhiteSpace(html: string) {
const TAGS_WITH_WS = />\s+</g;
Expand Down Expand Up @@ -36,7 +37,8 @@ export const formatRow = (hit: Record<string, any>, indexPattern: IndexPattern)
const pairs = highlights[key] ? highlightPairs : sourcePairs;
pairs.push([displayKey ? displayKey : key, val]);
});
return doTemplate({ defPairs: [...highlightPairs, ...sourcePairs] });
const maxEntries = getServices().uiSettings.get(MAX_DOC_FIELDS_DISPLAYED);
return doTemplate({ defPairs: [...highlightPairs, ...sourcePairs].slice(0, maxEntries) });
};

export const formatTopLevelObject = (
Expand Down Expand Up @@ -67,5 +69,6 @@ export const formatTopLevelObject = (
const pairs = highlights[key] ? highlightPairs : sourcePairs;
pairs.push([displayKey ? displayKey : key, formatted]);
});
return doTemplate({ defPairs: [...highlightPairs, ...sourcePairs] });
const maxEntries = getServices().uiSettings.get(MAX_DOC_FIELDS_DISPLAYED);
return doTemplate({ defPairs: [...highlightPairs, ...sourcePairs].slice(0, maxEntries) });
};
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { defaultPageSize, gridStyle, pageSizeArr, toolbarVisibility } from './co
import { DiscoverServices } from '../../../build_services';
import { getDisplayedColumns } from '../../helpers/columns';
import { KibanaContextProvider } from '../../../../../kibana_react/public';
import { MAX_DOC_FIELDS_DISPLAYED } from '../../../../common';
import { DiscoverGridDocumentToolbarBtn, getDocId } from './discover_grid_document_selection';

interface SortObj {
Expand Down Expand Up @@ -223,9 +224,10 @@ export const DiscoverGrid = ({
indexPattern,
displayedRows,
displayedRows ? displayedRows.map((hit) => indexPattern.flattenHit(hit)) : [],
useNewFieldsApi
useNewFieldsApi,
services.uiSettings.get(MAX_DOC_FIELDS_DISPLAYED)
),
[displayedRows, indexPattern, useNewFieldsApi]
[displayedRows, indexPattern, useNewFieldsApi, services.uiSettings]
);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ describe('Discover grid cell rendering', function () {
indexPatternMock,
rowsSource,
rowsSource.map((row) => indexPatternMock.flattenHit(row)),
false
false,
100
);
const component = shallow(
<DiscoverGridCellValue
Expand All @@ -94,7 +95,8 @@ describe('Discover grid cell rendering', function () {
indexPatternMock,
rowsSource,
rowsSource.map((row) => indexPatternMock.flattenHit(row)),
false
false,
100
);
const component = shallow(
<DiscoverGridCellValue
Expand Down Expand Up @@ -143,7 +145,8 @@ describe('Discover grid cell rendering', function () {
indexPatternMock,
rowsSource,
rowsSource.map((row) => indexPatternMock.flattenHit(row)),
false
false,
100
);
const component = shallow(
<DiscoverGridCellValue
Expand Down Expand Up @@ -184,7 +187,8 @@ describe('Discover grid cell rendering', function () {
indexPatternMock,
rowsFields,
rowsFields.map((row) => indexPatternMock.flattenHit(row)),
true
true,
100
);
const component = shallow(
<DiscoverGridCellValue
Expand Down Expand Up @@ -232,12 +236,55 @@ describe('Discover grid cell rendering', function () {
`);
});

it('limits amount of rendered items', () => {
const DiscoverGridCellValue = getRenderCellValueFn(
indexPatternMock,
rowsFields,
rowsFields.map((row) => indexPatternMock.flattenHit(row)),
true,
// this is the number of rendered items
1
);
const component = shallow(
<DiscoverGridCellValue
rowIndex={0}
columnId="_source"
isDetails={false}
isExpanded={false}
isExpandable={true}
setCellProps={jest.fn()}
/>
);
expect(component).toMatchInlineSnapshot(`
<EuiDescriptionList
className="dscDiscoverGrid__descriptionList"
compressed={true}
type="inline"
>
<EuiDescriptionListTitle>
extension
</EuiDescriptionListTitle>
<EuiDescriptionListDescription
className="dscDiscoverGrid__descriptionListDescription"
dangerouslySetInnerHTML={
Object {
"__html": Array [
".gz",
],
}
}
/>
</EuiDescriptionList>
`);
});

it('renders fields-based column correctly when isDetails is set to true', () => {
const DiscoverGridCellValue = getRenderCellValueFn(
indexPatternMock,
rowsFields,
rowsFields.map((row) => indexPatternMock.flattenHit(row)),
true
true,
100
);
const component = shallow(
<DiscoverGridCellValue
Expand Down Expand Up @@ -283,7 +330,8 @@ describe('Discover grid cell rendering', function () {
indexPatternMock,
rowsFieldsWithTopLevelObject,
rowsFieldsWithTopLevelObject.map((row) => indexPatternMock.flattenHit(row)),
true
true,
100
);
const component = shallow(
<DiscoverGridCellValue
Expand Down Expand Up @@ -322,7 +370,8 @@ describe('Discover grid cell rendering', function () {
indexPatternMock,
rowsFieldsWithTopLevelObject,
rowsFieldsWithTopLevelObject.map((row) => indexPatternMock.flattenHit(row)),
true
true,
100
);
const component = shallow(
<DiscoverGridCellValue
Expand Down Expand Up @@ -360,7 +409,8 @@ describe('Discover grid cell rendering', function () {
indexPatternMock,
rowsFieldsWithTopLevelObject,
rowsFieldsWithTopLevelObject.map((row) => indexPatternMock.flattenHit(row)),
true
true,
100
);
const component = shallow(
<DiscoverGridCellValue
Expand Down Expand Up @@ -389,7 +439,8 @@ describe('Discover grid cell rendering', function () {
indexPatternMock,
rowsFieldsWithTopLevelObject,
rowsFieldsWithTopLevelObject.map((row) => indexPatternMock.flattenHit(row)),
true
true,
100
);
const component = shallow(
<DiscoverGridCellValue
Expand Down Expand Up @@ -417,7 +468,8 @@ describe('Discover grid cell rendering', function () {
indexPatternMock,
rowsSource,
rowsSource.map((row) => indexPatternMock.flattenHit(row)),
false
false,
100
);
const component = shallow(
<DiscoverGridCellValue
Expand All @@ -437,7 +489,8 @@ describe('Discover grid cell rendering', function () {
indexPatternMock,
rowsSource,
rowsSource.map((row) => indexPatternMock.flattenHit(row)),
false
false,
100
);
const component = shallow(
<DiscoverGridCellValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export const getRenderCellValueFn = (
indexPattern: IndexPattern,
rows: ElasticSearchHit[] | undefined,
rowsFlattened: Array<Record<string, unknown>>,
useNewFieldsApi: boolean
useNewFieldsApi: boolean,
maxDocFieldsDisplayed: number
) => ({ rowIndex, columnId, isDetails, setCellProps }: EuiDataGridCellValueElementProps) => {
const row = rows ? rows[rowIndex] : undefined;
const rowFlattened = rowsFlattened
Expand Down Expand Up @@ -98,7 +99,7 @@ export const getRenderCellValueFn = (

return (
<EuiDescriptionList type="inline" compressed className="dscDiscoverGrid__descriptionList">
{[...highlightPairs, ...sourcePairs].map(([key, value]) => (
{[...highlightPairs, ...sourcePairs].slice(0, maxDocFieldsDisplayed).map(([key, value]) => (
<Fragment key={key}>
<EuiDescriptionListTitle>{key}</EuiDescriptionListTitle>
<EuiDescriptionListDescription
Expand Down Expand Up @@ -141,7 +142,7 @@ export const getRenderCellValueFn = (

return (
<EuiDescriptionList type="inline" compressed className="dscDiscoverGrid__descriptionList">
{[...highlightPairs, ...sourcePairs].map(([key, value]) => (
{[...highlightPairs, ...sourcePairs].slice(0, maxDocFieldsDisplayed).map(([key, value]) => (
<Fragment key={key}>
<EuiDescriptionListTitle>{key}</EuiDescriptionListTitle>
<EuiDescriptionListDescription
Expand Down
12 changes: 12 additions & 0 deletions src/plugins/discover/server/ui_settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
DOC_TABLE_LEGACY,
MODIFY_COLUMNS_ON_SWITCH,
SEARCH_FIELDS_FROM_SOURCE,
MAX_DOC_FIELDS_DISPLAYED,
} from '../common';

export const uiSettings: Record<string, UiSettingsParams> = {
Expand All @@ -38,6 +39,17 @@ export const uiSettings: Record<string, UiSettingsParams> = {
category: ['discover'],
schema: schema.arrayOf(schema.string()),
},
[MAX_DOC_FIELDS_DISPLAYED]: {
name: i18n.translate('discover.advancedSettings.maxDocFieldsDisplayedTitle', {
defaultMessage: 'Maximum document fields displayed',
}),
value: 200,
description: i18n.translate('discover.advancedSettings.maxDocFieldsDisplayedText', {
defaultMessage: 'Maximum number of fields rendered in the document column',
}),
category: ['discover'],
schema: schema.number(),
},
[SAMPLE_SIZE_SETTING]: {
name: i18n.translate('discover.advancedSettings.sampleSizeTitle', {
defaultMessage: 'Number of rows',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ export const stackManagementSchema: MakeSchemaFrom<UsageStats> = {
type: 'long',
_meta: { description: 'Non-default value of setting.' },
},
'discover:maxDocFieldsDisplayed': {
type: 'long',
_meta: { description: 'Non-default value of setting.' },
},
defaultColumns: {
type: 'array',
items: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface UsageStats {
'doc_table:legacy': boolean;
'discover:modifyColumnsOnSwitch': boolean;
'discover:searchFieldsFromSource': boolean;
'discover:maxDocFieldsDisplayed': number;
'securitySolution:rulesTableRefresh': string;
'apm:enableSignificantTerms': boolean;
'apm:enableServiceOverview': boolean;
Expand Down
18 changes: 12 additions & 6 deletions src/plugins/telemetry/schema/oss_plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7797,6 +7797,12 @@
"description": "Non-default value of setting."
}
},
"discover:maxDocFieldsDisplayed": {
"type": "long",
"_meta": {
"description": "Non-default value of setting."
}
},
"defaultColumns": {
"type": "array",
"items": {
Expand Down Expand Up @@ -8136,6 +8142,12 @@
"description": "Non-default value of setting."
}
},
"observability:enableInspectEsQueries": {
"type": "boolean",
"_meta": {
"description": "Non-default value of setting."
}
},
"banners:placement": {
"type": "keyword",
"_meta": {
Expand All @@ -8160,12 +8172,6 @@
"description": "Non-default value of setting."
}
},
"observability:enableInspectEsQueries": {
"type": "boolean",
"_meta": {
"description": "Non-default value of setting."
}
},
"labs:presentation:unifiedToolbar": {
"type": "boolean",
"_meta": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

.source-row--error,
.source-row--error:hover {
color: $euiColorDanger;
background: rgba($euiColorDanger, .1);

.euiLink {
color: $euiColorDanger;
}
}
Loading

0 comments on commit 8f2c477

Please sign in to comment.