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 gridStyle override support #166994

Merged
Merged
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
Loading