Skip to content

Commit

Permalink
[UnifiedDataTable] Add gridStyle override support (#166994)
Browse files Browse the repository at this point in the history
  • Loading branch information
opauloh authored Sep 26, 2023
1 parent 22029b5 commit a338dd8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
33 changes: 33 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 @@ -432,4 +432,37 @@ describe('UnifiedDataTable', () => {
expect(tourStep).toEqual('test-expand');
});
});

describe('gridStyleOverride', () => {
it('should render the grid with the default style if no gridStyleOverride is provided', async () => {
const component = await getComponent({
...getProps(),
});

const grid = findTestSubject(component, 'docTable');

expect(grid.hasClass('euiDataGrid--bordersHorizontal')).toBeTruthy();
expect(grid.hasClass('euiDataGrid--fontSizeSmall')).toBeTruthy();
expect(grid.hasClass('euiDataGrid--paddingLarge')).toBeTruthy();
expect(grid.hasClass('euiDataGrid--rowHoverHighlight')).toBeTruthy();
expect(grid.hasClass('euiDataGrid--headerUnderline')).toBeTruthy();
expect(grid.hasClass('euiDataGrid--stripes')).toBeTruthy();
});
it('should render the grid with style override if gridStyleOverride is provided', async () => {
const component = await getComponent({
...getProps(),
gridStyleOverride: {
stripes: false,
rowHover: 'none',
border: 'none',
},
});

const grid = findTestSubject(component, 'docTable');

expect(grid.hasClass('euiDataGrid--stripes')).toBeFalsy();
expect(grid.hasClass('euiDataGrid--rowHoverHighlight')).toBeFalsy();
expect(grid.hasClass('euiDataGrid--bordersNone')).toBeTruthy();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
EuiDataGridControlColumn,
EuiDataGridCustomBodyProps,
EuiDataGridCellValueElementProps,
EuiDataGridStyle,
} from '@elastic/eui';
import type { DataView } from '@kbn/data-views-plugin/public';
import {
Expand Down Expand Up @@ -282,6 +283,10 @@ export interface UnifiedDataTableProps {
* Optional key/value pairs to set guided onboarding steps ids for a data table components included to guided tour.
*/
componentsTourSteps?: Record<string, string>;
/**
* Optional gridStyle override.
*/
gridStyleOverride?: EuiDataGridStyle;
}

export const EuiDataGridMemoized = React.memo(EuiDataGrid);
Expand Down Expand Up @@ -335,6 +340,7 @@ export const UnifiedDataTable = ({
externalCustomRenderers,
consumer = 'discover',
componentsTourSteps,
gridStyleOverride,
}: UnifiedDataTableProps) => {
const { fieldFormats, toastNotifications, dataViewFieldEditor, uiSettings, storage, data } =
services;
Expand Down Expand Up @@ -789,7 +795,7 @@ export const UnifiedDataTable = ({
toolbarVisibility={toolbarVisibility}
rowHeightsOptions={rowHeightsOptions}
inMemory={inMemory}
gridStyle={GRID_STYLE}
gridStyle={gridStyleOverride ?? GRID_STYLE}
renderCustomGridBody={renderCustomGridBody}
trailingControlColumns={trailingControlColumns}
/>
Expand Down

0 comments on commit a338dd8

Please sign in to comment.