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

🪟🔧 Move connector loading state into connector card #20127

Merged
merged 14 commits into from
Dec 8, 2022

Conversation

flash1293
Copy link
Contributor

@flash1293 flash1293 commented Dec 6, 2022

Part of #14250

What

This PR moves the loading spinner which is shown when the connection specification definition is loaded into the connector card component. This is done for a bunch of reasons:

  • Simplifying the connector form code - it's now only rendered if the specification is available
  • Remove complexity by not passing the loading prop deep into the component tree
  • Preparing the component to be used in other places as well

How

In the current state, the formik form is always initialized and rendered, even if there is no specification. The form component is also responsible for rendering the loading spinner itself.

This PR lifts the loading spinner to the connector card level and only renders the form component if all the prerequisites are present.

Drive-by fixes

  • The loading spinner requires the name of the connector that's currently loaded. This doesn't work correctly in the current state as the loading spinner pulls the name from the specification definition which isn't loaded yet. This PR changes this by passing the chosen connector id down to the connector card even if it's not loaded yet so the name can be shown in the loading spinner
  • In case the loading of the specification definition fails, the current state is not showing any error message because the component handling this (EditControls/CreateControls) is only showing the error if the specification definition is loaded. This PR pulls this error case to the connector card level and doesn't even attempt to render the form in this situation
  • There were unused props errorMessage and successMessage on the connector card level, those were removed

🚨 User Impact 🚨

Fixes a bunch of small bugs but otherwise no user-visible change.

@octavia-squidington-iv octavia-squidington-iv added the area/platform issues related to the platform label Dec 6, 2022
@flash1293 flash1293 marked this pull request as ready for review December 6, 2022 14:48
@flash1293 flash1293 requested a review from a team as a code owner December 6, 2022 14:48
Copy link
Contributor

@krishnaglick krishnaglick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't done a deep dive into the code but I feel like there could be an argument for adding a context to hold some of these reused and prop-drilled values. Don't hold this up on my account, merely an observation.

import { ConnectorFormValues } from "./types";

interface FormRootProps {
formFields: FormBlock;
hasSuccess?: boolean;
isTestConnectionInProgress?: boolean;
errorMessage?: React.ReactNode;
fetchingConnectorError?: Error | null;
successMessage?: React.ReactNode;
onRetest?: () => void;
onStopTestingConnector?: () => void;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't comment on it but I think the | undefined on selectedConnector prop type (the line below this one) can now be removed, because it is now being passed in from the ConnectorForm in a branch where it is verified to not be undefined.

This should also allow us to remove the selectedConnector && () around the <CreateControls> component near the bottom of this file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, removed that stuff as well!

Comment on lines +90 to +91
selectedConnectorDefinition: ConnectorDefinition;
selectedConnectorDefinitionSpecification: ConnectorDefinitionSpecification;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A side note that doesn't need to be addressed in this PR: when we eventually want to use the component in the Connector Builder (#17674), there won't be any concept of "connector definitions" to pass to that component. Instead we will just have a JSON schema object that we need to pass in and get back a rendered connector form (or something similar). So it would be great if this component could be generified in that way

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm not sure yet at which level we can lift out the functionality required for the connector builder, I guess we need to move a few things around. I will go through with the rest of the cleanup and take a look then.

</div>
)}
{fetchingConnectorError && <FetchingConnectorError />}
{selectedConnectorDefinition && selectedConnectorDefinitionSpecification && (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible that one of these is nullish even though a user has clicked on a connector from the dropdown? If so we may want to show some sort of error message here indicating that the connector could not be loaded or something. Because based on this code it still seems possible for fetchingConnectorError to be nullish, and for one of these values to be nullish as well, in which case we just won't render anything here which feels like a not great UX

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there is a way to run into this situation besides the desired one when the user navigates to a completely empty form.

If you look at the code where the component is used in SourceForm and DestinationForm, the props isLoading,fetchingConnectorError and selectedConnectorDefinition are coming from a react-query hook, so one of them will always be set if there is a selection that has been made.

)}
{fetchingConnectorError && <FetchingConnectorError />}
{selectedConnectorDefinition && selectedConnectorDefinitionSpecification && (
<ConnectorForm
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I'm getting a little confused here: your new code makes sense to me in that it only renders a <ConnectorForm> if selectedConnectorDefinition and selectedConnectorDefinitionSpecification are not nullish, but I'm confused how the old code was handling that case -- it seems like the old code was always rendering a ConnectorForm which was always rendering a FormRoot which was always rendering a FormSection, so how does the UI currently look empty when no connector is selected?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, it would render all of the components, but if you follow all the branches in the tree they all used to end in an empty component eventually if nothing is selected (e.g. the form in this case only contains an empty form section which renders an empty fragment)

@lmossman
Copy link
Contributor

lmossman commented Dec 7, 2022

Tested it out locally and didn't notice any issues

@flash1293
Copy link
Contributor Author

Thanks for the review @lmossman , could you check again? Removed the additional bit you found.

Copy link
Contributor

@lmossman lmossman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes LGTM. Tested locally and seems to work as expected

@flash1293 flash1293 merged commit 0e6e02f into master Dec 8, 2022
@flash1293 flash1293 deleted the flash1293/connector-form-loading-state branch December 8, 2022 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/frontend Related to the Airbyte webapp area/platform issues related to the platform team/extensibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants