Skip to content

Commit

Permalink
Provides context to spaces grid action buttons (#27911)
Browse files Browse the repository at this point in the history
## Summary
Fixes #27744

cc @elastic/eui-design -- It appears that the [`DefaultItemAction`](https://elastic.github.io/eui/#/display/tables) can only accept hard-coded `name`/`description` values. While this isn't necessarily a bad thing, I'm wondering if the linked issue (#27744) will be a common enough occurrence within Kibana to make the DefaultItemAction less useful. What do you think about allowing functions for the `name` and `description` fields, so that they can get access to the row's record, and provide context as necessary?
  • Loading branch information
legrego authored Jan 3, 2019
1 parent dcc01f7 commit 36d0f4a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,11 @@ exports[`SpacesGridPage renders as expected 1`] = `
Object {
"actions": Array [
Object {
"color": "primary",
"description": "Edit this space.",
"icon": "pencil",
"name": "Edit",
"onClick": [Function],
"type": "icon",
"render": [Function],
},
Object {
"available": [Function],
"color": "danger",
"description": "Delete this space.",
"icon": "trash",
"name": "Delete",
"onClick": [Function],
"type": "icon",
"render": [Function],
},
],
"name": "Actions",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import React, { Component, Fragment } from 'react';

import {
EuiButton,
EuiButtonIcon,
EuiFlexGroup,
EuiFlexItem,
// @ts-ignore
Expand Down Expand Up @@ -306,33 +307,45 @@ class SpacesGridPageUI extends Component<Props, State> {
}),
actions: [
{
name: intl.formatMessage({
id: 'xpack.spaces.management.spacesGridPage.editSpaceActionName',
defaultMessage: 'Edit',
}),
description: intl.formatMessage({
id: 'xpack.spaces.management.spacesGridPage.editSpaceActionDescription',
defaultMessage: 'Edit this space.',
}),
onClick: this.onEditSpaceClick,
type: 'icon',
icon: 'pencil',
color: 'primary',
render: (record: Space) => {
return (
<EuiButtonIcon
aria-label={intl.formatMessage(
{
id: 'xpack.spaces.management.spacesGridPage.editSpaceActionName',
defaultMessage: `Edit {spaceName}.`,
},
{
spaceName: record.name,
}
)}
color={'primary'}
iconType={'pencil'}
onClick={() => this.onEditSpaceClick(record)}
/>
);
},
},
{
available: (record: Space) => !isReservedSpace(record),
name: intl.formatMessage({
id: 'xpack.spaces.management.spacesGridPage.deleteActionName',
defaultMessage: 'Delete',
}),
description: intl.formatMessage({
id: 'xpack.spaces.management.spacesGridPage.deleteThisSpaceActionDescription',
defaultMessage: 'Delete this space.',
}),
onClick: this.onDeleteSpaceClick,
type: 'icon',
icon: 'trash',
color: 'danger',
render: (record: Space) => {
return (
<EuiButtonIcon
aria-label={intl.formatMessage(
{
id: 'xpack.spaces.management.spacesGridPage.deleteActionName',
defaultMessage: `Delete {spaceName}.`,
},
{
spaceName: record.name,
}
)}
color={'danger'}
iconType={'trash'}
onClick={() => this.onDeleteSpaceClick(record)}
/>
);
},
},
],
},
Expand Down

0 comments on commit 36d0f4a

Please sign in to comment.