Skip to content

Commit

Permalink
Breaking change: only use id, not join for controls
Browse files Browse the repository at this point in the history
  • Loading branch information
grassick committed Jul 19, 2020
1 parent 640073d commit 7e2cc2e
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 49 deletions.
4 changes: 1 addition & 3 deletions lib/widgets/actions/addRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ var AddRowAction = /** @class */ (function (_super) {
}
var exprValidator = new mwater_expressions_1.ExprValidator(designCtx.schema, blocks_1.createExprVariables(designCtx.contextVars));
var exprUtils = new mwater_expressions_1.ExprUtils(designCtx.schema, blocks_1.createExprVariables(designCtx.contextVars));
// Get type of column
var columnType = (column.type === "join") ? "id" : column.type;
// Check context var
var contextVarExpr = this.actionDef.columnValues[columnId];
var contextVar;
Expand All @@ -135,7 +133,7 @@ var AddRowAction = /** @class */ (function (_super) {
}
// Validate expr
var error;
error = exprValidator.validateExpr(contextVarExpr.expr, { table: contextVar ? contextVar.table : undefined, types: [columnType] });
error = exprValidator.validateExpr(contextVarExpr.expr, { table: contextVar ? contextVar.table : undefined, types: [column.type] });
if (error) {
return error;
}
Expand Down
4 changes: 1 addition & 3 deletions lib/widgets/blocks/addRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,6 @@ var AddRowBlock = /** @class */ (function (_super) {
}
var exprValidator = new mwater_expressions_1.ExprValidator(options.schema, blocks_1.createExprVariables(options.contextVars));
var exprUtils = new mwater_expressions_1.ExprUtils(options.schema, blocks_1.createExprVariables(options.contextVars));
// Get type of column
var columnType = (column.type === "join") ? "id" : column.type;
// Check context var
var contextVarExpr = this.blockDef.columnValues[columnId];
var contextVar;
Expand All @@ -153,7 +151,7 @@ var AddRowBlock = /** @class */ (function (_super) {
}
// Validate expr
var error;
error = exprValidator.validateExpr(contextVarExpr.expr, { table: contextVar ? contextVar.table : undefined, types: [columnType] });
error = exprValidator.validateExpr(contextVarExpr.expr, { table: contextVar ? contextVar.table : undefined, types: [column.type] });
if (error) {
return error;
}
Expand Down
3 changes: 1 addition & 2 deletions lib/widgets/blocks/addWizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ var AddWizardPane = function (props) {
if (column.type === "enum"
|| column.type === "enumset"
|| column.type === "id"
|| column.type === "id[]"
|| (column.type === "join" && column.join.type === "n-1")) {
|| column.type === "id[]") {
createLabeledBlock({
id: uuid(),
type: "dropdown",
Expand Down
17 changes: 6 additions & 11 deletions lib/widgets/blocks/controls/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ var DropdownBlock = /** @class */ (function (_super) {
}
var contextVar = options.contextVars.find(function (cv) { return cv.id === _this.blockDef.rowContextVarId; });
var column = options.schema.getColumn(contextVar.table, this.blockDef.column);
if (column.type === "join") {
if (column.type === "id" || column.type == "id[]") {
var idMode = this.blockDef.idMode || "simple";
var exprValidator = new mwater_expressions_1.ExprValidator(options.schema, blocks_1.createExprVariables(options.contextVars));
var idTable = column.join.toTable;
var idTable = column.idTable;
if (idMode == "simple") {
if (!this.blockDef.idLabelExpr) {
return "Label Expression required";
Expand Down Expand Up @@ -166,9 +166,6 @@ var DropdownBlock = /** @class */ (function (_super) {
if (column.type === "id[]") {
return this.renderIds(props, column);
}
if (column.type === "join" && column.join.type === "n-1") {
return this.renderId(props, column);
}
throw new Error("Unsupported type");
};
DropdownBlock.prototype.renderEnum = function (props, column) {
Expand Down Expand Up @@ -211,7 +208,6 @@ var DropdownBlock = /** @class */ (function (_super) {
return React.createElement(react_select_1.default, { value: value, onChange: handleChange, options: enumValues, placeholder: localization_1.localize(this.blockDef.placeholder, props.locale), getOptionLabel: getOptionLabel, getOptionValue: getOptionValue, isDisabled: props.disabled, isClearable: true, isMulti: true, closeMenuOnScroll: true, menuPortalTarget: document.body, classNamePrefix: "react-select-short", styles: { menuPortal: function (style) { return (__assign(__assign({}, style), { zIndex: 2000 })); } } });
};
DropdownBlock.prototype.renderId = function (props, column) {
var idTable = column.join ? column.join.toTable : column.idTable;
var labelEmbeddedExprs;
var searchExprs;
var orderBy;
Expand All @@ -226,7 +222,7 @@ var DropdownBlock = /** @class */ (function (_super) {
searchExprs = [this.blockDef.idLabelExpr];
orderBy = [{ expr: this.blockDef.idLabelExpr, dir: "asc" }];
}
return React.createElement(IdDropdownComponent_1.IdDropdownComponent, { database: props.database, table: idTable, value: props.value, onChange: props.onChange, multi: false, labelEmbeddedExprs: labelEmbeddedExprs, searchExprs: searchExprs, orderBy: orderBy, filterExpr: this.blockDef.idFilterExpr || null, formatLabel: this.formatIdLabel.bind(null, props), contextVars: props.contextVars, contextVarValues: props.contextVarValues, styles: { menuPortal: function (style) { return (__assign(__assign({}, style), { zIndex: 2000 })); } } });
return React.createElement(IdDropdownComponent_1.IdDropdownComponent, { database: props.database, table: column.idTable, value: props.value, onChange: props.onChange, multi: false, labelEmbeddedExprs: labelEmbeddedExprs, searchExprs: searchExprs, orderBy: orderBy, filterExpr: this.blockDef.idFilterExpr || null, formatLabel: this.formatIdLabel.bind(null, props), contextVars: props.contextVars, contextVarValues: props.contextVarValues, styles: { menuPortal: function (style) { return (__assign(__assign({}, style), { zIndex: 2000 })); } } });
};
DropdownBlock.prototype.renderIds = function (props, column) {
var labelEmbeddedExprs;
Expand All @@ -253,9 +249,9 @@ var DropdownBlock = /** @class */ (function (_super) {
if (contextVar && contextVar.table && this.blockDef.column) {
column = props.schema.getColumn(contextVar.table, this.blockDef.column);
}
var isIdType = column && (column.type === "join" || column.type == "id" || column.type == "id[]");
var isIdType = column && (column.type == "id" || column.type == "id[]");
var idMode = this.blockDef.idMode || "simple";
var idTable = column && column.join ? column.join.toTable : (column ? column.idTable : null);
var idTable = column ? column.idTable : null;
var handleConvertToToggle = function () {
props.store.replaceBlock({
id: _this.blockDef.id,
Expand Down Expand Up @@ -329,8 +325,7 @@ var DropdownBlock = /** @class */ (function (_super) {
return column.type === "enum"
|| column.type === "enumset"
|| column.type === "id"
|| column.type === "id[]"
|| (column.type === "join" && column.join.type === "n-1");
|| column.type === "id[]";
};
return DropdownBlock;
}(ControlBlock_1.ControlBlock));
Expand Down
4 changes: 1 addition & 3 deletions lib/widgets/columnValues.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,11 @@ var ColumnValuesEditor = /** @class */ (function (_super) {
}
var contextVarExpr = this.props.value[columnId];
var contextVar = this.props.contextVars.find(function (cv) { return cv.id === contextVarExpr.contextVarId; });
// Get type of column
var columnType = (column.type === "join") ? "id" : column.type;
return react_1.default.createElement("tr", { key: columnId },
react_1.default.createElement("td", { key: "name" }, localization_1.localize(column.name, this.props.locale)),
react_1.default.createElement("td", { key: "value" },
react_1.default.createElement(propertyEditors_1.LabeledProperty, { label: "Expression" },
react_1.default.createElement(propertyEditors_1.ContextVarExprPropertyEditor, { contextVarId: contextVarExpr.contextVarId, expr: contextVarExpr.expr, onChange: this.handleContextVarExprChange.bind(null, columnId), contextVars: this.props.contextVars, schema: this.props.schema, dataSource: this.props.dataSource, idTable: column.idTable || (column.type === "join" ? column.join.toTable : undefined), enumValues: column.enumValues, types: [columnType] }))),
react_1.default.createElement(propertyEditors_1.ContextVarExprPropertyEditor, { contextVarId: contextVarExpr.contextVarId, expr: contextVarExpr.expr, onChange: this.handleContextVarExprChange.bind(null, columnId), contextVars: this.props.contextVars, schema: this.props.schema, dataSource: this.props.dataSource, idTable: column.idTable, enumValues: column.enumValues, types: [column.type] }))),
react_1.default.createElement("td", { key: "remove" },
react_1.default.createElement("i", { className: "fa fa-remove", onClick: this.handleRemove.bind(null, columnId) })));
};
Expand Down
5 changes: 1 addition & 4 deletions src/widgets/actions/addRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ export class AddRowAction extends Action<AddRowActionDef> {
const exprValidator = new ExprValidator(designCtx.schema, createExprVariables(designCtx.contextVars))
const exprUtils = new ExprUtils(designCtx.schema, createExprVariables(designCtx.contextVars))

// Get type of column
const columnType = (column.type === "join") ? "id" : column.type

// Check context var
const contextVarExpr: ContextVarExpr = this.actionDef.columnValues[columnId]
let contextVar: ContextVar | undefined
Expand All @@ -80,7 +77,7 @@ export class AddRowAction extends Action<AddRowActionDef> {

// Validate expr
let error
error = exprValidator.validateExpr(contextVarExpr.expr, { table: contextVar ? contextVar.table : undefined, types: [columnType] })
error = exprValidator.validateExpr(contextVarExpr.expr, { table: contextVar ? contextVar.table : undefined, types: [column.type] })
if (error) {
return error
}
Expand Down
5 changes: 1 addition & 4 deletions src/widgets/blocks/addRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ export class AddRowBlock extends Block<AddRowBlockDef> {
const exprValidator = new ExprValidator(options.schema, createExprVariables(options.contextVars))
const exprUtils = new ExprUtils(options.schema, createExprVariables(options.contextVars))

// Get type of column
const columnType = (column.type === "join") ? "id" : column.type

// Check context var
const contextVarExpr: ContextVarExpr = this.blockDef.columnValues[columnId]
let contextVar: ContextVar | undefined
Expand All @@ -112,7 +109,7 @@ export class AddRowBlock extends Block<AddRowBlockDef> {

// Validate expr
let error
error = exprValidator.validateExpr(contextVarExpr.expr, { table: contextVar ? contextVar.table : undefined, types: [columnType] })
error = exprValidator.validateExpr(contextVarExpr.expr, { table: contextVar ? contextVar.table : undefined, types: [column.type] })
if (error) {
return error
}
Expand Down
3 changes: 1 addition & 2 deletions src/widgets/blocks/addWizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ const AddWizardPane = (props: {
if (column.type === "enum"
|| column.type === "enumset"
|| column.type === "id"
|| column.type === "id[]"
|| (column.type === "join" && column.join!.type === "n-1")) {
|| column.type === "id[]") {
createLabeledBlock({
id: uuid(),
type: "dropdown",
Expand Down
18 changes: 6 additions & 12 deletions src/widgets/blocks/controls/dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ export class DropdownBlock extends ControlBlock<DropdownBlockDef> {
const contextVar = options.contextVars.find(cv => cv.id === this.blockDef.rowContextVarId)!
const column = options.schema.getColumn(contextVar.table!, this.blockDef.column!)!

if (column.type === "join") {
if (column.type === "id" || column.type == "id[]") {
const idMode = this.blockDef.idMode || "simple"
const exprValidator = new ExprValidator(options.schema, createExprVariables(options.contextVars))
const idTable = column.join!.toTable
const idTable = column.idTable!

if (idMode == "simple") {
if (!this.blockDef.idLabelExpr) {
Expand Down Expand Up @@ -166,9 +166,6 @@ export class DropdownBlock extends ControlBlock<DropdownBlockDef> {
if (column.type === "id[]") {
return this.renderIds(props, column)
}
if (column.type === "join" && column.join!.type === "n-1") {
return this.renderId(props, column)
}
throw new Error("Unsupported type")
}

Expand Down Expand Up @@ -264,8 +261,6 @@ export class DropdownBlock extends ControlBlock<DropdownBlockDef> {
}

renderId(props: RenderControlProps, column: Column) {
const idTable = column.join ? column.join.toTable : column.idTable

let labelEmbeddedExprs: Expr[]
let searchExprs: Expr[]
let orderBy: OrderBy[]
Expand All @@ -284,7 +279,7 @@ export class DropdownBlock extends ControlBlock<DropdownBlockDef> {

return <IdDropdownComponent
database={props.database}
table={idTable!}
table={column.idTable!}
value={props.value}
onChange={props.onChange}
multi={false}
Expand Down Expand Up @@ -342,9 +337,9 @@ export class DropdownBlock extends ControlBlock<DropdownBlockDef> {
column = props.schema.getColumn(contextVar.table, this.blockDef.column)
}

const isIdType = column && (column.type === "join" || column.type == "id" || column.type == "id[]")
const isIdType = column && (column.type == "id" || column.type == "id[]")
const idMode = this.blockDef.idMode || "simple"
const idTable = column && column.join ? column.join.toTable : (column ? column.idTable : null)
const idTable = column ? column.idTable : null

const handleConvertToToggle = () => {
props.store.replaceBlock({
Expand Down Expand Up @@ -506,7 +501,6 @@ export class DropdownBlock extends ControlBlock<DropdownBlockDef> {
return column.type === "enum"
|| column.type === "enumset"
|| column.type === "id"
|| column.type === "id[]"
|| (column.type === "join" && column.join!.type === "n-1")
|| column.type === "id[]"
}
}
7 changes: 2 additions & 5 deletions src/widgets/columnValues.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ export class ColumnValuesEditor extends React.Component<{

const contextVar = this.props.contextVars.find(cv => cv.id === contextVarExpr.contextVarId)

// Get type of column
const columnType = (column.type === "join") ? "id" : column.type

return <tr key={columnId}>
<td key="name">{localize(column.name, this.props.locale)}</td>
<td key="value">
Expand All @@ -76,9 +73,9 @@ export class ColumnValuesEditor extends React.Component<{
contextVars={this.props.contextVars}
schema={this.props.schema}
dataSource={this.props.dataSource}
idTable={column.idTable || (column.type === "join" ? column.join!.toTable : undefined)}
idTable={column.idTable}
enumValues={column.enumValues}
types={[columnType as LiteralType]}
types={[column.type as LiteralType]}
/>
</LabeledProperty>
</td>
Expand Down

0 comments on commit 7e2cc2e

Please sign in to comment.