mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Implement UI for trigger formulas.
Summary: - Implement UI with "Apply to new records" and "Apply on record changes" checkboxes, and options for selecting which changes to recalculate on. - For consistency, always represent empty RefList as None - Fix up generated SchemaTypes to remember that values are encoded. Included test cases for the main planned use cases: - Auto-filled UUID column - Data cleaning - NOW() formula for record's last-updated timestamp. - Updates that depend on other columns. Test Plan: Added a browser test. Reviewers: jarek Reviewed By: jarek Subscribers: paulfitz Differential Revision: https://phab.getgrist.com/D2885
This commit is contained in:
@@ -529,7 +529,7 @@ GridView.prototype._convertFormulasToData = function(selection) {
|
||||
// prevented by ACL rules).
|
||||
const fields = selection.fields.filter(f => f.column.peek().isFormula.peek());
|
||||
if (!fields.length) { return null; }
|
||||
return this.gristDoc.convertFormulasToData(fields.map(f => f.colRef.peek()));
|
||||
return this.gristDoc.convertIsFormula(fields.map(f => f.colRef.peek()), {toFormula: false});
|
||||
};
|
||||
|
||||
GridView.prototype.selectAll = function() {
|
||||
|
||||
@@ -42,6 +42,7 @@ import {DisposableWithEvents} from 'app/common/DisposableWithEvents';
|
||||
import {isSchemaAction} from 'app/common/DocActions';
|
||||
import {OpenLocalDocResult} from 'app/common/DocListAPI';
|
||||
import {HashLink, IDocPage} from 'app/common/gristUrls';
|
||||
import {RecalcWhen} from 'app/common/gristTypes';
|
||||
import {encodeQueryParams, waitObs} from 'app/common/gutil';
|
||||
import {StringUnion} from 'app/common/StringUnion';
|
||||
import {TableData} from 'app/common/TableData';
|
||||
@@ -572,16 +573,20 @@ export class GristDoc extends DisposableWithEvents {
|
||||
['BulkUpdateRecord', colRefs, {
|
||||
isFormula: colRefs.map(f => true),
|
||||
formula: colRefs.map(f => ''),
|
||||
// Set recalc settings to defaults when emptying a column.
|
||||
recalcWhen: colRefs.map(f => RecalcWhen.DEFAULT),
|
||||
recalcDeps: colRefs.map(f => null),
|
||||
}]
|
||||
);
|
||||
}
|
||||
|
||||
// Convert the given columns to data, saving the calculated values and unsetting the formulas.
|
||||
public async convertFormulasToData(colRefs: number[]): Promise<void> {
|
||||
public async convertIsFormula(colRefs: number[], opts: {toFormula: boolean, noRecalc?: boolean}): Promise<void> {
|
||||
return this.docModel.columns.sendTableAction(
|
||||
['BulkUpdateRecord', colRefs, {
|
||||
isFormula: colRefs.map(f => false),
|
||||
formula: colRefs.map(f => ''),
|
||||
isFormula: colRefs.map(f => opts.toFormula),
|
||||
recalcWhen: colRefs.map(f => opts.noRecalc ? RecalcWhen.NEVER : RecalcWhen.DEFAULT),
|
||||
recalcDeps: colRefs.map(f => null),
|
||||
}]
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user