shradmin
Version:
A frontend Framework for building admin application, using antd and mirrorjs.
139 lines (102 loc) • 4.5 kB
JavaScript
;
exports.__esModule = true;
var _style3 = require('antd/lib/card/style');
var _card = require('antd/lib/card');
var _card2 = _interopRequireDefault(_card);
var _style4 = require('antd/lib/spin/style');
var _spin = require('antd/lib/spin');
var _spin2 = _interopRequireDefault(_spin);
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _mirrorx = require('mirrorx');
var _compose = require('recompose/compose');
var _compose2 = _interopRequireDefault(_compose);
var _i18n = require('../../i18n');
var _ShowActions = require('./ShowActions');
var _ShowActions2 = _interopRequireDefault(_ShowActions);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var Show = function (_Component) {
_inherits(Show, _Component);
function Show() {
var _temp, _this, _ret;
_classCallCheck(this, Show);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, _Component.call.apply(_Component, [this].concat(args))), _this), _this.updateData = function () {
var _this$props = _this.props,
model = _this$props.model,
id = _this$props.id;
_mirrorx.actions[model].getOne(id);
}, _this.refresh = function (event) {
event.stopPropagation();
_this.updateData();
}, _temp), _possibleConstructorReturn(_this, _ret);
}
Show.prototype.componentDidMount = function componentDidMount() {
this.updateData();
};
Show.prototype.render = function render() {
var _props = this.props,
children = _props.children,
title = _props.title,
model = _props.model,
record = _props.record,
id = _props.id,
actions = _props.actions,
hasEdit = _props.hasEdit,
hasList = _props.hasList,
hasDelete = _props.hasDelete,
loading = _props.loading,
translate = _props.translate;
var titleElement = record && title ? _react2.default.cloneElement(title, { record: record }) : translate('models.' + model + '.name') + (' #' + id);
return _react2.default.createElement(
_card2.default,
{
title: titleElement,
bordered: false,
noHovering: true,
extra: _react2.default.cloneElement(actions, {
model: model,
record: record,
refresh: this.refresh,
hasEdit: hasEdit,
hasList: hasList,
hasDelete: hasDelete
}) },
_react2.default.createElement(
_spin2.default,
{ spinning: loading },
record && _react2.default.cloneElement(children, {
model: model,
record: record,
translate: translate
})
)
);
};
return Show;
}(_react.Component);
Show.propTypes = process.env.NODE_ENV !== "production" ? {
actions: _propTypes2.default.element,
model: _propTypes2.default.string.isRequired
} : {};
Show.defaultProps = {
actions: _react2.default.createElement(_ShowActions2.default, null)
};
var enhance = (0, _compose2.default)((0, _mirrorx.connect)(function (state, props) {
var id = decodeURIComponent(props.match.params.id);
var data = state[props.model].list[id] || {};
return {
id: id,
record: data.record,
loading: state.loading
};
}), _i18n.translate);
exports.default = enhance(Show);
module.exports = exports['default'];