|
1 |
| -import Popover from "@material-ui/core/Popover" |
2 | 1 | import makeStyles from "@material-ui/core/styles/makeStyles"
|
3 | 2 | import { watchAgentMetadata } from "api/api"
|
4 | 3 | import { WorkspaceAgent, WorkspaceAgentMetadata } from "api/typesGenerated"
|
5 | 4 | import { Stack } from "components/Stack/Stack"
|
6 |
| -import { |
7 |
| - HelpTooltipText, |
8 |
| - HelpTooltipTitle, |
9 |
| -} from "components/Tooltips/HelpTooltip" |
10 | 5 | import dayjs from "dayjs"
|
11 |
| -import { |
12 |
| - createContext, |
13 |
| - FC, |
14 |
| - PropsWithChildren, |
15 |
| - useContext, |
16 |
| - useEffect, |
17 |
| - useRef, |
18 |
| - useState, |
19 |
| -} from "react" |
20 |
| -import { humanDuration } from "utils/duration" |
| 6 | +import { createContext, FC, useContext, useEffect, useState } from "react" |
21 | 7 | import { Skeleton } from "@material-ui/lab"
|
22 | 8 | import { MONOSPACE_FONT_FAMILY } from "theme/constants"
|
23 | 9 |
|
24 | 10 | type ItemStatus = "stale" | "valid" | "loading"
|
25 | 11 |
|
26 | 12 | export const WatchAgentMetadataContext = createContext(watchAgentMetadata)
|
27 | 13 |
|
28 |
| -const MetadataItemValue: FC< |
29 |
| - PropsWithChildren<{ item: WorkspaceAgentMetadata; status: ItemStatus }> |
30 |
| -> = ({ item, children, status }) => { |
31 |
| - const [isOpen, setIsOpen] = useState(false) |
32 |
| - const anchorRef = useRef<HTMLDivElement>(null) |
33 |
| - const styles = useStyles() |
34 |
| - const updatesInSeconds = -(item.description.interval - item.result.age) |
35 |
| - |
36 |
| - return ( |
37 |
| - <> |
38 |
| - <div |
39 |
| - ref={anchorRef} |
40 |
| - onMouseEnter={() => setIsOpen(true)} |
41 |
| - role="presentation" |
42 |
| - > |
43 |
| - {children} |
44 |
| - </div> |
45 |
| - |
46 |
| - <Popover |
47 |
| - anchorOrigin={{ |
48 |
| - vertical: "bottom", |
49 |
| - horizontal: "left", |
50 |
| - }} |
51 |
| - transformOrigin={{ |
52 |
| - vertical: "top", |
53 |
| - horizontal: "left", |
54 |
| - }} |
55 |
| - open={isOpen} |
56 |
| - anchorEl={anchorRef.current} |
57 |
| - onClose={() => setIsOpen(false)} |
58 |
| - PaperProps={{ |
59 |
| - onMouseEnter: () => setIsOpen(true), |
60 |
| - onMouseLeave: () => setIsOpen(false), |
61 |
| - }} |
62 |
| - classes={{ paper: styles.metadataPopover }} |
63 |
| - > |
64 |
| - {item.result.error.length > 0 ? ( |
65 |
| - <> |
66 |
| - <div className={styles.metadataPopoverContent}> |
67 |
| - <HelpTooltipTitle> |
68 |
| - {item.description.display_name} |
69 |
| - </HelpTooltipTitle> |
70 |
| - <HelpTooltipText> |
71 |
| - An error happened while executing the command{" "} |
72 |
| - <pre className={styles.inlineCommand}> |
73 |
| - `{item.description.script}` |
74 |
| - </pre> |
75 |
| - </HelpTooltipText> |
76 |
| - </div> |
77 |
| - <div className={styles.metadataPopoverCode}> |
78 |
| - <pre>{item.result.error}</pre> |
79 |
| - </div> |
80 |
| - </> |
81 |
| - ) : ( |
82 |
| - <> |
83 |
| - <div className={styles.metadataPopoverContent}> |
84 |
| - <HelpTooltipTitle> |
85 |
| - {item.description.display_name} |
86 |
| - </HelpTooltipTitle> |
87 |
| - {status === "stale" ? ( |
88 |
| - <HelpTooltipText> |
89 |
| - This item is now stale because the agent hasn{"'"}t reported a |
90 |
| - new value in {humanDuration(item.result.age, "s")}. |
91 |
| - </HelpTooltipText> |
92 |
| - ) : ( |
93 |
| - <></> |
94 |
| - )} |
95 |
| - {status === "valid" ? ( |
96 |
| - <HelpTooltipText> |
97 |
| - The agent collected this value{" "} |
98 |
| - {humanDuration(item.result.age, "s")} ago and will update it |
99 |
| - in {humanDuration(Math.min(updatesInSeconds, 0), "s")}. |
100 |
| - </HelpTooltipText> |
101 |
| - ) : ( |
102 |
| - <></> |
103 |
| - )} |
104 |
| - {status === "loading" ? ( |
105 |
| - <HelpTooltipText> |
106 |
| - This value is loading for the first time... |
107 |
| - </HelpTooltipText> |
108 |
| - ) : ( |
109 |
| - <></> |
110 |
| - )} |
111 |
| - </div> |
112 |
| - <div className={styles.metadataPopoverCode}> |
113 |
| - <pre>{item.description.script}</pre> |
114 |
| - </div> |
115 |
| - </> |
116 |
| - )} |
117 |
| - </Popover> |
118 |
| - </> |
119 |
| - ) |
120 |
| -} |
121 |
| - |
122 | 14 | const MetadataItem: FC<{ item: WorkspaceAgentMetadata }> = ({ item }) => {
|
123 | 15 | const styles = useStyles()
|
124 | 16 |
|
@@ -172,12 +64,10 @@ const MetadataItem: FC<{ item: WorkspaceAgentMetadata }> = ({ item }) => {
|
172 | 64 |
|
173 | 65 | return (
|
174 | 66 | <div className={styles.metadata}>
|
175 |
| - <div className={styles.metadataLabel} role="presentation"> |
| 67 | + <div className={styles.metadataLabel}> |
176 | 68 | {item.description.display_name}
|
177 | 69 | </div>
|
178 |
| - <MetadataItemValue item={item} status={status}> |
179 |
| - {value} |
180 |
| - </MetadataItemValue> |
| 70 | + <div>{value}</div> |
181 | 71 | </div>
|
182 | 72 | )
|
183 | 73 | }
|
@@ -307,41 +197,6 @@ const useStyles = makeStyles((theme) => ({
|
307 | 197 | color: theme.palette.error.main,
|
308 | 198 | },
|
309 | 199 |
|
310 |
| - metadataPopover: { |
311 |
| - marginTop: theme.spacing(0.5), |
312 |
| - |
313 |
| - color: theme.palette.text.secondary, |
314 |
| - pointerEvents: "auto", |
315 |
| - width: "320px", |
316 |
| - borderRadius: 4, |
317 |
| - |
318 |
| - "& .MuiButton-root": { |
319 |
| - padding: theme.spacing(1, 2), |
320 |
| - borderRadius: 0, |
321 |
| - border: 0, |
322 |
| - |
323 |
| - "&:hover": { |
324 |
| - background: theme.palette.action.hover, |
325 |
| - }, |
326 |
| - }, |
327 |
| - }, |
328 |
| - |
329 |
| - metadataPopoverContent: { |
330 |
| - padding: theme.spacing(2.5), |
331 |
| - }, |
332 |
| - |
333 |
| - metadataPopoverCode: { |
334 |
| - padding: theme.spacing(2.5), |
335 |
| - fontFamily: MONOSPACE_FONT_FAMILY, |
336 |
| - background: theme.palette.background.default, |
337 |
| - color: theme.palette.text.primary, |
338 |
| - |
339 |
| - "& pre": { |
340 |
| - padding: 0, |
341 |
| - margin: 0, |
342 |
| - }, |
343 |
| - }, |
344 |
| - |
345 | 200 | skeleton: {
|
346 | 201 | marginTop: theme.spacing(0.5),
|
347 | 202 | },
|
|
0 commit comments