mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Fix hidden columns bug when editing data selection
Summary: Editing data selection would sometimes cause columns to be hidden in the updated view. A missing conditional was the culprit: generally, field visibility shouldn't be modified after the view is updated, but we make an exception for charts to keep certain fields visible or hidden between updates, so that chart configuration doesn't change too significantly and cause unexpected data to be displayed. This special behavior for charts was erroneously being applied to non-charts as well. Also, when no columns were visible in a view, opening the row menu would cause an error to be thrown. A loop was inadvertently using null control variables - an explicit check for non-null loop variables was added, which skips the loop when no columns are visible. Test Plan: Browser tests. Reviewers: jarek Reviewed By: jarek Subscribers: jarek Differential Revision: https://phab.getgrist.com/D3650
This commit is contained in:
@@ -339,7 +339,10 @@ BaseView.prototype.getAnchorLinkForSection = function(sectionId) {
|
||||
// Note that this case only happens in combination with the widget linking mentioned.
|
||||
// If the table is empty but the 'new record' row is selected, the `viewData.getRowId` line above works.
|
||||
|| 'new';
|
||||
const colRef = this.viewSection.viewFields().peek()[this.cursor.fieldIndex.peek()].colRef.peek();
|
||||
// The `fieldIndex` will be null if there are no visible columns.
|
||||
const fieldIndex = this.cursor.fieldIndex.peek();
|
||||
const field = fieldIndex !== null ? this.viewSection.viewFields().peek()[fieldIndex] : null;
|
||||
const colRef = field?.colRef.peek();
|
||||
return {hash: {sectionId, rowId, colRef}};
|
||||
}
|
||||
|
||||
|
||||
@@ -539,12 +539,16 @@ GridView.prototype.getSelection = function() {
|
||||
rowEnd = this.getLastDataRowIndex();
|
||||
}
|
||||
|
||||
var rowId;
|
||||
for(var i = colStart; i <= colEnd; i++) {
|
||||
let field = this.viewSection.viewFields().at(i);
|
||||
fields.push(field);
|
||||
colStyle[field.colId()] = this._getColStyle(i);
|
||||
// Start or end will be null if no fields are visible.
|
||||
if (colStart !== null && colEnd !== null) {
|
||||
for(var i = colStart; i <= colEnd; i++) {
|
||||
let field = this.viewSection.viewFields().at(i);
|
||||
fields.push(field);
|
||||
colStyle[field.colId()] = this._getColStyle(i);
|
||||
}
|
||||
}
|
||||
|
||||
var rowId;
|
||||
for(var j = rowStart; j <= rowEnd; j++) {
|
||||
rowId = this.viewData.getRowId(j);
|
||||
rowIds.push(rowId);
|
||||
|
||||
@@ -666,7 +666,7 @@ export class GristDoc extends DisposableWithEvents {
|
||||
// if table changes or a table is made a summary table, let's replace the view section by a
|
||||
// new one, and return.
|
||||
if (oldVal.table !== newVal.table || oldVal.summarize !== newVal.summarize) {
|
||||
return await this._replaceViewSection(section, newVal);
|
||||
return await this._replaceViewSection(section, oldVal, newVal);
|
||||
}
|
||||
|
||||
// if type changes, let's save it.
|
||||
@@ -1072,7 +1072,11 @@ export class GristDoc extends DisposableWithEvents {
|
||||
return await invokePrompt("Table name", "Create", '', "Default table name");
|
||||
}
|
||||
|
||||
private async _replaceViewSection(section: ViewSectionRec, newVal: IPageWidget) {
|
||||
private async _replaceViewSection(
|
||||
section: ViewSectionRec,
|
||||
oldVal: IPageWidget,
|
||||
newVal: IPageWidget
|
||||
) {
|
||||
|
||||
const docModel = this.docModel;
|
||||
const viewModel = section.view();
|
||||
@@ -1108,8 +1112,10 @@ export class GristDoc extends DisposableWithEvents {
|
||||
// persist options
|
||||
await newSection.options.saveOnly(options);
|
||||
|
||||
// persist view fields if possible
|
||||
await this.setSectionViewFieldsFromArray(newSection, colIds);
|
||||
// charts needs to keep view fields consistent across updates
|
||||
if (oldVal.type === 'chart' && newVal.type === 'chart') {
|
||||
await this.setSectionViewFieldsFromArray(newSection, colIds);
|
||||
}
|
||||
|
||||
// update theme, and chart type
|
||||
await newSection.theme.saveOnly(theme);
|
||||
|
||||
Reference in New Issue
Block a user