UNPKG

@qn-pandora/pandora-visualization

Version:

Pandora 通用可视化库

203 lines (202 loc) 10.2 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); }; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; var __values = (this && this.__values) || function(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); }; import React from 'react'; import classnames from 'classnames'; import { computed } from 'mobx'; import { observer } from 'mobx-react'; import { InputNumber } from 'antd'; import { DateTimePicker } from '@qn-pandora/pandora-component'; import { SolidRadioGroup, Selector } from '../../../../../components/Common'; import BasicComponent from '../../../../../components/Base/BasicComponent'; import { defaultTimeRange, transformToTimeRange, transformToTime } from '../../../../../services/search-condition'; import bind from '../../../../../utils/bind'; import { ChartTimeTypeOptions, TimeShiftUnitOptions, TimeShiftUnit } from '../../../../../services'; import errorBoundary from '../../../../../hocs/errorBoundary'; import { formatString } from '../../../../../services/language'; import { DashboardLocale } from '../../../../../constants/language/dashboard/type'; import * as styles from './style.mless'; var Base = DateTimePicker.Base; var TimeSelectorContent = /** @class */ (function (_super) { __extends(TimeSelectorContent, _super); function TimeSelectorContent() { return _super !== null && _super.apply(this, arguments) || this; } Object.defineProperty(TimeSelectorContent.prototype, "timeShift", { get: function () { var _a = this.props.value, value = _a === void 0 ? defaultTimeRange : _a; return value.timeShift || ''; }, enumerable: false, configurable: true }); Object.defineProperty(TimeSelectorContent.prototype, "timeShiftValue", { get: function () { return parseFloat(this.timeShift) || 0; }, enumerable: false, configurable: true }); Object.defineProperty(TimeSelectorContent.prototype, "timeShiftUnit", { get: function () { var e_1, _a; try { for (var TimeShiftUnitOptions_1 = __values(TimeShiftUnitOptions), TimeShiftUnitOptions_1_1 = TimeShiftUnitOptions_1.next(); !TimeShiftUnitOptions_1_1.done; TimeShiftUnitOptions_1_1 = TimeShiftUnitOptions_1.next()) { var item = TimeShiftUnitOptions_1_1.value; if (this.timeShift.endsWith(item.value)) { return item.value; } } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (TimeShiftUnitOptions_1_1 && !TimeShiftUnitOptions_1_1.done && (_a = TimeShiftUnitOptions_1.return)) _a.call(TimeShiftUnitOptions_1); } finally { if (e_1) throw e_1.error; } } return TimeShiftUnit.Second; }, enumerable: false, configurable: true }); TimeSelectorContent.prototype.handleTimeTypeChange = function (timeType) { var _a = this.props, onChange = _a.onChange, _b = _a.value, value = _b === void 0 ? defaultTimeRange : _b; if (!onChange) { return; } onChange(__assign(__assign({}, value), { global: timeType === "global" /* Global */ })); }; TimeSelectorContent.prototype.handleTimePickerChange = function (time) { var _a = this.props, onChange = _a.onChange, _b = _a.value, value = _b === void 0 ? defaultTimeRange : _b; if (!onChange) { return; } var resValue = transformToTimeRange(time); onChange(__assign(__assign({}, resValue), { global: value.global, timeShift: value.timeShift })); }; TimeSelectorContent.prototype.handleTimeShiftValueChange = function (shiftValue) { var _a = this.props, onChange = _a.onChange, _b = _a.value, value = _b === void 0 ? defaultTimeRange : _b; if (!onChange) { return; } onChange(__assign(__assign({}, value), { timeShift: shiftValue + this.timeShiftUnit })); }; TimeSelectorContent.prototype.handleTimeShiftUnitChange = function (unit) { var _a = this.props, onChange = _a.onChange, _b = _a.value, value = _b === void 0 ? defaultTimeRange : _b; if (!onChange) { return; } onChange(__assign(__assign({}, value), { timeShift: this.timeShiftValue + unit })); }; TimeSelectorContent.prototype.render = function () { var _a = this.props, className = _a.className, _b = _a.value, value = _b === void 0 ? defaultTimeRange : _b, onChange = _a.onChange, others = __rest(_a, ["className", "value", "onChange"]); return (React.createElement("div", { className: classnames(styles.root, className) }, React.createElement("div", { className: styles.row }, React.createElement("span", null, formatString(DashboardLocale.edit.chart.time.type)), React.createElement(SolidRadioGroup, { className: styles.solidRadioGroup, onChange: this.handleTimeTypeChange, value: value.global ? "global" /* Global */ : "custom" /* Custom */, options: ChartTimeTypeOptions })), !value.global && (React.createElement(Base, __assign({ value: transformToTime(value), onChange: this.handleTimePickerChange }, others))), React.createElement("div", { className: styles.row }, React.createElement("span", null, formatString(DashboardLocale.edit.chart.time.shift)), React.createElement("div", null, React.createElement(InputNumber, { value: this.timeShiftValue, onChange: this.handleTimeShiftValueChange, min: 0 }), React.createElement(Selector, { className: styles.selector, value: this.timeShiftUnit, onChange: this.handleTimeShiftUnitChange, getPopupContainer: this.getRootDOM, options: TimeShiftUnitOptions }))))); }; __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], TimeSelectorContent.prototype, "timeShift", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], TimeSelectorContent.prototype, "timeShiftValue", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], TimeSelectorContent.prototype, "timeShiftUnit", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", void 0) ], TimeSelectorContent.prototype, "handleTimeTypeChange", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], TimeSelectorContent.prototype, "handleTimePickerChange", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", [Number]), __metadata("design:returntype", void 0) ], TimeSelectorContent.prototype, "handleTimeShiftValueChange", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], TimeSelectorContent.prototype, "handleTimeShiftUnitChange", null); TimeSelectorContent = __decorate([ observer ], TimeSelectorContent); return TimeSelectorContent; }(BasicComponent)); export { TimeSelectorContent }; export default errorBoundary(TimeSelectorContent);