|
| 1 | +import { makeStyles } from "@material-ui/core/styles" |
| 2 | +import TableCell from "@material-ui/core/TableCell" |
| 3 | +import TableRow from "@material-ui/core/TableRow" |
| 4 | +import { WorkspaceBuild } from "api/typesGenerated" |
| 5 | +import { Stack } from "components/Stack/Stack" |
| 6 | +import { useClickable } from "hooks/useClickable" |
| 7 | +import { useTranslation } from "react-i18next" |
| 8 | +import { useNavigate } from "react-router-dom" |
| 9 | +import { MONOSPACE_FONT_FAMILY } from "theme/constants" |
| 10 | +import { |
| 11 | + displayWorkspaceBuildDuration, |
| 12 | + getDisplayWorkspaceBuildInitiatedBy, |
| 13 | +} from "util/workspace" |
| 14 | +import { BuildAvatar } from "./BuildAvatar" |
| 15 | + |
| 16 | +export interface BuildRowProps { |
| 17 | + build: WorkspaceBuild |
| 18 | +} |
| 19 | + |
| 20 | +export const BuildRow: React.FC<BuildRowProps> = ({ build }) => { |
| 21 | + const styles = useStyles() |
| 22 | + const { t } = useTranslation("workspacePage") |
| 23 | + const initiatedBy = getDisplayWorkspaceBuildInitiatedBy(build) |
| 24 | + const navigate = useNavigate() |
| 25 | + const clickableProps = useClickable(() => |
| 26 | + navigate(`builds/${build.build_number}`), |
| 27 | + ) |
| 28 | + |
| 29 | + return ( |
| 30 | + <TableRow |
| 31 | + hover |
| 32 | + data-testid={`build-${build.id}`} |
| 33 | + className={styles.buildRow} |
| 34 | + {...clickableProps} |
| 35 | + > |
| 36 | + <TableCell className={styles.buildCell}> |
| 37 | + <Stack |
| 38 | + direction="row" |
| 39 | + alignItems="center" |
| 40 | + className={styles.buildWrapper} |
| 41 | + > |
| 42 | + <Stack direction="row" alignItems="center"> |
| 43 | + <BuildAvatar build={build} /> |
| 44 | + <div> |
| 45 | + <Stack |
| 46 | + className={styles.buildResume} |
| 47 | + direction="row" |
| 48 | + alignItems="center" |
| 49 | + spacing={1} |
| 50 | + > |
| 51 | + <span> |
| 52 | + <strong>{initiatedBy}</strong>{" "} |
| 53 | + {build.reason !== "initiator" |
| 54 | + ? t("buildMessage.automatically") |
| 55 | + : ""} |
| 56 | + <strong>{t(`buildMessage.${build.transition}`)}</strong>{" "} |
| 57 | + {t("buildMessage.theWorkspace")} |
| 58 | + </span> |
| 59 | + |
| 60 | + <span className={styles.buildTime}> |
| 61 | + {new Date(build.created_at).toLocaleTimeString()} |
| 62 | + </span> |
| 63 | + </Stack> |
| 64 | + |
| 65 | + <Stack direction="row" spacing={1}> |
| 66 | + <span className={styles.buildInfo}> |
| 67 | + {t("buildData.reason")}: <strong>{build.reason}</strong> |
| 68 | + </span> |
| 69 | + |
| 70 | + <span className={styles.buildInfo}> |
| 71 | + {t("buildData.duration")}:{" "} |
| 72 | + <strong>{displayWorkspaceBuildDuration(build)}</strong> |
| 73 | + </span> |
| 74 | + </Stack> |
| 75 | + </div> |
| 76 | + </Stack> |
| 77 | + </Stack> |
| 78 | + </TableCell> |
| 79 | + </TableRow> |
| 80 | + ) |
| 81 | +} |
| 82 | + |
| 83 | +const useStyles = makeStyles((theme) => ({ |
| 84 | + buildRow: { |
| 85 | + cursor: "pointer", |
| 86 | + |
| 87 | + "&:focus": { |
| 88 | + outlineStyle: "solid", |
| 89 | + outlineOffset: -1, |
| 90 | + outlineWidth: 2, |
| 91 | + outlineColor: theme.palette.secondary.dark, |
| 92 | + }, |
| 93 | + |
| 94 | + "&:not(:last-child) td:before": { |
| 95 | + position: "absolute", |
| 96 | + top: 20, |
| 97 | + left: 50, |
| 98 | + display: "block", |
| 99 | + content: "''", |
| 100 | + height: "100%", |
| 101 | + width: 2, |
| 102 | + background: theme.palette.divider, |
| 103 | + }, |
| 104 | + }, |
| 105 | + |
| 106 | + buildWrapper: { |
| 107 | + padding: theme.spacing(2, 4), |
| 108 | + }, |
| 109 | + |
| 110 | + buildCell: { |
| 111 | + padding: "0 !important", |
| 112 | + position: "relative", |
| 113 | + borderBottom: 0, |
| 114 | + }, |
| 115 | + |
| 116 | + buildResume: { |
| 117 | + ...theme.typography.body1, |
| 118 | + fontFamily: "inherit", |
| 119 | + }, |
| 120 | + |
| 121 | + buildInfo: { |
| 122 | + ...theme.typography.body2, |
| 123 | + fontSize: 12, |
| 124 | + fontFamily: "inherit", |
| 125 | + color: theme.palette.text.secondary, |
| 126 | + display: "block", |
| 127 | + }, |
| 128 | + |
| 129 | + buildTime: { |
| 130 | + color: theme.palette.text.secondary, |
| 131 | + fontSize: 12, |
| 132 | + }, |
| 133 | + |
| 134 | + buildRight: { |
| 135 | + width: "auto", |
| 136 | + }, |
| 137 | + |
| 138 | + buildExtraInfo: { |
| 139 | + ...theme.typography.body2, |
| 140 | + fontFamily: MONOSPACE_FONT_FAMILY, |
| 141 | + color: theme.palette.text.secondary, |
| 142 | + whiteSpace: "nowrap", |
| 143 | + }, |
| 144 | +})) |
0 commit comments