ActionDetailsView.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. <template>
  2. <Section :title="'Action Details: ' + actionTitle" :padding="false">
  3. <template #toolbar>
  4. <button v-if="action" @click="startAction" title="Start this action" class="button neutral">
  5. <svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
  6. <path fill="currentColor" d="M8 6v12l8-6z" />
  7. </svg>
  8. Start
  9. </button>
  10. </template>
  11. <div class = "flex-row padding" v-if="action">
  12. <div class = "fg1">
  13. <dl>
  14. <dt>Title</dt>
  15. <dd>{{ action.title }}</dd>
  16. <dt>Timeout</dt>
  17. <dd>{{ action.timeout }} seconds</dd>
  18. </dl>
  19. <p v-if="action" class = "fg1">
  20. Execution history for this action. You can filter by execution tracking ID.
  21. </p>
  22. </div>
  23. <div style = "align-self: start; text-align: right;">
  24. <span class="icon" v-html="action.icon"></span>
  25. <div class="filter-container">
  26. <label class="input-with-icons">
  27. <svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
  28. <path fill="currentColor"
  29. 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" />
  30. </svg>
  31. <input placeholder="Filter current page" v-model="searchText" />
  32. <button title="Clear search filter" :disabled="!searchText" @click="clearSearch">
  33. <svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
  34. <path fill="currentColor"
  35. 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" />
  36. </svg>
  37. </button>
  38. </label>
  39. </div>
  40. </div>
  41. </div>
  42. <div v-show="filteredLogs.length > 0">
  43. <table class="logs-table">
  44. <thead>
  45. <tr>
  46. <th>Timestamp</th>
  47. <th>Execution ID</th>
  48. <th>Metadata</th>
  49. <th>Status</th>
  50. </tr>
  51. </thead>
  52. <tbody>
  53. <tr v-for="log in filteredLogs" :key="log.executionTrackingId" class="log-row" :title="log.actionTitle">
  54. <td class="timestamp">{{ formatTimestamp(log.datetimeStarted) }}</td>
  55. <td>
  56. <router-link :to="`/logs/${log.executionTrackingId}`">
  57. {{ log.executionTrackingId }}
  58. </router-link>
  59. </td>
  60. <td class="tags">
  61. <span class="annotation">
  62. <span class="annotation-key">User:</span>
  63. <span class="annotation-val">{{ log.user }}</span>
  64. </span>
  65. <span v-if="log.tags && log.tags.length > 0" class="tag-list">
  66. <span v-for="tag in log.tags" :key="tag" class="tag">{{ tag }}</span>
  67. </span>
  68. </td>
  69. <td class="exit-code">
  70. <span :class="getStatusClass(log) + ' annotation'">
  71. {{ getStatusText(log) }}
  72. </span>
  73. </td>
  74. </tr>
  75. </tbody>
  76. </table>
  77. <Pagination :pageSize="pageSize" :total="totalCount" :currentPage="currentPage" @page-change="handlePageChange" class="padding"
  78. @page-size-change="handlePageSizeChange" itemTitle="execution logs" />
  79. </div>
  80. <div v-show="logs.length === 0 && !loading" class="empty-state">
  81. <p>This action has no execution history.</p>
  82. <router-link to="/">Return to index</router-link>
  83. </div>
  84. </Section>
  85. </template>
  86. <script setup>
  87. import { ref, computed, onMounted, watch } from 'vue'
  88. import { useRoute, useRouter } from 'vue-router'
  89. import Pagination from 'picocrank/vue/components/Pagination.vue'
  90. import Section from 'picocrank/vue/components/Section.vue'
  91. const route = useRoute()
  92. const router = useRouter()
  93. const logs = ref([])
  94. const action = ref(null)
  95. const actionTitle = ref('Action Details')
  96. const searchText = ref('')
  97. const pageSize = ref(10)
  98. const currentPage = ref(1)
  99. const loading = ref(false)
  100. const totalCount = ref(0)
  101. const filteredLogs = computed(() => {
  102. if (!searchText.value) {
  103. return logs.value
  104. }
  105. const searchLower = searchText.value.toLowerCase()
  106. return logs.value.filter(log =>
  107. log.executionTrackingId.toLowerCase().includes(searchLower) ||
  108. log.actionTitle.toLowerCase().includes(searchLower)
  109. )
  110. })
  111. async function fetchActionLogs() {
  112. loading.value = true
  113. try {
  114. const actionId = route.params.actionId
  115. const startOffset = (currentPage.value - 1) * pageSize.value
  116. const args = {
  117. "actionId": actionId,
  118. "startOffset": BigInt(startOffset),
  119. "pageSize": BigInt(Number(pageSize.value)),
  120. }
  121. const response = await window.client.getActionLogs(args)
  122. logs.value = response.logs
  123. const serverPageSize = Number(response.pageSize)
  124. if (Number.isFinite(serverPageSize) && serverPageSize > 0) {
  125. pageSize.value = serverPageSize
  126. }
  127. totalCount.value = Number(response.totalCount) || 0
  128. } catch (err) {
  129. console.error('Failed to fetch action logs:', err)
  130. window.showBigError('fetch-action-logs', 'getting action logs', err, false)
  131. } finally {
  132. loading.value = false
  133. }
  134. }
  135. async function fetchAction() {
  136. try {
  137. const actionId = route.params.actionId
  138. const args = {
  139. "bindingId": actionId
  140. }
  141. const response = await window.client.getActionBinding(args)
  142. action.value = response.action
  143. actionTitle.value = action.value?.title || 'Unknown Action'
  144. } catch (err) {
  145. console.error('Failed to fetch action:', err)
  146. window.showBigError('fetch-action', 'getting action details', err, false)
  147. }
  148. }
  149. function resetState() {
  150. action.value = null
  151. actionTitle.value = 'Action Details'
  152. logs.value = []
  153. totalCount.value = 0
  154. currentPage.value = 1
  155. searchText.value = ''
  156. loading.value = true
  157. }
  158. function clearSearch() {
  159. searchText.value = ''
  160. }
  161. function formatTimestamp(timestamp) {
  162. if (!timestamp) return 'Unknown'
  163. try {
  164. const date = new Date(timestamp)
  165. return date.toLocaleString()
  166. } catch (err) {
  167. return timestamp
  168. }
  169. }
  170. function getStatusClass(log) {
  171. if (log.timedOut) return 'status-timeout'
  172. if (log.blocked) return 'status-blocked'
  173. if (log.exitCode !== 0) return 'status-error'
  174. return 'status-success'
  175. }
  176. function getStatusText(log) {
  177. if (log.timedOut) return 'Timed out'
  178. if (log.blocked) return 'Blocked'
  179. if (log.exitCode !== 0) return `Exit code ${log.exitCode}`
  180. return 'Completed'
  181. }
  182. function handlePageChange(page) {
  183. currentPage.value = page
  184. fetchActionLogs()
  185. }
  186. function handlePageSizeChange(newPageSize) {
  187. pageSize.value = newPageSize
  188. currentPage.value = 1
  189. fetchActionLogs()
  190. }
  191. async function startAction() {
  192. if (!action.value || !action.value.bindingId) {
  193. console.error('Cannot start action: no binding ID')
  194. return
  195. }
  196. try {
  197. const args = {
  198. "bindingId": action.value.bindingId,
  199. "arguments": []
  200. }
  201. const response = await window.client.startAction(args)
  202. router.push(`/logs/${response.executionTrackingId}`)
  203. } catch (err) {
  204. console.error('Failed to start action:', err)
  205. window.showBigError('start-action', 'starting action', err, false)
  206. }
  207. }
  208. onMounted(() => {
  209. fetchAction()
  210. fetchActionLogs()
  211. })
  212. watch(
  213. () => route.params.actionId,
  214. () => {
  215. resetState()
  216. fetchAction()
  217. fetchActionLogs()
  218. },
  219. { immediate: false }
  220. )
  221. </script>
  222. <style scoped>
  223. .action-header {
  224. display: flex;
  225. align-items: center;
  226. gap: 0.5rem;
  227. }
  228. .action-header h2 {
  229. margin: 0;
  230. }
  231. .icon {
  232. font-size: 1.5rem;
  233. }
  234. .logs-table {
  235. width: 100%;
  236. border-collapse: collapse;
  237. }
  238. .logs-table th {
  239. background-color: var(--section-background);
  240. padding: 0.5rem;
  241. text-align: left;
  242. font-weight: 600;
  243. }
  244. .logs-table td {
  245. padding: 0.5rem;
  246. border-top: 1px solid var(--border-color);
  247. }
  248. .log-row:hover {
  249. background-color: var(--hover-background);
  250. }
  251. .timestamp {
  252. font-family: monospace;
  253. font-size: 0.9rem;
  254. color: var(--text-secondary);
  255. }
  256. .empty-state {
  257. padding: 2rem;
  258. text-align: center;
  259. color: var(--text-secondary);
  260. }
  261. .filter-container {
  262. display: flex;
  263. justify-content: flex-end;
  264. padding: 0.5rem 1rem;
  265. }
  266. .input-with-icons {
  267. display: flex;
  268. align-items: center;
  269. gap: 0.5rem;
  270. padding: 0.5rem;
  271. border: 1px solid var(--border-color);
  272. border-radius: 0.25rem;
  273. background: var(--section-background);
  274. width: 100%;
  275. max-width: 300px;
  276. }
  277. .input-with-icons input {
  278. border: none;
  279. outline: none;
  280. background: transparent;
  281. flex: 1;
  282. color: var(--text-primary);
  283. }
  284. .input-with-icons button {
  285. background: none;
  286. border: none;
  287. cursor: pointer;
  288. color: var(--text-secondary);
  289. }
  290. .input-with-icons button:disabled {
  291. opacity: 0.3;
  292. cursor: not-allowed;
  293. }
  294. .tags {
  295. display: flex;
  296. flex-wrap: wrap;
  297. gap: 0.5rem;
  298. }
  299. .annotation {
  300. display: inline-flex;
  301. align-items: center;
  302. gap: 0.25rem;
  303. font-size: 0.85rem;
  304. }
  305. .annotation-key {
  306. font-weight: 600;
  307. color: var(--text-secondary);
  308. }
  309. .annotation-val {
  310. color: var(--text-primary);
  311. }
  312. .tag-list {
  313. display: inline-flex;
  314. gap: 0.25rem;
  315. }
  316. .tag {
  317. background-color: var(--accent-color);
  318. color: var(--accent-text);
  319. padding: 0.1rem 0.5rem;
  320. border-radius: 0.25rem;
  321. font-size: 0.85rem;
  322. }
  323. .exit-code .status-success {
  324. color: #28a745;
  325. }
  326. .exit-code .status-error {
  327. color: #dc3545;
  328. }
  329. .exit-code .status-timeout {
  330. color: #ffc107;
  331. }
  332. .exit-code .status-blocked {
  333. color: #6c757d;
  334. }
  335. .padding {
  336. padding: 1rem;
  337. }
  338. </style>