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

[EUI Datagrid] Adds rowHeightOptions property #4853

Merged
merged 35 commits into from
Jul 6, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
369cf15
Adds rowHeightOptions
VladLasitsa Jun 3, 2021
9e610d8
Add documentation
VladLasitsa Jun 3, 2021
6fd0fc5
Fix eslint
VladLasitsa Jun 4, 2021
583835b
Some work
VladLasitsa Jun 8, 2021
3bd3fbf
fix eslint
VladLasitsa Jun 8, 2021
b249223
Add lineCount as property for rowHeightOptions
VladLasitsa Jun 11, 2021
b298e50
increase performance
VladLasitsa Jun 14, 2021
da06a02
Fix some remarks
VladLasitsa Jun 14, 2021
69f16f3
Fix eslint
VladLasitsa Jun 14, 2021
15d4d49
Fix some remarks
VladLasitsa Jun 15, 2021
0653a21
Fix some style issues
VladLasitsa Jun 15, 2021
3a19c80
Fix eslint
VladLasitsa Jun 15, 2021
70d54ad
Fix tests
VladLasitsa Jun 16, 2021
def727c
Render and logic optimizations
chandlerprall Jun 16, 2021
db3770b
Merge branch 'set_height_for_row' of github.com:VladLasitsa/eui into …
chandlerprall Jun 16, 2021
3a476ed
Fix some problems
VladLasitsa Jun 17, 2021
593a096
Fix utils for firefox
VladLasitsa Jun 17, 2021
8c6b821
Merge remote-tracking branch 'upstream/master' into set_height_for_row
VladLasitsa Jun 17, 2021
4ab7d48
fix a11y
VladLasitsa Jun 17, 2021
08e844d
Add tests for rowHeightsOptions functionality
VladLasitsa Jun 17, 2021
e558c5c
Fix ci
VladLasitsa Jun 18, 2021
e9748eb
Add CHANGELOG
VladLasitsa Jun 18, 2021
86c2721
Merge remote-tracking branch 'upstream/master' into set_height_for_row
VladLasitsa Jun 18, 2021
72134e1
Fix name of function
VladLasitsa Jun 18, 2021
8b752ee
Fix problem with density and add validation for height
VladLasitsa Jun 21, 2021
e41ccda
Fix some remarks
VladLasitsa Jun 25, 2021
689a5a6
Fix tests
VladLasitsa Jun 25, 2021
3354ce4
Merge branch 'master' into set_height_for_row
chandlerprall Jun 29, 2021
c9318da
changelog update
chandlerprall Jun 29, 2021
ac900b4
Update row_height_utils.ts
alexwizp Jun 29, 2021
60d8973
Merge remote-tracking branch 'upstream/master' into set_height_for_row
VladLasitsa Jul 5, 2021
6a15a0d
Fix documentation
VladLasitsa Jul 5, 2021
531bd76
Fix eslint
VladLasitsa Jul 5, 2021
b632984
Removed unused AtLeastOnce util type, re-phrased minimum row height r…
chandlerprall Jul 6, 2021
6af2eb6
Merge branch 'master' into set_height_for_row
chandlerprall Jul 6, 2021
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 src-docs/src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import { DataGridStylingExample } from './views/datagrid/datagrid_styling_exampl
import { DataGridControlColumnsExample } from './views/datagrid/datagrid_controlcolumns_example';
import { DataGridFooterRowExample } from './views/datagrid/datagrid_footer_row_example';
import { DataGridVirtualizationExample } from './views/datagrid/datagrid_virtualization_example';
import { DataGridRowHeightOptionsExample } from './views/datagrid/datagrid_height_options_example';

import { DatePickerExample } from './views/date_picker/date_picker_example';

Expand Down Expand Up @@ -388,6 +389,7 @@ const navigation = [
DataGridControlColumnsExample,
DataGridFooterRowExample,
DataGridVirtualizationExample,
DataGridRowHeightOptionsExample,
TableExample,
TableInMemoryExample,
].map((example) => createExample(example)),
Expand Down
54 changes: 54 additions & 0 deletions src-docs/src/views/datagrid/datagrid_height_options_example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React, { Fragment } from 'react';

import { renderToHtml } from '../../services';
import { GuideSectionTypes } from '../../components';
import { EuiCode } from '../../../../src/components';

import DataGridRowHeightOptions from './row_height_options';
const dataGridRowHeightOptionsSource = require('!!raw-loader!./row_height_options');
const dataGridRowHeightOptionsHtml = renderToHtml(DataGridRowHeightOptions);

export const DataGridRowHeightOptionsExample = {
title: 'Data grid row height options',
sections: [
{
source: [
{
type: GuideSectionTypes.JS,
code: dataGridRowHeightOptionsSource,
},
{
type: GuideSectionTypes.HTML,
code: dataGridRowHeightOptionsHtml,
},
],
text: (
<Fragment>
<p>
Row height options can be passed down to the grid through the{' '}
<EuiCode>rowHeightOptions</EuiCode> prop. It accepts an object that
allows for customization.
</p>
<p>
The <EuiCode>rowHeightOptions</EuiCode> prop have two properties:
</p>
<ul>
<li>
<EuiCode>defaultHeight</EuiCode> - uses for defining height which
will be used for all rows as default (number)
</li>
<li>
<EuiCode>initialHeights</EuiCode> - uses for defining height which
will be used for defined row.
<br />
This is an object where the key is the row number and the value is
its height.
</li>
</ul>
</Fragment>
),
components: { DataGridRowHeightOptions },
demo: <DataGridRowHeightOptions />,
},
],
};
119 changes: 119 additions & 0 deletions src-docs/src/views/datagrid/row_height_options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import React, {
useCallback,
useState,
createContext,
useContext,
useMemo,
useEffect,
} from 'react';
import { fake } from 'faker';

import { EuiDataGrid, EuiText } from '../../../../src/components/';

const DataContext = createContext();

const columns = [
{
id: 'name',
displayAsText: 'Name',
defaultSortDirection: 'asc',
},
{
id: 'text',
},
];

// it is expensive to compute 10000 rows of fake data
// instead of loading up front, generate entries on the fly
const raw_data = [];

function RenderCellValue({ rowIndex, columnId }) {
const { data, adjustMountedCellCount } = useContext(DataContext);

useEffect(() => {
adjustMountedCellCount(1);
return () => adjustMountedCellCount(-1);
}, [adjustMountedCellCount]);

if (data[rowIndex] == null) {
data[rowIndex] = {
name: fake('{{lorem.text}}'),
text: fake('{{lorem.text}}'),
};
}

return data[rowIndex][columnId];
}

export default () => {
// ** Pagination config
const [pagination, setPagination] = useState({ pageIndex: 0, pageSize: 50 });

const onChangeItemsPerPage = useCallback(
(pageSize) =>
setPagination((pagination) => ({
...pagination,
pageSize,
pageIndex: 0,
})),
[setPagination]
);

const onChangePage = useCallback(
(pageIndex) =>
setPagination((pagination) => ({ ...pagination, pageIndex })),
[setPagination]
);

// Column visibility
const [visibleColumns, setVisibleColumns] = useState(() =>
columns.map(({ id }) => id)
); // initialize to the full set of columns

const [mountedCellCount, setMountedCellCount] = useState(0);

const dataContext = useMemo(
() => ({
data: raw_data,
adjustMountedCellCount: (adjustment) =>
setMountedCellCount(
(mountedCellCount) => mountedCellCount + adjustment
),
}),
[]
);

const grid = (
<EuiDataGrid
aria-label="Row height options demo"
columns={columns}
columnVisibility={{ visibleColumns, setVisibleColumns }}
rowCount={10000}
height={400}
renderCellValue={RenderCellValue}
rowHeightOptions={{
defaultHeight: 60,
initialHeights: {
1: 100,
4: 140,
5: 80,
},
}}
pagination={{
...pagination,
pageSizeOptions: [50, 250, 1000],
onChangeItemsPerPage: onChangeItemsPerPage,
onChangePage: onChangePage,
}}
/>
);

return (
<DataContext.Provider value={dataContext}>
<EuiText>
<p>There are {mountedCellCount} rendered cells</p>
</EuiText>
{grid}
</DataContext.Provider>
);
};
21 changes: 21 additions & 0 deletions src/components/datagrid/_data_grid_data_row.scss
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@
flex-grow: 1;
}

.euiDataGridRowCell__contentByHeight {
max-width: 100%;
VladLasitsa marked this conversation as resolved.
Show resolved Hide resolved
flex-grow: 1;
}

.euiDataGridRowCell__expandButton {
display: flex;
flex-grow: 0;
Expand Down Expand Up @@ -218,12 +223,20 @@
}
}

.euiDataGridRowCell--fontSizeSmall {
@include euiFontSizeXS;
}

@include euiDataGridStyles(fontSizeLarge) {
@include euiDataGridRowCell {
@include euiFontSize;
}
}

.euiDataGridRowCell--fontSizeLarge {
@include euiFontSize;
}

// Padding alternates
@include euiDataGridStyles(paddingSmall) {
@include euiDataGridRowCell {
Expand All @@ -236,6 +249,10 @@
}
}

.euiDataGridRowCell--paddingSmall {
padding: $euiDataGridCellPaddingS;
}

@include euiDataGridStyles(paddingLarge) {
@include euiDataGridRowCell {
padding: $euiDataGridCellPaddingL;
Expand All @@ -247,6 +264,10 @@
}
}

.euiDataGridRowCell--paddingLarge {
padding: $euiDataGridCellPaddingL;
}

@keyframes euiDataGridCellButtonSlideIn {
from {
margin-left: 0;
Expand Down
8 changes: 8 additions & 0 deletions src/components/datagrid/data_grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import {
EuiDataGridFocusedCell,
EuiDataGridOnColumnResizeHandler,
EuiDataGridStyleFooter,
EuiDataGridRowHeightOptions,
} from './data_grid_types';
import { EuiDataGridCellProps } from './data_grid_cell';
import { EuiButtonEmpty } from '../button';
Expand All @@ -78,6 +79,7 @@ import {
DataGridSortingContext,
} from './data_grid_context';
import { useDataGridColumnSorting } from './column_sorting';
import { computedStylesForGridCell } from './get_max_lines';

// Used to short-circuit some async browser behaviour that is difficult to account for in tests
const IS_JEST_ENVIRONMENT = global.hasOwnProperty('_isJest');
Expand Down Expand Up @@ -163,6 +165,8 @@ type CommonGridProps = CommonProps &
* Sets the grid's width, forcing it to overflow in a scrollable container with cell virtualization
*/
width?: CSSProperties['width'];

rowHeightOptions?: EuiDataGridRowHeightOptions;
};

// Force either aria-label or aria-labelledby to be defined
Expand Down Expand Up @@ -692,6 +696,7 @@ export const EuiDataGrid: FunctionComponent<EuiDataGridProps> = (props) => {
minSizeForControls = MINIMUM_WIDTH_FOR_GRID_CONTROLS,
height,
width,
rowHeightOptions,
...rest
} = props;

Expand Down Expand Up @@ -888,6 +893,8 @@ export const EuiDataGrid: FunctionComponent<EuiDataGridProps> = (props) => {
}
}, [focusedCell, contentRef]);

computedStylesForGridCell(gridStyles);

const classes = classNames(
'euiDataGrid',
fontSizesToClassMap[gridStyles.fontSize!],
Expand Down Expand Up @@ -1128,6 +1135,7 @@ export const EuiDataGrid: FunctionComponent<EuiDataGridProps> = (props) => {
renderFooterCellValue={renderFooterCellValue}
rowCount={rowCount}
interactiveCellId={interactiveCellId}
rowHeightOptions={rowHeightOptions}
/>
</div>
</div>
Expand Down
Loading