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

SLVS-1373 Validate credentials in OrganizationSelectionDialog #5634

Conversation

gabriela-trutan-sonarsource
Copy link
Contributor

@gabriela-trutan-sonarsource gabriela-trutan-sonarsource commented Aug 26, 2024

@terraform-techuser terraform-techuser changed the title SLVS-1373 Validate credentials in OrganizationSelectionDialog SLVS-1373 Validate credentials in OrganizationSelectionDialog Aug 26, 2024
if (manualSelection is true)
var isSelectedManualOrganizationValid = await ValidateManualOrganizationAsync(manualOrganizationSelectionDialog);

if (isSelectedManualOrganizationValid)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this code can be simplified if you remove this check and put the old check back. It would assign SelectedOrganization whichever value is selected (list or manual), and then always validate the SelectedOrganization in ViewModel in a uniform way. The error text can be made generic to not worry about mentioning manual organization selection in it. This will be even more relevant once we add the duplication check.

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 removed the assigning of the SelectedOrganization from the manual selection for two reasons:

  • Once the SelectedOrganization is assigned, the OK button becomes enabled. This should not be the case, though, because the organization is not valid. Therefore not assigning the SelectedOrganization in the first place, makes it more consistent.

  • The SelectedOrganization refers to the organization selected from the list. But the manual one that was chosen is not part of the list. This brings a lot of confusion: the view model property (hence also the Combobox.SelectedItem) is set to a string, but that string is not part of the list. You will notice that WPF does not add a combobox item that is selected, if you bind its view model to a string (as long as it's not part of the list, then it should not be a selected one)

  • It is more understanding for the user to have separate error messages for the manual selection or for the list selection. Imagine that the list of organizations is long. It would be very difficult for the user to know which organization was wrong, without scrolling like crazy and trying to find out if the organization was from the list or a manual one that he entered.

Choose a reason for hiding this comment

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

We can split the list selection from the value that is validated (the organization value then can be passed as a parameter to ViewModel.Validate). SelectedOrganization can be reset after validation fails. The error text can include the organization key. There will be no confusion if we reset selection and show the key in the error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What is the gain of setting the SelectedOrganization if we will anyway pass the organization value to the Validate method?

Copy link
Contributor

Choose a reason for hiding this comment

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

So the thing is. We will need to do a few common things for both scenarious

  1. catch exception for both manual and list selection 😉
  2. show duplication errors with connection id
  3. set some sort of final value for the manage connections dialog to use. currently we create connectioninfo here, discard it, and then create another connecioninfo in manage connections dialog using SelectedOrganization

Try to tick all 3 of those boxes with refactoring. You don't have to do it in the way I initially suggested (I though it was a bit more simple to fix)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Point 1 and 2 are solved by the fact that we use the same method in the ViewModel: ValidateConnectionForOrganizationAsync

I could work on point 3 and find a different approach

@@ -76,4 +80,24 @@ internal void UpdateOrganizations(AdapterResponseWithData<List<OrganizationDispl
responseWithData.ResponseData.ForEach(AddOrganization);
RaisePropertyChanged(nameof(NoOrganizationExists));
}

internal async Task<bool> ValidateConnectionForOrganizationAsync(string organizationKey, string warningText)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can be made private, see other comment. The warning text does not need to be parametrized as well.

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 think it does. For usability purposes.

…f ConnectionInfo in ManageConnectionsDialog and OrganizationSelection

private void OnConnectionValidationSucceeded(string organizationKey)
{
ViewModel.UpdateConnectionInfo(organizationKey);

Choose a reason for hiding this comment

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

why not call this inside the validation method and use the ConnectionInfo object that was already created there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because it should only be done once the validation succeeded and the dialog is closed.

Copy link
Contributor

Choose a reason for hiding this comment

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

You can automatically assign ConnectionInfo on adapterResponse.Success. I would also keep the default value as null rather than (null, SonarCloud), to make it more clear that it hasn't been set

@@ -35,6 +40,7 @@ public OrganizationDisplay SelectedOrganization
set
{
selectedOrganization = value;
UpdateConnectionInfo(selectedOrganization?.Key);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here

…ame method. Remove logic to keep ConnectionInfo in sync with the selected organization
Copy link

@georgii-borovinskikh-sonarsource georgii-borovinskikh-sonarsource merged commit 02f0efd into feature/new-connected-mode Aug 27, 2024
5 checks passed
@georgii-borovinskikh-sonarsource georgii-borovinskikh-sonarsource deleted the gt/organizations-dialog-validate-connection branch August 27, 2024 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants