-
Notifications
You must be signed in to change notification settings - Fork 8.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Obs ai assistant][ESQL] Visualizes a query #173076
Closed
Closed
Changes from 4 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
fbbd917
[Obs ai assistant]['ESQL] Visualize a query
stratoula 21ddc48
Allow saving an ES|QL chart to a dashboard
stratoula b7c3c4d
Better UI
stratoula e4c34fd
In app editing of Lens embeddable
stratoula 1a33e60
Keep the lens input on the conversation, fix saving bug
stratoula 326b0ac
Fixes cancel button
stratoula 2a57a45
Nits
stratoula 619babf
Fetch the embeddable correctly
stratoula d36de16
fix scrollbars
stratoula 3258022
Minor fixes
stratoula b1ac979
Revert small change
stratoula 56a2f0a
Inline editing on the lens function
stratoula 15c7557
Merge with main and resolve conflicts
stratoula File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
99 changes: 99 additions & 0 deletions
99
packages/kbn-visualization-utils/src/get_lens_attributes.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,99 @@ | ||
/* | ||
* 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 { i18n } from '@kbn/i18n'; | ||
import type { Ast } from '@kbn/interpreter'; | ||
import type { IconType } from '@elastic/eui/src/components/icon/icon'; | ||
import type { DataView } from '@kbn/data-views-plugin/public'; | ||
import type { AggregateQuery, Query, Filter } from '@kbn/es-query'; | ||
|
||
/** | ||
* Indicates what was changed in this table compared to the currently active table of this layer. | ||
* * `initial` means the layer associated with this table does not exist in the current configuration | ||
* * `unchanged` means the table is the same in the currently active configuration | ||
* * `reduced` means the table is a reduced version of the currently active table (some columns dropped, but not all of them) | ||
* * `extended` means the table is an extended version of the currently active table (added one or multiple additional columns) | ||
* * `reorder` means the table columns have changed order, which change the data as well | ||
* * `layers` means the change is a change to the layer structure, not to the table | ||
*/ | ||
export type TableChangeType = | ||
| 'initial' | ||
| 'unchanged' | ||
| 'reduced' | ||
| 'extended' | ||
| 'reorder' | ||
| 'layers'; | ||
|
||
export interface Suggestion<T = unknown, V = unknown> { | ||
visualizationId: string; | ||
datasourceState?: V; | ||
datasourceId?: string; | ||
columns: number; | ||
score: number; | ||
title: string; | ||
visualizationState: T; | ||
previewExpression?: Ast | string; | ||
previewIcon: IconType; | ||
hide?: boolean; | ||
// flag to indicate if the visualization is incomplete | ||
incomplete?: boolean; | ||
changeType: TableChangeType; | ||
keptLayerIds: string[]; | ||
} | ||
|
||
export const getLensAttributes = ({ | ||
filters, | ||
query, | ||
suggestion, | ||
dataView, | ||
}: { | ||
filters: Filter[]; | ||
query: Query | AggregateQuery; | ||
suggestion: Suggestion | undefined; | ||
dataView?: DataView; | ||
}) => { | ||
const suggestionDatasourceState = Object.assign({}, suggestion?.datasourceState); | ||
const suggestionVisualizationState = Object.assign({}, suggestion?.visualizationState); | ||
const datasourceStates = | ||
suggestion && suggestion.datasourceState | ||
? { | ||
[suggestion.datasourceId!]: { | ||
...suggestionDatasourceState, | ||
}, | ||
} | ||
: { | ||
formBased: {}, | ||
}; | ||
const visualization = suggestionVisualizationState; | ||
const attributes = { | ||
title: suggestion | ||
? suggestion.title | ||
: i18n.translate('xpack.lens.config.suggestion.title', { | ||
defaultMessage: 'New suggestion', | ||
}), | ||
references: [ | ||
{ | ||
id: dataView?.id ?? '', | ||
name: `textBasedLanguages-datasource-layer-suggestion`, | ||
type: 'index-pattern', | ||
}, | ||
], | ||
state: { | ||
datasourceStates, | ||
filters, | ||
query, | ||
visualization, | ||
...(dataView && | ||
dataView.id && | ||
!dataView.isPersisted() && { | ||
adHocDataViews: { [dataView.id]: dataView.toSpec(false) }, | ||
}), | ||
}, | ||
visualizationType: suggestion ? suggestion.visualizationId : 'lnsXY', | ||
}; | ||
return attributes; | ||
}; |
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
61 changes: 61 additions & 0 deletions
61
x-pack/plugins/lens/public/trigger_actions/open_lens_config/embeddable_edit_action.tsx
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,61 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import { i18n } from '@kbn/i18n'; | ||
import type { CoreStart } from '@kbn/core/public'; | ||
import { Action } from '@kbn/ui-actions-plugin/public'; | ||
import type { LensPluginStartDependencies } from '../../plugin'; | ||
import type { TypedLensByValueInput } from '../../embeddable/embeddable_component'; | ||
|
||
const ACTION_EDIT_LENS_EMBEDDABLE = 'ACTION_EDIT_LENS_EMBEDDABLE'; | ||
|
||
interface Context { | ||
attributes?: TypedLensByValueInput['attributes']; | ||
id?: string; | ||
onUpdate?: (input: TypedLensByValueInput['attributes']) => void; | ||
} | ||
|
||
export const getAsyncHelpers = async () => await import('../../async_services'); | ||
|
||
export class EditLensEmbeddableAction implements Action<Context> { | ||
public type = ACTION_EDIT_LENS_EMBEDDABLE; | ||
public id = ACTION_EDIT_LENS_EMBEDDABLE; | ||
public order = 50; | ||
|
||
constructor( | ||
protected readonly startDependencies: LensPluginStartDependencies, | ||
protected readonly core: CoreStart | ||
) {} | ||
|
||
public getDisplayName(): string { | ||
return i18n.translate('xpack.lens.app.editLensEmbeddableLabel', { | ||
defaultMessage: 'Edit visualization', | ||
}); | ||
} | ||
|
||
public getIconType() { | ||
return 'pencil'; | ||
} | ||
|
||
public async isCompatible() { | ||
// compatible only when ES|QL advanced setting is enabled | ||
const { isEmbeddableEditActionCompatible } = await getAsyncHelpers(); | ||
return isEmbeddableEditActionCompatible(this.core); | ||
} | ||
|
||
public async execute({ attributes, id, onUpdate }: Context) { | ||
const { executeEditEmbeddableAction } = await getAsyncHelpers(); | ||
if (attributes) { | ||
executeEditEmbeddableAction({ | ||
deps: this.startDependencies, | ||
core: this.core, | ||
attributes, | ||
embeddableId: id, | ||
onUpdate, | ||
}); | ||
} | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...ck/plugins/lens/public/trigger_actions/open_lens_config/embeddable_edit_action_helpers.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,70 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import { createGetterSetter } from '@kbn/kibana-utils-plugin/common'; | ||
import type { CoreStart } from '@kbn/core/public'; | ||
import { IncompatibleActionError } from '@kbn/ui-actions-plugin/public'; | ||
import type { Datasource, Visualization } from '../../types'; | ||
import type { LensPluginStartDependencies } from '../../plugin'; | ||
import { generateId } from '../../id_generator'; | ||
import { executeAction } from './helpers'; | ||
import type { TypedLensByValueInput } from '../../embeddable/embeddable_component'; | ||
|
||
// datasourceMap and visualizationMap setters/getters | ||
export const [getVisualizationMap, setVisualizationMap] = createGetterSetter< | ||
Record<string, Visualization<unknown, unknown, unknown>> | ||
>('VisualizationMap', false); | ||
|
||
export const [getDatasourceMap, setDatasourceMap] = createGetterSetter< | ||
Record<string, Datasource<unknown, unknown>> | ||
>('DatasourceMap', false); | ||
|
||
export function isEmbeddableEditActionCompatible(core: CoreStart) { | ||
return core.uiSettings.get('discover:enableESQL'); | ||
} | ||
|
||
export async function executeEditEmbeddableAction({ | ||
deps, | ||
core, | ||
attributes, | ||
embeddableId, | ||
onUpdate, | ||
}: { | ||
deps: LensPluginStartDependencies; | ||
core: CoreStart; | ||
attributes: TypedLensByValueInput['attributes']; | ||
embeddableId?: string; | ||
onUpdate?: (input: TypedLensByValueInput['attributes']) => void; | ||
}) { | ||
const isCompatibleAction = isEmbeddableEditActionCompatible(core); | ||
const defaultDataView = await deps.dataViews.getDefaultDataView({ | ||
displayErrors: false, | ||
}); | ||
if (!isCompatibleAction || !defaultDataView) { | ||
throw new IncompatibleActionError(); | ||
} | ||
|
||
const input = { | ||
attributes, | ||
id: embeddableId ?? generateId(), | ||
}; | ||
const embeddableStart = deps.embeddable; | ||
const factory = embeddableStart.getEmbeddableFactory('lens'); | ||
if (!factory) { | ||
return undefined; | ||
} | ||
const embeddable = await factory.create(input); | ||
// open the flyout if embeddable has been created successfully | ||
if (embeddable) { | ||
executeAction({ | ||
embeddable, | ||
startDependencies: deps, | ||
overlays: core.overlays, | ||
theme: core.theme, | ||
onUpdate, | ||
}); | ||
} | ||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stratoula reuse this is Lens