import { i18n } from '@osd/i18n' ; import { ChromeStart , DocLinksStart } from 'opensearch-dashboards/public' ; import { Filter } from '../../../../data/public' ; import { VisualizeServices , VisualizeEditorVisInstance } from '../types' ; export const addHelpMenuToAppChrome = ( chrome , docLinks ) => { chrome . setHelpExtension ( { appName : i18n . translate ( 'visualize.helpMenu.appName' , { defaultMessage : 'Visualize' , } ) , links : [ { linkType : 'documentation' , href : `${ docLinks . links . noDocumentation . visualize . guide }` , } , ] , } ) ; } ; export const addBadgeToAppChrome = ( chrome ) => { chrome . setBadge ( { text : i18n . translate ( 'visualize.badge.readOnly.text' , { defaultMessage : 'Read only' , } ) , tooltip : i18n . translate ( 'visualize.badge.readOnly.tooltip' , { defaultMessage : 'Unable to save visualizations' , } ) , iconType : 'glasses' , } ) ; } ; export const getDefaultQuery = ( { data } ) => { return data . query . queryString . getDefaultQuery ( ) ; } ; export const visStateToEditorState = ( visInstance , services ) => { const vis = visInstance . vis ; const savedVisState = services . visualizations . convertFromSerializedVis ( vis . serialize ( ) ) ; const savedVis = 'savedVis' in visInstance ? visInstance . savedVis : undefined ; return { uiState : savedVis && savedVis . uiStateJSON ? JSON . parse ( savedVis . uiStateJSON ) : vis . uiState . toJSON ( ) , query : vis . data . searchSource ?. getOwnField ( 'query' ) || getDefaultQuery ( services ) , filters : ( vis . data . searchSource ?. getOwnField ( 'filter' ) as Filter [ ] ) || [ ] , vis : { ... savedVisState . visState , title : vis . title } , linked : savedVis && savedVis . id ? ! ! savedVis . savedSearchId : ! ! savedVisState . savedSearchId , } ; } ;