UNPKG

@adaptabletools/adaptable-cjs

Version:

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

90 lines (89 loc) 5.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EntityRulePredicatesEditor = void 0; const tslib_1 = require("tslib"); const React = tslib_1.__importStar(require("react")); const HelpBlock_1 = tslib_1.__importDefault(require("../../../../components/HelpBlock")); const AdaptableContext_1 = require("../../../AdaptableContext"); const ButtonInfo_1 = require("../../Buttons/ButtonInfo"); const DocumentationLinkConstants_1 = require("../../../../Utilities/Constants/DocumentationLinkConstants"); const SimpleButton_1 = tslib_1.__importDefault(require("../../../../components/SimpleButton")); const Tag_1 = require("../../../../components/Tag"); const EntityRulePredicateEditor_1 = require("./EntityRulePredicateEditor"); const Radio_1 = tslib_1.__importDefault(require("../../../../components/Radio")); const getScopeViewItems_1 = require("../../../../Utilities/getScopeViewItems"); const Flex_1 = require("../../../../components/Flex"); const EntityRulePredicatesEditor = (props) => { const { api } = (0, AdaptableContext_1.useAdaptable)(); const showDocumentationLinks = api.internalApi.isDocumentationLinksDisplayed(); const columnPredicateEnabled = props.data.Rule.Predicates.some((predicate) => predicate.ColumnId !== undefined); // filter out predicates that are already in use const defaultPredicateDefs = props.predicateDefs.filter((predicateDef) => { return props.data.Rule?.Predicates?.every((rulePrediate) => rulePrediate.PredicateId !== predicateDef.id); }); const handlePredicateScopeTypeChange = (columnPredicateEnabled) => { if (columnPredicateEnabled) { props.onChange({ ...props.data, Rule: { Predicates: [ { PredicateId: null, ColumnId: '', }, ], }, }); } else { props.onChange({ ...props.data, Rule: { Predicates: [], }, }); } }; const handleAddNewPredicate = () => { props.onChange({ ...props.data, Rule: { Predicates: [ ...(props.data.Rule?.Predicates || []), { PredicateId: defaultPredicateDefs[0].id, Inputs: [], }, ], }, }); }; const scopeString = (0, getScopeViewItems_1.getScopeViewItems)(props.data.Scope, api).values.join(', '); const enablePredicateColumnId = props.enablePredicateColumnId ?? true; return (React.createElement(React.Fragment, null, React.createElement(Flex_1.Flex, { justifyContent: "space-between", className: "twa:mb-2" }, React.createElement(Flex_1.Box, { className: "twa:text-2 twa:mb-2" }, props.descriptions.selectPredicate), React.createElement(SimpleButton_1.default, { disabled: !props.data.Rule?.Predicates?.length, onClick: handleAddNewPredicate, icon: "plus", variant: "raised" }, "Add Predicate")), enablePredicateColumnId && (React.createElement(Flex_1.Flex, { className: "ab-EntityRulePredicateEditor-ScopeTypeSelector twa:p-2 twa:mb-2", flexDirection: "column" }, React.createElement(Flex_1.Box, { className: "twa:mb-2" }, "Create Predicate Rule(s) using"), React.createElement(Radio_1.default, { "data-name": "entity-scope", onClick: () => handlePredicateScopeTypeChange(false), className: "twa:mr-3", checked: !columnPredicateEnabled }, "Active Column: ", React.createElement(Tag_1.Tag, { className: "twa:mx-1" }, scopeString || 'Not Defined'), ' '), React.createElement(Radio_1.default, { "data-name": "column-scope", onClick: () => handlePredicateScopeTypeChange(true), checked: columnPredicateEnabled }, "Selected Columns (overriding Active Column)"))), (props.data.Rule?.Predicates?.length ? props.data.Rule.Predicates : [null]).map((predicate, index) => { const currentPredicatDef = props.predicateDefs.find((pd) => pd.id === predicate?.PredicateId); let editorPredicateDefs = defaultPredicateDefs; if (currentPredicatDef) { editorPredicateDefs = [currentPredicatDef, ...defaultPredicateDefs]; } return (React.createElement(React.Fragment, { key: `${index}-${predicate?.PredicateId}` }, index > 0 && (React.createElement(Flex_1.Box, null, React.createElement(Tag_1.Tag, { className: "twa:mb-3" }, "AND"))), React.createElement(EntityRulePredicateEditor_1.EntityRulePredicateEditor, { data: props.data, predicate: predicate, onChange: props.onChange, predicateDefs: editorPredicateDefs, getPredicateDefsForColId: props.getPredicateDefsForColId, columnPredicateEnabled: columnPredicateEnabled }))); }), showDocumentationLinks && (React.createElement(HelpBlock_1.default, { "data-name": "query-documentation", className: "twa:mt-3 twa:mb-2 twa:p-0 twa:text-3" }, React.createElement(ButtonInfo_1.ButtonInfo, { className: "twa:mr-2", onClick: () => window.open(DocumentationLinkConstants_1.PredicateDocsLink, '_blank') }), "See Predicate documentation for more details and examples")))); }; exports.EntityRulePredicatesEditor = EntityRulePredicatesEditor;