import './visualize_editor.scss' ; import React , { useEffect , useState } from 'react' ; import { useParams } from 'react-router-dom' ; import { EventEmitter } from 'events' ; import { useKibana } from '../../../../kibana_react/public' ; import { useChromeVisibility , useSavedVisInstance , useVisualizeAppState , useEditorUpdates , useLinkedSearchUpdates , } from '../utils' ; import { VisualizeServices } from '../types' ; import { VisualizeEditorCommon } from './visualize_editor_common' ; import { VisualizeAppProps } from '../app' ; import { VisualizeConstants } from '../../../common/constants' ; export const VisualizeEditor = ( { onAppLeave } ) => { const { id : visualizationIdFromUrl } = useParams < { id : string ; } > ( ) ; const [ originatingApp , setOriginatingApp ] = useState < string > ( ) ; const [ originatingPath , setOriginatingPath ] = useState < string > ( ) ; const [ embeddableIdValue , setEmbeddableId ] = useState < string > ( ) ; const { services } = useKibana < VisualizeServices > ( ) ; const [ eventEmitter ] = useState ( new EventEmitter ( ) ) ; const [ hasUnsavedChanges , setHasUnsavedChanges ] = useState ( ! visualizationIdFromUrl ) ; const isChromeVisible = useChromeVisibility ( services . chrome ) ; const { savedVisInstance , visEditorRef , visEditorController } = useSavedVisInstance ( services , eventEmitter , isChromeVisible , originatingApp , visualizationIdFromUrl ) ; const { appState , hasUnappliedChanges } = useVisualizeAppState ( services , eventEmitter , savedVisInstance ) ; const { isEmbeddableRendered , currentAppState } = useEditorUpdates ( services , eventEmitter , setHasUnsavedChanges , appState , savedVisInstance , visEditorController ) ; useLinkedSearchUpdates ( services , eventEmitter , appState , savedVisInstance ) ; useEffect ( ( ) => { const { stateTransferService , data } = services ; const { originatingApp : value , searchSessionId , embeddableId , originatingPath : pathValue , } = stateTransferService . getIncomingEditorState ( VisualizeConstants . APP_ID ) || { } ; if ( searchSessionId ) { data . search . session . continue ( searchSessionId ) ; } else { data . search . session . start ( ) ; } setEmbeddableId ( embeddableId ) ; setOriginatingApp ( value ) ; setOriginatingPath ( pathValue ) ; } , [ services ] ) ; useEffect ( ( ) => { return ( ) => { eventEmitter . removeAllListeners ( ) ; } ; } , [ eventEmitter , services ] ) ; return ( < VisualizeEditorCommon visInstance = { savedVisInstance } appState = { appState } currentAppState = { currentAppState } isChromeVisible = { isChromeVisible } hasUnsavedChanges = { hasUnsavedChanges } hasUnappliedChanges = { hasUnappliedChanges } isEmbeddableRendered = { isEmbeddableRendered } originatingApp = { originatingApp } setOriginatingApp = { setOriginatingApp } originatingPath = { originatingPath } visualizationIdFromUrl = { visualizationIdFromUrl } setHasUnsavedChanges = { setHasUnsavedChanges } visEditorRef = { visEditorRef } onAppLeave = { onAppLeave } embeddableId = { embeddableIdValue } / > ) ; } ;