Github user robertkowalski commented on a diff in the pull request:
https://github.com/apache/couchdb-fauxton/pull/544#discussion_r41139622
--- Diff: app/addons/fauxton/components.react.jsx ---
@@ -334,13 +354,246 @@ function (app, FauxtonAPI, React, ZeroClipboard) {
});
+ var NotificationCenterButton = React.createClass({
+ getInitialState: function () {
+ return {
+ visible: true
+ };
+ },
+
+ hide: function () {
+ this.setState({ visible: false });
+ },
+
+ show: function () {
+ this.setState({ visible: true });
+ },
+
+ render: function () {
+ var classes = 'fonticon fonticon-bell' + ((!this.state.visible) ? '
hide' : '');
+ return (
+ <div className={classes}
onClick={Actions.showNotificationCenter}></div>
+ );
+ }
+ });
+
+ var NotificationCenterPanel = React.createClass({
+
+ getInitialState: function () {
+ return this.getStoreState();
+ },
+
+ getStoreState: function () {
+ return {
+ isVisible: notificationStore.isNotificationCenterVisible(),
+ filter: notificationStore.getNotificationFilter(),
+ notifications: notificationStore.getNotifications()
+ };
+ },
+
+ componentDidMount: function () {
+ notificationStore.on('change', this.onChange, this);
+ },
+
+ componentWillUnmount: function () {
+ notificationStore.off('change', this.onChange);
+ },
+
+ onChange: function () {
+ if (this.isMounted()) {
+ this.setState(this.getStoreState());
+ }
+ },
+
+ getNotifications: function () {
+ if (!this.state.notifications.length) {
+ return (
+ <li className="no-notifications">No notifications.</li>
+ );
+ }
+
+ return _.map(this.state.notifications, function (notification, i) {
+ return (
+ <NotificationRow
+ isVisible={this.state.isVisible}
+ item={notification}
+ filter={this.state.filter}
+ key={notification.notificationId}
+ />
+ );
+ }, this);
+ },
+
+ selectFilter: function (e) {
+ var filter = $(e.target).closest('li').data('filter');
+ Actions.selectNotificationFilter(filter);
+ },
+
+ render: function () {
+ var panelClasses = 'notification-center-panel flex-layout flex-col';
+ if (this.state.isVisible) {
+ panelClasses += ' visible';
+ }
+
+ var filterClasses = {
+ all: 'flex-body',
+ success: 'flex-body',
+ error: 'flex-body',
+ info: 'flex-body'
+ };
+ filterClasses[this.state.filter] += ' selected';
+
+ var maskClasses = 'notification-page-mask' + ((this.state.isVisible)
? ' visible' : '');
+ return (
+ <div>
+ <div className={panelClasses}>
+
+ <header className="flex-layout flex-row">
+ <span className="fonticon fonticon-bell"></span>
+ <h1 className="flex-body">Notifications</h1>
+ <button type="button" aria-hidden="true"
onClick={Actions.hideNotificationCenter}>Ã</button>
+ </header>
+
+ <ul className="notification-filter flex-layout flex-row"
onClick={this.selectFilter}>
+ <li className={filterClasses.all} data-filter="all"
title="All notifications">All</li>
+ <li className={filterClasses.success} data-filter="success"
title="Success notifications">
+ <span className="fonticon fonticon-ok-circled"></span>
+ </li>
+ <li className={filterClasses.error} data-filter="error"
title="Error notifications">
+ <span className="fonticon
fonticon-attention-circled"></span>
+ </li>
+ <li className={filterClasses.info} data-filter="info"
title="Info notifications">
+ <span className="fonticon fonticon-info-circled"></span>
+ </li>
+ </ul>
+
+ <div className="flex-body">
+ <ul className="notification-list">
+ {this.getNotifications()}
+ </ul>
+ </div>
+
+ <footer>
+ <input type="button" value="Clear All" className="btn
btn-small btn-info" onClick={Actions.clearAllNotifications} />
+ </footer>
+ </div>
+
+ <div className={maskClasses}
onClick={Actions.hideNotificationCenter}></div>
+ </div>
+ );
+ }
+ });
+
+ var NotificationRow = React.createClass({
+ propTypes: {
+ item: React.PropTypes.object.isRequired,
+ filter: React.PropTypes.string.isRequired,
+ transitionSpeed: React.PropTypes.number
+ },
+
+ getDefaultProps: function () {
+ return {
+ transitionSpeed: 300
+ };
+ },
+
+ clearNotification: function () {
+ var notificationId = this.props.item.notificationId;
+ this.hide(function () {
+ Actions.clearSingleNotification(notificationId);
+ });
+ },
+
+ componentDidMount: function () {
+ this.setState({
+ elementHeight: this.getHeight()
+ });
+ },
+
+ componentDidUpdate: function (prevProps) {
+ // in order for the nice slide effects to work we need a concrete
element height to slide to and from.
+ // $.outerHeight() only works reliably on visible elements, hence
this additional setState here
+ if (!prevProps.isVisible && this.props.isVisible) {
+ this.setState({
+ elementHeight: this.getHeight()
+ });
+ }
+
+ var show = true;
+ if (this.props.filter !== 'all') {
+ show = this.props.item.type === this.props.filter;
+ }
+ if (show) {
+ console.log(this.state.elementHeight);
+ $(this.getDOMNode()).velocity({ opacity: 1, height:
this.state.elementHeight }, this.props.transitionSpeed);
+ } else {
+ this.hide();
--- End diff --
early returns make it easier readable and you don't need to nest that much
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---