@qn-pandora/pandora-visualization
Version:
Pandora 通用可视化库
228 lines (227 loc) • 11.8 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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
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 __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
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.");
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TimeSelectorContent = void 0;
var react_1 = __importDefault(require("react"));
var classnames_1 = __importDefault(require("classnames"));
var mobx_1 = require("mobx");
var mobx_react_1 = require("mobx-react");
var antd_1 = require("antd");
var pandora_component_1 = require("@qn-pandora/pandora-component");
var Common_1 = require("../../../../../components/Common");
var BasicComponent_1 = __importDefault(require("../../../../../components/Base/BasicComponent"));
var search_condition_1 = require("../../../../../services/search-condition");
var bind_1 = __importDefault(require("../../../../../utils/bind"));
var services_1 = require("../../../../../services");
var errorBoundary_1 = __importDefault(require("../../../../../hocs/errorBoundary"));
var language_1 = require("../../../../../services/language");
var type_1 = require("../../../../../constants/language/dashboard/type");
var styles = __importStar(require("./style.mless"));
var Base = pandora_component_1.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 ? search_condition_1.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(services_1.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 services_1.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 ? search_condition_1.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 ? search_condition_1.defaultTimeRange : _b;
if (!onChange) {
return;
}
var resValue = search_condition_1.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 ? search_condition_1.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 ? search_condition_1.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 ? search_condition_1.defaultTimeRange : _b, onChange = _a.onChange, others = __rest(_a, ["className", "value", "onChange"]);
return (react_1.default.createElement("div", { className: classnames_1.default(styles.root, className) },
react_1.default.createElement("div", { className: styles.row },
react_1.default.createElement("span", null, language_1.formatString(type_1.DashboardLocale.edit.chart.time.type)),
react_1.default.createElement(Common_1.SolidRadioGroup, { className: styles.solidRadioGroup, onChange: this.handleTimeTypeChange, value: value.global ? "global" /* Global */ : "custom" /* Custom */, options: services_1.ChartTimeTypeOptions })),
!value.global && (react_1.default.createElement(Base, __assign({ value: search_condition_1.transformToTime(value), onChange: this.handleTimePickerChange }, others))),
react_1.default.createElement("div", { className: styles.row },
react_1.default.createElement("span", null, language_1.formatString(type_1.DashboardLocale.edit.chart.time.shift)),
react_1.default.createElement("div", null,
react_1.default.createElement(antd_1.InputNumber, { value: this.timeShiftValue, onChange: this.handleTimeShiftValueChange, min: 0 }),
react_1.default.createElement(Common_1.Selector, { className: styles.selector, value: this.timeShiftUnit, onChange: this.handleTimeShiftUnitChange, getPopupContainer: this.getRootDOM, options: services_1.TimeShiftUnitOptions })))));
};
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], TimeSelectorContent.prototype, "timeShift", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], TimeSelectorContent.prototype, "timeShiftValue", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], TimeSelectorContent.prototype, "timeShiftUnit", null);
__decorate([
bind_1.default,
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", void 0)
], TimeSelectorContent.prototype, "handleTimeTypeChange", null);
__decorate([
bind_1.default,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], TimeSelectorContent.prototype, "handleTimePickerChange", null);
__decorate([
bind_1.default,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Number]),
__metadata("design:returntype", void 0)
], TimeSelectorContent.prototype, "handleTimeShiftValueChange", null);
__decorate([
bind_1.default,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], TimeSelectorContent.prototype, "handleTimeShiftUnitChange", null);
TimeSelectorContent = __decorate([
mobx_react_1.observer
], TimeSelectorContent);
return TimeSelectorContent;
}(BasicComponent_1.default));
exports.TimeSelectorContent = TimeSelectorContent;
exports.default = errorBoundary_1.default(TimeSelectorContent);