UNPKG

@adaptabletools/adaptable

Version:

Powerful AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements

78 lines (77 loc) 5.62 kB
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { isRuleBasedAlertDefinition } from '../../../Utilities/Helpers/Scheduling/ScheduledAlertHelper'; import { EntityRulesEditor, EntityRulesSummary } from '../../Components/EntityRulesEditor'; import { Tag } from '../../../components/Tag'; import { useOnePageAdaptableWizardContext } from '../../Wizard/OnePageAdaptableWizard'; import { getAvailablePredicateDefinitions } from '../Utilities/getAvailablePredicates'; import Radio from '../../../components/Radio'; import { Card } from '../../../components/Card'; import { Flex } from '../../../components/Flex'; import { OBSERVABLE_EXPRESSION_ROW_ADDED, OBSERVABLE_EXPRESSION_ROW_REMOVED, } from './../../../Utilities/Constants/GeneralConstants'; import { Box } from '../../../components/Flex'; export const getRuleStepDescription = (alertType) => { switch (alertType) { case 'DataChange': return (_jsx(_Fragment, { children: "Build the Rule for when the Alert should trigger (using a Predicate or a Query)" })); case 'RowChange': return _jsx(_Fragment, { children: "Specify which type of Row Change will trigger the Alert" }); case 'Validation': return (_jsx(_Fragment, { children: "Create the Validation Rule which will trigger the Alert (using a Predicate or a Query)" })); case 'Aggregation': return _jsx(_Fragment, { children: "Build an Aggregation Boolean Rule to specify when the Alert should trigger" }); case 'Observable': return _jsx(_Fragment, { children: "Build an Observable Rule to specify when the Alert should trigger" }); case 'Scheduled': return _jsx(_Fragment, { children: "Scheduled alerts fire at the configured date and time" }); } return ''; }; export const renderAlertRulesSummary = (alertDefinition) => { return (_jsx(EntityRulesSummary, { data: alertDefinition, renderPredicate: (contents) => { return (_jsxs(_Fragment, { children: ["Alert Rule ", _jsx(Tag, { children: contents })] })); }, renderQueryExpression: (contents) => { return (_jsxs(_Fragment, { children: ["Alert when ", _jsx(Tag, { children: contents })] })); } })); }; const RowChangeEditor = (props) => { const expression = props.alert.Rule.ObservableExpression; const handleRowAddedChange = () => { props.onChange({ ...props.alert, Rule: { ObservableExpression: 'ROW_ADDED()', }, }); }; const handleRowRemovedChange = () => { props.onChange({ ...props.alert, Rule: { ObservableExpression: 'ROW_REMOVED()', }, }); }; return (_jsx(Flex, { flexDirection: "column", className: "twa:gap-3 twa:p-3", children: _jsxs(Card, { shadow: false, children: [_jsxs(Card.Title, { children: [_jsx(Box, { className: "twa:font-medium", children: "Row Change" }), _jsx(Box, { className: "twa:text-xs twa:opacity-70 twa:font-normal twa:max-w-[520px]", children: "Choose which type of Row Change will trigger the Alert" })] }), _jsxs(Card.Body, { children: [_jsx(Radio, { onClick: () => handleRowAddedChange(), checked: expression?.includes(OBSERVABLE_EXPRESSION_ROW_ADDED), children: "Row Added" }), _jsx(Radio, { onClick: () => handleRowRemovedChange(), checked: expression?.includes(OBSERVABLE_EXPRESSION_ROW_REMOVED), children: "Row Removed" })] })] }) })); }; export const AlertRulesWizardSection = (props) => { const { data: alertData, api, moduleInfo } = useOnePageAdaptableWizardContext(); if (!isRuleBasedAlertDefinition(alertData)) { return null; } const data = alertData; const predicateDefs = getAvailablePredicateDefinitions(api, data.Scope, props.alertType); const showObservable = props.alertType === 'Observable'; const showAggregation = props.alertType === 'Aggregation'; const showBoolean = props.alertType === 'DataChange' || props.alertType == 'Validation'; const showPredicate = props.alertType === 'DataChange' || props.alertType == 'Validation'; const enablePredicateColumnId = props.alertType === 'DataChange' || props.alertType == 'Validation'; if (props.alertType === 'RowChange') { return _jsx(RowChangeEditor, { alert: data, onChange: props.onChange }); } return (_jsx(EntityRulesEditor, { module: moduleInfo.ModuleName, defaultPredicateId: "AnyChange", data: data, predicateDefs: predicateDefs, enablePredicateColumnId: enablePredicateColumnId, getPredicateDefsForColId: (colId) => getAvailablePredicateDefinitions(api, { ColumnIds: [colId] }, props.alertType), onChange: props.onChange, showAggregation: showAggregation, showObservable: showObservable, showBoolean: showBoolean, showPredicate: showPredicate, descriptions: { selectPredicate: 'Build the Predicate', 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"] })), } })); };