UNPKG

@adaptabletools/adaptable-cjs

Version:

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

111 lines (110 loc) 6.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SmartEditPopup = void 0; const tslib_1 = require("tslib"); const React = tslib_1.__importStar(require("react")); const react_redux_1 = require("react-redux"); const SmartEditRedux = tslib_1.__importStar(require("../../Redux/ActionsReducers/SmartEditRedux")); const InternalRedux = tslib_1.__importStar(require("../../Redux/ActionsReducers/InternalRedux")); const Enums_1 = require("../../AdaptableState/Common/Enums"); const PanelWithImage_1 = require("../Components/Panels/PanelWithImage"); const AdaptablePopover_1 = require("../AdaptablePopover"); const EnumExtensions_1 = require("../../Utilities/Extensions/EnumExtensions"); const PreviewResultsPanel_1 = require("../Components/PreviewResultsPanel"); const PreviewHelper_1 = require("../../Utilities/Helpers/PreviewHelper"); const StringExtensions_1 = require("../../Utilities/Extensions/StringExtensions"); const Input_1 = tslib_1.__importDefault(require("../../components/Input")); const DropdownButton_1 = tslib_1.__importDefault(require("../../components/DropdownButton")); const SimpleButton_1 = tslib_1.__importDefault(require("../../components/SimpleButton")); const Flex_1 = require("../../components/Flex"); const preventDefault = (e) => e.preventDefault(); class SmartEditPopupComponent extends React.Component { constructor(props) { super(props); this.state = { isShowingError: false, errorText: '' }; } componentDidMount() { this.props.onSmartEditCheckSelectedCells(); } render() { let col; if (this.props.PreviewInfo) { col = this.props.PreviewInfo.column; } let globalValidationMessage = PreviewHelper_1.PreviewHelper.GetValidationMessage(this.props.PreviewInfo, `${this.props.SmartEditValue}`); let showPanel = this.props.PreviewInfo && StringExtensions_1.StringExtensions.IsNotNullOrEmpty(`${this.props.SmartEditValue}`); let previewPanel = showPanel ? (React.createElement(PreviewResultsPanel_1.PreviewResultsPanel, { className: "twa:flex-[1_1_100%] twa:overflow-initial twa:h-full", previewInfo: this.props.PreviewInfo, api: this.props.api, selectedColumn: col, showPanel: showPanel, showHeader: true })) : null; const operationMenuItems = EnumExtensions_1.EnumExtensions.getNames(Enums_1.MathOperation).map((mathOperation, index) => { return { label: mathOperation, onClick: () => { this.props.onSmartEditOperationChange(mathOperation); }, }; }); const customOperations = this.props.api.smartEditApi.getSmartEditCustomOperations(); if (customOperations?.length) { operationMenuItems.push(...customOperations.map((operation) => { return { onClick: () => this.props.onSmartEditOperationChange(operation), label: operation.name, }; })); } return (React.createElement(PanelWithImage_1.PanelWithImage, { className: "twa:h-full twa:flex-1 twa:p-0!", variant: "primary", bodyProps: { className: 'twa:flex twa:flex-col', }, bodyScroll: true, glyphicon: this.props.moduleInfo.Glyph, header: this.props.moduleInfo.FriendlyName, infoLink: this.props.moduleInfo.HelpPage, infoLinkDisabled: !this.props.api.internalApi.isDocumentationLinksDisplayed(), onKeyDown: (e) => { if (e.key === 'Enter') { this.submit(); } } }, React.createElement(Flex_1.Flex, { flexDirection: "row", "data-name": "smart-edit-operation", className: "twa:p-2" }, React.createElement(DropdownButton_1.default, { "data-name": "smart-edit-operation-dropdown", items: operationMenuItems, columns: ['label'], onMouseDown: preventDefault }, typeof this.props.SmartEditOperation === 'object' ? this.props.SmartEditOperation.name : this.props.SmartEditOperation), React.createElement(Input_1.default, { "data-name": "smart-edit-value", value: this.props.SmartEditValue.toString(), className: "twa:mx-2", type: "number", placeholder: "Enter a Number", onChange: (e) => this.onSmartEditValueChange(e) }), React.createElement(SimpleButton_1.default, { "data-name": "smart-edit-apply-button", className: "twa:mr-2", tone: this.getButtonStyle(), variant: "raised", disabled: StringExtensions_1.StringExtensions.IsNullOrEmpty(`${this.props.SmartEditValue}`) || (this.props.PreviewInfo && this.props.PreviewInfo.previewValidationSummary.validationResult == 'All'), onClick: () => { this.submit(); } }, "Apply Smart Edit"), ' ', this.props.PreviewInfo && this.props.PreviewInfo.previewValidationSummary.validationResult != 'None' && (React.createElement(AdaptablePopover_1.AdaptablePopover, { headerText: 'Validation Error', bodyText: [globalValidationMessage], MessageType: 'Error' }))), previewPanel)); } submit() { this.props.onApplySmartEdit(); } onSmartEditValueChange(event) { const e = event.target; this.props.onSmartEditValueChange(Number(e.value)); } getButtonStyle() { if (this.props.PreviewInfo) { if (this.props.PreviewInfo.previewValidationSummary.validationResult == 'All') { return 'neutral'; } if (this.props.PreviewInfo.previewValidationSummary.validationResult == 'Some') { return 'error'; } } return 'success'; } } function mapStateToProps(state, ownProps) { return { SmartEditValue: state.Internal.SmartEdit.SmartEditValue, SmartEditOperation: state.Internal.SmartEdit.SmartEditOperation, PreviewInfo: state.Internal.SmartEdit.SmartEditPreviewInfo, }; } function mapDispatchToProps(dispatch) { return { onSmartEditValueChange: (value) => dispatch(InternalRedux.SmartEditChangeValue(value)), onSmartEditOperationChange: (SmartEditOperation) => dispatch(InternalRedux.SmartEditChangeOperation(SmartEditOperation)), onSmartEditCheckSelectedCells: () => dispatch(InternalRedux.SmartEditCheckCellSelection()), onApplySmartEdit: () => dispatch(SmartEditRedux.SmartEditApply(false)), }; } exports.SmartEditPopup = (0, react_redux_1.connect)(mapStateToProps, mapDispatchToProps)(SmartEditPopupComponent);