-
Notifications
You must be signed in to change notification settings - Fork 317
Add API usage log table #4288
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
Merged
+1,294
−3
Merged
Add API usage log table #4288
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
85dfbea
usage log table
jtydhr88 ab64623
Update locales [skip ci]
invalid-email-address e16af08
tooltip and i18n improve
jtydhr88 3a70bcf
Update locales [skip ci]
invalid-email-address 18eedb6
improve customerService
jtydhr88 1de9650
refactor code
jtydhr88 855d199
improve tooltip
jtydhr88 f9cbde8
add test for customerEventsService.ts
jtydhr88 d402b6d
add test for UsageLogsTable.vue
jtydhr88 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
188 changes: 188 additions & 0 deletions
188
src/components/dialog/content/setting/UsageLogsTable.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
<template> | ||
<div> | ||
<div v-if="loading" class="flex items-center justify-center p-8"> | ||
<ProgressSpinner /> | ||
</div> | ||
<div v-else-if="error" class="p-4"> | ||
<Message severity="error" :closable="false">{{ error }}</Message> | ||
</div> | ||
<DataTable | ||
v-else | ||
:value="events" | ||
:paginator="true" | ||
:rows="pagination.limit" | ||
:total-records="pagination.total" | ||
:first="dataTableFirst" | ||
:lazy="true" | ||
class="p-datatable-sm custom-datatable" | ||
@page="onPageChange" | ||
> | ||
<Column field="event_type" :header="$t('credits.eventType')"> | ||
<template #body="{ data }"> | ||
<Badge | ||
:value="customerEventService.formatEventType(data.event_type)" | ||
:severity="customerEventService.getEventSeverity(data.event_type)" | ||
/> | ||
</template> | ||
</Column> | ||
<Column field="details" :header="$t('credits.details')"> | ||
<template #body="{ data }"> | ||
<div class="event-details"> | ||
<!-- Credits Added --> | ||
<template v-if="data.event_type === EventType.CREDIT_ADDED"> | ||
<div class="text-green-500 font-semibold"> | ||
{{ $t('credits.added') }} ${{ | ||
customerEventService.formatAmount(data.params?.amount) | ||
}} | ||
</div> | ||
</template> | ||
|
||
<!-- Account Created --> | ||
<template v-else-if="data.event_type === EventType.ACCOUNT_CREATED"> | ||
<div>{{ $t('credits.accountInitialized') }}</div> | ||
</template> | ||
|
||
<!-- API Usage --> | ||
<template | ||
v-else-if="data.event_type === EventType.API_USAGE_COMPLETED" | ||
> | ||
<div class="flex flex-col gap-1"> | ||
<div class="font-semibold"> | ||
{{ data.params?.api_name || 'API' }} | ||
</div> | ||
<div class="text-sm text-gray-400"> | ||
{{ $t('credits.model') }}: {{ data.params?.model || '-' }} | ||
</div> | ||
</div> | ||
</template> | ||
</div> | ||
</template> | ||
</Column> | ||
<Column field="createdAt" :header="$t('credits.time')"> | ||
<template #body="{ data }"> | ||
{{ customerEventService.formatDate(data.createdAt) }} | ||
</template> | ||
</Column> | ||
<Column field="params" :header="$t('credits.additionalInfo')"> | ||
<template #body="{ data }"> | ||
<Button | ||
v-if="customerEventService.hasAdditionalInfo(data)" | ||
v-tooltip.top="{ | ||
escape: false, | ||
value: tooltipContentMap.get(data.event_id) || '', | ||
pt: { | ||
text: { | ||
style: { | ||
width: 'max-content !important' | ||
} | ||
} | ||
} | ||
}" | ||
icon="pi pi-info-circle" | ||
class="p-button-text p-button-sm" | ||
/> | ||
</template> | ||
</Column> | ||
</DataTable> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import Badge from 'primevue/badge' | ||
import Button from 'primevue/button' | ||
import Column from 'primevue/column' | ||
import DataTable from 'primevue/datatable' | ||
import Message from 'primevue/message' | ||
import ProgressSpinner from 'primevue/progressspinner' | ||
import { computed, ref } from 'vue' | ||
|
||
import { | ||
AuditLog, | ||
EventType, | ||
useCustomerEventsService | ||
} from '@/services/customerEventsService' | ||
|
||
const events = ref<AuditLog[]>([]) | ||
const loading = ref(true) | ||
const error = ref<string | null>(null) | ||
|
||
const customerEventService = useCustomerEventsService() | ||
|
||
const pagination = ref({ | ||
page: 1, | ||
limit: 7, | ||
total: 0, | ||
totalPages: 0 | ||
}) | ||
|
||
const dataTableFirst = computed( | ||
() => (pagination.value.page - 1) * pagination.value.limit | ||
) | ||
|
||
const tooltipContentMap = computed(() => { | ||
const map = new Map<string, string>() | ||
events.value.forEach((event) => { | ||
if (customerEventService.hasAdditionalInfo(event) && event.event_id) { | ||
map.set(event.event_id, customerEventService.getTooltipContent(event)) | ||
} | ||
}) | ||
return map | ||
}) | ||
|
||
const loadEvents = async () => { | ||
loading.value = true | ||
error.value = null | ||
|
||
try { | ||
const response = await customerEventService.getMyEvents({ | ||
page: pagination.value.page, | ||
limit: pagination.value.limit | ||
}) | ||
|
||
if (response) { | ||
if (response.events) { | ||
events.value = response.events | ||
} | ||
|
||
if (response.page) { | ||
pagination.value.page = response.page | ||
} | ||
|
||
if (response.limit) { | ||
pagination.value.limit = response.limit | ||
} | ||
|
||
if (response.total) { | ||
pagination.value.total = response.total | ||
} | ||
|
||
if (response.totalPages) { | ||
pagination.value.totalPages = response.totalPages | ||
} | ||
} else { | ||
error.value = customerEventService.error.value || 'Failed to load events' | ||
} | ||
} catch (err) { | ||
error.value = err instanceof Error ? err.message : 'Unknown error' | ||
console.error('Error loading events:', err) | ||
} finally { | ||
loading.value = false | ||
} | ||
} | ||
|
||
const onPageChange = (event: { page: number }) => { | ||
pagination.value.page = event.page + 1 | ||
void loadEvents() | ||
} | ||
|
||
const refresh = async () => { | ||
pagination.value.page = 1 | ||
await loadEvents() | ||
} | ||
|
||
defineExpose({ | ||
refresh | ||
}) | ||
</script> | ||
|
||
<style scoped></style> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.