Skip to content

Abort saving if a file cannot be saved #16900

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 5, 2024

Conversation

JasonWeill
Copy link
Contributor

References

Fixes jupyterlab/jupyter-collaboration#364.

Code changes

Aborts saving if the canSave property of the context is false. This is false when the context's model is in collaborative mode.

User-facing changes

When the user presses CTRL+S or +S with Jupyter Collaboration installed, the save command does nothing, and does not cause an error dialog to appear. Without Jupyter Collaboration installed, the command works as it did before.

Backwards-incompatible changes

None.

@JasonWeill JasonWeill added the bug label Oct 29, 2024
Copy link

Thanks for making a pull request to jupyterlab!
To try out this branch on binder, follow this link: Binder

Comment on lines 599 to 604
if (!this.canSave) {
// File cannot be saved.
return Promise.reject();
}
Copy link

Choose a reason for hiding this comment

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

Just for fun, I asked Claude to review this and it reverted with this suggestion:

if (!this.canSave) {
    // File cannot be saved.
    return Promise.reject(new Error('File cannot be saved')); // Add error message
}       

Feel free to ignore Claude! Else it all LGTM.

@jtpio jtpio added this to the 4.3.x milestone Oct 30, 2024
@jtpio
Copy link
Member

jtpio commented Oct 30, 2024

Thanks @JasonWeill for looking into this 👍

The test failures appear to be related though:

image

Comment on lines 599 to 604
if (!this.canSave) {
// File cannot be saved. The "save" command is disabled in the UI,
// but if the user tries to save anyway, act as though it succeeded.
this._saveState.emit('completed');
return Promise.resolve();
}
Copy link
Member

Choose a reason for hiding this comment

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

It would be good to consider what effect it has on the logic for updating the model hash (which is needed to prevent spurious "File Changed" dialogs). This condition prevents updating contentHash as it is performed in _maybeSave method and this condition prevents ever reaching it. I hope this would not be a problem for RTC because it now uses fileChanged signal to propagate new contentHash since:

I also think that it would not make the situation worse for other drives either as in that case they would not update the hash as they could not save the content.

I think that all we need to do is document the side-effects when saving and when saving is skipped, especially if we are going to emit saveState even if the save did not happen.

@krassowski
Copy link
Member

It might be good to document what happens on save (what events are emitted depending on whether save is supported or not) in https://jupyterlab.readthedocs.io/en/latest/extension/documents.html

@krassowski
Copy link
Member

I think the tests failing might be related to canSave being false when _contentsModel is null:

/**
* Whether the document can be saved via the Contents API.
*/
protected get canSave(): boolean {
return !!(this._contentsModel?.writable && !this._model.collaborative);
}

@JasonWeill
Copy link
Contributor Author

@krassowski Tests are passing now! Could you please take another look when you get the chance?

Copy link
Member

@krassowski krassowski left a comment

Choose a reason for hiding this comment

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

Thank you @JasonWeill

@JasonWeill JasonWeill merged commit 7070046 into jupyterlab:main Dec 5, 2024
83 checks passed
@JasonWeill
Copy link
Contributor Author

@meeseeksdev please backport to 4.3.x

meeseeksmachine pushed a commit to meeseeksmachine/jupyterlab that referenced this pull request Dec 5, 2024
JasonWeill added a commit that referenced this pull request Dec 5, 2024
Co-authored-by: Jason Weill <93281816+JasonWeill@users.noreply.github.com>
@JasonWeill
Copy link
Contributor Author

@meeseeksdev please backport to 4.2.x

This was referenced Dec 11, 2024
ImpSy pushed a commit to spotinst/jupyterlab that referenced this pull request Jan 7, 2025
* Revert "Alternate description for disabled filters"

This reverts commit 059fb7e.

* Revert "Revert "Alternate description for disabled filters""

This reverts commit 27ed1d0.

* Aborts saving if the file cannot be saved

* Treat save as successful if canSave is false

* Emit a "completed" event when saving an unsaveable file

* Modifies save check to use collaborative flag
krassowski pushed a commit that referenced this pull request Jan 8, 2025
…saved) (#17050)

* Backport PR #16900: Abort saving if a file cannot be saved

* Updates examples screenshots

---------

Co-authored-by: Jason Weill <93281816+JasonWeill@users.noreply.github.com>
Co-authored-by: Jason Weill <jweill@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ctrl-S is not disabled
4 participants