Skip to content

Commit

Permalink
[UnifiedDataTable] add row line-height override support (#167725)
Browse files Browse the repository at this point in the history
  • Loading branch information
opauloh authored Oct 2, 2023
1 parent 3f4e53f commit 66b1c7f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
23 changes: 23 additions & 0 deletions packages/kbn-unified-data-table/src/components/data_table.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -465,4 +465,27 @@ describe('UnifiedDataTable', () => {
expect(grid.hasClass('euiDataGrid--bordersNone')).toBeTruthy();
});
});
describe('rowLineHeightOverride', () => {
it('should render the grid with the default row line height if no rowLineHeightOverride is provided', async () => {
const component = await getComponent({
...getProps(),
});

const gridRowCell = findTestSubject(component, 'dataGridRowCell').first();
expect(gridRowCell.prop('style')).toMatchObject({
lineHeight: '1.6em',
});
});
it('should render the grid with row line height override if rowLineHeightOverride is provided', async () => {
const component = await getComponent({
...getProps(),
rowLineHeightOverride: '24px',
});

const gridRowCell = findTestSubject(component, 'dataGridRowCell').first();
expect(gridRowCell.prop('style')).toMatchObject({
lineHeight: '24px',
});
});
});
});
6 changes: 6 additions & 0 deletions packages/kbn-unified-data-table/src/components/data_table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,10 @@ export interface UnifiedDataTableProps {
* Optional gridStyle override.
*/
gridStyleOverride?: EuiDataGridStyle;
/**
* Optional row line height override. Default is 1.6em.
*/
rowLineHeightOverride?: string;
}

export const EuiDataGridMemoized = React.memo(EuiDataGrid);
Expand Down Expand Up @@ -341,6 +345,7 @@ export const UnifiedDataTable = ({
consumer = 'discover',
componentsTourSteps,
gridStyleOverride,
rowLineHeightOverride,
}: UnifiedDataTableProps) => {
const { fieldFormats, toastNotifications, dataViewFieldEditor, uiSettings, storage, data } =
services;
Expand Down Expand Up @@ -728,6 +733,7 @@ export const UnifiedDataTable = ({
storage,
configRowHeight,
consumer,
rowLineHeight: rowLineHeightOverride,
});

const isRenderComplete = loadingState !== DataLoadingState.loading;
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-unified-data-table/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const ROWS_HEIGHT_OPTIONS = {
single: 0,
default: -1,
};

export const defaultRowLineHeight = '1.6em';
export const defaultMonacoEditorWidth = 370;
export const defaultTimeColumnWidth = 212;
export const kibanaJSON = 'kibana-json';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ import {
getStoredRowHeight,
updateStoredRowHeight,
} from '../utils/row_heights';
import { ROWS_HEIGHT_OPTIONS } from '../constants';
import { defaultRowLineHeight, ROWS_HEIGHT_OPTIONS } from '../constants';

interface UseRowHeightProps {
rowHeightState?: number;
onUpdateRowHeight?: (rowHeight: number) => void;
storage: Storage;
configRowHeight?: number;
consumer: string;
rowLineHeight?: string;
}

/**
Expand Down Expand Up @@ -57,6 +58,7 @@ export const useRowHeightsOptions = ({
storage,
configRowHeight = ROWS_HEIGHT_OPTIONS.default,
consumer,
rowLineHeight = defaultRowLineHeight,
}: UseRowHeightProps) => {
return useMemo((): EuiDataGridRowHeightsOptions => {
const rowHeightFromLS = getStoredRowHeight(storage, consumer);
Expand All @@ -79,7 +81,7 @@ export const useRowHeightsOptions = ({

return {
defaultHeight,
lineHeight: '1.6em',
lineHeight: rowLineHeight,
onChange: ({ defaultHeight: newRowHeight }: EuiDataGridRowHeightsOptions) => {
const newSerializedRowHeight = serializeRowHeight(
// pressing "Reset to default" triggers onChange with the same value
Expand All @@ -89,5 +91,5 @@ export const useRowHeightsOptions = ({
onUpdateRowHeight?.(newSerializedRowHeight);
},
};
}, [storage, consumer, rowHeightState, configRowHeight, onUpdateRowHeight]);
}, [storage, consumer, rowHeightState, rowLineHeight, configRowHeight, onUpdateRowHeight]);
};

0 comments on commit 66b1c7f

Please sign in to comment.