Skip to content

fix: reduce spacing when agent metadata doesn't exist #6937

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 5 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add stories!
  • Loading branch information
ammario committed Mar 31, 2023
commit 568641f120e81da18fc1e4777d44bd4b8ad22b0b
9 changes: 7 additions & 2 deletions site/src/components/Resources/AgentMetadata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,19 @@ export const AgentMetadataView: FC<AgentMetadataViewProps> = ({ metadata }) => {

export const AgentMetadata: FC<{
agent: WorkspaceAgent
}> = ({ agent }) => {
storybookMetadata?: WorkspaceAgentMetadata[]
}> = ({ agent, storybookMetadata }) => {
const [metadata, setMetadata] = useState<
WorkspaceAgentMetadata[] | undefined
>(undefined)

const watchAgentMetadata = useContext(WatchAgentMetadataContext)

useEffect(() => {
if (storybookMetadata !== undefined) {
setMetadata(storybookMetadata)
return
}
const source = watchAgentMetadata(agent.id)

source.onerror = (e) => {
Expand All @@ -248,7 +253,7 @@ export const AgentMetadata: FC<{
return () => {
source.close()
}
}, [agent.id, watchAgentMetadata])
}, [agent.id, watchAgentMetadata, storybookMetadata])

if (metadata === undefined) {
return (
Expand Down
87 changes: 41 additions & 46 deletions site/src/components/Resources/AgentRow.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,48 @@ export default {

const Template: Story<AgentRowProps> = (args) => <AgentRow {...args} />

const defaultAgentMetadata = [
{
result: {
collected_at: "2021-05-05T00:00:00Z",
error: "",
value: "defvalue",
age: 5,
},
description: {
display_name: "DisPlay",
key: "defkey",
interval: 10,
timeout: 10,
script: "some command",
},
},
]

export const Example = Template.bind({})
Example.args = {
agent: MockWorkspaceAgent,
workspace: MockWorkspace,
applicationsHost: "",
showApps: true,
storybookAgentMetadata: defaultAgentMetadata,
}

export const HideSSHButton = Template.bind({})
HideSSHButton.args = {
agent: MockWorkspaceAgent,
workspace: MockWorkspace,
applicationsHost: "",
showApps: true,
...Example.args,
hideSSHButton: true,
}

export const HideVSCodeDesktopButton = Template.bind({})
HideVSCodeDesktopButton.args = {
agent: MockWorkspaceAgent,
workspace: MockWorkspace,
applicationsHost: "",
showApps: true,
...Example.args,
hideVSCodeDesktopButton: true,
}

export const NotShowingApps = Template.bind({})
NotShowingApps.args = {
agent: MockWorkspaceAgent,
workspace: MockWorkspace,
applicationsHost: "",
...Example.args,
showApps: false,
}

Expand All @@ -81,26 +92,21 @@ BunchOfApps.args = {

export const Connecting = Template.bind({})
Connecting.args = {
...Example.args,
agent: MockWorkspaceAgentConnecting,
workspace: MockWorkspace,
applicationsHost: "",
showApps: true,
storybookAgentMetadata: [],
}

export const Timeout = Template.bind({})
Timeout.args = {
...Example.args,
agent: MockWorkspaceAgentTimeout,
workspace: MockWorkspace,
applicationsHost: "",
showApps: true,
}

export const Starting = Template.bind({})
Starting.args = {
...Example.args,
agent: MockWorkspaceAgentStarting,
workspace: MockWorkspace,
applicationsHost: "",
showApps: true,

storybookStartupLogs: [
"Cloning Git repository...",
Expand All @@ -117,13 +123,11 @@ Starting.args = {

export const Started = Template.bind({})
Started.args = {
...Example.args,
agent: {
...MockWorkspaceAgentReady,
startup_logs_length: 1,
},
workspace: MockWorkspace,
applicationsHost: "",
showApps: true,

storybookStartupLogs: [
"Cloning Git repository...",
Expand All @@ -138,67 +142,58 @@ Started.args = {
})),
}

export const StartedNoMetadata = Template.bind({})
StartedNoMetadata.args = {
...Started.args,
storybookAgentMetadata: [],
}

export const StartTimeout = Template.bind({})
StartTimeout.args = {
...Example.args,
agent: MockWorkspaceAgentStartTimeout,
workspace: MockWorkspace,
applicationsHost: "",
showApps: true,
}

export const StartError = Template.bind({})
StartError.args = {
...Example.args,
agent: MockWorkspaceAgentStartError,
workspace: MockWorkspace,
applicationsHost: "",
showApps: true,
}

export const ShuttingDown = Template.bind({})
ShuttingDown.args = {
...Example.args,
agent: MockWorkspaceAgentShuttingDown,
workspace: MockWorkspace,
applicationsHost: "",
showApps: true,
}

export const ShutdownTimeout = Template.bind({})
ShutdownTimeout.args = {
...Example.args,
agent: MockWorkspaceAgentShutdownTimeout,
workspace: MockWorkspace,
applicationsHost: "",
showApps: true,
}

export const ShutdownError = Template.bind({})
ShutdownError.args = {
...Example.args,
agent: MockWorkspaceAgentShutdownError,
workspace: MockWorkspace,
applicationsHost: "",
showApps: true,
}

export const Off = Template.bind({})
Off.args = {
...Example.args,
agent: MockWorkspaceAgentOff,
workspace: MockWorkspace,
applicationsHost: "",
showApps: true,
}

export const ShowingPortForward = Template.bind({})
ShowingPortForward.args = {
agent: MockWorkspaceAgent,
workspace: MockWorkspace,
...Example.args,
applicationsHost: "https://coder.com",
showApps: true,
}

export const Outdated = Template.bind({})
Outdated.args = {
...Example.args,
agent: MockWorkspaceAgentOutdated,
workspace: MockWorkspace,
applicationsHost: "",
showApps: true,
serverVersion: "v99.999.9999+c1cdf14",
}
14 changes: 12 additions & 2 deletions site/src/components/Resources/AgentRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ import {
LineWithID,
workspaceAgentLogsMachine,
} from "xServices/workspaceAgentLogs/workspaceAgentLogsXService"
import { Workspace, WorkspaceAgent } from "../../api/typesGenerated"
import {
Workspace,
WorkspaceAgent,
WorkspaceAgentMetadata,
WorkspaceAgentMetadataDescription,
} from "../../api/typesGenerated"
import { AppLink } from "../AppLink/AppLink"
import { SSHButton } from "../SSHButton/SSHButton"
import { Stack } from "../Stack/Stack"
Expand All @@ -51,6 +56,7 @@ export interface AgentRowProps {
onUpdateAgent: () => void

storybookStartupLogs?: LineWithID[]
storybookAgentMetadata?: WorkspaceAgentMetadata[]
}

export const AgentRow: FC<AgentRowProps> = ({
Expand All @@ -63,6 +69,7 @@ export const AgentRow: FC<AgentRowProps> = ({
serverVersion,
onUpdateAgent,
storybookStartupLogs,
storybookAgentMetadata,
sshPrefix,
}) => {
const styles = useStyles()
Expand Down Expand Up @@ -287,7 +294,10 @@ export const AgentRow: FC<AgentRowProps> = ({
)}
</Stack>
</Stack>
<AgentMetadata agent={agent} />
<AgentMetadata
storybookMetadata={storybookAgentMetadata}
agent={agent}
/>
{hasStartupFeatures && (
<Stack
direction="row"
Expand Down