@@ -14,9 +14,10 @@ import {
1414 PanelNotFoundError ,
1515 type EmbeddableInput ,
1616 isReferenceOrValueEmbeddable ,
17+ isFilterableEmbeddable ,
1718} from '@kbn/embeddable-plugin/public' ;
1819import { Action , IncompatibleActionError } from '@kbn/ui-actions-plugin/public' ;
19-
20+ import { type AggregateQuery } from '@kbn/es-query' ;
2021import { DashboardPanelState } from '../../common' ;
2122import { pluginServices } from '../services/plugin_services' ;
2223import { dashboardAddToLibraryActionStrings } from './_dashboard_actions_strings' ;
@@ -61,7 +62,10 @@ export class AddToLibraryAction implements Action<AddToLibraryActionContext> {
6162 // TODO: Fix this, potentially by adding a 'canSave' function to embeddable interface
6263 const { maps, visualize } = this . applicationCapabilities ;
6364 const canSave = embeddable . type === 'map' ? maps . save : visualize . save ;
64-
65+ const { isOfAggregateQueryType } = await import ( '@kbn/es-query' ) ;
66+ const query = isFilterableEmbeddable ( embeddable ) && ( await embeddable . getQuery ( ) ) ;
67+ // Textbased panels (i.e. ES|QL, SQL) should not save to library
68+ const isTextBasedEmbeddable = isOfAggregateQueryType ( query as AggregateQuery ) ;
6569 return Boolean (
6670 canSave &&
6771 ! isErrorEmbeddable ( embeddable ) &&
@@ -70,7 +74,8 @@ export class AddToLibraryAction implements Action<AddToLibraryActionContext> {
7074 embeddable . getRoot ( ) . isContainer &&
7175 embeddable . getRoot ( ) . type === DASHBOARD_CONTAINER_TYPE &&
7276 isReferenceOrValueEmbeddable ( embeddable ) &&
73- ! embeddable . inputIsRefType ( embeddable . getInput ( ) )
77+ ! embeddable . inputIsRefType ( embeddable . getInput ( ) ) &&
78+ ! isTextBasedEmbeddable
7479 ) ;
7580 }
7681
0 commit comments