Fix #4350 Redesign Test connection flow (#4404)

This commit is contained in:
Sachin Chaurasiya 2022-04-23 21:09:24 +05:30 committed by GitHub
parent 7c8c51e862
commit 6fd572d635
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 63 additions and 25 deletions

View File

@ -14,7 +14,7 @@
import { ISubmitEvent } from '@rjsf/core'; import { ISubmitEvent } from '@rjsf/core';
import { cloneDeep, isNil } from 'lodash'; import { cloneDeep, isNil } from 'lodash';
import { LoadingState } from 'Models'; import { LoadingState } from 'Models';
import React, { FunctionComponent } from 'react'; import React, { Fragment, FunctionComponent } from 'react';
import { TestConnection } from '../../axiosAPIs/serviceAPI'; import { TestConnection } from '../../axiosAPIs/serviceAPI';
import { ServiceCategory } from '../../enums/service.enum'; import { ServiceCategory } from '../../enums/service.enum';
import { import {
@ -36,7 +36,7 @@ import { getDashboardConfig } from '../../utils/DashboardServiceUtils';
import { getDatabaseConfig } from '../../utils/DatabaseServiceUtils'; import { getDatabaseConfig } from '../../utils/DatabaseServiceUtils';
import { getMessagingConfig } from '../../utils/MessagingServiceUtils'; import { getMessagingConfig } from '../../utils/MessagingServiceUtils';
import { getPipelineConfig } from '../../utils/PipelineServiceUtils'; import { getPipelineConfig } from '../../utils/PipelineServiceUtils';
import { showErrorToast, showSuccessToast } from '../../utils/ToastUtils'; import { showErrorToast } from '../../utils/ToastUtils';
import FormBuilder from '../common/FormBuilder/FormBuilder'; import FormBuilder from '../common/FormBuilder/FormBuilder';
interface Props { interface Props {
@ -73,9 +73,6 @@ const ConnectionConfigForm: FunctionComponent<Props> = ({
// This api only responds with status 200 on success // This api only responds with status 200 on success
// No data sent on api success // No data sent on api success
if (res.status === 200) { if (res.status === 200) {
showSuccessToast(
jsonData['api-success-messages']['test-connection-success']
);
resolve(); resolve();
} else { } else {
throw jsonData['api-error-messages']['unexpected-server-response']; throw jsonData['api-error-messages']['unexpected-server-response'];
@ -149,7 +146,7 @@ const ConnectionConfigForm: FunctionComponent<Props> = ({
); );
}; };
return <>{getDatabaseFields()}</>; return <Fragment>{getDatabaseFields()}</Fragment>;
}; };
export default ConnectionConfigForm; export default ConnectionConfigForm;

View File

@ -147,6 +147,8 @@ const FormBuilder: FunctionComponent<Props> = ({
formData formData
); );
const [connectionTesting, setConnectionTesting] = useState<boolean>(false); const [connectionTesting, setConnectionTesting] = useState<boolean>(false);
const [connectionTestingState, setConnectionTestingState] =
useState<LoadingState>('initial');
const handleCancel = () => { const handleCancel = () => {
setLocalFormData(formData); setLocalFormData(formData);
@ -164,9 +166,23 @@ const FormBuilder: FunctionComponent<Props> = ({
const handleTestConnection = () => { const handleTestConnection = () => {
if (localFormData && onTestConnection) { if (localFormData && onTestConnection) {
setConnectionTesting(true); setConnectionTesting(true);
onTestConnection(localFormData).finally(() => { setConnectionTestingState('waiting');
setConnectionTesting(false); onTestConnection(localFormData)
}); .then(() => {
setTimeout(() => {
setConnectionTestingState('success');
}, 500);
})
.catch(() => {
setTimeout(() => {
setConnectionTestingState('initial');
}, 500);
})
.finally(() => {
setTimeout(() => {
setConnectionTesting(false);
}, 500);
});
} }
}; };
const debouncedOnChange = useCallback( const debouncedOnChange = useCallback(
@ -183,6 +199,29 @@ const FormBuilder: FunctionComponent<Props> = ({
debounceOnSearch(updatedData); debounceOnSearch(updatedData);
}; };
const getConnectionTestingMessage = () => {
switch (connectionTestingState) {
case 'waiting':
return (
<div className="tw-flex">
<Loader size="small" type="default" />{' '}
<span className="tw-ml-2">Running test...</span>
</div>
);
case 'success':
return (
<div className="tw-flex">
<SVGIcons alt="success-badge" icon={Icons.SUCCESS_BADGE} />
<span className="tw-ml-2">Connection test was successful</span>
</div>
);
case 'initial':
default:
return 'Test your connections before creating service';
}
};
return ( return (
<Form <Form
ArrayFieldTemplate={ArrayFieldTemplate} ArrayFieldTemplate={ArrayFieldTemplate}
@ -206,23 +245,25 @@ const FormBuilder: FunctionComponent<Props> = ({
No Connection Configs available. No Connection Configs available.
</div> </div>
)} )}
<div className="tw-mt-6 tw-flex tw-justify-between"> {!isEmpty(schema) && onTestConnection && (
<div> <div className="tw-flex tw-justify-between tw-bg-white tw-border tw-border-main tw-shadow tw-rounded tw-p-3 tw-mt-4">
{!isEmpty(schema) && onTestConnection && ( <div className="tw-self-center">{getConnectionTestingMessage()}</div>
<Button <Button
className={classNames({ className={classNames('tw-self-center tw-py-1 tw-px-1.5', {
'tw-opacity-40': connectionTesting, 'tw-opacity-40': connectionTesting,
})} })}
data-testid="test-connection-btn" data-testid="test-connection-btn"
disabled={connectionTesting} disabled={connectionTesting}
size="regular" size="small"
theme="primary" theme="primary"
variant="outlined" variant="outlined"
onClick={handleTestConnection}> onClick={handleTestConnection}>
Test Connection Test Connection
</Button> </Button>
)}
</div> </div>
)}
<div className="tw-mt-6 tw-flex tw-justify-between">
<div />
<div className="tw-text-right" data-testid="buttons"> <div className="tw-text-right" data-testid="buttons">
<Button <Button
size="regular" size="regular"