@adaptabletools/adaptable
Version:
Powerful AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements
43 lines (42 loc) • 3.24 kB
JavaScript
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { useOnePageAdaptableWizardContext } from '../../Wizard/OnePageAdaptableWizard';
import { EntityRulesEditor } from '../../Components/EntityRulesEditor';
import HelpBlock from '../../../components/HelpBlock';
import { Box } from '../../../components/Flex';
import { Tag } from '../../../components/Tag';
export const hasFormatColumnCondition = (formatColumn) => {
const rule = formatColumn.Rule;
if (!rule) {
return false;
}
return Boolean(rule.Predicates?.length ||
rule.BooleanExpression ||
('ObservableExpression' in rule && rule.ObservableExpression) ||
('AggregatedBooleanExpression' in rule && rule.AggregatedBooleanExpression));
};
export const renderFormatColumnConditionSummary = (formatColumn, api) => {
if (formatColumn.Target === 'columnHeader') {
return _jsx(Tag, { children: "No Condition" });
}
if (!hasFormatColumnCondition(formatColumn)) {
return _jsx(Tag, { children: "No Condition" });
}
const rule = formatColumn.Rule;
if (rule?.Predicates?.length) {
return (_jsx(Box, { className: "twa:flex twa:flex-col twa:gap-2", children: rule.Predicates.map((predicate, index) => (_jsx(Tag, { children: api.predicateApi.predicateToString(predicate) }, index))) }));
}
const expressionText = api.internalApi.getAdaptableQueryExpressionText(rule);
return _jsx(Tag, { children: expressionText || 'No Condition' });
};
export function FormatColumnRuleWizardSection(props) {
const { data, api, moduleInfo } = useOnePageAdaptableWizardContext();
if (data.Target && data.Target === 'columnHeader') {
return (_jsx(HelpBlock, { className: "twa:mt-3", children: "Conditions cannot be applied if the Target of the Format Column is Column Header" }));
}
return (_jsx(EntityRulesEditor, { module: moduleInfo.ModuleName, defaultPredicateId: props.defaultPredicateId, predicateDefs: api.formatColumnApi.internalApi.getFormatColumnDefsForScope(data.Scope), getPredicateDefsForColId: (colId) => api.formatColumnApi.internalApi.getFormatColumnDefsForScope({ ColumnIds: [colId] }), showNoRule: true, showBoolean: true, showAggregation: false, showObservable: false, showQueryBuilder: true, showPredicate: !api.columnScopeApi.scopeIsAll(data.Scope), data: data, onChange: (formatColumn) => props.onChange(formatColumn), descriptions: {
selectPredicate: 'Create a Format Column Rule - to be applied when data changes',
useBooleanQuery: (_jsxs(_Fragment, { children: ["Use an BooleanQuery if ", _jsx("i", { children: "Scope" }), " is 'All Columns' - so any data change may be evaluated in a complex BooleanExpression"] })),
useObservableQuery: (_jsxs(_Fragment, { children: ["Use an ObservableQuery if ", _jsx("i", { children: "Scope" }), " is 'All Columns' - so any data change may be evaluated in a complex ObservableExpression"] })),
useAggregationQuery: (_jsxs(_Fragment, { children: ["Use an AggregatedBooleanQuery if ", _jsx("i", { children: "Scope" }), " is 'All Columns' - so any data change may be evaluated in a complex AggregatedBooleanExpression"] })),
} }));
}