Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Clear Pull Request Form when canceled or completed. #523

Closed
paladique wants to merge 11 commits intomasterfrom
fixes/479-clear-pr-creation-form
Closed

Clear Pull Request Form when canceled or completed. #523
paladique wants to merge 11 commits intomasterfrom
fixes/479-clear-pr-creation-form

Conversation

@paladique
Copy link
Contributor

Fixes #479

Instead subscribing to the cancel and completion actions of the PullRequestCreation view model, ResetViewModel() was added to IViewModel that will execute the VMs overridden BaseViewModel's Reset(),

private set;
}

public ICommand Reset
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 had to the option to remove or hide this with new, I decided to remove it since this was not in use anywhere,

@paladique paladique force-pushed the fixes/479-clear-pr-creation-form branch from 2696454 to 35d1a98 Compare August 26, 2016 15:47
}

public override void Reset()
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Indentation is weird here.

@shana
Copy link
Contributor

shana commented Aug 29, 2016

So to avoid adding the Reset method to the GitHubPaneViewModel, which doesn't need it, an more interesting implementation can be:

  • Add a new interface called IResettable and move the Reset method definition in it
  • Add the new interface to the list of interfaces that the PullRequestCreationViewModel implements
  • In the UIController reset method, check whether the view model is an IResettable and only call the method if it is.

@paladique paladique force-pushed the fixes/479-clear-pr-creation-form branch from 29bdb09 to c0c6fa8 Compare September 6, 2016 21:38
var vm = pair.ViewModel as IResettable;
//TODO:Can I even do this?
//vm?.Reset();
vm?.Reset();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This seems like a handy C# 6 thing! What I'm doing here is using the null conditional operator to speculate that the VM could be a member of IResettable and to access Reset() if it is, so if vm is null, and the operator avoids a null reference exception

Copy link
Contributor

Choose a reason for hiding this comment

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

Yup, this is a very handy thing indeed!

@shana
Copy link
Contributor

shana commented Sep 12, 2016

@paladique I forget, did we figure out why these tests fail in CI? Do they pass in Visual Studio?

@paladique paladique force-pushed the fixes/479-clear-pr-creation-form branch from 4e3cbf8 to 2271bb2 Compare September 12, 2016 19:50
@paladique
Copy link
Contributor Author

@shana ran the tests in VS and it's failing on the new test added for the Reset() method, ResetIsCalled(). Clearing the form is successful when doing it in the UI, but in the test vm?.Reset() is skipped because the PullRequestCreationProxy is not being recognized as a member of IResettable

Should I be mocking IResettable in some way? That seems unnecessary because PullRequestCreation is already a member. This must be missing something else.

@shana
Copy link
Contributor

shana commented Sep 12, 2016

Oh! Yes, you need to mark the viewmodel as IResettable so it's recognized as such. We already do that for some views here: https://github.com/github/VisualStudio/blob/master/src/UnitTests/GitHub.App/Controllers/UIControllerTests.cs#L44-L47

You need to do it for the viewmodel in the SetupViewModel method.

@paladique
Copy link
Contributor Author

This was mostly an exploratory PR, so closing for now!

@paladique paladique closed this Jan 9, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants