Skip to content

Commit 97bcd44

Browse files
refactor: Improve agent loading state (coder#4814)
1 parent dde9a43 commit 97bcd44

File tree

7 files changed

+55
-10
lines changed

7 files changed

+55
-10
lines changed

site/src/components/AppLink/AppLink.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export const AppLink: FC<AppLinkProps> = ({
6161
let primaryTooltip = ""
6262
if (app.health === "initializing") {
6363
canClick = false
64-
icon = <CircularProgress size={16} />
64+
icon = <CircularProgress size={12} />
6565
primaryTooltip = "Initializing..."
6666
}
6767
if (app.health === "unhealthy") {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { makeStyles } from "@material-ui/core/styles"
2+
import { Skeleton } from "@material-ui/lab"
3+
import React from "react"
4+
import { borderRadiusSm } from "theme/constants"
5+
6+
export const AppLinkSkeleton: React.FC<{ width: number }> = ({ width }) => {
7+
const styles = useStyles()
8+
return (
9+
<Skeleton
10+
width={width}
11+
height={36}
12+
variant="rect"
13+
className={styles.skeleton}
14+
/>
15+
)
16+
}
17+
18+
export const useStyles = makeStyles(() => ({
19+
skeleton: {
20+
borderRadius: borderRadiusSm,
21+
},
22+
}))

site/src/components/Resources/AgentRow.stories.tsx

+9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Story } from "@storybook/react"
22
import {
33
MockWorkspace,
44
MockWorkspaceAgent,
5+
MockWorkspaceAgentConnecting,
56
MockWorkspaceApp,
67
} from "testHelpers/entities"
78
import { AgentRow, AgentRowProps } from "./AgentRow"
@@ -58,3 +59,11 @@ BunchOfApps.args = {
5859
applicationsHost: "",
5960
showApps: true,
6061
}
62+
63+
export const Connecting = Template.bind({})
64+
Connecting.args = {
65+
agent: MockWorkspaceAgentConnecting,
66+
workspace: MockWorkspace,
67+
applicationsHost: "",
68+
showApps: true,
69+
}

site/src/components/Resources/AgentRow.tsx

+8-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { AgentLatency } from "./AgentLatency"
1111
import { AgentVersion } from "./AgentVersion"
1212
import { Maybe } from "components/Conditionals/Maybe"
1313
import { AgentStatus } from "./AgentStatus"
14+
import { AppLinkSkeleton } from "components/AppLink/AppLinkSkeleton"
1415

1516
export interface AgentRowProps {
1617
agent: WorkspaceAgent
@@ -59,6 +60,11 @@ export const AgentRow: FC<AgentRowProps> = ({
5960
</Maybe>
6061

6162
<AgentLatency agent={agent} />
63+
64+
<Maybe condition={agent.status === "connecting"}>
65+
<Skeleton width={160} variant="text" />
66+
<Skeleton width={36} variant="text" />
67+
</Maybe>
6268
</Stack>
6369
</div>
6470
</Stack>
@@ -106,8 +112,8 @@ export const AgentRow: FC<AgentRowProps> = ({
106112
)}
107113
{showApps && agent.status === "connecting" && (
108114
<>
109-
<Skeleton width={80} height={36} variant="rect" />
110-
<Skeleton width={120} height={36} variant="rect" />
115+
<AppLinkSkeleton width={84} />
116+
<AppLinkSkeleton width={112} />
111117
</>
112118
)}
113119
</Stack>

site/src/components/Resources/AgentStatus.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,18 @@ const useStyles = makeStyles((theme) => ({
8484

8585
"@keyframes pulse": {
8686
"0%": {
87-
opacity: 0.25,
87+
opacity: 1,
8888
},
8989
"50%": {
90-
opacity: 1,
90+
opacity: 0.4,
9191
},
9292
"100%": {
93-
opacity: 0.25,
93+
opacity: 1,
9494
},
9595
},
9696

9797
connecting: {
9898
backgroundColor: theme.palette.info.light,
99-
animation: "$pulse 1s ease-in-out forwards infinite",
99+
animation: "$pulse 1.5s 0.5s ease-in-out forwards infinite",
100100
},
101101
}))

site/src/theme/constants.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export const spacing = 8
22
export const borderRadius = 8
3+
export const borderRadiusSm = 6
34
export const buttonBorderWidth = 2
45
export const MONOSPACE_FONT_FAMILY =
56
"'IBM Plex Mono', 'Lucida Console', 'Lucida Sans Typewriter', 'Liberation Mono', 'Monaco', 'Courier New', Courier, monospace"

site/src/theme/overrides.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { lighten, Theme } from "@material-ui/core/styles"
22
import { Overrides } from "@material-ui/core/styles/overrides"
33
import { colors } from "./colors"
4-
import { borderRadius } from "./constants"
4+
import { borderRadius, borderRadiusSm } from "./constants"
55

66
export const getOverrides = ({ palette, breakpoints }: Theme): Overrides => {
77
return {
@@ -61,15 +61,15 @@ export const getOverrides = ({ palette, breakpoints }: Theme): Overrides => {
6161
padding: `0 16px`,
6262
fontSize: 14,
6363
minHeight: 36,
64-
borderRadius: 6,
64+
borderRadius: borderRadiusSm,
6565
},
6666
iconSizeSmall: {
6767
width: 14,
6868
height: 14,
6969
marginLeft: "0 !important",
7070
marginRight: 8,
7171

72-
"& svg": {
72+
"& svg:not(.MuiCircularProgress-svg)": {
7373
width: 14,
7474
height: 14,
7575
},
@@ -190,5 +190,12 @@ export const getOverrides = ({ palette, breakpoints }: Theme): Overrides => {
190190
marginTop: 8,
191191
},
192192
},
193+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment -- The Mui types don't accept the MuiSkeleton but it works. I tried to extends the Overrides interface with no success.
194+
// @ts-ignore
195+
MuiSkeleton: {
196+
root: {
197+
backgroundColor: palette.divider,
198+
},
199+
},
193200
}
194201
}

0 commit comments

Comments
 (0)