Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select connector type before name #11388

Merged
merged 5 commits into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions airbyte-webapp-e2e-tests/cypress/support/commands/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ Cypress.Commands.add("fillEmail", (email) => {
Cypress.Commands.add("fillTestLocalJsonForm", (name) => {
cy.intercept("/api/v1/destination_definition_specifications/get").as("getDestinationSpecifications");

cy.get("input[name=name]").type(name);
cy.get("div[data-testid='serviceType']").click();
cy.get("div").contains("Local JSON").click();

cy.wait("@getDestinationSpecifications");


cy.get("input[name=name]").type(name);
cy.get("input[name='connectionConfiguration.destination_path']").type("/local");
})

Expand Down
8 changes: 4 additions & 4 deletions airbyte-webapp-e2e-tests/cypress/support/commands/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ Cypress.Commands.add("fillPgSourceForm", (name) => {
cy.intercept("/api/v1/source_definition_specifications/get").as(
"getSourceSpecifications"
);

cy.get("input[name=name]").type(name);

cy.get("div[data-testid='serviceType']").click();
cy.get("div").contains("Postgres").click();

cy.wait("@getSourceSpecifications");


cy.get("input[name=name]").type(name);
cy.get("input[name='connectionConfiguration.host']").type("localhost");
cy.get("input[name='connectionConfiguration.port']").type("{selectAll}{del}5433");
cy.get("input[name='connectionConfiguration.database']").type("airbyte_ci");
Expand Down
25 changes: 23 additions & 2 deletions airbyte-webapp/src/views/Connector/ServiceForm/ServiceForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,25 @@ const PatchInitialValuesWithWidgetConfig: React.FC<{ schema: JSONSchema7 }> = ({
return null;
};

/**
* A component that will observe whenever the serviceType (selected connector)
* changes and set the name of the connector to match the connector definition name.
*/
const SetDefaultName: React.FC = () => {
const { setFieldValue } = useFormikContext();
const { selectedService } = useServiceForm();

useEffect(() => {
// Formik has an issue, that prevents us from setting a field value directly in code here
// It won't change the value at all, unless we push it one execution slot further with setTimeout
setTimeout(() => {
timroes marked this conversation as resolved.
Show resolved Hide resolved
setFieldValue("name", selectedService?.name ?? "");
});
}, [selectedService, setFieldValue]);

return null;
};

const ServiceForm: React.FC<ServiceFormProps> = (props) => {
const [isOpenRequestModal, toggleOpenRequestModal] = useToggle(false);
const [initialRequestName, setInitialRequestName] = useState<string>();
Expand All @@ -101,8 +120,8 @@ const ServiceForm: React.FC<ServiceFormProps> = (props) => {
() => ({
type: "object",
properties: {
name: { type: "string" },
serviceType: { type: "string" },
...(selectedConnector ? { name: { type: "string" } } : {}),
...Object.fromEntries(
Object.entries({
connectionConfiguration: isLoading ? null : specifications,
Expand All @@ -111,7 +130,7 @@ const ServiceForm: React.FC<ServiceFormProps> = (props) => {
},
required: ["name", "serviceType"],
}),
[isLoading, specifications]
[isLoading, selectedConnector, specifications]
);

const { formFields, initialValues } = useBuildForm(jsonSchema, formValues);
Expand Down Expand Up @@ -209,7 +228,9 @@ const ServiceForm: React.FC<ServiceFormProps> = (props) => {
availableServices={props.availableServices}
isEditMode={props.isEditMode}
isLoadingSchema={props.isLoading}
serviceType={values.serviceType}
>
<SetDefaultName />
<FormikPatch />
<PatchInitialValuesWithWidgetConfig schema={jsonSchema} />
<FormRoot
Expand Down