ActionDetailsView.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. <template>
  2. <Section
  3. :icon="PlayIcon"
  4. :padding="false"
  5. >
  6. <template #title>
  7. <span class="section-title-with-icon">
  8. Action Details:
  9. <ActionIconGlyph
  10. v-if="action"
  11. class="action-title-icon"
  12. :glyph="action.icon"
  13. />
  14. {{ actionTitle }}
  15. </span>
  16. </template>
  17. <template #toolbar>
  18. <button
  19. v-for="dashboard in backToDashboards"
  20. :key="dashboard.path"
  21. :title="'Back to ' + dashboard.title"
  22. class="button neutral inline-icon"
  23. @click="goToDashboard(dashboard.path)"
  24. >
  25. <HugeiconsIcon :icon="DashboardSquare01Icon" />
  26. {{ dashboard.title }}
  27. </button>
  28. <button
  29. v-if="action"
  30. title="Run this action"
  31. class="button neutral inline-icon"
  32. @click="startAction"
  33. >
  34. <HugeiconsIcon :icon="WorkoutRunIcon" />
  35. Run
  36. </button>
  37. <router-link
  38. v-if="action"
  39. :to="{ name: 'ActionExecConditions', params: { actionId: route.params.actionId } }"
  40. class="button neutral"
  41. title="View configured automatic triggers and on-demand execution"
  42. >
  43. Execution conditions ({{ executionConditionCount }})
  44. </router-link>
  45. </template>
  46. <div
  47. v-if="action"
  48. class="flex-row padding"
  49. >
  50. <div class="fg1">
  51. <dl>
  52. <dt>Timeout</dt>
  53. <dd>{{ action.timeout }} seconds</dd>
  54. <template v-if="actionGroups.length > 0">
  55. <dt>
  56. <router-link
  57. :to="{ name: 'LogsQueue' }"
  58. class="action-groups-link"
  59. >
  60. Action groups
  61. </router-link>
  62. </dt>
  63. <dd>
  64. <ul class="action-group-list">
  65. <li
  66. v-for="group in actionGroups"
  67. :key="group.name"
  68. class="action-group-row"
  69. >
  70. <router-link
  71. :to="{ name: 'LogsQueue' }"
  72. class="action-groups-link action-group-name"
  73. >
  74. {{ group.name }}
  75. </router-link><template v-if="group.maxConcurrent > 0 && group.queueSize > 0">
  76. -
  77. </template><ActionGroupLimitsLabel
  78. :max-concurrent="group.maxConcurrent"
  79. :queue-size="group.queueSize"
  80. />
  81. </li>
  82. </ul>
  83. </dd>
  84. </template>
  85. </dl>
  86. <p class="fg1">
  87. Execution history for this action. You can filter by execution tracking ID.
  88. </p>
  89. </div>
  90. <div style="align-self: start; text-align: right;">
  91. <div class="filter-container">
  92. <label class="input-with-icons">
  93. <svg
  94. xmlns="http://www.w3.org/2000/svg"
  95. width="1em"
  96. height="1em"
  97. viewBox="0 0 24 24"
  98. >
  99. <path
  100. fill="currentColor"
  101. d="m19.6 21l-6.3-6.3q-.75.6-1.725.95T9.5 16q-2.725 0-4.612-1.888T3 9.5t1.888-4.612T9.5 3t4.613 1.888T16 9.5q0 1.1-.35 2.075T14.7 13.3l6.3 6.3zM9.5 14q1.875 0 3.188-1.312T14 9.5t-1.312-3.187T9.5 5T6.313 6.313T5 9.5t1.313 3.188T9.5 14"
  102. />
  103. </svg>
  104. <input
  105. v-model="searchText"
  106. placeholder="Filter current page"
  107. >
  108. <button
  109. title="Clear search filter"
  110. :disabled="!searchText"
  111. @click="clearSearch"
  112. >
  113. <svg
  114. xmlns="http://www.w3.org/2000/svg"
  115. width="1em"
  116. height="1em"
  117. viewBox="0 0 24 24"
  118. >
  119. <path
  120. fill="currentColor"
  121. d="M19 6.41L17.59 5L12 10.59L6.41 5L5 6.41L10.59 12L5 17.59L6.41 19L12 13.41L17.59 19L19 17.59L13.41 12z"
  122. />
  123. </svg>
  124. </button>
  125. </label>
  126. </div>
  127. </div>
  128. </div>
  129. <div v-show="filteredLogs.length > 0">
  130. <ExecutionLogsTable
  131. variant="action-history"
  132. :logs="filteredLogs"
  133. :loading="loading"
  134. >
  135. <template #duration="{ row }">
  136. {{ formatExecutionDuration(row) }}
  137. </template>
  138. </ExecutionLogsTable>
  139. <Pagination
  140. :page-size="pageSize"
  141. :total="totalCount"
  142. :current-page="currentPage"
  143. class="padding"
  144. item-title="execution logs"
  145. @page-change="handlePageChange"
  146. @page-size-change="handlePageSizeChange"
  147. />
  148. </div>
  149. <div
  150. v-show="logs.length === 0 && !loading"
  151. class="empty-state"
  152. >
  153. <p>This action has no execution history.</p>
  154. <router-link to="/">
  155. Return to index
  156. </router-link>
  157. </div>
  158. </Section>
  159. </template>
  160. <script setup>
  161. import { ref, computed, onMounted, onUnmounted, watch } from 'vue'
  162. import { useRoute, useRouter } from 'vue-router'
  163. import Pagination from 'picocrank/vue/components/Pagination.vue'
  164. import Section from 'picocrank/vue/components/Section.vue'
  165. import ActionIconGlyph from '../components/ActionIconGlyph.vue'
  166. import ActionGroupLimitsLabel from '../components/ActionGroupLimitsLabel.vue'
  167. import ExecutionLogsTable from '../components/ExecutionLogsTable.vue'
  168. import { HugeiconsIcon } from '@hugeicons/vue'
  169. import { DashboardSquare01Icon, PlayIcon, WorkoutRunIcon } from '@hugeicons/core-free-icons'
  170. import { requestReconnectNow } from '../../../js/websocket.js'
  171. import { needsArgumentForm } from '../utils/needsArgumentForm.js'
  172. import { getExecutionLogEntry, updateLogEntryInList } from '../utils/executionLogEvents.js'
  173. import { countExecutionConditions } from '../utils/executionConditionCount.js'
  174. const route = useRoute()
  175. const router = useRouter()
  176. const logs = ref([])
  177. const action = ref(null)
  178. const backToDashboards = ref([])
  179. const actionTitle = ref('Action Details')
  180. const searchText = ref('')
  181. const pageSize = ref(10)
  182. const currentPage = ref(1)
  183. const loading = ref(false)
  184. const totalCount = ref(0)
  185. const durationClock = ref(Date.now())
  186. let durationTicker = null
  187. const filteredLogs = computed(() => {
  188. if (!searchText.value) {
  189. return logs.value
  190. }
  191. const searchLower = searchText.value.toLowerCase()
  192. return logs.value.filter(log =>
  193. log.executionTrackingId.toLowerCase().includes(searchLower) ||
  194. log.actionTitle.toLowerCase().includes(searchLower) ||
  195. (log.justification || '').toLowerCase().includes(searchLower)
  196. )
  197. })
  198. const executionConditionCount = computed(() => countExecutionConditions(action.value))
  199. const actionGroups = computed(() => action.value?.groups ?? [])
  200. async function fetchActionLogs () {
  201. loading.value = true
  202. try {
  203. const actionId = route.params.actionId
  204. const startOffset = (currentPage.value - 1) * pageSize.value
  205. const args = {
  206. actionId,
  207. startOffset: BigInt(startOffset),
  208. pageSize: BigInt(Number(pageSize.value))
  209. }
  210. const response = await window.client.getActionLogs(args)
  211. logs.value = response.logs
  212. const serverPageSize = Number(response.pageSize)
  213. if (Number.isFinite(serverPageSize) && serverPageSize > 0) {
  214. pageSize.value = serverPageSize
  215. }
  216. totalCount.value = Number(response.totalCount) || 0
  217. syncDurationTicker()
  218. } catch (err) {
  219. console.error('Failed to fetch action logs:', err)
  220. window.showBigError('fetch-action-logs', 'getting action logs', err, false)
  221. } finally {
  222. loading.value = false
  223. }
  224. }
  225. async function fetchAction () {
  226. try {
  227. const actionId = route.params.actionId
  228. const args = {
  229. bindingId: actionId
  230. }
  231. const response = await window.client.getActionBinding(args)
  232. action.value = response.action
  233. backToDashboards.value = (response.backToDashboards || []).slice(0, 3)
  234. actionTitle.value = action.value?.title || 'Unknown Action'
  235. } catch (err) {
  236. console.error('Failed to fetch action:', err)
  237. window.showBigError('fetch-action', 'getting action details', err, false)
  238. }
  239. }
  240. function goToDashboard (path) {
  241. router.push(path)
  242. }
  243. function resetState () {
  244. action.value = null
  245. backToDashboards.value = []
  246. actionTitle.value = 'Action Details'
  247. logs.value = []
  248. totalCount.value = 0
  249. currentPage.value = 1
  250. searchText.value = ''
  251. loading.value = true
  252. syncDurationTicker()
  253. }
  254. function clearSearch () {
  255. searchText.value = ''
  256. }
  257. function plural (n, singular, pluralForm) {
  258. return n === 1 ? `1 ${singular}` : `${n} ${pluralForm}`
  259. }
  260. function formatDurationSimple (ms) {
  261. if (!Number.isFinite(ms) || ms < 0) {
  262. return '—'
  263. }
  264. const totalSec = Math.round(ms / 1000)
  265. if (totalSec === 0) {
  266. return '0 seconds'
  267. }
  268. const days = Math.floor(totalSec / 86400)
  269. const hours = Math.floor((totalSec % 86400) / 3600)
  270. const minutes = Math.floor((totalSec % 3600) / 60)
  271. const seconds = totalSec % 60
  272. const parts = []
  273. if (days > 0) parts.push(plural(days, 'day', 'days'))
  274. if (hours > 0) parts.push(plural(hours, 'hour', 'hours'))
  275. if (minutes > 0) parts.push(plural(minutes, 'minute', 'minutes'))
  276. if (seconds > 0) parts.push(plural(seconds, 'second', 'seconds'))
  277. return parts.join(' ')
  278. }
  279. function formatExecutionDuration (log) {
  280. // Reading durationClock keeps this column reactive while executions are in progress.
  281. const clock = durationClock.value
  282. if (!log?.datetimeStarted) {
  283. return '—'
  284. }
  285. const started = new Date(log.datetimeStarted)
  286. if (Number.isNaN(started.getTime())) {
  287. return '—'
  288. }
  289. let endMs
  290. if (log.executionFinished) {
  291. const finished = new Date(log.datetimeFinished)
  292. if (Number.isNaN(finished.getTime())) {
  293. return '—'
  294. }
  295. endMs = finished.getTime()
  296. } else {
  297. endMs = clock
  298. }
  299. return formatDurationSimple(endMs - started.getTime())
  300. }
  301. function syncDurationTicker () {
  302. if (durationTicker != null) {
  303. clearInterval(durationTicker)
  304. durationTicker = null
  305. }
  306. const hasRunning = logs.value.some(l => !l.executionFinished)
  307. if (!hasRunning) {
  308. return
  309. }
  310. durationTicker = window.setInterval(() => {
  311. durationClock.value = Date.now()
  312. }, 1000)
  313. }
  314. function handlePageChange (page) {
  315. currentPage.value = page
  316. fetchActionLogs()
  317. }
  318. function handlePageSizeChange (newPageSize) {
  319. pageSize.value = newPageSize
  320. currentPage.value = 1
  321. fetchActionLogs()
  322. }
  323. async function startAction () {
  324. if (!action.value || !action.value.bindingId) {
  325. console.error('Cannot start action: no binding ID')
  326. return
  327. }
  328. if (needsArgumentForm(action.value)) {
  329. router.push(`/actionBinding/${action.value.bindingId}/argumentForm`)
  330. return
  331. }
  332. try {
  333. requestReconnectNow()
  334. const args = {
  335. bindingId: action.value.bindingId,
  336. arguments: []
  337. }
  338. const response = await window.client.startAction(args)
  339. router.push(`/logs/${response.executionTrackingId}`)
  340. } catch (err) {
  341. console.error('Failed to start action:', err)
  342. window.showBigError('start-action', 'starting action', err, false)
  343. }
  344. }
  345. function onExecutionEvent (evt) {
  346. const logEntry = getExecutionLogEntry(evt)
  347. if (!logEntry || logEntry.bindingId !== route.params.actionId) {
  348. return
  349. }
  350. if (!updateLogEntryInList(logs.value, logEntry)) {
  351. fetchActionLogs()
  352. return
  353. }
  354. syncDurationTicker()
  355. }
  356. onMounted(() => {
  357. fetchAction()
  358. fetchActionLogs()
  359. window.addEventListener('EventExecutionStarted', onExecutionEvent)
  360. window.addEventListener('EventExecutionFinished', onExecutionEvent)
  361. })
  362. watch(
  363. () => route.params.actionId,
  364. () => {
  365. resetState()
  366. fetchAction()
  367. fetchActionLogs()
  368. },
  369. { immediate: false }
  370. )
  371. onUnmounted(() => {
  372. window.removeEventListener('EventExecutionStarted', onExecutionEvent)
  373. window.removeEventListener('EventExecutionFinished', onExecutionEvent)
  374. if (durationTicker != null) {
  375. clearInterval(durationTicker)
  376. durationTicker = null
  377. }
  378. })
  379. </script>
  380. <style scoped>
  381. .section-title-with-icon {
  382. display: inline-flex;
  383. align-items: center;
  384. gap: 0.5rem;
  385. }
  386. .action-title-icon {
  387. font-size: 1.5rem;
  388. }
  389. .empty-state {
  390. padding: 2rem;
  391. text-align: center;
  392. color: var(--text-secondary);
  393. }
  394. .filter-container {
  395. display: flex;
  396. justify-content: flex-end;
  397. padding: 0.5rem 1rem;
  398. }
  399. .input-with-icons {
  400. display: flex;
  401. align-items: center;
  402. gap: 0.5rem;
  403. padding: 0.5rem;
  404. border: 1px solid var(--border-color);
  405. border-radius: 0.25rem;
  406. background: var(--section-background);
  407. width: 100%;
  408. max-width: 300px;
  409. }
  410. .input-with-icons input {
  411. border: none;
  412. outline: none;
  413. background: transparent;
  414. flex: 1;
  415. color: var(--text-primary);
  416. }
  417. .input-with-icons button {
  418. background: none;
  419. border: none;
  420. cursor: pointer;
  421. color: var(--text-secondary);
  422. }
  423. .input-with-icons button:disabled {
  424. opacity: 0.3;
  425. cursor: not-allowed;
  426. }
  427. .tags {
  428. display: flex;
  429. flex-wrap: wrap;
  430. gap: 0.5rem;
  431. }
  432. .annotation {
  433. display: inline-flex;
  434. align-items: center;
  435. gap: 0.25rem;
  436. font-size: 0.85rem;
  437. }
  438. .annotation-key {
  439. font-weight: 600;
  440. color: var(--text-secondary);
  441. }
  442. .annotation-val {
  443. color: var(--text-primary);
  444. }
  445. .tag-list {
  446. display: inline-flex;
  447. gap: 0.25rem;
  448. }
  449. .tag {
  450. background-color: var(--accent-color);
  451. color: var(--accent-text);
  452. padding: 0.1rem 0.5rem;
  453. border-radius: 0.25rem;
  454. font-size: 0.85rem;
  455. }
  456. .padding {
  457. padding: 1rem;
  458. }
  459. .action-group-list {
  460. margin: 0;
  461. padding-left: 0;
  462. list-style: none;
  463. }
  464. .action-group-row {
  465. padding: 0.25rem 0;
  466. }
  467. .action-group-name {
  468. font-family: monospace;
  469. }
  470. .action-groups-link {
  471. color: inherit;
  472. text-decoration: none;
  473. }
  474. .action-groups-link:hover {
  475. text-decoration: underline;
  476. color: var(--link-color, #007bff);
  477. }
  478. </style>