Skip to content

Commit 5b63bf8

Browse files
fix: lift loading state to parent comp
1 parent 8a1aaa3 commit 5b63bf8

2 files changed

Lines changed: 35 additions & 23 deletions

File tree

frontend/src/components/audit-log/AuditLogBrowser.vue

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="ff-admin-audit">
33
<div data-el="audit-log">
44
<slot name="title" />
5-
<AuditLog :entries="logEntries" :associations="associations" :loading="gettingEntries" />
5+
<AuditLog :entries="logEntries" :associations="associations" :loading="loading" />
66
</div>
77
<div>
88
<SectionTopMenu hero="Filters" />
@@ -56,6 +56,10 @@ export default {
5656
type: Array,
5757
required: true
5858
},
59+
loading: {
60+
type: Boolean,
61+
required: true
62+
},
5963
associations: {
6064
type: Object,
6165
default: () => {}
@@ -68,7 +72,6 @@ export default {
6872
emits: ['load-entries'],
6973
data () {
7074
return {
71-
gettingEntries: true,
7275
auditFilters: {
7376
event: '',
7477
types: [],
@@ -98,22 +101,19 @@ export default {
98101
},
99102
watch: {
100103
'auditFilters.username': function () {
101-
if (this.gettingEntries) {
104+
if (this.loading) {
102105
return // skip if we're already loading entries
103106
}
104107
this.loadEntries()
105108
},
106109
'auditFilters.event': function () {
107-
if (this.gettingEntries) {
110+
if (this.loading) {
108111
return // skip if we're already loading entries
109112
}
110113
this.loadEntries()
111114
},
112115
users: function (users) {
113116
this.auditFilters.users = users
114-
},
115-
logEntries: function () {
116-
this.gettingEntries = false
117117
}
118118
119119
},
@@ -133,7 +133,6 @@ export default {
133133
* @param {string} [logType] The log type to load event type dropdown for
134134
*/
135135
loadEntries (scope, includeChildren, logType) {
136-
this.gettingEntries = true
137136
logType = logType || this.auditFilters.logType
138137
if (this.auditFilters.logType !== logType) {
139138
this.auditFilters.logType = logType // store the scope for later queries

frontend/src/pages/instance/AuditLog.vue

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<AuditLogBrowser ref="AuditLog" :users="users" :logEntries="logEntries" :associations="associations" logType="project" @load-entries="loadEntries">
2+
<AuditLogBrowser ref="AuditLog" :users="users" :logEntries="logEntries" :associations="associations" logType="project" :loading="loading" @load-entries="loadEntries">
33
<template #title>
44
<SectionTopMenu hero="Audit Log" info="Recorded events that have taken place in within this instance." />
55
</template>
@@ -49,6 +49,7 @@ export default {
4949
data () {
5050
return {
5151
logEntries: [],
52+
loading: true,
5253
associations: {}, // devices
5354
users: [],
5455
auditFilters: {
@@ -92,25 +93,37 @@ export default {
9293
* @param cursor - cursor to use for pagination
9394
*/
9495
async loadEntries (params = new URLSearchParams(), cursor = undefined) {
95-
if (this.instance.id) {
96-
const auditLog = (await InstanceApi.getInstanceAuditLog(this.instance.id, params, cursor, 200))
97-
this.logEntries = auditLog.log
98-
// dont show associations if we are looking at "this" scope (project)"
99-
let showAssociations = false
100-
if (this.auditFilters.selectedEventScope === 'device') {
101-
showAssociations = true
96+
try {
97+
if (this.instance.id) {
98+
const auditLog = (await InstanceApi.getInstanceAuditLog(this.instance.id, params, cursor, 200))
99+
this.logEntries = auditLog.log
100+
// dont show associations if we are looking at "this" scope (project)"
101+
let showAssociations = false
102+
if (this.auditFilters.selectedEventScope === 'device') {
103+
showAssociations = true
104+
}
105+
if (this.auditFilters.selectedEventScope === 'project' && this.auditFilters.includeChildren) {
106+
showAssociations = true
107+
}
108+
this.associations = showAssociations ? auditLog.associations : null
102109
}
103-
if (this.auditFilters.selectedEventScope === 'project' && this.auditFilters.includeChildren) {
104-
showAssociations = true
105-
}
106-
this.associations = showAssociations ? auditLog.associations : null
110+
} catch (error) {
111+
console.error('Failed to load audit logs:', error)
112+
this.auditLog = []
113+
} finally {
114+
this.loading = false
107115
}
108116
},
109117
triggerLoad ({ users = false, events = true } = {}) {
110118
// if `events` is true, call AuditLogBrowser.loadEntries - this will emit 'load-entries' event which calls this.loadEntries with appropriate params
111-
const eventTypes = this.auditFilters.selectedEventScope || 'instance'
112-
events && this.$refs.AuditLog?.loadEntries(this.auditFilters.selectedEventScope, this.auditFilters.includeChildren, eventTypes)
113-
users && this.loadUsers()
119+
if (events) {
120+
const eventTypes = this.auditFilters.selectedEventScope || 'instance'
121+
this.loading = true
122+
this.$refs.AuditLog?.loadEntries(this.auditFilters.selectedEventScope, this.auditFilters.includeChildren, eventTypes)
123+
}
124+
if (users) {
125+
this.loadUsers()
126+
}
114127
}
115128
116129
}

0 commit comments

Comments
 (0)