Skip to content

Commit

Permalink
[Bug][Investigations] - Fix timeline column reset (#188240)
Browse files Browse the repository at this point in the history
## Summary

**Bug:**
Within the new timeline, we have default columns that show whenever an
empty array for columns are provided.
This was causing columns to re-appear in the `Selected fields` section
even though the columns were not actually selected anymore leading to
mismatched state between the browser ui and the table preventing the
default columns from being removed again without page refresh. _The old
timeline table is not affected_.



https://github.com/user-attachments/assets/7d16b8c3-be1a-4bc7-87b0-62fcac563f15



**Fix:**
The logic used to default an empty array of columns to the default
timeline columns has been updated to allow the empty array to be passed.
With the old timeline experience this just means all columns _can_ be
removed and you'd see an empty table, but with the new unified table
(which will be the default in 8.15 after


https://github.com/user-attachments/assets/e5fbaf48-77e3-4363-8232-35d256729b7e
  • Loading branch information
michaelolo24 authored Jul 15, 2024
1 parent e606497 commit 385884d
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 229 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2117,7 +2117,7 @@ export const defaultTimelineProps: CreateTimelineProps = {
savedSearch: null,
isDataProviderVisible: false,
sampleSize: 500,
rowHeight: 1,
rowHeight: 3,
},
to: '2018-11-05T19:03:25.937Z',
notes: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ describe('alert actions', () => {
savedSearchId: null,
savedSearch: null,
isDataProviderVisible: false,
rowHeight: 1,
rowHeight: 3,
sampleSize: 500,
},
to: '2018-11-05T19:03:25.937Z',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe('UnifiedTimelineBody', () => {

expect(MockUnifiedTimelineComponent).toHaveBeenLastCalledWith(
expect.objectContaining({
columns: defaultUdtHeaders,
columns: [],
}),
{}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import type { ComponentProps, ReactElement } from 'react';
import React, { useEffect, useState, useMemo } from 'react';
import { RootDragDropProvider } from '@kbn/dom-drag-drop';
import { isEmpty } from 'lodash';
import { StyledTableFlexGroup, StyledUnifiedTableFlexItem } from '../unified_components/styles';
import { UnifiedTimeline } from '../unified_components';
import { defaultUdtHeaders } from '../unified_components/default_headers';
Expand Down Expand Up @@ -59,9 +58,7 @@ export const UnifiedTimelineBody = (props: UnifiedTimelineBodyProps) => {
});
}, [events, pageInfo.activePage]);

const columnsHeader = useMemo(() => {
return isEmpty(columns) ? defaultUdtHeaders : columns;
}, [columns]);
const columnsHeader = useMemo(() => columns ?? defaultUdtHeaders, [columns]);

return (
<StyledTableFlexGroup direction="column" gutterSize="s">
Expand Down

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 @@ -55,15 +55,15 @@ describe('useTimelineColumns', () => {
const { result } = renderHook(() => useTimelineColumns([]), {
wrapper: TestProviders,
});
expect(result.current.localColumns).toEqual(defaultHeaders);
expect(result.current.localColumns).toEqual([]);
});

it('should return the default unified data table (udt) columns', () => {
useIsExperimentalFeatureEnabledMock.mockReturnValue(false);
const { result } = renderHook(() => useTimelineColumns([]), {
wrapper: TestProviders,
});
expect(result.current.localColumns).toEqual(defaultUdtHeaders);
expect(result.current.localColumns).toEqual([]);
});

it('should return the provided columns', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 2.0.
*/

import { isEmpty } from 'lodash/fp';
import { useMemo } from 'react';
import { SourcererScopeName } from '../../../../../sourcerer/store/model';
import { useSourcererDataView } from '../../../../../sourcerer/containers';
Expand All @@ -28,10 +27,7 @@ export const useTimelineColumns = (columns: ColumnHeaderOptions[]) => {
[unifiedComponentsInTimelineDisabled]
);

const localColumns = useMemo(
() => (isEmpty(columns) ? defaultColumns : columns),
[columns, defaultColumns]
);
const localColumns = useMemo(() => columns ?? defaultColumns, [columns, defaultColumns]);

const augmentedColumnHeaders = memoizedGetTimelineColumnHeaders(
localColumns,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const timelineDefaults: SubsetTimelineModel &
savedSearch: null,
isDataProviderVisible: false,
sampleSize: 500,
rowHeight: 1,
rowHeight: 3,
};

export const getTimelineManageDefaults = (id: string) => ({
Expand Down

0 comments on commit 385884d

Please sign in to comment.