@bigfishtv/cockpit
Version:
130 lines (109 loc) • 4.94 kB
JavaScript
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;
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; }
import React, { Component } from 'react';
import cn from 'classnames';
import moment from 'moment';
import _get from 'lodash/get';
import Panel from './Panel';
import { modalHandler } from '../../modal/ModalHost';
import { formatDate, getTimeRange } from '../../../utils/timeUtils';
import SectionsPublishModal from '../../modal/SectionsPublishModal';
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 || _get(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';
modalHandler.add({
Component: SectionsPublishModal,
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 (moment().diff(publish_date) < 0) status = 'warning';
tooltip += ' from ' + formatDate(publish_date);
} else if (publish_date && expiry_date) {
if (moment().diff(publish_date) < 0 || moment().diff(expiry_date) > 0) status = 'warning';
tooltip += ' from ' + getTimeRange(publish_date, expiry_date);
}
}
var titleNode = React.createElement(
'div',
{ className: 'flex' },
React.createElement(
'div',
{ className: 'flex-none padding-right-xsmall' },
React.createElement(
'span',
{
'data-tooltip': tooltip,
'data-tooltip-direction': 'right',
style: { verticalAlign: 'initial' },
onClick: this.handleSectionPublishProperties },
React.createElement('div', { style: { cursor: 'pointer', marginRight: '0.5rem' }, className: cn('status', status) })
)
),
title && React.createElement(
'div',
{ className: 'flex-1-1-auto' },
title
)
);
var overwriteProps = {
panelClassName: cn(panelClassName),
title: titleNode
};
if (!enabled) overwriteProps.collapsed = true;
return React.createElement(
Panel,
_extends({}, props, overwriteProps, { title: titleNode }),
children
);
};
return SectionPanel;
}(Component), _class.defaultProps = {
panelClassName: 'panel'
}, _temp2);
export { SectionPanel as default };