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
Next Next commit
Remove error logic from Resources
  • Loading branch information
BrunoQuaresma committed Oct 27, 2022
commit f542eaace02904f1e44bbf93adbe26e1634a9426
4 changes: 1 addition & 3 deletions site/src/components/BuildsTable/BuildsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export const Language = {

export interface BuildsTableProps {
builds?: TypesGen.WorkspaceBuild[]
className?: string
}

const groupBuildsByDate = (builds?: TypesGen.WorkspaceBuild[]) => {
Expand All @@ -48,13 +47,12 @@ const groupBuildsByDate = (builds?: TypesGen.WorkspaceBuild[]) => {

export const BuildsTable: FC<React.PropsWithChildren<BuildsTableProps>> = ({
builds,
className,
}) => {
const isLoading = !builds
const buildsByDate = groupBuildsByDate(builds)

return (
<TableContainer className={className}>
<TableContainer>
<Table data-testid="builds-table" aria-describedby="builds table">
<TableBody>
{isLoading && <TableLoader />}
Expand Down
8 changes: 1 addition & 7 deletions site/src/components/Resources/Resources.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
WorkspaceResource,
} from "../../api/typesGenerated"
import { Stack } from "../Stack/Stack"
import { AlertBanner } from "components/AlertBanner/AlertBanner"
import { ResourceCard } from "./ResourceCard"

const countAgents = (resource: WorkspaceResource) => {
Expand All @@ -20,7 +19,6 @@ const countAgents = (resource: WorkspaceResource) => {

interface ResourcesProps {
resources: WorkspaceResource[]
getResourcesError?: Error | unknown
workspace: Workspace
canUpdateWorkspace: boolean
buildInfo?: BuildInfoResponse | undefined
Expand All @@ -30,7 +28,7 @@ interface ResourcesProps {

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

workspace,
canUpdateWorkspace,
hideSSHButton,
Expand All @@ -49,10 +47,6 @@ export const Resources: FC<React.PropsWithChildren<ResourcesProps>> = ({
.sort((a, b) => countAgents(b) - countAgents(a))
const hasHideResources = resources.some((r) => r.hide)

if (getResourcesError) {
return <AlertBanner severity="error" error={getResourcesError} />
}

return (
<Stack direction="column" spacing={0}>
{displayResources.map((resource) => {
Expand Down
35 changes: 15 additions & 20 deletions site/src/components/Workspace/Workspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { WorkspaceActions } from "../WorkspaceActions/WorkspaceActions"
import { WorkspaceDeletedBanner } from "../WorkspaceDeletedBanner/WorkspaceDeletedBanner"
import { WorkspaceScheduleBanner } from "../WorkspaceScheduleBanner/WorkspaceScheduleBanner"
import { WorkspaceScheduleButton } from "../WorkspaceScheduleButton/WorkspaceScheduleButton"
import { WorkspaceSection } from "../WorkspaceSection/WorkspaceSection"
import { WorkspaceStats } from "../WorkspaceStats/WorkspaceStats"
import { AlertBanner } from "../AlertBanner/AlertBanner"
import { useTranslation } from "react-i18next"
Expand Down Expand Up @@ -207,12 +206,16 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
/>
)}

{Boolean(workspaceErrors[WorkspaceErrors.GET_RESOURCES_ERROR]) && (
<AlertBanner
severity="error"
error={workspaceErrors[WorkspaceErrors.GET_RESOURCES_ERROR]}
/>
)}

{typeof resources !== "undefined" && resources.length > 0 && (
<Resources
resources={resources}
getResourcesError={
workspaceErrors[WorkspaceErrors.GET_RESOURCES_ERROR]
}
workspace={workspace}
canUpdateWorkspace={canUpdateWorkspace}
buildInfo={buildInfo}
Expand All @@ -221,18 +224,14 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
/>
)}

<WorkspaceSection
contentsProps={{ className: styles.timelineContents }}
>
{workspaceErrors[WorkspaceErrors.GET_BUILDS_ERROR] ? (
<AlertBanner
severity="error"
error={workspaceErrors[WorkspaceErrors.GET_BUILDS_ERROR]}
/>
) : (
<BuildsTable builds={builds} className={styles.timelineTable} />
)}
</WorkspaceSection>
{workspaceErrors[WorkspaceErrors.GET_BUILDS_ERROR] ? (
<AlertBanner
severity="error"
error={workspaceErrors[WorkspaceErrors.GET_BUILDS_ERROR]}
/>
) : (
<BuildsTable builds={builds} />
)}
</Stack>
</Margins>
)
Expand Down Expand Up @@ -276,9 +275,5 @@ export const useStyles = makeStyles((theme) => {
timelineContents: {
margin: 0,
},

timelineTable: {
border: 0,
},
}
})