Making WordPress.org


Ignore:
Timestamp:
03/01/2017 06:08:54 PM (10 years ago)
Author:
obenland
Message:

Plugin Directory: Update React client with latest changes.

This is largely a cleanup commit with some WIP around switching to node-wpapi.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/client/components/widget-area/widgets/support/index.jsx

    r4223 r5024  
    1 import React from 'react';
     1/**
     2 * External dependencies.
     3 */
     4import React, { Component, PropTypes } from 'react';
     5import { connect } from 'react-redux';
     6import { identity } from 'lodash';
     7import { localize } from 'i18n-calypso';
    28
    3 export default React.createClass( {
    4         displayName: 'SupportWidget',
    5         resolutions: false,
     9/**
     10 * Internal dependencies.
     11 */
     12import { getPlugin } from 'state/selectors';
     13
     14export class SupportWidget extends Component {
     15        resolutions: false;
     16
     17        static propTypes = {
     18                plugin: PropTypes.object,
     19                translate: PropTypes.func,
     20        };
     21
     22        static defaultProps = {
     23                plugin: {},
     24                translate: identity,
     25        };
    626
    727        componentWillMount() {
    8                 this.resolutions = ( this.props.plugin.support_threads || 'buddypress' === this.props.plugin.slug || 'bbpress' === this.props.plugin.slug );
    9         },
     28                const { meta, slug } = this.props.plugin;
     29                this.resolutions = ( meta.support_threads || 'buddypress' === slug || 'bbpress' === slug );
     30        }
    1031
    1132        componentDidUpdate() {
    12                 this.resolutions = this.resolutions || this.props.plugin.support_threads;
    13         },
     33                this.resolutions = this.resolutions || this.props.plugin.meta.support_threads;
     34        }
    1435
    1536        supportBar() {
    16                 const { support_threads: threads, support_threads_resolved: resolved } = this.props.plugin;
     37                const { support_threads: threads, support_threads_resolved: resolved } = this.props.plugin.meta;
     38
     39                if ( ! this.resolutions ) {
     40                        return (
     41                                <p>{ this.props.translate( 'Got something to say? Need help?' ) }</p>
     42                        );
     43                }
    1744
    1845                return (
    1946                        <div>
    20                                 <p className="aside">Issues resolved in last two months:</p>
     47                                <p className="aside">{ this.props.translate( 'Issues resolved in last two months:' ) }</p>
    2148                                <p className="counter-container">
    2249                                        <span className="counter-back">
    … …  
    2451                                        </span>
    2552                                        <span className="counter-count">
    26                                                 { resolved } out of { threads }
     53                                                { this.props.translate( '%(resolved)s out of %(threads)s', { args: { resolved, threads } } ) }
    2754                                        </span>
    2855                                </p>
    2956                        </div>
    30                 )
    31         },
     57                );
     58        }
    3259
    3360        getSupportUrl() {
    34                 let supportURL = `https://wordpress.org/support/plugin/${ this.props.plugin.slug }/`;
     61                const { slug } = this.props.plugin;
     62                let supportURL = `https://wordpress.org/support/plugin/${ slug }/`;
    3563
    3664                /*
    … …  
    3866                 * In the future we could open this up to all plugins that define a custom support URL.
    3967                 */
    40                 if ( 'buddypress' === this.props.plugin.slug ) {
     68                if ( 'buddypress' === slug ) {
    4169                        supportURL = 'https://buddypress.org/support/';
    42                 } else if ( 'bbpress' === this.props.plugin.slug ) {
     70                } else if ( 'bbpress' === slug ) {
    4371                        supportURL = 'https://bbpress.org/forums/';
    4472                }
    4573
    4674                return supportURL;
    47         },
     75        }
    4876
    4977        render() {
    5078                return (
    5179                        <div className="widget plugin-support">
    52                                 <h4 className="widget-title">Support</h4>
    53                                 { this.resolutions ?
    54                                         this.supportBar() :
    55                                         <p>Got something to say? Need help?</p>
    56                                 }
     80                                <h4 className="widget-title">{ this.props.translate( 'Support' ) }</h4>
     81
     82                                { this.supportBar() }
     83
    5784                                <p>
    58                                         <a className="button" href={ this.getSupportUrl() }>View support forum</a>
     85                                        <a className="button" href={ this.getSupportUrl() }>
     86                                                { this.props.translate( 'View support forum' ) }
     87                                        </a>
    5988                                </p>
    6089                        </div>
    61                 )
     90                );
    6291        }
    63 } );
     92}
     93
     94export default connect(
     95        ( state ) => ( {
     96                plugin: getPlugin( state ),
     97        } ),
     98)( localize( SupportWidget ) );
Note: See TracChangeset for help on using the changeset viewer.