@adaptabletools/adaptable
Version:
Powerful AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements
62 lines (61 loc) • 4.68 kB
JavaScript
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { SummaryText, useOnePageAdaptableWizardContext, } from '../../Wizard/OnePageAdaptableWizard';
import { EntityRulesEditor, EntityRulesSummary } from '../../Components/EntityRulesEditor';
import { CodeBlock } from '../../../components/CodeBlock';
import { isAdaptableRuleValid } from '../../Components/EntityRulesEditor/Utilities';
import { Box, Flex } from '../../../components/Flex';
import { Card } from '../../../components/Card';
import { TypeRadio } from '../../Wizard/TypeRadio';
import { Tag } from '../../../components/Tag';
export function PlusMinusRuleSummary() {
const { data } = useOnePageAdaptableWizardContext();
return (_jsx(EntityRulesSummary, { data: data, renderPredicate: (contents) => {
return (_jsxs(_Fragment, { children: ["Apply Plus Minus on ", _jsx(CodeBlock, { children: contents })] }));
}, renderQueryExpression: (contents) => {
return (_jsxs(_Fragment, { children: ["Apply Plus Minus when", ' ', _jsx("b", { children: _jsx(CodeBlock, { children: contents }) })] }));
} }));
}
export const PlusMinusRuleStepSummary = () => {
const { data } = useOnePageAdaptableWizardContext();
const hasCondition = Boolean(data.Rule);
return (_jsxs(_Fragment, { children: [_jsxs(SummaryText, { children: ["Nudge Type ", _jsx(Tag, { children: hasCondition ? 'Conditional' : 'Always Apply' })] }), hasCondition ? _jsx(PlusMinusRuleSummary, {}) : null] }));
};
export const isRuleValid = (data, api, context) => {
if (!data.Rule) {
return true;
}
if (!data.Rule.BooleanExpression) {
return 'A valid rule is required.';
}
const ruleValidation = isAdaptableRuleValid(data, api, context);
if (typeof ruleValidation === 'string') {
return ruleValidation;
}
return true;
};
export function PlusMinusRuleWizardSection(props) {
const { data, moduleInfo } = useOnePageAdaptableWizardContext();
const hasCondition = Boolean(data.Rule);
const handleNudgeTypeChange = (conditional) => {
if (conditional) {
props.onChange({
...data,
Rule: data.Rule ?? { BooleanExpression: '' },
});
return;
}
const preparedData = { ...data };
delete preparedData.Rule;
props.onChange(preparedData);
};
const plusMinusNudge = {
...data,
Rule: data?.Rule ?? { BooleanExpression: '' },
};
return (_jsxs(Flex, { flexDirection: "column", className: "twa:h-full twa:gap-3 twa:p-3", children: [_jsxs(Card, { shadow: false, children: [_jsxs(Card.Title, { children: [_jsx(Box, { className: "twa:font-medium", children: "Nudge Type" }), _jsx(Box, { className: "twa:text-xs twa:opacity-70 twa:font-normal twa:max-w-[520px]", children: "Choose whether the nudge is always applied or only when a condition is met" })] }), _jsx(Card.Body, { children: _jsxs(Flex, { flexDirection: "column", children: [_jsx(TypeRadio, { "data-name": "nudge-type-always", text: "Always Apply", description: "The nudge value is always applied when using Plus/Minus", checked: !hasCondition, onClick: () => handleNudgeTypeChange(false) }), _jsx(TypeRadio, { "data-name": "nudge-type-condition", text: "Conditional", description: "Apply the nudge only when the row matches a rule", checked: hasCondition, onClick: () => handleNudgeTypeChange(true) })] }) })] }), hasCondition ? (_jsxs(Card, { shadow: false, className: "twa:flex-1 twa:min-h-0", children: [_jsxs(Card.Title, { children: [_jsx(Box, { className: "twa:font-medium", children: "Condition" }), _jsx(Box, { className: "twa:text-xs twa:opacity-70 twa:font-normal twa:max-w-[520px]", children: "Build a rule that determines when the nudge should be applied" })] }), _jsx(Card.Body, { className: "twa:flex-1 twa:min-h-0", children: _jsx(EntityRulesEditor, { module: moduleInfo.ModuleName, flexProps: { style: { minHeight: 0 } }, defaultPredicateId: props.defaultPredicateId, predicateDefs: [], showAggregation: false, showObservable: false, showPredicate: false, data: plusMinusNudge, onChange: (plusMinus) => props.onChange(plusMinus), descriptions: {
selectPredicate: null,
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: null,
useAggregationQuery: null,
} }) })] })) : null] }));
}