@qn-pandora/pandora-visualization
Version:
Pandora 通用可视化库
137 lines (136 loc) • 6.78 kB
JavaScript
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);
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
};
import * as React from 'react';
import classnames from 'classnames';
import { findIndex, findLastIndex } from 'lodash';
import { Input } from 'antd';
import { Form } from '@qn-pandora/pandora-app-component';
import { BaseLocale } from '../../../../../constants/language/base/type';
import { OtherLocale } from '../../../../../constants/language/other/type';
import { formatString } from '../../../../../services/language';
import { Selector } from '../../../../Common';
import { AddIcon, DeleteIcon } from '../../../../Base';
import bind from '../../../../../utils/bind';
import contextWrapper from '../../../../../hocs/contextWrapper';
import statusPanelContext from '../../context';
import * as style from './style.mless';
var RowContainer = Form.RowContainer;
var StringThreshold = /** @class */ (function (_super) {
__extends(StringThreshold, _super);
function StringThreshold() {
return _super !== null && _super.apply(this, arguments) || this;
}
StringThreshold.prototype.handleCreate = function () {
var _a = this.props, value = _a.value, onChange = _a.onChange;
onChange(__spread(value, [
{
value: '',
level: ''
}
]));
};
StringThreshold.prototype.handleChange = function (threshold, props, newValue) {
var _a = this.props, value = _a.value, onChange = _a.onChange;
onChange(value.map(function (e) {
var _a;
return e === threshold
? __assign(__assign({}, e), (_a = {}, _a[props] = newValue, _a)) : e;
}));
};
StringThreshold.prototype.handleDelete = function (threshold) {
var _a = this.props, value = _a.value, onChange = _a.onChange;
onChange(value.filter(function (item) { return item !== threshold; }));
};
StringThreshold.prototype.render = function () {
var _this = this;
var _a = this.props, thresholds = _a.value, _b = _a.levelOptions, levelOptions = _b === void 0 ? [] : _b, getPopupContainer = _a.getPopupContainer;
return (React.createElement("div", null,
thresholds.map(function (item, index) {
var _a;
var value = item.value, level = item.level;
var inputHasError = findIndex(thresholds, function (item) { return item.value === value; }) !==
findLastIndex(thresholds, function (item) { return item.value === value; });
return (React.createElement("div", { key: index, className: style.item },
React.createElement(RowContainer, { sizes: [14, 6, 4], gutter: 8 },
React.createElement(Input, { className: classnames(style.input, (_a = {},
_a[style.error] = inputHasError,
_a)), value: value, onChange: function (e) {
return _this.handleChange(item, 'value', e.target.value);
} }),
React.createElement(Selector, { className: style.selector, dropdownMatchSelectWidth: false, options: levelOptions, value: level, onChange: function (e) { return _this.handleChange(item, 'level', e); }, getPopupContainer: getPopupContainer }),
React.createElement(DeleteIcon, { onClick: function () { return _this.handleDelete(item); } }))));
}),
React.createElement(AddIcon, { onClick: this.handleCreate, title: "" + formatString(BaseLocale.add) + formatString(OtherLocale.ranges) })));
};
__decorate([
bind,
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], StringThreshold.prototype, "handleCreate", null);
__decorate([
bind,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, String, Object]),
__metadata("design:returntype", void 0)
], StringThreshold.prototype, "handleChange", null);
__decorate([
bind,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], StringThreshold.prototype, "handleDelete", null);
return StringThreshold;
}(React.Component));
export default contextWrapper(StringThreshold, statusPanelContext);