From f8e2cc4de33e60e997299363b514741379fd135e Mon Sep 17 00:00:00 2001 From: George Gevoian Date: Tue, 7 Dec 2021 12:42:03 -0800 Subject: [PATCH] (core) Skip saving column resizes in read-only mode Summary: This makes it so a notification about insufficient write access is no longer shown every time a user in a read-only document resizes a column. Test Plan: Browser test. Reviewers: jarek Reviewed By: jarek Differential Revision: https://phab.getgrist.com/D3171 --- app/client/components/GridView.js | 2 +- app/client/components/viewCommon.js | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/client/components/GridView.js b/app/client/components/GridView.js index d5968be0..d6a597bf 100644 --- a/app/client/components/GridView.js +++ b/app/client/components/GridView.js @@ -890,7 +890,7 @@ GridView.prototype.buildDom = function() { dom.testId("GridView_columnLabel"), kd.style('width', field.widthPx), kd.style('borderRightWidth', v.borderWidthPx), - viewCommon.makeResizable(field.width), + viewCommon.makeResizable(field.width, {shouldSave: !this.gristDoc.isReadonly.get()}), kd.toggleClass('selected', () => ko.unwrap(this.isColSelected.at(field._index()))), dom.on('contextmenu', ev => { // This is a little hack to position the menu the same way as with a click diff --git a/app/client/components/viewCommon.js b/app/client/components/viewCommon.js index ac076035..377854f6 100644 --- a/app/client/components/viewCommon.js +++ b/app/client/components/viewCommon.js @@ -21,7 +21,7 @@ $.ui.resizable.prototype._respectSize = function() { /** * When used as an argument to dom() function, makes the containing element resizable, with the * size written into the given observable. If the observable has a .save() method, it's called - * when the resize is complete (to save the new size to the server). + * by default when the resize is complete (to save the new size to the server). * @param {Object} options.enabled: An observable, a constant, or a function for a computed * observable. The value is treated as a boolean, and determined whether resizable * functionality is enabled. @@ -31,6 +31,8 @@ $.ui.resizable.prototype._respectSize = function() { * @param {Boolean} options.isFlex: If true, will avoid changing 'left' when resizing the left edge. * @param {Number} options.minWidth: The minimum width the element can be resized to. * Defaults to 10 (JQuery default). + * @param {Boolean} options.shouldSave: Whether .save() on `widthObservable` should be called. + * Defaults to true. */ function makeResizable(widthObservable, options) { options = options || {}; @@ -40,7 +42,7 @@ function makeResizable(widthObservable, options) { if (options.stop) { options.stop(e, ui); } - if (widthObservable.save) { + if (widthObservable.save && options.shouldSave !== false) { widthObservable.save(); } }