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

[DATA GRID] Column header menu #3087

Merged
merged 43 commits into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
8e6613f
header menu boilerplate
snide Mar 16, 2020
42e07ed
Merge remote-tracking branch 'upstream/master' into grid/menus
snide Jul 20, 2020
674b4c7
Enable column option "Hide column"
kertal Jul 20, 2020
97b433c
Enable column options for sorting
kertal Jul 21, 2020
d6be83e
Enable column options for moving columns left/right
kertal Jul 21, 2020
9ef3752
Fix moving column left / right
kertal Jul 23, 2020
cbf6d4a
Merge master / fix conflicts
kertal Aug 4, 2020
1527cca
Fix header row detection, migrate to use EuiButtonIcon
kertal Aug 6, 2020
57a5c6f
Merge remote-tracking branch 'upstream/master' into kertal-data-grid-…
kertal Aug 20, 2020
75eff28
Make column actions configureable
kertal Aug 22, 2020
39eef30
Document types
kertal Aug 24, 2020
23f7414
Fix tests
kertal Aug 24, 2020
805105b
Improve columns_actions.tsx types
kertal Aug 27, 2020
319058b
Update src/components/datagrid/column_actions.tsx
kertal Aug 27, 2020
fba5db3
Update src/components/datagrid/column_actions.tsx
kertal Aug 27, 2020
6e7a37c
Add header action label i18n
kertal Aug 27, 2020
324b6c0
Undo header interactives detection
kertal Aug 27, 2020
54f7dc7
Extract logic of columns selector into helper function
kertal Aug 27, 2020
0fcbc78
Merge branch 'grid/menus' of https://github.com/snide/eui into kertal…
kertal Aug 27, 2020
9ab3b6c
Remove EuiPopover id since it's not used
kertal Aug 27, 2020
9caf2af
Prevent displaying 0 when column actions are set to false
kertal Aug 27, 2020
5aaf887
Refactor switchColumnPos code
kertal Aug 27, 2020
8d7098d
Allow unsorting of columns by column actions
kertal Aug 27, 2020
d5af4db
Merge branch 'grid/menus' of https://github.com/snide/eui into kertal…
kertal Aug 27, 2020
a835ac0
Add example to doc
kertal Sep 2, 2020
6655f4d
Address review comments
kertal Sep 2, 2020
4427e20
Add test
kertal Sep 3, 2020
0d9729f
Merge remote-tracking branch 'upstream/master' into kertal-data-grid-…
kertal Sep 4, 2020
039e4ae
Fix test
kertal Sep 4, 2020
76886a3
Merge remote-tracking branch 'upstream/master' into kertal-data-grid-…
kertal Sep 8, 2020
59fbfd4
Address review comments
kertal Sep 8, 2020
3a1b6ea
icon sizing and color
snide Sep 10, 2020
23badbb
Merge remote-tracking branch 'upstream/master' into grid/menus
snide Sep 14, 2020
4d8987a
Refactor header cell to use a button element
kertal Sep 15, 2020
cfbc170
Adapt CHANGELOG.md
kertal Sep 15, 2020
ac62f85
fix focus in menu
andreadelrio Sep 15, 2020
22290eb
fix focus of menu (again) and add mixin
andreadelrio Sep 15, 2020
ff0b060
Fix closing menu
kertal Sep 17, 2020
a89a385
Remove any
kertal Sep 18, 2020
5462b1b
Cleanup
kertal Sep 18, 2020
8dc426d
Merge master / fix conflicts
kertal Sep 18, 2020
7b00e40
End the focus war
kertal Sep 18, 2020
a3075ae
Update CHANGELOG.md
chandlerprall Sep 18, 2020
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Added `boolean` type to the `notification` prop of `EuiHeaderSectionItemButton` to show a simple dot ([#4008](https://github.com/elastic/eui/pull/4008))
- Added `popoverButton` and `popoverButtonBreakpoints` props to `EuiSelectableTemplateSitewide` for responsive capabilities ([#4008](https://github.com/elastic/eui/pull/4008))
- Added `isWithinMaxBreakpoint` service ([#4008](https://github.com/elastic/eui/pull/4008))
- Added column header menu to `EuiDataGrid` ([#3087](https://github.com/elastic/eui/pull/3087))

**Bug fixes**

Expand Down
107 changes: 107 additions & 0 deletions src-docs/src/views/datagrid/column_actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import React, { useState, useCallback } from 'react';
import { fake } from 'faker';

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

const columns = [
{
id: 'avatar',
initialWidth: 40,
isResizable: false,
actions: false,
},
{
id: 'name',
initialWidth: 100,
isSortable: true,
actions: {
showHide: false,
},
},
{
id: 'email',
isSortable: true,
actions: {
additional: [
{
iconType: 'heart',
label: 'Send Email',
size: 'xs',
onClick: () =>
alert('🎵Return to sender, address unknown, no such number,...'),
},
],
},
},
{
id: 'city',
isSortable: true,
actions: {
showHide: {
iconType: 'cross',
label: 'Remove column',
},
},
},
{
id: 'country',
},
{
id: 'account',
},
];

const data = [];

for (let i = 1; i < 5; i++) {
data.push({
avatar: (
<EuiAvatar
size="s"
imageUrl={fake('{{internet.avatar}}')}
name={fake('{{name.lastName}}, {{name.firstName}}')}
/>
),
name: fake('{{name.lastName}}, {{name.firstName}} {{name.suffix}}'),
email: fake('{{internet.email}}'),
city: fake('{{address.city}}'),
country: fake('{{address.country}}'),
account: fake('{{finance.account}}'),
});
}

export default () => {
const [pagination, setPagination] = useState({ pageIndex: 0, pageSize: 10 });

const [visibleColumns, setVisibleColumns] = useState(() =>
columns.map(({ id }) => id)
);

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

return (
<EuiDataGrid
aria-label="DataGrid demonstrating column sizing constraints"
columns={columns}
columnVisibility={{
visibleColumns: visibleColumns,
setVisibleColumns: setVisibleColumns,
}}
rowCount={data.length}
renderCellValue={({ rowIndex, columnId }) => data[rowIndex][columnId]}
pagination={{
...pagination,
pageSizeOptions: [5, 10, 25],
onChangeItemsPerPage: setPageSize,
onChangePage: setPageIndex,
}}
/>
);
};
31 changes: 15 additions & 16 deletions src-docs/src/views/datagrid/datagrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,26 @@ const columns = [
},
{
id: 'email',
display: (
// This is an example of an icon next to a title that still respects text truncate
<EuiFlexGroup gutterSize="xs" responsive={false}>
<EuiFlexItem className="eui-textTruncate">
<div className="eui-textTruncate">email</div>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButtonIcon
aria-label="Column header email"
iconType="gear"
color="text"
onClick={() => alert('Email Icon Clicked!')}
/>
</EuiFlexItem>
</EuiFlexGroup>
),
},
{
id: 'location',
},
{
id: 'account',
actions: {
showHide: { label: 'Custom hide label' },
showMoveLeft: false,
showMoveRight: false,
additional: [
{
label: 'Custom action',
onClick: () => alert('🎉'),
iconType: 'cheer',
size: 'xs',
color: 'text',
},
],
},
chandlerprall marked this conversation as resolved.
Show resolved Hide resolved
},
{
id: 'date',
Expand All @@ -65,6 +63,7 @@ const columns = [
defaultSortDirection: 'desc',
initialWidth: 65,
isResizable: false,
actions: false,
},
];

Expand Down
12 changes: 9 additions & 3 deletions src-docs/src/views/datagrid/datagrid_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
EuiDataGridStyle,
EuiDataGridToolBarVisibilityOptions,
EuiDataGridColumnVisibility,
EuiDataGridColumnActions,
EuiDataGridPopoverContentProps,
EuiDataGridControlColumn,
EuiDataGridToolBarVisibilityColumnSelectorOptions,
Expand All @@ -41,9 +42,13 @@ const gridSnippet = `
// Required. There are 200 total records.
rowCount={200}
// Required. Sets up three columns, the last of which has a custom schema we later define down below.
// The second column B won't allow clicking in to see the content in a popup.
// The first column defines a starting width of 150px and prevents the user from resizing it
columns={[{ id: 'A', initialWidth: 150, isResizable: false }, { id: 'B', isExpandable: false }, {id: 'C', schema: 'franchise'}]}
// The second column B won't allow clicking in to see the content in a popup and doesn't show move actions in column header cell
// The first column defines a starting width of 150px, prevents the user from resizing it and no actions are displayed
columns={[
{ id: 'A', initialWidth: 150, isResizable: false, actions: false },
{ id: 'B', isExpandable: false, actions: { showMoveLeft: false, showMoveRight: false } },
{ id: 'C', schema: 'franchise'}
]}
// Optional. This allows you to initially hide columns. Users can still turn them on.
columnVisibility={{
visibleColumns: ['A', 'C'],
Expand Down Expand Up @@ -354,6 +359,7 @@ export const DataGridExample = {
EuiDataGrid,
EuiDataGridColumn,
EuiDataGridColumnVisibility,
EuiDataGridColumnActions,
EuiDataGridControlColumn,
EuiDataGridInMemory,
EuiDataGridPaginationProps,
Expand Down
2 changes: 2 additions & 0 deletions src-docs/src/views/datagrid/datagrid_schema_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const dataGridSchemaHtml = renderToHtml(DataGridSchema);

import {
EuiDataGridColumn,
EuiDataGridColumnActions,
EuiDataGridPaginationProps,
EuiDataGridSorting,
EuiDataGridInMemory,
Expand Down Expand Up @@ -89,6 +90,7 @@ export const DataGridSchemaExample = {
EuiDataGrid,
EuiDataGridInMemory,
EuiDataGridColumn,
EuiDataGridColumnActions,
EuiDataGridColumnVisibility,
EuiDataGridPaginationProps,
EuiDataGridSorting,
Expand Down
55 changes: 53 additions & 2 deletions src-docs/src/views/datagrid/datagrid_styling_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import React, { Fragment } from 'react';
import { renderToHtml } from '../../services';

import { GuideSectionTypes } from '../../components';
import { EuiDataGrid, EuiCode, EuiCodeBlock } from '../../../../src/components';
import {
EuiDataGrid,
EuiCode,
EuiCodeBlock,
EuiListGroupItem,
} from '../../../../src/components';

import DataGridContainer from './container';
const dataGridContainerSource = require('!!raw-loader!./container');
Expand All @@ -18,11 +23,15 @@ const dataGridControlsSource = require('!!raw-loader!./additional_controls');
const dataGridControlsHtml = renderToHtml(DataGridControls);

import DataGridColumnWidths from './column_widths';
import DataGridColumnActions from './column_actions';
const dataGridColumnWidthsSource = require('!!raw-loader!./column_widths');
const dataGridColumnWidthsHtml = renderToHtml(DataGridColumnWidths);
const dataGridColumnActionsSource = require('!!raw-loader!./column_actions');
const dataGridColumnActionsHtml = renderToHtml(DataGridColumnActions);

import {
EuiDataGridColumn,
EuiDataGridColumnActions,
EuiDataGridStyle,
EuiDataGridToolBarVisibilityOptions,
} from '!!prop-loader!../../../../src/components/datagrid/data_grid_types';
Expand Down Expand Up @@ -122,7 +131,7 @@ const widthsSnippet = `<EuiDataGrid
`;

export const DataGridStylingExample = {
title: 'Data grid styling and toolbar',
title: 'Data grid styling and control',
sections: [
{
source: [
Expand Down Expand Up @@ -259,5 +268,47 @@ export const DataGridStylingExample = {
},
demo: <DataGridColumnWidths />,
},
{
source: [
{
type: GuideSectionTypes.JS,
code: dataGridColumnActionsSource,
},
{
type: GuideSectionTypes.HTML,
code: dataGridColumnActionsHtml,
},
],
title: 'Column actions',
text: (
<Fragment>
<p>
By default, columns provide actions for sorting, moving and hiding.
These can be extended with custom actions. You can customize the
actions by setting the <EuiCode>actions</EuiCode> value of{' '}
<strong>EuiDataGridColumn</strong>. Setting it to{' '}
<EuiCode>false</EuiCode> removes the action menu displayed. You can
configure it by passing an object of type{' '}
<strong>EuiDataGridColumnAction</strong>. This allows you a hide,
configure the existing actions and add new ones.
</p>
<p>
Below, the first column provides no action, the second doesn&apos;t
provide the ability to hide the columns, the 3rd provides an
additional action, the 4th overwrites the hide action with a custom
label and icon.
</p>
</Fragment>
),
components: { DataGridColumnActions },
snippet: widthsSnippet,
props: {
EuiDataGrid,
EuiDataGridColumn,
EuiDataGridColumnActions,
EuiListGroupItem,
},
demo: <DataGridColumnActions />,
},
chandlerprall marked this conversation as resolved.
Show resolved Hide resolved
],
};
6 changes: 6 additions & 0 deletions src-docs/src/views/datagrid/focus.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export default () => {
</EuiFlexGroup>
),
isExpandable: false,
actions: false,
},
{
id: 'no-interactives is expandable',
Expand All @@ -115,6 +116,7 @@ export default () => {
</EuiFlexItem>
</EuiFlexGroup>
),
actions: false,
},
{
id: 'one-interactive not expandable',
Expand All @@ -134,6 +136,7 @@ export default () => {
</EuiFlexGroup>
),
isExpandable: false,
actions: false,
},
{
id: 'one-interactives is expandable',
Expand All @@ -153,6 +156,7 @@ export default () => {
</EuiFlexItem>
</EuiFlexGroup>
),
actions: false,
},
{
id: 'two-interactives not expandable',
Expand All @@ -173,6 +177,7 @@ export default () => {
</EuiFlexGroup>
),
isExpandable: false,
actions: false,
},
{
id: 'two-interactives is expandable',
Expand All @@ -192,6 +197,7 @@ export default () => {
</EuiFlexItem>
</EuiFlexGroup>
),
actions: false,
},
],
[areHeadersInteractive]
Expand Down
Loading