@qn-pandora/pandora-visualization
Version:
Pandora 通用可视化库
125 lines (124 loc) • 5.71 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 __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 classnames from 'classnames';
import { includes } from 'lodash';
import { computed, observable, action } from 'mobx';
import { observer } from 'mobx-react';
import PropTypes from 'prop-types';
import { ReloadOutlined } from '@qn-pandora/pandora-component-icons';
import { OptionList } from '@qn-pandora/pandora-component';
import BasicComponent from '../../../../../components/Base/BasicComponent';
import { Button } from '../../../../../components/Common';
import errorBoundary from '../../../../../hocs/errorBoundary';
import { DashboardLocale } from '../../../../../constants/language/dashboard/type';
import { formatString } from '../../../../../services/language';
import bind from '../../../../../utils/bind';
import { refreshIntervals } from './constants';
import * as actionBarStyle from '../style.mless';
import * as style from './style.mless';
var Refresh = /** @class */ (function (_super) {
__extends(Refresh, _super);
function Refresh() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.ref = React.createRef();
_this.active = false;
return _this;
}
Refresh.prototype.toActive = function () {
this.active = true;
};
Refresh.prototype.toDisActive = function (e) {
if (includes(e.propagationPath && e.propagationPath(), this.ref.current)) {
return;
}
this.active = false;
};
Object.defineProperty(Refresh.prototype, "options", {
get: function () {
var _a = this.props, selectedValue = _a.value, onChange = _a.onChange;
return refreshIntervals.map(function (_a) {
var value = _a.value, text = _a.text;
return ({
key: "" + value,
text: formatString(text),
active: value === selectedValue,
onClick: function () { return onChange && onChange(value); }
});
});
},
enumerable: false,
configurable: true
});
Refresh.prototype.componentDidMount = function () {
var _this = this;
document.addEventListener('click', this.toDisActive);
this.addDisposer(function () {
document.removeEventListener('click', _this.toDisActive);
});
};
Refresh.prototype.render = function () {
var _a;
var _b = this.props, className = _b.className, onRefresh = _b.onRefresh;
var getPopupContainer = this.context.getPopupContainer;
return (React.createElement("div", { ref: this.ref, className: classnames(style.root, actionBarStyle.refresh, (_a = {},
_a[style.active] = this.active,
_a), className), onClick: this.toActive },
React.createElement(Button, { className: style.refreshButton, icon: React.createElement(ReloadOutlined, { style: { fontSize: '16px' } }), onClick: onRefresh }, formatString(DashboardLocale.refresh.title)),
React.createElement(OptionList, { placement: "bottomRight", mode: "popover", options: this.options, getPopupContainer: getPopupContainer, popupClassName: style.list },
React.createElement(Button, { icon: "caret-down", className: style.downButton }))));
};
Refresh.contextTypes = {
baseDashboardStore: PropTypes.object,
getPopupContainer: PropTypes.func
};
__decorate([
observable,
__metadata("design:type", Boolean)
], Refresh.prototype, "active", void 0);
__decorate([
bind,
action,
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], Refresh.prototype, "toActive", null);
__decorate([
bind,
action,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], Refresh.prototype, "toDisActive", null);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], Refresh.prototype, "options", null);
Refresh = __decorate([
observer
], Refresh);
return Refresh;
}(BasicComponent));
export { Refresh };
export default errorBoundary(Refresh);