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

fix(connection-form): vscode support & cleanup COMPASS-8098 #6225

Merged
merged 13 commits into from
Sep 27, 2024

Conversation

paula-stacho
Copy link
Contributor

@paula-stacho paula-stacho commented Sep 11, 2024

Description

Preparing the new connection form for VSCode.
New preferences to be set in VSCode:

saveAndConnectLabel: 'Save & Connect', 
showHelpCardsInForm: false,
showPersonalisationForm: false,

I also used this opportunity to do a bit of cleanup of the pre-MC code (tbh tiptoing around the legacy parts of connection form has been something that bugged me for a while).

Left out (changes that will be visible in VSCode - let me know if you think these should also be customizable so that we avoid them in VSCode):

  • the new subtitle 'Manage your connection settings'
  • horizontal line above the buttons

Checklist

Motivation and Context

  • Bugfix
  • New feature
  • Dependency update
  • Misc

Open Questions

Dependents

Types of changes

  • Backport Needed
  • Patch (non-breaking change which fixes an issue)
  • Minor (non-breaking change which adds functionality)
  • Major (fix or feature that would cause existing functionality to change)

@github-actions github-actions bot added the fix label Sep 11, 2024
@paula-stacho paula-stacho changed the title fix(connection-form): cleanup & vscode support fix(connection-form): vscode support & cleanup Sep 12, 2024
@paula-stacho paula-stacho changed the title fix(connection-form): vscode support & cleanup fix(connection-form): vscode support & cleanup COMPASS-8098 Sep 12, 2024
@paula-stacho paula-stacho added the no release notes Fix or feature not for release notes label Sep 12, 2024
@paula-stacho paula-stacho force-pushed the COMPASS-8098 branch 2 times, most recently from 731f6b1 to fa57be6 Compare September 13, 2024 08:39
@paula-stacho paula-stacho marked this pull request as ready for review September 13, 2024 09:16
@@ -125,8 +83,7 @@ function Home({
hideCollectionSubMenu,
showSettings,
}: Omit<HomeProps, 'connectionStorage'>): React.ReactElement | null {
const appRegistry = useLocalAppRegistry();
const { connectionInfo, isConnected, disconnect } =
const { isConnected, disconnect } =
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we're making it impossible to use single connection mode by removing the form, why are we keeping this code here?

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 have reverted this bit and will be only removing the tests here. as much as I'd love to follow this rabbit hole, I don't have time to do that, so I'll leave it for the scheduled MC cleanup. I hope the partial cleanup I've done in the connection-form is okay. This is why I was asking in the channel if it's safe to say we won't be reverting the MC flag.

@@ -29,6 +34,7 @@ const defaultPreferences = {
showKerberosAuth: true,
showCSFLE: true,
showProxySettings: true,
saveAndConnectLabel: 'Connect',
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the intention for these preferences was only to map compass preferences to connection form without the need to have a dependency on the preferences model (although @mcasimir might correct me on that), this is just something that you'd usually pass as a component property, doesn't feel like it belongs here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm.. I put it there because 'showFavoriteActions' was already there. There is a note above that says '// Not all of these preference map to Compass preferences.', which suggests that what you say used to be true, but at this point maybe we can keep the form preferences together?

Copy link
Collaborator

@gribnoysup gribnoysup Sep 16, 2024

Choose a reason for hiding this comment

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

If we're already diverging from React patterns in an unconventional ways here and don't want to touch this particular part, I guess it's okay to keep it for now like that for consistency, but just want to make sure we all understand that we are leaving more clean up to do after a "clean up" PR here.

My main concern here is that we are copying patterns in compass codebase often from one place to another (which is totally normal), so leaving code like that is always a risk that antipatterns will start spreading through other parts of the codebase

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gribnoysup as discussed, changed the provider into ConnectFormSettingsProvider, which combines compass preferences and other settings (such as the VSCode customizations). externally, these are top level properties

Copy link
Collaborator

@gribnoysup gribnoysup left a comment

Choose a reason for hiding this comment

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

A few small comments, but otherwise looks good

enableOidc: true,
},
updateConnectionFormField,
}: {
connectionStringUrl?: ConnectionStringUrl;
connectionFormPreferences?: Partial<ConnectionFormPreferences>;
ConnectionFormSettings?: Partial<ConnectionFormSettings>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Super small nit: seems like the fist capitalization here is not expected

})
);
const cancelButton = screen.getByRole('button', { name: 'Cancel' });
userEvent.click(cancelButton);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice cleanup, thanks!

export const ConnectionFormPreferencesContext = createContext<
Partial<ConnectionFormPreferences>
export const ConnectionFormSettingsContext = createContext<
Partial<ConnectionFormSettings>
>({});

export const useConnectionFormPreference = <
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we rename the use hook to settings instead of preferences too?

Comment on lines 561 to 577
value={{
showFavoriteActions,
showHelpCardsInForm,
showPersonalisationForm,
protectConnectionStrings,
forceConnectionOptions,
showKerberosPasswordField,
showOIDCDeviceAuthFlow,
enableOidc,
enableDebugUseCsfleSchemaMap,
protectConnectionStringsForNewConnections,
showOIDCAuth,
showKerberosAuth,
showCSFLE,
showProxySettings,
saveAndConnectLabel,
}}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Before we could've passed this value straight to provider without any extra code because the outer code made sure that the object is stable and is not re-created every render, now that we're destructuring here, it would be better to make sure that the value is stable (even if it makes the code a bit weird), so let's wrap the value in useMemo before passing to provider, kinda like this:

const value = useMemo(() => {
  return {
    ... properties
  }
}, [ ... dependencies])

return <Provider value={value}> ... </Provider>

Otherwise anything using the context will be re-rendering erroneously

@paula-stacho paula-stacho merged commit dc13694 into main Sep 27, 2024
27 checks passed
@paula-stacho paula-stacho deleted the COMPASS-8098 branch September 27, 2024 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix no release notes Fix or feature not for release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants