Skip to content

refactor: Improve agent loading state #4814

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion site/src/components/AppLink/AppLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const AppLink: FC<AppLinkProps> = ({
let primaryTooltip = ""
if (app.health === "initializing") {
canClick = false
icon = <CircularProgress size={16} />
icon = <CircularProgress size={12} />
primaryTooltip = "Initializing..."
}
if (app.health === "unhealthy") {
Expand Down
22 changes: 22 additions & 0 deletions site/src/components/AppLink/AppLinkSkeleton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { makeStyles } from "@material-ui/core/styles"
import { Skeleton } from "@material-ui/lab"
import React from "react"
import { borderRadiusSm } from "theme/constants"

export const AppLinkSkeleton: React.FC<{ width: number }> = ({ width }) => {
const styles = useStyles()
return (
<Skeleton
width={width}
height={36}
variant="rect"
className={styles.skeleton}
/>
)
}

export const useStyles = makeStyles(() => ({
skeleton: {
borderRadius: borderRadiusSm,
},
}))
9 changes: 9 additions & 0 deletions site/src/components/Resources/AgentRow.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Story } from "@storybook/react"
import {
MockWorkspace,
MockWorkspaceAgent,
MockWorkspaceAgentConnecting,
MockWorkspaceApp,
} from "testHelpers/entities"
import { AgentRow, AgentRowProps } from "./AgentRow"
Expand Down Expand Up @@ -58,3 +59,11 @@ BunchOfApps.args = {
applicationsHost: "",
showApps: true,
}

export const Connecting = Template.bind({})
Connecting.args = {
agent: MockWorkspaceAgentConnecting,
workspace: MockWorkspace,
applicationsHost: "",
showApps: true,
}
10 changes: 8 additions & 2 deletions site/src/components/Resources/AgentRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { AgentLatency } from "./AgentLatency"
import { AgentVersion } from "./AgentVersion"
import { Maybe } from "components/Conditionals/Maybe"
import { AgentStatus } from "./AgentStatus"
import { AppLinkSkeleton } from "components/AppLink/AppLinkSkeleton"

export interface AgentRowProps {
agent: WorkspaceAgent
Expand Down Expand Up @@ -59,6 +60,11 @@ export const AgentRow: FC<AgentRowProps> = ({
</Maybe>

<AgentLatency agent={agent} />

<Maybe condition={agent.status === "connecting"}>
<Skeleton width={160} variant="text" />
<Skeleton width={36} variant="text" />
</Maybe>
</Stack>
</div>
</Stack>
Expand Down Expand Up @@ -106,8 +112,8 @@ export const AgentRow: FC<AgentRowProps> = ({
)}
{showApps && agent.status === "connecting" && (
<>
<Skeleton width={80} height={36} variant="rect" />
<Skeleton width={120} height={36} variant="rect" />
<AppLinkSkeleton width={84} />
<AppLinkSkeleton width={112} />
</>
)}
</Stack>
Expand Down
8 changes: 4 additions & 4 deletions site/src/components/Resources/AgentStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,18 @@ const useStyles = makeStyles((theme) => ({

"@keyframes pulse": {
"0%": {
opacity: 0.25,
opacity: 1,
},
"50%": {
opacity: 1,
opacity: 0.4,
},
"100%": {
opacity: 0.25,
opacity: 1,
},
},

connecting: {
backgroundColor: theme.palette.info.light,
animation: "$pulse 1s ease-in-out forwards infinite",
animation: "$pulse 1.5s 0.5s ease-in-out forwards infinite",
},
}))
1 change: 1 addition & 0 deletions site/src/theme/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export const spacing = 8
export const borderRadius = 8
export const borderRadiusSm = 6
export const buttonBorderWidth = 2
export const MONOSPACE_FONT_FAMILY =
"'IBM Plex Mono', 'Lucida Console', 'Lucida Sans Typewriter', 'Liberation Mono', 'Monaco', 'Courier New', Courier, monospace"
Expand Down
13 changes: 10 additions & 3 deletions site/src/theme/overrides.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { lighten, Theme } from "@material-ui/core/styles"
import { Overrides } from "@material-ui/core/styles/overrides"
import { colors } from "./colors"
import { borderRadius } from "./constants"
import { borderRadius, borderRadiusSm } from "./constants"

export const getOverrides = ({ palette, breakpoints }: Theme): Overrides => {
return {
Expand Down Expand Up @@ -61,15 +61,15 @@ export const getOverrides = ({ palette, breakpoints }: Theme): Overrides => {
padding: `0 16px`,
fontSize: 14,
minHeight: 36,
borderRadius: 6,
borderRadius: borderRadiusSm,
},
iconSizeSmall: {
width: 14,
height: 14,
marginLeft: "0 !important",
marginRight: 8,

"& svg": {
"& svg:not(.MuiCircularProgress-svg)": {
width: 14,
height: 14,
},
Expand Down Expand Up @@ -190,5 +190,12 @@ export const getOverrides = ({ palette, breakpoints }: Theme): Overrides => {
marginTop: 8,
},
},
// 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.
// @ts-ignore
MuiSkeleton: {
root: {
backgroundColor: palette.divider,
},
},
}
}