|
| 1 | +import { useTheme } from "@emotion/react"; |
| 2 | +import Business from "@mui/icons-material/Business"; |
| 3 | +import Person from "@mui/icons-material/Person"; |
| 4 | +import Tooltip from "@mui/material/Tooltip"; |
| 5 | +import type { HealthMessage, ProvisionerDaemon } from "api/typesGenerated"; |
| 6 | +import { Pill } from "components/Pill/Pill"; |
| 7 | +import type { FC } from "react"; |
| 8 | +import { createDayString } from "utils/createDayString"; |
| 9 | +import { ProvisionerTag } from "./ProvisionerTag"; |
| 10 | + |
| 11 | +interface ProvisionerProps { |
| 12 | + readonly provisioner: ProvisionerDaemon; |
| 13 | + readonly warnings?: readonly HealthMessage[]; |
| 14 | +} |
| 15 | + |
| 16 | +export const Provisioner: FC<ProvisionerProps> = ({ |
| 17 | + provisioner, |
| 18 | + warnings, |
| 19 | +}) => { |
| 20 | + const theme = useTheme(); |
| 21 | + const daemonScope = provisioner.tags.scope || "organization"; |
| 22 | + const iconScope = daemonScope === "organization" ? <Business /> : <Person />; |
| 23 | + |
| 24 | + const extraTags = Object.entries(provisioner.tags).filter( |
| 25 | + ([key]) => key !== "scope" && key !== "owner", |
| 26 | + ); |
| 27 | + const isWarning = warnings && warnings.length > 0; |
| 28 | + return ( |
| 29 | + <div |
| 30 | + key={provisioner.name} |
| 31 | + css={[ |
| 32 | + { |
| 33 | + borderRadius: 8, |
| 34 | + border: `1px solid ${theme.palette.divider}`, |
| 35 | + fontSize: 14, |
| 36 | + }, |
| 37 | + isWarning && { borderColor: theme.palette.warning.light }, |
| 38 | + ]} |
| 39 | + > |
| 40 | + <header |
| 41 | + css={{ |
| 42 | + padding: 24, |
| 43 | + display: "flex", |
| 44 | + alignItems: "center", |
| 45 | + justifyContenxt: "space-between", |
| 46 | + gap: 24, |
| 47 | + }} |
| 48 | + > |
| 49 | + <div |
| 50 | + css={{ |
| 51 | + display: "flex", |
| 52 | + alignItems: "center", |
| 53 | + gap: 24, |
| 54 | + objectFit: "fill", |
| 55 | + }} |
| 56 | + > |
| 57 | + <div css={{ lineHeight: "160%" }}> |
| 58 | + <h4 css={{ fontWeight: 500, margin: 0 }}>{provisioner.name}</h4> |
| 59 | + <span css={{ color: theme.palette.text.secondary }}> |
| 60 | + <code>{provisioner.version}</code> |
| 61 | + </span> |
| 62 | + </div> |
| 63 | + </div> |
| 64 | + <div |
| 65 | + css={{ |
| 66 | + marginLeft: "auto", |
| 67 | + display: "flex", |
| 68 | + flexWrap: "wrap", |
| 69 | + gap: 12, |
| 70 | + }} |
| 71 | + > |
| 72 | + <Tooltip title="Scope"> |
| 73 | + <Pill size="lg" icon={iconScope}> |
| 74 | + <span |
| 75 | + css={{ |
| 76 | + ":first-letter": { textTransform: "uppercase" }, |
| 77 | + }} |
| 78 | + > |
| 79 | + {daemonScope} |
| 80 | + </span> |
| 81 | + </Pill> |
| 82 | + </Tooltip> |
| 83 | + {extraTags.map(([key, value]) => ( |
| 84 | + <ProvisionerTag key={key} tagName={key} tagValue={value} /> |
| 85 | + ))} |
| 86 | + </div> |
| 87 | + </header> |
| 88 | + |
| 89 | + <div |
| 90 | + css={{ |
| 91 | + borderTop: `1px solid ${theme.palette.divider}`, |
| 92 | + display: "flex", |
| 93 | + alignItems: "center", |
| 94 | + justifyContent: "space-between", |
| 95 | + padding: "8px 24px", |
| 96 | + fontSize: 12, |
| 97 | + color: theme.palette.text.secondary, |
| 98 | + }} |
| 99 | + > |
| 100 | + {warnings && warnings.length > 0 ? ( |
| 101 | + <div css={{ display: "flex", flexDirection: "column" }}> |
| 102 | + {warnings.map((warning) => ( |
| 103 | + <span key={warning.code}>{warning.message}</span> |
| 104 | + ))} |
| 105 | + </div> |
| 106 | + ) : ( |
| 107 | + <span>No warnings</span> |
| 108 | + )} |
| 109 | + {provisioner.last_seen_at && ( |
| 110 | + <span css={{ color: theme.roles.info.text }} data-chromatic="ignore"> |
| 111 | + Last seen {createDayString(provisioner.last_seen_at)} |
| 112 | + </span> |
| 113 | + )} |
| 114 | + </div> |
| 115 | + </div> |
| 116 | + ); |
| 117 | +}; |
0 commit comments