import './visualize_editor.scss' ; import React , { useEffect , useState } from 'react' ; import { useParams } from 'react-router-dom' ; import { EventEmitter } from 'events' ; import { useOpenSearchDashboards } from '../../../../opensearch_dashboards_react/public' ; import { useChromeVisibility , useSavedVisInstance , useVisualizeAppState , useEditorUpdates , useLinkedSearchUpdates , } from '../utils' ; import { VisualizeServices } from '../types' ; import { VisualizeEditorCommon } from './visualize_editor_common' ; import { VisualizeAppProps } from '../app' ; export const VisualizeEditor = ( { onAppLeave } ) => { const { id : visualizationIdFromUrl } = useParams < { id : string ; } > ( ) ; const [ originatingApp , setOriginatingApp ] = useState < string > ( ) ; const { services } = useOpenSearchDashboards < VisualizeServices > ( ) ; const [ eventEmitter ] = useState ( new EventEmitter ( ) ) ; const [ hasUnsavedChanges , setHasUnsavedChanges ] = useState ( ! visualizationIdFromUrl ) ; const isChromeVisible = useChromeVisibility ( services . chrome ) ; const { savedVisInstance , visEditorRef , visEditorController } = useSavedVisInstance ( services , eventEmitter , isChromeVisible , 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 { originatingApp : value } = services . embeddable . getStateTransfer ( services . scopedHistory ) . getIncomingEditorState ( { keysToRemoveAfterFetch : [ 'id' , 'input' ] } ) || { } ; setOriginatingApp ( value ) ; } , [ services ] ) ; useEffect ( ( ) => { return ( ) => { eventEmitter . removeAllListeners ( ) ; } ; } , [ eventEmitter ] ) ; return ( < VisualizeEditorCommon visInstance = { savedVisInstance } appState = { appState } currentAppState = { currentAppState } isChromeVisible = { isChromeVisible } hasUnsavedChanges = { hasUnsavedChanges } hasUnappliedChanges = { hasUnappliedChanges } isEmbeddableRendered = { isEmbeddableRendered } originatingApp = { originatingApp } setOriginatingApp = { setOriginatingApp } visualizationIdFromUrl = { visualizationIdFromUrl } setHasUnsavedChanges = { setHasUnsavedChanges } visEditorRef = { visEditorRef } onAppLeave = { onAppLeave } / > ) ; } ;