From a581087f530ce4a9143d54d76147b7b645a39da4 Mon Sep 17 00:00:00 2001 From: Stratoula Kalafateli Date: Mon, 16 Sep 2024 12:03:58 +0200 Subject: [PATCH] [ES|QL] Enable cursor sync for timeseries charts (#192837) ## Summary Syncs the cursor for timeseries charts powered by ES|QL ![meow](https://github.com/user-attachments/assets/62664b27-ce95-493d-863a-b5ecaa8006ed) ### Checklist - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Marco Vettorello --- .../active_cursor/active_cursor_utils.test.ts | 33 +++++++++++++++++++ .../active_cursor/active_cursor_utils.ts | 11 +++++++ src/plugins/charts/tsconfig.json | 1 + 3 files changed, 45 insertions(+) diff --git a/src/plugins/charts/public/services/active_cursor/active_cursor_utils.test.ts b/src/plugins/charts/public/services/active_cursor/active_cursor_utils.test.ts index 31f139eb41a4f6..65b6ac7c408eeb 100644 --- a/src/plugins/charts/public/services/active_cursor/active_cursor_utils.test.ts +++ b/src/plugins/charts/public/services/active_cursor/active_cursor_utils.test.ts @@ -137,6 +137,39 @@ describe('active_cursor_utils', () => { } `); }); + + test('should return isDateHistogram true in case the datatable is powered by ES|QL', () => { + expect( + parseSyncOptions({ + datatables: [ + { + columns: [ + { + id: 'timestamp', + meta: { + type: 'date', + }, + }, + { + id: 'count', + meta: { + type: 'number', + }, + }, + ], + meta: { + type: 'es_ql', + }, + }, + ] as unknown as Datatable[], + }) + ).toMatchInlineSnapshot(` + Object { + "accessors": Array [], + "isDateHistogram": true, + } + `); + }); }); }); }); diff --git a/src/plugins/charts/public/services/active_cursor/active_cursor_utils.ts b/src/plugins/charts/public/services/active_cursor/active_cursor_utils.ts index c2126e5efdc2bf..8c7fd434a5c08d 100644 --- a/src/plugins/charts/public/services/active_cursor/active_cursor_utils.ts +++ b/src/plugins/charts/public/services/active_cursor/active_cursor_utils.ts @@ -10,6 +10,7 @@ import { uniq } from 'lodash'; import type { Datatable } from '@kbn/expressions-plugin/public'; +import { ESQL_TABLE_TYPE } from '@kbn/data-plugin/common'; import type { ActiveCursorSyncOption, DateHistogramSyncOption } from './types'; import type { ActiveCursorPayload } from './types'; @@ -20,6 +21,16 @@ function isDateHistogramSyncOption( } const parseDatatable = (dataTables: Datatable[]) => { + const isEsqlMode = dataTables.some((t) => t?.meta?.type === ESQL_TABLE_TYPE); + + if (isEsqlMode) { + return { + isDateHistogram: + Boolean(dataTables.length) && + dataTables.every((t) => t.columns.some((c) => c.meta.type === 'date')), + accessors: [], + }; + } const isDateHistogram = Boolean(dataTables.length) && dataTables.every((dataTable) => diff --git a/src/plugins/charts/tsconfig.json b/src/plugins/charts/tsconfig.json index 42bbe987f45fa0..8ad33a85170311 100644 --- a/src/plugins/charts/tsconfig.json +++ b/src/plugins/charts/tsconfig.json @@ -15,6 +15,7 @@ "@kbn/ui-theme", "@kbn/shared-ux-utility", "@kbn/config-schema", + "@kbn/data-plugin", ], "exclude": [ "target/**/*",