|
| 1 | +<template> |
| 2 | + <ContextChip |
| 3 | + class="flow-selection-button" |
| 4 | + :modelValue="modelValue" |
| 5 | + @toggle="toggleSelection" |
| 6 | + > |
| 7 | + <template #text> |
| 8 | + <span>Debug</span> |
| 9 | + <span class="counter italic" :title="selectionTitle">( {{ selectedCounter }} {{ pluralize('log', selectedCounter) }} )</span> |
| 10 | + </template> |
| 11 | + </ContextChip> |
| 12 | +</template> |
| 13 | + |
| 14 | +<script> |
| 15 | +import { mapActions, mapState } from 'vuex' |
| 16 | +
|
| 17 | +import { pluralize } from '../../../composables/String.js' |
| 18 | +
|
| 19 | +import ContextChip from './ContextChip/index.vue' |
| 20 | +
|
| 21 | +export default { |
| 22 | + name: 'IncludeDebugContextButton', |
| 23 | + components: { |
| 24 | + ContextChip |
| 25 | + }, |
| 26 | + props: { |
| 27 | + modelValue: { |
| 28 | + type: Boolean, |
| 29 | + required: false, |
| 30 | + default: true |
| 31 | + } |
| 32 | + }, |
| 33 | + emits: ['update:modelValue'], |
| 34 | + computed: { |
| 35 | + ...mapState('product/assistant', ['debugLog']), |
| 36 | + selectedCounter () { |
| 37 | + return this.debugLog.length |
| 38 | + }, |
| 39 | + selectionTitle () { |
| 40 | + const map = {} |
| 41 | + this.debugLog.forEach(n => { |
| 42 | + map[n.type] = (map[n.type] ?? 0) + 1 |
| 43 | + }) |
| 44 | +
|
| 45 | + const tipBuilder = (logEntry, index) => { |
| 46 | + logEntry = logEntry || {} |
| 47 | + const level = logEntry.level || '' |
| 48 | + const nonDebugLevel = level !== 'debug' ? level : '' |
| 49 | + const topic = logEntry.metadata?.topic || '' |
| 50 | + const name = logEntry.source?.name || logEntry.source?.id || logEntry.metadata?.path || '' |
| 51 | + const format = logEntry.metadata?.format || '' |
| 52 | + const type = logEntry.source?.type || '' |
| 53 | + const property = logEntry.metadata?.property || '' |
| 54 | + const strBuilder = [] |
| 55 | + if (name) strBuilder.push(`node: ${name}`) |
| 56 | + if (topic) strBuilder.push(`topic: ${topic}`) |
| 57 | + if (nonDebugLevel) { |
| 58 | + if (type) { |
| 59 | + strBuilder.push(`${type} : (${nonDebugLevel})`) |
| 60 | + } |
| 61 | + } |
| 62 | + if (property) { |
| 63 | + if (format) { |
| 64 | + strBuilder.push(`property: ${property} ${format}`) |
| 65 | + } else { |
| 66 | + strBuilder.push(`property: ${property}`) |
| 67 | + } |
| 68 | + } |
| 69 | + return `${index + 1}: ${strBuilder.join(', ')}` |
| 70 | + } |
| 71 | +
|
| 72 | + const list = this.debugLog.map(tipBuilder).join('\n') |
| 73 | +
|
| 74 | + return `Selected Logs: \n${list}` |
| 75 | + } |
| 76 | + }, |
| 77 | + methods: { |
| 78 | + ...mapActions('product/assistant', ['resetDebugLogContext']), |
| 79 | + pluralize, |
| 80 | + toggleSelection () { |
| 81 | + this.$emit('update:modelValue', !this.modelValue) |
| 82 | + this.resetDebugLogContext() |
| 83 | + } |
| 84 | + } |
| 85 | +} |
| 86 | +</script> |
| 87 | +
|
| 88 | +<style lang="scss"> |
| 89 | +.flow-selection-button { |
| 90 | + .text { |
| 91 | + .counter { |
| 92 | + color: $ff-grey-500; |
| 93 | + margin-left: 4px; |
| 94 | + font-size: $ff-funit-xs; |
| 95 | + } |
| 96 | + } |
| 97 | +} |
| 98 | +</style> |
0 commit comments