Making WordPress.org


Ignore:
Timestamp:
12/17/2018 07:34:12 AM (7 years ago)
Author:
vedjain
Message:

WCPT Application Tracker: Multiple changes in rendering of application status report, see desc.

  1. Add customRender option to allow specifying different render logic in application tracker report.
  2. Send timestamp for lastUpdated column instead of humanize_time_diff. Move logic for humanize_time_diff to frontend, because its a very simple logic, and would make a easy fix for #2501
  3. Use customRender option to display X time ago instead of absolute timestamp.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/javascript/tracker/source/tracker.jsx

    r3814 r7976  
    77require( './style.scss' );
    88
     9/**
     10 * Courtesy: https://stackoverflow.com/a/3177838/1845153
     11 *
     12 * Converts unix seconds into human readable time.
     13 * Looks like exact javascript convert of WordPress's human_time_diff, except this always compares from current time, instead of getting two arguments.
     14 *
     15 * @param {int} date Unix timestamp date to compare from
     16 *
     17 * @returns {string} Human readable time ago
     18 */
     19const timeSince = ( date ) => {
     20
     21    const seconds = Math.floor( (new Date() / 1000 ) - date );
     22
     23    let interval = Math.floor(seconds / 31536000);
     24
     25    if (interval > 1) {
     26        return interval + " years";
     27    }
     28    interval = Math.floor(seconds / 2592000);
     29    if (interval > 1) {
     30        return interval + " months";
     31    }
     32    interval = Math.floor(seconds / 86400);
     33    if (interval > 1) {
     34        return interval + " days";
     35    }
     36    interval = Math.floor(seconds / 3600);
     37    if (interval > 1) {
     38        return interval + " hours";
     39    }
     40    interval = Math.floor(seconds / 60);
     41    if (interval > 1) {
     42        return interval + " minutes";
     43    }
     44    return Math.floor(seconds) + " seconds";
     45};
     46
     47/**
     48 * Custom render function for lastUpdatedColumn. Will display X time ago instead of unix timestamp
     49 */
     50const renderHumanizeTime = ( time ) => {
     51    return timeSince( time ) + " ago";
     52};
     53
     54
    955ReactDOM.render(
    1056    <FilterableTable
    1157        initialSortField = { wpcApplicationTracker.initialSortField }
    1258        columns          = { wpcApplicationTracker.displayColumns }
     59        customRender     = {
     60            {
     61                lastUpdate: renderHumanizeTime
     62            }
     63        }
    1364    />,
    1465    document.getElementById( 'wpc-application-tracker' )
Note: See TracChangeset for help on using the changeset viewer.