Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1af3630

Browse files
committed
refactor: typegen
1 parent 4c04053 commit 1af3630

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ dayjs.extend(duration)
2020
dayjs.extend(relativeTime)
2121

2222
export const Language = {
23-
autoStartDisplay: (schedule: string): string => {
23+
autoStartDisplay: (schedule: string | undefined): string => {
2424
if (schedule) {
2525
return cronstrue.toString(stripTimezone(schedule), { throwExceptionOnParseError: false })
2626
}
2727
return "Manual"
2828
},
29-
autoStartLabel: (schedule: string): string => {
29+
autoStartLabel: (schedule: string | undefined): string => {
3030
const prefix = "Start"
3131

3232
if (schedule) {
@@ -40,7 +40,7 @@ export const Language = {
4040
// a mannual shutdown has a deadline of '"0001-01-01T00:00:00Z"'
4141
// SEE: #1834
4242
const hasDeadline = deadline.year() > 1
43-
const ttl = workspace.ttl
43+
const ttl = workspace.ttl_ms
4444

4545
if (isWorkspaceOn(workspace) && hasDeadline) {
4646
// Workspace is on --> derive from latest_build.deadline. Note that the
@@ -61,7 +61,7 @@ export const Language = {
6161
} else {
6262
// The workspace has a ttl set, but is either in an unknown state or is
6363
// not running. Therefore, we derive from workspace.ttl.
64-
const duration = dayjs.duration(ttl / 1_000_000, "milliseconds")
64+
const duration = dayjs.duration(ttl, "milliseconds")
6565
return `${duration.humanize()} after start`
6666
}
6767
},

site/src/pages/WorkspaceSchedulePage/WorkspaceSchedulePage.test.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ describe("WorkspaceSchedulePage", () => {
123123
ttl: 0,
124124
},
125125
{
126-
ttl: undefined,
126+
ttl_ms: undefined,
127127
},
128128
],
129129
[
@@ -133,7 +133,7 @@ describe("WorkspaceSchedulePage", () => {
133133
ttl: 2,
134134
},
135135
{
136-
ttl: 7_200_000_000_000,
136+
ttl_ms: 7_200_000,
137137
},
138138
],
139139
[
@@ -143,7 +143,7 @@ describe("WorkspaceSchedulePage", () => {
143143
ttl: 8,
144144
},
145145
{
146-
ttl: 28_800_000_000_000,
146+
ttl_ms: 28_800_000,
147147
},
148148
],
149149
])(`formValuesToTTLRequest(%p) returns %p`, (values, request) => {
@@ -157,8 +157,8 @@ describe("WorkspaceSchedulePage", () => {
157157
[
158158
{
159159
...Mocks.MockWorkspace,
160-
autostart_schedule: "",
161-
ttl: undefined,
160+
autostart_schedule: undefined,
161+
ttl_ms: undefined,
162162
},
163163
{
164164
sunday: false,
@@ -179,7 +179,7 @@ describe("WorkspaceSchedulePage", () => {
179179
{
180180
...Mocks.MockWorkspace,
181181
autostart_schedule: "",
182-
ttl: 7_200_000_000_000,
182+
ttl_ms: 7_200_000,
183183
},
184184
{
185185
sunday: false,
@@ -203,7 +203,7 @@ describe("WorkspaceSchedulePage", () => {
203203
{
204204
...Mocks.MockWorkspace,
205205
autostart_schedule: "CRON_TZ=UTC 30 9 * * 1-5",
206-
ttl: 7_200_000_000_000,
206+
ttl_ms: 7_200_000,
207207
},
208208
{
209209
sunday: false,
@@ -224,7 +224,7 @@ describe("WorkspaceSchedulePage", () => {
224224
{
225225
...Mocks.MockWorkspace,
226226
autostart_schedule: "CRON_TZ=Canada/Eastern 20 16 * * 1,3-4,6",
227-
ttl: 28_800_000_000_000,
227+
ttl_ms: 28_800_000,
228228
},
229229
{
230230
sunday: false,

site/src/pages/WorkspaceSchedulePage/WorkspaceSchedulePage.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ export const formValuesToAutoStartRequest = (
8787
export const formValuesToTTLRequest = (values: WorkspaceScheduleFormValues): TypesGen.UpdateWorkspaceTTLRequest => {
8888
return {
8989
// minutes to nanoseconds
90-
ttl: values.ttl ? values.ttl * 60 * 60 * 1000 * 1_000_000 : undefined,
90+
ttl_ms: values.ttl ? values.ttl * 60 * 60 * 1000 : undefined,
9191
}
9292
}
9393

9494
export const workspaceToInitialValues = (workspace: TypesGen.Workspace): WorkspaceScheduleFormValues => {
9595
const schedule = workspace.autostart_schedule
96-
const ttl = workspace.ttl ? workspace.ttl / (1_000_000 * 1000 * 60 * 60) : 0
96+
const ttl = workspace.ttl_ms ? workspace.ttl_ms / (1000 * 60 * 60) : 0
9797

9898
if (!schedule) {
9999
return {
@@ -106,7 +106,7 @@ export const workspaceToInitialValues = (workspace: TypesGen.Workspace): Workspa
106106
saturday: false,
107107
startTime: "",
108108
timezone: "",
109-
ttl,
109+
ttl: ttl,
110110
}
111111
}
112112

@@ -133,7 +133,7 @@ export const workspaceToInitialValues = (workspace: TypesGen.Workspace): Workspa
133133
saturday: weeklyFlags[6],
134134
startTime: `${HH.padStart(2, "0")}:${mm.padStart(2, "0")}`,
135135
timezone,
136-
ttl,
136+
ttl: ttl,
137137
}
138138
}
139139

site/src/testHelpers/entities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export const MockWorkspace: TypesGen.Workspace = {
164164
owner_id: MockUser.id,
165165
owner_name: MockUser.username,
166166
autostart_schedule: MockWorkspaceAutostartEnabled.schedule,
167-
ttl: 2 * 60 * 60 * 1000 * 1_000_000, // 2 hours as nanoseconds
167+
ttl_ms: 2 * 60 * 60 * 1000 * 1_000_000, // 2 hours as nanoseconds
168168
latest_build: MockWorkspaceBuild,
169169
}
170170

0 commit comments

Comments
 (0)