Skip to content

refactor(site): Add more info on agent outdated tooltip and update action #5967

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 3 commits into from
Feb 2, 2023
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
10 changes: 10 additions & 0 deletions site/src/components/Resources/AgentRow.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
MockWorkspace,
MockWorkspaceAgent,
MockWorkspaceAgentConnecting,
MockWorkspaceAgentOutdated,
MockWorkspaceAgentStartError,
MockWorkspaceAgentStarting,
MockWorkspaceAgentStartTimeout,
Expand Down Expand Up @@ -120,3 +121,12 @@ ShowingPortForward.args = {
applicationsHost: "https://coder.com",
showApps: true,
}

export const Outdated = Template.bind({})
Outdated.args = {
agent: MockWorkspaceAgentOutdated,
workspace: MockWorkspace,
applicationsHost: "",
showApps: true,
serverVersion: "v99.999.9999+c1cdf14",
}
8 changes: 7 additions & 1 deletion site/src/components/Resources/AgentRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface AgentRowProps {
hideSSHButton?: boolean
hideVSCodeDesktopButton?: boolean
serverVersion: string
onUpdateAgent: () => void
}

export const AgentRow: FC<AgentRowProps> = ({
Expand All @@ -33,6 +34,7 @@ export const AgentRow: FC<AgentRowProps> = ({
hideSSHButton,
hideVSCodeDesktopButton,
serverVersion,
onUpdateAgent,
}) => {
const styles = useStyles()
const { t } = useTranslation("agent")
Expand Down Expand Up @@ -61,7 +63,11 @@ export const AgentRow: FC<AgentRowProps> = ({
<span className={styles.agentOS}>{agent.operating_system}</span>

<Maybe condition={agent.status === "connected"}>
<AgentVersion agent={agent} serverVersion={serverVersion} />
<AgentVersion
agent={agent}
serverVersion={serverVersion}
onUpdate={onUpdateAgent}
/>
</Maybe>

<AgentLatency agent={agent} />
Expand Down
23 changes: 8 additions & 15 deletions site/src/components/Resources/AgentVersion.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { useRef, useState, FC } from "react"
import { makeStyles } from "@material-ui/core/styles"
import {
HelpTooltipText,
HelpPopover,
HelpTooltipTitle,
} from "components/Tooltips/HelpTooltip"
import { WorkspaceAgent } from "api/typesGenerated"
import { getDisplayVersionStatus } from "util/workspace"
import { AgentOutdatedTooltip } from "components/Tooltips/AgentOutdatedTooltip"

export const AgentVersion: FC<{
agent: WorkspaceAgent
serverVersion: string
}> = ({ agent, serverVersion }) => {
onUpdate: () => void
}> = ({ agent, serverVersion, onUpdate }) => {
const styles = useStyles()
const anchorRef = useRef<HTMLButtonElement>(null)
const [isOpen, setIsOpen] = useState(false)
Expand All @@ -37,20 +34,16 @@ export const AgentVersion: FC<{
>
Agent Outdated
</span>
<HelpPopover
<AgentOutdatedTooltip
id={id}
open={isOpen}
anchorEl={anchorRef.current}
onOpen={() => setIsOpen(true)}
onClose={() => setIsOpen(false)}
>
<HelpTooltipTitle>Agent Outdated</HelpTooltipTitle>
<HelpTooltipText>
This agent is an older version than the Coder server. This can happen
after you update Coder with running workspaces. To fix this, you can
stop and start the workspace.
</HelpTooltipText>
</HelpPopover>
agent={agent}
serverVersion={serverVersion}
onUpdate={onUpdate}
/>
</>
)
}
Expand Down
3 changes: 3 additions & 0 deletions site/src/components/Resources/ResourceCard.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { action } from "@storybook/addon-actions"
import { Story } from "@storybook/react"
import { MockWorkspace, MockWorkspaceResource } from "testHelpers/entities"
import { AgentRow } from "./AgentRow"
Expand All @@ -21,6 +22,7 @@ Example.args = {
workspace={MockWorkspace}
applicationsHost=""
serverVersion=""
onUpdateAgent={action("updateAgent")}
/>
),
}
Expand Down Expand Up @@ -75,6 +77,7 @@ BunchOfMetadata.args = {
workspace={MockWorkspace}
applicationsHost=""
serverVersion=""
onUpdateAgent={action("updateAgent")}
/>
),
}
88 changes: 88 additions & 0 deletions site/src/components/Tooltips/AgentOutdatedTooltip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { ComponentProps, FC } from "react"
import { makeStyles } from "@material-ui/core/styles"
import RefreshIcon from "@material-ui/icons/RefreshOutlined"
import {
HelpTooltipText,
HelpPopover,
HelpTooltipTitle,
HelpTooltipAction,
HelpTooltipLinksGroup,
HelpTooltipContext,
} from "components/Tooltips/HelpTooltip"
import { WorkspaceAgent } from "api/typesGenerated"
import { Stack } from "components/Stack/Stack"
import { useTranslation } from "react-i18next"

type AgentOutdatedTooltipProps = ComponentProps<typeof HelpPopover> & {
agent: WorkspaceAgent
serverVersion: string
onUpdate: () => void
}

export const AgentOutdatedTooltip: FC<AgentOutdatedTooltipProps> = ({
agent,
serverVersion,
onUpdate,
onOpen,
id,
open,
onClose,
anchorEl,
}) => {
const styles = useStyles()
const { t } = useTranslation("workspacePage")

return (
<HelpPopover
id={id}
open={open}
anchorEl={anchorEl}
onOpen={onOpen}
onClose={onClose}
>
<HelpTooltipContext.Provider value={{ open, onClose }}>
<Stack spacing={1}>
<div>
<HelpTooltipTitle>
{t("agentOutdatedTooltip.title")}
</HelpTooltipTitle>
<HelpTooltipText>
{t("agentOutdatedTooltip.description")}
</HelpTooltipText>
</div>

<Stack spacing={0.5}>
<span className={styles.versionLabel}>
{t("agentOutdatedTooltip.agentVersionLabel")}
</span>
<span>{agent.version}</span>
</Stack>

<Stack spacing={0.5}>
<span className={styles.versionLabel}>
{t("agentOutdatedTooltip.serverVersionLabel")}
</span>
<span>{serverVersion}</span>
</Stack>

<HelpTooltipLinksGroup>
<HelpTooltipAction
icon={RefreshIcon}
onClick={onUpdate}
ariaLabel="Update workspace"
>
{t("agentOutdatedTooltip.updateWorkspaceLabel")}
</HelpTooltipAction>
</HelpTooltipLinksGroup>
</Stack>
</HelpTooltipContext.Provider>
</HelpPopover>
)
}

const useStyles = makeStyles((theme) => ({
versionLabel: {
fontWeight: 600,
color: theme.palette.text.primary,
},
}))
2 changes: 1 addition & 1 deletion site/src/components/Tooltips/HelpTooltip/HelpTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const Language = {
ariaLabel: "tooltip",
}

const HelpTooltipContext = createContext<
export const HelpTooltipContext = createContext<
{ open: boolean; onClose: () => void } | undefined
>(undefined)

Expand Down
1 change: 1 addition & 0 deletions site/src/components/Workspace/Workspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
hideSSHButton={hideSSHButton}
hideVSCodeDesktopButton={hideVSCodeDesktopButton}
serverVersion={serverVersion}
onUpdateAgent={handleUpdate} // On updating the workspace the agent version is also updated
/>
)}
/>
Expand Down
7 changes: 7 additions & 0 deletions site/src/i18n/en/workspacePage.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,12 @@
"reason": "Reason",
"duration": "Duration",
"version": "Version"
},
"agentOutdatedTooltip": {
"title": "Agent Outdated",
"description": "This agent is an older version than the Coder server. This can happen after you update Coder with running workspaces. To fix this, you can stop and start the workspace.",
"agentVersionLabel": "Agent version",
"serverVersionLabel": "Server version",
"updateWorkspaceLabel": "Update workspace"
}
}