UNPKG

@qn-pandora/pandora-visualization

Version:

Pandora 通用可视化库

96 lines (95 loc) 5.07 kB
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 (Object.prototype.hasOwnProperty.call(b, 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 __()); }; })(); var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; import * as React from 'react'; import { Selector, Form } from '../../../Common'; import { OtherLocale } from '../../../../constants/language/other/type'; import { SolidRadioItem } from '../../../Base'; import bind from '../../../../utils/bind'; import contextWrapper from '../../../../hocs/contextWrapper'; import statusPanelContext from '../context'; import StringThreshold from './StringThreshold'; import NumberThreshold from './NumberThreshold'; import { ruleTypeOptions } from './constants'; var Item = Form.Item; var formItemLayout = { labelCol: { span: 6 }, wrapperCol: { span: 18 } }; var Rule = /** @class */ (function (_super) { __extends(Rule, _super); function Rule() { return _super !== null && _super.apply(this, arguments) || this; } Rule.prototype.handleChange = function (props, newValue) { var _a; var _b = this.props, value = _b.value, onChange = _b.onChange, _c = _b.stringFields, stringFields = _c === void 0 ? [] : _c; var resValue = __assign(__assign({}, value), (_a = {}, _a[props] = newValue, _a)); // 改变的为指标时要判断是字段类型是否改变 if (props === 'fieldKey') { var isNumberField = stringFields.indexOf(newValue) === -1; resValue.type = isNumberField ? 'number' : 'string'; // 重置阈值 resValue.thresholds = isNumberField ? [{ value: Infinity, level: '' }] : []; } if (props === 'type') { // 重置阈值 resValue.thresholds = newValue === 'number' ? [{ value: Infinity, level: '' }] : []; } onChange(resValue); }; Rule.prototype.render = function () { var _this = this; var _a = this.props, className = _a.className, value = _a.value, _b = _a.fieldOptions, fieldOptions = _b === void 0 ? [] : _b; return (React.createElement("div", { className: className }, React.createElement(Item, __assign({ label: OtherLocale.status.name }, formItemLayout), React.createElement(Selector, { options: fieldOptions, value: value.fieldKey, onChange: function (key) { return _this.handleChange('fieldKey', key); } })), React.createElement(SolidRadioItem, __assign({ label: OtherLocale.status.type, value: value.type, options: ruleTypeOptions, onChange: function (type) { return _this.handleChange('type', type); } }, formItemLayout)), React.createElement(Item, __assign({ label: OtherLocale.status.threshold }, formItemLayout), value.type === 'number' ? (React.createElement(NumberThreshold, { value: value.thresholds, onChange: function (thresholds) { return _this.handleChange('thresholds', thresholds); } })) : (React.createElement(StringThreshold, { value: value.thresholds, onChange: function (thresholds) { return _this.handleChange('thresholds', thresholds); } }))))); }; __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", [String, Object]), __metadata("design:returntype", void 0) ], Rule.prototype, "handleChange", null); return Rule; }(React.Component)); export default contextWrapper(Rule, statusPanelContext);