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 all 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
2 changes: 1 addition & 1 deletion docs/management/advanced-options.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ The default refresh interval for the time filter. Example:
The default selection in the time filter.

[[truncate-maxheight]]`truncate:maxHeight`::
The maximum height that a cell occupies in a table. Set to 0 to disable
deprecated:[8.16.0]The maximum height that a cell occupies in a table. Set to 0 to disable
truncation.

[[enableESQL]]`enableESQL`::
Expand Down
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;
9 changes: 8 additions & 1 deletion 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 @@ -318,13 +319,19 @@ export const getUiSettings: (
name: i18n.translate('discover.advancedSettings.params.maxCellHeightTitle', {
defaultMessage: 'Maximum cell height in the classic table',
}),
value: 115,
value: TRUNCATE_MAX_HEIGHT_DEFAULT_VALUE,
category: ['discover'],
description: i18n.translate('discover.advancedSettings.params.maxCellHeightText', {
defaultMessage:
'The maximum height that a cell in a table should occupy. Set to 0 to disable truncation.',
}),
schema: schema.number({ min: 0 }),
requiresPageReload: true,
deprecation: {
message: i18n.translate('discover.advancedSettings.discover.maxCellHeightDeprecation', {
defaultMessage: 'This setting is deprecated and will be removed in Kibana 9.0.',
}),
docLinksKey: 'discoverSettings',
},
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ export const MAIN_COLUMNS: Array<EuiBasicTableColumn<FieldRecordLegacy>> = [
formattedValue={formattedValue}
rawValue={flattenedField}
ignoreReason={ignored}
isDetails={false}
isLegacy={true}
/>
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,9 @@ import {
isNestedFieldParent,
usePager,
} from '@kbn/discover-utils';
import {
FieldDescription,
getFieldSearchMatchingHighlight,
getTextBasedColumnIconType,
} from '@kbn/field-utils';
import { getTextBasedColumnIconType } from '@kbn/field-utils';
import type { DocViewRenderProps } from '@kbn/unified-doc-viewer/types';
import { FieldName } from '@kbn/unified-doc-viewer';
import { getUnifiedDocViewerServices } from '../../plugin';
import { TableFieldValue } from './table_cell_value';
import {
type TableRow,
getFieldCellActions,
Expand All @@ -58,6 +52,7 @@ import {
getTabContentAvailableHeight,
} from '../doc_viewer_source/get_height';
import { TableFilters, TableFiltersProps, useTableFilters } from './table_filters';
import { TableCell } from './table_cell';

export type FieldRecord = TableRow;

Expand Down Expand Up @@ -137,7 +132,7 @@ export const DocViewerTable = ({
}: DocViewRenderProps) => {
const isEsqlMode = Array.isArray(textBasedHits);
const [containerRef, setContainerRef] = useState<HTMLDivElement | null>(null);
const { fieldFormats, storage, uiSettings, fieldsMetadata } = getUnifiedDocViewerServices();
const { fieldFormats, storage, uiSettings } = getUnifiedDocViewerServices();
const showMultiFields = uiSettings.get(SHOW_MULTIFIELDS);
const currentDataViewId = dataView.id!;

Expand Down Expand Up @@ -375,60 +370,17 @@ export const DocViewerTable = ({

const renderCellValue: EuiDataGridProps['renderCellValue'] = useCallback(
({ rowIndex, columnId, isDetails }) => {
const row = rows[rowIndex];

if (!row) {
return null;
}

const {
action: { flattenedField },
field: { field, fieldMapping, fieldType, scripted, pinned },
value: { formattedValue, ignored },
} = row;

if (columnId === 'name') {
return (
<div>
<FieldName
fieldName={field}
fieldType={fieldType}
fieldMapping={fieldMapping}
scripted={scripted}
highlight={getFieldSearchMatchingHighlight(
fieldMapping?.displayName ?? field,
tableFiltersProps.searchTerm
)}
isPinned={pinned}
/>

{isDetails && !!fieldMapping ? (
<div>
<FieldDescription
fieldsMetadataService={fieldsMetadata}
field={fieldMapping}
truncate={false}
/>
</div>
) : null}
</div>
);
}

if (columnId === 'value') {
return (
<TableFieldValue
field={field}
formattedValue={formattedValue}
rawValue={flattenedField}
ignoreReason={ignored}
/>
);
}

return null;
return (
<TableCell
searchTerm={tableFiltersProps.searchTerm}
rows={rows}
rowIndex={rowIndex}
columnId={columnId}
isDetails={isDetails}
/>
);
},
[rows, tableFiltersProps.searchTerm, fieldsMetadata]
[rows, tableFiltersProps.searchTerm]
);

const renderCellPopover = useCallback(
Expand Down Expand Up @@ -528,6 +480,7 @@ export const DocViewerTable = ({
`}
>
<EuiDataGrid
key={`fields-table-${hit.id}`}
{...GRID_PROPS}
aria-label={i18n.translate('unifiedDocViewer.fieldsTable.ariaLabel', {
defaultMessage: 'Field values',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* 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 { FieldName } from '@kbn/unified-doc-viewer';
import { FieldDescription, getFieldSearchMatchingHighlight } from '@kbn/field-utils';
import { TableFieldValue } from './table_cell_value';
import type { TableRow } from './table_cell_actions';
import { getUnifiedDocViewerServices } from '../../plugin';

interface TableCellProps {
searchTerm: string;
rows: TableRow[];
rowIndex: number;
columnId: string;
isDetails: boolean;
}

export const TableCell: React.FC<TableCellProps> = React.memo(
({ searchTerm, rows, rowIndex, columnId, isDetails }) => {
const { fieldsMetadata } = getUnifiedDocViewerServices();

const row = rows[rowIndex];

if (!row) {
return null;
}

const {
action: { flattenedField },
field: { field, fieldMapping, fieldType, scripted, pinned },
value: { formattedValue, ignored },
} = row;

if (columnId === 'name') {
return (
<div>
<FieldName
fieldName={field}
fieldType={fieldType}
fieldMapping={fieldMapping}
scripted={scripted}
highlight={getFieldSearchMatchingHighlight(
fieldMapping?.displayName ?? field,
searchTerm
)}
isPinned={pinned}
/>

{isDetails && !!fieldMapping ? (
<div>
<FieldDescription
fieldsMetadataService={fieldsMetadata}
field={fieldMapping}
truncate={false}
/>
</div>
) : null}
</div>
);
}

if (columnId === 'value') {
return (
<TableFieldValue
field={field}
formattedValue={formattedValue}
rawValue={flattenedField}
ignoreReason={ignored}
isDetails={isDetails}
/>
);
}

return null;
}
);
Loading