Skip to content

Commit

Permalink
fix(site): delete workspace action in audit log (coder#8494)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtojek authored Jul 13, 2023
1 parent 24ec05b commit ebdc510
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,25 @@ export const BuildAuditDescription: FC<{ auditLog: AuditLog }> = ({
const { t } = useTranslation("auditLog")

const workspaceName = auditLog.additional_fields?.workspace_name?.trim()
// workspaces can be started/stopped by a user, or kicked off automatically by Coder
// workspaces can be started/stopped/deleted by a user, or kicked off automatically by Coder
const user =
auditLog.additional_fields?.build_reason &&
auditLog.additional_fields?.build_reason !== "initiator"
? "Coder automatically"
: auditLog.user?.username.trim()

const action = auditLog.action === "start" ? "started" : "stopped"
const action: string = (() => {
switch (auditLog.action) {
case "start":
return "started"
case "stop":
return "stopped"
case "delete":
return "deleted"
default:
return auditLog.action
}
})()

if (auditLog.resource_link) {
return (
Expand Down
26 changes: 23 additions & 3 deletions site/src/components/AuditLogRow/AuditLogRow.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,29 @@ WithLongDiffRow.args = {
defaultIsDiffOpen: true,
}

export const WithWorkspaceBuild = Template.bind({})
WithWorkspaceBuild.args = {
auditLog: MockAuditLogWithWorkspaceBuild,
export const WithStoppedWorkspaceBuild = Template.bind({})
WithStoppedWorkspaceBuild.args = {
auditLog: {
...MockAuditLogWithWorkspaceBuild,
action: "stop",
},
}

export const WithStartedWorkspaceBuild = Template.bind({})
WithStartedWorkspaceBuild.args = {
auditLog: {
...MockAuditLogWithWorkspaceBuild,
action: "start",
},
}

export const WithDeletedWorkspaceBuild = Template.bind({})
WithDeletedWorkspaceBuild.args = {
auditLog: {
...MockAuditLogWithWorkspaceBuild,
action: "delete",
is_deleted: true,
},
}

export const DeletedResource = Template.bind({})
Expand Down

0 comments on commit ebdc510

Please sign in to comment.