Skip to content

Conversation

lerouxb
Copy link
Contributor

@lerouxb lerouxb commented Oct 9, 2024

This follows on from #6336

new connection

Screenshot 2024-10-09 at 17 04 12

editing a disconnected connection

Screenshot 2024-10-09 at 17 04 05

editing a connected connection

Screenshot 2024-10-09 at 17 03 59

All the buttons do what they say.

The Save&Connect button's label already comes from a setting, so vscode should be unaffected.

Which buttons show up is now entirely determined by which of the three optional callbacks are specified. The onSubmit handler follows the same logic. Save & Connect is the default and Connect is there for the use case where people don't want their credentials to be saved with the connection.

@lerouxb lerouxb changed the title feat(connection-form): up to three buttons: save, connect, save & connect feat(connection-form): up to three buttons: save, connect, save & connect COMPASS-8360 Oct 9, 2024
@github-actions github-actions bot added the feat label Oct 9, 2024
@lerouxb lerouxb marked this pull request as ready for review October 10, 2024 08:13
}
}
onSaveAndConnectClicked={
disableEditingConnectedConnection
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 changed all these to not include the button callback prop if it shouldn't show up. That makes the logic easier and less error prone because you don't have to check both the boolean AND the button to know which buttons to include inside the form and to know which one to call.

disableEditingConnectedConnection is then only used when a button isn't directly involved like when showing the banner.


onCancel?: () => void;

// If onSaveClicked is specified, a Save button will show up. It will be the
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The comments are probably redundant now that the logic has been simplified and all buttons do what they say. But maybe they can guard against that regressing.

const onSubmitForm = useCallback(
(intendedAction?: 'connect' | 'save-and-connect') => {
const updatedConnectionOptions = cloneDeep(connectionOptions);
// TODO: this method throws on malformed connection strings instead of
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Again: This is an old comment.

showCSFLE: true,
showProxySettings: true,
saveAndConnectLabel: 'Connect',
saveAndConnectLabel: 'Save & Connect',
Copy link
Contributor Author

@lerouxb lerouxb Oct 10, 2024

Choose a reason for hiding this comment

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

This is basically the magic that means this PR shouldn't break vscode. The callback was already onSaveAndConnectClicked and my understanding is that vscode already works this way where clicking the primary button in the edit form when editing a non-connected connection will just update everything and connect.

Copy link
Collaborator

Choose a reason for hiding this comment

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

just fyi, VSCode provides it's own settings, it isn't using this hook. in case that's what you meant by this comment, not sure if I got it right. https://github.com/mongodb-js/vscode/blob/bfa57d4ce7b057fadb9fcec95327826f5d0dbb6b/src/views/webview-app/connection-form.tsx#L103

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's what I meant - it uses the setting too. The setting is arguably redundant now, though: both apps set it to the same.

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.

One suggestion, otherwise looks good

@lerouxb lerouxb merged commit 919397b into main Oct 10, 2024
24 of 27 checks passed
@lerouxb lerouxb deleted the save-and-connect branch October 10, 2024 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants