gristlabs_grist-core/app/client/components/FormulaTransform.ts
Paul Fitzpatrick 1654a2681f (core) move client code to core
Summary:
This moves all client code to core, and makes minimal fix-ups to
get grist and grist-core to compile correctly.  The client works
in core, but I'm leaving clean-up around the build and bundles to
follow-up.

Test Plan: existing tests pass; server-dev bundle looks sane

Reviewers: dsagal

Reviewed By: dsagal

Differential Revision: https://phab.getgrist.com/D2627
2020-10-02 13:24:21 -04:00

55 lines
1.9 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"))
),
];
}
public finalize() {
this.cancel();
}
}