{"action":"created","issue":{"url":"https://api.github.com/repos/hypothesis/h/issues/2689","labels_url":"https://api.github.com/repos/hypothesis/h/issues/2689/labels{/name}","comments_url":"https://api.github.com/repos/hypothesis/h/issues/2689/comments","events_url":"https://api.github.com/repos/hypothesis/h/issues/2689/events","html_url":"https://github.com/hypothesis/h/pull/2689","id":114072209,"number":2689,"title":"Avoid losing unsaved changes to new or existing annotations when switching groups","user":{"login":"robertknight","id":2458,"avatar_url":"https://avatars.githubusercontent.com/u/2458?v=3","gravatar_id":"","url":"https://api.github.com/users/robertknight","html_url":"https://github.com/robertknight","followers_url":"https://api.github.com/users/robertknight/followers","following_url":"https://api.github.com/users/robertknight/following{/other_user}","gists_url":"https://api.github.com/users/robertknight/gists{/gist_id}","starred_url":"https://api.github.com/users/robertknight/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robertknight/subscriptions","organizations_url":"https://api.github.com/users/robertknight/orgs","repos_url":"https://api.github.com/users/robertknight/repos","events_url":"https://api.github.com/users/robertknight/events{/privacy}","received_events_url":"https://api.github.com/users/robertknight/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-10-29T15:17:08Z","updated_at":"2015-10-30T10:49:23Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/hypothesis/h/pulls/2689","html_url":"https://github.com/hypothesis/h/pull/2689","diff_url":"https://github.com/hypothesis/h/pull/2689.diff","patch_url":"https://github.com/hypothesis/h/pull/2689.patch"},"body":"This PR fixes two issues related to creating or editing annotations and switching groups:\r\n\r\n * I create a new annotation, realize that I have the wrong group selected and then switch to the intended group. In master, the annotation remains in the previous group and I have to (a) delete it and (b) re-create it in the new group\r\n * I start editing an annotation, then switch to another group. In master, the unsaved changes are lost with no warning. At least when you logout you get a prompt as to whether you want to keep or discard changes.\r\n\r\nThe end-user behavior of this PR is:\r\n\r\n * When switching groups, new annotations are moved to the newly selected group and the text and tags that has been entered so far are preserved.\r\n * When switching groups, in-progress edits to existing annotations are kept. The draft will not be shown when viewing the new group but will re-appear with unsaved edits intact when switching back to the original group.\r\n\r\nThe implementation involves:\r\n\r\n * Replacing the drafts service with one which stores not just the identities of annotations\r\n   which are being edited also the changes to text and tags of the draft.\r\n * Not discarding drafts when an annotation is unloaded\r\n * Moving new annotations to the newly focused group when the focused group changes\r\n \r\nI also added some documentation on what the threading service is for whilst I was grokking the code.\r\n\r\n----\r\nTODO\r\n* [X] Check if not reloading the view when the focused group changes is something that can be split out into a separate PR. I originally thought it was essential but now I'm not so sure. _Update: Yes, it looks like this is not critical and can be moved into a separate PR_\r\n* [X] Look into an issue where, when switching groups, new annotations are posted to the currently selected group, but the 'Post to' button does not update. _Update: This is an existing bug in the Post button. I'll fix it and clean up the code for that in a separate PR: #2691_\r\n* [X] Add tests to check that the annotation controller saves and restores drafts as expected\r\n* [X] Check that the behavior of discarding changes on logout is consistent with what we had before. _This was broken but is fixed by the last commit_"},"comment":{"url":"https://api.github.com/repos/hypothesis/h/issues/comments/152491456","html_url":"https://github.com/hypothesis/h/pull/2689#issuecomment-152491456","issue_url":"https://api.github.com/repos/hypothesis/h/issues/2689","id":152491456,"user":{"login":"robertknight","id":2458,"avatar_url":"https://avatars.githubusercontent.com/u/2458?v=3","gravatar_id":"","url":"https://api.github.com/users/robertknight","html_url":"https://github.com/robertknight","followers_url":"https://api.github.com/users/robertknight/followers","following_url":"https://api.github.com/users/robertknight/following{/other_user}","gists_url":"https://api.github.com/users/robertknight/gists{/gist_id}","starred_url":"https://api.github.com/users/robertknight/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robertknight/subscriptions","organizations_url":"https://api.github.com/users/robertknight/orgs","repos_url":"https://api.github.com/users/robertknight/repos","events_url":"https://api.github.com/users/robertknight/events{/privacy}","received_events_url":"https://api.github.com/users/robertknight/received_events","type":"User","site_admin":false},"created_at":"2015-10-30T10:49:23Z","updated_at":"2015-10-30T10:49:23Z","body":"> 1. Edit an annotation, change its privacy e.g. from Only Me to Group\r\n> 2. Change the focus to another group\r\n> 3. Change the focus back to the original group. The annotation that is being edited has its privacy set to Only Me again\r\n\r\nI noticed this as well but I think it would be better to fix this after your permissions handling refactoring is done."}}