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 29 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: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## [`master`](https://github.com/elastic/eui/tree/master)

No public interface changes since `34.5.1`.
- Added `rowHeightsOptions` to `EuiDataGrid` to allow configuring row heights ([#4853](https://github.com/elastic/eui/pull/4853))

## [`34.5.1`](https://github.com/elastic/eui/tree/v34.5.1)

Expand Down
1 change: 1 addition & 0 deletions scripts/a11y-testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const docsPages = async (root, page) => {
`${root}#/tabular-content/data-grid-control-columns`,
`${root}#/tabular-content/data-grid-footer-row`,
`${root}#/tabular-content/data-grid-virtualization`,
`${root}#/tabular-content/data-grid-row-height-options`,
];

return [
Expand Down
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 @@ -379,6 +380,7 @@ const navigation = [
DataGridControlColumnsExample,
DataGridFooterRowExample,
DataGridVirtualizationExample,
DataGridRowHeightOptionsExample,
TableExample,
TableInMemoryExample,
].map((example) => createExample(example)),
Expand Down
2 changes: 2 additions & 0 deletions src-docs/src/views/datagrid/datagrid_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
EuiDataGridPopoverContentProps,
EuiDataGridControlColumn,
EuiDataGridToolBarVisibilityColumnSelectorOptions,
EuiDataGridRowHeightsOptions,
} from '!!prop-loader!../../../../src/components/datagrid/data_grid_types';

import { EuiDataGridCellValueElementProps } from '!!prop-loader!../../../../src/components/datagrid/data_grid_cell';
Expand Down Expand Up @@ -377,6 +378,7 @@ export const DataGridExample = {
EuiDataGridToolBarVisibilityOptions,
EuiDataGridToolBarVisibilityColumnSelectorOptions,
EuiDataGridPopoverContentProps,
EuiDataGridRowHeightsOptions,
},
demo: (
<Fragment>
Expand Down
66 changes: 66 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,66 @@
import React, { Fragment } from 'react';

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

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

const rowHeightsSnippet = `
VladLasitsa marked this conversation as resolved.
Show resolved Hide resolved
{
defaultHeight: {
lineCount: 2, // default every row to 2 lines of text. Also we can provide height in pixels
},
rowHeights: {
1: {
lineCount: 5, // for row which have index 1 we allow to show 5 lines after that we truncate
},
4: 140, // for row which have index 4 we set 140 pixel
5: 80,
},
}
`;

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>rowHeightsOptions</EuiCode> prop. It accepts an object
configuring the default height and/or specific row heights:
</p>
<ul>
<li>
<EuiCode>defaultHeight</EuiCode> - defines the default size for
all rows
</li>
<li>
<EuiCode>rowHeights</EuiCode> - overrides the height for a
specific row
</li>
</ul>
<EuiCodeBlock language="javascript" paddingSize="s" isCopyable>
{rowHeightsSnippet}
</EuiCodeBlock>
</Fragment>
),
components: { DataGridRowHeightOptions },
demo: <DataGridRowHeightOptions />,
},
],
};
128 changes: 128 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,128 @@
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 rowHeightsOptions = useMemo(
() => ({
defaultHeight: {
lineCount: 2,
},
rowHeights: {
1: {
lineCount: 5,
},
4: 10,
5: 80,
VladLasitsa marked this conversation as resolved.
Show resolved Hide resolved
},
}),
[]
);

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}
rowHeightsOptions={rowHeightsOptions}
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>
);
};
8 changes: 8 additions & 0 deletions src/components/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ export const assertNever = (x: never): never => {
export type OneOf<T, K extends keyof T> = Omit<T, K> &
{ [k in K]: Pick<Required<T>, k> & { [k1 in Exclude<K, k>]?: never } }[K];

/**
* Require at least one of the keys in `T`
*
* Usage: AtLeastOne<typeToExtend>
*/
export type AtLeastOne<T, U = { [K in keyof T]: Pick<T, K> }> = Partial<T> &
U[keyof U];

/**
* Wraps Object.keys with proper typescript definition of the resulting array
*/
Expand Down
Loading