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

75 lines
3.0 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-02 09:42:40 +01:00
import { Switch, Icon, IconButton } from 'react-mdl';
2016-12-04 11:56:41 +01:00
import Progress from './progress';
import { shorten, calc } from '../common';
2016-12-04 11:56:41 +01:00
2016-11-10 14:26:24 +01:00
import style from './feature.scss';
const Feature = ({
feature,
onFeatureClick,
onFeatureRemove,
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
const removeToggle = () => {
if (window.confirm('Are you sure you want to remove this toggle?')) { // eslint-disable-line no-alert
onFeatureRemove(name);
}
};
2016-11-10 14:26:24 +01:00
return (
2016-12-04 11:56:41 +01:00
<li key={name} className="mdl-list__item">
<span className="mdl-list__item-secondary-action">
2016-12-04 11:56:41 +01:00
<div style={{ width: '40px', textAlign: 'center' }}>
{
isStale ?
<Icon
style={{ width: '25px', marginTop: '4px', fontSize: '25px', color: '#ccc' }}
name="report problem" title="No metrics avaiable" /> :
<div>
<Progress strokeWidth={15} percentage={percent} width="50" />
</div>
2016-12-04 11:56:41 +01:00
}
</div>
</span>
<span className="mdl-list__item-secondary-action" style={{ width: '45px' }} title={`Toggle ${name}`}>
<Switch title="test" key="left-actions" onChange={() => onFeatureClick(feature)} checked={enabled} />
</span>
<span className="mdl-list__item-primary-content">
<Link to={`/features/view/${name}`} className={style.link} style={{ display: 'inline-block', width: '100%' }}>
2016-12-23 08:48:29 +01:00
{shorten(name, 50)} <small className={style.hideLt960}>{shorten(description, 30) || ''}</small>
2016-12-04 11:56:41 +01:00
</Link>
</span>
<span className="mdl-list__item-secondary-action">
2017-01-02 09:42:40 +01:00
{strategies && strategies.map((s, i) => <span className={[style.iconListItemChip, style.hideLt960].join(' ')} key={i}>
{s.name}
</span>)}
</span>
<span className="mdl-list__item-secondary-action">
2016-12-22 16:06:30 +01:00
<IconButton name="delete" onClick={removeToggle} className={style.iconListItem} />
2016-12-04 11:56:41 +01:00
</span>
</li>
2016-11-10 14:26:24 +01:00
);
};
Feature.propTypes = {
feature: PropTypes.object,
onFeatureClick: PropTypes.func,
onFeatureRemove: PropTypes.func,
};
export default Feature;