UNPKG

@bigfishtv/cockpit

Version:

154 lines (119 loc) 5.67 kB
'use strict'; exports.__esModule = true; exports.default = undefined; var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; var _class, _temp2; var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _classnames = require('classnames'); var _classnames2 = _interopRequireDefault(_classnames); var _moment = require('moment'); var _moment2 = _interopRequireDefault(_moment); var _get2 = require('lodash/get'); var _get3 = _interopRequireDefault(_get2); var _Panel = require('./Panel'); var _Panel2 = _interopRequireDefault(_Panel); var _ModalHost = require('../../modal/ModalHost'); var _timeUtils = require('../../../utils/timeUtils'); var _SectionsPublishModal = require('../../modal/SectionsPublishModal'); var _SectionsPublishModal2 = _interopRequireDefault(_SectionsPublishModal); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } 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 SectionPanel = (_temp2 = _class = function (_Component) { _inherits(SectionPanel, _Component); function SectionPanel() { var _temp, _this, _ret; _classCallCheck(this, SectionPanel); 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.handleSectionPublishProperties = function () { var _this$props = _this.props, formValue = _this$props.formValue, allSections = _this$props.allSections; var section = formValue.value; var title = (section.title || section.name || section.label || (0, _get3.default)(allSections.map(function (_ref) { var sectionType = _ref.sectionType; return sectionType; }).find(function (_ref2) { var property = _ref2.property; return property == formValue.keyPath[0]; }), 'title', 'Section')) + ' - Publish Properties'; _ModalHost.modalHandler.add({ Component: _SectionsPublishModal2.default, props: { formValue: formValue, sections: allSections, multiple: false, title: title } }); }, _temp), _possibleConstructorReturn(_this, _ret); } SectionPanel.prototype.render = function render() { var _props = this.props, children = _props.children, props = _objectWithoutProperties(_props, ['children']); var formValue = props.formValue, panelClassName = props.panelClassName, title = props.title; var _ref3 = formValue.value || {}, publish_date = _ref3.publish_date, expiry_date = _ref3.expiry_date, enabled = _ref3.enabled; var status = 'success'; var tooltip = ''; if (!enabled) { status = 'error'; tooltip = 'Disabled'; } else { tooltip = 'Enabled'; if (publish_date && !expiry_date) { if ((0, _moment2.default)().diff(publish_date) < 0) status = 'warning'; tooltip += ' from ' + (0, _timeUtils.formatDate)(publish_date); } else if (publish_date && expiry_date) { if ((0, _moment2.default)().diff(publish_date) < 0 || (0, _moment2.default)().diff(expiry_date) > 0) status = 'warning'; tooltip += ' from ' + (0, _timeUtils.getTimeRange)(publish_date, expiry_date); } } var titleNode = _react2.default.createElement( 'div', { className: 'flex' }, _react2.default.createElement( 'div', { className: 'flex-none padding-right-xsmall' }, _react2.default.createElement( 'span', { 'data-tooltip': tooltip, 'data-tooltip-direction': 'right', style: { verticalAlign: 'initial' }, onClick: this.handleSectionPublishProperties }, _react2.default.createElement('div', { style: { cursor: 'pointer', marginRight: '0.5rem' }, className: (0, _classnames2.default)('status', status) }) ) ), title && _react2.default.createElement( 'div', { className: 'flex-1-1-auto' }, title ) ); var overwriteProps = { panelClassName: (0, _classnames2.default)(panelClassName), title: titleNode }; if (!enabled) overwriteProps.collapsed = true; return _react2.default.createElement( _Panel2.default, _extends({}, props, overwriteProps, { title: titleNode }), children ); }; return SectionPanel; }(_react.Component), _class.defaultProps = { panelClassName: 'panel' }, _temp2); exports.default = SectionPanel;