Skip to content

Commit dd8ebf1

Browse files
authored
fix: duplicate workspace update entries (#4513)
* fix: duplicate workspace update entries * remove console log * attempting to fix tests * keep diffs with 0 changes * cleaned up test
1 parent a029817 commit dd8ebf1

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

coderd/audit/audit.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ func (nop) Export(context.Context, database.AuditLog) error {
2121
return nil
2222
}
2323

24-
func (nop) diff(any, any) Map { return Map{} }
24+
func (nop) diff(any, any) Map {
25+
return Map{}
26+
}
2527

2628
func NewMock() *MockAuditor {
2729
return &MockAuditor{}
@@ -36,4 +38,6 @@ func (a *MockAuditor) Export(_ context.Context, alog database.AuditLog) error {
3638
return nil
3739
}
3840

39-
func (*MockAuditor) diff(any, any) Map { return Map{} }
41+
func (*MockAuditor) diff(any, any) Map {
42+
return Map{}
43+
}

site/src/pages/WorkspaceSchedulePage/WorkspaceSchedulePage.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ export const WorkspaceSchedulePage: React.FC = () => {
108108
onSubmit={(values) => {
109109
scheduleSend({
110110
type: "SUBMIT_SCHEDULE",
111-
autoStart: formValuesToAutoStartRequest(values),
111+
autoStart: values.autoStartEnabled
112+
? formValuesToAutoStartRequest(values)
113+
: undefined,
112114
ttl: formValuesToTTLRequest(values),
113115
})
114116
}}

site/src/testHelpers/entities.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,13 @@ export const MockAuditLog: TypesGen.AuditLog = {
872872
resource_target: "bruno-dev",
873873
resource_icon: "",
874874
action: "create",
875-
diff: {},
875+
diff: {
876+
ttl: {
877+
old: 0,
878+
new: 3600000000000,
879+
secret: false,
880+
},
881+
},
876882
status_code: 200,
877883
additional_fields: "",
878884
description: "{user} updated workspace {target}",

site/src/xServices/workspaceSchedule/workspaceScheduleXService.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export type WorkspaceScheduleEvent =
4545
| { type: "GET_WORKSPACE"; username: string; workspaceName: string }
4646
| {
4747
type: "SUBMIT_SCHEDULE"
48-
autoStart: TypesGen.UpdateWorkspaceAutostartRequest
48+
autoStart: TypesGen.UpdateWorkspaceAutostartRequest | undefined
4949
ttl: TypesGen.UpdateWorkspaceTTLRequest
5050
}
5151

@@ -195,10 +195,9 @@ export const workspaceSchedule = createMachine(
195195
throw new Error("Failed to load workspace.")
196196
}
197197

198-
// REMARK: These calls are purposefully synchronous because if one
199-
// value contradicts the other, we don't want a race condition
200-
// on re-submission.
201-
await API.putWorkspaceAutostart(context.workspace.id, event.autoStart)
198+
if (event.autoStart?.schedule !== undefined) {
199+
await API.putWorkspaceAutostart(context.workspace.id, event.autoStart)
200+
}
202201
await API.putWorkspaceAutostop(context.workspace.id, event.ttl)
203202
},
204203
},

0 commit comments

Comments
 (0)