import { createSavedObjectClass , SavedObject , SavedObjectOpenSearchDashboardsServices , } from '../../../../plugins/saved_objects/public' ; import { extractReferences , injectReferences } from './saved_dashboard_references' ; import { Filter , ISearchSource , Query , RefreshInterval } from '../../../../plugins/data/public' ; import { createDashboardEditUrl } from '../dashboard_constants' ; export interface SavedObjectDashboard extends SavedObject { id ? : string ; timeRestore : boolean ; timeTo ? : string ; timeFrom ? : string ; description ? : string ; panelsJSON : string ; optionsJSON ? : string ; uiStateJSON ? : string ; lastSavedTitle : string ; refreshInterval ? : RefreshInterval ; searchSource : ISearchSource ; getQuery ( ) : Query ; getFilters ( ) : Filter [ ] ; } export function createSavedDashboardClass ( services ) { const SavedObjectClass = createSavedObjectClass ( services ) ; class SavedDashboard extends SavedObjectClass { public static type = 'dashboard' ; public static mapping = { title : 'text' , hits : 'integer' , description : 'text' , panelsJSON : 'text' , optionsJSON : 'text' , version : 'integer' , timeRestore : 'boolean' , timeTo : 'keyword' , timeFrom : 'keyword' , refreshInterval : { type : 'object' , properties : { display : { type : 'keyword' } , pause : { type : 'boolean' } , section : { type : 'integer' } , value : { type : 'integer' } , } , } , } ; public static fieldOrder = [ 'title' , 'description' ] ; public static searchSource = true ; public showInRecentlyAccessed = true ; constructor ( id ) { super ( { type : SavedDashboard . type , mapping : SavedDashboard . mapping , searchSource : SavedDashboard . searchSource , extractReferences , injectReferences , id , defaults : { title : '' , hits : 0 , description : '' , panelsJSON : '[]' , optionsJSON : JSON . stringify ( { useMargins : ! id , hidePanelTitles : false , } ) , version : 1 , timeRestore : false , timeTo : undefined , timeFrom : undefined , refreshInterval : undefined , } , } ) ; this . getFullPath = ( ) => `/app/dashboards#${ createDashboardEditUrl ( String ( this . id ) ) }` ; } getQuery ( ) { return this . searchSource ! . getOwnField ( 'query' ) || { query : '' , language : 'kuery' } ; } getFilters ( ) { return this . searchSource ! . getOwnField ( 'filter' ) || [ ] ; } } return ( SavedDashboard as unknown ) as new ( id ) => SavedObjectDashboard ; }