4
0

executionLogEvents.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. export function cloneLogEntry (logEntry) {
  2. if (!logEntry) {
  3. return null
  4. }
  5. return {
  6. ...logEntry,
  7. tags: Array.isArray(logEntry.tags) ? [...logEntry.tags] : logEntry.tags
  8. }
  9. }
  10. export function getExecutionLogEntry (evt) {
  11. const logEntry = evt?.payload?.logEntry ?? evt?.detail?.logEntry ?? null
  12. return cloneLogEntry(logEntry)
  13. }
  14. export function updateLogEntryInList (entries, logEntry) {
  15. if (!logEntry?.executionTrackingId || !entries) {
  16. return false
  17. }
  18. const index = entries.findIndex(
  19. item => item.executionTrackingId === logEntry.executionTrackingId
  20. )
  21. if (index < 0) {
  22. return false
  23. }
  24. entries[index] = logEntry
  25. return true
  26. }
  27. export function updateLogEntryInGroups (groups, logEntry) {
  28. const entry = cloneLogEntry(logEntry)
  29. if (!entry?.executionTrackingId || !groups) {
  30. return null
  31. }
  32. let firstMatch = null
  33. for (const group of groups) {
  34. for (const action of group.actions || []) {
  35. const entries = action.entries || []
  36. const index = entries.findIndex(
  37. item => item.executionTrackingId === entry.executionTrackingId
  38. )
  39. if (index < 0) {
  40. continue
  41. }
  42. const previous = entries[index]
  43. entries[index] = entry
  44. if (!firstMatch) {
  45. firstMatch = { group, action, index, previous }
  46. }
  47. }
  48. }
  49. return firstMatch
  50. }