Skip to content

refactor(site): refactor resource and agents #11647

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 28 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
06c9bef
Refactor resource metadata
BrunoQuaresma Jan 16, 2024
f2346e6
Fix scrolling
BrunoQuaresma Jan 16, 2024
2c58d16
Refactor agent apps
BrunoQuaresma Jan 16, 2024
0a2cb43
Refactor metadata and logs button
BrunoQuaresma Jan 16, 2024
7db1022
Refactor ssh and open port actions
BrunoQuaresma Jan 16, 2024
91fe9f2
Add terminal icon to the terminal button
BrunoQuaresma Jan 16, 2024
0438f3a
Add simple message for agentless resources
BrunoQuaresma Jan 16, 2024
c3411b3
Add back agent status
BrunoQuaresma Jan 16, 2024
bc1a216
Make agent header thiner
BrunoQuaresma Jan 16, 2024
0490e89
rowback the changes on latency color
BrunoQuaresma Jan 16, 2024
e4b2aa1
Remove non apps from preview
BrunoQuaresma Jan 16, 2024
2e542ca
rowback a few decisions
BrunoQuaresma Jan 16, 2024
2b270ec
Solve a few visual issues
BrunoQuaresma Jan 17, 2024
b0f773d
More visual fixes
BrunoQuaresma Jan 17, 2024
295f8f7
Refactor agent buttons and links
BrunoQuaresma Jan 17, 2024
9136c14
Merge branch 'main' of https://github.com/coder/coder into bq/imrefac…
BrunoQuaresma Jan 17, 2024
05fae9c
Fix conflict
BrunoQuaresma Jan 17, 2024
223f36b
Merge branch 'main' of https://github.com/coder/coder into bq/imrefac…
BrunoQuaresma Jan 18, 2024
f55397e
Remove unecessary checks
BrunoQuaresma Jan 18, 2024
f362353
Add agent row visibility test
BrunoQuaresma Jan 18, 2024
def0f70
Improve AppLink code structure
BrunoQuaresma Jan 18, 2024
0dba1cd
Add comment about icons spacing
BrunoQuaresma Jan 18, 2024
21b0c1f
Use right metadata reference
BrunoQuaresma Jan 18, 2024
d663f30
Avoid metadata mutation
BrunoQuaresma Jan 18, 2024
e8c7322
Improve 'p' component name
BrunoQuaresma Jan 18, 2024
90ce45a
Use better var name
BrunoQuaresma Jan 18, 2024
f8e56bc
Remove unecessary word
BrunoQuaresma Jan 18, 2024
5edc204
Improve nesting click handler
BrunoQuaresma Jan 18, 2024
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
Next Next commit
Refactor resource metadata
  • Loading branch information
BrunoQuaresma committed Jan 16, 2024
commit 06c9bef632e204da918a5ea548e8de11e9513918
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"bodyclose",
"buildinfo",
"buildname",
"childrens",
"circbuf",
"cliflag",
"cliui",
Expand Down
39 changes: 19 additions & 20 deletions site/src/components/Resources/AgentRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export const AgentRow: FC<AgentRowProps> = ({
styles[`agentRow-lifecycle-${agent.lifecycle_state}`],
]}
>
<div css={styles.agentInfo}>
<header css={styles.agentInfo}>
<div css={styles.agentNameAndStatus}>
<div css={styles.agentNameAndInfo}>
<AgentStatus agent={agent} />
Expand Down Expand Up @@ -270,7 +270,7 @@ export const AgentRow: FC<AgentRowProps> = ({
/>
</div>
)}
</div>
</header>

<AgentMetadata storybookMetadata={storybookAgentMetadata} agent={agent} />

Expand Down Expand Up @@ -506,61 +506,59 @@ const useAgentLogs = (
const styles = {
agentRow: (theme) => ({
fontSize: 16,
borderLeft: `2px solid ${theme.palette.text.secondary}`,

"&:not(:first-of-type)": {
borderTop: `2px solid ${theme.palette.divider}`,
},
border: `1px solid ${theme.palette.text.secondary}`,
backgroundColor: theme.palette.background.default,
borderRadius: 8,
}),

"agentRow-connected": (theme) => ({
borderLeftColor: theme.palette.success.light,
borderColor: theme.palette.success.light,
}),

"agentRow-disconnected": (theme) => ({
borderLeftColor: theme.palette.text.secondary,
borderColor: theme.palette.text.secondary,
}),

"agentRow-connecting": (theme) => ({
borderLeftColor: theme.palette.info.light,
borderColor: theme.palette.info.light,
}),

"agentRow-timeout": (theme) => ({
borderLeftColor: theme.palette.warning.light,
borderColor: theme.palette.warning.light,
}),

"agentRow-lifecycle-created": {},

"agentRow-lifecycle-starting": (theme) => ({
borderLeftColor: theme.palette.info.light,
borderColor: theme.palette.info.light,
}),

"agentRow-lifecycle-ready": (theme) => ({
borderLeftColor: theme.palette.success.light,
borderColor: theme.palette.success.light,
}),

"agentRow-lifecycle-start_timeout": (theme) => ({
borderLeftColor: theme.palette.warning.light,
borderColor: theme.palette.warning.light,
}),

"agentRow-lifecycle-start_error": (theme) => ({
borderLeftColor: theme.palette.error.light,
borderColor: theme.palette.error.light,
}),

"agentRow-lifecycle-shutting_down": (theme) => ({
borderLeftColor: theme.palette.info.light,
borderColor: theme.palette.info.light,
}),

"agentRow-lifecycle-shutdown_timeout": (theme) => ({
borderLeftColor: theme.palette.warning.light,
borderColor: theme.palette.warning.light,
}),

"agentRow-lifecycle-shutdown_error": (theme) => ({
borderLeftColor: theme.palette.error.light,
borderColor: theme.palette.error.light,
}),

"agentRow-lifecycle-off": (theme) => ({
borderLeftColor: theme.palette.text.secondary,
borderColor: theme.palette.text.secondary,
}),

agentInfo: (theme) => ({
Expand All @@ -570,7 +568,6 @@ const styles = {
alignItems: "center",
justifyContent: "space-between",
flexWrap: "wrap",
backgroundColor: theme.palette.background.paper,

[theme.breakpoints.down("md")]: {
gap: 16,
Expand Down Expand Up @@ -675,6 +672,8 @@ const styles = {
gap: 8,
whiteSpace: "nowrap",
width: "100%",
borderBottomLeftRadius: 8,
borderBottomRightRadius: 8,

"&:hover": {
color: theme.palette.text.primary,
Expand Down
96 changes: 89 additions & 7 deletions site/src/pages/WorkspacePage/Workspace.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type Interpolation, type Theme } from "@emotion/react";
import Button from "@mui/material/Button";
import AlertTitle from "@mui/material/AlertTitle";
import { type FC } from "react";
import { PropsWithChildren, type FC, Children } from "react";
import { useNavigate } from "react-router-dom";
import type * as TypesGen from "api/typesGenerated";
import { Alert, AlertDetail } from "components/Alert/Alert";
Expand All @@ -19,9 +19,11 @@ import { useTheme } from "@mui/material/styles";
import { SidebarIconButton } from "components/FullPageLayout/Sidebar";
import HubOutlined from "@mui/icons-material/HubOutlined";
import { ResourcesSidebar } from "./ResourcesSidebar";
import { ResourceCard } from "components/Resources/ResourceCard";
import { WorkspacePermissions } from "./permissions";
import { resourceOptionValue, useResourcesNav } from "./useResourcesNav";
import { MemoizedInlineMarkdown } from "components/Markdown/Markdown";
import { SensitiveValue } from "components/Resources/SensitiveValue";
import { CopyableValue } from "components/CopyableValue/CopyableValue";

export interface WorkspaceProps {
handleStart: (buildParameters?: TypesGen.WorkspaceBuildParameter[]) => void;
Expand Down Expand Up @@ -182,6 +184,9 @@ export const Workspace: FC<WorkspaceProps> = ({

<div css={styles.content}>
<div css={styles.dotBackground}>
{selectedResource && (
<WorkspaceResourceData resource={selectedResource} />
)}
<div
css={{
display: "flex",
Expand Down Expand Up @@ -229,9 +234,10 @@ export const Workspace: FC<WorkspaceProps> = ({
{buildLogs}

{selectedResource && (
<ResourceCard
resource={selectedResource}
agentRow={(agent) => (
<section
css={{ display: "flex", flexDirection: "column", gap: 24 }}
>
{selectedResource.agents?.map((agent) => (
<AgentRow
key={agent.id}
agent={agent}
Expand All @@ -245,8 +251,8 @@ export const Workspace: FC<WorkspaceProps> = ({
serverAPIVersion={buildInfo?.agent_api_version || ""}
onUpdateAgent={handleUpdate} // On updating the workspace the agent version is also updated
/>
)}
/>
))}
</section>
)}
</div>
</div>
Expand All @@ -255,6 +261,53 @@ export const Workspace: FC<WorkspaceProps> = ({
);
};

const WorkspaceResourceData: FC<{ resource: TypesGen.WorkspaceResource }> = ({
resource,
}) => {
const metadata = resource.metadata ?? [];

if (resource.daily_cost > 0) {
metadata.push({
key: "Daily cost",
value: resource.daily_cost.toString(),
sensitive: false,
});
}

if (metadata.length === 0) {
return null;
}

return (
<header css={styles.resourceData}>
{resource.metadata?.map((meta) => {
return (
<div css={styles.resourceDataItem} key={meta.key}>
<div css={styles.resourceDataItemValue}>
{meta.sensitive ? (
<SensitiveValue value={meta.value} />
) : (
<MemoizedInlineMarkdown components={{ p }}>
{meta.value}
</MemoizedInlineMarkdown>
)}
</div>
<div css={styles.resourceDataItemLabel}>{meta.key}</div>
</div>
);
})}
</header>
);
};

const p = ({ children }: PropsWithChildren) => {
const childrens = Children.toArray(children);
if (childrens.every((child) => typeof child === "string")) {
return <CopyableValue value={childrens.join("")}>{children}</CopyableValue>;
}
return <>{children}</>;
};

const countAgents = (resource: TypesGen.WorkspaceResource) => {
return resource.agents ? resource.agents.length : 0;
};
Expand All @@ -264,6 +317,7 @@ const styles = {
padding: 24,
gridArea: "content",
overflowY: "auto",
position: "relative",
},

dotBackground: (theme) => ({
Expand All @@ -288,4 +342,32 @@ const styles = {
flexDirection: "column",
},
}),

resourceData: (theme) => ({
padding: 24,
margin: "-48px 0 0 -48px",
display: "flex",
gap: 48,
marginBottom: 24,
fontSize: 14,
background: `linear-gradient(180deg, ${theme.palette.background.default} 0%, rgba(0, 0, 0, 0) 100%)`,
}),

resourceDataItem: () => ({
lineHeight: "1.5",
}),

resourceDataItemLabel: (theme) => ({
fontSize: 13,
color: theme.palette.text.secondary,
textOverflow: "ellipsis",
overflow: "hidden",
whiteSpace: "nowrap",
}),

resourceDataItemValue: () => ({
textOverflow: "ellipsis",
overflow: "hidden",
whiteSpace: "nowrap",
}),
} satisfies Record<string, Interpolation<Theme>>;