Skip to content

Commit

Permalink
Merge pull request #15178 from Budibase/ts-portal-auditlogs-store
Browse files Browse the repository at this point in the history
Convert portal audit logs store to typescript
  • Loading branch information
aptkingston authored Dec 17, 2024
2 parents e3d2041 + f8a4b42 commit a873fa7
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@
events: selectedEvents,
})
logsPageInfo.fetched(
$auditLogs.logs.hasNextPage,
$auditLogs.logs.bookmark
$auditLogs.logs?.hasNextPage,
$auditLogs.logs?.bookmark
)
} catch (error) {
notifications.error(`Error getting audit logs - ${error}`)
Expand Down Expand Up @@ -200,6 +200,8 @@
return Object.entries(obj).map(([id, label]) => {
return { id, label }
})
} else {
return []
}
}
Expand Down Expand Up @@ -316,7 +318,7 @@
<Table
on:click={({ detail }) => viewDetails(detail)}
{customRenderers}
data={$auditLogs.logs.data}
data={$auditLogs.logs?.data}
allowEditColumns={false}
allowEditRows={false}
allowSelectRows={false}
Expand Down
2 changes: 1 addition & 1 deletion packages/builder/src/stores/BudiStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class BudiStore<T> implements Writable<T> {
set: Writable<T>["set"]

constructor(init: T, opts?: BudiStoreOpts) {
const store = writable<T>({ ...init })
const store = writable<T>(init)

/**
* Internal Svelte store
Expand Down
43 changes: 0 additions & 43 deletions packages/builder/src/stores/portal/auditLogs.js

This file was deleted.

45 changes: 45 additions & 0 deletions packages/builder/src/stores/portal/auditLogs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { get } from "svelte/store"
import { API } from "api"
import { licensing } from "./licensing"
import BudiStore from "../BudiStore"
import {
DownloadAuditLogsRequest,
SearchAuditLogsRequest,
SearchAuditLogsResponse,
} from "@budibase/types"

interface PortalAuditLogsStore {
events?: Record<string, string>
logs?: SearchAuditLogsResponse
}

export class AuditLogsStore extends BudiStore<PortalAuditLogsStore> {
constructor() {
super({})
}

async search(opts: SearchAuditLogsRequest = {}) {
if (get(licensing).auditLogsEnabled) {
const res = await API.searchAuditLogs(opts)
this.update(state => ({
...state,
logs: res,
}))
return res
}
}

async getEventDefinitions() {
const res = await API.getEventDefinitions()
this.update(state => ({
...state,
events: res.events,
}))
}

getDownloadUrl(opts: DownloadAuditLogsRequest = {}) {
return API.getDownloadUrl(opts)
}
}

export const auditLogs = new AuditLogsStore()
1 change: 1 addition & 0 deletions packages/builder/src/stores/portal/licensing.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const createLicensingStore = () => {
scimEnabled: false,
budibaseAIEnabled: false,
customAIConfigsEnabled: false,
auditLogsEnabled: false,
// the currently used quotas from the db
quotaUsage: undefined,
// derived quota metrics for percentages used
Expand Down

0 comments on commit a873fa7

Please sign in to comment.