Skip to content

Commit

Permalink
[Security Solution] Fix sorting on unmapped fields in Timeline Events… (
Browse files Browse the repository at this point in the history
elastic#87241)

* [Security Solution] Fix sorting on unmapped fields in Timeline Events table

* set unmapped_type to the column type

* add missing types

* Update saved_object_mappings.ts

Co-authored-by: Xavier Mouligneau <[email protected]>
  • Loading branch information
patrykkopycinski and XavierM committed Jan 12, 2021
1 parent d1b3d09 commit db9c926
Show file tree
Hide file tree
Showing 36 changed files with 121 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ export interface TimelineRequestBasicOptions extends IEsSearchRequest {
factoryQueryType?: TimelineFactoryQueryTypes;
}

export interface TimelineRequestSortField<Field = string> extends SortField<Field> {
type: string;
}

export interface TimelineRequestOptionsPaginated<Field = string>
extends TimelineRequestBasicOptions {
pagination: Pick<PaginationInputPaginated, 'activePage' | 'querySize'>;
sort: Array<SortField<Field>>;
sort: Array<TimelineRequestSortField<Field>>;
}

export type TimelineStrategyResponseType<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ const SavedFavoriteRuntimeType = runtimeTypes.partial({

const SavedSortObject = runtimeTypes.partial({
columnId: unionWithNullType(runtimeTypes.string),
columnType: unionWithNullType(runtimeTypes.string),
sortDirection: unionWithNullType(runtimeTypes.string),
});
const SavedSortRuntimeType = runtimeTypes.union([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ const eventsViewerDefaultProps = {
sort: [
{
columnId: 'foo',
columnType: 'number',
sortDirection: 'asc' as SortDirection,
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,9 @@ const EventsViewerComponent: React.FC<Props> = ({

const sortField = useMemo(
() =>
sort.map(({ columnId, sortDirection }) => ({
sort.map(({ columnId, columnType, sortDirection }) => ({
field: columnId,
type: columnType,
direction: sortDirection as Direction,
})),
[sort]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ SecuritySolutionAppWrapper.displayName = 'SecuritySolutionAppWrapper';
and `EuiPopover`, `EuiToolTip` global styles
*/
export const AppGlobalStyle = createGlobalStyle<{ theme: { eui: { euiColorPrimary: string } } }>`
// fixes double scrollbar on views with EventsTable
#kibana-body {
overflow: hidden;
}
div.app-wrapper {
background-color: rgba(0,0,0,0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export const mockGlobalState: State = {
pinnedEventIds: {},
pinnedEventsSaveObject: {},
itemsPerPageOptions: [5, 10, 20],
sort: [{ columnId: '@timestamp', sortDirection: Direction.desc }],
sort: [{ columnId: '@timestamp', columnType: 'number', sortDirection: Direction.desc }],
isSaving: false,
version: null,
status: TimelineStatus.active,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2150,6 +2150,7 @@ export const mockTimelineModel: TimelineModel = {
sort: [
{
columnId: '@timestamp',
columnType: 'number',
sortDirection: Direction.desc,
},
],
Expand Down Expand Up @@ -2184,7 +2185,7 @@ export const mockTimelineResult: TimelineResult = {
templateTimelineId: null,
templateTimelineVersion: null,
savedQueryId: null,
sort: [{ columnId: '@timestamp', sortDirection: 'desc' }],
sort: [{ columnId: '@timestamp', columnType: 'number', sortDirection: 'desc' }],
version: '1',
};

Expand All @@ -2202,7 +2203,7 @@ export const defaultTimelineProps: CreateTimelineProps = {
timeline: {
activeTab: TimelineTabs.query,
columns: [
{ columnHeaderType: 'not-filtered', id: '@timestamp', width: 190 },
{ columnHeaderType: 'not-filtered', id: '@timestamp', type: 'number', width: 190 },
{ columnHeaderType: 'not-filtered', id: 'message', width: 180 },
{ columnHeaderType: 'not-filtered', id: 'event.category', width: 180 },
{ columnHeaderType: 'not-filtered', id: 'event.action', width: 180 },
Expand Down Expand Up @@ -2254,7 +2255,7 @@ export const defaultTimelineProps: CreateTimelineProps = {
selectedEventIds: {},
show: false,
showCheckboxes: false,
sort: [{ columnId: '@timestamp', sortDirection: Direction.desc }],
sort: [{ columnId: '@timestamp', columnType: 'number', sortDirection: Direction.desc }],
status: TimelineStatus.draft,
title: '',
timelineType: TimelineType.default,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ describe('alert actions', () => {
{
columnHeaderType: 'not-filtered',
id: '@timestamp',
type: 'number',
width: 190,
},
{
Expand Down Expand Up @@ -207,6 +208,7 @@ describe('alert actions', () => {
sort: [
{
columnId: '@timestamp',
columnType: 'number',
sortDirection: 'desc',
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export const mockTimeline = {
savedQueryId: null,
sort: {
columnId: '@timestamp',
columnType: 'number',
sortDirection: 'desc',
__typename: 'SortTimelineResult',
},
Expand Down Expand Up @@ -403,6 +404,7 @@ export const mockTemplate = {
savedQueryId: null,
sort: {
columnId: '@timestamp',
columnType: 'number',
sortDirection: 'desc',
__typename: 'SortTimelineResult',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ describe('helpers', () => {
{
columnHeaderType: 'not-filtered',
id: '@timestamp',
type: 'number',
width: 190,
},
{
Expand Down Expand Up @@ -319,6 +320,7 @@ describe('helpers', () => {
sort: [
{
columnId: '@timestamp',
columnType: 'number',
sortDirection: 'desc',
},
],
Expand Down Expand Up @@ -347,6 +349,7 @@ describe('helpers', () => {
{
columnHeaderType: 'not-filtered',
id: '@timestamp',
type: 'number',
width: 190,
},
{
Expand Down Expand Up @@ -420,6 +423,7 @@ describe('helpers', () => {
sort: [
{
columnId: '@timestamp',
columnType: 'number',
sortDirection: 'desc',
},
],
Expand Down Expand Up @@ -448,6 +452,7 @@ describe('helpers', () => {
{
columnHeaderType: 'not-filtered',
id: '@timestamp',
type: 'number',
width: 190,
},
{
Expand Down Expand Up @@ -521,6 +526,7 @@ describe('helpers', () => {
sort: [
{
columnId: '@timestamp',
columnType: 'number',
sortDirection: 'desc',
},
],
Expand All @@ -547,6 +553,7 @@ describe('helpers', () => {
{
columnHeaderType: 'not-filtered',
id: '@timestamp',
type: 'number',
width: 190,
},
{
Expand Down Expand Up @@ -620,6 +627,7 @@ describe('helpers', () => {
sort: [
{
columnId: '@timestamp',
columnType: 'number',
sortDirection: 'desc',
},
],
Expand Down Expand Up @@ -652,7 +660,7 @@ describe('helpers', () => {
example: undefined,
id: '@timestamp',
placeholder: undefined,
type: undefined,
type: 'number',
width: 190,
},
{
Expand Down Expand Up @@ -760,6 +768,7 @@ describe('helpers', () => {
sort: [
{
columnId: '@timestamp',
columnType: 'number',
sortDirection: 'desc',
},
],
Expand Down Expand Up @@ -815,6 +824,7 @@ describe('helpers', () => {
{
columnHeaderType: 'not-filtered',
id: '@timestamp',
type: 'number',
width: 190,
},
{
Expand Down Expand Up @@ -929,6 +939,7 @@ describe('helpers', () => {
sort: [
{
columnId: '@timestamp',
columnType: 'number',
sortDirection: 'desc',
},
],
Expand All @@ -953,6 +964,7 @@ describe('helpers', () => {
{
columnHeaderType: 'not-filtered',
id: '@timestamp',
type: 'number',
width: 190,
},
{
Expand Down Expand Up @@ -1026,6 +1038,7 @@ describe('helpers', () => {
sort: [
{
columnId: '@timestamp',
columnType: 'number',
sortDirection: 'desc',
},
],
Expand Down Expand Up @@ -1054,6 +1067,7 @@ describe('helpers', () => {
{
columnHeaderType: 'not-filtered',
id: '@timestamp',
type: 'number',
width: 190,
},
{
Expand Down Expand Up @@ -1127,6 +1141,7 @@ describe('helpers', () => {
sort: [
{
columnId: '@timestamp',
columnType: 'number',
sortDirection: 'desc',
},
],
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 @@ -13,6 +13,7 @@ export const defaultHeaders: ColumnHeaderOptions[] = [
{
columnHeaderType: defaultColumnHeaderType,
id: '@timestamp',
type: 'number',
width: DEFAULT_DATE_COLUMN_MIN_WIDTH,
},
{
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 @@ -35,6 +35,7 @@ describe('Header', () => {
const sort: Sort[] = [
{
columnId: columnHeader.id,
columnType: columnHeader.type ?? 'number',
sortDirection: Direction.desc,
},
];
Expand Down Expand Up @@ -124,6 +125,7 @@ describe('Header', () => {
sort: [
{
columnId: columnHeader.id,
columnType: columnHeader.type ?? 'number',
sortDirection: Direction.asc, // (because the previous state was Direction.desc)
},
],
Expand Down Expand Up @@ -191,6 +193,7 @@ describe('Header', () => {
const nonMatching: Sort[] = [
{
columnId: 'differentSocks',
columnType: columnHeader.type ?? 'number',
sortDirection: Direction.desc,
},
];
Expand All @@ -201,14 +204,19 @@ describe('Header', () => {

describe('getNextSortDirection', () => {
test('it returns "asc" when the current direction is "desc"', () => {
const sortDescending: Sort = { columnId: columnHeader.id, sortDirection: Direction.desc };
const sortDescending: Sort = {
columnId: columnHeader.id,
columnType: columnHeader.type ?? 'number',
sortDirection: Direction.desc,
};

expect(getNextSortDirection(sortDescending)).toEqual('asc');
});

test('it returns "desc" when the current direction is "asc"', () => {
const sortAscending: Sort = {
columnId: columnHeader.id,
columnType: columnHeader.type ?? 'number',
sortDirection: Direction.asc,
};

Expand All @@ -218,6 +226,7 @@ describe('Header', () => {
test('it returns "desc" by default', () => {
const sortNone: Sort = {
columnId: columnHeader.id,
columnType: columnHeader.type ?? 'number',
sortDirection: 'none',
};

Expand All @@ -230,6 +239,7 @@ describe('Header', () => {
const sortMatches: Sort[] = [
{
columnId: columnHeader.id,
columnType: columnHeader.type ?? 'number',
sortDirection: Direction.desc,
},
];
Expand All @@ -246,6 +256,7 @@ describe('Header', () => {
const sortDoesNotMatch: Sort[] = [
{
columnId: 'someOtherColumn',
columnType: columnHeader.type ?? 'number',
sortDirection: 'none',
},
];
Expand Down
Loading

0 comments on commit db9c926

Please sign in to comment.