1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/frontend/src/component/feature/feature-list-item-component.jsx

65 lines
2.6 KiB
React
Raw Normal View History

2016-11-10 14:26:24 +01:00
import React, { PropTypes } from 'react';
import { Link } from 'react-router';
2017-01-06 12:53:53 +01:00
import { Switch, Icon } from 'react-mdl';
2016-12-04 11:56:41 +01:00
import Progress from './progress';
import { shorten, calc, styles as commonStyles } from '../common';
2016-12-04 11:56:41 +01:00
import styles from './feature.scss';
2016-11-10 14:26:24 +01:00
const Feature = ({
feature,
toggleFeature,
2016-12-04 11:56:41 +01:00
settings,
metricsLastHour = { yes: 0, no: 0, isFallback: true },
metricsLastMinute = { yes: 0, no: 0, isFallback: true },
2016-11-10 14:26:24 +01:00
}) => {
2016-12-04 11:56:41 +01:00
const { name, description, enabled, strategies } = feature;
const { showLastHour = false } = settings;
const isStale = showLastHour ? metricsLastHour.isFallback : metricsLastMinute.isFallback;
2016-11-10 14:26:24 +01:00
2016-12-04 11:56:41 +01:00
const percent = 1 * (showLastHour ?
calc(metricsLastHour.yes, metricsLastHour.yes + metricsLastHour.no, 0) :
calc(metricsLastMinute.yes, metricsLastMinute.yes + metricsLastMinute.no, 0)
2016-12-04 11:56:41 +01:00
);
2016-12-22 16:06:30 +01:00
2016-11-10 14:26:24 +01:00
return (
2017-01-02 11:25:10 +01:00
<li key={name} className="mdl-list__item mdl-list__item--two-line">
<span className={styles.iconListItemProgress}>
<div style={{ width: '40px', textAlign: 'center' }}>
2016-12-04 11:56:41 +01:00
{
isStale ?
<Icon
style={{ width: '25px', marginTop: '4px', fontSize: '25px', color: '#ccc' }}
name="report problem" title="No metrics available" /> :
<div>
<Progress strokeWidth={15} percentage={percent} width="50" />
</div>
2016-12-04 11:56:41 +01:00
}
</div>
</span>
<span className={styles.iconListItemToggle}>
<Switch title={`Toggle ${name}`} key="left-actions" onChange={() => toggleFeature(name)} checked={enabled} />
</span>
<span className={['mdl-list__item-primary-content', commonStyles.truncate].join(' ')}>
<Link to={`/features/view/${name}`} className={[styles.link, commonStyles.truncate].join(' ')}>
{shorten(name, 75)}
<span className={['mdl-list__item-sub-title', commonStyles.truncate].join(' ')}>{shorten(description, 75) || ''}</span>
2016-12-04 11:56:41 +01:00
</Link>
</span>
<span className={commonStyles.hideLt960}>
2017-01-06 12:53:53 +01:00
{strategies && strategies.map((s, i) => <span className={[styles.iconListItemChip, styles.hideLt960].join(' ')} key={i}>
2017-01-02 09:42:40 +01:00
{s.name}
2017-01-06 12:53:53 +01:00
</span>)}
2016-12-04 11:56:41 +01:00
</span>
</li>
2016-11-10 14:26:24 +01:00
);
};
Feature.propTypes = {
feature: PropTypes.object,
toggleFeature: PropTypes.func,
2016-11-10 14:26:24 +01:00
};
export default Feature;