-
Notifications
You must be signed in to change notification settings - Fork 188
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
Conversation
731f6b1
to
fa57be6
Compare
2e1291f
to
dc18eec
Compare
@@ -125,8 +83,7 @@ function Home({ | |||
hideCollectionSubMenu, | |||
showSettings, | |||
}: Omit<HomeProps, 'connectionStorage'>): React.ReactElement | null { | |||
const appRegistry = useLocalAppRegistry(); | |||
const { connectionInfo, isConnected, disconnect } = | |||
const { isConnected, disconnect } = |
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.
If we're making it impossible to use single connection mode by removing the form, why are we keeping this code here?
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 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', |
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 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
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.
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?
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.
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
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.
@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
9e0a9a7
to
3fa4f60
Compare
3fa4f60
to
e477705
Compare
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.
A few small comments, but otherwise looks good
enableOidc: true, | ||
}, | ||
updateConnectionFormField, | ||
}: { | ||
connectionStringUrl?: ConnectionStringUrl; | ||
connectionFormPreferences?: Partial<ConnectionFormPreferences>; | ||
ConnectionFormSettings?: Partial<ConnectionFormSettings>; |
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.
Super small nit: seems like the fist capitalization here is not expected
}) | ||
); | ||
const cancelButton = screen.getByRole('button', { name: 'Cancel' }); | ||
userEvent.click(cancelButton); |
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.
Nice cleanup, thanks!
export const ConnectionFormPreferencesContext = createContext< | ||
Partial<ConnectionFormPreferences> | ||
export const ConnectionFormSettingsContext = createContext< | ||
Partial<ConnectionFormSettings> | ||
>({}); | ||
|
||
export const useConnectionFormPreference = < |
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.
Should we rename the use hook to settings instead of preferences too?
value={{ | ||
showFavoriteActions, | ||
showHelpCardsInForm, | ||
showPersonalisationForm, | ||
protectConnectionStrings, | ||
forceConnectionOptions, | ||
showKerberosPasswordField, | ||
showOIDCDeviceAuthFlow, | ||
enableOidc, | ||
enableDebugUseCsfleSchemaMap, | ||
protectConnectionStringsForNewConnections, | ||
showOIDCAuth, | ||
showKerberosAuth, | ||
showCSFLE, | ||
showProxySettings, | ||
saveAndConnectLabel, | ||
}} |
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.
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
Description
Preparing the new connection form for VSCode.
New preferences to be set in VSCode:
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):
Checklist
Motivation and Context
Open Questions
Dependents
Types of changes