Skip to content

Commit

Permalink
Cleanup and Jest test updates
Browse files Browse the repository at this point in the history
  • Loading branch information
davismcphee committed Aug 12, 2024
1 parent 13c52f1 commit 2603c14
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 23 deletions.
6 changes: 4 additions & 2 deletions packages/kbn-unified-data-table/src/components/data_table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -697,12 +697,14 @@ export const UnifiedDataTable = ({
[dataView, displayedColumns, shouldPrependTimeFieldColumn]
);

// When columns are modified, reset the last column to auto width if only absolute
// width columns remain, to ensure the columns fill the available grid space
useDeepCompareEffect(() => {
const hasAutowidthColumn = visibleColumns.some(
const hasAutoWidthColumn = visibleColumns.some(
(col) => settings?.columns?.[col]?.width == null
);

if (!hasAutowidthColumn) {
if (!hasAutoWidthColumn) {
onResize?.({ columnId: visibleColumns[visibleColumns.length - 1] });
}
}, [onResize, visibleColumns]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
type EuiDataGridColumn,
type EuiDataGridColumnCellAction,
EuiScreenReaderOnly,
EuiListGroupItemProps,
} from '@elastic/eui';
import { type DataView, DataViewField } from '@kbn/data-views-plugin/public';
import { ToastsStart, IUiSettingsClient } from '@kbn/core/public';
Expand Down Expand Up @@ -145,6 +146,20 @@ function buildEuiGridColumn({
editField &&
dataViewField &&
buildEditFieldButton({ hasEditDataViewPermission, dataView, field: dataViewField, editField });
const resetWidthButton: EuiListGroupItemProps | undefined =
onResize && columnWidth > 0
? {
label: i18n.translate('unifiedDataTable.grid.resetColumnWidthButton', {
defaultMessage: 'Reset width',
}),
iconType: 'refresh',
size: 'xs',
iconProps: { size: 'm' },
onClick: () => {
onResize({ columnId: columnName });
},
}
: undefined;

const columnDisplayName = getColumnDisplayName(
columnName,
Expand Down Expand Up @@ -196,21 +211,7 @@ function buildEuiGridColumn({
showMoveLeft: !defaultColumns,
showMoveRight: !defaultColumns,
additional: [
...(onResize && columnWidth > 0
? [
{
label: i18n.translate('unifiedDataTable.resetWidthColumnLabel', {
defaultMessage: 'Reset width',
}),
iconType: 'refresh',
size: 'xs' as 'xs',
iconProps: { size: 'm' as 'm' },
onClick: () => {
onResize({ columnId: columnName });
},
},
]
: []),
...(resetWidthButton ? [resetWidthButton] : []),
...(columnName === '__source'
? []
: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ describe('getDefaultProfileState', () => {
defaultColumns: ['messsage', 'bytes'],
dataView: dataViewWithTimefieldMock,
esqlQueryColumns: undefined,
records: [],
});
expect(appState).toEqual({
columns: ['message', 'extension', 'bytes'],
Expand All @@ -54,11 +53,13 @@ describe('getDefaultProfileState', () => {
},
defaultColumns: ['messsage', 'bytes'],
dataView: emptyDataView,
esqlQueryColumns: [{ id: '1', name: 'foo', meta: { type: 'string' } }],
records: [],
esqlQueryColumns: [
{ id: '1', name: 'foo', meta: { type: 'string' } },
{ id: '2', name: 'bar', meta: { type: 'string' } },
],
});
expect(appState).toEqual({
columns: ['foo'],
columns: ['foo', 'bar'],
grid: {
columns: {
foo: {
Expand All @@ -79,7 +80,6 @@ describe('getDefaultProfileState', () => {
defaultColumns: [],
dataView: dataViewWithTimefieldMock,
esqlQueryColumns: undefined,
records: [],
});
expect(appState).toEqual({
rowHeight: 3,
Expand All @@ -96,7 +96,6 @@ describe('getDefaultProfileState', () => {
defaultColumns: [],
dataView: dataViewWithTimefieldMock,
esqlQueryColumns: undefined,
records: [],
});
expect(appState).toEqual(undefined);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ export const createContextAwarenessMocks = ({
name: 'foo',
width: 300,
},
{
name: 'bar',
width: 400,
},
],
rowHeight: 3,
})),
Expand Down

0 comments on commit 2603c14

Please sign in to comment.