(core) Preserving rules when data is transformed

Summary: Rules where removed when data in column was transformed.

Test Plan: Added new test

Reviewers: georgegevoian

Reviewed By: georgegevoian

Differential Revision: https://phab.getgrist.com/D3883
This commit is contained in:
Jarosław Sadziński
2023-05-05 11:52:24 +02:00
parent 8810aa3bd3
commit ca3cf0cd06
3 changed files with 48 additions and 1 deletions

View File

@@ -10,6 +10,7 @@ import {ViewFieldRec} from 'app/client/models/entities/ViewFieldRec';
import {TableData} from 'app/client/models/TableData';
import {FieldBuilder} from 'app/client/widgets/FieldBuilder';
import {UserAction} from 'app/common/DocActions';
import {GristObjCode} from 'app/plugin/GristData';
import {Disposable, Observable} from 'grainjs';
import isPlainObject from 'lodash/isPlainObject';
import * as ko from 'knockout';
@@ -34,6 +35,7 @@ export class ColumnTransform extends Disposable {
protected editor: AceEditor|null = null; // Created when the dom is built by extending classes
protected formulaUpToDate = Observable.create(this, true);
protected _tableData: TableData;
protected rules: [GristObjCode.List, ...number[]]|null;
// Whether _doFinalize should execute the transform, or cancel it.
protected _shouldExecute: boolean = false;
@@ -53,6 +55,7 @@ export class ColumnTransform extends Disposable {
this.origColumn = this.field.column();
this.origDisplayCol = this.field.displayColModel();
this.origWidgetOptions = this.field.widgetOptionsJson();
this.rules = this.origColumn.rules();
this.isCallPending = _fieldBuilder.isCallPending;
this._tableData = gristDoc.docData.getTable(this.origColumn.table().tableId())!;
@@ -169,6 +172,14 @@ export class ColumnTransform extends Disposable {
formula: this.getIdentityFormula(),
...(this.origWidgetOptions ? {widgetOptions: JSON.stringify(this.origWidgetOptions)} : {}),
}]);
if (this.rules) {
// We are in bundle, it is safe to just send another action.
// NOTE: We could add rules with AddColumn action, but there are some optimizations that converts array values.
await this.gristDoc.docData.sendActions([
['UpdateRecord', '_grist_Tables_column', newColInfo.colRef, {rules: this.rules}]
]);
}
return newColInfo.colRef;
}

View File

@@ -423,6 +423,7 @@ export class FieldBuilder extends Disposable {
kf.checkButton(transformButton,
dom('span.glyphicon.glyphicon-flash'),
dom.testId("FieldBuilder_editTransform"),
testId('edit-transform'),
kd.toggleClass('disabled', () => this._isTransformingType() || this.origColumn.isFormula() ||
this.origColumn.disableModifyBase())
)