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

[Discover][DocViewer] Limit the height of long field values by default #183736

Merged
merged 28 commits into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
16613fd
[Discover][DocViewer] Reintroduce limiting of long values by default
jughosta May 17, 2024
f845d26
[Discover][DocViewer] Clean up
jughosta May 17, 2024
25a891f
[Discover][DocViewer] Improve the logic
jughosta May 17, 2024
bb13aaa
[Discover][DocViewer] Update test
jughosta May 17, 2024
bec50e8
[Discover][DocViewer] Rename
jughosta May 17, 2024
935974e
[Discover][DocViewer] Keep in memory expanded values
jughosta May 17, 2024
bd8cbd0
Merge branch 'main' into collapse-long-field-values
jughosta May 21, 2024
9386cfd
Merge branch 'main' into collapse-long-field-values
jughosta May 23, 2024
ace9b68
Merge remote-tracking branch 'upstream/main' into collapse-long-field…
jughosta Jul 3, 2024
0c74b1e
[Discover] Switch to an icon button
jughosta Jul 3, 2024
dcac57a
[Discover] Update icons and the overflow shadow
jughosta Jul 4, 2024
12f4f4e
Merge branch 'main' into collapse-long-field-values
jughosta Aug 2, 2024
433de38
[Discover] Update icons
jughosta Aug 2, 2024
094a45a
[Discover] Change the logic
jughosta Aug 2, 2024
13303bb
[Discover] Update comment
jughosta Aug 2, 2024
00aef88
[Discover] Improve tests
jughosta Aug 2, 2024
2ce432e
Merge branch 'main' into collapse-long-field-values
jughosta Aug 2, 2024
2a9539d
[Discover] Fix types
jughosta Aug 2, 2024
b1b40cf
Merge remote-tracking branch 'origin/collapse-long-field-values' into…
jughosta Aug 2, 2024
5586997
Merge branch 'main' into collapse-long-field-values
jughosta Aug 5, 2024
a1e1187
Merge branch 'main' into collapse-long-field-values
jughosta Aug 7, 2024
0b69204
Merge branch 'main' into collapse-long-field-values
jughosta Aug 8, 2024
2d0a4e5
Merge branch 'main' into collapse-long-field-values
jughosta Aug 9, 2024
4eb2b2b
Update src/plugins/unified_doc_viewer/public/components/doc_viewer_ta…
jughosta Aug 9, 2024
5a77b80
[Discover] Refactor the truncation to be based on the cell height
jughosta Aug 9, 2024
f349d4f
Merge remote-tracking branch 'upstream/main' into collapse-long-field…
jughosta Aug 9, 2024
efa74d6
[Discover] Fix updates
jughosta Aug 9, 2024
7c25efe
Merge branch 'main' into collapse-long-field-values
jughosta Aug 10, 2024
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
1 change: 1 addition & 0 deletions packages/kbn-discover-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export {
SHOW_MULTIFIELDS,
SORT_DEFAULT_ORDER_SETTING,
TRUNCATE_MAX_HEIGHT,
TRUNCATE_MAX_HEIGHT_DEFAULT_VALUE,
IgnoredReason,
buildDataTableRecord,
buildDataTableRecordList,
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-discover-utils/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ export const SHOW_FIELD_STATISTICS = 'discover:showFieldStatistics';
export const SHOW_MULTIFIELDS = 'discover:showMultiFields';
export const SORT_DEFAULT_ORDER_SETTING = 'discover:sort:defaultOrder';
export const TRUNCATE_MAX_HEIGHT = 'truncate:maxHeight';
export const TRUNCATE_MAX_HEIGHT_DEFAULT_VALUE = 115;
5 changes: 3 additions & 2 deletions src/plugins/discover/server/ui_settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
MAX_DOC_FIELDS_DISPLAYED,
SHOW_MULTIFIELDS,
TRUNCATE_MAX_HEIGHT,
TRUNCATE_MAX_HEIGHT_DEFAULT_VALUE,
SHOW_FIELD_STATISTICS,
ROW_HEIGHT_OPTION,
} from '@kbn/discover-utils';
Expand Down Expand Up @@ -316,9 +317,9 @@ export const getUiSettings: (
},
[TRUNCATE_MAX_HEIGHT]: {
name: i18n.translate('discover.advancedSettings.params.maxCellHeightTitle', {
defaultMessage: 'Maximum cell height in the classic table',
defaultMessage: 'Maximum cell height in the table',
}),
value: 115,
value: TRUNCATE_MAX_HEIGHT_DEFAULT_VALUE,
category: ['discover'],
description: i18n.translate('discover.advancedSettings.params.maxCellHeightText', {
defaultMessage:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import { findTestSubject } from '@elastic/eui/lib/test';
import { DocViewerLegacyTable } from './table';
import type { DataView } from '@kbn/data-views-plugin/public';
import type { DocViewRenderProps } from '@kbn/unified-doc-viewer/types';
import { buildDataTableRecord } from '@kbn/discover-utils';
import {
buildDataTableRecord,
TRUNCATE_MAX_HEIGHT,
TRUNCATE_MAX_HEIGHT_DEFAULT_VALUE,
} from '@kbn/discover-utils';
import { setUnifiedDocViewerServices } from '../../../plugin';
import type { UnifiedDocViewerServices } from '../../../types';

Expand All @@ -22,6 +26,9 @@ const services = {
if (key === 'discover:showMultiFields') {
return true;
}
if (key === TRUNCATE_MAX_HEIGHT) {
return TRUNCATE_MAX_HEIGHT_DEFAULT_VALUE;
}
},
},
fieldFormats: {
Expand Down Expand Up @@ -127,34 +134,39 @@ describe('DocViewTable at Discover', () => {
{
_property: '_index',
addInclusiveFilterButton: true,
['toggleLongFieldValue-message']: false,
noMappingWarning: false,
toggleColumnButton: true,
underscoreWarning: false,
},
{
_property: 'message',
addInclusiveFilterButton: false,
['toggleLongFieldValue-message']: true,
noMappingWarning: false,
toggleColumnButton: true,
underscoreWarning: false,
},
{
_property: '_underscore',
addInclusiveFilterButton: false,
['toggleLongFieldValue-message']: false,
noMappingWarning: false,
toggleColumnButton: true,
underScoreWarning: true,
},
{
_property: 'scripted',
addInclusiveFilterButton: false,
['toggleLongFieldValue-message']: false,
noMappingWarning: false,
toggleColumnButton: true,
underScoreWarning: false,
},
{
_property: 'not_mapped',
addInclusiveFilterButton: false,
['toggleLongFieldValue-message']: false,
noMappingWarning: true,
toggleColumnButton: true,
underScoreWarning: false,
Expand All @@ -166,21 +178,26 @@ describe('DocViewTable at Discover', () => {
expect(rowComponent.length).toBe(1);
});

(['addInclusiveFilterButton', 'toggleColumnButton', 'underscoreWarning'] as const).forEach(
(element) => {
const elementExist = check[element];

if (typeof elementExist === 'boolean') {
const btn = findTestSubject(rowComponent, element, '^=');

it(`renders ${element} for '${check._property}' correctly`, () => {
const disabled = btn.length ? btn.props().disabled : true;
const clickAble = btn.length && !disabled ? true : false;
expect(clickAble).toBe(elementExist);
});
}
(
[
'addInclusiveFilterButton',
'toggleLongFieldValue-message',
'toggleColumnButton',
'underscoreWarning',
] as const
).forEach((element) => {
const elementExist = check[element];

if (typeof elementExist === 'boolean') {
const btn = findTestSubject(rowComponent, element, '^=');

it(`renders ${element} for '${check._property}' correctly`, () => {
const disabled = btn.length ? btn.props().disabled : true;
const clickAble = btn.length && !disabled ? true : false;
expect(clickAble).toBe(elementExist);
});
}
);
});
});
});

Expand Down Expand Up @@ -226,6 +243,17 @@ describe('DocViewTable at Discover Context', () => {
btn.simulate('click');
expect(props.filter).toBeCalled();
});

it(`renders functional collapse button`, () => {
const btn = findTestSubject(component, 'toggleLongFieldValue-message');
const html = component.html();

expect(html).toContain('kbnDocViewer__value--truncated');

expect(btn.length).toBe(1);
btn.simulate('click');
expect(component.html() !== html).toBeTruthy();
});
});

describe('DocViewTable at Discover Doc', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ export const DocViewerTable = ({
formattedValue={formattedValue}
rawValue={flattenedField}
ignoreReason={ignored}
isDetails={isDetails}
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import React from 'react';
import { render, screen } from '@testing-library/react';
import type { IUiSettingsClient } from '@kbn/core-ui-settings-browser';
import { TRUNCATE_MAX_HEIGHT, TRUNCATE_MAX_HEIGHT_DEFAULT_VALUE } from '@kbn/discover-utils';
import { TableFieldValue } from './table_cell_value';
import { setUnifiedDocViewerServices } from '../../plugin';
import { mockUnifiedDocViewerServices } from '../../__mocks__';

const mockServices = {
...mockUnifiedDocViewerServices,
};

mockServices.uiSettings.get = ((key: string) => {
if (key === TRUNCATE_MAX_HEIGHT) {
return TRUNCATE_MAX_HEIGHT_DEFAULT_VALUE;
}
return;
}) as IUiSettingsClient['get'];

setUnifiedDocViewerServices(mockUnifiedDocViewerServices);

describe('TableFieldValue', () => {
it('should render correctly', async () => {
render(
<TableFieldValue
formattedValue="100,000"
rawValue={10000}
field="bytes"
isDetails={false}
ignoreReason={undefined}
/>
);

expect(screen.getByText('100,000')).toBeInTheDocument();
expect(screen.queryByTestId('toggleLongFieldValue-bytes')).toBeNull();
});

it('should truncate a long value correctly', async () => {
const value = 'long value'.repeat(300);
render(
<TableFieldValue
formattedValue={value}
rawValue={value}
field="message"
isDetails={false}
ignoreReason={undefined}
/>
);

expect(screen.getByText(value)).toBeInTheDocument();

let toggleButton = screen.getByTestId('toggleLongFieldValue-message');
expect(toggleButton).toBeInTheDocument();
expect(toggleButton.getAttribute('aria-expanded')).toBe('false');

let valueElement = screen.getByTestId('tableDocViewRow-message-value');
expect(valueElement.getAttribute('css')).toBeDefined();
expect(valueElement.classList.contains('kbnDocViewer__value--truncated')).toBe(true);

toggleButton.click();

toggleButton = screen.getByTestId('toggleLongFieldValue-message');
expect(toggleButton).toBeInTheDocument();
expect(toggleButton.getAttribute('aria-expanded')).toBe('true');

valueElement = screen.getByTestId('tableDocViewRow-message-value');
expect(valueElement.getAttribute('css')).toBeNull();
expect(valueElement.classList.contains('kbnDocViewer__value--truncated')).toBe(false);
});

it('should not truncate a long value when inside a popover', async () => {
const value = 'long value'.repeat(300);
render(
<TableFieldValue
formattedValue={value}
rawValue={value}
field="message"
isDetails={true}
ignoreReason={undefined}
/>
);

expect(screen.getByText(value)).toBeInTheDocument();

expect(screen.queryByTestId('toggleLongFieldValue-bytes')).toBeNull();
jughosta marked this conversation as resolved.
Show resolved Hide resolved

const valueElement = screen.getByTestId('tableDocViewRow-message-value');
expect(valueElement.getAttribute('css')).toBeNull();
expect(valueElement.classList.contains('kbnDocViewer__value--truncated')).toBe(false);
});
});
Loading