import { observable } from 'mobx' ; import { useObjectRef , useObservableRef } from '@cloudbeaver/core-blocks' ; import { useService } from '@cloudbeaver/core-di' ; import type { ILogEntry } from './ILogEntry' ; import { LogViewerService } from './LogViewerService' ; interface Props { selectedItem : ILogEntry | null ; logViewerService : LogViewerService ; } export function useLogViewer ( ) { const logViewerService = useService ( LogViewerService ) ; const props = useObservableRef ( ( ) => ( { selectedItem : null } ) , { selectedItem : observable . ref } , { logViewerService } ) ; return useObjectRef ( ( ) => ( { get selectedItem ( ) { return props . selectedItem ; } , selectItem ( item ) { if ( item ?. id === props . selectedItem ?. id ) { props . selectedItem = null ; return ; } props . selectedItem = item ; } , get isActive ( ) { return props . logViewerService . isActive ; } , get logItems ( ) { return props . logViewerService . getLog ( ) ; } , clearLog ( ) { props . logViewerService . clearLog ( ) ; this . selectItem ( null ) ; } , } ) , false ) ; }