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

[UnifiedDataTable] Add density configuration #188495

Merged
merged 42 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
8e7d5ed
[UnifiedDataTable] Add density configuration
lukasolson Jul 17, 2024
32dc686
Merge branch 'main' into unified_data_table_density
lukasolson Jul 17, 2024
61e9849
Fill out unit tests
lukasolson Jul 17, 2024
6457b74
Update comment text
lukasolson Jul 17, 2024
8e7e1c0
Merge branch 'main' into unified_data_table_density
lukasolson Jul 17, 2024
68d0408
Fix source document view
lukasolson Jul 19, 2024
96c4d65
Use dataGridStyle instead of density
lukasolson Jul 19, 2024
6c10fcd
Merge branch 'main' into unified_data_table_density
lukasolson Jul 22, 2024
9868caf
Fix tests & types
lukasolson Jul 22, 2024
1dc7401
Update snapshots & fix tests
lukasolson Jul 23, 2024
1822c7b
Merge branch 'main' into unified_data_table_density
lukasolson Jul 23, 2024
526781c
Merge branch 'main' into unified_data_table_density
lukasolson Jul 26, 2024
a1ba359
Use density key instead of data grid style
lukasolson Jul 26, 2024
185f791
Review feedback
lukasolson Jul 26, 2024
39d0734
Merge branch 'main' into unified_data_table_density
lukasolson Jul 26, 2024
b1e456b
Fix references to grid style
lukasolson Jul 26, 2024
ae547da
Merge branch 'unified_data_table_density' of github.com:lukasolson/ki…
lukasolson Jul 26, 2024
9158a2e
Fix tests
lukasolson Jul 26, 2024
101d311
Remove .only
lukasolson Jul 29, 2024
f249a19
Merge branch 'main' into unified_data_table_density
lukasolson Jul 29, 2024
0ae4b4b
Update test
lukasolson Jul 29, 2024
c3af7e2
Merge branch 'unified_data_table_density' of github.com:lukasolson/ki…
lukasolson Jul 29, 2024
3cf607a
Fix test
lukasolson Jul 30, 2024
55ad28f
Add density to saved search config
lukasolson Jul 31, 2024
ed0866d
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Jul 31, 2024
c899fe4
[CI] Auto-commit changed files from 'node scripts/jest_integration -u…
kibanamachine Jul 31, 2024
bbbbbc3
Merge branch 'main' into unified_data_table_density
lukasolson Jul 31, 2024
b54267a
Merge branch 'unified_data_table_density' github.com:lukasolson/kiba…
lukasolson Aug 1, 2024
b9e083c
Merge branch 'main' into unified_data_table_density
lukasolson Aug 1, 2024
05e8f68
Fix additional row settings
lukasolson Aug 1, 2024
69a580a
Merge branch 'main' of github.com:elastic/kibana into unified_data_ta…
lukasolson Aug 6, 2024
73f460f
Update jest snapshots
lukasolson Aug 6, 2024
c6be703
Merge branch 'main' into unified_data_table_density
lukasolson Aug 9, 2024
a28d99a
Merge branch 'main' into unified_data_table_density
bhavyarm Aug 9, 2024
0fd4430
Merge branch 'main' into unified_data_table_density
lukasolson Aug 12, 2024
1c215ef
Review feedback & remove unnecessary state
lukasolson Aug 13, 2024
54f9c02
Merge branch 'unified_data_table_density' of github.com:lukasolson/ki…
lukasolson Aug 13, 2024
371ee20
Remove showDensitySelector prop
lukasolson Aug 13, 2024
b6b708a
Workaround for EUI bug
lukasolson Aug 13, 2024
c37f61e
Add density functional tests
lukasolson Aug 14, 2024
cdb6099
Merge branch 'main' into unified_data_table_density
lukasolson Aug 15, 2024
f6baa05
Merge branch 'main' into unified_data_table_density
lukasolson Aug 19, 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: 2 additions & 0 deletions packages/kbn-unified-data-table/README.md
Copy link
Contributor

Choose a reason for hiding this comment

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

This makes me realize we have not been keeping the Unified Data Table docs updated..

Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ Props description:
| **externalCustomRenderers** | (optional)Record<string,(props: EuiDataGridCellValueElementProps) => React.ReactNode>; | An optional settings for a specified fields rendering like links. Applied only for the listed fields rendering. |
| **consumer** | (optional)string | Name of the UnifiedDataTable consumer component or application. |
| **componentsTourSteps** | (optional)Record<string,string> | Optional key/value pairs to set guided onboarding steps ids for a data table components included to guided tour. |
| **showDensitySelector** | (optional)boolean | Optional boolean to toggle whether or not to show the density selector. |
| **onUpdateDataGridDensity** | (optional)(DataGridDensity) => void; | Optional callback when the data grid density configuration is modified. |

*Required **services** list:
```
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-unified-data-table/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export {
} from './src/components/row_height_settings';
export { getDisplayedColumns } from './src/utils/columns';
export { getTextBasedColumnsMeta } from './src/utils/get_columns_meta';
export { ROWS_HEIGHT_OPTIONS } from './src/constants';
export { ROWS_HEIGHT_OPTIONS, DataGridDensity } from './src/constants';

export { JSONCodeEditorCommonMemoized } from './src/components/json_code_editor/json_code_editor_common';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ describe('CompareDocuments', () => {
"data-test-subj": "unifiedDataTableCompareDocuments",
"gridStyle": Object {
"border": "horizontal",
"cellPadding": "l",
"cellPadding": "s",
"fontSize": "s",
"header": "underline",
"rowHover": "highlight",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { AdditionalFieldGroups } from '@kbn/unified-field-list';
import { memoize } from 'lodash';
import React, { useMemo, useState } from 'react';
import useLocalStorage from 'react-use/lib/useLocalStorage';
import { GRID_STYLE } from '../../constants';
import { DATA_GRID_STYLE_DEFAULT } from '../../constants';
import { ComparisonControls } from './comparison_controls';
import { renderComparisonToolbar } from './comparison_toolbar';
import { useComparisonCellValue } from './hooks/use_comparison_cell_value';
Expand Down Expand Up @@ -55,7 +55,7 @@ export interface CompareDocumentsProps {

const COMPARISON_ROW_HEIGHT: EuiDataGridRowHeightsOptions = { defaultHeight: 'auto' };
const COMPARISON_IN_MEMORY: EuiDataGridInMemory = { level: 'sorting' };
const COMPARISON_GRID_STYLE: EuiDataGridStyle = { ...GRID_STYLE, stripes: undefined };
const COMPARISON_GRID_STYLE: EuiDataGridStyle = { ...DATA_GRID_STYLE_DEFAULT, stripes: undefined };

const getStorageKey = (consumer: string, key: string) => `${consumer}:dataGridComparison${key}`;

Expand Down
44 changes: 24 additions & 20 deletions packages/kbn-unified-data-table/src/components/data_table.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -382,16 +382,18 @@ describe('UnifiedDataTable', () => {
"additionalControls": null,
"showColumnSelector": false,
"showDisplaySelector": Object {
"additionalDisplaySettings": <UnifiedDataTableAdditionalDisplaySettings
headerRowHeight="custom"
headerRowHeightLines={1}
onChangeRowHeight={[Function]}
onChangeRowHeightLines={[Function]}
onChangeSampleSize={[MockFunction]}
rowHeight="custom"
rowHeightLines={3}
sampleSize={150}
/>,
"additionalDisplaySettings": <React.Fragment>
<UnifiedDataTableAdditionalDisplaySettings
headerRowHeight="custom"
headerRowHeightLines={1}
onChangeRowHeight={[Function]}
onChangeRowHeightLines={[Function]}
onChangeSampleSize={[MockFunction]}
rowHeight="custom"
rowHeightLines={3}
sampleSize={150}
/>
</React.Fragment>,
"allowDensity": false,
"allowResetButton": false,
"allowRowHeight": false,
Expand All @@ -414,15 +416,17 @@ describe('UnifiedDataTable', () => {
"additionalControls": null,
"showColumnSelector": false,
"showDisplaySelector": Object {
"additionalDisplaySettings": <UnifiedDataTableAdditionalDisplaySettings
headerRowHeight="custom"
headerRowHeightLines={1}
onChangeRowHeight={[Function]}
onChangeRowHeightLines={[Function]}
rowHeight="custom"
rowHeightLines={3}
sampleSize={200}
/>,
"additionalDisplaySettings": <React.Fragment>
<UnifiedDataTableAdditionalDisplaySettings
headerRowHeight="custom"
headerRowHeightLines={1}
onChangeRowHeight={[Function]}
onChangeRowHeightLines={[Function]}
rowHeight="custom"
rowHeightLines={3}
sampleSize={200}
/>
</React.Fragment>,
"allowDensity": false,
"allowResetButton": false,
"allowRowHeight": false,
Expand Down Expand Up @@ -700,7 +704,7 @@ describe('UnifiedDataTable', () => {

expect(grid.hasClass('euiDataGrid--bordersHorizontal')).toBeTruthy();
expect(grid.hasClass('euiDataGrid--fontSizeSmall')).toBeTruthy();
expect(grid.hasClass('euiDataGrid--paddingLarge')).toBeTruthy();
expect(grid.hasClass('euiDataGrid--paddingSmall')).toBeTruthy();
expect(grid.hasClass('euiDataGrid--rowHoverHighlight')).toBeTruthy();
expect(grid.hasClass('euiDataGrid--headerUnderline')).toBeTruthy();
expect(grid.hasClass('euiDataGrid--stripes')).toBeTruthy();
Expand Down
104 changes: 75 additions & 29 deletions packages/kbn-unified-data-table/src/components/data_table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ import {
EuiDataGridInMemory,
EuiDataGridControlColumn,
EuiDataGridCustomBodyProps,
EuiDataGridToolBarVisibilityDisplaySelectorOptions,
EuiDataGridStyle,
EuiDataGridProps,
EuiHorizontalRule,
EuiDataGridToolBarVisibilityDisplaySelectorOptions,
} from '@elastic/eui';
import type { DataView } from '@kbn/data-views-plugin/public';
import {
Expand All @@ -45,6 +46,7 @@ import type { ThemeServiceStart } from '@kbn/react-kibana-context-common';
import type { DataPublicPluginStart } from '@kbn/data-plugin/public';
import type { DocViewFilterFn } from '@kbn/unified-doc-viewer/types';
import { AdditionalFieldGroups } from '@kbn/unified-field-list';
import { DATA_GRID_DENSITY_STYLE_MAP, useDataGridDensity } from '../hooks/use_data_grid_density';
import {
UnifiedDataTableSettings,
ValueToStringConverter,
Expand All @@ -70,10 +72,11 @@ import { getSchemaDetectors } from './data_table_schema';
import { DataTableDocumentToolbarBtn } from './data_table_document_selection';
import { useRowHeightsOptions } from '../hooks/use_row_heights_options';
import {
DATA_GRID_STYLE_DEFAULT,
DEFAULT_ROWS_PER_PAGE,
GRID_STYLE,
ROWS_HEIGHT_OPTIONS,
toolbarVisibility as toolbarVisibilityDefaults,
DataGridDensity,
} from '../constants';
import { UnifiedDataTableFooter } from './data_table_footer';
import { UnifiedDataTableAdditionalDisplaySettings } from './data_table_additional_display_settings';
Expand Down Expand Up @@ -232,6 +235,18 @@ export interface UnifiedDataTableProps {
* Update row height state
*/
onUpdateRowHeight?: (rowHeight: number) => void;
/**
* Whether or not to show the density selector
*/
showDensitySelector?: boolean;
/**
* Density from state
*/
dataGridDensityState?: DataGridDensity;
/**
* Callback when the data grid density configuration is modified
*/
onUpdateDataGridDensity?: (dataGridDensity: DataGridDensity) => void;
/**
* Is text base lang mode enabled
*/
Expand Down Expand Up @@ -468,6 +483,9 @@ export const UnifiedDataTable = ({
cellContext,
renderCellPopover,
getRowIndicator,
showDensitySelector = false,
dataGridDensityState,
onUpdateDataGridDensity,
}: UnifiedDataTableProps) => {
const { fieldFormats, toastNotifications, dataViewFieldEditor, uiSettings, storage, data } =
services;
Expand Down Expand Up @@ -604,6 +622,23 @@ export const UnifiedDataTable = ({
return getShouldShowFieldHandler(dataViewFields, dataView, showMultiFields);
}, [dataView, showMultiFields]);

const { dataGridDensity, onChangeDataGridDensity } = useDataGridDensity({
storage,
consumer,
dataGridDensityState,
onUpdateDataGridDensity,
});

const gridStyle = useMemo<EuiDataGridStyle>(
() => ({
...DATA_GRID_STYLE_DEFAULT,
...DATA_GRID_DENSITY_STYLE_MAP[dataGridDensity],
onChange: onChangeDataGridDensity,
...gridStyleOverride,
}),
[dataGridDensity, onChangeDataGridDensity, gridStyleOverride]
);

/**
* Cell rendering
*/
Expand All @@ -619,6 +654,7 @@ export const UnifiedDataTable = ({
maxEntries: maxDocFieldsDisplayed,
externalCustomRenderers,
isPlainRecord,
isCompressed: dataGridDensity === DataGridDensity.COMPACT,
}),
[
dataView,
Expand All @@ -629,6 +665,7 @@ export const UnifiedDataTable = ({
fieldFormats,
externalCustomRenderers,
isPlainRecord,
dataGridDensity,
]
);

Expand Down Expand Up @@ -940,34 +977,41 @@ export const UnifiedDataTable = ({
[renderCustomToolbar, additionalControls]
);

const showDisplaySelector = useMemo(() => {
const options: EuiDataGridToolBarVisibilityDisplaySelectorOptions = {};

if (onUpdateRowHeight) {
options.allowDensity = false;
const showDisplaySelector = useMemo(():
| EuiDataGridToolBarVisibilityDisplaySelectorOptions
| undefined => {
if (
!onUpdateDataGridDensity &&
!onUpdateRowHeight &&
!onUpdateHeaderRowHeight &&
!onUpdateSampleSize
) {
return;
}

if (onUpdateRowHeight || onUpdateHeaderRowHeight || onUpdateSampleSize) {
options.allowRowHeight = false;
options.allowResetButton = false;
options.additionalDisplaySettings = (
<UnifiedDataTableAdditionalDisplaySettings
rowHeight={rowHeight}
rowHeightLines={rowHeightLines}
onChangeRowHeight={onChangeRowHeight}
onChangeRowHeightLines={onChangeRowHeightLines}
headerRowHeight={headerRowHeight}
headerRowHeightLines={headerRowHeightLines}
onChangeHeaderRowHeight={onChangeHeaderRowHeight}
onChangeHeaderRowHeightLines={onChangeHeaderRowHeightLines}
maxAllowedSampleSize={maxAllowedSampleSize}
sampleSize={sampleSizeState}
onChangeSampleSize={onUpdateSampleSize}
/>
);
}

return Object.keys(options).length ? options : undefined;
return {
allowDensity: Boolean(onUpdateDataGridDensity),
allowRowHeight: false,
allowResetButton: false,
additionalDisplaySettings: (
<>
{showDensitySelector ? <EuiHorizontalRule margin="s" /> : null}
lukasolson marked this conversation as resolved.
Show resolved Hide resolved
<UnifiedDataTableAdditionalDisplaySettings
rowHeight={rowHeight}
rowHeightLines={rowHeightLines}
onChangeRowHeight={onChangeRowHeight}
onChangeRowHeightLines={onChangeRowHeightLines}
headerRowHeight={headerRowHeight}
headerRowHeightLines={headerRowHeightLines}
onChangeHeaderRowHeight={onChangeHeaderRowHeight}
onChangeHeaderRowHeightLines={onChangeHeaderRowHeightLines}
maxAllowedSampleSize={maxAllowedSampleSize}
sampleSize={sampleSizeState}
onChangeSampleSize={onUpdateSampleSize}
/>
</>
),
};
}, [
headerRowHeight,
headerRowHeightLines,
Expand All @@ -982,6 +1026,8 @@ export const UnifiedDataTable = ({
rowHeight,
rowHeightLines,
sampleSizeState,
showDensitySelector,
onUpdateDataGridDensity,
]);

const inMemory = useMemo(() => {
Expand Down Expand Up @@ -1108,7 +1154,7 @@ export const UnifiedDataTable = ({
toolbarVisibility={toolbarVisibility}
rowHeightsOptions={rowHeightsOptions}
inMemory={inMemory}
gridStyle={gridStyleOverride ?? GRID_STYLE}
gridStyle={gridStyle}
renderCustomGridBody={renderCustomGridBody}
renderCustomToolbar={renderCustomToolbarFn}
trailingControlColumns={trailingControlColumns}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export function SourceDocument({
fieldFormats,
dataTestSubj = 'discoverCellDescriptionList',
className,
isCompressed = true,
}: {
useTopLevelObjectColumns: boolean;
row: DataTableRecord;
Expand All @@ -48,6 +49,7 @@ export function SourceDocument({
fieldFormats: FieldFormatsStart;
dataTestSubj?: string;
className?: string;
isCompressed?: boolean;
}) {
const pairs: FormattedHit = useTopLevelObjectColumns
? getTopLevelObjectPairs(row.raw, columnId, dataView, shouldShowFieldHandler).slice(
Expand All @@ -59,7 +61,7 @@ export function SourceDocument({
return (
<EuiDescriptionList
type="inline"
compressed
compressed={isCompressed}
className={classnames('unifiedDataTable__descriptionList', CELL_CLASS, className)}
data-test-subj={dataTestSubj}
>
Expand Down
29 changes: 24 additions & 5 deletions packages/kbn-unified-data-table/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { EuiDataGridStyle } from '@elastic/eui';
import type { EuiDataGridStyle } from '@elastic/eui';

export const DEFAULT_CONTROL_COLUMN_WIDTH = 24;

export const DEFAULT_ROWS_PER_PAGE = 100;
export const MAX_LOADED_GRID_ROWS = 10000;

export const ROWS_PER_PAGE_OPTIONS = [10, 25, 50, DEFAULT_ROWS_PER_PAGE, 250, 500];
/**
* Row height might be a value from -1 to 20
Expand All @@ -29,13 +28,27 @@ export const defaultMonacoEditorWidth = 370;
export const defaultTimeColumnWidth = 212;
export const kibanaJSON = 'kibana-json';

export const GRID_STYLE: EuiDataGridStyle = {
border: 'horizontal',
export const DATA_GRID_STYLE_COMPACT: EuiDataGridStyle = {
cellPadding: 's',
fontSize: 's',
};

export const DATA_GRID_STYLE_NORMAL: EuiDataGridStyle = {
cellPadding: 'm',
fontSize: 'm',
};

export const DATA_GRID_STYLE_EXPANDED: EuiDataGridStyle = {
cellPadding: 'l',
fontSize: 'l',
};

export const DATA_GRID_STYLE_DEFAULT: EuiDataGridStyle = {
...DATA_GRID_STYLE_COMPACT,
border: 'horizontal',
stripes: true,
rowHover: 'highlight',
header: 'underline',
stripes: true,
};

export const toolbarVisibility = {
Expand All @@ -44,3 +57,9 @@ export const toolbarVisibility = {
allowReorder: true,
},
};

export enum DataGridDensity {
COMPACT = 'compact',
NORMAL = 'normal',
EXPANDED = 'expanded',
}
Loading