1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-07-21 13:47:39 +02:00
unleash.unleash/frontend/src/component/feature/FeatureView/FeatureStatus/FeatureStatus.tsx
Fredrik Strand Oseberg 18287cdbd0 Fix/cleanup unused code (#651)
* fix: remove unused context code

* fix: refactor users

* fix: rename delete user

* fix: rename frontend

* fix: update feature view path

* fix: cleanup create feature

* fix: cleanup feature views

* fix: cleanup feature strategies

* fix: update paths

* fix: remove unused strategy components

* fix strategies link

* fix: update snapshots

* fix: import paths

* fix: add name to useEffect dependency
2022-02-04 10:36:08 +01:00

115 lines
3.1 KiB
TypeScript

import { useStyles } from './FeatureStatus.styles';
import TimeAgo from 'react-timeago';
import ConditionallyRender from '../../../common/ConditionallyRender';
import { Tooltip } from '@material-ui/core';
function generateUnit(unit?: string): string {
switch (unit) {
case 'second':
return 's';
case 'minute':
return 'm';
case 'hour':
return 'h';
case 'day':
return 'D';
case 'week':
return 'W';
case 'month':
return 'M';
case 'year':
return 'Y';
default:
return '';
}
}
function getColor(unit?: string): string {
switch (unit) {
case 'second':
return '#98E3AF';
case 'minute':
return '#98E3AF';
case 'hour':
return '#98E3AF';
case 'day':
return '#98E3AF';
case 'week':
return '#ECD875';
case 'month':
return '#F5A69A';
case 'year':
return '#F5A69A';
default:
return '#EDF0F1';
}
}
interface FeatureStatusProps {
lastSeenAt?: Date;
tooltipPlacement?: string;
}
const FeatureStatus = ({
lastSeenAt,
tooltipPlacement,
}: FeatureStatusProps) => {
const styles = useStyles();
const Wrapper = (
props: React.PropsWithChildren<{ color: string; toolTip: string }>
) => {
return (
<Tooltip title={props.toolTip} arrow placement={tooltipPlacement}>
<div
className={styles.container}
style={{ background: props.color, fontSize: '0.8rem' }}
>
{props.children}
</div>
</Tooltip>
);
};
return (
<ConditionallyRender
condition={!!lastSeenAt}
show={
//@ts-ignore
<TimeAgo
date={lastSeenAt}
title=""
live={false}
formatter={(
value: number,
unit: string,
suffix: string
) => {
return (
<Wrapper
toolTip={`Last usage reported ${value} ${unit}${
value !== 1 ? 's' : ''
} ${suffix}`}
color={getColor(unit)}
>
{value}
{generateUnit(unit)}
</Wrapper>
);
}}
/>
}
elseShow={
<Wrapper
toolTip="No usage reported from connected applications"
color={getColor()}
>
<span style={{ fontSize: '1.4rem' }}></span>
</Wrapper>
}
/>
);
};
export default FeatureStatus;