import { observable , computed , makeObservable } from 'mobx' ; import { DBDriver , DBDriverResource } from '@cloudbeaver/core-connections' ; import { injectable , IInitializableController } from '@cloudbeaver/core-di' ; import { NotificationService } from '@cloudbeaver/core-events' ; import { PublicConnectionFormService } from '@cloudbeaver/plugin-connections' ; @ injectable ( ) export class CustomConnectionController implements IInitializableController { isLoading = true ; onClose ! : ( ) => void ; get drivers ( ) : DBDriver [ ] { return this . dbDriverResource . values . sort ( this . dbDriverResource . compare ) ; } constructor ( private dbDriverResource , private notificationService , private readonly publicConnectionFormService ) { makeObservable ( this , { isLoading : observable , drivers : computed , } ) ; } init ( onClose ) { this . loadDBDrivers ( ) ; this . onClose = onClose ; } onDriverSelect = async ( driverId ) => { const state = await this . publicConnectionFormService . open ( { driverId } , this . dbDriverResource . keys ) ; if ( state ) { this . onClose ( ) ; } } ; private async loadDBDrivers ( ) { try { await this . dbDriverResource . loadAll ( ) ; } catch ( exception ) { this . notificationService . logException ( exception , 'Can\'t load database drivers' ) ; } finally { this . isLoading = false ; } } }