Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions src/components/home/cluster_dashboard_item.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { relativeDate } from '../../lib/helpers.js';
import Button from '../shared/button';
import ButtonGroup from 'react-bootstrap/lib/ButtonGroup';
import ClusterIDLabel from '../shared/cluster_id_label';
import moment from 'moment';
import PropTypes from 'prop-types';
import React from 'react';

Expand Down Expand Up @@ -70,6 +71,19 @@ class ClusterDashboardItem extends React.Component {
return 0;
}

/**
* Returns true if the cluster is younger than 30 days
*/
clusterYoungerThan30Days() {
var age = Math.abs(
moment(this.props.cluster.create_date)
.utc()
.diff(moment().utc()) / 1000
);

return age < 30 * 24 * 60 * 60;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small perf improvement: calculate this in a class var as constant to avoid do the calculation every call :)

}

accessCluster() {
this.props.dispatch(
push(
Expand All @@ -86,6 +100,7 @@ class ClusterDashboardItem extends React.Component {
var memory = this.getMemoryTotal();
var storage = this.getStorageTotal();
var cpus = this.getCpusTotal();

return (
<div className='cluster-dashboard-item well'>
<div className='cluster-dashboard-item--label'>
Expand Down Expand Up @@ -144,12 +159,16 @@ class ClusterDashboardItem extends React.Component {
</div>

<div className='cluster-dashboard-item--buttons'>
<ButtonGroup>
<Button onClick={this.accessCluster.bind(this)}>
<i className='fa fa-start' />
Get Started
</Button>
</ButtonGroup>
{this.clusterYoungerThan30Days() ? (
<ButtonGroup>
<Button onClick={this.accessCluster.bind(this)}>
<i className='fa fa-start' />
Get Started
</Button>
</ButtonGroup>
) : (
''
)}
</div>
</div>
);
Expand Down