2020-08-03 11:10:58 +03:00
|
|
|
import * as React from "react";
|
|
|
|
import * as Constants from "~/common/constants";
|
|
|
|
import * as Strings from "~/common/strings";
|
|
|
|
import * as System from "~/components/system";
|
|
|
|
|
|
|
|
import { css } from "@emotion/react";
|
|
|
|
|
|
|
|
// NOTE(jim): 10 GB
|
|
|
|
const MAX_IN_BYTES = 10737418240;
|
|
|
|
|
|
|
|
const STYLES_CONTAINER = css`
|
|
|
|
border-radius: 4px;
|
|
|
|
border: 1px solid ${Constants.system.border};
|
2020-08-08 03:22:45 +03:00
|
|
|
padding: 24px;
|
2020-08-26 07:13:50 +03:00
|
|
|
max-width: 100%;
|
2020-08-08 03:22:45 +03:00
|
|
|
width: 100%;
|
2020-08-03 11:10:58 +03:00
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_DATA = css`
|
|
|
|
width: 100%;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
height: 8px;
|
|
|
|
border-radius: 3px;
|
|
|
|
background-color: ${Constants.system.border};
|
|
|
|
overflow: hidden;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_DATA_METER = css`
|
|
|
|
flex-shrink: 0;
|
|
|
|
height: 100%;
|
2020-08-15 05:18:55 +03:00
|
|
|
background-color: #2935ff;
|
2020-08-20 08:45:43 +03:00
|
|
|
background-image: linear-gradient(
|
|
|
|
to left,
|
|
|
|
#2935ff,
|
|
|
|
#342fc4,
|
|
|
|
#33288b,
|
|
|
|
#2b2157,
|
|
|
|
#1d1927
|
|
|
|
);
|
2020-08-03 11:10:58 +03:00
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_ROW = css`
|
|
|
|
display: flex;
|
|
|
|
align-items: flex-end;
|
|
|
|
justify-content: space-between;
|
|
|
|
font-family: ${Constants.font.code};
|
|
|
|
color: ${Constants.system.darkGray};
|
|
|
|
font-size: 10px;
|
|
|
|
margin-top: 2px;
|
|
|
|
text-transform: uppercase;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_STATS_ROW = css`
|
|
|
|
display: flex;
|
|
|
|
align-items: flex-end;
|
|
|
|
justify-content: space-between;
|
|
|
|
font-family: ${Constants.font.code};
|
|
|
|
color: ${Constants.system.black};
|
|
|
|
font-size: 12px;
|
|
|
|
text-transform: uppercase;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_LEFT = css`
|
|
|
|
min-width: 10%;
|
|
|
|
width: 100% "";
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_RIGHT = css`
|
|
|
|
flex-shrink: 0;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_TITLE = css`
|
|
|
|
font-family: ${Constants.font.semiBold};
|
|
|
|
font-weight: 400;
|
|
|
|
font-size: 14px;
|
|
|
|
display: block;
|
|
|
|
margin-bottom: 4px;
|
2020-08-16 04:32:38 +03:00
|
|
|
overflow-wrap: break-word;
|
2020-08-03 11:10:58 +03:00
|
|
|
`;
|
|
|
|
|
2020-08-15 05:08:17 +03:00
|
|
|
export const DataMeterBar = (props) => {
|
|
|
|
const percentage = props.bytes / props.maximumBytes;
|
2020-08-03 11:10:58 +03:00
|
|
|
|
|
|
|
return (
|
2020-08-15 05:08:17 +03:00
|
|
|
<React.Fragment>
|
2020-08-17 07:49:50 +03:00
|
|
|
<div css={STYLES_STATS_ROW}>
|
|
|
|
<div css={STYLES_LEFT}>{Strings.bytesToSize(props.bytes)}</div>
|
|
|
|
<div css={STYLES_RIGHT}>{Strings.bytesToSize(props.maximumBytes)}</div>
|
|
|
|
</div>
|
2020-08-03 11:10:58 +03:00
|
|
|
|
2020-08-08 03:22:45 +03:00
|
|
|
<div css={STYLES_ROW}>
|
2020-08-20 08:45:43 +03:00
|
|
|
<div
|
|
|
|
css={STYLES_LEFT}
|
2020-08-30 23:31:09 +03:00
|
|
|
style={{ color: props.failed ? Constants.system.red : null }}>
|
2020-08-16 04:32:38 +03:00
|
|
|
{props.leftLabel}
|
|
|
|
</div>
|
|
|
|
<div css={STYLES_RIGHT}>{props.rightLabel}</div>
|
2020-08-08 03:22:45 +03:00
|
|
|
</div>
|
2020-08-03 11:10:58 +03:00
|
|
|
|
2020-08-20 08:45:43 +03:00
|
|
|
<div
|
|
|
|
css={STYLES_DATA}
|
|
|
|
style={{
|
|
|
|
marginTop: 4,
|
|
|
|
backgroundColor: props.failed ? Constants.system.red : null,
|
2020-08-30 23:31:09 +03:00
|
|
|
}}>
|
2020-08-20 08:45:43 +03:00
|
|
|
<div
|
|
|
|
css={STYLES_DATA_METER}
|
|
|
|
style={{ width: `${percentage * 100}%` }}
|
|
|
|
/>
|
2020-08-03 11:10:58 +03:00
|
|
|
</div>
|
2020-08-15 05:08:17 +03:00
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-08-30 23:31:09 +03:00
|
|
|
export const DataMeter = (props) => {
|
2020-08-15 05:08:17 +03:00
|
|
|
return (
|
|
|
|
<div css={STYLES_CONTAINER} style={props.style}>
|
2020-08-16 04:32:38 +03:00
|
|
|
<DataMeterBar
|
|
|
|
leftLabel="used"
|
|
|
|
rightLabel="total"
|
|
|
|
bytes={props.stats.bytes}
|
|
|
|
maximumBytes={props.stats.maximumBytes}
|
|
|
|
/>
|
2020-08-03 11:10:58 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
2020-08-30 23:31:09 +03:00
|
|
|
|
|
|
|
export default DataMeter;
|