forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ES|QL] [Discover] Keeps the preferred chart configuration when possi…
…ble (elastic#197453) ## Summary Closes elastic#184631 It keeps the chart configuration when the user is doing actions compatible with the current query such as: - Adding a where filter (by clicking the table, the sidebar, the chart) - Changes the breakdown field and the field type is compatible with the current chart - Changing to a compatible chart type (from example from bar to line or pie to treemap) - Changing the query that doesnt affect the generated columns mapped to a chart. For example adding a limit or creating a runtime field etc. The logic depends on the suggestions. If the suggestions return the preferred chart type, then we are going to use this. So it really depends on the api and the type / number of columns. It is as smarter as it can in order to not create bugs. I am quite happy with the result. It is much better than what we have so far. ![meow](https://github.com/user-attachments/assets/c4249e5e-e785-4e57-8651-d1f660f5a61a) ### Next steps I would love to do the same on the dahsboard too, needs more time though. But the changes made here will def work in favor ### Checklist - [x] [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 - [x] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed --------- Co-authored-by: Marta Bondyra <[email protected]> (cherry picked from commit ccbcab9)
- Loading branch information
Showing
16 changed files
with
858 additions
and
81 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
export const getDatasourceId = (datasourceStates: Record<string, unknown>) => { | ||
const datasourceId: 'formBased' | 'textBased' | undefined = [ | ||
'formBased' as const, | ||
'textBased' as const, | ||
].find((key) => Boolean(datasourceStates[key])); | ||
|
||
return datasourceId; | ||
}; |
32 changes: 32 additions & 0 deletions
32
packages/kbn-visualization-utils/src/map_vis_to_chart_type.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,32 @@ | ||
/* | ||
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
import { ChartType, LensVisualizationType } from './types'; | ||
|
||
type ValueOf<T> = T[keyof T]; | ||
type LensToChartMap = { | ||
[K in ValueOf<typeof LensVisualizationType>]: ChartType; | ||
}; | ||
const lensTypesToChartTypes: LensToChartMap = { | ||
[LensVisualizationType.XY]: ChartType.XY, | ||
[LensVisualizationType.Metric]: ChartType.Metric, | ||
[LensVisualizationType.LegacyMetric]: ChartType.Metric, | ||
[LensVisualizationType.Pie]: ChartType.Pie, | ||
[LensVisualizationType.Heatmap]: ChartType.Heatmap, | ||
[LensVisualizationType.Gauge]: ChartType.Gauge, | ||
[LensVisualizationType.Datatable]: ChartType.Table, | ||
}; | ||
function isLensVisualizationType(value: string): value is LensVisualizationType { | ||
return Object.values(LensVisualizationType).includes(value as LensVisualizationType); | ||
} | ||
export const mapVisToChartType = (visualizationType: string) => { | ||
if (isLensVisualizationType(visualizationType)) { | ||
return lensTypesToChartTypes[visualizationType]; | ||
} | ||
}; |
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
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
Oops, something went wrong.