11import { Theme } from "@material-ui/core/styles"
22import dayjs from "dayjs"
3+ import utc from "dayjs/plugin/utc"
34import { WorkspaceBuildTransition } from "../api/types"
4- import { Workspace , WorkspaceAgent , WorkspaceBuild } from "../api/typesGenerated"
5+ import * as TypesGen from "../api/typesGenerated"
6+
7+ dayjs . extend ( utc )
58
69export type WorkspaceStatus =
710 | "queued"
@@ -29,7 +32,7 @@ const succeededToStatus: Record<WorkspaceBuildTransition, WorkspaceStatus> = {
2932}
3033
3134// Converts a workspaces status to a human-readable form.
32- export const getWorkspaceStatus = ( workspaceBuild ?: WorkspaceBuild ) : WorkspaceStatus => {
35+ export const getWorkspaceStatus = ( workspaceBuild ?: TypesGen . WorkspaceBuild ) : WorkspaceStatus => {
3336 const transition = workspaceBuild ?. transition as WorkspaceBuildTransition
3437 const jobStatus = workspaceBuild ?. job . status
3538 switch ( jobStatus ) {
@@ -67,7 +70,7 @@ export const DisplayStatusLanguage = {
6770// Localize workspace status and provide corresponding color from theme
6871export const getDisplayStatus = (
6972 theme : Theme ,
70- build : WorkspaceBuild ,
73+ build : TypesGen . WorkspaceBuild ,
7174) : {
7275 color : string
7376 status : string
@@ -133,7 +136,7 @@ export const getDisplayStatus = (
133136 throw new Error ( "unknown status " + status )
134137}
135138
136- export const getWorkspaceBuildDurationInSeconds = ( build : WorkspaceBuild ) : number | undefined => {
139+ export const getWorkspaceBuildDurationInSeconds = ( build : TypesGen . WorkspaceBuild ) : number | undefined => {
137140 const isCompleted = build . job . started_at && build . job . completed_at
138141
139142 if ( ! isCompleted ) {
@@ -145,7 +148,10 @@ export const getWorkspaceBuildDurationInSeconds = (build: WorkspaceBuild): numbe
145148 return completedAt . diff ( startedAt , "seconds" )
146149}
147150
148- export const displayWorkspaceBuildDuration = ( build : WorkspaceBuild , inProgressLabel = "In progress" ) : string => {
151+ export const displayWorkspaceBuildDuration = (
152+ build : TypesGen . WorkspaceBuild ,
153+ inProgressLabel = "In progress" ,
154+ ) : string => {
149155 const duration = getWorkspaceBuildDurationInSeconds ( build )
150156 return duration ? `${ duration } seconds` : inProgressLabel
151157}
@@ -158,7 +164,7 @@ export const DisplayAgentStatusLanguage = {
158164
159165export const getDisplayAgentStatus = (
160166 theme : Theme ,
161- agent : WorkspaceAgent ,
167+ agent : TypesGen . WorkspaceAgent ,
162168) : {
163169 color : string
164170 status : string
@@ -187,8 +193,17 @@ export const getDisplayAgentStatus = (
187193 }
188194}
189195
190- export const isWorkspaceOn = ( workspace : Workspace ) : boolean => {
196+ export const isWorkspaceOn = ( workspace : TypesGen . Workspace ) : boolean => {
191197 const transition = workspace . latest_build . transition
192198 const status = workspace . latest_build . job . status
193199 return transition === "start" && status === "succeeded"
194200}
201+
202+ export const defaultWorkspaceExtension = ( __startDate ?: dayjs . Dayjs ) : TypesGen . PutExtendWorkspaceRequest => {
203+ const now = __startDate ? dayjs ( __startDate ) : dayjs ( )
204+ const NinetyMinutesFromNow = now . add ( 90 , "minutes" ) . utc ( )
205+
206+ return {
207+ deadline : NinetyMinutesFromNow . format ( ) ,
208+ }
209+ }
0 commit comments