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

Added support for default selections in EuiBasicTable #3418

Merged
merged 36 commits into from
May 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
029c9eb
Added selected prop to EuiTableSelectionType
ashikmeerankutty May 2, 2020
e230cf5
Allow default selecetion to basic table
ashikmeerankutty May 2, 2020
dbb8177
Added test for default selection
ashikmeerankutty May 2, 2020
4f6a955
Updated snapshot
ashikmeerankutty May 2, 2020
698efb2
Added cl
ashikmeerankutty May 2, 2020
39d00e6
Use array instead of function for default selected items
ashikmeerankutty May 6, 2020
b5c94be
Updated snapshots
ashikmeerankutty May 6, 2020
40d5930
Renamed to initialSelected
ashikmeerankutty May 6, 2020
dd0bb6f
Updated test
ashikmeerankutty May 6, 2020
97c9cc1
Removed test
ashikmeerankutty May 7, 2020
246fb19
Updated snapshot
ashikmeerankutty May 7, 2020
4d05aec
Set selection from outside the component
ashikmeerankutty May 7, 2020
1220402
Merge branch 'master' into data-table-selection
ashikmeerankutty May 7, 2020
06f8e04
Merge remote-tracking branch 'upstream/master' into data-table-selection
ashikmeerankutty May 10, 2020
0329cf1
Added initial selection and external selection info to docs
ashikmeerankutty May 10, 2020
bc1af46
Forward setSelection to basic table from in memory table
ashikmeerankutty May 14, 2020
c98858f
Merge branch 'master' into data-table-selection
ashikmeerankutty May 14, 2020
793c5d9
Refractor initial selection to be applied only once
ashikmeerankutty May 14, 2020
e6070cf
Updated in memory table docs
ashikmeerankutty May 14, 2020
ebcf0ba
Merge branch 'data-table-selection' of github.com:ashikmeerankutty/eu…
ashikmeerankutty May 14, 2020
0dd3090
Online users to Select online users
ashikmeerankutty May 14, 2020
9608f4f
Added test for initial selection
ashikmeerankutty May 14, 2020
357f583
Updated snapshot
ashikmeerankutty May 14, 2020
364f0a7
Merge branch 'master' into data-table-selection
chandlerprall May 14, 2020
c2f2487
Updated basic table docs
ashikmeerankutty May 14, 2020
25bccc7
Removed usage
ashikmeerankutty May 14, 2020
9a08724
Merge branch 'data-table-selection' of github.com:ashikmeerankutty/eu…
ashikmeerankutty May 14, 2020
f93e20b
Fixed initial selection in in memory selection
ashikmeerankutty May 15, 2020
e9d8137
Updated docs
ashikmeerankutty May 15, 2020
4384dc6
Merge remote-tracking branch 'upstream/master' into data-table-selection
ashikmeerankutty May 15, 2020
521ef1e
Updated docs
ashikmeerankutty May 16, 2020
f402d39
Merge remote-tracking branch 'upstream/master' into data-table-selection
ashikmeerankutty May 18, 2020
e95bd89
Fixed typos
ashikmeerankutty May 18, 2020
95843a5
Added test for initial selection in basic table
ashikmeerankutty May 18, 2020
a245782
Add test for initial selection for in_memory table
ashikmeerankutty May 18, 2020
daff6a9
Updated snapshots
ashikmeerankutty May 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
@@ -1,5 +1,6 @@
## [`master`](https://github.com/elastic/eui/tree/master)

- Added `initialSelected` to `EuiTableSelectionType` properties to set initial selected checkboxes for `EuiBasicTable` ([#3418](https://github.com/elastic/eui/pull/3418))
- Added exports for `EuiSteps` and related components types ([#3471](https://github.com/elastic/eui/pull/3471))
- Added `displayName` to components using `React.forwardRef` ([#3451](https://github.com/elastic/eui/pull/3451))
- Added event target checker for `EuiOverlayMask`'s `onClick` prop ([#3462](https://github.com/elastic/eui/pull/3462))
Expand Down
27 changes: 24 additions & 3 deletions src-docs/src/views/tables/in_memory/in_memory_selection.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useState, Fragment, useRef } from 'react';
import { formatDate } from '../../../../../src/services/format';
import { createDataStore } from '../data_store';
import {
Expand All @@ -7,6 +7,9 @@ import {
EuiButton,
EuiInMemoryTable,
EuiEmptyPrompt,
EuiFlexGroup,
EuiFlexItem,
EuiSpacer,
} from '../../../../../src/components';
import { Random } from '../../../../../src/services/random';

Expand Down Expand Up @@ -61,6 +64,7 @@ export const Table = () => {

const [selection, setSelection] = useState([]);
const [error, setError] = useState();
const tableRef = useRef();

const loadUsers = () => {
setMessage('Loading users...');
Expand Down Expand Up @@ -208,16 +212,33 @@ export const Table = () => {
pageSizeOptions: [3, 5, 8],
};

const onlineUsers = store.users.filter(user => user.online);

const selectionValue = {
selectable: user => user.online,
selectableMessage: selectable =>
!selectable ? 'User is currently offline' : undefined,
onSelectionChange: selection => setSelection(selection),
initialSelected: onlineUsers,
};

const onSelection = () => {
tableRef.current.setSelection(onlineUsers);
};

return (
<div>
<Fragment>
<EuiFlexGroup alignItems="center">
<EuiFlexItem grow={false}>
<EuiButton onClick={onSelection}>Select online users</EuiButton>
</EuiFlexItem>
<EuiFlexItem />
</EuiFlexGroup>

<EuiSpacer size="l" />

<EuiInMemoryTable
ref={tableRef}
items={users}
itemId="id"
error={error}
Expand All @@ -230,6 +251,6 @@ export const Table = () => {
selection={selectionValue}
isSelectable={true}
/>
</div>
</Fragment>
);
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import { EuiCode } from '../../../../../src/components';
import { GuideSectionTypes } from '../../../components';
import { renderToHtml } from '../../../services';

Expand All @@ -22,7 +23,13 @@ export const selectionSection = {
<p>
The following example shows how to use <strong>EuiInMemoryTable</strong>{' '}
along with item selection. It also shows how you can display messages,
errors and show loading indication.
errors and show loading indication. You can set items to be selected
initially by passing an array of items as the{' '}
<EuiCode>initialSelected</EuiCode> value inside{' '}
<EuiCode>selection</EuiCode> property. You can also use the{' '}
<EuiCode>setSelection</EuiCode> method to take complete control over table
selection. This can be useful if you want to handle selection in table
based on user interaction with another part of the UI.
</p>
),
demo: <Table />,
Expand Down
23 changes: 21 additions & 2 deletions src-docs/src/views/tables/selection/selection.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, Fragment } from 'react';
import React, { useState, Fragment, useRef } from 'react';
import { formatDate } from '../../../../../src/services/format';
import { createDataStore } from '../data_store';

Expand All @@ -9,6 +9,7 @@ import {
EuiButton,
EuiFlexGroup,
EuiFlexItem,
EuiSpacer,
} from '../../../../../src/components';

/*
Expand Down Expand Up @@ -41,6 +42,7 @@ export const Table = () => {
const [sortField, setSortField] = useState('firstName');
const [sortDirection, setSortDirection] = useState('asc');
const [selectedItems, setSelectedItems] = useState([]);
const tableRef = useRef();

const onTableChange = ({ page = {}, sort = {} }) => {
const { index: pageIndex, size: pageSize } = page;
Expand Down Expand Up @@ -176,17 +178,34 @@ export const Table = () => {
},
};

const onlineUsers = store.users.filter(user => user.online);

const selection = {
selectable: user => user.online,
selectableMessage: selectable =>
!selectable ? 'User is currently offline' : undefined,
onSelectionChange: onSelectionChange,
initialSelected: onlineUsers,
};

const onSelection = () => {
tableRef.current.setSelection(onlineUsers);
};

return (
<Fragment>
{deleteButton}
<EuiFlexGroup alignItems="center">
<EuiFlexItem grow={false}>
<EuiButton onClick={onSelection}>Select online users</EuiButton>
</EuiFlexItem>
<EuiFlexItem />
{deleteButton}
</EuiFlexGroup>

<EuiSpacer size="l" />

<EuiBasicTable
ref={tableRef}
items={pageOfItems}
itemId="id"
columns={columns}
Expand Down
7 changes: 6 additions & 1 deletion src-docs/src/views/tables/selection/selection_section.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ export const section = {
<p>
The following example shows how to configure selection via the{' '}
<EuiCode>selection</EuiCode>
property.
property. You can set items to be selected initially by passing an array
of items as the <EuiCode>initialSelected</EuiCode> value inside{' '}
<EuiCode>selection</EuiCode> property. You can also use the{' '}
<EuiCode>setSelection</EuiCode> method to take complete control over table
selection. This can be useful if you want to handle selection in table
based on user interaction with another part of the UI.
</p>
),
components: { EuiBasicTable },
Expand Down
Loading