({
workspace,
template,
permissions,
})
| 42 | } |
| 43 | |
| 44 | export const WorkspaceReadyPage: FC<WorkspaceReadyPageProps> = ({ |
| 45 | workspace, |
| 46 | template, |
| 47 | permissions, |
| 48 | }) => { |
| 49 | const queryClient = useQueryClient(); |
| 50 | |
| 51 | // Build logs |
| 52 | const shouldStreamBuildLogs = workspace.latest_build.status !== "running"; |
| 53 | const buildLogs = useWorkspaceBuildLogs( |
| 54 | workspace.latest_build.id, |
| 55 | shouldStreamBuildLogs, |
| 56 | ); |
| 57 | |
| 58 | // Restart |
| 59 | const [confirmingRestart, setConfirmingRestart] = useState<{ |
| 60 | open: boolean; |
| 61 | buildParameters?: TypesGen.WorkspaceBuildParameter[]; |
| 62 | }>({ open: false }); |
| 63 | |
| 64 | const [workspaceErrorDialog, setWorkspaceErrorDialog] = useState<{ |
| 65 | open: boolean; |
| 66 | error?: ApiError; |
| 67 | }>({ open: false }); |
| 68 | |
| 69 | const handleError = (error: unknown) => { |
| 70 | if (isApiError(error) && error.code === "ERR_BAD_REQUEST") { |
| 71 | setWorkspaceErrorDialog({ |
| 72 | open: true, |
| 73 | error: error, |
| 74 | }); |
| 75 | } else { |
| 76 | toast.error( |
| 77 | getErrorMessage( |
| 78 | error, |
| 79 | `Failed to build workspace "${workspace.name}".`, |
| 80 | ), |
| 81 | { |
| 82 | description: getErrorDetail(error), |
| 83 | }, |
| 84 | ); |
| 85 | } |
| 86 | }; |
| 87 | |
| 88 | const [ephemeralParametersDialog, setEphemeralParametersDialog] = useState<{ |
| 89 | open: boolean; |
| 90 | action: "start" | "restart"; |
| 91 | buildParameters?: TypesGen.WorkspaceBuildParameter[]; |
| 92 | ephemeralParameters: TypesGen.TemplateVersionParameter[]; |
| 93 | }>({ open: false, action: "start", ephemeralParameters: [] }); |
| 94 | |
| 95 | const [isCancelConfirmOpen, setIsCancelConfirmOpen] = useState(false); |
| 96 | |
| 97 | const { mutate: mutateRestartWorkspace, isPending: isRestarting } = |
| 98 | useMutation({ |
| 99 | mutationFn: API.restartWorkspace, |
| 100 | onError: (error: unknown) => { |
| 101 | handleError(error); |
nothing calls this directly
no test coverage detected