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

Allow DataGrid's columns popover to optionally not allow hiding and/or reordering #2993

Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 2 additions & 1 deletion src-docs/src/views/datagrid/datagrid_styling_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ const gridSnippet = `<EuiDataGrid
]}
// This can work as a shape.
toolbarVisibility={{
showColumnSelector: false
showStyleSelector: false
showSortSelector: false
showFullScreenSelector: false
// showColumnSelector also takes an object, check the prop docs.
showColumnSelector: false
additionalControls: (
<Fragment>
<EuiButtonEmpty
Expand Down
73 changes: 58 additions & 15 deletions src-docs/src/views/datagrid/styling.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,17 @@ export default class DataGrid extends Component {
},
];

this.allowHideColumnsOptions = [
{
id: 'true',
label: 'True',
},
{
id: 'false',
label: 'False',
},
];

this.showFullScreenSelectorOptions = [
{
id: 'true',
Expand Down Expand Up @@ -212,6 +223,7 @@ export default class DataGrid extends Component {
showSortSelector: true,
showStyleSelector: true,
showColumnSelector: true,
allowHideColumns: true,
showFullScreenSelector: true,
showToolbar: true,
toolbarPropTypeIsBoolean: true,
Expand Down Expand Up @@ -279,6 +291,12 @@ export default class DataGrid extends Component {
});
};

onAllowHideColumnsChange = optionId => {
this.setState({
allowHideColumns: optionId === 'true',
});
};

onShowFullScreenSelectorChange = optionId => {
this.setState({
showFullScreenSelector: optionId === 'true',
Expand Down Expand Up @@ -356,8 +374,18 @@ export default class DataGrid extends Component {
</EuiButton>
);

let showColumnSelector = this.state.showColumnSelector;
if (
this.state.showColumnSelector === true &&
this.state.allowHideColumns === false
) {
showColumnSelector = {
allowHide: false,
};
}

const toolbarVisibilityOptions = {
showColumnSelector: this.state.showColumnSelector,
showColumnSelector: showColumnSelector,
showStyleSelector: this.state.showStyleSelector,
showSortSelector: this.state.showSortSelector,
showFullScreenSelector: this.state.showFullScreenSelector,
Expand Down Expand Up @@ -459,7 +487,7 @@ export default class DataGrid extends Component {
anchorPosition="rightUp"
zIndex={2}
closePopover={this.closeToolbarPopover.bind(this)}>
<div style={{ width: 300 }}>
<div style={{ width: 400 }}>
<EuiFormRow
display="columnCompressed"
label="toolbarVisibility prop">
Expand All @@ -474,19 +502,6 @@ export default class DataGrid extends Component {
</EuiFormRow>
{this.state.toolbarPropTypeIsBoolean === false ? (
<Fragment>
<EuiFormRow
display="columnCompressed"
label="Show column selector">
<EuiButtonGroup
isFullWidth
buttonSize="compressed"
legend="Border"
options={this.showColumnSelectorOptions}
idSelected={this.state.showColumnSelector.toString()}
onChange={this.onShowColumnSelectorChange}
/>
</EuiFormRow>

<EuiFormRow
display="columnCompressed"
label="Show style selector">
Expand Down Expand Up @@ -525,6 +540,34 @@ export default class DataGrid extends Component {
onChange={this.onShowFullScreenSelectorChange}
/>
</EuiFormRow>

<EuiFormRow
display="columnCompressed"
label="Show column selector">
<EuiButtonGroup
isFullWidth
buttonSize="compressed"
legend="Border"
options={this.showColumnSelectorOptions}
idSelected={this.state.showColumnSelector.toString()}
onChange={this.onShowColumnSelectorChange}
/>
</EuiFormRow>
{this.state.showColumnSelector && (
<EuiFormRow
display="columnCompressed"
label="Allow hiding columns"
style={{ marginLeft: 32 }}>
<EuiButtonGroup
isFullWidth
buttonSize="compressed"
legend="Border"
options={this.allowHideColumnsOptions}
idSelected={this.state.allowHideColumns.toString()}
onChange={this.onAllowHideColumnsChange}
/>
</EuiFormRow>
)}
</Fragment>
) : (
<EuiFormRow display="columnCompressed" label="Show toolbar">
Expand Down
16 changes: 8 additions & 8 deletions src/components/datagrid/__snapshots__/data_grid.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,12 @@ Array [
<div
aria-hidden="true"
class="euiButtonEmpty__icon"
data-euiicon-type="eyeClosed"
data-euiicon-type="listAdd"
/>
<span
class="euiButtonEmpty__text"
>
Hide fields
Columns
</span>
</span>
</button>
Expand Down Expand Up @@ -713,12 +713,12 @@ Array [
<div
aria-hidden="true"
class="euiButtonEmpty__icon"
data-euiicon-type="eyeClosed"
data-euiicon-type="listAdd"
/>
<span
class="euiButtonEmpty__text"
>
Hide fields
Columns
</span>
</span>
</button>
Expand Down Expand Up @@ -1430,12 +1430,12 @@ Array [
<div
aria-hidden="true"
class="euiButtonEmpty__icon"
data-euiicon-type="eyeClosed"
data-euiicon-type="listAdd"
/>
<span
class="euiButtonEmpty__text"
>
Hide fields
Columns
</span>
</span>
</button>
Expand Down Expand Up @@ -1951,12 +1951,12 @@ Array [
<div
aria-hidden="true"
class="euiButtonEmpty__icon"
data-euiicon-type="eyeClosed"
data-euiicon-type="listAdd"
/>
<span
class="euiButtonEmpty__text"
>
Hide fields
Columns
</span>
</span>
</button>
Expand Down
4 changes: 4 additions & 0 deletions src/components/datagrid/_data_grid_column_selector.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
margin: 0 (-$euiSizeS);
}

.euiDataGridColumnSelector__itemLabel {
@include euiFontSizeXS;
}

.euiDataGridColumnSelectorPopover {
// Hack because the fixed positions of drag and drop don't work inside of transformed elements
// sass-lint:disable-block no-important
Expand Down
Loading