Skip to content

refactor: Refactor template resources #4789

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 14 commits into from
Oct 27, 2022
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
Accept different resource card
  • Loading branch information
BrunoQuaresma committed Oct 27, 2022
commit 3f499e9150fdf884ee2f86cc08b0fb8e61269f5c
36 changes: 4 additions & 32 deletions site/src/components/Resources/Resources.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,22 @@ import {
OpenDropdown,
} from "components/DropdownArrows/DropdownArrows"
import { FC, useState } from "react"
import {
BuildInfoResponse,
Workspace,
WorkspaceResource,
} from "../../api/typesGenerated"
import { WorkspaceResource } from "../../api/typesGenerated"
import { Stack } from "../Stack/Stack"
import { ResourceCard } from "./ResourceCard"

const countAgents = (resource: WorkspaceResource) => {
return resource.agents ? resource.agents.length : 0
}

interface ResourcesProps {
resources: WorkspaceResource[]
workspace: Workspace
canUpdateWorkspace: boolean
buildInfo?: BuildInfoResponse | undefined
hideSSHButton?: boolean
applicationsHost?: string
resourceCard: (resource: WorkspaceResource) => JSX.Element
}

export const Resources: FC<React.PropsWithChildren<ResourcesProps>> = ({
resources,

workspace,
canUpdateWorkspace,
hideSSHButton,
applicationsHost,
buildInfo,
resourceCard,
}) => {
const serverVersion = buildInfo?.version || ""
const styles = useStyles()
const [shouldDisplayHideResources, setShouldDisplayHideResources] =
useState(false)
Expand All @@ -49,20 +34,7 @@ export const Resources: FC<React.PropsWithChildren<ResourcesProps>> = ({

return (
<Stack direction="column" spacing={0}>
{displayResources.map((resource) => {
return (
<ResourceCard
key={resource.id}
resource={resource}
workspace={workspace}
applicationsHost={applicationsHost}
showApps={canUpdateWorkspace}
hideSSHButton={hideSSHButton}
serverVersion={serverVersion}
/>
)
})}

{displayResources.map(resourceCard)}
{hasHideResources && (
<div className={styles.buttonWrapper}>
<Button
Expand Down
18 changes: 13 additions & 5 deletions site/src/components/Workspace/Workspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
EstimateTransitionTime,
WorkspaceBuildProgress,
} from "components/WorkspaceBuildProgress/WorkspaceBuildProgress"
import { ResourceCard } from "components/Resources/ResourceCard"

export enum WorkspaceErrors {
GET_RESOURCES_ERROR = "getResourcesError",
Expand Down Expand Up @@ -86,6 +87,7 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
const { t } = useTranslation("workspacePage")
const styles = useStyles()
const navigate = useNavigate()
const serverVersion = buildInfo?.version || ""
const hasTemplateIcon =
workspace.template_icon && workspace.template_icon !== ""

Expand Down Expand Up @@ -216,11 +218,17 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
{typeof resources !== "undefined" && resources.length > 0 && (
<Resources
resources={resources}
workspace={workspace}
canUpdateWorkspace={canUpdateWorkspace}
buildInfo={buildInfo}
hideSSHButton={hideSSHButton}
applicationsHost={applicationsHost}
resourceCard={(resource) => (
<ResourceCard
key={resource.id}
resource={resource}
workspace={workspace}
applicationsHost={applicationsHost}
showApps={canUpdateWorkspace}
hideSSHButton={hideSSHButton}
serverVersion={serverVersion}
/>
)}
/>
)}

Expand Down