Skip to content

Commit b968d2f

Browse files
author
linyuan.yang
committed
agenda memory
1 parent 7b84990 commit b968d2f

7 files changed

Lines changed: 322 additions & 132 deletions

File tree

‎packages/admin/src/components/modals/AgendaListModal.vue‎

Lines changed: 138 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,33 @@
11
<script setup lang="ts">
22
import { computed, ref, watch } from 'vue'
33
import { useI18n } from 'vue-i18n'
4-
import { SModal } from 'sbot-ui'
4+
import { SBadge, SButton, SModal, STab, STabBar, useToast } from 'sbot-ui'
55
import AgendaBoard from '@/components/AgendaBoard.vue'
66
import AgendaTriggerEditModal from '@/components/modals/AgendaTriggerEditModal.vue'
77
import AgendaFiresModal from '@/components/modals/AgendaFiresModal.vue'
88
import { useAgendas, type AgendaRow, type AgendaTrigger } from '@/composables/useAgendas'
9+
import { apiFetch } from '@/shared/api'
10+
11+
interface AgendaJob {
12+
id: number
13+
channelSessionId: number
14+
messageCount: number
15+
status: 'pending' | 'failed'
16+
attemptCount: number
17+
errorMessage: string | null
18+
createdAt: number
19+
updatedAt: number
20+
}
921
1022
const { t } = useI18n()
23+
const { show } = useToast()
1124
1225
const visible = ref(false)
1326
const agendaIdRef = ref('')
1427
const sessionLabel = ref('')
28+
const tab = ref<'items' | 'jobs'>('items')
29+
const jobsLoading = ref(false)
30+
const jobs = ref<AgendaJob[]>([])
1531
1632
const {
1733
loading,
@@ -59,9 +75,38 @@ function onTriggerSubmit(payload: { row: AgendaRow; spec: Record<string, unknown
5975
6076
const title = computed(() => sessionLabel.value ? `${t('agenda.title')} - ${sessionLabel.value}` : t('agenda.title'))
6177
78+
async function loadJobs(): Promise<void> {
79+
if (!agendaIdRef.value) return
80+
jobsLoading.value = true
81+
try {
82+
const query = `agendaId=${encodeURIComponent(agendaIdRef.value)}&limit=50`
83+
const res = await apiFetch(`/api/agendas/jobs?${query}`)
84+
jobs.value = (res.data?.jobs || []) as AgendaJob[]
85+
} catch (e: any) {
86+
show(e.message, 'error')
87+
} finally {
88+
jobsLoading.value = false
89+
}
90+
}
91+
92+
function fmtTime(value: number | null | undefined): string {
93+
if (!value) return '-'
94+
return new Date(value).toLocaleString()
95+
}
96+
97+
function jobStatusLabel(status: AgendaJob['status']): string {
98+
return t(status === 'failed' ? 'agenda.job_status_failed' : 'agenda.job_status_pending')
99+
}
100+
101+
function jobVariant(status: AgendaJob['status']): 'warning' | 'danger' {
102+
return status === 'failed' ? 'danger' : 'warning'
103+
}
104+
62105
async function openByAgendaId(agendaId: string | null | undefined, label?: string) {
63106
agendaIdRef.value = agendaId ? String(agendaId) : ''
64107
sessionLabel.value = label || (agendaId ? String(agendaId) : '')
108+
tab.value = 'items'
109+
jobs.value = []
65110
visible.value = true
66111
if (agendaIdRef.value) await load()
67112
}
@@ -70,12 +115,26 @@ watch(statusFilter, () => {
70115
if (visible.value && agendaIdRef.value) load()
71116
})
72117
118+
watch(tab, value => {
119+
if (value === 'jobs' && visible.value && agendaIdRef.value) loadJobs()
120+
})
121+
73122
defineExpose({ openByAgendaId })
74123
</script>
75124

76125
<template>
77126
<SModal v-model:visible="visible" :title="title" width="xl">
127+
<div class="agenda-viewer-tabs">
128+
<STabBar v-model="tab" class="agenda-tabs">
129+
<STab name="items">{{ t('agenda.viewer_items') }}</STab>
130+
<STab name="jobs">{{ t('agenda.viewer_jobs') }}</STab>
131+
</STabBar>
132+
<SButton v-if="tab === 'jobs'" type="outline" size="sm" :loading="jobsLoading" @click="loadJobs">
133+
{{ t('common.refresh') }}
134+
</SButton>
135+
</div>
78136
<AgendaBoard
137+
v-if="tab === 'items'"
79138
v-model:status-filter="statusFilter"
80139
:items="sortedAgendas"
81140
:loading="loading"
@@ -100,7 +159,85 @@ defineExpose({ openByAgendaId })
100159
@update-trigger="updateTrigger"
101160
@add-trigger="onAddTrigger"
102161
/>
162+
<div v-else class="agenda-jobs">
163+
<div v-if="jobsLoading" class="agenda-jobs-empty">{{ t('common.loading') }}</div>
164+
<div v-else-if="jobs.length === 0" class="agenda-jobs-empty">{{ t('agenda.no_jobs') }}</div>
165+
<article v-for="job in jobs" v-else :key="job.id" class="agenda-job">
166+
<div class="agenda-job-head">
167+
<strong>#{{ job.id }}</strong>
168+
<SBadge :variant="jobVariant(job.status)" size="sm">{{ jobStatusLabel(job.status) }}</SBadge>
169+
</div>
170+
<dl class="agenda-job-grid">
171+
<dt>{{ t('agenda.job_type') }}</dt><dd>{{ t('agenda.job_type_sync') }}</dd>
172+
<dt>{{ t('agenda.job_channel_session') }}</dt><dd><code>{{ job.channelSessionId || '-' }}</code></dd>
173+
<dt>{{ t('agenda.job_message_count') }}</dt><dd>{{ job.messageCount }}</dd>
174+
<dt>{{ t('agenda.attempt_count') }}</dt><dd>{{ job.attemptCount }}</dd>
175+
<dt>{{ t('agenda.created_at') }}</dt><dd><code>{{ fmtTime(job.createdAt) }}</code></dd>
176+
<dt>{{ t('agenda.updated_at') }}</dt><dd><code>{{ fmtTime(job.updatedAt) }}</code></dd>
177+
<dt>{{ t('agenda.error_message') }}</dt><dd><code>{{ job.errorMessage || '-' }}</code></dd>
178+
</dl>
179+
</article>
180+
</div>
103181
<AgendaTriggerEditModal ref="triggerEditModal" @submit="onTriggerSubmit" />
104182
<AgendaFiresModal ref="firesModal" />
105183
</SModal>
106184
</template>
185+
186+
<style scoped>
187+
.agenda-viewer-tabs {
188+
display: flex;
189+
align-items: center;
190+
justify-content: space-between;
191+
gap: var(--sui-sp-3);
192+
margin-bottom: var(--sui-sp-4);
193+
border-bottom: 1px solid var(--sui-border-subtle);
194+
}
195+
196+
.agenda-tabs {
197+
padding: 0;
198+
border-bottom: 0;
199+
background: transparent;
200+
}
201+
202+
.agenda-jobs {
203+
min-height: 520px;
204+
max-height: 68vh;
205+
overflow: auto;
206+
}
207+
208+
.agenda-job {
209+
padding: var(--sui-sp-3);
210+
margin-bottom: var(--sui-sp-2);
211+
border: 1px solid var(--sui-border-subtle);
212+
border-radius: var(--sui-radius-sm);
213+
}
214+
215+
.agenda-job-head {
216+
display: flex;
217+
align-items: center;
218+
justify-content: space-between;
219+
gap: var(--sui-sp-2);
220+
}
221+
222+
.agenda-job-grid {
223+
display: grid;
224+
grid-template-columns: 120px minmax(0, 1fr);
225+
gap: var(--sui-sp-2);
226+
margin: var(--sui-sp-3) 0 0;
227+
font-size: var(--sui-fs-sm);
228+
}
229+
230+
.agenda-job-grid dt { color: var(--sui-fg-muted); }
231+
.agenda-job-grid dd { margin: 0; overflow-wrap: anywhere; }
232+
.agenda-job-grid code { font-family: var(--sui-font-mono); font-size: var(--sui-fs-xs); }
233+
234+
.agenda-jobs-empty {
235+
padding: var(--sui-sp-4);
236+
color: var(--sui-fg-muted);
237+
text-align: center;
238+
}
239+
240+
@media (max-width: 700px) {
241+
.agenda-job-grid { grid-template-columns: 1fr; }
242+
}
243+
</style>

0 commit comments

Comments
 (0)