Skip to content

Commit b40a80e

Browse files
committed
Update frontend, wip
1 parent 04efd25 commit b40a80e

File tree

6 files changed

+15
-39
lines changed

6 files changed

+15
-39
lines changed

codersdk/audit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ type AuditLogsRequest struct {
113113

114114
type AuditLogResponse struct {
115115
AuditLogs []AuditLog `json:"audit_logs"`
116-
Count int64 `json:"q, omitempty"`
116+
Count int64 `json:"count, omitempty"`
117117
}
118118

119119
type CreateTestAuditLogRequest struct {

site/src/api/api.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -554,14 +554,6 @@ export const getAuditLogs = async (
554554
return response.data
555555
}
556556

557-
export const getAuditLogsCount = async (
558-
options: TypesGen.AuditLogCountRequest = {},
559-
): Promise<TypesGen.AuditLogCountResponse> => {
560-
const url = getURLWithSearchParams("/api/v2/audit/count", options)
561-
const response = await axios.get(url)
562-
return response.data
563-
}
564-
565557
export const getTemplateDAUs = async (
566558
templateId: string,
567559
): Promise<TypesGen.TemplateDAUsResponse> => {

site/src/api/typesGenerated.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export interface AuditLog {
7373
// From codersdk/audit.go
7474
export interface AuditLogResponse {
7575
readonly audit_logs: AuditLog[]
76-
readonly q: number
76+
readonly count: number
7777
}
7878

7979
// From codersdk/audit.go

site/src/pages/AuditPage/AuditPage.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe("AuditPage", () => {
3131
it("filters by typing", async () => {
3232
const getAuditLogsSpy = jest
3333
.spyOn(API, "getAuditLogs")
34-
.mockResolvedValue({ audit_logs: [MockAuditLog] })
34+
.mockResolvedValue({ audit_logs: [MockAuditLog], count: 1 })
3535

3636
render(<AuditPage />)
3737
await waitForLoaderToBeRemoved()
@@ -55,7 +55,7 @@ describe("AuditPage", () => {
5555
it("filters by URL", async () => {
5656
const getAuditLogsSpy = jest
5757
.spyOn(API, "getAuditLogs")
58-
.mockResolvedValue({ audit_logs: [MockAuditLog] })
58+
.mockResolvedValue({ audit_logs: [MockAuditLog], count: 1 })
5959

6060
const query = "resource_type:workspace action:create"
6161
history.push(`/audit?filter=${encodeURIComponent(query)}`)
@@ -69,7 +69,7 @@ describe("AuditPage", () => {
6969
it("resets page to 1 when filter is changed", async () => {
7070
const getAuditLogsSpy = jest
7171
.spyOn(API, "getAuditLogs")
72-
.mockResolvedValue({ audit_logs: [MockAuditLog] })
72+
.mockResolvedValue({ audit_logs: [MockAuditLog], count: 1 })
7373

7474
history.push(`/audit?page=2`)
7575
render(<AuditPage />)

site/src/testHelpers/handlers.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,11 @@ export const handlers = [
213213
ctx.status(200),
214214
ctx.json({
215215
audit_logs: [M.MockAuditLog, M.MockAuditLog2],
216+
count: 2
216217
}),
217218
)
218219
}),
219220

220-
rest.get("/api/v2/audit/count", (req, res, ctx) => {
221-
return res(ctx.status(200), ctx.json({ count: 1000 }))
222-
}),
223-
224221
// Applications host
225222
rest.get("/api/v2/applications/host", (req, res, ctx) => {
226223
return res(ctx.status(200), ctx.json({ host: "*.dev.coder.com" }))

site/src/xServices/audit/auditXService.ts

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { getAuditLogs, getAuditLogsCount } from "api/api"
1+
import { getAuditLogs } from "api/api"
22
import { getErrorMessage } from "api/errors"
3-
import { AuditLog } from "api/typesGenerated"
3+
import { AuditLog, AuditLogResponse } from "api/typesGenerated"
44
import { displayError } from "components/GlobalSnackbar/utils"
55
import { getPaginationData } from "components/PaginationWidget/utils"
66
import {
@@ -29,10 +29,7 @@ export const auditMachine = createMachine(
2929
context: {} as AuditContext,
3030
services: {} as {
3131
loadAuditLogsAndCount: {
32-
data: {
33-
auditLogs: AuditLog[]
34-
count: number
35-
}
32+
data: AuditLogResponse
3633
}
3734
},
3835
events: {} as
@@ -91,7 +88,7 @@ export const auditMachine = createMachine(
9188
auditLogs: (_) => undefined,
9289
}),
9390
assignAuditLogsAndCount: assign({
94-
auditLogs: (_, event) => event.data.auditLogs,
91+
auditLogs: (_, event) => event.data.audit_logs,
9592
count: (_, event) => event.data.count,
9693
}),
9794
assignPaginationRef: assign({
@@ -117,21 +114,11 @@ export const auditMachine = createMachine(
117114
loadAuditLogsAndCount: async (context) => {
118115
if (context.paginationRef) {
119116
const { offset, limit } = getPaginationData(context.paginationRef)
120-
const [auditLogs, count] = await Promise.all([
121-
getAuditLogs({
122-
offset,
123-
limit,
124-
q: context.filter,
125-
}).then((data) => data.audit_logs),
126-
getAuditLogsCount({
127-
q: context.filter,
128-
}).then((data) => data.count),
129-
])
130-
131-
return {
132-
auditLogs,
133-
count,
134-
}
117+
return getAuditLogs({
118+
offset,
119+
limit,
120+
q: context.filter,
121+
})
135122
} else {
136123
throw new Error("Cannot get audit logs without pagination data")
137124
}

0 commit comments

Comments
 (0)