Skip to content

Commit

Permalink
[Lens] Add reset and hide actions to columns on dashboard (elastic#10…
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 authored and John Dorlus committed Jun 15, 2021
1 parent 1fedbae commit dfda2de
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 28 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -152,31 +152,33 @@ export const createGridColumns = (

const additionalActions: EuiListGroupItemProps[] = [];

if (!isReadOnly) {
additionalActions.push({
color: 'text',
size: 'xs',
onClick: () => onColumnResize({ columnId: originalColumnId || field, width: undefined }),
iconType: 'empty',
label: i18n.translate('xpack.lens.table.resize.reset', {
defaultMessage: 'Reset width',
}),
'data-test-subj': 'lensDatatableResetWidth',
isDisabled: initialWidth == null,
});
if (!isTransposed) {
additionalActions.push({
color: 'text',
size: 'xs',
onClick: () => onColumnResize({ columnId: originalColumnId || field, width: undefined }),
iconType: 'empty',
label: i18n.translate('xpack.lens.table.resize.reset', {
defaultMessage: 'Reset width',
onClick: () => onColumnHide({ columnId: originalColumnId || field }),
iconType: 'eyeClosed',
label: i18n.translate('xpack.lens.table.hide.hideLabel', {
defaultMessage: 'Hide',
}),
'data-test-subj': 'lensDatatableResetWidth',
isDisabled: initialWidth == null,
'data-test-subj': 'lensDatatableHide',
isDisabled: !isHidden && visibleColumns.length <= 1,
});
if (!isTransposed) {
additionalActions.push({
color: 'text',
size: 'xs',
onClick: () => onColumnHide({ columnId: originalColumnId || field }),
iconType: 'eyeClosed',
label: i18n.translate('xpack.lens.table.hide.hideLabel', {
defaultMessage: 'Hide',
}),
'data-test-subj': 'lensDatatableHide',
isDisabled: !isHidden && visibleColumns.length <= 1,
});
} else if (columnArgs?.bucketValues) {
}

if (!isReadOnly) {
if (isTransposed && columnArgs?.bucketValues) {
const bucketValues = columnArgs?.bucketValues;
additionalActions.push({
color: 'text',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe('DatatableComponent', () => {
).toMatchSnapshot();
});

test('it should not render actions on header when it is in read only mode', () => {
test('it should render hide and reset actions on header even when it is in read only mode', () => {
const { data, args } = sampleArgs();

expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,13 @@ export const DatatableComponent = (props: DatatableRenderProps) => {
[formatters, columnConfig, props.uiSettings]
);

const columnVisibility = useMemo(() => ({ visibleColumns, setVisibleColumns: () => {} }), [
visibleColumns,
]);
const columnVisibility = useMemo(
() => ({
visibleColumns,
setVisibleColumns: () => {},
}),
[visibleColumns]
);

const sorting = useMemo<EuiDataGridSorting>(
() => createGridSortingConfig(sortBy, sortDirection as LensGridDirection, onEditAction),
Expand Down

0 comments on commit dfda2de

Please sign in to comment.