Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add audit log detail page #3356

Merged
merged 2 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions frontend/common/services/useAuditLogItem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Res } from 'common/types/responses'
import { Req } from 'common/types/requests'
import { service } from 'common/service'

export const auditLogItemService = service
.enhanceEndpoints({ addTagTypes: ['AuditLogItem'] })
.injectEndpoints({
endpoints: (builder) => ({
getAuditLogItem: builder.query<
Res['auditLogItem'],
Req['getAuditLogItem']
>({
providesTags: (res) => [{ id: res?.id, type: 'AuditLogItem' }],
query: (query: Req['getAuditLogItem']) => ({
url: `audit/${query.id}/`,
}),
}),
// END OF ENDPOINTS
}),
})

export async function getAuditLogItem(
store: any,
data: Req['getAuditLogItem'],
options?: Parameters<
typeof auditLogItemService.endpoints.getAuditLogItem.initiate
>[1],
) {
return store.dispatch(
auditLogItemService.endpoints.getAuditLogItem.initiate(data, options),
)
}
// END OF FUNCTION_EXPORTS

export const {
useGetAuditLogItemQuery,
// END OF EXPORTS
} = auditLogItemService

/* Usage examples:
const { data, isLoading } = useGetAuditLogItemQuery({ id: 2 }, {}) //get hook
const [createAuditLogItem, { isLoading, data, isSuccess }] = useCreateAuditLogItemMutation() //create hook
auditLogItemService.endpoints.getAuditLogItem.select({id: 2})(store.getState()) //access data from any function
*/
1 change: 1 addition & 0 deletions frontend/common/types/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,6 @@ export type Req = {
getGroupSummaries: {
orgId: string
}
getAuditLogItem: { id: string }
// END OF TYPES
}
8 changes: 8 additions & 0 deletions frontend/common/types/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ export type AuditLogItem = {
is_system_event: boolean
}

export type AuditLogDetail = AuditLogItem & {
change_details: {
field: string
old: FlagsmithValue
new: FlagsmithValue
}[]
}
export type Subscription = {
id: number
uuid: string
Expand Down Expand Up @@ -397,5 +404,6 @@ export type Res = {
groupWithRole: PagedResponse<Roles>
changeRequests: PagedResponse<ChangeRequestSummary>
groupSummaries: UserGroupSummary[]
auditLogItem: AuditLogDetail
// END OF TYPES
}
Loading
Loading