-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
🪟 🔧 Move the serviceType
prop out from Formik form (<ServiceForm/> refactoring part 2)
#18168
🪟 🔧 Move the serviceType
prop out from Formik form (<ServiceForm/> refactoring part 2)
#18168
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the detailed PR description! I think all of the changes you described make sense, and I like that this simplifies ServiceForm even further and moves logic that is really the domain of the ConnectorCard into that component.
I just had one comment about getting rid of the term "Service" since we don't really use that term anywhere else. But, I think it could also make sense to make that change in a future PR if you don't want to increase the scope of this PR.
I tested this a bit locally and it seems to be working as expected from what I can tell. I also confirmed that selecting a connector type and then navigating away correctly does not show the warning modal 🎉
onServiceSelect?: (id: string) => void; | ||
availableServices: ConnectorDefinition[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While we're here changing things anyway, we should go ahead and try to get rid of the term "service" from all of these places.
It is confusing that this component and the ServiceForm component are the only places that refer to connectors and connector definitions as "services", so we should fix that. In this case, better names for these props would be onConnectorDefinitionSelect
and availableConnectorDefinitions
, to better match the terminology that we use for these objects throughout the rest of the Airbyte codebase.
Ideally we would also rename ServiceForm
to something like ConnectorForm
, and rename all related methods/variables/components as such.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also was thinking about that, but wasn't sure 😊
Ok, will fix that!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Decided to try to rename all "service" related usages - got more modified files than I expected 😕
Good news - no "service" term mentions anymore 😊
// TODO: need to clean up the ConnectorCard and ServiceForm props, | ||
// since some of props are used in both components, and some of them used just as a prop-drill |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you create an issue for this, which captures why the current state is bad and what might be a better solution?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, here is it: #18553
I will add it to comment also
const selectedConnectorDefinitionSpecificationId = | ||
selectedConnectorDefinitionSpecification && ConnectorSpecification.id(selectedConnectorDefinitionSpecification); | ||
// Fill form with existing connector values otherwise set the default service name | ||
const formValues = isEditMode ? props.connector : { name: selectedService?.name }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest we move the default name logic into the ServiceForm
where the initialValues of the Formik context are actually calculated, so that we have all the "formik" values logic ideally inside the ServiceForm
as much as possible and not passing those values from the outside.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds reasonable, and I also did a try:
The first thing which confuses me, we just replace one prop(formValues) with another dependency - connector.
And here is the place where the errors come:
Because of:
interface ConnectorCardCreateProps extends ConnectorCardBaseProps {
isEditMode?: false;
}
interface ConnectorCardEditProps extends ConnectorCardBaseProps {
isEditMode: true;
connector: ConnectorT;
}
export const ConnectorCard: React.FC<ConnectorCardCreateProps | ConnectorCardEditProps>
Also did a try to pass the connector
prop implicitly to <ServiceForm />
just for testing, and surprisingly, the tests start failing...
Should I continue digging into it?
Since the PR already has some changes out of the scope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is still some code in https://github.com/airbytehq/airbyte/blob/master/airbyte-webapp/src/views/Connector/ServiceForm/useBuildForm.tsx#L33 when calculating the default values that has the serviceType
still on it, which I believe we should be able to remove now as well.
I wonder if we might want to break the useBuildForm
hook apart and remove the initialValues
calculation from it? It feels the two calculation done in this hook have pretty much nothing to do with each other, so I feel they should either be two hooks or the initialValues
could simply be inlined into the ServiceForm, since it's not really much or complex code at all?
remove selectedService var from ConnectorDefinitionTypeControl (since we calculated it ConnectorCard) and pass as a prop
serviceType
prop out from Formik form (<ServiceForm/> refactoring part 2)serviceType
prop out from Formik form (<ServiceForm/> refactoring part 2)
…formvalues # Conflicts: # airbyte-webapp/src/views/Connector/ServiceForm/serviceFormContext.tsx
…onnectorDefinitionSpecification"
…formvalues # Conflicts: # airbyte-webapp/src/views/Connection/ConnectionForm/ScheduleField/ScheduleField.tsx
Missed that. Fixed
Agree, honesty I think the whole |
serviceType
prop out from Formik form (<ServiceForm/> refactoring part 2)serviceType
prop out from Formik form (<ServiceForm/> refactoring part 2)
totally fine pushing this to another PR! |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code LGTM. Have done a quick smoke test locally, things seem to still work.
What
Closes #18051
Part 1
Fixed use-case:
Previously:
Unsaved changes modal appears
Now:
The user didn't touch any field so there is no need to show the unsaved changes modal
How
Move the
serviceType
prop out from Formik form and handle it in<ConnectorCard />
componentReading order(moving from bottom up)
ConnectorFormValues
since we need to handleserviceType
separately fromServiceFomValues
availableServices
was passed in order to determinate whatselectedService
is. And sinceselectedService
is also used on upper levels, it was replaced withselectedService
availableServices
since we don't pass it to context anymore. Was replaced withselectedService
.testConnector
- func argument was replaced withConnectorFormValues
, sinceServiceFomValues
doesn't containserviceType
anymore<SetDefaultName />
- it was a tricky solution to set the default name for connector. Now we set default name informValues
on upper level (<ConnectorCard/ >
)<ServiceForm />
<ServiceForm />
became responsible for the actual form valuesonSubmit
handler. Since ServiceFormProps usedonSubmit
withoutserviceType
, and ConnectorCardProps with. SimplyOmit<ServiceFormProps, "onSubmit">
and overwrite didn't help and caused the errors. Left a TODO to fix that later on. And for now, just created the newConnectorCardProps
and marked which props used are in parent(<ConnectorCard />
) and child(<ServiceFrom />
) components:formValues
- ifisEdit
we pass the existing values to<ServiceFrom />
otherwise set the service name for as the default connector name