|
| 1 | +import LinearProgress from '@material-ui/core/LinearProgress'; |
| 2 | +import { FC } from "react" |
| 3 | +import { makeStyles } from "@material-ui/core/styles" |
| 4 | +import { MONOSPACE_FONT_FAMILY } from "../../theme/constants" |
| 5 | +import Skeleton from '@material-ui/lab/Skeleton'; |
| 6 | + |
| 7 | +export interface WorkspaceQuotaProps { |
| 8 | + loading: boolean |
| 9 | + count?: number |
| 10 | + limit?: number |
| 11 | +} |
| 12 | + |
| 13 | +export const WorkspaceQuota: FC<WorkspaceQuotaProps> = ({ loading, count, limit }) => { |
| 14 | + const styles = useStyles() |
| 15 | + |
| 16 | + const safeCount = count ? count : 0; |
| 17 | + const safeLimit = limit ? limit : 100; |
| 18 | + const value = Math.round((safeCount / safeLimit) * 100) |
| 19 | + const limitLanguage = limit ? limit : `∞` |
| 20 | + |
| 21 | + return ( |
| 22 | + <div className={styles.root}> |
| 23 | + <span> |
| 24 | + {loading ? ( |
| 25 | + <div className={styles.item}> |
| 26 | + <div className={styles.quotaBar}> |
| 27 | + <LinearProgress |
| 28 | + value={value} |
| 29 | + color="primary" |
| 30 | + /> |
| 31 | + </div> |
| 32 | + <div className={styles.quotaLabel}> |
| 33 | + <Skeleton /> |
| 34 | + </div> |
| 35 | + <div className={styles.quotaLabel}> |
| 36 | + FILLER TEXT IDK HOW CSS WORKS |
| 37 | + </div> |
| 38 | + </div> |
| 39 | + ) : ( |
| 40 | + <div className={styles.item}> |
| 41 | + <div className={styles.quotaBar}> |
| 42 | + <LinearProgress |
| 43 | + value={value} |
| 44 | + variant="determinate" |
| 45 | + color="primary" |
| 46 | + /> |
| 47 | + </div> |
| 48 | + <div className={styles.quotaLabel}> |
| 49 | + {safeCount} of {limitLanguage} workspaces used |
| 50 | + </div> |
| 51 | + </div> |
| 52 | + )} |
| 53 | + </span> |
| 54 | + </div> |
| 55 | + ) |
| 56 | +} |
| 57 | + |
| 58 | +const useStyles = makeStyles((theme) => ({ |
| 59 | + root: { |
| 60 | + paddingLeft: theme.spacing(2), |
| 61 | + paddingRight: theme.spacing(2), |
| 62 | + borderRadius: theme.shape.borderRadius, |
| 63 | + border: `1px solid ${theme.palette.divider}`, |
| 64 | + display: "flex", |
| 65 | + alignItems: "center", |
| 66 | + color: theme.palette.text.secondary, |
| 67 | + fontFamily: MONOSPACE_FONT_FAMILY, |
| 68 | + margin: "0px", |
| 69 | + [theme.breakpoints.down("sm")]: { |
| 70 | + display: "block", |
| 71 | + }, |
| 72 | + }, |
| 73 | + item: { |
| 74 | + minWidth: "16%", |
| 75 | + padding: theme.spacing(2), |
| 76 | + }, |
| 77 | + quotaBar: { |
| 78 | + fontSize: 12, |
| 79 | + textTransform: "uppercase", |
| 80 | + display: "block", |
| 81 | + fontWeight: 600, |
| 82 | + wordWrap: "break-word", |
| 83 | + paddingTop: theme.spacing(0.5), |
| 84 | + }, |
| 85 | + quotaLabel: { |
| 86 | + fontSize: 12, |
| 87 | + textTransform: "uppercase", |
| 88 | + display: "block", |
| 89 | + fontWeight: 600, |
| 90 | + wordWrap: "break-word", |
| 91 | + paddingTop: theme.spacing(0.5), |
| 92 | + }, |
| 93 | +})) |
0 commit comments