From a9d2fc5572e6b9ce7cb3fe59d9dafb6160522101 Mon Sep 17 00:00:00 2001 From: Sachin Chaurasiya Date: Wed, 13 Jul 2022 19:26:46 +0530 Subject: [PATCH] Fix #5880 Validate Airflow connection in Test Connection button (#6060) --- .../ServiceConfig/ConnectionConfigForm.tsx | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/openmetadata-ui/src/main/resources/ui/src/components/ServiceConfig/ConnectionConfigForm.tsx b/openmetadata-ui/src/main/resources/ui/src/components/ServiceConfig/ConnectionConfigForm.tsx index de6c2f705c7..ce7378f976c 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/ServiceConfig/ConnectionConfigForm.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/ServiceConfig/ConnectionConfigForm.tsx @@ -14,7 +14,14 @@ import { ISubmitEvent } from '@rjsf/core'; import { cloneDeep, isNil } from 'lodash'; import { LoadingState } from 'Models'; -import React, { Fragment, FunctionComponent, useMemo } from 'react'; +import React, { + Fragment, + FunctionComponent, + useEffect, + useMemo, + useState, +} from 'react'; +import { checkAirflowStatus } from '../../axiosAPIs/ingestionPipelineAPI'; import { TestConnection } from '../../axiosAPIs/serviceAPI'; import { ServiceCategory } from '../../enums/service.enum'; import { MlModelServiceType } from '../../generated/api/services/createMlModelService'; @@ -76,6 +83,8 @@ const ConnectionConfigForm: FunctionComponent = ({ onCancel, onSave, }: Props) => { + const [isAirflowAvailable, setIsAirflowAvailable] = useState(false); + const allowTestConn = useMemo(() => { return shouldTestConnection(serviceType); }, [serviceType]); @@ -165,11 +174,28 @@ const ConnectionConfigForm: FunctionComponent = ({ uiSchema={connSch.uiSchema} onCancel={onCancel} onSubmit={handleSave} - onTestConnection={allowTestConn ? handleTestConnection : undefined} + onTestConnection={ + allowTestConn && isAirflowAvailable ? handleTestConnection : undefined + } /> ); }; + useEffect(() => { + checkAirflowStatus() + .then((res) => { + if (res.status === 200) { + setIsAirflowAvailable(true); + } else { + setIsAirflowAvailable(false); + } + }) + .catch((error) => { + // eslint-disable-next-line no-console + console.log(error); + }); + }, []); + return {getDatabaseFields()}; };