Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LHS Functions (draft) #896

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 32 additions & 10 deletions packages/core/modules/actions/rule.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
import * as constants from "../stores/constants";
import {toImmutableList} from "../utils/stuff";
import { toImmutableList } from "../utils/stuff";

/**
* @param {object} config
* @param {Immutable.List} path
* @param {string} field
*/
export const setField = (config, path, field) => ({
type: constants.SET_FIELD,
export const setField = (config, path, field) => {
return {
type: constants.SET_FIELD,
path: toImmutableList(path),
field: field,
config: config,
};
};

/**
* @param {object} config
* @param {Immutable.List} path
* @param {*} srcKey
*/
export const setFieldSrc = (config, path, srcKey) => ({
type: constants.SET_FIELD_SRC,
path: toImmutableList(path),
field: field,
config: config
srcKey: srcKey,
config: config,
});

/**
Expand All @@ -22,7 +36,7 @@ export const setOperator = (config, path, operator) => ({
type: constants.SET_OPERATOR,
path: toImmutableList(path),
operator: operator,
config: config
config: config,
});

/**
Expand All @@ -34,15 +48,23 @@ export const setOperator = (config, path, operator) => ({
* @param {*} asyncListValues
* @param {boolean} __isInternal
*/
export const setValue = (config, path, delta, value, valueType, asyncListValues, __isInternal) => ({
export const setValue = (
config,
path,
delta,
value,
valueType,
asyncListValues,
__isInternal
) => ({
type: constants.SET_VALUE,
path: toImmutableList(path),
delta: delta,
value: value,
valueType: valueType,
asyncListValues: asyncListValues,
config: config,
__isInternal: __isInternal
__isInternal: __isInternal,
});

/**
Expand All @@ -56,7 +78,7 @@ export const setValueSrc = (config, path, delta, srcKey) => ({
path: toImmutableList(path),
delta: delta,
srcKey: srcKey,
config: config
config: config,
});

/**
Expand All @@ -70,5 +92,5 @@ export const setOperatorOption = (config, path, name, value) => ({
path: toImmutableList(path),
name: name,
value: value,
config: config
config: config,
});
3 changes: 1 addition & 2 deletions packages/core/modules/config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const settings = {
return field;
},


fieldSources: ["field", "func"],
valueSourcesInfo: {
value: {},
},
Expand Down Expand Up @@ -54,5 +54,4 @@ export const settings = {
valueSourcesPopupTitle: "Select value source",
removeRuleConfirmOptions: null,
removeGroupConfirmOptions: null,

};
74 changes: 37 additions & 37 deletions packages/core/modules/config/funcs.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@ const RELATIVE_DATETIME = {
returnType: "datetime",
renderBrackets: ["", ""],
renderSeps: ["", "", ""],
jsonLogic: ({date, op, val, dim}) => ({
"date_add": [
date,
val * (op == "minus" ? -1 : +1),
dim
]
jsonLogic: ({ date, op, val, dim }) => ({
date_add: [date, val * (op == "minus" ? -1 : +1), dim],
}),
jsonLogicImport: (v) => {
const date = v["date_add"][0];
Expand All @@ -35,19 +31,23 @@ const RELATIVE_DATETIME = {
return [date, op, val, dim];
},
jsonLogicCustomOps: {
date_add: (date, val, dim) => moment(date).add(val, dim).toDate()
date_add: (date, val, dim) => moment(date).add(val, dim).toDate(),
},
// MySQL
//todo: other SQL dialects?
sqlFormatFunc: ({date, op, val, dim}) => `DATE_ADD(${date}, INTERVAL ${parseInt(val) * (op == "minus" ? -1 : +1)} ${dim.replace(/^'|'$/g, "")})`,
sqlFormatFunc: ({ date, op, val, dim }) =>
`DATE_ADD(${date}, INTERVAL ${
parseInt(val) * (op == "minus" ? -1 : +1)
} ${dim.replace(/^'|'$/g, "")})`,
mongoFormatFunc: null, //todo: support?
//todo: spel
formatFunc: ({date, op, val, dim}) => (!val ? date : `${date} ${op == "minus" ? "-" : "+"} ${val} ${dim}`),
formatFunc: ({ date, op, val, dim }) =>
!val ? date : `${date} ${op == "minus" ? "-" : "+"} ${val} ${dim}`,
args: {
date: {
label: "Date",
type: "datetime",
defaultValue: {func: "NOW", args: []},
defaultValue: { func: "NOW", args: [] },
valueSources: ["func", "field"],
},
op: {
Expand All @@ -57,15 +57,15 @@ const RELATIVE_DATETIME = {
valueSources: ["value"],
mainWidgetProps: {
customProps: {
showSearch: false
}
showSearch: false,
},
},
fieldSettings: {
listValues: {
plus: "+",
minus: "-",
},
}
},
},
val: {
label: "Value",
Expand All @@ -83,8 +83,8 @@ const RELATIVE_DATETIME = {
valueSources: ["value"],
mainWidgetProps: {
customProps: {
showSearch: false
}
showSearch: false,
},
},
fieldSettings: {
listValues: {
Expand All @@ -93,13 +93,15 @@ const RELATIVE_DATETIME = {
month: "month",
year: "year",
},
}
},
},
}
},
};

const LOWER = {
label: "Lowercase",
allowSelfNesting: true,
valueSources: ["value", "field", "func"],
mongoFunc: "$toLower",
jsonLogic: "toLowerCase",
spelFunc: ".toLowerCase",
Expand All @@ -110,15 +112,17 @@ const LOWER = {
returnType: "text",
args: {
str: {
label: "String",
label: "ARGUMENT",
type: "text",
valueSources: ["value", "field"],
valueSources: ["value", "field", "func"],
},
}
},
};

const UPPER = {
label: "Uppercase",
allowSelfNesting: true,
valueSources: ["value", "field", "func"],
mongoFunc: "$toUpper",
jsonLogic: "toUpperCase",
spelFunc: ".toUpperCase",
Expand All @@ -129,21 +133,23 @@ const UPPER = {
returnType: "text",
args: {
str: {
label: "String",
label: "ARGUMENT",
type: "text",
valueSources: ["value", "field"],
valueSources: ["value", "field", "func"],
},
}
},
};

const LINEAR_REGRESSION = {
label: "Linear regression",
returnType: "number",
formatFunc: ({coef, bias, val}, _) => `(${coef} * ${val} + ${bias})`,
sqlFormatFunc: ({coef, bias, val}) => `(${coef} * ${val} + ${bias})`,
spelFormatFunc: ({coef, bias, val}) => `(${coef} * ${val} + ${bias})`,
mongoFormatFunc: ({coef, bias, val}) => ({"$sum": [{"$multiply": [coef, val]}, bias]}),
jsonLogic: ({coef, bias, val}) => ({ "+": [ {"*": [coef, val]}, bias ] }),
formatFunc: ({ coef, bias, val }, _) => `(${coef} * ${val} + ${bias})`,
sqlFormatFunc: ({ coef, bias, val }) => `(${coef} * ${val} + ${bias})`,
spelFormatFunc: ({ coef, bias, val }) => `(${coef} * ${val} + ${bias})`,
mongoFormatFunc: ({ coef, bias, val }) => ({
$sum: [{ $multiply: [coef, val] }, bias],
}),
jsonLogic: ({ coef, bias, val }) => ({ "+": [{ "*": [coef, val] }, bias] }),
jsonLogicImport: (v) => {
const coef = v["+"][0]["*"][0];
const val = v["+"][0]["*"][1];
Expand All @@ -169,14 +175,8 @@ const LINEAR_REGRESSION = {
type: "number",
defaultValue: 0,
valueSources: ["value"],
}
}
},
},
};

export {
LOWER,
UPPER,
NOW,
RELATIVE_DATETIME,
LINEAR_REGRESSION,
};
export { LOWER, UPPER, NOW, RELATIVE_DATETIME, LINEAR_REGRESSION };
Loading