mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
mutli column condition for JSL data
This commit is contained in:
parent
b26be02203
commit
7c03d31b84
@ -738,7 +738,7 @@ export abstract class GridDisplay {
|
|||||||
// return sql;
|
// return sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
compileFilters(): Condition {
|
compileJslFilters(): Condition {
|
||||||
const filters = this.config && this.config.filters;
|
const filters = this.config && this.config.filters;
|
||||||
if (!filters) return null;
|
if (!filters) return null;
|
||||||
const conditions = [];
|
const conditions = [];
|
||||||
@ -761,6 +761,17 @@ export abstract class GridDisplay {
|
|||||||
// filter parse error - ignore filter
|
// 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;
|
if (conditions.length == 0) return null;
|
||||||
return {
|
return {
|
||||||
conditionType: 'and',
|
conditionType: 'and',
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import _ from 'lodash';
|
import _cloneDeepWith from 'lodash/cloneDeepWith';
|
||||||
import { Condition, BinaryCondition } from './types';
|
import _escapeRegExp from 'lodash/escapeRegExp';
|
||||||
|
import { Condition, Expression } from './types';
|
||||||
import { evaluateExpression } from './evaluateExpression';
|
import { evaluateExpression } from './evaluateExpression';
|
||||||
|
|
||||||
function isEmpty(value) {
|
function isEmpty(value) {
|
||||||
@ -10,7 +11,7 @@ function isEmpty(value) {
|
|||||||
function isLike(value, test) {
|
function isLike(value, test) {
|
||||||
if (!value) return false;
|
if (!value) return false;
|
||||||
if (!test) 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);
|
const res = !!value.toString().match(regex);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@ -55,5 +56,16 @@ export function evaluateCondition(condition: Condition, values) {
|
|||||||
return !isLike(evaluateExpression(condition.left, values), evaluateExpression(condition.right, values));
|
return !isLike(evaluateExpression(condition.left, values), evaluateExpression(condition.right, values));
|
||||||
case 'not':
|
case 'not':
|
||||||
return !evaluateCondition(condition.condition, values);
|
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);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,6 +111,11 @@ export interface RawTemplateCondition {
|
|||||||
expr: Expression;
|
expr: Expression;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface AnyColumnPassEvalOnlyCondition {
|
||||||
|
conditionType: 'anyColumnPass';
|
||||||
|
placeholderCondition: Condition;
|
||||||
|
}
|
||||||
|
|
||||||
export type Condition =
|
export type Condition =
|
||||||
| BinaryCondition
|
| BinaryCondition
|
||||||
| NotCondition
|
| NotCondition
|
||||||
@ -121,7 +126,8 @@ export type Condition =
|
|||||||
| NotExistsCondition
|
| NotExistsCondition
|
||||||
| BetweenCondition
|
| BetweenCondition
|
||||||
| InCondition
|
| InCondition
|
||||||
| RawTemplateCondition;
|
| RawTemplateCondition
|
||||||
|
| AnyColumnPassEvalOnlyCondition;
|
||||||
|
|
||||||
export interface Source {
|
export interface Source {
|
||||||
name?: NamedObjectInfo;
|
name?: NamedObjectInfo;
|
||||||
|
@ -88,6 +88,7 @@
|
|||||||
expandMacros={!!dispatchChangeSet}
|
expandMacros={!!dispatchChangeSet}
|
||||||
onRunMacro={handleRunMacro}
|
onRunMacro={handleRunMacro}
|
||||||
macroCondition={infoUsed?.__isDynamicStructure ? null : macro => macro.type == 'transformValue'}
|
macroCondition={infoUsed?.__isDynamicStructure ? null : macro => macro.type == 'transformValue'}
|
||||||
|
hasMultiColumnFilter
|
||||||
{changeSetState}
|
{changeSetState}
|
||||||
{changeSetStore}
|
{changeSetStore}
|
||||||
{dispatchChangeSet}
|
{dispatchChangeSet}
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
offset,
|
offset,
|
||||||
limit,
|
limit,
|
||||||
formatterFunction,
|
formatterFunction,
|
||||||
filters: display ? display.compileFilters() : null,
|
filters: display ? display.compileJslFilters() : null,
|
||||||
sort: display.config.sort,
|
sort: display.config.sort,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
offset: index,
|
offset: index,
|
||||||
limit: 1,
|
limit: 1,
|
||||||
formatterFunction,
|
formatterFunction,
|
||||||
filters: display ? display.compileFilters() : null,
|
filters: display ? display.compileJslFilters() : null,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.errorMessage) return response;
|
if (response.errorMessage) return response;
|
||||||
|
Loading…
Reference in New Issue
Block a user