Merge pull request #15178 from Budibase/ts-portal-auditlogs-store

Convert portal audit logs store to typescript
This commit is contained in:
Andrew Kingston 2024-12-17 10:39:37 +00:00 committed by GitHub
commit a873fa7caf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 52 additions and 47 deletions

View File

@ -160,8 +160,8 @@
events: selectedEvents, events: selectedEvents,
}) })
logsPageInfo.fetched( logsPageInfo.fetched(
$auditLogs.logs.hasNextPage, $auditLogs.logs?.hasNextPage,
$auditLogs.logs.bookmark $auditLogs.logs?.bookmark
) )
} catch (error) { } catch (error) {
notifications.error(`Error getting audit logs - ${error}`) notifications.error(`Error getting audit logs - ${error}`)
@ -200,6 +200,8 @@
return Object.entries(obj).map(([id, label]) => { return Object.entries(obj).map(([id, label]) => {
return { id, label } return { id, label }
}) })
} else {
return []
} }
} }
@ -316,7 +318,7 @@
<Table <Table
on:click={({ detail }) => viewDetails(detail)} on:click={({ detail }) => viewDetails(detail)}
{customRenderers} {customRenderers}
data={$auditLogs.logs.data} data={$auditLogs.logs?.data}
allowEditColumns={false} allowEditColumns={false}
allowEditRows={false} allowEditRows={false}
allowSelectRows={false} allowSelectRows={false}

View File

@ -11,7 +11,7 @@ export default class BudiStore<T> implements Writable<T> {
set: Writable<T>["set"] set: Writable<T>["set"]
constructor(init: T, opts?: BudiStoreOpts) { constructor(init: T, opts?: BudiStoreOpts) {
const store = writable<T>({ ...init }) const store = writable<T>(init)
/** /**
* Internal Svelte store * Internal Svelte store

View File

@ -1,43 +0,0 @@
import { writable, get } from "svelte/store"
import { API } from "api"
import { licensing } from "stores/portal"
export function createAuditLogsStore() {
const { subscribe, update } = writable({
events: {},
logs: {},
})
async function search(opts = {}) {
if (get(licensing).auditLogsEnabled) {
const paged = await API.searchAuditLogs(opts)
update(state => {
return { ...state, logs: { ...paged, opts } }
})
return paged
}
}
async function getEventDefinitions() {
const events = await API.getEventDefinitions()
update(state => {
return { ...state, ...events }
})
}
function getDownloadUrl(opts = {}) {
return API.getDownloadUrl(opts)
}
return {
subscribe,
search,
getEventDefinitions,
getDownloadUrl,
}
}
export const auditLogs = createAuditLogsStore()

View File

@ -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()

View File

@ -24,6 +24,7 @@ export const createLicensingStore = () => {
scimEnabled: false, scimEnabled: false,
budibaseAIEnabled: false, budibaseAIEnabled: false,
customAIConfigsEnabled: false, customAIConfigsEnabled: false,
auditLogsEnabled: false,
// the currently used quotas from the db // the currently used quotas from the db
quotaUsage: undefined, quotaUsage: undefined,
// derived quota metrics for percentages used // derived quota metrics for percentages used