Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Supersedes #239 (after #280 I preferred openning a new PR rather than rebasing).
See jupyterlab/jupyterlab#16008.
This PR adds a menu to the Notebook page (it should add it to every shared document in the future), which allows to choose between "Editing" and "Suggesting". The former is the current state (edit document directly), and the later is an editing mode where edits become suggestions, which is the purpose of this PR.
When entering the suggesting mode, the root provider for the shared document is retrieved and a request to fork the document is done with
context.model.sharedModel.provider.fork()
. This triggers aPUT /api/collaboration/fork_room
request with the root room ID of the document in the body. The response gives back a fork ID, which is the room ID for the forked document that is created in the backend. The forked document is a dependency of the root room, and it is kept in sync with the root document: updates to the root document are applied to the forked document, but not the other way around. The shared document is disconnected from the root provider, and connected to a new provider for the forked document. The forked document is advertised on the root Y document as a newstate
entryfork_{forkId}
, so that other users can connect to the forked room. They can do that by callingWebSocketProvider.connect(forkId, sharedModel)
on their current provider.JupyterLab shows a notification when a client enters the suggestion mode, and the user can choose to view the suggestion or remain on the root document. When viewing the suggestion, changes are synchronized with the suggester and it is also possible to collaborate on the suggestion, since it is a regular room. A user (not the suggester) can merge the suggestion or discard it in the
Review
menu. When merged, aPUT /api/collaboration/merge_room
request is done with the fork room ID and the root room ID in the body.A menu shows which room the document is currently connect to. It can be "Root" for the root room, or the ID of a fork. Users can connect to anyone of them at any time.