Skip to content

Commit f9a7ed7

Browse files
committed
Move types
1 parent b30165a commit f9a7ed7

File tree

5 files changed

+37
-56
lines changed

5 files changed

+37
-56
lines changed

site/src/api/api.ts

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { MockAuditLog } from "testHelpers/entities"
44
import * as Types from "./types"
55
import { WorkspaceBuildTransition } from "./types"
66
import * as TypesGen from "./typesGenerated"
7-
import { User } from "./typesGenerated"
87

98
const CONTENT_TYPE_JSON: AxiosRequestHeaders = {
109
"Content-Type": "application/json",
@@ -386,36 +385,9 @@ export const getEntitlements = async (): Promise<TypesGen.Entitlements> => {
386385
return response.data
387386
}
388387

389-
export interface AuditLog {
390-
readonly id: string
391-
readonly request_id: string
392-
readonly time: string
393-
readonly organization_id: string
394-
// Named type "net/netip.Addr" unknown, using "any"
395-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
396-
readonly ip: any
397-
readonly user_agent: string
398-
readonly resource_type: "organization" | "template" | "template_version" | "user" | "workspace"
399-
readonly resource_id: string
400-
readonly resource_target: string
401-
readonly action: any
402-
readonly diff: Record<string, { old: string; new: string }>
403-
readonly status_code: number
404-
// This is likely an enum in an external package ("encoding/json.RawMessage")
405-
readonly additional_fields: any
406-
readonly description: string
407-
readonly user?: User
408-
// This is likely an enum in an external package ("encoding/json.RawMessage")
409-
readonly resource:
410-
| TypesGen.Organization
411-
| TypesGen.Template
412-
| TypesGen.TemplateVersion
413-
| TypesGen.User
414-
| TypesGen.Workspace
415-
}
416-
417-
export const getAuditLogs = async (): Promise<AuditLog[]> => {
388+
export const getAuditLogs = async (): Promise<TypesGen.AuditLog[]> => {
418389
return [MockAuditLog]
390+
// TODO: Uncomment this to get the data from the API instead of mock
419391
// const response = await axios.get("/api/v2/audit")
420392
// return response.data
421393
}

site/src/api/typesGenerated.ts

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

621621
// From codersdk/workspacebuilds.go
622622
export type WorkspaceTransition = "delete" | "start" | "stop"
623+
624+
// TODO: Remove this when the generated types work for AuditLogs
625+
export interface AuditLog {
626+
readonly id: string
627+
readonly request_id: string
628+
readonly time: string
629+
readonly organization_id: string
630+
// Named type "net/netip.Addr" unknown, using "any"
631+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
632+
readonly ip: any
633+
readonly user_agent: string
634+
readonly resource_type: "organization" | "template" | "template_version" | "user" | "workspace"
635+
readonly resource_id: string
636+
readonly resource_target: string
637+
readonly action: "write" | "create" | "delete"
638+
readonly diff: Record<string, { old: number | string | boolean; new: number | string | boolean }>
639+
readonly status_code: number
640+
// This is likely an enum in an external package ("encoding/json.RawMessage")
641+
readonly additional_fields: Record<string, string>
642+
readonly description: string
643+
readonly user?: User
644+
// This is likely an enum in an external package ("encoding/json.RawMessage")
645+
readonly resource: Organization | Template | TemplateVersion | User | Workspace
646+
}

site/src/pages/AuditPage/AuditPageView.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ComponentMeta, Story } from "@storybook/react"
2-
import { MockAuditLog, MockAuditLogWithDiff } from "testHelpers/entities"
2+
import { MockAuditLog, MockAuditLog2 } from "testHelpers/entities"
33
import { AuditPageView } from "./AuditPageView"
44

55
export default {
@@ -11,7 +11,7 @@ const Template: Story = (args) => <AuditPageView {...args} />
1111

1212
export const AuditPage = Template.bind({})
1313
AuditPage.args = {
14-
auditLogs: [MockAuditLog, MockAuditLog, MockAuditLogWithDiff],
14+
auditLogs: [MockAuditLog, MockAuditLog2],
1515
}
1616

1717
export const AuditPageSmallViewport = Template.bind({})

site/src/pages/AuditPage/AuditPageView.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import TableCell from "@material-ui/core/TableCell"
77
import TableContainer from "@material-ui/core/TableContainer"
88
import TableHead from "@material-ui/core/TableHead"
99
import TableRow from "@material-ui/core/TableRow"
10-
import { AuditLog } from "api/api"
11-
import { Template, Workspace } from "api/typesGenerated"
10+
import { AuditLog, Template, Workspace } from "api/typesGenerated"
1211
import { CodeExample } from "components/CodeExample/CodeExample"
1312
import { CloseDropdown, OpenDropdown } from "components/DropdownArrows/DropdownArrows"
1413
import { Margins } from "components/Margins/Margins"
@@ -113,7 +112,7 @@ const ResourceLink: React.FC<{
113112
}
114113

115114
const actionLabelByAction: Record<AuditLog["action"], string> = {
116-
create: "created",
115+
create: "created a new",
117116
write: "updated",
118117
delete: "deleted",
119118
}

site/src/testHelpers/entities.ts

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { AuditLog } from "api/api"
21
import { FieldError } from "api/errors"
32
import * as Types from "../api/types"
43
import * as TypesGen from "../api/typesGenerated"
@@ -686,14 +685,14 @@ export const MockEntitlementsWithAuditLog: TypesGen.Entitlements = {
686685
},
687686
}
688687

689-
export const MockAuditLog: AuditLog = {
688+
export const MockAuditLog: TypesGen.AuditLog = {
690689
id: "fbd2116a-8961-4954-87ae-e4575bd29ce0",
691690
request_id: "53bded77-7b9d-4e82-8771-991a34d759f9",
692691
time: "2022-05-19T16:45:57.122Z",
693692
organization_id: "fc0774ce-cc9e-48d4-80ae-88f7a4d4a8b0",
694693
ip: "127.0.0.1",
695694
user_agent: "browser",
696-
resource_type: "organization",
695+
resource_type: "workspace",
697696
resource_id: "ef8d1cf4-82de-4fd9-8980-047dad6d06b5",
698697
resource_target: "Bruno's Org",
699698
action: "create",
@@ -702,24 +701,16 @@ export const MockAuditLog: AuditLog = {
702701
additional_fields: {},
703702
description: "Colin Adler updated the organization Bruno's Org",
704703
user: MockUser,
705-
resource: MockOrganization,
704+
resource: MockWorkspace,
706705
}
707706

708-
export const MockAuditLogWithDiff = {
709-
id: "fbd2116a-8961-4954-87ae-e4575bd29ce0",
710-
request_id: "53bded77-7b9d-4e82-8771-991a34d759f9",
711-
time: "2022-05-19T16:45:57.122Z",
712-
organization_id: "fc0774ce-cc9e-48d4-80ae-88f7a4d4a8b0",
713-
ip: "127.0.0.1",
714-
user_agent: "browser",
715-
resource_type: "organization",
716-
resource_id: "ef8d1cf4-82de-4fd9-8980-047dad6d06b5",
717-
resource_target: "Bruno's Org",
707+
export const MockAuditLog2: TypesGen.AuditLog = {
708+
...MockAuditLog,
718709
action: "write",
719710
diff: {
720711
workspace_name: {
721-
old: "alice-workspace",
722-
new: "aharvey",
712+
old: "old-workspace-name",
713+
new: MockWorkspace.name,
723714
},
724715
workspace_auto_off: {
725716
old: true,
@@ -730,9 +721,4 @@ export const MockAuditLogWithDiff = {
730721
new: "53bded77-7b9d-4e82-8771-991a34d759f9",
731722
},
732723
},
733-
status_code: 200,
734-
additional_fields: {},
735-
description: "Colin Adler updated the organization Bruno's Org",
736-
user: MockUser,
737-
resource: MockOrganization,
738724
}

0 commit comments

Comments
 (0)