Skip to content

Commit 524605c

Browse files
author
Tim Roes
authored
Fix bugs in form behavior (#13052)
* Fix bugs in form behavior * Fix e2e tests * Clear timeout properly
1 parent 868ed76 commit 524605c

File tree

5 files changed

+19
-5
lines changed

5 files changed

+19
-5
lines changed

airbyte-webapp-e2e-tests/cypress/support/commands/common.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Cypress.Commands.add("fillTestLocalJsonForm", (name) => {
1414

1515
cy.wait("@getDestinationSpecifications");
1616

17-
cy.get("input[name=name]").type(name);
17+
cy.get("input[name=name]").clear().type(name);
1818
cy.get("input[name='connectionConfiguration.destination_path']").type("/local");
1919
})
2020

airbyte-webapp-e2e-tests/cypress/support/commands/source.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Cypress.Commands.add("fillPgSourceForm", (name) => {
88

99
cy.wait("@getSourceSpecifications");
1010

11-
cy.get("input[name=name]").type(name);
11+
cy.get("input[name=name]").clear().type(name);
1212
cy.get("input[name='connectionConfiguration.host']").type("localhost");
1313
cy.get("input[name='connectionConfiguration.port']").type("{selectAll}{del}5433");
1414
cy.get("input[name='connectionConfiguration.database']").type("airbyte_ci");

airbyte-webapp/src/views/Connector/ConnectorCard/ConnectorCard.tsx

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from "react";
1+
import React, { useEffect, useState } from "react";
22
import { FormattedMessage } from "react-intl";
33

44
import { ContentCard } from "components";
@@ -37,7 +37,13 @@ export const ConnectorCard: React.FC<
3737
const [saved, setSaved] = useState(false);
3838
const [errorStatusRequest, setErrorStatusRequest] = useState<Error | null>(null);
3939

40-
const { testConnector, isTestConnectionInProgress, onStopTesting, error } = useTestConnector(props);
40+
const { testConnector, isTestConnectionInProgress, onStopTesting, error, reset } = useTestConnector(props);
41+
42+
useEffect(() => {
43+
// Whenever the selected connector changed, reset the check connection call and other errors
44+
reset();
45+
setErrorStatusRequest(null);
46+
}, [props.selectedConnectorDefinitionSpecification, reset]);
4147

4248
const trackNewSourceAction = useTrackAction(TrackActionType.NEW_SOURCE);
4349
const trackNewDestinationAction = useTrackAction(TrackActionType.NEW_DESTINATION);

airbyte-webapp/src/views/Connector/ConnectorCard/useTestConnector.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export const useTestConnector = (
2222
onStopTesting: () => void;
2323
testConnector: (v?: ServiceFormValues) => Promise<CheckConnectionRead>;
2424
error: Error | null;
25+
reset: () => void;
2526
} => {
2627
const { mutateAsync, isLoading, error, isSuccess, reset } = useCheckConnector(props.formType);
2728

@@ -31,6 +32,7 @@ export const useTestConnector = (
3132
isTestConnectionInProgress: isLoading,
3233
isSuccess,
3334
error,
35+
reset,
3436
onStopTesting: () => {
3537
abortControllerRef.current?.abort();
3638
reset();

airbyte-webapp/src/views/Connector/ServiceForm/ServiceForm.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,14 @@ const SetDefaultName: React.FC = () => {
8282

8383
useEffect(() => {
8484
if (selectedService) {
85-
setFieldValue("name", selectedService.name);
85+
const timeout = setTimeout(() => {
86+
// We need to push this out one execution slot, so the form isn't still in its
87+
// initialization status and won't react to this call but would just take the initialValues instead.
88+
setFieldValue("name", selectedService.name);
89+
});
90+
return () => clearTimeout(timeout);
8691
}
92+
return;
8793
// eslint-disable-next-line react-hooks/exhaustive-deps
8894
}, [selectedService]);
8995

0 commit comments

Comments
 (0)