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/ratings/index.jsx

    r4223 r5024  
    1 import React from 'react';
    2 import rangeRight from 'lodash/rangeRight';
     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';
     8import { rangeRight } from 'lodash';
    39
     10/**
     11 * Internal dependencies.
     12 */
     13import { getPlugin } from 'state/selectors';
    414import PluginRatings from 'components/plugin-ratings';
    515
    6 export default React.createClass( {
    7     displayName: 'RatingsWidget',
     16export class RatingsWidget extends Component {
     17    static propTypes = {
     18        plugin: PropTypes.object,
     19        translate: PropTypes.func,
     20    };
     21
     22    static defaultProps = {
     23        plugin: {},
     24        translate: identity,
     25    };
    826
    927    ratingsBreakdown() {
     28        const { plugin, translate } = this.props;
     29
     30        if ( ! plugin.ratings.length ) {
     31            return (
     32                <div className="rating"><p>{ translate( 'This plugin has not been rated yet.' ) }</p></div>
     33            );
     34        }
     35
    1036        return (
    1137            <div>
    12                 <a className="reviews-link" href={ `https://wordpress.org/support/plugin/${ this.props.plugin.slug }/reviews/` }>See all</a>
     38                <a className="reviews-link" href={ `https://wordpress.org/support/plugin/${ plugin.slug }/reviews/` }>
     39                    { translate( 'See all' ) }
     40                </a>
    1341
    14                 <PluginRatings rating={ this.props.plugin.rating } ratingCount={ this.props.plugin.num_ratings } />
     42                <PluginRatings rating={ plugin.meta.rating } ratingCount={ plugin.ratings.length } />
    1543
    1644                <ul className="ratings-list">
    17                     { rangeRight( 1, 6 ).map( stars => {
    18                         const barWidth = this.props.plugin.num_ratings ? 100 * this.props.plugin.ratings[ stars ] / this.props.plugin.num_ratings : 0;
     45                    { rangeRight( 1, 6 ).map( ( stars ) => {
     46                        const barWidth = plugin.ratings.length ? 100 * plugin.ratings[ stars ] / plugin.ratings.length : 0;
     47                        const link = `https://wordpress.org/support/plugin/${ plugin.slug }/reviews/?filter=${ stars }`;
    1948
    2049                        return (
    21                             <li className="counter-container">
    22                                 <a href={ `https://wordpress.org/support/plugin/${ this.props.plugin.slug }/reviews/?filter=${ stars }` }>
    23                                     <span className="counter-label">{ stars > 1 ? `${ stars } stars` : `${ stars } star` }</span>
     50                            <li key={ stars } className="counter-container">
     51                                <a href={ link }>
     52                                    <span className="counter-label">
     53                                        { translate( '1 star', '%(stars)s stars', { count: stars, args: { stars } } ) }
     54                                    </span>
    2455                                    <span className="counter-back">
    2556                                        <span className="counter-bar" style={ { width: `${ barWidth }%` } } />
    2657                                    </span>
    27                                     <span className="counter-count">{ this.props.plugin.ratings[ stars ] }</span>
     58                                    <span className="counter-count">{ plugin.ratings[ stars ] }</span>
    2859                                </a>
    2960                            </li>
     
    3364            </div>
    3465        );
    35     },
     66    }
    3667
    3768    render() {
     69        const { plugin, translate } = this.props;
     70
    3871        return (
    3972            <div className="widget plugin-ratings">
    40                 <h4 className="widget-title">Ratings</h4>
    41                 <meta itemProp="ratingCount" content={ this.props.plugin.num_ratings } />
    42                 { this.props.plugin.num_ratings ?
    43                     this.ratingsBreakdown() :
    44                     <div className="rating"><p>This plugin has not been rated yet.</p></div>
    45                 }
     73                <h4 className="widget-title">{ translate( 'Ratings' ) }</h4>
     74                <meta itemProp="ratingCount" content={ plugin.ratings.length } />
     75
     76                { this.ratingsBreakdown() }
     77
    4678                <div className="user-rating">
    47                     <a className="button button-secondary" href={ `https://wordpress.org/support/plugin/${ this.props.plugin.slug }/reviews/#new-post` }>Add my review</a>
     79                    <a
     80                        className="button button-secondary"
     81                        href={ `https://wordpress.org/support/plugin/${ plugin.slug }/reviews/#new-post` }
     82                    >
     83                        { translate( 'Add my review' ) }
     84                    </a>
    4885                </div>
    4986            </div>
    50         )
     87        );
    5188    }
    52 } );
     89}
     90
     91export default connect(
     92    ( state ) => ( {
     93        plugin: getPlugin( state ),
     94    } ),
     95)( localize( RatingsWidget ) );
Note: See TracChangeset for help on using the changeset viewer.