|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Reactive; |
| 4 | +using System.Threading.Tasks; |
| 5 | +using GitHub.Models; |
| 6 | +using GitHub.ViewModels; |
| 7 | +using GitHub.ViewModels.Documents; |
| 8 | +using ReactiveUI; |
| 9 | + |
| 10 | +namespace GitHub.SampleData.Documents |
| 11 | +{ |
| 12 | + public class PullRequestPageViewModelDesigner : ViewModelBase, IPullRequestPageViewModel |
| 13 | + { |
| 14 | + public PullRequestPageViewModelDesigner() |
| 15 | + { |
| 16 | + Body = @"Save drafts of inline comments, PR reviews and PRs. |
| 17 | +
|
| 18 | +> Note: This feature required a refactoring of the comment view models because they now need async initialization and to be available from GitHub.App. This part of the PR has been submitted separately as #1993 to ease review. The two PRs can alternatively be reviewed as one if that's more convenient. |
| 19 | +
|
| 20 | +As described in #1905, it is easy to lose a comment that you're working on if you close the diff view accidentally. This PR saves drafts of comments as they are being written to an SQLite database. |
| 21 | +
|
| 22 | +In addition to saving drafts of inline comments, it also saves comments to PR reviews and PRs themselves. |
| 23 | +
|
| 24 | +The comments are written to an SQLite database directly instead of going through Akavache because in the case of inline reviews, there can be many drafts in progress on a separate file. When a diff is opened we need to look for any comments present on that file and show the most recent. That use-case didn't fit well with Akavache (being a pure key/value store). |
| 25 | +
|
| 26 | +## Testing |
| 27 | +
|
| 28 | +### Inline Comments |
| 29 | +
|
| 30 | +- Open a PR |
| 31 | +- Open the diff of a file |
| 32 | +- Start adding a comment |
| 33 | +- Close the comment by closing the peek view, or the document tab |
| 34 | +- Reopen the diff |
| 35 | +- You should see the comment displayed in edit mode with the draft of the comment you were previously writing |
| 36 | +
|
| 37 | +### PR reviews |
| 38 | +
|
| 39 | +- Open a PR |
| 40 | +- Click ""Add your review"" |
| 41 | +- Start adding a review |
| 42 | +- Click the ""Back"" button and navigate to a different PR |
| 43 | +- Click the ""Back"" button and navigate to the original PR |
| 44 | +- Click ""Add your review"" |
| 45 | +- You should see the the draft of the review you were previously writing |
| 46 | +
|
| 47 | +### PRs |
| 48 | +
|
| 49 | +-Click ""Create new"" at the top of the PR list |
| 50 | +- Start adding a PR title/ description |
| 51 | +- Close VS |
| 52 | +- Restart VS and click ""Create new"" again |
| 53 | +- You should see the the draft of the PR you were previously writing |
| 54 | +
|
| 55 | +Depends on #1993 |
| 56 | +Fixes #1905"; |
| 57 | + Timeline = new IViewModel[] |
| 58 | + { |
| 59 | + new CommitListViewModel( |
| 60 | + new CommitSummaryViewModel(new CommitModel |
| 61 | + { |
| 62 | + Author = new ActorModel { Login = "grokys" }, |
| 63 | + AbbreviatedOid = "c7c7d25", |
| 64 | + MessageHeadline = "Refactor comment view models." |
| 65 | + }), |
| 66 | + new CommitSummaryViewModel(new CommitModel |
| 67 | + { |
| 68 | + Author = new ActorModel { Login = "shana" }, |
| 69 | + AbbreviatedOid = "04e6a90", |
| 70 | + MessageHeadline = "Refactor comment view models.", |
| 71 | + })), |
| 72 | + new CommentViewModelDesigner |
| 73 | + { |
| 74 | + Author = new ActorViewModelDesigner("meaghanlewis"), |
| 75 | + Body = @"This is looking great! Really enjoying using this feature so far. |
| 76 | +
|
| 77 | +When leaving an inline comment, the comment posts successfully and then a new comment is drafted with the same text.", |
| 78 | + }, |
| 79 | + new CommentViewModelDesigner |
| 80 | + { |
| 81 | + Author = new ActorViewModelDesigner("grokys"), |
| 82 | + Body = @"Oops, sorry about that @meaghanlewis - I was sure I tested those things, but must have got messed up again at some point. Should be fixed now.", |
| 83 | + }, |
| 84 | + }; |
| 85 | + } |
| 86 | + |
| 87 | + public string Id { get; set; } |
| 88 | + public PullRequestState State { get; set; } = PullRequestState.Open; |
| 89 | + public IReadOnlyList<IViewModel> Timeline { get; } |
| 90 | + public string SourceBranchDisplayName { get; set; } = "feature/save-drafts"; |
| 91 | + public string TargetBranchDisplayName { get; set; } = "master"; |
| 92 | + public IActorViewModel Author { get; set; } = new ActorViewModelDesigner("grokys"); |
| 93 | + public int CommitCount { get; set; } = 2; |
| 94 | + public string Body { get; set; } |
| 95 | + public int Number { get; set; } = 1994; |
| 96 | + public LocalRepositoryModel LocalRepository { get; } |
| 97 | + public RemoteRepositoryModel Repository { get; set; } |
| 98 | + public string Title { get; set; } = "Save drafts of comments"; |
| 99 | + public Uri WebUrl { get; set; } |
| 100 | + public ReactiveCommand<Unit, Unit> OpenOnGitHub { get; } |
| 101 | + public ReactiveCommand<string, Unit> ShowCommit { get; } |
| 102 | + |
| 103 | + |
| 104 | + public Task InitializeAsync(RemoteRepositoryModel repository, LocalRepositoryModel localRepository, ActorModel currentUser, PullRequestDetailModel model) |
| 105 | + { |
| 106 | + throw new NotImplementedException(); |
| 107 | + } |
| 108 | + } |
| 109 | +} |
0 commit comments