({
workspace,
isUpdating,
isRestarting,
template,
buildLogs,
latestVersion,
permissions,
timings,
handleStart,
handleStop,
handleRestart,
handleUpdate,
handleCancel,
handleDormantActivate,
handleToggleFavorite,
handleRetry,
handleDebug,
})
| 46 | * Workspace is the top-level component for viewing an individual workspace |
| 47 | */ |
| 48 | export const Workspace: FC<WorkspaceProps> = ({ |
| 49 | workspace, |
| 50 | isUpdating, |
| 51 | isRestarting, |
| 52 | template, |
| 53 | buildLogs, |
| 54 | latestVersion, |
| 55 | permissions, |
| 56 | timings, |
| 57 | handleStart, |
| 58 | handleStop, |
| 59 | handleRestart, |
| 60 | handleUpdate, |
| 61 | handleCancel, |
| 62 | handleDormantActivate, |
| 63 | handleToggleFavorite, |
| 64 | handleRetry, |
| 65 | handleDebug, |
| 66 | }) => { |
| 67 | const getLink = useLinks(); |
| 68 | const createWorkspaceLink = `${getLink( |
| 69 | linkToTemplate(workspace.organization_name, workspace.template_name), |
| 70 | )}/workspace`; |
| 71 | const templateName = |
| 72 | workspace.template_display_name || workspace.template_name; |
| 73 | |
| 74 | const transitionStats = |
| 75 | template !== undefined |
| 76 | ? getActiveTransitionStats(template, workspace) |
| 77 | : undefined; |
| 78 | |
| 79 | const sidebarOption = useSearchParamsKey({ key: "sidebar" }); |
| 80 | const setSidebarOption = (newOption: string) => { |
| 81 | if (sidebarOption.value === newOption) { |
| 82 | sidebarOption.deleteValue(); |
| 83 | } else { |
| 84 | sidebarOption.setValue(newOption); |
| 85 | } |
| 86 | }; |
| 87 | |
| 88 | const resources = [...workspace.latest_build.resources].sort( |
| 89 | (a, b) => countAgents(b) - countAgents(a), |
| 90 | ); |
| 91 | const resourcesNav = useResourcesNav(resources); |
| 92 | const selectedResource = resources.find( |
| 93 | (r) => resourceOptionValue(r) === resourcesNav.value, |
| 94 | ); |
| 95 | |
| 96 | const workspaceRunning = workspace.latest_build.status === "running"; |
| 97 | const workspacePending = workspace.latest_build.status === "pending"; |
| 98 | const haveBuildLogs = (buildLogs ?? []).length > 0; |
| 99 | const shouldShowBuildLogs = haveBuildLogs && !workspaceRunning; |
| 100 | const provisionersHealthy = |
| 101 | (workspace.latest_build.matched_provisioners?.available ?? 1) > 0; |
| 102 | const shouldShowProvisionerAlert = |
| 103 | workspacePending && !haveBuildLogs && !provisionersHealthy && !isRestarting; |
| 104 | |
| 105 | return ( |
nothing calls this directly
no test coverage detected