@adaptabletools/adaptable-cjs
Version:
Powerful data-agnostic HTML5 AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements
34 lines (33 loc) • 1.66 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isAdaptableRuleValid = void 0;
const isAdaptableRuleValid = (abObject, api, context) => {
if (abObject?.Rule?.Predicates?.length) {
if (!api.predicateApi.isEveryPredicateValid(abObject?.Rule?.Predicates)) {
return `The Predicate${abObject?.Rule?.Predicates?.length === 1 ? ' is' : 's are'} not valid`;
}
}
if (abObject?.Rule?.BooleanExpression) {
if (!api.expressionApi.isValidBooleanExpression(abObject?.Rule?.BooleanExpression, context.moduleInfo.ModuleName)) {
return 'The Expression is not a valid Boolean Expression';
}
}
if (abObject?.Rule?.ObservableExpression) {
if (!api.expressionApi.isValidObservableExpression(abObject?.Rule?.ObservableExpression, context.moduleInfo.ModuleName)) {
return 'The Expression is not a valid Observable Expression';
}
}
if (abObject?.Rule?.AggregatedBooleanExpression) {
if (!api.expressionApi.isValidAggregatedBooleanExpression(abObject?.Rule?.AggregatedBooleanExpression, context.moduleInfo.ModuleName)) {
return 'The Expression is not a valid Aggregated Boolean Expression';
}
}
if (abObject?.Rule?.Predicates?.length) {
const isAPredicateWithInvalidColumnId = abObject?.Rule?.Predicates?.some((predicate) => predicate.ColumnId !== undefined && predicate.ColumnId === '');
if (isAPredicateWithInvalidColumnId) {
return 'Predicates with custom scope need a valid column';
}
}
return true;
};
exports.isAdaptableRuleValid = isAdaptableRuleValid;