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

Commit 9b82783

Browse files
committed
add reset viewmodel method
1 parent 9d3ad69 commit 9b82783

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

src/GitHub.App/Controllers/UIController.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ void ConfigureUIHandlingStates()
340340
.PermitDynamic(Trigger.Next, () => Go(Trigger.Next))
341341
.PermitDynamic(Trigger.Cancel, () => Go(Trigger.Cancel))
342342
.PermitDynamic(Trigger.Finish, () => Go(Trigger.Finish))
343-
.OnExit(() => Reset());
343+
.OnExit(() => ResetViewModel(UIViewType.PRCreation));
344344

345345
uiStateMachine.Configure(UIViewType.Login)
346346
.OnEntry(tr => RunView(UIViewType.Login, CalculateDirection(tr)))
@@ -414,6 +414,16 @@ void ConfigureUIHandlingStates()
414414
.Permit(Trigger.Finish, UIViewType.None);
415415
}
416416

417+
void ResetViewModel(UIViewType viewType)
418+
{
419+
var flowList = GetObjectsForFlow(activeFlow);
420+
IUIPair pair;
421+
if (flowList.TryGetValue(viewType, out pair))
422+
{
423+
pair.ViewModel.Reset();
424+
}
425+
}
426+
417427
/// <summary>
418428
/// Configure all the logical state transitions for each of the
419429
/// ui flows we support.

src/GitHub.App/ViewModels/PullRequestCreationViewModel.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,6 @@ public PullRequestCreationViewModel(IRepositoryHost repositoryHost, ISimpleRepos
120120
this.WhenAnyValue(x => x.Initialized, x => x.GitHubRepository, x => x.Description, x => x.IsExecuting)
121121
.Select(x => !(x.Item1 && x.Item2 != null && x.Item3 != null && !x.Item4))
122122
.Subscribe(x => IsBusy = x);
123-
124-
CancelCommand.Subscribe(_ => Reset());
125-
CreatePullRequest.Subscribe(_ => Reset());
126123
}
127124

128125
public override void Initialize(ViewWithData data = null)

src/UnitTests/GitHub.App/Controllers/UIControllerTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using System.ComponentModel;
1717
using System.Collections.ObjectModel;
1818
using GitHub.App.Factories;
19+
using System.Linq;
1920

2021
public class UIControllerTests
2122
{
@@ -636,6 +637,9 @@ public void Flow()
636637
Assert.True(uiController.IsStopped);
637638
Assert.True(success.HasValue);
638639
Assert.False(success);
640+
641+
var vm = provider.GetExportFactoryProvider().GetViewModel(GitHub.Exports.UIViewType.PRCreation).Value;
642+
Assert.Equal(2, vm.ReceivedCalls().Where(x => x.GetMethodInfo().Name == nameof(IViewModel.Reset)).Count());
639643
}
640644
}
641645

0 commit comments

Comments
 (0)