Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Apr 5, 2024
1 parent a63043a commit 35f57be
Showing 1 changed file with 39 additions and 48 deletions.
87 changes: 39 additions & 48 deletions packages/collaboration-extension/src/collaboration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,77 +324,68 @@ export class EditingModeExtension implements DocumentRegistry.IWidgetExtension<N
changes.stateChange.forEach(value => {
const forkPrefix = 'fork_';
if (value.name === 'merge' || value.name === 'delete') {
// FIXME: a client who is not connected to the fork should not see this update
// we are on fork
if (sharedModel.currentRoomId === value.newValue) {
editingMenu.title.label = 'Editing';
suggestionMenu.title.label = 'Root';
const item: Menu.IItem = suggestions[value.newValue];
delete suggestions[value.newValue];
suggestionMenu.removeItem(item);
reviewMenu.clearItems();
const merge = value.name === 'merge';
sharedModel.provider.connect(sharedModel.rootRoomId, merge);
open_dialog('Editing', this._trans);
myForkId = '';
}
}
else if (value.name.startsWith(forkPrefix)) {
// we are on root
const forkId = value.name.slice(forkPrefix.length);
if (value.newValue === 'new') {
suggestionCommands.addCommand(forkId, {
label: forkId,
execute: () => {
if (myForkId === forkId) {
editingMenu.title.label = 'Suggesting';
// our suggestion, cannot be reviewed
reviewMenu.clearItems();
}
else {
editingMenu.title.label = 'Editing';
// not our suggestion, can be reviewed
reviewMenu.clearItems();
reviewMenu.addItem({type: 'command', command: 'merge'});
reviewMenu.addItem({type: 'command', command: 'discard'});
}
editingMenu.title.label = 'Suggesting';
reviewMenu.clearItems();
reviewMenu.addItem({type: 'command', command: 'merge'});
reviewMenu.addItem({type: 'command', command: 'discard'});
suggestionMenu.title.label = forkId;
sharedModel.provider.connect(forkId);
open_dialog('Suggesting', this._trans);
}
});
const item = suggestionMenu.addItem({type: 'command', command: forkId});
suggestions[forkId] = item;
if ((myForkId !== 'pending') && (myForkId !== forkId)) {
const dialog = new Dialog({
title: this._trans.__('New suggestion'),
body: this._trans.__('View suggestion?'),
buttons: [
Dialog.okButton({ label: 'View' }),
Dialog.cancelButton({ label: 'Discard' }),
],
});
dialog.launch().then(resp => {
dialog.close();
if (resp.button.label === 'View') {
sharedModel.provider.connect(forkId);
suggestionMenu.title.label = forkId;
editingMenu.title.label = 'Editing';
reviewMenu.clearItems();
reviewMenu.addItem({type: 'command', command: 'merge'});
reviewMenu.addItem({type: 'command', command: 'discard'});
}
});
if (myForkId !== forkId) {
if (myForkId !== 'pending') {
const dialog = new Dialog({
title: this._trans.__('New suggestion'),
body: this._trans.__('View suggestion?'),
buttons: [
Dialog.okButton({ label: 'View' }),
Dialog.cancelButton({ label: 'Discard' }),
],
});
dialog.launch().then(resp => {
dialog.close();
if (resp.button.label === 'View') {
sharedModel.provider.connect(forkId);
suggestionMenu.title.label = forkId;
editingMenu.title.label = 'Suggesting';
reviewMenu.clearItems();
reviewMenu.addItem({type: 'command', command: 'merge'});
reviewMenu.addItem({type: 'command', command: 'discard'});
}
});
}
else {
reviewMenu.clearItems();
reviewMenu.addItem({type: 'command', command: 'merge'});
reviewMenu.addItem({type: 'command', command: 'discard'});
}
}
}
else if (value.newValue === undefined) {
if (sharedModel.currentRoomId === forkId) {
editingMenu.title.label = 'Editing';
suggestionMenu.title.label = 'Root';
const item: Menu.IItem = suggestions[value.newValue];
delete suggestions[value.newValue];
suggestionMenu.removeItem(item);
reviewMenu.clearItems();
sharedModel.provider.connect(sharedModel.rootRoomId);
open_dialog('Editing', this._trans);
}
editingMenu.title.label = 'Editing';
suggestionMenu.title.label = 'Root';
const item: Menu.IItem = suggestions[value.oldValue];
delete suggestions[value.oldValue];
suggestionMenu.removeItem(item);
}
}
});
Expand Down

0 comments on commit 35f57be

Please sign in to comment.