|
| 1 | +<template> |
| 2 | + <div |
| 3 | + v-uni-id="'case-id-' + rowId" |
| 4 | + class="case-ids-cell" |
| 5 | + > |
| 6 | + <template v-if="!ids.length"> |
| 7 | + — |
| 8 | + </template> |
| 9 | + <template v-else-if="!hasOverflow"> |
| 10 | + <span class="case-ids-preview">{{ ids.join(", ") }}</span> |
| 11 | + </template> |
| 12 | + <template v-else> |
| 13 | + <button |
| 14 | + :id="popoverTriggerId" |
| 15 | + type="button" |
| 16 | + class="case-ids-trigger" |
| 17 | + :title="$t('Show full list')" |
| 18 | + > |
| 19 | + <span class="case-ids-preview">{{ previewHead }}</span><span class="case-ids-ellipsis">…</span><span class="case-ids-more-count text-muted">+{{ moreHiddenCount }}</span> |
| 20 | + </button> |
| 21 | + <b-popover |
| 22 | + :target="popoverTriggerId" |
| 23 | + triggers="click" |
| 24 | + placement="auto" |
| 25 | + boundary="viewport" |
| 26 | + container="body" |
| 27 | + custom-class="case-ids-popover" |
| 28 | + > |
| 29 | + <template #title> |
| 30 | + {{ $t("Case IDs") }} |
| 31 | + <span class="text-muted font-weight-normal">({{ ids.length }})</span> |
| 32 | + </template> |
| 33 | + <div class="case-ids-popover-inner"> |
| 34 | + <pre class="case-ids-popover-pre mb-0">{{ fullListText }}</pre> |
| 35 | + </div> |
| 36 | + </b-popover> |
| 37 | + </template> |
| 38 | + </div> |
| 39 | +</template> |
| 40 | + |
| 41 | +<script> |
| 42 | +import { createUniqIdsMixin } from "vue-uniq-ids"; |
| 43 | +
|
| 44 | +const uniqIdsMixin = createUniqIdsMixin(); |
| 45 | +
|
| 46 | +export default { |
| 47 | + name: "CaseIdsTableCell", |
| 48 | + mixins: [uniqIdsMixin], |
| 49 | + props: { |
| 50 | + caseIds: { |
| 51 | + type: [Array, String, Number], |
| 52 | + default: null, |
| 53 | + }, |
| 54 | + rowId: { |
| 55 | + type: [Number, String], |
| 56 | + required: true, |
| 57 | + }, |
| 58 | + previewLimit: { |
| 59 | + type: Number, |
| 60 | + default: 5, |
| 61 | + }, |
| 62 | + }, |
| 63 | + computed: { |
| 64 | + ids() { |
| 65 | + return this.parseCaseIdsArray(this.caseIds); |
| 66 | + }, |
| 67 | + hasOverflow() { |
| 68 | + return this.ids.length > this.previewLimit; |
| 69 | + }, |
| 70 | + previewHead() { |
| 71 | + return this.ids.slice(0, this.previewLimit).join(", "); |
| 72 | + }, |
| 73 | + moreHiddenCount() { |
| 74 | + return this.ids.length - this.previewLimit; |
| 75 | + }, |
| 76 | + fullListText() { |
| 77 | + return this.ids.join(", "); |
| 78 | + }, |
| 79 | + popoverTriggerId() { |
| 80 | + return `retention-case-ids-pop-${this.rowId}`; |
| 81 | + }, |
| 82 | + }, |
| 83 | + methods: { |
| 84 | + parseCaseIdsArray(caseIds) { |
| 85 | + if (caseIds == null || caseIds === "") { |
| 86 | + return []; |
| 87 | + } |
| 88 | + if (Array.isArray(caseIds)) { |
| 89 | + return caseIds.map(String); |
| 90 | + } |
| 91 | + if (typeof caseIds === "string") { |
| 92 | + try { |
| 93 | + const parsed = JSON.parse(caseIds); |
| 94 | + return Array.isArray(parsed) ? parsed.map(String) : []; |
| 95 | + } catch { |
| 96 | + return []; |
| 97 | + } |
| 98 | + } |
| 99 | + return [String(caseIds)]; |
| 100 | + }, |
| 101 | + }, |
| 102 | +}; |
| 103 | +</script> |
| 104 | + |
| 105 | +<style lang="scss" scoped> |
| 106 | +.case-ids-preview { |
| 107 | + color: #4e5663; |
| 108 | +} |
| 109 | +
|
| 110 | +.case-ids-trigger { |
| 111 | + cursor: pointer; |
| 112 | + border: none; |
| 113 | + background: transparent; |
| 114 | + font: inherit; |
| 115 | + color: inherit; |
| 116 | + border-radius: 4px; |
| 117 | + margin: -2px -4px; |
| 118 | + padding: 2px 4px; |
| 119 | + display: inline; |
| 120 | + text-align: left; |
| 121 | + line-height: inherit; |
| 122 | + vertical-align: baseline; |
| 123 | +
|
| 124 | + &:hover, |
| 125 | + &:focus { |
| 126 | + background-color: rgba(0, 0, 0, 0.04); |
| 127 | + } |
| 128 | +
|
| 129 | + &:focus { |
| 130 | + outline: none; |
| 131 | + box-shadow: 0 0 0 2px rgba(13, 110, 253, 0.25); |
| 132 | + } |
| 133 | +} |
| 134 | +
|
| 135 | +.case-ids-ellipsis { |
| 136 | + color: #4e5663; |
| 137 | + letter-spacing: 0.02em; |
| 138 | +} |
| 139 | +
|
| 140 | +.case-ids-more-count { |
| 141 | + font-size: 12px; |
| 142 | + margin-left: 2px; |
| 143 | + font-weight: 500; |
| 144 | + white-space: nowrap; |
| 145 | +} |
| 146 | +</style> |
| 147 | + |
| 148 | +<!-- Popover is teleported to body; scoped styles do not apply. --> |
| 149 | +<style lang="scss"> |
| 150 | +.popover.case-ids-popover { |
| 151 | + max-width: min(440px, 92vw); |
| 152 | + box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12); |
| 153 | +} |
| 154 | +
|
| 155 | +.popover.case-ids-popover .popover-body { |
| 156 | + padding: 0; |
| 157 | +} |
| 158 | +
|
| 159 | +.case-ids-popover-inner { |
| 160 | + max-height: min(320px, 50vh); |
| 161 | + overflow: auto; |
| 162 | + padding: 0.75rem 1rem; |
| 163 | +} |
| 164 | +
|
| 165 | +.case-ids-popover-pre { |
| 166 | + white-space: pre-wrap; |
| 167 | + word-break: break-all; |
| 168 | + font-size: 13px; |
| 169 | + line-height: 1.45; |
| 170 | + color: #4e5663; |
| 171 | +} |
| 172 | +</style> |
0 commit comments