UNPKG

@gooddata/react-components

Version:

GoodData.UI - A powerful JavaScript library for building analytical applications

102 lines 5.47 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); // (C) 2019 GoodData Corporation var React = require("react"); var get = require("lodash/get"); var Message_1 = require("@gooddata/goodstrap/lib/Messages/Message"); var react_intl_1 = require("react-intl"); var ConfigSubsection_1 = require("../configurationControls/ConfigSubsection"); var InputControl_1 = require("../configurationControls/InputControl"); var controlsHelper_1 = require("../../utils/controlsHelper"); var defaultMinMaxControlState = { minScale: { hasWarning: false, warningMessage: "", incorrectValue: "", }, maxScale: { hasWarning: false, warningMessage: "", incorrectValue: "", }, }; var MinMaxControl = /** @class */ (function (_super) { __extends(MinMaxControl, _super); function MinMaxControl(props) { var _this = _super.call(this, props) || this; _this.minInputValidateAndPushDataCallback = function (data) { controlsHelper_1.minInputValidateAndPushData(data, _this.state, _this.props, _this.setState.bind(_this), defaultMinMaxControlState); }; _this.maxInputValidateAndPushDataCallback = function (data) { controlsHelper_1.maxInputValidateAndPushData(data, _this.state, _this.props, _this.setState.bind(_this), defaultMinMaxControlState); }; _this.state = defaultMinMaxControlState; return _this; } MinMaxControl.getDerivedStateFromProps = function (props) { if (get(props, ["propertiesMeta", "undoApplied"], false)) { return defaultMinMaxControlState; } return null; }; MinMaxControl.prototype.render = function () { return this.renderMinMaxSection(); }; MinMaxControl.prototype.renderMinMaxSection = function () { var _a = this.props, properties = _a.properties, basePath = _a.basePath, isDisabled = _a.isDisabled; var axisScaleMin = get(this.props, "properties.controls." + basePath + ".min", ""); var axisScaleMax = get(this.props, "properties.controls." + basePath + ".max", ""); var axisVisible = get(this.props, "properties.controls." + basePath + ".visible", true); return (React.createElement(ConfigSubsection_1.default, { title: "properties.axis.scale" }, React.createElement(InputControl_1.default, { valuePath: basePath + ".min", labelText: "properties.axis.min", placeholder: "properties.auto_placeholder", type: "number", hasWarning: this.minScaleHasWarning(), value: this.minScaleHasIncorrectValue() ? get(this.state, "minScale.incorrectValue") : axisScaleMin, disabled: isDisabled || !axisVisible, properties: properties, pushData: this.minInputValidateAndPushDataCallback }), this.renderMinErrorMessage(), React.createElement(InputControl_1.default, { valuePath: basePath + ".max", labelText: "properties.axis.max", placeholder: "properties.auto_placeholder", type: "number", hasWarning: this.maxScaleHasWarning(), value: this.maxScaleHasIncorrectValue() ? get(this.state, "maxScale.incorrectValue") : axisScaleMax, disabled: isDisabled || !axisVisible, properties: properties, pushData: this.maxInputValidateAndPushDataCallback }), this.renderMaxErrorMessage())); }; MinMaxControl.prototype.minScaleHasIncorrectValue = function () { return get(this.state, "minScale.incorrectValue", "") !== ""; }; MinMaxControl.prototype.maxScaleHasIncorrectValue = function () { return get(this.state, "maxScale.incorrectValue", "") !== ""; }; MinMaxControl.prototype.minScaleHasWarning = function () { return get(this.state, "minScale.hasWarning", false); }; MinMaxControl.prototype.maxScaleHasWarning = function () { return get(this.state, "maxScale.hasWarning", false); }; MinMaxControl.prototype.renderMinErrorMessage = function () { var minScaleWarningMessage = get(this.state, "minScale.warningMessage", ""); if (!this.minScaleHasWarning() || minScaleWarningMessage === "") { return false; } return (React.createElement(Message_1.default, { type: "warning", className: "adi-input-warning" }, minScaleWarningMessage)); }; MinMaxControl.prototype.renderMaxErrorMessage = function () { var maxScaleWarningMessage = get(this.state, "maxScale.warningMessage", ""); if (!this.maxScaleHasWarning() || maxScaleWarningMessage === "") { return false; } return (React.createElement(Message_1.default, { type: "warning", className: "adi-input-warning" }, maxScaleWarningMessage)); }; return MinMaxControl; }(React.Component)); exports.default = react_intl_1.injectIntl(MinMaxControl); //# sourceMappingURL=MinMaxControl.js.map