Making WordPress.org


Ignore:
Timestamp:
03/01/2017 06:08:54 PM (7 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/meta/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 { Link } from 'react-router';
     7import { localize } from 'i18n-calypso';
     8import { identity } from 'lodash';
    29
    3 export default React.createClass( {
    4     displayName: 'MetaWidget',
     10/**
     11 * Internal dependencies.
     12 */
     13import { getPlugin } from 'state/selectors';
    514
     15export class MetaWidget extends Component {
     16    static propTypes = {
     17        moment: PropTypes.func,
     18        numberFormat: PropTypes.func,
     19        plugin: PropTypes.object,
     20        translate: PropTypes.func,
     21    };
     22
     23    static defaultProps = {
     24        moment: identity,
     25        numberFormat: identity,
     26        plugin: {},
     27        translate: identity,
     28    };
     29
     30    /**
     31     * Returns a string representing the number of active installs for a plugin.
     32     *
     33     * @return {String} Active installs.
     34     */
     35    activeInstalls() {
     36        const { numberFormat, translate, plugin } = this.props;
     37        let text;
     38
     39        if ( plugin.meta.active_installs <= 10 ) {
     40            text = translate( 'Less than 10' );
     41        } else if ( plugin.meta.active_installs >= 1000000 ) {
     42            text = translate( '1+ million' );
     43        } else {
     44            text = numberFormat( plugin.meta.active_installs ) + '+';
     45        }
     46
     47        return text;
     48    }
     49
     50    /**
     51     * Returns markup to display tags, if there are any.
     52     *
     53     * @return {XML} Tags markup.
     54     */
    655    renderTags() {
    7         if ( this.props.plugin.tags.length ) {
    8             return ( <li>Categories: <div className="tags">{ this.props.plugin.tags.map( tag =>
    9                 <a key={ tag } href={ `https://wordpress.org/plugins-wp/category/${ tag }/` } rel="tag">{ tag }</a>
    10             ) }</div></li> );
     56        const { plugin_tags: tags } = this.props.plugin;
     57
     58        if ( tags && tags.length ) {
     59            const tagsList = (
     60                <div className="tags">
     61                    { tags.map( ( tag ) => <Link key={ tag } to={ `tags/${ tag }/` } rel="tag">{ tag }</Link> ) }
     62                </div>
     63            );
     64
     65            return (
     66                <li>
     67                    { this.props.translate( 'Tag: {{tagsList/}}', 'Tags: {{tagsList/}}', {
     68                        count: tags.length,
     69                        components: { tagsList },
     70                    } ) }
     71                </li>
     72            );
    1173        }
    12     },
     74    }
    1375
    1476    render() {
     77        const { moment, plugin, translate } = this.props;
    1578
    1679        return (
    1780            <div className="widget plugin-meta">
    18                 <h3 className="screen-reader-text">Meta</h3>
     81                <h3 className="screen-reader-text">{ translate( 'Meta' ) }</h3>
    1982                <link itemProp="applicationCategory" href="http://schema.org/OtherApplication" />
    2083                <span itemProp="offers" itemScope itemType="http://schema.org/Offer">
     
    2790
    2891                <ul>
    29                     <li>Version: <strong>{ this.props.plugin.version }</strong></li>
    30                     <li>Last updated: <strong><span itemProp="dateModified" content={ this.props.plugin.last_updated }>{ this.props.plugin.last_updated }</span> ago</strong></li>
    31                     <li>Active installs: <strong>{ this.props.plugin.active_installs }</strong></li>
    32                     <li>Tested up to: <strong>{ this.props.plugin.tested }</strong></li>
     92                    <li>
     93                        { translate( 'Version: {{strong}}%(version)s{{/strong}}', {
     94                            args: { version: plugin.meta.version },
     95                            components: { strong: <strong /> },
     96                        } ) }
     97                    </li>
     98                    <li>
     99                        { translate( 'Last updated: {{strong}}%(updated)s{{/strong}}', {
     100                            args: { updated: moment( plugin.modified_gmt ).fromNow() },
     101                            components: { strong: <strong itemProp="dateModified" content={ plugin.modified_gmt } /> },
     102                        } ) }
     103                    </li>
     104                    <li>
     105                        { translate( 'Active installs: {{strong}}%(installs)s{{/strong}}', {
     106                            args: { installs: this.activeInstalls() },
     107                            components: { strong: <strong /> },
     108                        } ) }
     109                    </li>
     110                    <li>
     111                        { translate( 'Tested up to: {{strong}}%(tested)s{{/strong}}', {
     112                            args: { tested: plugin.meta.tested },
     113                            components: { strong: <strong /> },
     114                        } ) }
     115                    </li>
    33116                    { this.renderTags() }
    34117                </ul>
    35118            </div>
    36         )
     119        );
    37120    }
    38 } );
     121}
     122
     123export default connect(
     124    ( state ) => ( {
     125        plugin: getPlugin( state ),
     126    } ),
     127)( localize( MetaWidget ) );
Note: See TracChangeset for help on using the changeset viewer.