mutli column condition for JSL data

This commit is contained in:
Jan Prochazka 2023-02-26 15:44:29 +01:00
parent b26be02203
commit 7c03d31b84
6 changed files with 37 additions and 7 deletions

View File

@ -738,7 +738,7 @@ export abstract class GridDisplay {
// return sql;
}
compileFilters(): Condition {
compileJslFilters(): Condition {
const filters = this.config && this.config.filters;
if (!filters) return null;
const conditions = [];
@ -761,6 +761,17 @@ export abstract class GridDisplay {
// filter parse error - ignore filter
}
}
if (this.config.multiColumnFilter) {
const placeholderCondition = parseFilter(this.config.multiColumnFilter, 'string');
if (placeholderCondition) {
conditions.push({
conditionType: 'anyColumnPass',
placeholderCondition,
});
}
}
if (conditions.length == 0) return null;
return {
conditionType: 'and',

View File

@ -1,5 +1,6 @@
import _ from 'lodash';
import { Condition, BinaryCondition } from './types';
import _cloneDeepWith from 'lodash/cloneDeepWith';
import _escapeRegExp from 'lodash/escapeRegExp';
import { Condition, Expression } from './types';
import { evaluateExpression } from './evaluateExpression';
function isEmpty(value) {
@ -10,7 +11,7 @@ function isEmpty(value) {
function isLike(value, test) {
if (!value) return false;
if (!test) return false;
const regex = new RegExp(`^${_.escapeRegExp(test).replace(/%/g, '.*')}$`, 'i');
const regex = new RegExp(`^${_escapeRegExp(test).replace(/%/g, '.*')}$`, 'i');
const res = !!value.toString().match(regex);
return res;
}
@ -55,5 +56,16 @@ export function evaluateCondition(condition: Condition, values) {
return !isLike(evaluateExpression(condition.left, values), evaluateExpression(condition.right, values));
case 'not':
return !evaluateCondition(condition.condition, values);
case 'anyColumnPass':
return Object.keys(values).some(columnName => {
const replaced = _cloneDeepWith(condition.placeholderCondition, (expr: Expression) => {
if (expr.exprType == 'placeholder')
return {
exprType: 'column',
columnName,
};
});
return evaluateCondition(replaced, values);
});
}
}

View File

@ -111,6 +111,11 @@ export interface RawTemplateCondition {
expr: Expression;
}
export interface AnyColumnPassEvalOnlyCondition {
conditionType: 'anyColumnPass';
placeholderCondition: Condition;
}
export type Condition =
| BinaryCondition
| NotCondition
@ -121,7 +126,8 @@ export type Condition =
| NotExistsCondition
| BetweenCondition
| InCondition
| RawTemplateCondition;
| RawTemplateCondition
| AnyColumnPassEvalOnlyCondition;
export interface Source {
name?: NamedObjectInfo;

View File

@ -88,6 +88,7 @@
expandMacros={!!dispatchChangeSet}
onRunMacro={handleRunMacro}
macroCondition={infoUsed?.__isDynamicStructure ? null : macro => macro.type == 'transformValue'}
hasMultiColumnFilter
{changeSetState}
{changeSetStore}
{dispatchChangeSet}

View File

@ -19,7 +19,7 @@
offset,
limit,
formatterFunction,
filters: display ? display.compileFilters() : null,
filters: display ? display.compileJslFilters() : null,
sort: display.config.sort,
});

View File

@ -7,7 +7,7 @@
offset: index,
limit: 1,
formatterFunction,
filters: display ? display.compileFilters() : null,
filters: display ? display.compileJslFilters() : null,
});
if (response.errorMessage) return response;