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

Move EuiBasicTable's itemId prop out of selection into a top-level prop #830

Merged
merged 9 commits into from
May 16, 2018
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
- Made boolean matching in `EuiSearchBar` more exact so it doesn't match words starting with booleans, like "truest" or "offer" ([#776](https://github.com/elastic/eui/pull/776))
- `EuiComboBox` do not setState or call refs once component is unmounted ([807](https://github.com/elastic/eui/pull/807) and [#813](https://github.com/elastic/eui/pull/813))

**Breaking changes**

- Move `EuiBasicTable`'s `itemId` prop from `selection` to a top-level property [#830](https://github.com/elastic/eui/pull/830)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the link should be wrapped in parentheses to match the others


## [`0.0.46`](https://github.com/elastic/eui/tree/v0.0.46)

- Added `EuiDescribedFormGroup` component, a wrapper around `EuiFormRow`(s) ([#707](https://github.com/elastic/eui/pull/707))
Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/views/tables/actions/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ export class Table extends Component {
};

const selection = {
itemId: 'id',
selectable: (user) => user.online,
selectableMessage: (selectable) => !selectable ? 'User is currently offline' : undefined,
onSelectionChange: this.onSelectionChange
Expand Down Expand Up @@ -292,6 +291,7 @@ export class Table extends Component {

<EuiBasicTable
items={pageOfItems}
itemId="id"
columns={columns}
pagination={pagination}
sorting={sorting}
Expand Down
10 changes: 5 additions & 5 deletions src-docs/src/views/tables/basic/props_info.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ export const propsInfo = {
required: true,
type: { name: 'object[]' }
},
itemId: {
description: 'describes how to extract a unique ID from each item, used for selections & expanded rows',
required: false,
type: { name: 'string | (item) => string' }
},
compressed: {
description: 'Makes the font and padding smaller for the entire table',
type: { name: 'bool' }
Expand Down Expand Up @@ -88,11 +93,6 @@ export const propsInfo = {
__docgenInfo: {
_euiObjectType: 'type',
props: {
itemId: {
description: 'describes how to extract a unique ID from each item',
required: true,
type: { name: 'string | (item) => string' }
},
onSelectionChanged: {
description: 'A callback that will be called whenever the item selection changes',
required: false,
Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/views/tables/expanding_rows/expanding_rows.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ export class Table extends Component {
};

const selection = {
itemId: 'id',
selectable: (user) => user.online,
selectableMessage: (selectable) => !selectable ? 'User is currently offline' : undefined,
onSelectionChange: this.onSelectionChange
Expand All @@ -219,6 +218,7 @@ export class Table extends Component {
{deleteButton}
<EuiBasicTable
items={pageOfItems}
itemId="id"
itemIdToExpandedRowMap={this.state.itemIdToExpandedRowMap}
isExpandable={true}
hasActions={true}
Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/views/tables/in_memory/in_memory_selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ export class Table extends Component {
};

const selection = {
itemId: 'id',
selectable: (user) => user.online,
selectableMessage: (selectable) => !selectable ? 'User is currently offline' : undefined,
onSelectionChange: (selection) => this.setState({ selection })
Expand All @@ -227,6 +226,7 @@ export class Table extends Component {
<div>
<EuiInMemoryTable
items={this.state.users}
itemId="id"
error={this.state.error}
loading={this.state.loading}
message={this.state.message}
Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/views/tables/mobile/mobile.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ export class Table extends Component {
};

const selection = {
itemId: 'id',
selectable: (user) => user.online,
selectableMessage: (selectable) => !selectable ? 'User is currently offline' : undefined,
onSelectionChange: this.onSelectionChange
Expand Down Expand Up @@ -219,6 +218,7 @@ export class Table extends Component {

<EuiBasicTable
items={pageOfItems}
itemId="id"
columns={columns}
pagination={pagination}
sorting={sorting}
Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/views/tables/selection/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ export class Table extends Component {
};

const selection = {
itemId: 'id',
selectable: (user) => user.online,
selectableMessage: (selectable) => !selectable ? 'User is currently offline' : undefined,
onSelectionChange: this.onSelectionChange
Expand All @@ -203,6 +202,7 @@ export class Table extends Component {
{deleteButton}
<EuiBasicTable
items={pageOfItems}
itemId="id"
columns={columns}
pagination={pagination}
sorting={sorting}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ exports[`EuiInMemoryTable with pagination and selection 1`] = `
},
]
}
itemId="id"
itemIdToExpandedRowMap={Object {}}
items={
Array [
Expand Down Expand Up @@ -342,7 +343,6 @@ exports[`EuiInMemoryTable with pagination and selection 1`] = `
responsive={true}
selection={
Object {
"itemId": "id",
"onSelectionChanged": [Function],
}
}
Expand Down Expand Up @@ -400,6 +400,7 @@ exports[`EuiInMemoryTable with pagination, selection and sorting 1`] = `
},
]
}
itemId="id"
itemIdToExpandedRowMap={Object {}}
items={
Array [
Expand Down Expand Up @@ -434,7 +435,6 @@ exports[`EuiInMemoryTable with pagination, selection and sorting 1`] = `
responsive={true}
selection={
Object {
"itemId": "id",
"onSelectionChanged": [Function],
}
}
Expand Down Expand Up @@ -476,6 +476,7 @@ exports[`EuiInMemoryTable with pagination, selection, sorting and simple search
},
]
}
itemId="id"
itemIdToExpandedRowMap={Object {}}
items={
Array [
Expand Down Expand Up @@ -510,7 +511,6 @@ exports[`EuiInMemoryTable with pagination, selection, sorting and simple search
responsive={true}
selection={
Object {
"itemId": "id",
"onSelectionChanged": [Function],
}
}
Expand Down Expand Up @@ -546,6 +546,7 @@ exports[`EuiInMemoryTable with pagination, selection, sorting and a single recor
},
]
}
itemId="id"
itemIdToExpandedRowMap={Object {}}
items={
Array [
Expand Down Expand Up @@ -580,7 +581,6 @@ exports[`EuiInMemoryTable with pagination, selection, sorting and a single recor
responsive={true}
selection={
Object {
"itemId": "id",
"onSelectionChanged": [Function],
}
}
Expand All @@ -605,6 +605,7 @@ exports[`EuiInMemoryTable with pagination, selection, sorting and column rendere
},
]
}
itemId="id"
itemIdToExpandedRowMap={Object {}}
items={
Array [
Expand Down Expand Up @@ -635,7 +636,6 @@ exports[`EuiInMemoryTable with pagination, selection, sorting and column rendere
responsive={true}
selection={
Object {
"itemId": "id",
"onSelectionChanged": [Function],
}
}
Expand Down Expand Up @@ -697,6 +697,7 @@ exports[`EuiInMemoryTable with pagination, selection, sorting and configured sea
},
]
}
itemId="id"
itemIdToExpandedRowMap={Object {}}
items={
Array [
Expand All @@ -723,7 +724,6 @@ exports[`EuiInMemoryTable with pagination, selection, sorting and configured sea
responsive={true}
selection={
Object {
"itemId": "id",
"onSelectionChanged": [Function],
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/basic_table/basic_table.behavior.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe('EuiBasicTable', () => {
{ id: '1', name: 'name1' },
{ id: '2', name: 'name2' }
],
itemId: 'id',
columns: [
{
field: 'name',
Expand All @@ -24,7 +25,6 @@ describe('EuiBasicTable', () => {
}
],
selection: {
itemId: 'id',
onSelectionChanged: () => {}
},
onChange: () => {}
Expand Down
16 changes: 8 additions & 8 deletions src/components/basic_table/basic_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,12 @@ export const ComputedColumnType = PropTypes.shape({

export const ColumnType = PropTypes.oneOfType([FieldDataColumnType, ComputedColumnType, ActionsColumnType]);

const ItemIdType = PropTypes.oneOfType([
export const ItemIdType = PropTypes.oneOfType([
PropTypes.string, // the name of the item id property
PropTypes.func // (item) => string
]);

export const SelectionType = PropTypes.shape({
itemId: ItemIdType.isRequired,
onSelectionChange: PropTypes.func, // (selection: Record[]) => void;,
selectable: PropTypes.func, // (item) => boolean;
selectableMessage: PropTypes.func // (selectable, item) => boolean;
Expand All @@ -129,6 +128,7 @@ const SortingType = PropTypes.shape({

const BasicTablePropTypes = {
items: PropTypes.array.isRequired,
itemId: ItemIdType,
columns: PropTypes.arrayOf(ColumnType).isRequired,
pagination: PaginationType,
sorting: SortingType,
Expand Down Expand Up @@ -172,12 +172,12 @@ export class EuiBasicTable extends Component {
}

itemId(item) {
const { selection } = this.props;
if (selection) {
if (isFunction(selection.itemId)) {
return selection.itemId(item);
const { itemId } = this.props;
if (itemId) {
if (isFunction(itemId)) {
return itemId(item);
}
return item[selection.itemId];
return item[itemId];
}
}

Expand Down Expand Up @@ -480,7 +480,7 @@ export class EuiBasicTable extends Component {

const cells = [];

const itemId = selection ? this.itemId(item) : rowIndex;
const itemId = this.itemId(item) || rowIndex;
const selected = !selection ? false : this.state.selection && !!this.state.selection.find(selectedRecord => (
this.itemId(selectedRecord) === itemId
));
Expand Down
14 changes: 7 additions & 7 deletions src/components/basic_table/basic_table.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ describe('EuiBasicTable', () => {
{ id: '2', name: 'name2' },
{ id: '3', name: 'name3' }
],
itemId: 'id',
columns: [
{
field: 'name',
Expand All @@ -285,7 +286,6 @@ describe('EuiBasicTable', () => {
totalItemCount: 5
},
selection: {
itemId: 'id',
onSelectionChanged: () => undefined
},
onChange: () => {}
Expand All @@ -306,6 +306,7 @@ describe('EuiBasicTable', () => {
{ id: '2', name: 'name2' },
{ id: '3', name: 'name3' }
],
itemId: 'id',
columns: [
{
field: 'name',
Expand All @@ -320,7 +321,6 @@ describe('EuiBasicTable', () => {
totalItemCount: 5
},
selection: {
itemId: 'id',
onSelectionChanged: () => undefined
},
sorting: {
Expand All @@ -344,6 +344,7 @@ describe('EuiBasicTable', () => {
{ id: '2', name: 'name2' },
{ id: '3', name: 'name3' }
],
itemId: 'id',
columns: [
{
field: 'name',
Expand All @@ -359,7 +360,6 @@ describe('EuiBasicTable', () => {
totalItemCount: 5
},
selection: {
itemId: 'id',
onSelectionChanged: () => undefined
},
sorting: {
Expand All @@ -383,6 +383,7 @@ describe('EuiBasicTable', () => {
{ id: '2', count: 2 },
{ id: '3', count: 3 }
],
itemId: 'id',
columns: [
{
field: 'count',
Expand All @@ -398,7 +399,6 @@ describe('EuiBasicTable', () => {
totalItemCount: 5
},
selection: {
itemId: 'id',
onSelectionChanged: () => undefined
},
sorting: {
Expand All @@ -423,6 +423,7 @@ describe('EuiBasicTable', () => {
{ id: '2', count: 2 },
{ id: '3', count: 3 }
],
itemId: 'id',
columns: [
{
field: 'count',
Expand All @@ -439,7 +440,6 @@ describe('EuiBasicTable', () => {
totalItemCount: 5
},
selection: {
itemId: 'id',
onSelectionChanged: () => undefined
},
sorting: {
Expand All @@ -463,6 +463,7 @@ describe('EuiBasicTable', () => {
{ id: '2', name: 'name2' },
{ id: '3', name: 'name3' }
],
itemId: 'id',
columns: [
{
field: 'name',
Expand All @@ -488,7 +489,6 @@ describe('EuiBasicTable', () => {
totalItemCount: 5
},
selection: {
itemId: 'id',
onSelectionChanged: () => undefined
},
sorting: {
Expand All @@ -512,6 +512,7 @@ describe('EuiBasicTable', () => {
{ id: '2', name: 'name2' },
{ id: '3', name: 'name3' }
],
itemId: 'id',
columns: [
{
field: 'name',
Expand Down Expand Up @@ -543,7 +544,6 @@ describe('EuiBasicTable', () => {
totalItemCount: 5
},
selection: {
itemId: 'id',
onSelectionChanged: () => undefined
},
sorting: {
Expand Down
Loading