From dd8ebf10db2501439ecdfe77e07f29a5e4a242ee Mon Sep 17 00:00:00 2001 From: Kira Pilot Date: Fri, 14 Oct 2022 14:39:20 -0400 Subject: [PATCH] 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 --- coderd/audit/audit.go | 8 ++++++-- .../WorkspaceSchedulePage/WorkspaceSchedulePage.tsx | 4 +++- site/src/testHelpers/entities.ts | 8 +++++++- .../workspaceSchedule/workspaceScheduleXService.ts | 9 ++++----- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/coderd/audit/audit.go b/coderd/audit/audit.go index 92f4471305..ca343123e9 100644 --- a/coderd/audit/audit.go +++ b/coderd/audit/audit.go @@ -21,7 +21,9 @@ func (nop) Export(context.Context, database.AuditLog) error { return nil } -func (nop) diff(any, any) Map { return Map{} } +func (nop) diff(any, any) Map { + return Map{} +} func NewMock() *MockAuditor { return &MockAuditor{} @@ -36,4 +38,6 @@ func (a *MockAuditor) Export(_ context.Context, alog database.AuditLog) error { return nil } -func (*MockAuditor) diff(any, any) Map { return Map{} } +func (*MockAuditor) diff(any, any) Map { + return Map{} +} diff --git a/site/src/pages/WorkspaceSchedulePage/WorkspaceSchedulePage.tsx b/site/src/pages/WorkspaceSchedulePage/WorkspaceSchedulePage.tsx index 471fc3d9ee..492a56ae47 100644 --- a/site/src/pages/WorkspaceSchedulePage/WorkspaceSchedulePage.tsx +++ b/site/src/pages/WorkspaceSchedulePage/WorkspaceSchedulePage.tsx @@ -108,7 +108,9 @@ export const WorkspaceSchedulePage: React.FC = () => { onSubmit={(values) => { scheduleSend({ type: "SUBMIT_SCHEDULE", - autoStart: formValuesToAutoStartRequest(values), + autoStart: values.autoStartEnabled + ? formValuesToAutoStartRequest(values) + : undefined, ttl: formValuesToTTLRequest(values), }) }} diff --git a/site/src/testHelpers/entities.ts b/site/src/testHelpers/entities.ts index 6e26a4fee5..445696133d 100644 --- a/site/src/testHelpers/entities.ts +++ b/site/src/testHelpers/entities.ts @@ -872,7 +872,13 @@ export const MockAuditLog: TypesGen.AuditLog = { resource_target: "bruno-dev", resource_icon: "", action: "create", - diff: {}, + diff: { + ttl: { + old: 0, + new: 3600000000000, + secret: false, + }, + }, status_code: 200, additional_fields: "", description: "{user} updated workspace {target}", diff --git a/site/src/xServices/workspaceSchedule/workspaceScheduleXService.ts b/site/src/xServices/workspaceSchedule/workspaceScheduleXService.ts index 1c5f478f09..3d2e7cacfc 100644 --- a/site/src/xServices/workspaceSchedule/workspaceScheduleXService.ts +++ b/site/src/xServices/workspaceSchedule/workspaceScheduleXService.ts @@ -45,7 +45,7 @@ export type WorkspaceScheduleEvent = | { type: "GET_WORKSPACE"; username: string; workspaceName: string } | { type: "SUBMIT_SCHEDULE" - autoStart: TypesGen.UpdateWorkspaceAutostartRequest + autoStart: TypesGen.UpdateWorkspaceAutostartRequest | undefined ttl: TypesGen.UpdateWorkspaceTTLRequest } @@ -195,10 +195,9 @@ export const workspaceSchedule = createMachine( throw new Error("Failed to load workspace.") } - // REMARK: These calls are purposefully synchronous because if one - // value contradicts the other, we don't want a race condition - // on re-submission. - await API.putWorkspaceAutostart(context.workspace.id, event.autoStart) + if (event.autoStart?.schedule !== undefined) { + await API.putWorkspaceAutostart(context.workspace.id, event.autoStart) + } await API.putWorkspaceAutostop(context.workspace.id, event.ttl) }, },