@react-awesome-query-builder/core
Advanced tools
Comparing version 6.1.3 to 6.2.0
@@ -755,3 +755,3 @@ "use strict"; | ||
formatValue: function formatValue(val, fieldDef, wgtDef, isForDisplay) { | ||
var valLabel = (0, _listValues.getTitleInListValues)(fieldDef.fieldSettings.listValues || fieldDef.asyncListValues, val); | ||
var valLabel = (0, _listValues.getTitleInListValues)(fieldDef.fieldSettings.treeValues || fieldDef.fieldSettings.listValues || fieldDef.asyncListValues, val); | ||
return isForDisplay ? (0, _export.stringifyForDisplay)(valLabel) : JSON.stringify(val); | ||
@@ -780,3 +780,3 @@ }, | ||
var valsLabels = vals.map(function (v) { | ||
return (0, _listValues.getTitleInListValues)(fieldDef.fieldSettings.listValues || fieldDef.asyncListValues, v); | ||
return (0, _listValues.getTitleInListValues)(fieldDef.fieldSettings.treeValues || fieldDef.fieldSettings.listValues || fieldDef.asyncListValues, v); | ||
}); | ||
@@ -783,0 +783,0 @@ return isForDisplay ? valsLabels.map(_export.stringifyForDisplay) : vals.map(JSON.stringify); |
@@ -7,2 +7,3 @@ "use strict"; | ||
}); | ||
exports.ES_7_SYNTAX = exports.ES_6_SYNTAX = void 0; | ||
exports.elasticSearchFormat = elasticSearchFormat; | ||
@@ -170,3 +171,3 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
} | ||
function buildParameters(queryType, value, operator, fieldName, config) { | ||
function buildParameters(queryType, value, operator, fieldName, config, syntax) { | ||
var textField = determineField(fieldName, config); | ||
@@ -186,3 +187,5 @@ switch (queryType) { | ||
case "term": | ||
return (0, _defineProperty2["default"])({}, fieldName, value[0]); | ||
return syntax === ES_7_SYNTAX ? (0, _defineProperty2["default"])({}, fieldName, { | ||
value: value[0] | ||
}) : (0, _defineProperty2["default"])({}, fieldName, value[0]); | ||
@@ -210,6 +213,7 @@ //todo: not used | ||
* @param {string} operator - The condition on how the value is matched | ||
* @param {string} syntax - The version of ElasticSearch syntax to generate | ||
* @returns {object} - The ES rule | ||
* @private | ||
*/ | ||
function buildEsRule(fieldName, value, operator, config, valueSrc) { | ||
function buildEsRule(fieldName, value, operator, config, valueSrc, syntax) { | ||
if (!fieldName || !operator || value == undefined) return undefined; // rule is not fully entered | ||
@@ -257,3 +261,3 @@ var op = operator; | ||
} else { | ||
parameters = buildParameters(queryType, value, op, fieldName, config); | ||
parameters = buildParameters(queryType, value, op, fieldName, config, syntax); | ||
} | ||
@@ -281,3 +285,3 @@ if (not) { | ||
*/ | ||
function buildEsGroup(children, conjunction, not, recursiveFxn, config) { | ||
function buildEsGroup(children, conjunction, not, recursiveFxn, config, syntax) { | ||
if (!children || !children.size) return undefined; | ||
@@ -287,3 +291,3 @@ var childrenArray = children.valueSeq().toArray(); | ||
var result = childrenArray.map(function (c) { | ||
return recursiveFxn(c, config); | ||
return recursiveFxn(c, config, syntax); | ||
}).filter(function (v) { | ||
@@ -298,3 +302,8 @@ return v !== undefined; | ||
} | ||
var ES_7_SYNTAX = "ES_7_SYNTAX"; | ||
exports.ES_7_SYNTAX = ES_7_SYNTAX; | ||
var ES_6_SYNTAX = "ES_6_SYNTAX"; | ||
exports.ES_6_SYNTAX = ES_6_SYNTAX; | ||
function elasticSearchFormat(tree, config) { | ||
var syntax = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ES_6_SYNTAX; | ||
// -- format the es dsl here | ||
@@ -319,6 +328,6 @@ if (!tree) return undefined; | ||
return value[0].map(function (val) { | ||
return buildEsRule(field, [val], operator, config, valueSrc); | ||
return buildEsRule(field, [val], operator, config, valueSrc, syntax); | ||
}); | ||
} else { | ||
return buildEsRule(field, value, operator, config, valueSrc); | ||
return buildEsRule(field, value, operator, config, valueSrc, syntax); | ||
} | ||
@@ -331,4 +340,4 @@ } | ||
var children = tree.get("children1"); | ||
return buildEsGroup(children, conjunction, not, elasticSearchFormat, config); | ||
return buildEsGroup(children, conjunction, not, elasticSearchFormat, config, syntax); | ||
} | ||
} |
@@ -84,3 +84,3 @@ "use strict"; | ||
var list = children.map(function (currentChild) { | ||
return formatItem([].concat((0, _toConsumableArray2["default"])(parents), [item]), currentChild, config, meta, not, true, mode == "array" ? function (f) { | ||
return formatItem([].concat((0, _toConsumableArray2["default"])(parents), [item]), currentChild, config, meta, not, mode != "array", mode == "array" ? function (f) { | ||
return "$$el.".concat(f); | ||
@@ -154,7 +154,9 @@ } : undefined); | ||
"$size": { | ||
"$filter": { | ||
input: "$" + groupFieldName, | ||
as: "el", | ||
cond: resultQuery | ||
} | ||
"$ifNull": [{ | ||
"$filter": { | ||
input: "$" + groupFieldName, | ||
as: "el", | ||
cond: resultQuery | ||
} | ||
}, []] | ||
} | ||
@@ -161,0 +163,0 @@ } : totalQuery; |
/* eslint-disable no-extra-semi */ | ||
import {List as ImmutableList, Map as ImmutableMap, OrderedMap as ImmutableOMap} from "immutable"; | ||
import {List as ImmList, Map as ImmMap, OrderedMap as ImmOMap} from "immutable"; | ||
import {ElementType, ReactElement, Factory} from "react"; | ||
@@ -8,2 +8,5 @@ import type { Moment as MomentType } from "moment"; | ||
export type Moment = MomentType; | ||
export type ImmutableList<T> = ImmList<T>; | ||
export type ImmutableMap<K, V> = ImmMap<K, V>; | ||
export type ImmutableOMap<K, V> = ImmOMap<K, V>; | ||
@@ -53,3 +56,3 @@ //////////////// | ||
type RuleValue = boolean | number | string | Date | Array<string> | any; | ||
export type RuleValue = boolean | number | string | Date | Array<string> | any; | ||
@@ -177,3 +180,3 @@ export type ValueSource = "value" | "field" | "func" | "const"; | ||
_mongodbFormat(tree: ImmutableTree, config: Config): [Object | undefined, Array<string>]; | ||
elasticSearchFormat(tree: ImmutableTree, config: Config): Object | undefined; | ||
elasticSearchFormat(tree: ImmutableTree, config: Config, syntax?: "ES_6_SYNTAX" | "ES_7_SYNTAX"): Object | undefined; | ||
// load, save | ||
@@ -319,5 +322,3 @@ getTree(tree: ImmutableTree, light?: boolean, children1AsArray?: boolean): JsonTree; | ||
interface BaseWidgetProps { | ||
value: RuleValue, | ||
setValue(val: RuleValue, asyncListValues?: Array<any>): void, | ||
interface AbstractWidgetProps<C = Config> { | ||
placeholder: string, | ||
@@ -328,3 +329,3 @@ field: string, | ||
fieldDefinition: Field, | ||
config: Config, | ||
config: C, | ||
delta?: number, | ||
@@ -336,17 +337,33 @@ customProps?: AnyObject, | ||
} | ||
interface RangeWidgetProps extends BaseWidgetProps { | ||
interface BaseWidgetProps<C = Config, V = RuleValue> extends AbstractWidgetProps<C> { | ||
value: V | Empty, | ||
setValue(val: V | Empty, asyncListValues?: Array<any>): void, | ||
} | ||
interface RangeWidgetProps<C = Config, V = RuleValue> extends AbstractWidgetProps<C> { | ||
value: Array<V | Empty>, | ||
setValue(val: Array<V | Empty>, asyncListValues?: Array<any>): void, | ||
placeholders: Array<string>, | ||
textSeparators: Array<string>, | ||
} | ||
export type WidgetProps = (BaseWidgetProps | RangeWidgetProps) & FieldSettings; | ||
// BaseWidgetProps | RangeWidgetProps | ||
interface RangeableWidgetProps<C = Config, V = RuleValue> extends AbstractWidgetProps<C> { | ||
value: V | Empty | Array<V | Empty>, | ||
setValue(val: V | Empty | Array<V | Empty>, asyncListValues?: Array<any>): void, | ||
placeholders?: Array<string>, | ||
textSeparators?: Array<string>, | ||
} | ||
export type WidgetProps<C = Config> = RangeableWidgetProps<C> & FieldSettings; | ||
export type TextWidgetProps = BaseWidgetProps & TextFieldSettings; | ||
export type DateTimeWidgetProps = BaseWidgetProps & DateTimeFieldSettings; | ||
export type BooleanWidgetProps = BaseWidgetProps & BooleanFieldSettings; | ||
export type NumberWidgetProps = BaseWidgetProps & NumberFieldSettings; | ||
export type SelectWidgetProps = BaseWidgetProps & SelectFieldSettings; | ||
export type TreeSelectWidgetProps = BaseWidgetProps & TreeSelectFieldSettings; | ||
export type RangeSliderWidgetProps = RangeWidgetProps & NumberFieldSettings; | ||
export type CaseValueWidgetProps = BaseWidgetProps & CaseValueFieldSettings; | ||
export type TextWidgetProps<C = Config> = BaseWidgetProps<C, string> & TextFieldSettings; | ||
export type DateTimeWidgetProps<C = Config> = RangeableWidgetProps<C, string> & DateTimeFieldSettings; | ||
export type BooleanWidgetProps<C = Config> = BaseWidgetProps<C, boolean> & BooleanFieldSettings; | ||
export type NumberWidgetProps<C = Config> = RangeableWidgetProps<C, number> & NumberFieldSettings; | ||
export type RangeSliderWidgetProps<C = Config> = RangeableWidgetProps<C, number> & NumberFieldSettings; | ||
export type SelectWidgetProps<C = Config> = BaseWidgetProps<C, string | number> & SelectFieldSettings; | ||
export type MultiSelectWidgetProps<C = Config> = BaseWidgetProps<C, string[] | number[]> & MultiSelectFieldSettings; | ||
export type TreeSelectWidgetProps<C = Config> = BaseWidgetProps<C, string | number> & TreeSelectFieldSettings; | ||
export type TreeMultiSelectWidgetProps<C = Config> = BaseWidgetProps<C, string[] | number[]> & TreeMultiSelectFieldSettings; | ||
export type CaseValueWidgetProps<C = Config> = BaseWidgetProps<C> & CaseValueFieldSettings; | ||
///////////////// | ||
@@ -369,3 +386,3 @@ // FieldProps | ||
export interface FieldProps { | ||
export interface FieldProps<C = Config> { | ||
items: FieldItems, | ||
@@ -379,3 +396,3 @@ setField(fieldPath: string): void, | ||
selectedFullLabel?: string | Empty, | ||
config?: Config, | ||
config?: C, | ||
customProps?: AnyObject, | ||
@@ -395,12 +412,12 @@ placeholder?: string, | ||
type FormatValue = (val: RuleValue, fieldDef: Field, wgtDef: Widget, isForDisplay: boolean, op: string, opDef: Operator, rightFieldDef?: Field) => string; | ||
type SqlFormatValue = (val: RuleValue, fieldDef: Field, wgtDef: Widget, op: string, opDef: Operator, rightFieldDef?: Field) => string; | ||
type SpelFormatValue = (val: RuleValue, fieldDef: Field, wgtDef: Widget, op: string, opDef: Operator, rightFieldDef?: Field) => string; | ||
type MongoFormatValue = (val: RuleValue, fieldDef: Field, wgtDef: Widget, op: string, opDef: Operator) => MongoValue; | ||
type JsonLogicFormatValue = (val: RuleValue, fieldDef: Field, wgtDef: Widget, op: string, opDef: Operator) => JsonLogicValue; | ||
type ValidateValue = (val: RuleValue, fieldSettings: FieldSettings, op: string, opDef: Operator, rightFieldDef?: Field) => boolean | string | null; | ||
type ElasticSearchFormatValue = (queryType: ElasticSearchQueryType, val: RuleValue, op: string, field: string, config: Config) => AnyObject | null; | ||
type FormatValue = (val: RuleValue, fieldDef: Field, wgtDef: Widget, isForDisplay: boolean, op: string, opDef: Operator, rightFieldDef?: Field) => string; | ||
type SqlFormatValue = (val: RuleValue, fieldDef: Field, wgtDef: Widget, op: string, opDef: Operator, rightFieldDef?: Field) => string; | ||
type SpelFormatValue = (val: RuleValue, fieldDef: Field, wgtDef: Widget, op: string, opDef: Operator, rightFieldDef?: Field) => string; | ||
type MongoFormatValue = (val: RuleValue, fieldDef: Field, wgtDef: Widget, op: string, opDef: Operator) => MongoValue; | ||
type JsonLogicFormatValue = (val: RuleValue, fieldDef: Field, wgtDef: Widget, op: string, opDef: Operator) => JsonLogicValue; | ||
type ValidateValue<V = RuleValue> = (val: V, fieldSettings: FieldSettings, op: string, opDef: Operator, rightFieldDef?: Field) => boolean | string | null; | ||
type ElasticSearchFormatValue = (queryType: ElasticSearchQueryType, val: RuleValue, op: string, field: string, config: Config) => AnyObject | null; | ||
export interface BaseWidget { | ||
export interface BaseWidget<C = Config, WP = WidgetProps<C>> { | ||
type: string; | ||
@@ -423,11 +440,10 @@ jsType?: string; | ||
//@ui | ||
factory: Factory<WidgetProps>; | ||
factory: Factory<WP>; | ||
customProps?: AnyObject; | ||
} | ||
export interface RangeableWidget extends BaseWidget { | ||
export interface RangeableWidget<C = Config, WP = WidgetProps<C>> extends BaseWidget<C, WP> { | ||
singleWidget?: string, | ||
valueLabels?: Array<string | {label: string, placeholder: string}>, | ||
} | ||
export interface FieldWidget { | ||
valueSrc: "field", | ||
interface BaseFieldWidget<C = Config, WP = WidgetProps<C>> { | ||
valuePlaceholder?: string, | ||
@@ -442,16 +458,44 @@ valueLabel?: string, | ||
customProps?: AnyObject, | ||
factory?: Factory<WP>, | ||
} | ||
export interface FieldWidget<C = Config, WP = WidgetProps<C>> extends BaseFieldWidget<C, WP> { | ||
valueSrc: "field", | ||
} | ||
export interface FuncWidget<C = Config, WP = WidgetProps<C>> extends BaseFieldWidget<C, WP> { | ||
valueSrc: "func", | ||
} | ||
export type TextWidget = BaseWidget & TextFieldSettings; | ||
export type DateTimeWidget = RangeableWidget & DateTimeFieldSettings; | ||
export type BooleanWidget = BaseWidget & BooleanFieldSettings; | ||
export type NumberWidget = RangeableWidget & NumberFieldSettings; | ||
export type SelectWidget = BaseWidget & SelectFieldSettings; | ||
export type TreeSelectWidget = BaseWidget & TreeSelectFieldSettings; | ||
export type CaseValueWidget = BaseWidget & CaseValueFieldSettings; | ||
export type TextWidget<C = Config, WP = TextWidgetProps<C>> = BaseWidget<C, WP> & TextFieldSettings; | ||
export type DateTimeWidget<C = Config, WP = DateTimeWidgetProps<C>> = RangeableWidget<C, WP> & DateTimeFieldSettings; | ||
export type BooleanWidget<C = Config, WP = BooleanWidgetProps<C>> = BaseWidget<C, WP> & BooleanFieldSettings; | ||
export type NumberWidget<C = Config, WP = NumberWidgetProps<C>> = RangeableWidget<C, WP> & NumberFieldSettings; | ||
export type RangeSliderWidget<C = Config, WP = RangeSliderWidgetProps<C>> = RangeableWidget<C, WP> & NumberFieldSettings; | ||
export type SelectWidget<C = Config, WP = SelectWidgetProps<C>> = BaseWidget<C, WP> & SelectFieldSettings; | ||
export type MultiSelectWidget<C = Config, WP = MultiSelectWidgetProps<C>> = BaseWidget<C, WP> & MultiSelectFieldSettings; | ||
export type TreeSelectWidget<C = Config, WP = TreeSelectWidgetProps<C>> = BaseWidget<C, WP> & TreeSelectFieldSettings; | ||
export type TreeMultiSelectWidget<C = Config, WP = TreeMultiSelectWidgetProps<C>> = BaseWidget<C, WP> & TreeMultiSelectFieldSettings; | ||
export type CaseValueWidget<C = Config, WP = CaseValueWidgetProps<C>> = BaseWidget<C, WP> & CaseValueFieldSettings; | ||
export type Widget = FieldWidget | TextWidget | DateTimeWidget | BooleanWidget | NumberWidget | SelectWidget | TreeSelectWidget | RangeableWidget | BaseWidget; | ||
export type Widgets = TypedMap<Widget>; | ||
// tip: use generic WidgetProps here, TS can't determine correct factory | ||
export type TypedWidget<C = Config> = | ||
TextWidget<C, WidgetProps<C>> | ||
| DateTimeWidget<C, WidgetProps<C>> | ||
| BooleanWidget<C, WidgetProps<C>> | ||
| NumberWidget<C, WidgetProps<C>> | ||
| RangeSliderWidget<C, WidgetProps<C>> | ||
| SelectWidget<C, WidgetProps<C>> | ||
| MultiSelectWidget<C, WidgetProps<C>> | ||
| TreeSelectWidget<C, WidgetProps<C>> | ||
| TreeMultiSelectWidget<C, WidgetProps<C>> | ||
| CaseValueWidget<C, WidgetProps<C>>; | ||
export type Widget<C = Config> = | ||
FieldWidget<C> | ||
| FuncWidget<C> | ||
| TypedWidget<C> | ||
| RangeableWidget<C> | ||
| BaseWidget<C>; | ||
export type Widgets<C = Config> = TypedMap<Widget<C>>; | ||
///////////////// | ||
@@ -528,12 +572,13 @@ // Conjunctions | ||
} | ||
export interface ProximityProps extends ProximityConfig { | ||
export interface ProximityProps<C = Config> extends ProximityConfig { | ||
options: ImmutableMap<string, any>, | ||
setOption: (key: string, value: any) => void, | ||
config: Config, | ||
config: C, | ||
} | ||
export interface ProximityOptions extends ProximityConfig { | ||
factory: Factory<ProximityProps>, | ||
export interface ProximityOptions<C = Config, PP = ProximityProps<C>> extends ProximityConfig { | ||
//@ui | ||
factory: Factory<PP>, | ||
} | ||
interface BaseOperator { | ||
export interface BaseOperator { | ||
label: string, | ||
@@ -556,9 +601,9 @@ reversedOp?: string, | ||
} | ||
interface UnaryOperator extends BaseOperator { | ||
export interface UnaryOperator extends BaseOperator { | ||
//cardinality: 0, | ||
} | ||
interface BinaryOperator extends BaseOperator { | ||
export interface BinaryOperator extends BaseOperator { | ||
//cardinality: 1, | ||
} | ||
interface Operator2 extends BaseOperator { | ||
export interface Operator2 extends BaseOperator { | ||
//cardinality: 2 | ||
@@ -569,7 +614,7 @@ textSeparators: Array<string>, | ||
} | ||
interface OperatorProximity extends Operator2 { | ||
options: ProximityOptions, | ||
export interface OperatorProximity<C = Config> extends Operator2 { | ||
options: ProximityOptions<C, ProximityProps<C>>, | ||
} | ||
export type Operator = UnaryOperator | BinaryOperator | Operator2 | OperatorProximity; | ||
export type Operators = TypedMap<Operator>; | ||
export type Operator<C = Config> = UnaryOperator | BinaryOperator | Operator2 | OperatorProximity<C>; | ||
export type Operators<C = Config> = TypedMap<Operator<C>>; | ||
@@ -628,10 +673,10 @@ | ||
export interface BasicFieldSettings { | ||
validateValue?: ValidateValue, | ||
export interface BasicFieldSettings<V = RuleValue> { | ||
validateValue?: ValidateValue<V>, | ||
} | ||
export interface TextFieldSettings extends BasicFieldSettings { | ||
export interface TextFieldSettings<V = string> extends BasicFieldSettings<V> { | ||
maxLength?: number, | ||
maxRows?: number, | ||
} | ||
export interface NumberFieldSettings extends BasicFieldSettings { | ||
export interface NumberFieldSettings<V = number> extends BasicFieldSettings<V> { | ||
min?: number, | ||
@@ -642,3 +687,3 @@ max?: number, | ||
} | ||
export interface DateTimeFieldSettings extends BasicFieldSettings { | ||
export interface DateTimeFieldSettings<V = string> extends BasicFieldSettings<V> { | ||
timeFormat?: string, | ||
@@ -650,3 +695,3 @@ dateFormat?: string, | ||
} | ||
export interface SelectFieldSettings extends BasicFieldSettings { | ||
export interface SelectFieldSettings<V = string | number> extends BasicFieldSettings<V> { | ||
listValues?: ListValues, | ||
@@ -661,14 +706,28 @@ allowCustomValues?: boolean, | ||
} | ||
export interface TreeSelectFieldSettings extends BasicFieldSettings { | ||
listValues?: TreeData, | ||
export interface MultiSelectFieldSettings<V = string[] | number[]> extends SelectFieldSettings<V> { | ||
} | ||
export interface TreeSelectFieldSettings<V = string | number> extends BasicFieldSettings<V> { | ||
treeValues?: TreeData, | ||
treeExpandAll?: boolean, | ||
treeSelectOnlyLeafs?: boolean, | ||
} | ||
export interface BooleanFieldSettings extends BasicFieldSettings { | ||
export interface TreeMultiSelectFieldSettings<V = string[] | number[]> extends TreeSelectFieldSettings<V> { | ||
} | ||
export interface BooleanFieldSettings<V = boolean> extends BasicFieldSettings<V> { | ||
labelYes?: ReactElement | string, | ||
labelNo?: ReactElement | string, | ||
} | ||
export interface CaseValueFieldSettings extends BasicFieldSettings { | ||
export interface CaseValueFieldSettings<V = any> extends BasicFieldSettings<V> { | ||
} | ||
export type FieldSettings = NumberFieldSettings | DateTimeFieldSettings | SelectFieldSettings | TreeSelectFieldSettings | BooleanFieldSettings | TextFieldSettings | BasicFieldSettings; | ||
// tip: use RuleValue here, TS can't determine correct types in `validateValue` | ||
export type FieldSettings = | ||
NumberFieldSettings<RuleValue> | ||
| DateTimeFieldSettings<RuleValue> | ||
| SelectFieldSettings<RuleValue> | ||
| MultiSelectFieldSettings<RuleValue> | ||
| TreeSelectFieldSettings<RuleValue> | ||
| TreeMultiSelectFieldSettings<RuleValue> | ||
| BooleanFieldSettings<RuleValue> | ||
| TextFieldSettings<RuleValue> | ||
| BasicFieldSettings<RuleValue>; | ||
@@ -900,65 +959,73 @@ interface BaseField { | ||
export interface CoreOperators<C = Config> extends Operators<C> { | ||
equal: BinaryOperator, | ||
not_equal: BinaryOperator, | ||
less: BinaryOperator, | ||
less_or_equal: BinaryOperator, | ||
greater: BinaryOperator, | ||
greater_or_equal: BinaryOperator, | ||
like: BinaryOperator, | ||
not_like: BinaryOperator, | ||
starts_with: BinaryOperator, | ||
ends_with: BinaryOperator, | ||
between: Operator2, | ||
not_between: Operator2, | ||
is_null: UnaryOperator, | ||
is_not_null: UnaryOperator, | ||
is_empty: UnaryOperator, | ||
is_not_empty: UnaryOperator, | ||
select_equals: BinaryOperator, | ||
select_not_equals: BinaryOperator, | ||
select_any_in: BinaryOperator, | ||
select_not_any_in: BinaryOperator, | ||
multiselect_contains: BinaryOperator, | ||
multiselect_not_contains: BinaryOperator, | ||
multiselect_equals: BinaryOperator, | ||
multiselect_not_equals: BinaryOperator, | ||
proximity: OperatorProximity<C>, | ||
} | ||
export interface CoreConjunctions extends Conjunctions { | ||
AND: Conjunction, | ||
OR: Conjunction, | ||
} | ||
export interface CoreWidgets<C = Config> extends Widgets<C> { | ||
text: TextWidget<C>, | ||
textarea: TextWidget<C>, | ||
number: NumberWidget<C>, | ||
slider: NumberWidget<C>, | ||
rangeslider: RangeSliderWidget<C>, | ||
select: SelectWidget<C>, | ||
multiselect: MultiSelectWidget<C>, | ||
treeselect: TreeSelectWidget<C>, | ||
treemultiselect: TreeMultiSelectWidget<C>, | ||
date: DateTimeWidget<C>, | ||
time: DateTimeWidget<C>, | ||
datetime: DateTimeWidget<C>, | ||
boolean: BooleanWidget<C>, | ||
field: FieldWidget<C>, | ||
func: FuncWidget<C>, | ||
case_value: CaseValueWidget<C>, | ||
} | ||
export interface CoreTypes extends Types { | ||
text: Type, | ||
number: Type, | ||
date: Type, | ||
time: Type, | ||
datetime: Type, | ||
select: Type, | ||
multiselect: Type, | ||
treeselect: Type, | ||
treemultiselect: Type, | ||
boolean: Type, | ||
case_value: Type, | ||
} | ||
export interface CoreConfig extends Config { | ||
conjunctions: { | ||
AND: Conjunction, | ||
OR: Conjunction, | ||
}, | ||
operators: { | ||
equal: BinaryOperator, | ||
not_equal: BinaryOperator, | ||
less: BinaryOperator, | ||
less_or_equal: BinaryOperator, | ||
greater: BinaryOperator, | ||
greater_or_equal: BinaryOperator, | ||
like: BinaryOperator, | ||
not_like: BinaryOperator, | ||
starts_with: BinaryOperator, | ||
ends_with: BinaryOperator, | ||
between: Operator2, | ||
not_between: Operator2, | ||
is_null: UnaryOperator, | ||
is_not_null: UnaryOperator, | ||
is_empty: UnaryOperator, | ||
is_not_empty: UnaryOperator, | ||
select_equals: BinaryOperator, | ||
select_not_equals: BinaryOperator, | ||
select_any_in: BinaryOperator, | ||
select_not_any_in: BinaryOperator, | ||
multiselect_contains: BinaryOperator, | ||
multiselect_not_contains: BinaryOperator, | ||
multiselect_equals: BinaryOperator, | ||
multiselect_not_equals: BinaryOperator, | ||
proximity: OperatorProximity, | ||
}, | ||
widgets: { | ||
text: TextWidget, | ||
textarea: TextWidget, | ||
number: NumberWidget, | ||
slider: NumberWidget, | ||
rangeslider: NumberWidget, | ||
select: SelectWidget, | ||
multiselect: SelectWidget, | ||
treeselect: TreeSelectWidget, | ||
treemultiselect: TreeSelectWidget, | ||
date: DateTimeWidget, | ||
time: DateTimeWidget, | ||
datetime: DateTimeWidget, | ||
boolean: BooleanWidget, | ||
field: FieldWidget, | ||
func: FieldWidget, | ||
case_value: CaseValueWidget, | ||
}, | ||
types: { | ||
text: Type, | ||
number: Type, | ||
date: Type, | ||
time: Type, | ||
datetime: Type, | ||
select: Type, | ||
multiselect: Type, | ||
treeselect: Type, | ||
treemultiselect: Type, | ||
boolean: Type, | ||
case_value: Type, | ||
}, | ||
conjunctions: CoreConjunctions, | ||
operators: CoreOperators, | ||
widgets: CoreWidgets, | ||
types: CoreTypes, | ||
settings: Settings, | ||
@@ -965,0 +1032,0 @@ } |
@@ -155,3 +155,3 @@ "use strict"; | ||
if (fieldConfig.type != "!struct" && fieldConfig.type != "!group") { | ||
var keysToPutInFieldSettings = ["listValues", "allowCustomValues", "validateValue"]; | ||
var keysToPutInFieldSettings = ["listValues", "treeValues", "allowCustomValues", "validateValue"]; | ||
if (!fieldConfig.fieldSettings) fieldConfig.fieldSettings = {}; | ||
@@ -165,2 +165,4 @@ for (var _i = 0, _keysToPutInFieldSett = keysToPutInFieldSettings; _i < _keysToPutInFieldSett.length; _i++) { | ||
} | ||
// normalize listValues | ||
if (fieldConfig.fieldSettings.listValues) { | ||
@@ -171,2 +173,8 @@ if (config.settings.normalizeListValues) { | ||
} | ||
// same for treeValues | ||
if (fieldConfig.fieldSettings.treeValues) { | ||
if (config.settings.normalizeListValues) { | ||
fieldConfig.fieldSettings.treeValues = config.settings.normalizeListValues(fieldConfig.fieldSettings.treeValues, fieldConfig.type, fieldConfig.fieldSettings); | ||
} | ||
} | ||
if (!typeConfig) { | ||
@@ -173,0 +181,0 @@ //console.warn(`No type config for ${fieldConfig.type}`); |
@@ -313,11 +313,12 @@ "use strict"; | ||
var fieldSettings = fieldConfig.fieldSettings; | ||
var listValues = fieldSettings.treeValues || fieldSettings.listValues; | ||
if (valueType && valueType != wType) return ["Value should have type ".concat(wType, ", but got value of type ").concat(valueType), value]; | ||
if (jsType && !isTypeOf(value, jsType) && !fieldSettings.listValues) { | ||
//tip: can skip tye check for listValues | ||
if (jsType && !isTypeOf(value, jsType) && !listValues) { | ||
//tip: can skip type check for listValues | ||
return ["Value should have JS type ".concat(jsType, ", but got value of type ").concat((0, _typeof2["default"])(value)), value]; | ||
} | ||
if (fieldSettings) { | ||
var listValues = asyncListValues || fieldSettings.listValues; | ||
if (listValues && !fieldSettings.allowCustomValues) { | ||
return validateValueInList(value, listValues, canFix, isEndValue, config.settings.removeInvalidMultiSelectValuesOnLoad); | ||
var realListValues = asyncListValues || listValues; | ||
if (realListValues && !fieldSettings.allowCustomValues) { | ||
return validateValueInList(value, realListValues, canFix, isEndValue, config.settings.removeInvalidMultiSelectValuesOnLoad); | ||
} | ||
@@ -324,0 +325,0 @@ if (fieldSettings.min != null && value < fieldSettings.min) { |
@@ -747,3 +747,3 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty"; | ||
formatValue: function formatValue(val, fieldDef, wgtDef, isForDisplay) { | ||
var valLabel = getTitleInListValues(fieldDef.fieldSettings.listValues || fieldDef.asyncListValues, val); | ||
var valLabel = getTitleInListValues(fieldDef.fieldSettings.treeValues || fieldDef.fieldSettings.listValues || fieldDef.asyncListValues, val); | ||
return isForDisplay ? stringifyForDisplay(valLabel) : JSON.stringify(val); | ||
@@ -772,3 +772,3 @@ }, | ||
var valsLabels = vals.map(function (v) { | ||
return getTitleInListValues(fieldDef.fieldSettings.listValues || fieldDef.asyncListValues, v); | ||
return getTitleInListValues(fieldDef.fieldSettings.treeValues || fieldDef.fieldSettings.listValues || fieldDef.asyncListValues, v); | ||
}); | ||
@@ -775,0 +775,0 @@ return isForDisplay ? valsLabels.map(stringifyForDisplay) : vals.map(JSON.stringify); |
@@ -163,3 +163,3 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty"; | ||
} | ||
function buildParameters(queryType, value, operator, fieldName, config) { | ||
function buildParameters(queryType, value, operator, fieldName, config, syntax) { | ||
var textField = determineField(fieldName, config); | ||
@@ -179,3 +179,5 @@ switch (queryType) { | ||
case "term": | ||
return _defineProperty({}, fieldName, value[0]); | ||
return syntax === ES_7_SYNTAX ? _defineProperty({}, fieldName, { | ||
value: value[0] | ||
}) : _defineProperty({}, fieldName, value[0]); | ||
@@ -203,6 +205,7 @@ //todo: not used | ||
* @param {string} operator - The condition on how the value is matched | ||
* @param {string} syntax - The version of ElasticSearch syntax to generate | ||
* @returns {object} - The ES rule | ||
* @private | ||
*/ | ||
function buildEsRule(fieldName, value, operator, config, valueSrc) { | ||
function buildEsRule(fieldName, value, operator, config, valueSrc, syntax) { | ||
if (!fieldName || !operator || value == undefined) return undefined; // rule is not fully entered | ||
@@ -250,3 +253,3 @@ var op = operator; | ||
} else { | ||
parameters = buildParameters(queryType, value, op, fieldName, config); | ||
parameters = buildParameters(queryType, value, op, fieldName, config, syntax); | ||
} | ||
@@ -274,3 +277,3 @@ if (not) { | ||
*/ | ||
function buildEsGroup(children, conjunction, not, recursiveFxn, config) { | ||
function buildEsGroup(children, conjunction, not, recursiveFxn, config, syntax) { | ||
if (!children || !children.size) return undefined; | ||
@@ -280,3 +283,3 @@ var childrenArray = children.valueSeq().toArray(); | ||
var result = childrenArray.map(function (c) { | ||
return recursiveFxn(c, config); | ||
return recursiveFxn(c, config, syntax); | ||
}).filter(function (v) { | ||
@@ -291,3 +294,6 @@ return v !== undefined; | ||
} | ||
export var ES_7_SYNTAX = "ES_7_SYNTAX"; | ||
export var ES_6_SYNTAX = "ES_6_SYNTAX"; | ||
export function elasticSearchFormat(tree, config) { | ||
var syntax = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ES_6_SYNTAX; | ||
// -- format the es dsl here | ||
@@ -312,6 +318,6 @@ if (!tree) return undefined; | ||
return value[0].map(function (val) { | ||
return buildEsRule(field, [val], operator, config, valueSrc); | ||
return buildEsRule(field, [val], operator, config, valueSrc, syntax); | ||
}); | ||
} else { | ||
return buildEsRule(field, value, operator, config, valueSrc); | ||
return buildEsRule(field, value, operator, config, valueSrc, syntax); | ||
} | ||
@@ -324,4 +330,4 @@ } | ||
var children = tree.get("children1"); | ||
return buildEsGroup(children, conjunction, not, elasticSearchFormat, config); | ||
return buildEsGroup(children, conjunction, not, elasticSearchFormat, config, syntax); | ||
} | ||
} |
@@ -76,3 +76,3 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray"; | ||
var list = children.map(function (currentChild) { | ||
return formatItem([].concat(_toConsumableArray(parents), [item]), currentChild, config, meta, not, true, mode == "array" ? function (f) { | ||
return formatItem([].concat(_toConsumableArray(parents), [item]), currentChild, config, meta, not, mode != "array", mode == "array" ? function (f) { | ||
return "$$el.".concat(f); | ||
@@ -146,7 +146,9 @@ } : undefined); | ||
"$size": { | ||
"$filter": { | ||
input: "$" + groupFieldName, | ||
as: "el", | ||
cond: resultQuery | ||
} | ||
"$ifNull": [{ | ||
"$filter": { | ||
input: "$" + groupFieldName, | ||
as: "el", | ||
cond: resultQuery | ||
} | ||
}, []] | ||
} | ||
@@ -153,0 +155,0 @@ } : totalQuery; |
/* eslint-disable no-extra-semi */ | ||
import {List as ImmutableList, Map as ImmutableMap, OrderedMap as ImmutableOMap} from "immutable"; | ||
import {List as ImmList, Map as ImmMap, OrderedMap as ImmOMap} from "immutable"; | ||
import {ElementType, ReactElement, Factory} from "react"; | ||
@@ -8,2 +8,5 @@ import type { Moment as MomentType } from "moment"; | ||
export type Moment = MomentType; | ||
export type ImmutableList<T> = ImmList<T>; | ||
export type ImmutableMap<K, V> = ImmMap<K, V>; | ||
export type ImmutableOMap<K, V> = ImmOMap<K, V>; | ||
@@ -53,3 +56,3 @@ //////////////// | ||
type RuleValue = boolean | number | string | Date | Array<string> | any; | ||
export type RuleValue = boolean | number | string | Date | Array<string> | any; | ||
@@ -177,3 +180,3 @@ export type ValueSource = "value" | "field" | "func" | "const"; | ||
_mongodbFormat(tree: ImmutableTree, config: Config): [Object | undefined, Array<string>]; | ||
elasticSearchFormat(tree: ImmutableTree, config: Config): Object | undefined; | ||
elasticSearchFormat(tree: ImmutableTree, config: Config, syntax?: "ES_6_SYNTAX" | "ES_7_SYNTAX"): Object | undefined; | ||
// load, save | ||
@@ -319,5 +322,3 @@ getTree(tree: ImmutableTree, light?: boolean, children1AsArray?: boolean): JsonTree; | ||
interface BaseWidgetProps { | ||
value: RuleValue, | ||
setValue(val: RuleValue, asyncListValues?: Array<any>): void, | ||
interface AbstractWidgetProps<C = Config> { | ||
placeholder: string, | ||
@@ -328,3 +329,3 @@ field: string, | ||
fieldDefinition: Field, | ||
config: Config, | ||
config: C, | ||
delta?: number, | ||
@@ -336,17 +337,33 @@ customProps?: AnyObject, | ||
} | ||
interface RangeWidgetProps extends BaseWidgetProps { | ||
interface BaseWidgetProps<C = Config, V = RuleValue> extends AbstractWidgetProps<C> { | ||
value: V | Empty, | ||
setValue(val: V | Empty, asyncListValues?: Array<any>): void, | ||
} | ||
interface RangeWidgetProps<C = Config, V = RuleValue> extends AbstractWidgetProps<C> { | ||
value: Array<V | Empty>, | ||
setValue(val: Array<V | Empty>, asyncListValues?: Array<any>): void, | ||
placeholders: Array<string>, | ||
textSeparators: Array<string>, | ||
} | ||
export type WidgetProps = (BaseWidgetProps | RangeWidgetProps) & FieldSettings; | ||
// BaseWidgetProps | RangeWidgetProps | ||
interface RangeableWidgetProps<C = Config, V = RuleValue> extends AbstractWidgetProps<C> { | ||
value: V | Empty | Array<V | Empty>, | ||
setValue(val: V | Empty | Array<V | Empty>, asyncListValues?: Array<any>): void, | ||
placeholders?: Array<string>, | ||
textSeparators?: Array<string>, | ||
} | ||
export type WidgetProps<C = Config> = RangeableWidgetProps<C> & FieldSettings; | ||
export type TextWidgetProps = BaseWidgetProps & TextFieldSettings; | ||
export type DateTimeWidgetProps = BaseWidgetProps & DateTimeFieldSettings; | ||
export type BooleanWidgetProps = BaseWidgetProps & BooleanFieldSettings; | ||
export type NumberWidgetProps = BaseWidgetProps & NumberFieldSettings; | ||
export type SelectWidgetProps = BaseWidgetProps & SelectFieldSettings; | ||
export type TreeSelectWidgetProps = BaseWidgetProps & TreeSelectFieldSettings; | ||
export type RangeSliderWidgetProps = RangeWidgetProps & NumberFieldSettings; | ||
export type CaseValueWidgetProps = BaseWidgetProps & CaseValueFieldSettings; | ||
export type TextWidgetProps<C = Config> = BaseWidgetProps<C, string> & TextFieldSettings; | ||
export type DateTimeWidgetProps<C = Config> = RangeableWidgetProps<C, string> & DateTimeFieldSettings; | ||
export type BooleanWidgetProps<C = Config> = BaseWidgetProps<C, boolean> & BooleanFieldSettings; | ||
export type NumberWidgetProps<C = Config> = RangeableWidgetProps<C, number> & NumberFieldSettings; | ||
export type RangeSliderWidgetProps<C = Config> = RangeableWidgetProps<C, number> & NumberFieldSettings; | ||
export type SelectWidgetProps<C = Config> = BaseWidgetProps<C, string | number> & SelectFieldSettings; | ||
export type MultiSelectWidgetProps<C = Config> = BaseWidgetProps<C, string[] | number[]> & MultiSelectFieldSettings; | ||
export type TreeSelectWidgetProps<C = Config> = BaseWidgetProps<C, string | number> & TreeSelectFieldSettings; | ||
export type TreeMultiSelectWidgetProps<C = Config> = BaseWidgetProps<C, string[] | number[]> & TreeMultiSelectFieldSettings; | ||
export type CaseValueWidgetProps<C = Config> = BaseWidgetProps<C> & CaseValueFieldSettings; | ||
///////////////// | ||
@@ -369,3 +386,3 @@ // FieldProps | ||
export interface FieldProps { | ||
export interface FieldProps<C = Config> { | ||
items: FieldItems, | ||
@@ -379,3 +396,3 @@ setField(fieldPath: string): void, | ||
selectedFullLabel?: string | Empty, | ||
config?: Config, | ||
config?: C, | ||
customProps?: AnyObject, | ||
@@ -395,12 +412,12 @@ placeholder?: string, | ||
type FormatValue = (val: RuleValue, fieldDef: Field, wgtDef: Widget, isForDisplay: boolean, op: string, opDef: Operator, rightFieldDef?: Field) => string; | ||
type SqlFormatValue = (val: RuleValue, fieldDef: Field, wgtDef: Widget, op: string, opDef: Operator, rightFieldDef?: Field) => string; | ||
type SpelFormatValue = (val: RuleValue, fieldDef: Field, wgtDef: Widget, op: string, opDef: Operator, rightFieldDef?: Field) => string; | ||
type MongoFormatValue = (val: RuleValue, fieldDef: Field, wgtDef: Widget, op: string, opDef: Operator) => MongoValue; | ||
type JsonLogicFormatValue = (val: RuleValue, fieldDef: Field, wgtDef: Widget, op: string, opDef: Operator) => JsonLogicValue; | ||
type ValidateValue = (val: RuleValue, fieldSettings: FieldSettings, op: string, opDef: Operator, rightFieldDef?: Field) => boolean | string | null; | ||
type ElasticSearchFormatValue = (queryType: ElasticSearchQueryType, val: RuleValue, op: string, field: string, config: Config) => AnyObject | null; | ||
type FormatValue = (val: RuleValue, fieldDef: Field, wgtDef: Widget, isForDisplay: boolean, op: string, opDef: Operator, rightFieldDef?: Field) => string; | ||
type SqlFormatValue = (val: RuleValue, fieldDef: Field, wgtDef: Widget, op: string, opDef: Operator, rightFieldDef?: Field) => string; | ||
type SpelFormatValue = (val: RuleValue, fieldDef: Field, wgtDef: Widget, op: string, opDef: Operator, rightFieldDef?: Field) => string; | ||
type MongoFormatValue = (val: RuleValue, fieldDef: Field, wgtDef: Widget, op: string, opDef: Operator) => MongoValue; | ||
type JsonLogicFormatValue = (val: RuleValue, fieldDef: Field, wgtDef: Widget, op: string, opDef: Operator) => JsonLogicValue; | ||
type ValidateValue<V = RuleValue> = (val: V, fieldSettings: FieldSettings, op: string, opDef: Operator, rightFieldDef?: Field) => boolean | string | null; | ||
type ElasticSearchFormatValue = (queryType: ElasticSearchQueryType, val: RuleValue, op: string, field: string, config: Config) => AnyObject | null; | ||
export interface BaseWidget { | ||
export interface BaseWidget<C = Config, WP = WidgetProps<C>> { | ||
type: string; | ||
@@ -423,11 +440,10 @@ jsType?: string; | ||
//@ui | ||
factory: Factory<WidgetProps>; | ||
factory: Factory<WP>; | ||
customProps?: AnyObject; | ||
} | ||
export interface RangeableWidget extends BaseWidget { | ||
export interface RangeableWidget<C = Config, WP = WidgetProps<C>> extends BaseWidget<C, WP> { | ||
singleWidget?: string, | ||
valueLabels?: Array<string | {label: string, placeholder: string}>, | ||
} | ||
export interface FieldWidget { | ||
valueSrc: "field", | ||
interface BaseFieldWidget<C = Config, WP = WidgetProps<C>> { | ||
valuePlaceholder?: string, | ||
@@ -442,16 +458,44 @@ valueLabel?: string, | ||
customProps?: AnyObject, | ||
factory?: Factory<WP>, | ||
} | ||
export interface FieldWidget<C = Config, WP = WidgetProps<C>> extends BaseFieldWidget<C, WP> { | ||
valueSrc: "field", | ||
} | ||
export interface FuncWidget<C = Config, WP = WidgetProps<C>> extends BaseFieldWidget<C, WP> { | ||
valueSrc: "func", | ||
} | ||
export type TextWidget = BaseWidget & TextFieldSettings; | ||
export type DateTimeWidget = RangeableWidget & DateTimeFieldSettings; | ||
export type BooleanWidget = BaseWidget & BooleanFieldSettings; | ||
export type NumberWidget = RangeableWidget & NumberFieldSettings; | ||
export type SelectWidget = BaseWidget & SelectFieldSettings; | ||
export type TreeSelectWidget = BaseWidget & TreeSelectFieldSettings; | ||
export type CaseValueWidget = BaseWidget & CaseValueFieldSettings; | ||
export type TextWidget<C = Config, WP = TextWidgetProps<C>> = BaseWidget<C, WP> & TextFieldSettings; | ||
export type DateTimeWidget<C = Config, WP = DateTimeWidgetProps<C>> = RangeableWidget<C, WP> & DateTimeFieldSettings; | ||
export type BooleanWidget<C = Config, WP = BooleanWidgetProps<C>> = BaseWidget<C, WP> & BooleanFieldSettings; | ||
export type NumberWidget<C = Config, WP = NumberWidgetProps<C>> = RangeableWidget<C, WP> & NumberFieldSettings; | ||
export type RangeSliderWidget<C = Config, WP = RangeSliderWidgetProps<C>> = RangeableWidget<C, WP> & NumberFieldSettings; | ||
export type SelectWidget<C = Config, WP = SelectWidgetProps<C>> = BaseWidget<C, WP> & SelectFieldSettings; | ||
export type MultiSelectWidget<C = Config, WP = MultiSelectWidgetProps<C>> = BaseWidget<C, WP> & MultiSelectFieldSettings; | ||
export type TreeSelectWidget<C = Config, WP = TreeSelectWidgetProps<C>> = BaseWidget<C, WP> & TreeSelectFieldSettings; | ||
export type TreeMultiSelectWidget<C = Config, WP = TreeMultiSelectWidgetProps<C>> = BaseWidget<C, WP> & TreeMultiSelectFieldSettings; | ||
export type CaseValueWidget<C = Config, WP = CaseValueWidgetProps<C>> = BaseWidget<C, WP> & CaseValueFieldSettings; | ||
export type Widget = FieldWidget | TextWidget | DateTimeWidget | BooleanWidget | NumberWidget | SelectWidget | TreeSelectWidget | RangeableWidget | BaseWidget; | ||
export type Widgets = TypedMap<Widget>; | ||
// tip: use generic WidgetProps here, TS can't determine correct factory | ||
export type TypedWidget<C = Config> = | ||
TextWidget<C, WidgetProps<C>> | ||
| DateTimeWidget<C, WidgetProps<C>> | ||
| BooleanWidget<C, WidgetProps<C>> | ||
| NumberWidget<C, WidgetProps<C>> | ||
| RangeSliderWidget<C, WidgetProps<C>> | ||
| SelectWidget<C, WidgetProps<C>> | ||
| MultiSelectWidget<C, WidgetProps<C>> | ||
| TreeSelectWidget<C, WidgetProps<C>> | ||
| TreeMultiSelectWidget<C, WidgetProps<C>> | ||
| CaseValueWidget<C, WidgetProps<C>>; | ||
export type Widget<C = Config> = | ||
FieldWidget<C> | ||
| FuncWidget<C> | ||
| TypedWidget<C> | ||
| RangeableWidget<C> | ||
| BaseWidget<C>; | ||
export type Widgets<C = Config> = TypedMap<Widget<C>>; | ||
///////////////// | ||
@@ -528,12 +572,13 @@ // Conjunctions | ||
} | ||
export interface ProximityProps extends ProximityConfig { | ||
export interface ProximityProps<C = Config> extends ProximityConfig { | ||
options: ImmutableMap<string, any>, | ||
setOption: (key: string, value: any) => void, | ||
config: Config, | ||
config: C, | ||
} | ||
export interface ProximityOptions extends ProximityConfig { | ||
factory: Factory<ProximityProps>, | ||
export interface ProximityOptions<C = Config, PP = ProximityProps<C>> extends ProximityConfig { | ||
//@ui | ||
factory: Factory<PP>, | ||
} | ||
interface BaseOperator { | ||
export interface BaseOperator { | ||
label: string, | ||
@@ -556,9 +601,9 @@ reversedOp?: string, | ||
} | ||
interface UnaryOperator extends BaseOperator { | ||
export interface UnaryOperator extends BaseOperator { | ||
//cardinality: 0, | ||
} | ||
interface BinaryOperator extends BaseOperator { | ||
export interface BinaryOperator extends BaseOperator { | ||
//cardinality: 1, | ||
} | ||
interface Operator2 extends BaseOperator { | ||
export interface Operator2 extends BaseOperator { | ||
//cardinality: 2 | ||
@@ -569,7 +614,7 @@ textSeparators: Array<string>, | ||
} | ||
interface OperatorProximity extends Operator2 { | ||
options: ProximityOptions, | ||
export interface OperatorProximity<C = Config> extends Operator2 { | ||
options: ProximityOptions<C, ProximityProps<C>>, | ||
} | ||
export type Operator = UnaryOperator | BinaryOperator | Operator2 | OperatorProximity; | ||
export type Operators = TypedMap<Operator>; | ||
export type Operator<C = Config> = UnaryOperator | BinaryOperator | Operator2 | OperatorProximity<C>; | ||
export type Operators<C = Config> = TypedMap<Operator<C>>; | ||
@@ -628,10 +673,10 @@ | ||
export interface BasicFieldSettings { | ||
validateValue?: ValidateValue, | ||
export interface BasicFieldSettings<V = RuleValue> { | ||
validateValue?: ValidateValue<V>, | ||
} | ||
export interface TextFieldSettings extends BasicFieldSettings { | ||
export interface TextFieldSettings<V = string> extends BasicFieldSettings<V> { | ||
maxLength?: number, | ||
maxRows?: number, | ||
} | ||
export interface NumberFieldSettings extends BasicFieldSettings { | ||
export interface NumberFieldSettings<V = number> extends BasicFieldSettings<V> { | ||
min?: number, | ||
@@ -642,3 +687,3 @@ max?: number, | ||
} | ||
export interface DateTimeFieldSettings extends BasicFieldSettings { | ||
export interface DateTimeFieldSettings<V = string> extends BasicFieldSettings<V> { | ||
timeFormat?: string, | ||
@@ -650,3 +695,3 @@ dateFormat?: string, | ||
} | ||
export interface SelectFieldSettings extends BasicFieldSettings { | ||
export interface SelectFieldSettings<V = string | number> extends BasicFieldSettings<V> { | ||
listValues?: ListValues, | ||
@@ -661,14 +706,28 @@ allowCustomValues?: boolean, | ||
} | ||
export interface TreeSelectFieldSettings extends BasicFieldSettings { | ||
listValues?: TreeData, | ||
export interface MultiSelectFieldSettings<V = string[] | number[]> extends SelectFieldSettings<V> { | ||
} | ||
export interface TreeSelectFieldSettings<V = string | number> extends BasicFieldSettings<V> { | ||
treeValues?: TreeData, | ||
treeExpandAll?: boolean, | ||
treeSelectOnlyLeafs?: boolean, | ||
} | ||
export interface BooleanFieldSettings extends BasicFieldSettings { | ||
export interface TreeMultiSelectFieldSettings<V = string[] | number[]> extends TreeSelectFieldSettings<V> { | ||
} | ||
export interface BooleanFieldSettings<V = boolean> extends BasicFieldSettings<V> { | ||
labelYes?: ReactElement | string, | ||
labelNo?: ReactElement | string, | ||
} | ||
export interface CaseValueFieldSettings extends BasicFieldSettings { | ||
export interface CaseValueFieldSettings<V = any> extends BasicFieldSettings<V> { | ||
} | ||
export type FieldSettings = NumberFieldSettings | DateTimeFieldSettings | SelectFieldSettings | TreeSelectFieldSettings | BooleanFieldSettings | TextFieldSettings | BasicFieldSettings; | ||
// tip: use RuleValue here, TS can't determine correct types in `validateValue` | ||
export type FieldSettings = | ||
NumberFieldSettings<RuleValue> | ||
| DateTimeFieldSettings<RuleValue> | ||
| SelectFieldSettings<RuleValue> | ||
| MultiSelectFieldSettings<RuleValue> | ||
| TreeSelectFieldSettings<RuleValue> | ||
| TreeMultiSelectFieldSettings<RuleValue> | ||
| BooleanFieldSettings<RuleValue> | ||
| TextFieldSettings<RuleValue> | ||
| BasicFieldSettings<RuleValue>; | ||
@@ -900,65 +959,73 @@ interface BaseField { | ||
export interface CoreOperators<C = Config> extends Operators<C> { | ||
equal: BinaryOperator, | ||
not_equal: BinaryOperator, | ||
less: BinaryOperator, | ||
less_or_equal: BinaryOperator, | ||
greater: BinaryOperator, | ||
greater_or_equal: BinaryOperator, | ||
like: BinaryOperator, | ||
not_like: BinaryOperator, | ||
starts_with: BinaryOperator, | ||
ends_with: BinaryOperator, | ||
between: Operator2, | ||
not_between: Operator2, | ||
is_null: UnaryOperator, | ||
is_not_null: UnaryOperator, | ||
is_empty: UnaryOperator, | ||
is_not_empty: UnaryOperator, | ||
select_equals: BinaryOperator, | ||
select_not_equals: BinaryOperator, | ||
select_any_in: BinaryOperator, | ||
select_not_any_in: BinaryOperator, | ||
multiselect_contains: BinaryOperator, | ||
multiselect_not_contains: BinaryOperator, | ||
multiselect_equals: BinaryOperator, | ||
multiselect_not_equals: BinaryOperator, | ||
proximity: OperatorProximity<C>, | ||
} | ||
export interface CoreConjunctions extends Conjunctions { | ||
AND: Conjunction, | ||
OR: Conjunction, | ||
} | ||
export interface CoreWidgets<C = Config> extends Widgets<C> { | ||
text: TextWidget<C>, | ||
textarea: TextWidget<C>, | ||
number: NumberWidget<C>, | ||
slider: NumberWidget<C>, | ||
rangeslider: RangeSliderWidget<C>, | ||
select: SelectWidget<C>, | ||
multiselect: MultiSelectWidget<C>, | ||
treeselect: TreeSelectWidget<C>, | ||
treemultiselect: TreeMultiSelectWidget<C>, | ||
date: DateTimeWidget<C>, | ||
time: DateTimeWidget<C>, | ||
datetime: DateTimeWidget<C>, | ||
boolean: BooleanWidget<C>, | ||
field: FieldWidget<C>, | ||
func: FuncWidget<C>, | ||
case_value: CaseValueWidget<C>, | ||
} | ||
export interface CoreTypes extends Types { | ||
text: Type, | ||
number: Type, | ||
date: Type, | ||
time: Type, | ||
datetime: Type, | ||
select: Type, | ||
multiselect: Type, | ||
treeselect: Type, | ||
treemultiselect: Type, | ||
boolean: Type, | ||
case_value: Type, | ||
} | ||
export interface CoreConfig extends Config { | ||
conjunctions: { | ||
AND: Conjunction, | ||
OR: Conjunction, | ||
}, | ||
operators: { | ||
equal: BinaryOperator, | ||
not_equal: BinaryOperator, | ||
less: BinaryOperator, | ||
less_or_equal: BinaryOperator, | ||
greater: BinaryOperator, | ||
greater_or_equal: BinaryOperator, | ||
like: BinaryOperator, | ||
not_like: BinaryOperator, | ||
starts_with: BinaryOperator, | ||
ends_with: BinaryOperator, | ||
between: Operator2, | ||
not_between: Operator2, | ||
is_null: UnaryOperator, | ||
is_not_null: UnaryOperator, | ||
is_empty: UnaryOperator, | ||
is_not_empty: UnaryOperator, | ||
select_equals: BinaryOperator, | ||
select_not_equals: BinaryOperator, | ||
select_any_in: BinaryOperator, | ||
select_not_any_in: BinaryOperator, | ||
multiselect_contains: BinaryOperator, | ||
multiselect_not_contains: BinaryOperator, | ||
multiselect_equals: BinaryOperator, | ||
multiselect_not_equals: BinaryOperator, | ||
proximity: OperatorProximity, | ||
}, | ||
widgets: { | ||
text: TextWidget, | ||
textarea: TextWidget, | ||
number: NumberWidget, | ||
slider: NumberWidget, | ||
rangeslider: NumberWidget, | ||
select: SelectWidget, | ||
multiselect: SelectWidget, | ||
treeselect: TreeSelectWidget, | ||
treemultiselect: TreeSelectWidget, | ||
date: DateTimeWidget, | ||
time: DateTimeWidget, | ||
datetime: DateTimeWidget, | ||
boolean: BooleanWidget, | ||
field: FieldWidget, | ||
func: FieldWidget, | ||
case_value: CaseValueWidget, | ||
}, | ||
types: { | ||
text: Type, | ||
number: Type, | ||
date: Type, | ||
time: Type, | ||
datetime: Type, | ||
select: Type, | ||
multiselect: Type, | ||
treeselect: Type, | ||
treemultiselect: Type, | ||
boolean: Type, | ||
case_value: Type, | ||
}, | ||
conjunctions: CoreConjunctions, | ||
operators: CoreOperators, | ||
widgets: CoreWidgets, | ||
types: CoreTypes, | ||
settings: Settings, | ||
@@ -965,0 +1032,0 @@ } |
@@ -147,3 +147,3 @@ import _typeof from "@babel/runtime/helpers/typeof"; | ||
if (fieldConfig.type != "!struct" && fieldConfig.type != "!group") { | ||
var keysToPutInFieldSettings = ["listValues", "allowCustomValues", "validateValue"]; | ||
var keysToPutInFieldSettings = ["listValues", "treeValues", "allowCustomValues", "validateValue"]; | ||
if (!fieldConfig.fieldSettings) fieldConfig.fieldSettings = {}; | ||
@@ -157,2 +157,4 @@ for (var _i = 0, _keysToPutInFieldSett = keysToPutInFieldSettings; _i < _keysToPutInFieldSett.length; _i++) { | ||
} | ||
// normalize listValues | ||
if (fieldConfig.fieldSettings.listValues) { | ||
@@ -163,2 +165,8 @@ if (config.settings.normalizeListValues) { | ||
} | ||
// same for treeValues | ||
if (fieldConfig.fieldSettings.treeValues) { | ||
if (config.settings.normalizeListValues) { | ||
fieldConfig.fieldSettings.treeValues = config.settings.normalizeListValues(fieldConfig.fieldSettings.treeValues, fieldConfig.type, fieldConfig.fieldSettings); | ||
} | ||
} | ||
if (!typeConfig) { | ||
@@ -165,0 +173,0 @@ //console.warn(`No type config for ${fieldConfig.type}`); |
@@ -303,11 +303,12 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray"; | ||
var fieldSettings = fieldConfig.fieldSettings; | ||
var listValues = fieldSettings.treeValues || fieldSettings.listValues; | ||
if (valueType && valueType != wType) return ["Value should have type ".concat(wType, ", but got value of type ").concat(valueType), value]; | ||
if (jsType && !isTypeOf(value, jsType) && !fieldSettings.listValues) { | ||
//tip: can skip tye check for listValues | ||
if (jsType && !isTypeOf(value, jsType) && !listValues) { | ||
//tip: can skip type check for listValues | ||
return ["Value should have JS type ".concat(jsType, ", but got value of type ").concat(_typeof(value)), value]; | ||
} | ||
if (fieldSettings) { | ||
var listValues = asyncListValues || fieldSettings.listValues; | ||
if (listValues && !fieldSettings.allowCustomValues) { | ||
return validateValueInList(value, listValues, canFix, isEndValue, config.settings.removeInvalidMultiSelectValuesOnLoad); | ||
var realListValues = asyncListValues || listValues; | ||
if (realListValues && !fieldSettings.allowCustomValues) { | ||
return validateValueInList(value, realListValues, canFix, isEndValue, config.settings.removeInvalidMultiSelectValuesOnLoad); | ||
} | ||
@@ -314,0 +315,0 @@ if (fieldSettings.min != null && value < fieldSettings.min) { |
@@ -702,3 +702,3 @@ import { | ||
formatValue: (val, fieldDef, wgtDef, isForDisplay) => { | ||
let valLabel = getTitleInListValues(fieldDef.fieldSettings.listValues || fieldDef.asyncListValues, val); | ||
let valLabel = getTitleInListValues(fieldDef.fieldSettings.treeValues || fieldDef.fieldSettings.listValues || fieldDef.asyncListValues, val); | ||
return isForDisplay ? stringifyForDisplay(valLabel) : JSON.stringify(val); | ||
@@ -720,3 +720,3 @@ }, | ||
formatValue: (vals, fieldDef, wgtDef, isForDisplay) => { | ||
let valsLabels = vals.map(v => getTitleInListValues(fieldDef.fieldSettings.listValues || fieldDef.asyncListValues, v)); | ||
let valsLabels = vals.map(v => getTitleInListValues(fieldDef.fieldSettings.treeValues || fieldDef.fieldSettings.listValues || fieldDef.asyncListValues, v)); | ||
return isForDisplay ? valsLabels.map(stringifyForDisplay) : vals.map(JSON.stringify); | ||
@@ -723,0 +723,0 @@ }, |
@@ -173,3 +173,3 @@ import {getWidgetForFieldOp} from "../utils/ruleUtils"; | ||
function buildParameters(queryType, value, operator, fieldName, config) { | ||
function buildParameters(queryType, value, operator, fieldName, config, syntax) { | ||
const textField = determineField(fieldName, config); | ||
@@ -190,3 +190,6 @@ switch (queryType) { | ||
case "term": | ||
return { [fieldName]: value[0] }; | ||
return syntax === ES_7_SYNTAX | ||
? { [fieldName]: { | ||
value: value[0] | ||
}} : { [fieldName]: value[0] }; | ||
@@ -218,6 +221,7 @@ //todo: not used | ||
* @param {string} operator - The condition on how the value is matched | ||
* @param {string} syntax - The version of ElasticSearch syntax to generate | ||
* @returns {object} - The ES rule | ||
* @private | ||
*/ | ||
function buildEsRule(fieldName, value, operator, config, valueSrc) { | ||
function buildEsRule(fieldName, value, operator, config, valueSrc, syntax) { | ||
if (!fieldName || !operator || value == undefined) | ||
@@ -267,3 +271,3 @@ return undefined; // rule is not fully entered | ||
} else { | ||
parameters = buildParameters(queryType, value, op, fieldName, config); | ||
parameters = buildParameters(queryType, value, op, fieldName, config, syntax); | ||
} | ||
@@ -296,3 +300,3 @@ | ||
*/ | ||
function buildEsGroup(children, conjunction, not, recursiveFxn, config) { | ||
function buildEsGroup(children, conjunction, not, recursiveFxn, config, syntax) { | ||
if (!children || !children.size) | ||
@@ -302,3 +306,3 @@ return undefined; | ||
const occurrence = determineOccurrence(conjunction, not); | ||
const result = childrenArray.map((c) => recursiveFxn(c, config)).filter(v => v !== undefined); | ||
const result = childrenArray.map((c) => recursiveFxn(c, config, syntax)).filter(v => v !== undefined); | ||
if (!result.length) | ||
@@ -314,3 +318,6 @@ return undefined; | ||
export function elasticSearchFormat(tree, config) { | ||
export const ES_7_SYNTAX = "ES_7_SYNTAX"; | ||
export const ES_6_SYNTAX = "ES_6_SYNTAX"; | ||
export function elasticSearchFormat(tree, config, syntax = ES_6_SYNTAX) { | ||
// -- format the es dsl here | ||
@@ -336,7 +343,7 @@ if (!tree) return undefined; | ||
//TODO : Handle case where the value has multiple values such as in the case of a list | ||
return value[0].map((val) => | ||
buildEsRule(field, [val], operator, config, valueSrc) | ||
return value[0].map((val) => | ||
buildEsRule(field, [val], operator, config, valueSrc, syntax) | ||
); | ||
} else { | ||
return buildEsRule(field, value, operator, config, valueSrc); | ||
return buildEsRule(field, value, operator, config, valueSrc, syntax); | ||
} | ||
@@ -351,4 +358,4 @@ } | ||
const children = tree.get("children1"); | ||
return buildEsGroup(children, conjunction, not, elasticSearchFormat, config); | ||
return buildEsGroup(children, conjunction, not, elasticSearchFormat, config, syntax); | ||
} | ||
} |
@@ -74,3 +74,3 @@ import {defaultValue} from "../utils/stuff"; | ||
.map((currentChild) => formatItem( | ||
[...parents, item], currentChild, config, meta, not, true, mode == "array" ? (f => `$$el.${f}`) : undefined) | ||
[...parents, item], currentChild, config, meta, not, mode != "array", mode == "array" ? (f => `$$el.${f}`) : undefined) | ||
) | ||
@@ -139,7 +139,12 @@ .filter((currentChild) => typeof currentChild !== "undefined"); | ||
"$size": { | ||
"$filter": { | ||
input: "$" + groupFieldName, | ||
as: "el", | ||
cond: resultQuery | ||
} | ||
"$ifNull": [ | ||
{ | ||
"$filter": { | ||
input: "$" + groupFieldName, | ||
as: "el", | ||
cond: resultQuery | ||
} | ||
}, | ||
[] | ||
] | ||
} | ||
@@ -222,3 +227,3 @@ } : totalQuery; | ||
const formattedValue = cardinality > 1 ? fvalue.toArray() : (cardinality == 1 ? fvalue.first() : null); | ||
//build rule | ||
@@ -255,3 +260,3 @@ const fn = operatorDefinition.mongoFormatOp; | ||
return [undefined, false]; | ||
let ret; | ||
@@ -258,0 +263,0 @@ let useExpr = false; |
/* eslint-disable no-extra-semi */ | ||
import {List as ImmutableList, Map as ImmutableMap, OrderedMap as ImmutableOMap} from "immutable"; | ||
import {List as ImmList, Map as ImmMap, OrderedMap as ImmOMap} from "immutable"; | ||
import {ElementType, ReactElement, Factory} from "react"; | ||
@@ -8,2 +8,5 @@ import type { Moment as MomentType } from "moment"; | ||
export type Moment = MomentType; | ||
export type ImmutableList<T> = ImmList<T>; | ||
export type ImmutableMap<K, V> = ImmMap<K, V>; | ||
export type ImmutableOMap<K, V> = ImmOMap<K, V>; | ||
@@ -53,3 +56,3 @@ //////////////// | ||
type RuleValue = boolean | number | string | Date | Array<string> | any; | ||
export type RuleValue = boolean | number | string | Date | Array<string> | any; | ||
@@ -177,3 +180,3 @@ export type ValueSource = "value" | "field" | "func" | "const"; | ||
_mongodbFormat(tree: ImmutableTree, config: Config): [Object | undefined, Array<string>]; | ||
elasticSearchFormat(tree: ImmutableTree, config: Config): Object | undefined; | ||
elasticSearchFormat(tree: ImmutableTree, config: Config, syntax?: "ES_6_SYNTAX" | "ES_7_SYNTAX"): Object | undefined; | ||
// load, save | ||
@@ -319,5 +322,3 @@ getTree(tree: ImmutableTree, light?: boolean, children1AsArray?: boolean): JsonTree; | ||
interface BaseWidgetProps { | ||
value: RuleValue, | ||
setValue(val: RuleValue, asyncListValues?: Array<any>): void, | ||
interface AbstractWidgetProps<C = Config> { | ||
placeholder: string, | ||
@@ -328,3 +329,3 @@ field: string, | ||
fieldDefinition: Field, | ||
config: Config, | ||
config: C, | ||
delta?: number, | ||
@@ -336,17 +337,33 @@ customProps?: AnyObject, | ||
} | ||
interface RangeWidgetProps extends BaseWidgetProps { | ||
interface BaseWidgetProps<C = Config, V = RuleValue> extends AbstractWidgetProps<C> { | ||
value: V | Empty, | ||
setValue(val: V | Empty, asyncListValues?: Array<any>): void, | ||
} | ||
interface RangeWidgetProps<C = Config, V = RuleValue> extends AbstractWidgetProps<C> { | ||
value: Array<V | Empty>, | ||
setValue(val: Array<V | Empty>, asyncListValues?: Array<any>): void, | ||
placeholders: Array<string>, | ||
textSeparators: Array<string>, | ||
} | ||
export type WidgetProps = (BaseWidgetProps | RangeWidgetProps) & FieldSettings; | ||
// BaseWidgetProps | RangeWidgetProps | ||
interface RangeableWidgetProps<C = Config, V = RuleValue> extends AbstractWidgetProps<C> { | ||
value: V | Empty | Array<V | Empty>, | ||
setValue(val: V | Empty | Array<V | Empty>, asyncListValues?: Array<any>): void, | ||
placeholders?: Array<string>, | ||
textSeparators?: Array<string>, | ||
} | ||
export type WidgetProps<C = Config> = RangeableWidgetProps<C> & FieldSettings; | ||
export type TextWidgetProps = BaseWidgetProps & TextFieldSettings; | ||
export type DateTimeWidgetProps = BaseWidgetProps & DateTimeFieldSettings; | ||
export type BooleanWidgetProps = BaseWidgetProps & BooleanFieldSettings; | ||
export type NumberWidgetProps = BaseWidgetProps & NumberFieldSettings; | ||
export type SelectWidgetProps = BaseWidgetProps & SelectFieldSettings; | ||
export type TreeSelectWidgetProps = BaseWidgetProps & TreeSelectFieldSettings; | ||
export type RangeSliderWidgetProps = RangeWidgetProps & NumberFieldSettings; | ||
export type CaseValueWidgetProps = BaseWidgetProps & CaseValueFieldSettings; | ||
export type TextWidgetProps<C = Config> = BaseWidgetProps<C, string> & TextFieldSettings; | ||
export type DateTimeWidgetProps<C = Config> = RangeableWidgetProps<C, string> & DateTimeFieldSettings; | ||
export type BooleanWidgetProps<C = Config> = BaseWidgetProps<C, boolean> & BooleanFieldSettings; | ||
export type NumberWidgetProps<C = Config> = RangeableWidgetProps<C, number> & NumberFieldSettings; | ||
export type RangeSliderWidgetProps<C = Config> = RangeableWidgetProps<C, number> & NumberFieldSettings; | ||
export type SelectWidgetProps<C = Config> = BaseWidgetProps<C, string | number> & SelectFieldSettings; | ||
export type MultiSelectWidgetProps<C = Config> = BaseWidgetProps<C, string[] | number[]> & MultiSelectFieldSettings; | ||
export type TreeSelectWidgetProps<C = Config> = BaseWidgetProps<C, string | number> & TreeSelectFieldSettings; | ||
export type TreeMultiSelectWidgetProps<C = Config> = BaseWidgetProps<C, string[] | number[]> & TreeMultiSelectFieldSettings; | ||
export type CaseValueWidgetProps<C = Config> = BaseWidgetProps<C> & CaseValueFieldSettings; | ||
///////////////// | ||
@@ -369,3 +386,3 @@ // FieldProps | ||
export interface FieldProps { | ||
export interface FieldProps<C = Config> { | ||
items: FieldItems, | ||
@@ -379,3 +396,3 @@ setField(fieldPath: string): void, | ||
selectedFullLabel?: string | Empty, | ||
config?: Config, | ||
config?: C, | ||
customProps?: AnyObject, | ||
@@ -395,12 +412,12 @@ placeholder?: string, | ||
type FormatValue = (val: RuleValue, fieldDef: Field, wgtDef: Widget, isForDisplay: boolean, op: string, opDef: Operator, rightFieldDef?: Field) => string; | ||
type SqlFormatValue = (val: RuleValue, fieldDef: Field, wgtDef: Widget, op: string, opDef: Operator, rightFieldDef?: Field) => string; | ||
type SpelFormatValue = (val: RuleValue, fieldDef: Field, wgtDef: Widget, op: string, opDef: Operator, rightFieldDef?: Field) => string; | ||
type MongoFormatValue = (val: RuleValue, fieldDef: Field, wgtDef: Widget, op: string, opDef: Operator) => MongoValue; | ||
type JsonLogicFormatValue = (val: RuleValue, fieldDef: Field, wgtDef: Widget, op: string, opDef: Operator) => JsonLogicValue; | ||
type ValidateValue = (val: RuleValue, fieldSettings: FieldSettings, op: string, opDef: Operator, rightFieldDef?: Field) => boolean | string | null; | ||
type ElasticSearchFormatValue = (queryType: ElasticSearchQueryType, val: RuleValue, op: string, field: string, config: Config) => AnyObject | null; | ||
type FormatValue = (val: RuleValue, fieldDef: Field, wgtDef: Widget, isForDisplay: boolean, op: string, opDef: Operator, rightFieldDef?: Field) => string; | ||
type SqlFormatValue = (val: RuleValue, fieldDef: Field, wgtDef: Widget, op: string, opDef: Operator, rightFieldDef?: Field) => string; | ||
type SpelFormatValue = (val: RuleValue, fieldDef: Field, wgtDef: Widget, op: string, opDef: Operator, rightFieldDef?: Field) => string; | ||
type MongoFormatValue = (val: RuleValue, fieldDef: Field, wgtDef: Widget, op: string, opDef: Operator) => MongoValue; | ||
type JsonLogicFormatValue = (val: RuleValue, fieldDef: Field, wgtDef: Widget, op: string, opDef: Operator) => JsonLogicValue; | ||
type ValidateValue<V = RuleValue> = (val: V, fieldSettings: FieldSettings, op: string, opDef: Operator, rightFieldDef?: Field) => boolean | string | null; | ||
type ElasticSearchFormatValue = (queryType: ElasticSearchQueryType, val: RuleValue, op: string, field: string, config: Config) => AnyObject | null; | ||
export interface BaseWidget { | ||
export interface BaseWidget<C = Config, WP = WidgetProps<C>> { | ||
type: string; | ||
@@ -423,11 +440,10 @@ jsType?: string; | ||
//@ui | ||
factory: Factory<WidgetProps>; | ||
factory: Factory<WP>; | ||
customProps?: AnyObject; | ||
} | ||
export interface RangeableWidget extends BaseWidget { | ||
export interface RangeableWidget<C = Config, WP = WidgetProps<C>> extends BaseWidget<C, WP> { | ||
singleWidget?: string, | ||
valueLabels?: Array<string | {label: string, placeholder: string}>, | ||
} | ||
export interface FieldWidget { | ||
valueSrc: "field", | ||
interface BaseFieldWidget<C = Config, WP = WidgetProps<C>> { | ||
valuePlaceholder?: string, | ||
@@ -442,16 +458,44 @@ valueLabel?: string, | ||
customProps?: AnyObject, | ||
factory?: Factory<WP>, | ||
} | ||
export interface FieldWidget<C = Config, WP = WidgetProps<C>> extends BaseFieldWidget<C, WP> { | ||
valueSrc: "field", | ||
} | ||
export interface FuncWidget<C = Config, WP = WidgetProps<C>> extends BaseFieldWidget<C, WP> { | ||
valueSrc: "func", | ||
} | ||
export type TextWidget = BaseWidget & TextFieldSettings; | ||
export type DateTimeWidget = RangeableWidget & DateTimeFieldSettings; | ||
export type BooleanWidget = BaseWidget & BooleanFieldSettings; | ||
export type NumberWidget = RangeableWidget & NumberFieldSettings; | ||
export type SelectWidget = BaseWidget & SelectFieldSettings; | ||
export type TreeSelectWidget = BaseWidget & TreeSelectFieldSettings; | ||
export type CaseValueWidget = BaseWidget & CaseValueFieldSettings; | ||
export type TextWidget<C = Config, WP = TextWidgetProps<C>> = BaseWidget<C, WP> & TextFieldSettings; | ||
export type DateTimeWidget<C = Config, WP = DateTimeWidgetProps<C>> = RangeableWidget<C, WP> & DateTimeFieldSettings; | ||
export type BooleanWidget<C = Config, WP = BooleanWidgetProps<C>> = BaseWidget<C, WP> & BooleanFieldSettings; | ||
export type NumberWidget<C = Config, WP = NumberWidgetProps<C>> = RangeableWidget<C, WP> & NumberFieldSettings; | ||
export type RangeSliderWidget<C = Config, WP = RangeSliderWidgetProps<C>> = RangeableWidget<C, WP> & NumberFieldSettings; | ||
export type SelectWidget<C = Config, WP = SelectWidgetProps<C>> = BaseWidget<C, WP> & SelectFieldSettings; | ||
export type MultiSelectWidget<C = Config, WP = MultiSelectWidgetProps<C>> = BaseWidget<C, WP> & MultiSelectFieldSettings; | ||
export type TreeSelectWidget<C = Config, WP = TreeSelectWidgetProps<C>> = BaseWidget<C, WP> & TreeSelectFieldSettings; | ||
export type TreeMultiSelectWidget<C = Config, WP = TreeMultiSelectWidgetProps<C>> = BaseWidget<C, WP> & TreeMultiSelectFieldSettings; | ||
export type CaseValueWidget<C = Config, WP = CaseValueWidgetProps<C>> = BaseWidget<C, WP> & CaseValueFieldSettings; | ||
export type Widget = FieldWidget | TextWidget | DateTimeWidget | BooleanWidget | NumberWidget | SelectWidget | TreeSelectWidget | RangeableWidget | BaseWidget; | ||
export type Widgets = TypedMap<Widget>; | ||
// tip: use generic WidgetProps here, TS can't determine correct factory | ||
export type TypedWidget<C = Config> = | ||
TextWidget<C, WidgetProps<C>> | ||
| DateTimeWidget<C, WidgetProps<C>> | ||
| BooleanWidget<C, WidgetProps<C>> | ||
| NumberWidget<C, WidgetProps<C>> | ||
| RangeSliderWidget<C, WidgetProps<C>> | ||
| SelectWidget<C, WidgetProps<C>> | ||
| MultiSelectWidget<C, WidgetProps<C>> | ||
| TreeSelectWidget<C, WidgetProps<C>> | ||
| TreeMultiSelectWidget<C, WidgetProps<C>> | ||
| CaseValueWidget<C, WidgetProps<C>>; | ||
export type Widget<C = Config> = | ||
FieldWidget<C> | ||
| FuncWidget<C> | ||
| TypedWidget<C> | ||
| RangeableWidget<C> | ||
| BaseWidget<C>; | ||
export type Widgets<C = Config> = TypedMap<Widget<C>>; | ||
///////////////// | ||
@@ -528,12 +572,13 @@ // Conjunctions | ||
} | ||
export interface ProximityProps extends ProximityConfig { | ||
export interface ProximityProps<C = Config> extends ProximityConfig { | ||
options: ImmutableMap<string, any>, | ||
setOption: (key: string, value: any) => void, | ||
config: Config, | ||
config: C, | ||
} | ||
export interface ProximityOptions extends ProximityConfig { | ||
factory: Factory<ProximityProps>, | ||
export interface ProximityOptions<C = Config, PP = ProximityProps<C>> extends ProximityConfig { | ||
//@ui | ||
factory: Factory<PP>, | ||
} | ||
interface BaseOperator { | ||
export interface BaseOperator { | ||
label: string, | ||
@@ -556,9 +601,9 @@ reversedOp?: string, | ||
} | ||
interface UnaryOperator extends BaseOperator { | ||
export interface UnaryOperator extends BaseOperator { | ||
//cardinality: 0, | ||
} | ||
interface BinaryOperator extends BaseOperator { | ||
export interface BinaryOperator extends BaseOperator { | ||
//cardinality: 1, | ||
} | ||
interface Operator2 extends BaseOperator { | ||
export interface Operator2 extends BaseOperator { | ||
//cardinality: 2 | ||
@@ -569,7 +614,7 @@ textSeparators: Array<string>, | ||
} | ||
interface OperatorProximity extends Operator2 { | ||
options: ProximityOptions, | ||
export interface OperatorProximity<C = Config> extends Operator2 { | ||
options: ProximityOptions<C, ProximityProps<C>>, | ||
} | ||
export type Operator = UnaryOperator | BinaryOperator | Operator2 | OperatorProximity; | ||
export type Operators = TypedMap<Operator>; | ||
export type Operator<C = Config> = UnaryOperator | BinaryOperator | Operator2 | OperatorProximity<C>; | ||
export type Operators<C = Config> = TypedMap<Operator<C>>; | ||
@@ -628,10 +673,10 @@ | ||
export interface BasicFieldSettings { | ||
validateValue?: ValidateValue, | ||
export interface BasicFieldSettings<V = RuleValue> { | ||
validateValue?: ValidateValue<V>, | ||
} | ||
export interface TextFieldSettings extends BasicFieldSettings { | ||
export interface TextFieldSettings<V = string> extends BasicFieldSettings<V> { | ||
maxLength?: number, | ||
maxRows?: number, | ||
} | ||
export interface NumberFieldSettings extends BasicFieldSettings { | ||
export interface NumberFieldSettings<V = number> extends BasicFieldSettings<V> { | ||
min?: number, | ||
@@ -642,3 +687,3 @@ max?: number, | ||
} | ||
export interface DateTimeFieldSettings extends BasicFieldSettings { | ||
export interface DateTimeFieldSettings<V = string> extends BasicFieldSettings<V> { | ||
timeFormat?: string, | ||
@@ -650,3 +695,3 @@ dateFormat?: string, | ||
} | ||
export interface SelectFieldSettings extends BasicFieldSettings { | ||
export interface SelectFieldSettings<V = string | number> extends BasicFieldSettings<V> { | ||
listValues?: ListValues, | ||
@@ -661,14 +706,28 @@ allowCustomValues?: boolean, | ||
} | ||
export interface TreeSelectFieldSettings extends BasicFieldSettings { | ||
listValues?: TreeData, | ||
export interface MultiSelectFieldSettings<V = string[] | number[]> extends SelectFieldSettings<V> { | ||
} | ||
export interface TreeSelectFieldSettings<V = string | number> extends BasicFieldSettings<V> { | ||
treeValues?: TreeData, | ||
treeExpandAll?: boolean, | ||
treeSelectOnlyLeafs?: boolean, | ||
} | ||
export interface BooleanFieldSettings extends BasicFieldSettings { | ||
export interface TreeMultiSelectFieldSettings<V = string[] | number[]> extends TreeSelectFieldSettings<V> { | ||
} | ||
export interface BooleanFieldSettings<V = boolean> extends BasicFieldSettings<V> { | ||
labelYes?: ReactElement | string, | ||
labelNo?: ReactElement | string, | ||
} | ||
export interface CaseValueFieldSettings extends BasicFieldSettings { | ||
export interface CaseValueFieldSettings<V = any> extends BasicFieldSettings<V> { | ||
} | ||
export type FieldSettings = NumberFieldSettings | DateTimeFieldSettings | SelectFieldSettings | TreeSelectFieldSettings | BooleanFieldSettings | TextFieldSettings | BasicFieldSettings; | ||
// tip: use RuleValue here, TS can't determine correct types in `validateValue` | ||
export type FieldSettings = | ||
NumberFieldSettings<RuleValue> | ||
| DateTimeFieldSettings<RuleValue> | ||
| SelectFieldSettings<RuleValue> | ||
| MultiSelectFieldSettings<RuleValue> | ||
| TreeSelectFieldSettings<RuleValue> | ||
| TreeMultiSelectFieldSettings<RuleValue> | ||
| BooleanFieldSettings<RuleValue> | ||
| TextFieldSettings<RuleValue> | ||
| BasicFieldSettings<RuleValue>; | ||
@@ -900,65 +959,73 @@ interface BaseField { | ||
export interface CoreOperators<C = Config> extends Operators<C> { | ||
equal: BinaryOperator, | ||
not_equal: BinaryOperator, | ||
less: BinaryOperator, | ||
less_or_equal: BinaryOperator, | ||
greater: BinaryOperator, | ||
greater_or_equal: BinaryOperator, | ||
like: BinaryOperator, | ||
not_like: BinaryOperator, | ||
starts_with: BinaryOperator, | ||
ends_with: BinaryOperator, | ||
between: Operator2, | ||
not_between: Operator2, | ||
is_null: UnaryOperator, | ||
is_not_null: UnaryOperator, | ||
is_empty: UnaryOperator, | ||
is_not_empty: UnaryOperator, | ||
select_equals: BinaryOperator, | ||
select_not_equals: BinaryOperator, | ||
select_any_in: BinaryOperator, | ||
select_not_any_in: BinaryOperator, | ||
multiselect_contains: BinaryOperator, | ||
multiselect_not_contains: BinaryOperator, | ||
multiselect_equals: BinaryOperator, | ||
multiselect_not_equals: BinaryOperator, | ||
proximity: OperatorProximity<C>, | ||
} | ||
export interface CoreConjunctions extends Conjunctions { | ||
AND: Conjunction, | ||
OR: Conjunction, | ||
} | ||
export interface CoreWidgets<C = Config> extends Widgets<C> { | ||
text: TextWidget<C>, | ||
textarea: TextWidget<C>, | ||
number: NumberWidget<C>, | ||
slider: NumberWidget<C>, | ||
rangeslider: RangeSliderWidget<C>, | ||
select: SelectWidget<C>, | ||
multiselect: MultiSelectWidget<C>, | ||
treeselect: TreeSelectWidget<C>, | ||
treemultiselect: TreeMultiSelectWidget<C>, | ||
date: DateTimeWidget<C>, | ||
time: DateTimeWidget<C>, | ||
datetime: DateTimeWidget<C>, | ||
boolean: BooleanWidget<C>, | ||
field: FieldWidget<C>, | ||
func: FuncWidget<C>, | ||
case_value: CaseValueWidget<C>, | ||
} | ||
export interface CoreTypes extends Types { | ||
text: Type, | ||
number: Type, | ||
date: Type, | ||
time: Type, | ||
datetime: Type, | ||
select: Type, | ||
multiselect: Type, | ||
treeselect: Type, | ||
treemultiselect: Type, | ||
boolean: Type, | ||
case_value: Type, | ||
} | ||
export interface CoreConfig extends Config { | ||
conjunctions: { | ||
AND: Conjunction, | ||
OR: Conjunction, | ||
}, | ||
operators: { | ||
equal: BinaryOperator, | ||
not_equal: BinaryOperator, | ||
less: BinaryOperator, | ||
less_or_equal: BinaryOperator, | ||
greater: BinaryOperator, | ||
greater_or_equal: BinaryOperator, | ||
like: BinaryOperator, | ||
not_like: BinaryOperator, | ||
starts_with: BinaryOperator, | ||
ends_with: BinaryOperator, | ||
between: Operator2, | ||
not_between: Operator2, | ||
is_null: UnaryOperator, | ||
is_not_null: UnaryOperator, | ||
is_empty: UnaryOperator, | ||
is_not_empty: UnaryOperator, | ||
select_equals: BinaryOperator, | ||
select_not_equals: BinaryOperator, | ||
select_any_in: BinaryOperator, | ||
select_not_any_in: BinaryOperator, | ||
multiselect_contains: BinaryOperator, | ||
multiselect_not_contains: BinaryOperator, | ||
multiselect_equals: BinaryOperator, | ||
multiselect_not_equals: BinaryOperator, | ||
proximity: OperatorProximity, | ||
}, | ||
widgets: { | ||
text: TextWidget, | ||
textarea: TextWidget, | ||
number: NumberWidget, | ||
slider: NumberWidget, | ||
rangeslider: NumberWidget, | ||
select: SelectWidget, | ||
multiselect: SelectWidget, | ||
treeselect: TreeSelectWidget, | ||
treemultiselect: TreeSelectWidget, | ||
date: DateTimeWidget, | ||
time: DateTimeWidget, | ||
datetime: DateTimeWidget, | ||
boolean: BooleanWidget, | ||
field: FieldWidget, | ||
func: FieldWidget, | ||
case_value: CaseValueWidget, | ||
}, | ||
types: { | ||
text: Type, | ||
number: Type, | ||
date: Type, | ||
time: Type, | ||
datetime: Type, | ||
select: Type, | ||
multiselect: Type, | ||
treeselect: Type, | ||
treemultiselect: Type, | ||
boolean: Type, | ||
case_value: Type, | ||
}, | ||
conjunctions: CoreConjunctions, | ||
operators: CoreOperators, | ||
widgets: CoreWidgets, | ||
types: CoreTypes, | ||
settings: Settings, | ||
@@ -965,0 +1032,0 @@ } |
@@ -132,3 +132,3 @@ import merge from "lodash/merge"; | ||
if (fieldConfig.type != "!struct" && fieldConfig.type != "!group") { | ||
const keysToPutInFieldSettings = ["listValues", "allowCustomValues", "validateValue"]; | ||
const keysToPutInFieldSettings = ["listValues", "treeValues", "allowCustomValues", "validateValue"]; | ||
if (!fieldConfig.fieldSettings) | ||
@@ -143,2 +143,3 @@ fieldConfig.fieldSettings = {}; | ||
// normalize listValues | ||
if (fieldConfig.fieldSettings.listValues) { | ||
@@ -151,2 +152,10 @@ if (config.settings.normalizeListValues) { | ||
} | ||
// same for treeValues | ||
if (fieldConfig.fieldSettings.treeValues) { | ||
if (config.settings.normalizeListValues) { | ||
fieldConfig.fieldSettings.treeValues = config.settings.normalizeListValues( | ||
fieldConfig.fieldSettings.treeValues, fieldConfig.type, fieldConfig.fieldSettings | ||
); | ||
} | ||
} | ||
@@ -153,0 +162,0 @@ if (!typeConfig) { |
@@ -308,6 +308,7 @@ import { | ||
const fieldSettings = fieldConfig.fieldSettings; | ||
const listValues = fieldSettings.treeValues || fieldSettings.listValues; | ||
if (valueType && valueType != wType) | ||
return [`Value should have type ${wType}, but got value of type ${valueType}`, value]; | ||
if (jsType && !isTypeOf(value, jsType) && !fieldSettings.listValues) { //tip: can skip tye check for listValues | ||
if (jsType && !isTypeOf(value, jsType) && !listValues) { //tip: can skip type check for listValues | ||
return [`Value should have JS type ${jsType}, but got value of type ${typeof value}`, value]; | ||
@@ -317,5 +318,5 @@ } | ||
if (fieldSettings) { | ||
const listValues = asyncListValues || fieldSettings.listValues; | ||
if (listValues && !fieldSettings.allowCustomValues) { | ||
return validateValueInList(value, listValues, canFix, isEndValue, config.settings.removeInvalidMultiSelectValuesOnLoad); | ||
const realListValues = asyncListValues || listValues; | ||
if (realListValues && !fieldSettings.allowCustomValues) { | ||
return validateValueInList(value, realListValues, canFix, isEndValue, config.settings.removeInvalidMultiSelectValuesOnLoad); | ||
} | ||
@@ -322,0 +323,0 @@ if (fieldSettings.min != null && value < fieldSettings.min) { |
{ | ||
"name": "@react-awesome-query-builder/core", | ||
"version": "6.1.3", | ||
"version": "6.2.0", | ||
"description": "User-friendly query builder for React. Core", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
1183607
29371