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

Commit 620962e

Browse files
committed
Merge pull request #162 from github/shana/fix-publish-completion
Fix publish form not going away when done
2 parents 68157d0 + b495516 commit 620962e

File tree

9 files changed

+79
-45
lines changed

9 files changed

+79
-45
lines changed

src/GitHub.App/Controllers/UIController.cs

+25-9
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ enum Trigger { Cancel = 0, Auth = 1, Create = 2, Clone = 3, Publish = 4, Next, F
3636
readonly CompositeDisposable disposables = new CompositeDisposable();
3737
readonly StateMachine<UIViewType, Trigger> machine;
3838
Subject<UserControl> transition;
39+
Subject<bool> completion;
3940
UIControllerFlow currentFlow;
4041
NotifyCollectionChangedEventHandler connectionAdded;
4142

@@ -118,17 +119,10 @@ public UIController(IUIProvider uiProvider, IRepositoryHosts hosts, IExportFacto
118119
.Permit(Trigger.Next, UIViewType.End);
119120

120121
machine.Configure(UIViewType.End)
121-
.OnEntry(() =>
122-
{
123-
uiProvider.RemoveService(typeof(IConnection));
124-
transition.OnCompleted();
125-
})
122+
.OnEntryFrom(Trigger.Cancel, () => End(false))
123+
.OnEntryFrom(Trigger.Next, () => End(true))
126124
.Permit(Trigger.Next, UIViewType.Finished);
127125

128-
// it might be useful later to check which triggered
129-
// made us enter here (Cancel or Next) and set a final
130-
// result accordingly, which is why UIViewType.End only
131-
// allows a Next trigger
132126
machine.Configure(UIViewType.Finished);
133127
}
134128

@@ -142,6 +136,27 @@ public IObservable<UserControl> SelectFlow(UIControllerFlow choice)
142136
return transition;
143137
}
144138

139+
/// <summary>
140+
/// Allows listening to the completion state of the ui flow - whether
141+
/// it was completed because it was cancelled or whether it succeeded.
142+
/// </summary>
143+
/// <returns>true for success, false for cancel</returns>
144+
public IObservable<bool> ListenToCompletionState()
145+
{
146+
if (completion == null)
147+
completion = new Subject<bool>();
148+
return completion;
149+
}
150+
151+
void End(bool success)
152+
{
153+
uiProvider.RemoveService(typeof(IConnection));
154+
transition.OnCompleted();
155+
completion?.OnNext(success);
156+
completion?.OnCompleted();
157+
completion = null;
158+
}
159+
145160
void RunView(UIViewType viewType)
146161
{
147162
var view = CreateViewAndViewModel(viewType);
@@ -281,6 +296,7 @@ protected virtual void Dispose(bool disposing)
281296
Debug.WriteLine("Disposing ({0})", GetHashCode());
282297
disposables.Dispose();
283298
transition?.Dispose();
299+
completion?.Dispose();
284300
if (connectionAdded != null)
285301
connectionManager.Connections.CollectionChanged -= connectionAdded;
286302
connectionAdded = null;

src/GitHub.App/SampleData/SampleViewModels.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public bool IsPublishing
249249
private set;
250250
}
251251

252-
public IReactiveCommand<Unit> PublishRepository
252+
public IReactiveCommand<ProgressState> PublishRepository
253253
{
254254
get;
255255
private set;

src/GitHub.App/ViewModels/RepositoryPublishViewModel.cs

+10-7
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public RepositoryPublishViewModel(
117117
public bool CanKeepPrivate { get { return canKeepPrivate.Value; } }
118118
public bool IsPublishing { get { return isPublishing.Value; } }
119119

120-
public IReactiveCommand<Unit> PublishRepository { get; private set; }
120+
public IReactiveCommand<ProgressState> PublishRepository { get; private set; }
121121
public ReactiveList<IConnection> Connections { get; private set; }
122122

123123
IConnection selectedConnection;
@@ -145,29 +145,32 @@ public bool IsHostComboBoxVisible
145145
get { return isHostComboBoxVisible.Value; }
146146
}
147147

148-
ReactiveCommand<Unit> InitializePublishRepositoryCommand()
148+
ReactiveCommand<ProgressState> InitializePublishRepositoryCommand()
149149
{
150150
var canCreate = this.WhenAny(x => x.RepositoryNameValidator.ValidationResult.IsValid, x => x.Value);
151151
return ReactiveCommand.CreateAsyncObservable(canCreate, OnPublishRepository);
152152
}
153153

154-
private IObservable<Unit> OnPublishRepository(object arg)
154+
IObservable<ProgressState> OnPublishRepository(object arg)
155155
{
156156
var newRepository = GatherRepositoryInfo();
157157
var account = SelectedAccount;
158158

159159
return repositoryPublishService.PublishRepository(newRepository, account, SelectedHost.ApiClient)
160-
.SelectUnit()
161-
.Do(_ => vsServices.ShowMessage("Repository published successfully."))
162-
.Catch<Unit, Exception>(ex =>
160+
.Select(_ =>
161+
{
162+
vsServices.ShowMessage("Repository published successfully.");
163+
return ProgressState.Success;
164+
})
165+
.Catch<ProgressState, Exception>(ex =>
163166
{
164167
if (!ex.IsCriticalException())
165168
{
166169
log.Error(ex);
167170
var error = new PublishRepositoryUserError(ex.Message);
168171
vsServices.ShowError((error.ErrorMessage + Environment.NewLine + error.ErrorCauseOrResolution).TrimEnd());
169172
}
170-
return Observable.Return(Unit.Default);
173+
return Observable.Return(ProgressState.Fail);
171174
});
172175
}
173176

src/GitHub.Exports.Reactive/ViewModels/IRepositoryPublishViewModel.cs

+10-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public interface IRepositoryPublishViewModel : IRepositoryForm
1111
/// <summary>
1212
/// Command that creates the repository.
1313
/// </summary>
14-
IReactiveCommand<Unit> PublishRepository { get; }
14+
IReactiveCommand<ProgressState> PublishRepository { get; }
1515

1616
/// <summary>
1717
/// True when publishing is in progress.
@@ -33,4 +33,13 @@ public interface IRepositoryPublishViewModel : IRepositoryForm
3333
/// </summary>
3434
string DefaultRepositoryName { get; }
3535
}
36+
37+
public enum ProgressState
38+
{
39+
Idle,
40+
Running,
41+
Success,
42+
Fail
43+
}
44+
3645
}

src/GitHub.Exports/UI/IUIController.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@ namespace GitHub.UI
77
{
88
public interface IUIController
99
{
10-
//IObservable<object> Transition { get; }
1110
IObservable<UserControl> SelectFlow(UIControllerFlow choice);
11+
/// <summary>
12+
/// Allows listening to the completion state of the ui flow - whether
13+
/// it was completed because it was cancelled or whether it succeeded.
14+
/// </summary>
15+
/// <returns>true for success, false for cancel</returns>
16+
IObservable<bool> ListenToCompletionState();
1217
void Start(IConnection connection);
1318
void Stop();
1419
bool IsStopped { get; }

src/GitHub.UI.Reactive/Controls/SimpleViewUserControl.cs

+9
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,27 @@ public SimpleViewUserControl()
4343

4444
protected void NotifyDone()
4545
{
46+
if (disposed)
47+
return;
48+
4649
close.OnNext(null);
4750
close.OnCompleted();
4851
}
4952

5053
protected void NotifyCancel()
5154
{
55+
if (disposed)
56+
return;
57+
5258
cancel.OnNext(null);
5359
cancel.OnCompleted();
5460
}
5561

5662
protected void NotifyIsBusy(bool busy)
5763
{
64+
if (disposed)
65+
return;
66+
5867
isBusy.OnNext(busy);
5968
}
6069

src/GitHub.VisualStudio/TeamExplorer/Sync/GitHubPublishSection.cs

+9-21
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public GitHubPublishSection(ISimpleApiClientFactory apiFactory, ITeamExplorerSer
5050
view.DataContext = this;
5151
}
5252

53-
async void RTMSetup()
53+
async void Setup()
5454
{
5555
if (ActiveRepo != null && ActiveRepoUri == null)
5656
{
@@ -64,34 +64,16 @@ async void RTMSetup()
6464
IsVisible = false;
6565
}
6666

67-
async void PreRTMSetup()
68-
{
69-
if (ActiveRepo != null && ActiveRepoUri == null)
70-
{
71-
IsVisible = true;
72-
loggedIn = await connectionManager.IsLoggedIn(hosts);
73-
if (loggedIn)
74-
ShowPublish();
75-
else
76-
{
77-
ShowGetStarted = true;
78-
ShowSignup = true;
79-
}
80-
}
81-
else
82-
IsVisible = false;
83-
}
84-
8567
public override void Initialize(IServiceProvider serviceProvider)
8668
{
8769
base.Initialize(serviceProvider);
88-
RTMSetup();
70+
Setup();
8971
}
9072

9173
protected override void RepoChanged()
9274
{
9375
base.RepoChanged();
94-
RTMSetup();
76+
Setup();
9577
}
9678

9779
public async void Connect()
@@ -135,6 +117,12 @@ void ShowPublish()
135117
disposable = uiflow;
136118
var ui = uiflow.Value;
137119
var creation = ui.SelectFlow(UIControllerFlow.Publish);
120+
ui.ListenToCompletionState().Subscribe(done =>
121+
{
122+
IsVisible = false;
123+
ServiceProvider.TryGetService<ITeamExplorer>()?.NavigateToPage(new Guid(TeamExplorerPageIds.Home), null);
124+
});
125+
138126
creation.Subscribe(c =>
139127
{
140128
SectionContent = c;

src/GitHub.VisualStudio/UI/Views/Controls/RepositoryPublishControl.xaml.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ public RepositoryPublishControl()
4444
d(this.OneWayBind(ViewModel, vm => vm.IsPublishing, v => v.description.IsEnabled, x => x == false));
4545
d(this.OneWayBind(ViewModel, vm => vm.IsPublishing, v => v.accountsComboBox.IsEnabled, x => x == false));
4646

47-
ViewModel.PublishRepository.Subscribe(_ => NotifyDone());
47+
ViewModel.PublishRepository.Subscribe(state =>
48+
{
49+
if (state == ProgressState.Success)
50+
NotifyDone();
51+
});
4852

4953
d(this.WhenAny(x => x.ViewModel.IsPublishing, x => x.Value)
5054
.Subscribe(x => NotifyIsBusy(x)));

src/UnitTests/GitHub.App/ViewModels/RepositoryPublishViewModelTests.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ public async Task DisplaysSuccessMessageWhenCompletedWithoutError()
339339

340340
vm.RepositoryName = "repo-name";
341341

342-
await vm.PublishRepository.ExecuteAsync().Catch(Observable.Return(Unit.Default));
342+
await vm.PublishRepository.ExecuteAsync().Catch(Observable.Return(ProgressState.Success));
343343

344344
vsServices.Received().ShowMessage("Repository published successfully.");
345345
vsServices.DidNotReceive().ShowError(Args.String);
@@ -358,7 +358,7 @@ public async Task DisplaysRepositoryExistsErrorWithVisualStudioNotifications()
358358
var vm = Helpers.SetupConnectionsAndViewModel(hosts, repositoryPublishService, vsServices, cm);
359359
vm.RepositoryName = "repo-name";
360360

361-
await vm.PublishRepository.ExecuteAsync().Catch(Observable.Return(Unit.Default));
361+
await vm.PublishRepository.ExecuteAsync().Catch(Observable.Return(ProgressState.Fail));
362362

363363
vsServices.DidNotReceive().ShowMessage(Args.String);
364364
vsServices.Received().ShowError("There is already a repository named 'repo-name' for the current account.");
@@ -391,7 +391,7 @@ public async Task ClearsErrorsWhenSwitchingHosts()
391391

392392
vm.RepositoryName = "repo-name";
393393

394-
await vm.PublishRepository.ExecuteAsync().Catch(Observable.Return(Unit.Default));
394+
await vm.PublishRepository.ExecuteAsync().Catch(Observable.Return(ProgressState.Fail));
395395

396396
vm.SelectedConnection = conns.First(x => x != vm.SelectedConnection);
397397

@@ -422,7 +422,7 @@ public async Task ClearsErrorsWhenSwitchingAccounts()
422422

423423
vm.RepositoryName = "repo-name";
424424

425-
await vm.PublishRepository.ExecuteAsync().Catch(Observable.Return(Unit.Default));
425+
await vm.PublishRepository.ExecuteAsync().Catch(Observable.Return(ProgressState.Fail));
426426

427427
vm.SelectedAccount = accounts[1];
428428

0 commit comments

Comments
 (0)