import { DBDriverResource } from '@cloudbeaver/core-connections' ; import { Bootstrap , injectable } from '@cloudbeaver/core-di' ; import type { IExecutionContextProvider } from '@cloudbeaver/core-executor' ; import { isObjectPropertyInfoStateEqual } from '@cloudbeaver/core-sdk' ; import { ConnectionFormService } from '../ConnectionFormService' ; import { connectionConfigContext } from '../Contexts/connectionConfigContext' ; import { connectionFormStateContext } from '../Contexts/connectionFormStateContext' ; import type { IConnectionFormFillConfigData , IConnectionFormSubmitData , IConnectionFormState } from '../IConnectionFormProps' ; import { DriverProperties } from './DriverProperties' ; @ injectable ( ) export class ConnectionDriverPropertiesTabService extends Bootstrap { constructor ( private readonly connectionFormService , private readonly dbDriverResource ) { super ( ) ; } register ( ) { this . connectionFormService . tabsContainer . add ( { key : 'driver_properties' , name : 'customConnection_properties' , title : 'customConnection_properties' , order : 2 , panel : ( ) => DriverProperties , isDisabled : ( tabId , props ) => { if ( props ?. state . config . driverId ) { return ! props ?. state . config . driverId ; } return true ; } , } ) ; this . connectionFormService . prepareConfigTask . addHandler ( this . prepareConfig . bind ( this ) ) ; this . connectionFormService . formStateTask . addHandler ( this . formState . bind ( this ) ) ; this . connectionFormService . fillConfigTask . addHandler ( this . fillConfig . bind ( this ) ) ; } load ( ) { } private fillConfig ( { state , updated } , contexts ) { if ( ! updated ) { return ; } if ( ! state . config . properties ) { state . config . properties = { } ; } if ( ! state . info ) { return ; } state . config . properties = { ... state . info . properties } ; } private prepareConfig ( { state , } , contexts ) { const config = contexts . getContext ( connectionConfigContext ) ; config . properties = { ... state . config . properties } ; } private formState ( data , contexts ) { if ( ! data . info || ! data . config . driverId ) { return ; } const config = contexts . getContext ( connectionConfigContext ) ; const driver = this . dbDriverResource . get ( data . config . driverId ) ; if ( ! driver ?. driverProperties ) { return ; } if ( ! isObjectPropertyInfoStateEqual ( driver . driverProperties , config . properties , data . info . properties ) ) { const stateContext = contexts . getContext ( connectionFormStateContext ) ; stateContext . markEdited ( ) ; } } }