Skip to content

Commit a0ce84e

Browse files
committed
Fix audit log row to match the new API types
1 parent 0267d4e commit a0ce84e

File tree

2 files changed

+2
-73
lines changed

2 files changed

+2
-73
lines changed

site/src/api/typesGenerated.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -667,27 +667,3 @@ export type WorkspaceAgentStatus = "connected" | "connecting" | "disconnected"
667667

668668
// From codersdk/workspacebuilds.go
669669
export type WorkspaceTransition = "delete" | "start" | "stop"
670-
671-
// TODO: Remove this when the generated types work for AuditLogs
672-
export interface AuditLog {
673-
readonly id: string
674-
readonly request_id: string
675-
readonly time: string
676-
readonly organization_id: string
677-
// Named type "net/netip.Addr" unknown, using "any"
678-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
679-
readonly ip: any
680-
readonly user_agent: string
681-
readonly resource_type: "organization" | "template" | "template_version" | "user" | "workspace"
682-
readonly resource_id: string
683-
readonly resource_target: string
684-
readonly action: "write" | "create" | "delete"
685-
readonly diff: Record<string, { old: number | string | boolean; new: number | string | boolean }>
686-
readonly status_code: number
687-
// This is likely an enum in an external package ("encoding/json.RawMessage")
688-
readonly additional_fields: Record<string, string>
689-
readonly description: string
690-
readonly user?: User
691-
// This is likely an enum in an external package ("encoding/json.RawMessage")
692-
readonly resource: Organization | Template | TemplateVersion | User | Workspace
693-
}

site/src/components/AuditLogRow/AuditLogRow.tsx

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import Collapse from "@material-ui/core/Collapse"
2-
import Link from "@material-ui/core/Link"
32
import { makeStyles } from "@material-ui/core/styles"
43
import TableCell from "@material-ui/core/TableCell"
54
import TableRow from "@material-ui/core/TableRow"
6-
import { AuditLog, Template, Workspace } from "api/typesGenerated"
5+
import { AuditLog } from "api/typesGenerated"
76
import { CloseDropdown, OpenDropdown } from "components/DropdownArrows/DropdownArrows"
87
import { Pill } from "components/Pill/Pill"
98
import { Stack } from "components/Stack/Stack"
109
import { UserAvatar } from "components/UserAvatar/UserAvatar"
1110
import { t } from "i18next"
1211
import { ComponentProps, useState } from "react"
13-
import { Link as RouterLink } from "react-router-dom"
1412
import { createDayString } from "util/createDayString"
1513
import { AuditLogDiff } from "./AuditLogDiff"
1614

@@ -26,48 +24,6 @@ const pillTypeByHttpStatus = (httpStatus: number): ComponentProps<typeof Pill>["
2624
return "success"
2725
}
2826

29-
const getResourceLabel = (resource: AuditLog["resource"]): string => {
30-
if ("name" in resource) {
31-
return resource.name
32-
}
33-
34-
return resource.username
35-
}
36-
37-
const getResourceHref = (
38-
resource: AuditLog["resource"],
39-
resourceType: AuditLog["resource_type"],
40-
): string | undefined => {
41-
switch (resourceType) {
42-
case "user":
43-
return `/users`
44-
case "template":
45-
return `/templates/${(resource as Template).name}`
46-
case "workspace":
47-
return `/workspaces/@${(resource as Workspace).owner_name}/${(resource as Workspace).name}`
48-
case "organization":
49-
return
50-
}
51-
}
52-
53-
const ResourceLink: React.FC<{
54-
resource: AuditLog["resource"]
55-
resourceType: AuditLog["resource_type"]
56-
}> = ({ resource, resourceType }) => {
57-
const href = getResourceHref(resource, resourceType)
58-
const label = <strong>{getResourceLabel(resource)}</strong>
59-
60-
if (!href) {
61-
return label
62-
}
63-
64-
return (
65-
<Link component={RouterLink} to={href}>
66-
{label}
67-
</Link>
68-
)
69-
}
70-
7127
const actionLabelByAction: Record<AuditLog["action"], string> = {
7228
create: t("actions.create", { ns: "auditLog" }),
7329
write: t("actions.write", { ns: "auditLog" }),
@@ -140,10 +96,7 @@ export const AuditLogRow: React.FC<AuditLogRowProps> = ({
14096
<div>
14197
<span className={styles.auditLogResume}>
14298
<strong>{auditLog.user?.username}</strong> {readableActionMessage(auditLog)}{" "}
143-
<ResourceLink
144-
resource={auditLog.resource}
145-
resourceType={auditLog.resource_type}
146-
/>
99+
<strong>{auditLog.resource_target}</strong>
147100
</span>
148101
<span className={styles.auditLogTime}>{createDayString(auditLog.time)}</span>
149102
</div>

0 commit comments

Comments
 (0)