Skip to content

Commit 0c66c39

Browse files
committed
fix: Site references to workspace.latest_build.deadline
1 parent e11e186 commit 0c66c39

File tree

5 files changed

+13
-22
lines changed

5 files changed

+13
-22
lines changed

site/src/components/WorkspaceSchedule/WorkspaceSchedule.stories.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ NoTTL.args = {
3838
...Mocks.MockWorkspace,
3939
latest_build: {
4040
...Mocks.MockWorkspaceBuild,
41-
// a manual shutdown has a deadline of '"0001-01-01T00:00:00Z"'
42-
// SEE: #1834
43-
deadline: "0001-01-01T00:00:00Z",
41+
deadline: undefined,
4442
},
4543
ttl_ms: undefined,
4644
},

site/src/components/WorkspaceScheduleBanner/WorkspaceScheduleBanner.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ export const shouldDisplay = (workspace: TypesGen.Workspace): boolean => {
2626
if (!isWorkspaceOn(workspace)) {
2727
return false
2828
} else {
29-
// a manual shutdown has a deadline of '"0001-01-01T00:00:00Z"'
30-
// SEE: #1834
29+
if (!workspace.latest_build.deadline) {
30+
return false
31+
}
3132
const deadline = dayjs(workspace.latest_build.deadline).utc()
32-
const hasDeadline = deadline.year() > 1
3333
const thirtyMinutesFromNow = dayjs().add(30, "minutes").utc()
34-
return hasDeadline && deadline.isSameOrBefore(thirtyMinutesFromNow)
34+
return deadline.isSameOrBefore(thirtyMinutesFromNow)
3535
}
3636
}
3737

site/src/components/WorkspaceScheduleButton/WorkspaceScheduleButton.stories.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ NoTTL.args = {
4040
...Mocks.MockWorkspace,
4141
latest_build: {
4242
...Mocks.MockWorkspaceBuild,
43-
// a manual shutdown has a deadline of '"0001-01-01T00:00:00Z"'
44-
// SEE: #1834
45-
deadline: "0001-01-01T00:00:00Z",
43+
deadline: undefined,
4644
},
4745
ttl_ms: undefined,
4846
},

site/src/components/WorkspaceScheduleButton/WorkspaceScheduleButton.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ dayjs.extend(relativeTime)
2828
dayjs.extend(timezone)
2929

3030
export const shouldDisplayPlusMinus = (workspace: Workspace): boolean => {
31-
if (!isWorkspaceOn(workspace)) {
32-
return false
33-
}
34-
const deadline = dayjs(workspace.latest_build.deadline).utc()
35-
return deadline.year() > 1
31+
return isWorkspaceOn(workspace) && !!workspace.latest_build.deadline
3632
}
3733

3834
export interface WorkspaceScheduleButtonProps {

site/src/util/schedule.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,27 +73,26 @@ export const autoStartDisplay = (schedule: string | undefined): string => {
7373

7474
export const isShuttingDown = (workspace: Workspace, deadline?: Dayjs): boolean => {
7575
if (!deadline) {
76+
if (!workspace.latest_build.deadline) {
77+
return false
78+
}
7679
deadline = dayjs(workspace.latest_build.deadline).utc()
7780
}
78-
const hasDeadline = deadline.year() > 1
7981
const now = dayjs().utc()
80-
return isWorkspaceOn(workspace) && hasDeadline && now.isAfter(deadline)
82+
return isWorkspaceOn(workspace) && now.isAfter(deadline)
8183
}
8284

8385
export const autoStopDisplay = (workspace: Workspace): string => {
84-
const deadline = dayjs(workspace.latest_build.deadline).utc()
85-
// a manual shutdown has a deadline of '"0001-01-01T00:00:00Z"'
86-
// SEE: #1834
87-
const hasDeadline = deadline.year() > 1
8886
const ttl = workspace.ttl_ms
8987

90-
if (isWorkspaceOn(workspace) && hasDeadline) {
88+
if (isWorkspaceOn(workspace) && workspace.latest_build.deadline) {
9189
// Workspace is on --> derive from latest_build.deadline. Note that the
9290
// user may modify their workspace object (ttl) while the workspace is
9391
// running and depending on system semantics, the deadline may still
9492
// represent the previously defined ttl. Thus, we always derive from the
9593
// deadline as the source of truth.
9694

95+
const deadline = dayjs(workspace.latest_build.deadline).utc()
9796
if (isShuttingDown(workspace, deadline)) {
9897
return Language.workspaceShuttingDownLabel
9998
} else {

0 commit comments

Comments
 (0)