-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathLogTableRow.vue
More file actions
254 lines (228 loc) Β· 6.65 KB
/
LogTableRow.vue
File metadata and controls
254 lines (228 loc) Β· 6.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<!--
SPDX-FileCopyrightText: 2023 Nextcloud Gmbh and Nextcloud contributors
SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
<tr ref="tableRowElement" :class="{ expanded: isExpanded }">
<td :class="cssLevelClass">
<span>{{ levelString }}</span>
</td>
<td :title="row.app">
<span>{{ row.app }}</span>
</td>
<td class="row-message" @click="isExpanded = !isExpanded">
<div class="row-message__container" :class="{ 'row-message__container--expanded': isExpanded }">
<div class="row-message__text">
<LogException v-if="row.exception" :exception="row.exception" />
<div v-if="showLogMessage" class="row-message__text_message" :title="row.message">
{{ row.message }}
</div>
</div>
<div class="row-message__action">
<NcButton
variant="tertiary-no-background"
:aria-label="
isExpanded
? t('logreader', 'Collapse row')
: t('logreader', 'Expand row')
"
@click.stop="isExpanded = !isExpanded">
<template #icon>
<IconChevronUp v-if="isExpanded" :size="20" />
<IconChevronDown v-else :size="20" />
</template>
</NcButton>
</div>
</div>
</td>
<td>
<span v-if="isRawDate">{{ row.time }}</span>
<NcDateTime
v-else
:key="settingsStore.dateTimeFormat"
:timestamp="timestamp"
:relative-time="isRelativeDate && 'long'"
:format="dateTimeFormat" />
</td>
<td>
<NcActions placement="left-start">
<NcActionButton close-after-click @click="$emit('show-details', row)">
<template #icon>
<IconViewList />
</template>
{{ t('logreader', 'Show details') }}
</NcActionButton>
<NcActionButton close-after-click @click="copyRaw">
<template #icon>
<IconContentCopy />
</template>
{{ t('logreader', 'Copy raw entry') }}
</NcActionButton>
<NcActionButton close-after-click @click="copyFormatted">
<template #icon>
<IconContentCopy />
</template>
{{ t('logreader', 'Copy formatted entry') }}
</NcActionButton>
</NcActions>
</td>
</tr>
</template>
<script setup lang="ts">
import type { ILogEntry } from '../../interfaces'
import { showSuccess } from '@nextcloud/dialogs'
import { translate as t } from '@nextcloud/l10n'
import { computed, nextTick, onUpdated, ref, watch } from 'vue'
import NcActionButton from '@nextcloud/vue/components/NcActionButton'
import NcActions from '@nextcloud/vue/components/NcActions'
import NcButton from '@nextcloud/vue/components/NcButton'
import NcDateTime from '@nextcloud/vue/components/NcDateTime'
import IconChevronDown from 'vue-material-design-icons/ChevronDown.vue'
import IconChevronUp from 'vue-material-design-icons/ChevronUp.vue'
import IconContentCopy from 'vue-material-design-icons/ContentCopy.vue'
import IconViewList from 'vue-material-design-icons/ViewList.vue'
import LogException from '../exception/LogException.vue'
import { LOGGING_LEVEL, LOGGING_LEVEL_NAMES } from '../../constants'
import { useSettingsStore } from '../../store/settings'
import { copyToCipboard } from '../../utils/clipboard'
import { useLogFormatting } from '../../utils/format'
const props = withDefaults(
defineProps<{
row: ILogEntry
timeFormat?: 'local' | 'raw' | 'utc'
}>(),
{
timeFormat: 'local',
},
)
const settingsStore = useSettingsStore()
const isRawDate = computed(() => settingsStore.dateTimeFormat === 'raw')
const isRelativeDate = computed(() => settingsStore.dateTimeFormat === 'relative')
const dateTimeFormat = computed(() => ({
dateStyle: 'medium',
timeStyle: 'medium',
timeZone: settingsStore.dateTimeFormat === 'utc' ? 'UTC' : undefined,
}))
const { formatLogEntry } = useLogFormatting()
const timestamp = computed(() => Date.parse(props.row.time))
/**
* Whether the row is expanded to show an overflowing log message
*/
const isExpanded = ref(false)
/**
* Show log message if either there is no exception or a custom message was added (at expanded view)
*/
const showLogMessage = computed(() => {
return !props.row.exception || (props.row.message !== props.row.exception.Message && isExpanded.value)
})
/**
* Human readable and localized level name
*/
const levelString = computed(() => LOGGING_LEVEL_NAMES[props.row.level])
/**
* CSS classes for row logging level (used for left border color)
*/
const cssLevelClass = computed(() => [
'logging-level',
`logging-level--${LOGGING_LEVEL[props.row.level]}`,
])
/**
* Reference to the current table row element (`tr`)
*/
const tableRowElement = ref<HTMLTableRowElement>()
/**
* Copy the raw log entry as json
*/
async function copyRaw() {
if (await copyToCipboard(JSON.stringify(props.row))) {
showSuccess(t('logreader', 'Log entry successfully copied'))
}
}
/**
* Copy the log entry formatted to be human readable
*/
async function copyFormatted() {
if (await copyToCipboard(formatLogEntry(props.row))) {
showSuccess(t('logreader', 'Log entry successfully copied'))
}
}
/**
* If expanded set a fixed height to show the full log message,
* if not remove the height style to reset the height to one text line with hidden overflow
*/
function resizeTabeRow() {
if (isExpanded.value) {
nextTick(() => {
const height = tableRowElement.value?.scrollHeight || 0
if (tableRowElement.value) {
tableRowElement.value.style.height = `${height}px`
}
})
} else if (tableRowElement.value !== undefined) {
tableRowElement.value.style.height = ''
}
}
// Handle the expand resizing of the table row
onUpdated(() => resizeTabeRow)
watch(isExpanded, () => resizeTabeRow)
</script>
<style lang="scss" scoped>
td {
display: block;
overflow: hidden;
text-overflow: ellipsis;
min-height: 42px;
padding-block-start: 4px;
padding-inline: 18px 0;
}
.row-message {
&__container {
display: flex;
justify-content: space-between;
justify-items: start;
&--expanded {
margin-block-end: 0.5rem;
}
}
// The text container (exception / message)
&__text {
display: flex;
flex-direction: column;
width: calc(100% - 48px); // 100% - 44px action - 2*4px action padding
// The real message
&_message {
overflow: hidden;
text-overflow: ellipsis;
width: 100%;
}
}
&__action {
// Ensure outline is show when focus-visible
padding: 2px;
}
}
tr {
display: flex;
&.expanded {
white-space: normal;
.row-message--text {
white-space: normal;
}
}
}
.logging-level {
border-inline-start: 4px solid;
&--debug {
border-inline-start-color: var(--color-border-maxcontrast);
}
&--info {
border-inline-start-color: var(--color-element-info, var(--color-info));
}
&--warning {
border-inline-start-color: var(--color-element-warning, var(--color-warning));
}
&--error, &--fatal {
border-inline-start-color: var(--color-element-error, var(--color-error));
}
}
</style>