Skip to content

Conversation

@krassowski
Copy link
Collaborator

@krassowski krassowski commented Jul 1, 2025

@krassowski
Copy link
Collaborator Author

My plan would be:

@krassowski
Copy link
Collaborator Author

bot please update snapshots

@krassowski krassowski force-pushed the read-only-notebook-clean branch from ba55b54 to d3251ed Compare July 2, 2025 08:35
@krassowski
Copy link
Collaborator Author

krassowski commented Jul 2, 2025

bot please update snapshots (again, again, one last time)

@krassowski krassowski force-pushed the read-only-notebook-clean branch from e1d219a to 7fe19d4 Compare July 2, 2025 10:41
@krassowski krassowski marked this pull request as ready for review July 2, 2025 10:43
@krassowski krassowski changed the title Implement view-only notebook Implement view-only notebook using content factory Jul 2, 2025
@krassowski krassowski changed the title Implement view-only notebook using content factory Implement view-only notebook using custom factory Jul 2, 2025
Copy link
Member

@agriyakhetarpal agriyakhetarpal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @krassowski! Your implementation is much better than mine 😄

Not for this PR, but is there a way to remove the "Click to add a cell" container below the cell and the four buttons inside the cell, as they can be used to change the order of the cells/add or delete a cell/etc. (not that those changes will be persisted to CKHub though, but maybe it makes sense to not allow them in the UI if it's a view-only notebook):

image

Comment on lines +161 to +167
"jupyter.lab.transform": true,
"properties": {
"toolbar": {
"title": "View-only notebook panel toolbar items",
"type": "array",
"default": []
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: does this remove the "notebook is read-only" bar as well, as you're not manipulating the DOM to do so and instead adding back the buttons for ViewOnlyNotebook?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that item gets removed too, but in a different way, here:

super({
...options,
toolbar: new FilteredToolbar({
itemsToFilterOut: new Set(['read-only-indicator'])
})
});

class FilteredToolbar extends ReactiveToolbar {
constructor(options: FilteredToolbar.IOptions) {
super(options);
this._itemsToFilterOut = options.itemsToFilterOut;
}
insertItem(index: number, name: string, widget: Widget): boolean {
if (this._itemsToFilterOut?.has(name)) {
return false;
}
return super.insertItem(index, name, widget);
}
// This can be undefined during the super() call in constructor
private _itemsToFilterOut: Set<string> | undefined;
}

Comment on lines +79 to +82
// Even though we have a custom view-only factory, we still
// want to indicate that notebook is read-only to avoid
// error on Ctrl + S and instead get a nice notification that
// the notebook cannot be saved unless using save-as.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One follow-up here after this PR could be to style that notification as well. The default design is pretty neat, so maybe all we need to do is to change the orange-ish colour to something like --je-slate-blue.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we could adjust the styling. Maybe we could track that in a follow-up issue - would you like to open one?

Though orange/yellow is meant to symbolize danger so maybe not a bad choice? But surely there is some rounding and borders we could adjust.

@krassowski
Copy link
Collaborator Author

is there a way to remove the "Click to add a cell" container below the cell and the four buttons inside the cell, as they can be used to change the order of the cells/add or delete a cell/etc. (not that those changes will be persisted to CKHub though, but maybe it makes sense to not allow them in the UI if it's a view-only notebook):

@agriyakhetarpal this is no longer the case with this PR, see:

image

@krassowski krassowski merged commit 129988b into JupyterEverywhere:main Jul 2, 2025
13 checks passed
@krassowski krassowski deleted the read-only-notebook-clean branch July 2, 2025 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Do not allow interactions and do not start a kernel in read-only mode Display the View Only div using the ContentsHeader

2 participants