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

Fix table re-rendering by showing/hiding actions column via CSS instead #665

Merged
merged 6 commits into from
Apr 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
- Wrap `EuiHorizontalStep` text instead of truncating it ([#653](https://github.com/elastic/eui/pull/653))
- Fixed a bug where `EuiSideNavItem` wouldn't pass an `onClick` handler down to `<a>` tags if they also had an `href`. ([#664](https://github.com/elastic/eui/pull/664))

**Bug fixes**

- Fixed `EuiBasicTable` re-rendering on hover of table rows ([#665](https://github.com/elastic/eui/pull/665))

**Breaking changes**

- `EuiHorizontalSteps` now requires an `onClick` prop be provided for each step configuration object ([#653](https://github.com/elastic/eui/pull/653))
Expand Down
98 changes: 78 additions & 20 deletions src-docs/src/views/tables/actions/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
EuiFlexItem,
EuiSwitch,
EuiSpacer,
EuiText,
} from '../../../../../src/components';

/*
Expand Down Expand Up @@ -47,7 +48,8 @@ export class Table extends Component {
sortField: 'firstName',
sortDirection: 'asc',
selectedItems: [],
multiAction: false
multiAction: false,
customAction: false,
};
}

Expand Down Expand Up @@ -79,6 +81,10 @@ export class Table extends Component {
});
};

onSelectionChange = (selectedItems) => {
this.setState({ selectedItems });
};

renderDeleteButton() {
const { selectedItems } = this.state;

Expand All @@ -101,6 +107,10 @@ export class Table extends Component {
this.setState(prevState => ({ multiAction: !prevState.multiAction }));
};

toggleCustomAction = () => {
this.setState(prevState => ({ customAction: !prevState.customAction }));
};

deleteUser = user => {
store.deleteUsers(user.id);
this.setState({ selectedItems: [] });
Expand All @@ -117,6 +127,8 @@ export class Table extends Component {
pageSize,
sortField,
sortDirection,
multiAction,
customAction,
} = this.state;

const {
Expand All @@ -126,6 +138,63 @@ export class Table extends Component {

const deleteButton = this.renderDeleteButton();

let actions = null;

if(multiAction) {
actions = customAction
? [{
render: (item) => {
return (
<EuiText color="secondary" onClick={() => this.cloneUser(item)}>
Clone
</EuiText>
);
}
}, {
render: (item) => {
return (
<EuiText color="danger" onClick={() => this.deleteUser(item)}>
Delete
</EuiText>
);
}
}]
: [{
name: 'Clone',
description: 'Clone this person',
icon: 'copy',
onClick: this.cloneUser
}, {
name: 'Delete',
description: 'Delete this person',
icon: 'trash',
color: 'danger',
onClick: this.deleteUser
}];
} else {
actions = customAction
? [{
render: (item) => {
return (
<EuiLink
onClick={() => this.deleteUser(item)}
color="danger"
>
Delete
</EuiLink>
);
}
}]
: [{
name: 'Delete',
description: 'Delete this person',
icon: 'trash',
color: 'danger',
type: 'icon',
onClick: this.deleteUser
}];
}

const columns = [{
field: 'firstName',
name: 'First Name',
Expand Down Expand Up @@ -166,25 +235,7 @@ export class Table extends Component {
sortable: true
}, {
name: 'Actions',
actions: this.state.multiAction ? [{
name: 'Clone',
description: 'Clone this person',
icon: 'copy',
onClick: this.cloneUser
}, {
name: 'Delete',
description: 'Delete this person',
icon: 'trash',
color: 'danger',
onClick: this.deleteUser
}] : [{
name: 'Delete',
type: 'icon',
description: 'Delete this person',
icon: 'trash',
color: 'danger',
onClick: this.deleteUser
}]
actions
}];

const pagination = {
Expand Down Expand Up @@ -219,6 +270,13 @@ export class Table extends Component {
onChange={this.toggleMultiAction}
/>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiSwitch
label="Custom Actions"
checked={this.state.customAction}
onChange={this.toggleCustomAction}
/>
</EuiFlexItem>
</EuiFlexGroup>

<EuiSpacer size="l" />
Expand Down
Loading