mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-20 17:14:11 +00:00
2a592d8b4d
Summary: Type conversions and formula tranforms wait for the user and bundle multiple actions. When an unrelated action is done (e.g. adding a page widget or a column), we want to finalize the transform before applying it. The approach turns out fairly complicated. There is an implicit queue of bundles (which we don't let grow beyond 2, as that's too abnormal). Bundles may be finalized by a user clicking something, or by an unrelated action/bundle, or (as before) by transform DOM getting disposed. - Updated RecordLayout to use bundleActions() helper - Added support for nesting bundleActions inside another bundle (needed for setting visibleCol during type change) - In an unrelated tweak, when in debug-log in ActiveDoc, use a short representation of result. Test Plan: Added a unittest for action bundling during type transform Reviewers: paulfitz Reviewed By: paulfitz Differential Revision: https://phab.getgrist.com/D2655
51 lines
1.8 KiB
TypeScript
51 lines
1.8 KiB
TypeScript
/**
|
|
* FormulaTransform extends ColumnTransform, creating the transform dom in the field config tab
|
|
* used to transform a column of data using a formula. Allows the user to easily and quickly clean
|
|
* data or change data to a more useful form.
|
|
*/
|
|
|
|
// Client libraries
|
|
import * as AceEditor from 'app/client/components/AceEditor';
|
|
import {ColumnTransform} from 'app/client/components/ColumnTransform';
|
|
import {GristDoc} from 'app/client/components/GristDoc';
|
|
import {cssButtonRow} from 'app/client/ui/RightPanel';
|
|
import {basicButton, primaryButton} from 'app/client/ui2018/buttons';
|
|
import {testId} from 'app/client/ui2018/cssVars';
|
|
import {FieldBuilder} from 'app/client/widgets/FieldBuilder';
|
|
import {dom} from 'grainjs';
|
|
|
|
/**
|
|
* Creates an instance of FormulaTransform for a single field. Extends ColumnTransform.
|
|
*/
|
|
export class FormulaTransform extends ColumnTransform {
|
|
constructor(gristDoc: GristDoc, fieldBuilder: FieldBuilder) {
|
|
super(gristDoc, fieldBuilder);
|
|
}
|
|
|
|
/**
|
|
* Build the transform menu for a formula transform
|
|
*/
|
|
public buildDom() {
|
|
this.editor = this.autoDispose(AceEditor.create({ observable: this.transformColumn.formula }));
|
|
return [
|
|
dom('div.transform_menu',
|
|
dom('div.transform_editor',
|
|
this.buildEditorDom(this.getIdentityFormula()),
|
|
testId("formula-transform-top")
|
|
)
|
|
),
|
|
cssButtonRow(
|
|
basicButton(dom.on('click', () => this.cancel()),
|
|
'Cancel', testId("formula-transform-cancel")),
|
|
basicButton(dom.on('click', () => this.editor.writeObservable()),
|
|
'Preview',
|
|
dom.cls('disabled', this.formulaUpToDate),
|
|
{ title: 'Update formula (Shift+Enter)' },
|
|
testId("formula-transform-update")),
|
|
primaryButton(dom.on('click', () => this.execute()),
|
|
'Apply', testId("formula-transform-apply"))
|
|
),
|
|
];
|
|
}
|
|
}
|