|
19 | 19 | class="px-4 py-3 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6" |
20 | 20 | :class="{ 'bg-white': index % 2 === 0, 'bg-gray-50': index % 2 !== 0 }" |
21 | 21 | > |
22 | | - <dt |
23 | | - :id="'health-detail__' + name" |
24 | | - class="text-sm font-medium text-gray-500" |
25 | | - > |
| 22 | + <dt :id="`health-${id}__${name}`" class="text-sm font-medium text-gray-500"> |
26 | 23 | {{ name }} |
27 | 24 | </dt> |
28 | 25 | <dd |
29 | 26 | class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2" |
30 | | - :aria-labelledby="'health-detail__' + name" |
| 27 | + :aria-labelledby="`health-${id}__` + name" |
31 | 28 | > |
32 | 29 | <sba-status-badge v-if="health.status" :status="health.status" /> |
33 | 30 |
|
34 | 31 | <dl v-if="details && details.length > 0" class="grid grid-cols-2 mt-2"> |
35 | 32 | <template v-for="detail in details" :key="detail.name"> |
36 | | - <dt class="font-medium" v-text="detail.name" /> |
| 33 | + <dt |
| 34 | + class="font-medium" |
| 35 | + :id="`health-detail-${id}__${detail.name}`" |
| 36 | + v-text="detail.name" |
| 37 | + /> |
37 | 38 | <dd |
38 | | - v-if="name === 'diskSpace' && typeof detail.value === 'number'" |
| 39 | + v-if=" |
| 40 | + name.toLowerCase().startsWith('diskspace') && |
| 41 | + typeof detail.value === 'number' |
| 42 | + " |
| 43 | + :aria-labelledby="`health-detail-${id}__${detail.name}`" |
39 | 44 | v-text="prettyBytes(detail.value)" |
40 | 45 | /> |
41 | | - <dd v-else-if="typeof detail.value === 'object'"> |
| 46 | + <dd |
| 47 | + v-else-if="typeof detail.value === 'object'" |
| 48 | + :aria-labelledby="`health-detail-${id}__${detail.name}`" |
| 49 | + > |
42 | 50 | <pre |
43 | 51 | class="break-words whitespace-pre-wrap" |
44 | | - v-text="toJson(detail.value)" |
| 52 | + v-text="JSON.stringify(detail.value)" |
45 | 53 | /> |
46 | 54 | </dd> |
47 | 55 | <dd |
48 | 56 | v-else |
| 57 | + :aria-labelledby="`health-detail-${id}__${detail.name}`" |
49 | 58 | class="break-words whitespace-pre-wrap" |
50 | 59 | v-text="detail.value" |
51 | 60 | /> |
|
63 | 72 | /> |
64 | 73 | </template> |
65 | 74 |
|
66 | | -<script> |
| 75 | +<script lang="ts" setup> |
67 | 76 | import prettyBytes from 'pretty-bytes'; |
| 77 | +import { computed, useId } from 'vue'; |
| 78 | +
|
| 79 | +const id = useId(); |
68 | 80 |
|
69 | 81 | const isChildHealth = (value) => { |
70 | 82 | return value !== null && typeof value === 'object' && 'status' in value; |
71 | 83 | }; |
72 | 84 |
|
73 | | -export default { |
74 | | - name: 'HealthDetails', |
75 | | - props: { |
76 | | - name: { |
77 | | - type: String, |
78 | | - required: true, |
79 | | - }, |
80 | | - health: { |
81 | | - type: Object, |
82 | | - required: true, |
83 | | - }, |
84 | | - index: { |
85 | | - type: Number, |
86 | | - default: 0, |
87 | | - }, |
88 | | - }, |
89 | | - computed: { |
90 | | - details() { |
91 | | - if (this.health.details || this.health.components) { |
92 | | - return Object.entries(this.health.details || this.health.components) |
93 | | - .filter(([, value]) => !isChildHealth(value)) |
94 | | - .map(([name, value]) => ({ name, value })); |
95 | | - } |
96 | | - return []; |
97 | | - }, |
98 | | - childHealth() { |
99 | | - if (this.health.details || this.health.components) { |
100 | | - return Object.entries(this.health.details || this.health.components) |
101 | | - .filter(([, value]) => isChildHealth(value)) |
102 | | - .map(([name, value]) => ({ name, value })); |
103 | | - } |
104 | | - return []; |
105 | | - }, |
106 | | - }, |
107 | | - methods: { |
108 | | - prettyBytes, |
109 | | - toJson(obj) { |
110 | | - return JSON.stringify(obj, null, 2); |
111 | | - }, |
112 | | - }, |
113 | | -}; |
| 85 | +const { |
| 86 | + health, |
| 87 | + name, |
| 88 | + index = 0, |
| 89 | +} = defineProps<{ |
| 90 | + name: string; |
| 91 | + health: Record<string, any>; |
| 92 | + index?: number; |
| 93 | +}>(); |
| 94 | +
|
| 95 | +const details = computed(() => { |
| 96 | + if (health.details || health.components) { |
| 97 | + return Object.entries(health.details || health.components) |
| 98 | + .filter(([, value]) => !isChildHealth(value)) |
| 99 | + .map(([name, value]) => ({ name, value })); |
| 100 | + } |
| 101 | + return []; |
| 102 | +}); |
| 103 | +
|
| 104 | +const childHealth = computed(() => { |
| 105 | + if (health.details || health.components) { |
| 106 | + return Object.entries(health.details || health.components) |
| 107 | + .filter(([, value]) => isChildHealth(value)) |
| 108 | + .map(([name, value]) => ({ name, value })); |
| 109 | + } |
| 110 | + return []; |
| 111 | +}); |
114 | 112 | </script> |
0 commit comments