-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Lens] Synchronize cursor position for X-axis across all Lens visuali…
…zations in a dashboard (#106845) (#107691) * [Lens] Synchronize cursor position for X-axis across all Lens visualizations in a dashboard Closes: #77530 * add mocks for active_cursor service * fix jest tests * fix jest tests * apply PR comments * fix cursor style * update heatmap, jest * add tests * fix wrong import * replace cursor for timelion * update tsvb_dashboard baseline * fix CI * update baseline * Update active_cursor_utils.ts * add debounce * remove cursor from heatmap and pie * add tests for debounce * return theme order back Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
98a66ed
commit 602e26b
Showing
31 changed files
with
657 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/plugins/charts/public/services/active_cursor/active_cursor.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { ActiveCursor } from './active_cursor'; | ||
|
||
describe('ActiveCursor', () => { | ||
let activeCursor: ActiveCursor; | ||
|
||
beforeEach(() => { | ||
activeCursor = new ActiveCursor(); | ||
}); | ||
|
||
test('should initialize activeCursor$ stream on setup hook', () => { | ||
expect(activeCursor.activeCursor$).toBeUndefined(); | ||
|
||
activeCursor.setup(); | ||
|
||
expect(activeCursor.activeCursor$).toMatchInlineSnapshot(` | ||
Subject { | ||
"_isScalar": false, | ||
"closed": false, | ||
"hasError": false, | ||
"isStopped": false, | ||
"observers": Array [], | ||
"thrownError": null, | ||
} | ||
`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
src/plugins/charts/public/services/active_cursor/active_cursor_utils.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { parseSyncOptions } from './active_cursor_utils'; | ||
import type { Datatable } from '../../../../expressions/public'; | ||
|
||
describe('active_cursor_utils', () => { | ||
describe('parseSyncOptions', () => { | ||
describe('dateHistogramSyncOption', () => { | ||
test('should return isDateHistogram true in case if that mode is active', () => { | ||
expect(parseSyncOptions({ isDateHistogram: true })).toMatchInlineSnapshot(` | ||
Object { | ||
"isDateHistogram": true, | ||
} | ||
`); | ||
}); | ||
|
||
test('should return isDateHistogram false for other cases', () => { | ||
expect(parseSyncOptions({ datatables: [] as Datatable[] })).toMatchInlineSnapshot(` | ||
Object { | ||
"accessors": Array [], | ||
"isDateHistogram": false, | ||
} | ||
`); | ||
}); | ||
}); | ||
|
||
describe('datatablesSyncOption', () => { | ||
test('should extract accessors', () => { | ||
expect( | ||
parseSyncOptions({ | ||
datatables: ([ | ||
{ | ||
columns: [ | ||
{ | ||
meta: { | ||
index: 'foo_index', | ||
field: 'foo_field', | ||
}, | ||
}, | ||
], | ||
}, | ||
] as unknown) as Datatable[], | ||
}).accessors | ||
).toMatchInlineSnapshot(` | ||
Array [ | ||
"foo_index:foo_field", | ||
] | ||
`); | ||
}); | ||
|
||
test('should return isDateHistogram true in case all datatables is time based', () => { | ||
expect( | ||
parseSyncOptions({ | ||
datatables: ([ | ||
{ | ||
columns: [ | ||
{ | ||
meta: { | ||
index: 'foo_index', | ||
field: 'foo_field', | ||
sourceParams: { | ||
appliedTimeRange: {}, | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
{ | ||
columns: [ | ||
{ | ||
meta: { | ||
index: 'foo_index1', | ||
field: 'foo_field1', | ||
sourceParams: { | ||
appliedTimeRange: {}, | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
] as unknown) as Datatable[], | ||
}) | ||
).toMatchInlineSnapshot(` | ||
Object { | ||
"accessors": Array [ | ||
"foo_index:foo_field", | ||
"foo_index1:foo_field1", | ||
], | ||
"isDateHistogram": true, | ||
} | ||
`); | ||
}); | ||
|
||
test('should return isDateHistogram false in case of not all datatables is time based', () => { | ||
expect( | ||
parseSyncOptions({ | ||
datatables: ([ | ||
{ | ||
columns: [ | ||
{ | ||
meta: { | ||
index: 'foo_index', | ||
field: 'foo_field', | ||
sourceParams: { | ||
appliedTimeRange: {}, | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
{ | ||
columns: [ | ||
{ | ||
meta: { | ||
index: 'foo_index1', | ||
field: 'foo_field1', | ||
}, | ||
}, | ||
], | ||
}, | ||
] as unknown) as Datatable[], | ||
}) | ||
).toMatchInlineSnapshot(` | ||
Object { | ||
"accessors": Array [ | ||
"foo_index:foo_field", | ||
"foo_index1:foo_field1", | ||
], | ||
"isDateHistogram": false, | ||
} | ||
`); | ||
}); | ||
}); | ||
}); | ||
}); |
49 changes: 49 additions & 0 deletions
49
src/plugins/charts/public/services/active_cursor/active_cursor_utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
import { uniq } from 'lodash'; | ||
|
||
import type { Datatable } from '../../../../expressions/public'; | ||
import type { ActiveCursorSyncOption, DateHistogramSyncOption } from './types'; | ||
import type { ActiveCursorPayload } from './types'; | ||
|
||
function isDateHistogramSyncOption( | ||
syncOption?: ActiveCursorSyncOption | ||
): syncOption is DateHistogramSyncOption { | ||
return Boolean(syncOption && 'isDateHistogram' in syncOption); | ||
} | ||
|
||
const parseDatatable = (dataTables: Datatable[]) => { | ||
const isDateHistogram = | ||
Boolean(dataTables.length) && | ||
dataTables.every((dataTable) => | ||
dataTable.columns.some((c) => Boolean(c.meta.sourceParams?.appliedTimeRange)) | ||
); | ||
|
||
const accessors = uniq( | ||
dataTables | ||
.map((dataTable) => { | ||
const column = dataTable.columns.find((c) => c.meta.index && c.meta.field); | ||
|
||
if (column?.meta.index) { | ||
return `${column.meta.index}:${column.meta.field}`; | ||
} | ||
}) | ||
.filter(Boolean) as string[] | ||
); | ||
return { isDateHistogram, accessors }; | ||
}; | ||
|
||
/** @internal **/ | ||
export const parseSyncOptions = ( | ||
syncOptions: ActiveCursorSyncOption | ||
): Partial<ActiveCursorPayload> => | ||
isDateHistogramSyncOption(syncOptions) | ||
? { | ||
isDateHistogram: syncOptions.isDateHistogram, | ||
} | ||
: parseDatatable(syncOptions.datatables); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import type { ActiveCursor } from './active_cursor'; | ||
|
||
export const activeCursorMock: ActiveCursor = { | ||
activeCursor$: { | ||
subscribe: jest.fn(), | ||
pipe: jest.fn(() => ({ | ||
subscribe: jest.fn(), | ||
})), | ||
}, | ||
setup: jest.fn(), | ||
} as any; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import type { PointerEvent } from '@elastic/charts'; | ||
import type { Datatable } from '../../../../expressions/public'; | ||
|
||
/** @public **/ | ||
export type ActiveCursorSyncOption = DateHistogramSyncOption | DatatablesSyncOption; | ||
|
||
/** @internal **/ | ||
export interface ActiveCursorPayload { | ||
cursor: PointerEvent; | ||
isDateHistogram?: boolean; | ||
accessors?: string[]; | ||
} | ||
|
||
/** @internal **/ | ||
interface BaseSyncOptions { | ||
debounce?: number; | ||
} | ||
|
||
/** @internal **/ | ||
export interface DateHistogramSyncOption extends BaseSyncOptions { | ||
isDateHistogram: boolean; | ||
} | ||
|
||
/** @internal **/ | ||
export interface DatatablesSyncOption extends BaseSyncOptions { | ||
datatables: Datatable[]; | ||
} |
Oops, something went wrong.