UNPKG

@adaptabletools/adaptable-cjs

Version:

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

98 lines (97 loc) 6.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AlertRulesWizardSection = exports.renderAlertRulesSummary = exports.getRuleStepDescription = void 0; const tslib_1 = require("tslib"); const React = tslib_1.__importStar(require("react")); const EntityRulesEditor_1 = require("../../Components/EntityRulesEditor"); const Tag_1 = require("../../../components/Tag"); const OnePageAdaptableWizard_1 = require("../../Wizard/OnePageAdaptableWizard"); const getAvailablePredicates_1 = require("../Utilities/getAvailablePredicates"); const Tabs_1 = require("../../../components/Tabs"); const Radio_1 = tslib_1.__importDefault(require("../../../components/Radio")); const rebass_1 = require("rebass"); const GeneralConstants_1 = require("./../../../Utilities/Constants/GeneralConstants"); const getRuleStepDescription = (alertType) => { switch (alertType) { case 'DataChange': return (React.createElement(React.Fragment, null, "Build the Rule ", React.createElement("b", null, "when"), " the Alert should trigger (using a Predicate or a Query)")); case 'RowChange': return React.createElement(React.Fragment, null, "Specify which type of Row Change will trigger the Alert"); case 'Validation': return (React.createElement(React.Fragment, null, "Create the Validation Rule which will trigger the Alert (using a Predicate or a Query)")); case 'Aggregation': return React.createElement(React.Fragment, null, "Build an Aggregation Boolean Rule to specify when the Alert should trigger"); case 'Observable': return React.createElement(React.Fragment, null, "Build an Observable Rule to specify when the Alert should trigger"); } return ''; }; exports.getRuleStepDescription = getRuleStepDescription; const renderAlertRulesSummary = (alertDefinition) => { return (React.createElement(EntityRulesEditor_1.EntityRulesSummary, { data: alertDefinition, renderPredicate: (contents) => { return (React.createElement(React.Fragment, null, "Alert Rule ", React.createElement(Tag_1.Tag, null, contents))); }, renderQueryExpression: (contents) => { return (React.createElement(React.Fragment, null, "Alert when ", React.createElement(Tag_1.Tag, null, contents))); } })); }; exports.renderAlertRulesSummary = renderAlertRulesSummary; 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 (React.createElement(rebass_1.Box, { p: 2 }, React.createElement(Tabs_1.Tabs, null, React.createElement(Tabs_1.Tabs.Tab, null, "Row Change"), React.createElement(Tabs_1.Tabs.Content, null, React.createElement(Radio_1.default, { onClick: () => handleRowAddedChange(), checked: expression?.includes(GeneralConstants_1.OBSERVABLE_EXPRESSION_ROW_ADDED) }, "Row Added"), React.createElement(Radio_1.default, { onClick: () => handleRowRemovedChange(), checked: expression?.includes(GeneralConstants_1.OBSERVABLE_EXPRESSION_ROW_REMOVED) }, "Row Removed"))))); }; const AlertRulesWizardSection = (props) => { const { data, api, moduleInfo } = (0, OnePageAdaptableWizard_1.useOnePageAdaptableWizardContext)(); const predicateDefs = (0, getAvailablePredicates_1.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 React.createElement(RowChangeEditor, { alert: data, onChange: props.onChange }); } return (React.createElement(EntityRulesEditor_1.EntityRulesEditor, { module: moduleInfo.ModuleName, defaultPredicateId: "AnyChange", data: data, predicateDefs: predicateDefs, enablePredicateColumnId: enablePredicateColumnId, getPredicateDefsForColId: (colId) => (0, getAvailablePredicates_1.getAvailablePredicateDefinitions)(api, { ColumnIds: [colId] }, props.alertType), onChange: props.onChange, showAggregation: showAggregation, showObservable: showObservable, showBoolean: showBoolean, showPredicate: showPredicate, descriptions: { selectPredicate: 'Build the Predicate', useBooleanQuery: (React.createElement(React.Fragment, null, "Use an BooleanQuery if ", React.createElement("i", null, "Scope"), " is 'All Columns' - so any data change may be evaluated in a complex BooleanExpression")), useObservableQuery: (React.createElement(React.Fragment, null, "Use an ObservableQuery if ", React.createElement("i", null, "Scope"), " is 'All Columns' - so any data change may be evaluated in a complex ObservableExpression")), useAggregationQuery: (React.createElement(React.Fragment, null, "Use an AggregatedBooleanQuery if ", React.createElement("i", null, "Scope"), " is 'All Columns' - so any data change may be evaluated in a complex AggregatedBooleanExpression")), } })); }; exports.AlertRulesWizardSection = AlertRulesWizardSection;