From 8f01c22296f540329b05938f16c4699bcd360302 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Mon, 16 Sep 2024 22:21:49 +1000 Subject: [PATCH] [8.x] [ES|QL] Enable cursor sync for timeseries charts (#192837) (#192982) # Backport This will backport the following commits from `main` to `8.x`: - [[ES|QL] Enable cursor sync for timeseries charts (#192837)](https://github.com/elastic/kibana/pull/192837) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Stratoula Kalafateli --- .../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 31f139eb41a4f..65b6ac7c408ee 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 c2126e5efdc2b..8c7fd434a5c08 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 42bbe987f45fa..8ad33a8517031 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/**/*",